NewsService.php 288 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  65. class NewsService implements NewsServiceInterface
  66. {
  67. #[Inject]
  68. protected Redis $redis;
  69. /**
  70. * 获取导航池列表
  71. * @param array $data
  72. * @return array
  73. */
  74. public function getCategoryList(array $data): array
  75. {
  76. $search = $data['name'] ?? '';
  77. $page = (int)($data['page'] ?? 1);
  78. $perPage = (int)($data['pageSize'] ?? 10);
  79. // 1. 查出所有匹配的分类id
  80. if ($search) {
  81. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  82. if (empty($matchedIds)) {
  83. return Result::success(['rows' => [], 'total' => 0]);
  84. }
  85. // 2. 递归查所有父级,直到一级分类
  86. $idsStr = implode(',', $matchedIds);
  87. $sql = "
  88. WITH RECURSIVE parents AS (
  89. SELECT * FROM category WHERE id IN ($idsStr)
  90. UNION ALL
  91. SELECT c.* FROM category c
  92. INNER JOIN parents p ON c.id = p.pid
  93. )
  94. SELECT * FROM parents
  95. ";
  96. $parents = Db::select($sql);
  97. $parentIds = [];
  98. foreach ($parents as $row) {
  99. if ($row->pid == 0) {
  100. $parentIds[] = $row->id;
  101. }
  102. }
  103. $parentIds = array_unique($parentIds);
  104. } else {
  105. // 没有搜索,一级分类就是根
  106. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  107. }
  108. // 3. 一级分类分页
  109. $total = count($parentIds);
  110. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  111. if (empty($parentIds)) {
  112. return Result::success(['rows' => [], 'total' => $total]);
  113. }
  114. // 4. 递归查所有子孙
  115. $idsStr = implode(',', $parentIds);
  116. $sql = "
  117. WITH RECURSIVE subcategories AS (
  118. SELECT * FROM category WHERE id IN ($idsStr)
  119. UNION ALL
  120. SELECT c.* FROM category c
  121. INNER JOIN subcategories s ON c.pid = s.id
  122. )
  123. SELECT * FROM subcategories ORDER BY updated_at DESC
  124. ";
  125. $allCategories = Db::select($sql);
  126. // 5. 组装树结构
  127. $categoryMap = [];
  128. foreach ($allCategories as $cat) {
  129. $cat = (array)$cat;
  130. $cat['children'] = [];
  131. $categoryMap[$cat['id']] = $cat;
  132. }
  133. foreach ($categoryMap as $id => &$cat) {
  134. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  135. $categoryMap[$cat['pid']]['children'][] = &$cat;
  136. }
  137. }
  138. unset($cat);
  139. $categoryTree = [];
  140. foreach ($parentIds as $id) {
  141. if (isset($categoryMap[$id])) {
  142. $categoryTree[] = $categoryMap[$id];
  143. }
  144. }
  145. return Result::success([
  146. 'rows' => $categoryTree,
  147. 'total' => $total,
  148. ]);
  149. }
  150. private function findMatchedCategories($search)
  151. {
  152. if ($search) {
  153. return Category::where('name', 'like', "%{$search}%")
  154. ->orderBy('updated_at', 'desc')
  155. ->get();
  156. }
  157. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  158. ->get();
  159. }
  160. private function findAllParents($categories)
  161. {
  162. $allCategories = [];
  163. foreach ($categories as $category) {
  164. $parentId = $category->pid;
  165. while ($parentId > 0) {
  166. $parent = Category::find($parentId);
  167. if ($parent) {
  168. $allCategories[$parent->id] = $parent;
  169. $parentId = $parent->pid;
  170. } else {
  171. break;
  172. }
  173. }
  174. $allCategories[$category->id] = $category;
  175. }
  176. return array_values($allCategories);
  177. }
  178. private function buildCategoryTree($category, $allRequiredCategories)
  179. {
  180. $categoryData = $category->toArray();
  181. $children = [];
  182. foreach ($allRequiredCategories as $c) {
  183. if ($c->pid === $category->id) {
  184. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  185. }
  186. }
  187. if (!empty($children)) {
  188. $categoryData['children'] = $children;
  189. }
  190. return $categoryData;
  191. }
  192. public function myCategoryList(array $data): array
  193. {
  194. $sszq = $data['sszq'] ?? '';
  195. unset($data['sszq']);
  196. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  197. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  198. $where[] = [
  199. 'pid',
  200. '=',
  201. $data['pid'],
  202. ];
  203. if (isset($data['name'])) {
  204. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  205. }
  206. var_dump($where);
  207. //根据分类id,从category表中取出分类信息
  208. $result = Category::where($where)
  209. ->whereIn('category.id', $catorytids)
  210. ->select('category.*', 'category.id as category_id')->get();
  211. if (empty($result)) {
  212. return Result::error("没有栏目数据");
  213. }
  214. return Result::success($result);
  215. }
  216. /**
  217. * @param array $data
  218. * @return array
  219. */
  220. public function categoryList(array $data): array
  221. {
  222. $where[] = [
  223. 'pid',
  224. '=',
  225. $data['pid']
  226. ];
  227. if (isset($data['name'])) {
  228. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  229. }
  230. var_dump($where);
  231. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  232. if (empty($result)) {
  233. return Result::error("没有栏目数据");
  234. }
  235. return Result::success($result);
  236. }
  237. /**
  238. * @param array $data
  239. * @return array
  240. */
  241. public function addCategory(array $data): array
  242. {
  243. if (isset($data['id'])) {
  244. unset($data['id']);
  245. }
  246. $id = Category::insertGetId($data);
  247. if (empty($id)) {
  248. return Result::error("添加失败");
  249. }
  250. return Result::success(['id' => $id]);
  251. }
  252. /**
  253. * @param array $data
  254. * @return array
  255. */
  256. public function delCategory(array $data): array
  257. {
  258. Db::beginTransaction();
  259. try {
  260. $categoryList = Category::where(['pid' => $data['id']])->get();
  261. if ($categoryList->toArray()) {
  262. Db::rollBack();
  263. return Result::error("分类下面有子分类不能删除");
  264. }
  265. $articleList = Article::where(['catid' => $data['id']])->get();
  266. if ($articleList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有资讯不能删除");
  269. }
  270. $result = Category::where($data)->delete();
  271. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  272. if (!$result) {
  273. Db::rollBack();
  274. return Result::error("删除失败");
  275. }
  276. Db::commit();
  277. return Result::success($result);
  278. } catch (\Exception $e) {
  279. Db::rollBack();
  280. return Result::error("删除失败" . $e->getMessage());
  281. }
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function updateCategory(array $data): array
  288. {
  289. $where = [
  290. 'id' => $data['id'],
  291. ];
  292. $result = Category::where($where)->update($data);
  293. if ($result) {
  294. return Result::success($result);
  295. } else {
  296. return Result::error("更新失败");
  297. }
  298. }
  299. /**
  300. * 获取导航池信息
  301. * @param array $data
  302. * @return array
  303. */
  304. public function getCategoryInfo(array $data): array
  305. {
  306. $where = [
  307. 'id' => $data['id'],
  308. ];
  309. $result = Category::where($where)->first();
  310. if ($result) {
  311. return Result::success($result);
  312. } else {
  313. return Result::error("更新失败");
  314. }
  315. }
  316. public function getArticleCommend(array $data): array
  317. {
  318. $where = [
  319. 'website_id' => $data['website_id'],
  320. ];
  321. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  322. var_dump($ids);
  323. if (empty($ids)) {
  324. return Result::error("没有推荐数据");
  325. }
  326. //id
  327. $whereArticle = [];
  328. if (isset($data['id'])) {
  329. $whereArticle['id'] = $data['id'];
  330. }
  331. //title like
  332. if (isset($data['title'])) {
  333. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  334. }
  335. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  336. ->where($whereArticle)
  337. ->orderBy('id', 'desc')
  338. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  339. if ($article) {
  340. $data = [
  341. 'rows' => $article->items(),
  342. 'count' => $article->total(),
  343. ];
  344. return Result::success($data);
  345. } else {
  346. return Result::error("获取失败失败");
  347. }
  348. }
  349. /**
  350. * @param array $data
  351. * @return array
  352. */
  353. public function getArticleList(array $data): array
  354. {
  355. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  356. $type_id = $data['type_id'];
  357. unset($data['type_id']);
  358. $user_id = $data['user_id'];
  359. unset($data['user_id']);
  360. $where = [];
  361. $status1 = [];
  362. if (isset($data['id']) && $data['id']) {
  363. array_push($where, ['article.id', '=', $data['id']]);
  364. }
  365. if (isset($data['title']) && $data['title']) {
  366. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  367. }
  368. if (isset($data['category_name']) && $data['category_name']) {
  369. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  370. }
  371. if (isset($data['catid']) && $data['catid']) {
  372. array_push($where, ['article.catid', '=', $data['catid']]);
  373. }
  374. if (isset($data['author']) && $data['author']) {
  375. array_push($where, ['article.author', '=', $data['author']]);
  376. }
  377. if (isset($data['islink']) && $data['islink'] !== "") {
  378. array_push($where, ['article.islink', '=', $data['islink']]);
  379. }
  380. if (isset($data['status']) && $data['status'] !== "") {
  381. array_push($where, ['article.status', '=', $data['status']]);
  382. }
  383. if (isset($data['status1'])) {
  384. $status1 = json_decode(($data['status1']));
  385. }
  386. //不是管理员展示个人数据;
  387. if ($type_id != 10000) {
  388. $where[] = ['article.admin_user_id', '=', $user_id];
  389. }
  390. $rep = Article::where($where)
  391. ->whereNotIn('article.status', [404])
  392. ->when($status1, function ($query) use ($status1) {
  393. if (isset($status1) && $status1) {
  394. $query->whereIn('article.status', $status1);
  395. }
  396. })
  397. ->leftJoin('category', 'article.catid', 'category.id')
  398. ->leftJoin('website_category', function ($join) {
  399. $join->on('article.web_site_id', '=', 'website_category.website_id')
  400. ->on('article.catid', '=', 'website_category.category_id');
  401. })
  402. ->select("article.*", "category.name as category_name", "website_category.alias")
  403. ->orderBy("article.updated_at", "desc")
  404. ->limit($data['pageSize'])
  405. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  406. $count = Article::where($where)->whereNotIn('article.status', [404])
  407. ->when($status1, function ($query) use ($status1) {
  408. if (isset($status1) && $status1) {
  409. $query->whereIn('article.status', $status1);
  410. }
  411. })
  412. ->leftJoin('category', 'article.catid', 'category.id')->count();
  413. $data = [
  414. 'rows' => $rep->toArray(),
  415. 'count' => $count,
  416. ];
  417. if (empty($rep)) {
  418. return Result::error("没有信息数据");
  419. }
  420. return Result::success($data);
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function addArticle(array $data): array
  427. {
  428. var_dump($data, '----------12-----------1');
  429. unset($data['user_type']);
  430. unset($data['nav_add_pool_id']);
  431. // unset($data['commend_id']);
  432. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  433. Db::beginTransaction();
  434. try {
  435. //处理投票
  436. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  437. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  438. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  439. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  440. unset($data['is_survey']);
  441. unset($data['survey_name']);
  442. unset($data['suvey_array']);
  443. // unset($data['website_id']);
  444. // unset($data['web_site_id']);
  445. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  446. if ($data['hits'] == '') {
  447. $data['hits'] = 0;
  448. }
  449. if ($data['is_original'] == '') {
  450. $data['is_original'] = 0;
  451. }
  452. if ($data['status'] == '') {
  453. $data['status'] = 0;
  454. }
  455. $articleData = $data;
  456. unset($articleData['content']);
  457. //自动处理缩略图、关键字、描述
  458. if ($articleData['imgurl'] == '') {
  459. //如果没有图,设置level=0
  460. $levelArr = json_decode($articleData['level'], true);
  461. var_dump($levelArr, '----------levelArr-----------1');
  462. //content中提取图片第一个图,正则提取
  463. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  464. preg_match_all($reg, $data['content'], $matches);
  465. if (isset($matches[1][0])) {
  466. //截取varchar240
  467. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  468. //如果有图,设置level=3
  469. if (!in_array(3, $levelArr)) {
  470. $levelArr[] = 3;
  471. }
  472. $articleData['level'] = json_encode($levelArr);
  473. } else {
  474. if (!in_array(0, $levelArr)) {
  475. $levelArr[] = 0;
  476. }
  477. $articleData['level'] = json_encode($levelArr);
  478. }
  479. }
  480. var_dump($articleData['level'], '----------$articleData[level]----------1');
  481. if ($articleData['keyword'] == '') {
  482. //提取标题+内容中的关键词
  483. $articleData['keyword'] = $data['title'];
  484. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  485. Jieba::init(); // 初始化 jieba-php
  486. Finalseg::init();
  487. $segList = Jieba::cut($articleData['keyword']);
  488. $segList1 = array_slice($segList, 0, 8);
  489. $articleData['keyword'] = implode(',', $segList1);
  490. }
  491. if ($articleData['introduce'] == '') {
  492. //提取内容中的描述
  493. $content = $data['content'];
  494. // 去除 <style> 和 <script> 标签及其内容
  495. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  496. // 去除所有 HTML 标签
  497. $content = strip_tags($content);
  498. // 去除 HTML 实体
  499. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  500. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  501. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  502. // 去除多余空白
  503. $content = preg_replace('/\s+/u', '', $content);
  504. // 截取 100 个字符
  505. $articleData['introduce'] = mb_substr($content, 0, 100);
  506. }
  507. if ($articleData['status'] == 0) {
  508. $this->sendMessage([
  509. 'talk_type' => 100,
  510. 'title' => $articleData['title'],
  511. 'content' => '提交了审核',
  512. 'messageType' => 2,
  513. ]);
  514. }
  515. $id = Article::insertGetId($articleData);
  516. $articleDataContent = [
  517. 'article_id' => $id,
  518. 'content' => $data['content'],
  519. ];
  520. ArticleData::insertGetId($articleDataContent);
  521. //处理投票
  522. if ($is_survey == 1) {
  523. //生成年月日时分秒+8位随机数
  524. $uuid = date('YmdHis') . rand(10000000, 99999999);
  525. var_dump($suvey_array, 'suvey_array________');
  526. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  527. var_dump($suveys_array, '---------------------1');
  528. var_dump($suvey_array, '---------------------2');
  529. $suvey_data = [];
  530. foreach ($suveys_array as $key => $value) {
  531. if ($value == '') {
  532. continue;
  533. }
  534. if (is_array($value)) {
  535. $suvey_data[] = [
  536. 'sur_id' => $uuid,
  537. 'art_id' => $id,
  538. 'website_id' => $website_id ?? 2,
  539. 'survey_name' => $survey_name,
  540. 'choice_name' => $value[1],
  541. 'is_other' => 1,
  542. 'other_id' => 0,
  543. 'results' => 0,
  544. ];
  545. } else {
  546. $suvey_data[] = [
  547. 'sur_id' => $uuid,
  548. 'art_id' => $id,
  549. 'website_id' => $website_id ?? 2,
  550. 'survey_name' => $survey_name,
  551. 'choice_name' => $value,
  552. 'is_other' => 0,
  553. 'other_id' => 0,
  554. 'results' => 0,
  555. ];
  556. }
  557. if (empty($suvey_data)) {
  558. throw new \Exception("投票数据为空");
  559. }
  560. }
  561. $result = ArticleSurvey::insert($suvey_data);
  562. if (!$result) {
  563. throw new \Exception("投票失败,ArticleSurvey插入失败");
  564. }
  565. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  566. if (!$result) {
  567. throw new \Exception("投票失败,更新主表失败");
  568. }
  569. }
  570. Db::commit();
  571. return Result::success(['id' => $id]);
  572. } catch (\Throwable $ex) {
  573. Db::rollBack();
  574. var_dump($ex->getMessage());
  575. return Result::error("创建失败", 0);
  576. }
  577. }
  578. /**
  579. * @param array $data
  580. * @return array
  581. */
  582. public function delArticle(array $data): array
  583. {
  584. $result = Article::where($data)->delete();
  585. //survey投票删除
  586. articleSurvey::where(['art_id' => $data['id']])->delete();
  587. if (!$result) {
  588. return Result::error("删除失败");
  589. }
  590. return Result::success($result);
  591. }
  592. /**
  593. * @param array $data
  594. * @return array
  595. */
  596. public function updateArticle(array $data): array
  597. {
  598. var_dump($data, '----------12-----------1');
  599. Db::beginTransaction();
  600. unset($data['user_type']);
  601. // unset($data['web_site_id']);
  602. unset($data['nav_add_pool_id']);
  603. try {
  604. //处理投票
  605. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  606. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  607. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  608. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  609. unset($data['is_survey']);
  610. unset($data['survey_name']);
  611. unset($data['suvey_array']);
  612. unset($data['website_id']);
  613. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  614. if ($data['hits'] == '') {
  615. $data['hits'] = 0;
  616. }
  617. if ($data['is_original'] == '') {
  618. $data['is_original'] = 0;
  619. }
  620. if ($data['status'] == '') {
  621. $data['status'] = 0;
  622. }
  623. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  624. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  625. $articleData = $data;
  626. unset($articleData['content']);
  627. unset($articleData['status_name']);
  628. unset($articleData['name']);
  629. unset($articleData['content']);
  630. unset($articleData['pid_arr']);
  631. unset($articleData['pid']);
  632. //自动处理缩略图、关键字、描述
  633. if ($articleData['imgurl'] == '') {
  634. //如果没有图,设置level=0
  635. $levelArr = json_decode($articleData['level'], true);
  636. var_dump($levelArr, '----------levelArr-----------1');
  637. //content中提取图片第一个图,正则提取
  638. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  639. preg_match_all($reg, $data['content'], $matches);
  640. if (isset($matches[1][0])) {
  641. //截取varchar240
  642. // 截取到第一个<
  643. $articleData['imgurl'] = $matches[1][0];
  644. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  645. $pos = strpos($articleData['imgurl'], '"');
  646. if ($pos !== false) {
  647. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  648. }
  649. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  650. //如果有图,设置level=3
  651. if (!in_array(3, $levelArr)) {
  652. $levelArr[] = 3;
  653. }
  654. $articleData['level'] = json_encode($levelArr);
  655. } else {
  656. if (!in_array(0, $levelArr)) {
  657. $levelArr[] = 0;
  658. }
  659. $articleData['level'] = json_encode($levelArr);
  660. }
  661. }
  662. var_dump($articleData['level'], '----------$articleData[level]----------1');
  663. if ($articleData['keyword'] == '') {
  664. //提取标题+内容中的关键词
  665. $articleData['keyword'] = $data['title'];
  666. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  667. Jieba::init(); // 初始化 jieba-php
  668. Finalseg::init();
  669. $segList = Jieba::cut($articleData['keyword']);
  670. $segList1 = array_slice($segList, 0, 8);
  671. $articleData['keyword'] = implode(',', $segList1);
  672. }
  673. if ($articleData['introduce'] == '') {
  674. //提取内容中的描述
  675. $content = $data['content'];
  676. // 去除 <style> 和 <script> 标签及其内容
  677. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  678. // 去除所有 HTML 标签
  679. $content = strip_tags($content);
  680. // 去除 HTML 实体
  681. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  682. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  683. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  684. // 去除多余空白
  685. $content = preg_replace('/\s+/u', '', $content);
  686. // 截取 100 个字符
  687. $articleData['introduce'] = mb_substr($content, 0, 100);
  688. }
  689. if ($articleData['status'] == 0) {
  690. $this->sendMessage([
  691. 'talk_type' => 100,
  692. 'title' => $articleData['title'],
  693. 'content' => '提交了审核',
  694. 'messageType' => 2,
  695. ]);
  696. }
  697. $id = Article::where(['id' => $data['id']])->update($articleData);
  698. $articleDataContent = [
  699. 'content' => $data['content'],
  700. ];
  701. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  702. //处理投票
  703. $id = $data['id'];
  704. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  705. var_dump($suvey_array, 'suvey_array________delete');
  706. //处理投票
  707. if ($is_survey == 1) {
  708. //生成年月日时分秒+8位随机数
  709. $uuid = date('YmdHis') . rand(10000000, 99999999);
  710. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  711. var_dump($suveys_array, '---------------------1');
  712. $suvey_data = [];
  713. if (is_array($suveys_array)) {
  714. foreach ($suveys_array as $key => $value) {
  715. if ($value == '') {
  716. continue;
  717. }
  718. if (is_array($value)) {
  719. $suvey_data[] = [
  720. 'sur_id' => $uuid,
  721. 'art_id' => $id,
  722. 'website_id' => $website_id ?? 2,
  723. 'survey_name' => $survey_name,
  724. 'choice_name' => $value[1],
  725. 'is_other' => 1,
  726. 'other_id' => 0,
  727. 'results' => 0,
  728. ];
  729. } else {
  730. $suvey_data[] = [
  731. 'sur_id' => $uuid,
  732. 'art_id' => $id,
  733. 'website_id' => $website_id ?? 2,
  734. 'survey_name' => $survey_name,
  735. 'choice_name' => $value,
  736. 'is_other' => 0,
  737. 'other_id' => 0,
  738. 'results' => 0,
  739. ];
  740. }
  741. if (empty($suvey_data)) {
  742. throw new \Exception("投票数据为空");
  743. }
  744. }
  745. }
  746. $result = ArticleSurvey::insert($suvey_data);
  747. if (!$result) {
  748. throw new \Exception("投票失败");
  749. }
  750. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. } else {
  755. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  756. }
  757. Db::commit();
  758. return Result::success([]);
  759. } catch (\Throwable $ex) {
  760. Db::rollBack();
  761. var_dump($ex->getMessage());
  762. return Result::error("更新失败" . $ex->getMessage(), 0);
  763. }
  764. }
  765. /**
  766. * 更新资讯状态
  767. * @param array $data
  768. * @return array
  769. */
  770. public function upArticleStatus(array $data): array
  771. {
  772. $articleData = Article::where(['id' => $data['id']])->first();
  773. if ($data['status'] == 1) {
  774. $this->sendMessage([
  775. 'talk_type' => 101,
  776. 'title' => $articleData['title'],
  777. 'content' => '审核通过',
  778. 'messageType' => 2,
  779. 'user_id' => $articleData['admin_user_id'],
  780. ]);
  781. }
  782. if ($data['status'] == 2) {
  783. $this->sendMessage([
  784. 'talk_type' => 101,
  785. 'title' => $articleData['title'],
  786. 'content' => '审核拒绝',
  787. 'messageType' => 2,
  788. 'user_id' => $articleData['admin_user_id'],
  789. ]);
  790. }
  791. if ($data['status'] == 0) {
  792. $this->sendMessage([
  793. 'talk_type' => 100,
  794. 'title' => $articleData['title'],
  795. 'content' => '提交了审核',
  796. 'messageType' => 2,
  797. ]);
  798. }
  799. $result = Article::where(['id' => $data['id']])->update($data);
  800. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  801. //article_ignore 表插入数据 db操作
  802. //转成数组
  803. //删掉数据重新写入
  804. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  805. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  806. $insert_data = [];
  807. foreach ($website_ids as $key => $value) {
  808. $insert_data[] = [
  809. 'article_id' => $data['id'],
  810. 'website_id' => $value,
  811. ];
  812. }
  813. DB::table('article_ignore')->insert($insert_data);
  814. }
  815. if ($result) {
  816. return Result::success();
  817. } else {
  818. return Result::error("更新状态失败", 0);
  819. }
  820. }
  821. /**
  822. * 获取新闻详情
  823. * @param array $data
  824. * @return array
  825. */
  826. public function getArticleInfo(array $data): array
  827. {
  828. $where = [
  829. 'article.id' => $data['id'],
  830. // 'article.status' => 1,
  831. ];
  832. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  833. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  834. $info = $result;
  835. // var_dump($info, 'info');
  836. $info['survey_array'] = $articleSurvey;
  837. if ($result) {
  838. return Result::success($info);
  839. } else {
  840. return Result::error("查询失败", 0);
  841. }
  842. }
  843. /**
  844. * 获取头条新闻
  845. * @param array $data
  846. * @return array
  847. */
  848. public function getWebsiteArticlett(array $data): array
  849. {
  850. $website_id = $data['website_id'];
  851. $website = Website::where('id', $data['website_id'])->first();
  852. if(empty($website)){
  853. return Result::error("网站不存在",0);
  854. }
  855. $categorys = $this->processArticlePro($website_id);
  856. $catiall = $categorys['catiall'];
  857. $categoryIds = $categorys['categoryIds'];
  858. $where = [
  859. 'status' => 1
  860. ];
  861. // $website_column = $website['column'];
  862. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  863. $website_column = json_decode($website['website_column_arr_id'],true);
  864. }
  865. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  866. // return Result::success($diff_pid_categoryIds);
  867. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  868. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  869. }
  870. // $website_id = $data['website_id'];
  871. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  872. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  873. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  874. switch ($data['level']) {
  875. case 1:
  876. case 2:
  877. case 3:
  878. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  879. $query = Article::where($where)
  880. ->where('level', 'like', '%' . $data['level'] . '%')
  881. ->orderBy('updated_at', 'desc');
  882. break;
  883. case 4: //最新资讯
  884. $query = Article::where($where)->orderBy('updated_at', 'desc');
  885. break;
  886. case 5: //资讯推荐
  887. $query = Article::where($where)
  888. ->where('updated_at', '>', $month);
  889. break;
  890. case 7: //资讯分类
  891. if (isset($data['id']) && !empty($data['id'])) {
  892. $keyword = Article::where('id', $data['id'])->value('keyword');
  893. $keywordArray = explode(',', $keyword);
  894. $whereL7 = [];
  895. foreach ($keywordArray as $k => $v) {
  896. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  897. }
  898. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  899. break;
  900. } else {
  901. return Result::error("请输入资讯ID", 0);
  902. break;
  903. }
  904. default:
  905. break;
  906. }
  907. // $whereL7 = [];
  908. // if(isset($data['id']) && !empty($data['id'])){
  909. // $keyword = Article::where('id', $data['id'])->value('keyword');
  910. // $keywordArray = explode(',', $keyword);
  911. // foreach ($keywordArray as $k => $v) {
  912. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  913. // }
  914. // }
  915. // $query = Article::where($where)
  916. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  917. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  918. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  919. // }
  920. // if($data['level'] == 7){
  921. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  922. // }
  923. // if($data['level'] == 4){
  924. // $query = $query->inRandomOrder()
  925. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  926. // }
  927. // if($data['level'] == 5){
  928. // $query = $query->orderBy('updated_at','desc');
  929. // }
  930. // });
  931. if ($data['textnum'] > 0) {
  932. $query = clone $query;
  933. $result['text'] = $query
  934. ->whereIn('catid', $categoryIds)
  935. ->leftJoinSub(function ($query) use ($website_id) {
  936. $query->from('article_ignore')
  937. ->where('website_id', $website_id);
  938. }, 'article_ignore', function ($join) {
  939. $join->on('article_ignore.article_id', '=', 'article.id');
  940. })
  941. ->where(function ($query) use ($website_id) {
  942. $query->whereNull('article_ignore.article_id')
  943. ->orWhere('article_ignore.website_id', '!=', $website_id);
  944. })
  945. ->select(
  946. 'article.id',
  947. 'article.title',
  948. 'article.author',
  949. 'article.updated_at',
  950. 'article.introduce',
  951. 'article.islink',
  952. 'article.linkurl',
  953. 'article.copyfrom',
  954. 'article.cat_arr_id',
  955. 'article.catid',
  956. 'article.level'
  957. )
  958. ->offset($data['placeid'])
  959. ->limit($data['textnum'])
  960. ->get()->all();
  961. foreach ($result['text'] as $k => $v) {
  962. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  963. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  964. }
  965. }
  966. if ($data['imgnum'] > 0) {
  967. $query = clone $query;
  968. $result['img'] = $query
  969. ->whereIn('catid', $categoryIds)
  970. ->where('article.imgurl', '!=', '')
  971. ->select(
  972. 'article.id',
  973. 'article.title',
  974. 'article.imgurl',
  975. 'article.author',
  976. 'article.updated_at',
  977. 'article.introduce',
  978. 'article.islink',
  979. 'article.linkurl',
  980. 'article.copyfrom',
  981. 'article.cat_arr_id',
  982. 'article.catid',
  983. 'article.level'
  984. )
  985. ->offset($data['placeid'])
  986. ->limit($data['imgnum'])
  987. ->get()->all();
  988. foreach ($result['img'] as $k => $v) {
  989. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  990. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  991. }
  992. }
  993. if (empty($result)) {
  994. return Result::error("暂无相关资讯", 0);
  995. }
  996. return Result::success($result);
  997. }
  998. /**
  999. * 获取模块新闻
  1000. * @param array $data
  1001. * @return array
  1002. */
  1003. public function getWebsiteModelArticles(array $data): array
  1004. {
  1005. $catid = $data['catid'];
  1006. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1007. $category = $category->toArray();
  1008. if (!empty($category)) {
  1009. $where = [
  1010. 'status' => 1,
  1011. 'catid' => $catid,
  1012. ];
  1013. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1014. // 1:文字新闻;2:轮播图;3:图文;
  1015. // 级别:0:未分类
  1016. // 3:推荐图片
  1017. if ($data['level'] == 1) {
  1018. $data['level'] = 0;
  1019. }
  1020. $result = Article::where($where)
  1021. ->where(function ($query) use ($data) {
  1022. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1023. ->orWhereNull("level")
  1024. ->orWhereRaw("level = '[]'");
  1025. })
  1026. ->where(function ($query) use ($data) {
  1027. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1028. ->orWhereNull("ignore_ids");
  1029. })
  1030. ->orderBy("updated_at", "desc")
  1031. ->offset($placeid)
  1032. ->limit($data['pagesize'])
  1033. ->get();
  1034. if (empty($result)) {
  1035. return Result::error("此栏目暂无相关新闻", 0);
  1036. }
  1037. } else {
  1038. return Result::error("此网站暂无此栏目", 0);
  1039. }
  1040. return Result::success($result);
  1041. }
  1042. /**
  1043. *获取新闻列表
  1044. * @param array $data
  1045. * @return array
  1046. */
  1047. public function getWebsiteArticleList(array $data): array
  1048. {
  1049. // return Result::success($data);
  1050. $where[] = ['status', '=', 1];
  1051. $website_id = $data['website_id'];
  1052. $website = Website::where('id', $data['website_id'])->first();
  1053. if(empty($website)){
  1054. return Result::error("网站不存在",0);
  1055. }
  1056. // $website_column = $website['column'];
  1057. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1058. $website_column = json_decode($website['website_column_arr_id'],true);
  1059. }
  1060. $categorys = $this->processArticlePro($website_id);
  1061. $cat_1st_arr = $categorys['cat_1st_arr'];
  1062. $catiall = $categorys['catiall'];
  1063. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1064. // return Result::success($diff_pid_categoryIds);
  1065. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1066. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1067. }
  1068. if (isset($data['catid']) && !empty($data['catid'])) {
  1069. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1070. if (empty($category)) {
  1071. return Result::error("此网站暂无此栏目", 0);
  1072. }
  1073. array_push($where, ['catid', '=', $data['catid']]);
  1074. }
  1075. // return Result::success($where);
  1076. $query = Article::where($where)
  1077. ->leftJoinSub(function ($query) use ($website_id) {
  1078. $query->from('article_ignore')
  1079. ->where('website_id', $website_id);
  1080. }, 'article_ignore', function ($join) {
  1081. $join->on('article_ignore.article_id', '=', 'article.id');
  1082. })
  1083. ->where(function ($query) use ($website_id) {
  1084. $query->whereNull('article_ignore.article_id')
  1085. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1086. })
  1087. ->select(
  1088. 'article.id',
  1089. 'article.title',
  1090. 'article.imgurl',
  1091. 'article.author',
  1092. 'article.updated_at',
  1093. 'article.introduce',
  1094. 'article.islink',
  1095. 'article.linkurl',
  1096. 'article.copyfrom',
  1097. 'article.cat_arr_id',
  1098. 'article.catid'
  1099. );
  1100. $count = $query->count();
  1101. $rep = $query->orderBy("updated_at", "desc")
  1102. ->offset(($data['page'] - 1) * $data['pageSize'])
  1103. ->limit($data['pageSize'])
  1104. ->get()->all();
  1105. $categorys = $this->processArticlePro($website_id);
  1106. $cat_1st_arr = $categorys['cat_1st_arr'];
  1107. $catiall = $categorys['catiall'];
  1108. // $web['website_id'] = $data['website_id'];
  1109. foreach ($rep as $k => $v) {
  1110. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1111. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1112. }
  1113. // $rep = $this->processArticles($rep,$web);
  1114. $data = [
  1115. 'rows' => $rep,
  1116. 'count' => $count,
  1117. ];
  1118. if (empty($rep)) {
  1119. return Result::error("没有信息数据");
  1120. }
  1121. return Result::success($data);
  1122. }
  1123. /**
  1124. * 前端-获取新闻详情
  1125. * @param array $data
  1126. * @return array
  1127. */
  1128. public function selectWebsiteArticleInfo(array $data): array
  1129. {
  1130. $where = [
  1131. 'article.id' => $data['id'],
  1132. 'article.status' => 1,
  1133. ];
  1134. $result = Article::where($where)
  1135. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1136. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1137. ->where(function ($query) use ($data) {
  1138. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1139. ->orWhereNull("ignore_ids");
  1140. })
  1141. ->select(
  1142. 'article.*',
  1143. 'article_data.content',
  1144. 'article_data.article_id',
  1145. 'article_extend.website_url',
  1146. 'article_extend.email',
  1147. 'article_extend.contacts',
  1148. 'article_extend.contacts_mobile',
  1149. 'article_extend.contacts_address',
  1150. 'article_extend.zip_code',
  1151. 'article_extend.enterprise_name'
  1152. )
  1153. ->first();
  1154. if (empty($result)) {
  1155. return Result::error("暂无此新闻!", 0);
  1156. }
  1157. if (!empty($result['publiced_at'])) {
  1158. $result['updated_at'] = $result['publiced_at'];
  1159. }
  1160. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1161. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1162. ->where('website_category.website_id', $data['website_id'])
  1163. ->where(['website_category.category_id' => $result['catid']])
  1164. ->first();
  1165. if (empty($category)) {
  1166. return Result::error("查询失败", 0);
  1167. }
  1168. //手动推荐文章
  1169. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1170. if (empty($commend_ids)) {
  1171. $commendArticle = [];
  1172. } else {
  1173. //去除不存在的文章ID
  1174. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1175. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1176. ->where('article.status', 1)
  1177. ->where('website_category.website_id', $data['website_id'])
  1178. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1179. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1180. // ->orderBy('article.updated_at', 'desc')
  1181. ->limit(5)
  1182. ->get();
  1183. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1184. foreach ($commendArticle as $k => $v) {
  1185. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1186. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1187. $cat_arr_id = array_unique($cat_arr_id);
  1188. // 从website_category取出alias_pinyin
  1189. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1190. ->whereIn('category_id', $cat_arr_id)
  1191. ->pluck('alias_pinyin', 'category_id')
  1192. ->toArray();
  1193. // 将cat_arr_id的json转成路径/隔开
  1194. $path_parts = [];
  1195. foreach ($cat_arr_id as $cat_id) {
  1196. if (isset($cat_arr[$cat_id])) {
  1197. $path_parts[] = $cat_arr[$cat_id];
  1198. }
  1199. }
  1200. $v->alias_pinyin = implode('/', $path_parts);
  1201. } else {
  1202. $v->alias_pinyin = '';
  1203. }
  1204. }
  1205. }
  1206. $result['category_id'] = $category['category_id'];
  1207. $result['cat_name'] = $category['alias'];
  1208. $result['website_name'] = $category['website_name'] ?? "";
  1209. $result['suffix'] = $category['suffix'] ?? "";
  1210. $result['commendArticle'] = $commendArticle;
  1211. $result['commend_ids'] = $commend_ids;
  1212. return Result::success($result);
  1213. }
  1214. /**
  1215. * 前端-获取网站调查问卷
  1216. * @param array $data
  1217. * @return array
  1218. */
  1219. public function getWebsiteSurvey(array $data): array
  1220. {
  1221. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1222. $website = Website::where('id', $data['website_id'])->first();
  1223. if (empty($website)) {
  1224. return Result::error("暂无此网站", 0);
  1225. }
  1226. }
  1227. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1228. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1229. if (empty($article)) {
  1230. return Result::error("暂无此文章", 0);
  1231. }
  1232. // return Result::error($data,0);
  1233. $where['art_id'] = $data['art_id'];
  1234. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1235. } else {
  1236. $survey = Article::where(function ($query) {
  1237. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1238. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1239. })
  1240. ->where('status', 1)
  1241. ->where('is_survey', 1)
  1242. ->select('survey_id')
  1243. ->orderBy('updated_at', 'desc')
  1244. ->first();
  1245. if (empty($survey)) {
  1246. return Result::error("暂无调查问卷", 0);
  1247. }
  1248. $where['sur_id'] = $survey['survey_id'];
  1249. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1250. }
  1251. // return Result::success($where);
  1252. $result = ArticleSurvey::where($where)
  1253. ->where(function ($query) {
  1254. $query->where('is_other', 0)
  1255. ->orWhere(function ($subQuery) {
  1256. $subQuery->where('is_other', 1)
  1257. ->where('other_id', 0);
  1258. });
  1259. })
  1260. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1261. ->select('article_survey.*', 'article.survey_type')
  1262. ->get()->all();
  1263. if (empty($result)) {
  1264. return Result::error("此文章暂无调查问卷", 0);
  1265. }
  1266. return Result::success($result);
  1267. }
  1268. /**
  1269. * 前端-添加网站调查问卷选项
  1270. * @param array $data
  1271. * @return array
  1272. */
  1273. public function addWebsiteSurveyOption(array $data): array
  1274. {
  1275. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1276. $website = Website::where('id', $data['website_id'])->first();
  1277. if (empty($website)) {
  1278. return Result::error("暂无此网站", 0);
  1279. }
  1280. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1281. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1282. if (empty($survey)) {
  1283. return Result::error("此调查问卷不可添加选项", 0);
  1284. }
  1285. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1286. $choice = [
  1287. 'art_id' => $survey['art_id'],
  1288. 'website_id' => $data['website_id'],
  1289. 'survey_name' => $survey['survey_name'],
  1290. 'choice_name' => $data['choice_name'],
  1291. 'sur_id' => $survey['sur_id'],
  1292. 'is_other' => 1,
  1293. 'other_id' => $survey['id'],
  1294. ];
  1295. $result = ArticleSurvey::insertGetId($choice);
  1296. if (empty($result)) {
  1297. return Result::error("添加失败", 0);
  1298. }
  1299. return Result::success($result);
  1300. }
  1301. }
  1302. return Result::error("添加失败", 0);
  1303. }
  1304. return Result::error("添加失败", 0);
  1305. }
  1306. /**
  1307. * 前端-调查问卷投票
  1308. * @param array $data
  1309. * @return array
  1310. */
  1311. public function addWebsiteSurveyVote(array $data): array
  1312. {
  1313. // return Result::success($data);
  1314. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1315. $website = Website::where('id', $data['website_id'])->first();
  1316. if (empty($website)) {
  1317. return Result::error("暂无此网站", 0);
  1318. }
  1319. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1320. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1321. // return Result::success($survey);
  1322. if (empty($is_survey)) {
  1323. return Result::error("此调查问卷不存在", 0);
  1324. }
  1325. // return Result::success($survey);
  1326. // 调查问卷类型
  1327. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1328. //多选 若是json型则转化成数组类型
  1329. if (strpos($data['choice_id'], '[') === 0) {
  1330. $data['choice_id'] = json_decode($data['choice_id'], true);
  1331. } else {
  1332. // 单选 也转换成数组
  1333. $data['choice_id'] = [$data['choice_id']];
  1334. }
  1335. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1336. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1337. // ->where('website_id',$data['website_id'])
  1338. ->where('is_other', 1)
  1339. ->where('other_id', 0)
  1340. ->first();
  1341. if (!empty($other)) {
  1342. return Result::error("请选择已有的选项!", 0);
  1343. }
  1344. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1345. // ->where('website_id',$data['website_id'])
  1346. ->where('is_other', 1)
  1347. ->where('other_id', '!=', 0)
  1348. ->first();
  1349. // return Result::success($choice['other']);
  1350. $choice_id = $data['choice_id'];
  1351. if (!empty($choice['other'])) {
  1352. // array_push($data['choice_id'],$choice['other']['other_id']);
  1353. if (!empty($choice_id)) {
  1354. $key = array_search($choice['other']['id'], $choice_id);
  1355. if ($key !== false) {
  1356. unset($choice_id[$key]);
  1357. $choice_id = array_values($choice_id);
  1358. }
  1359. array_push($choice_id, $choice['other']['other_id']);
  1360. } else {
  1361. $choice_id[0] = $choice['other']['other_id'];
  1362. }
  1363. array_push($data['choice_id'], $choice['other']['other_id']);
  1364. }
  1365. // return Result::success($data);
  1366. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1367. // ->where('website_id',$data['website_id'])
  1368. ->increment('results', 1);
  1369. if (empty($choice)) {
  1370. return Result::error("请选择已有的选项!", 0);
  1371. }
  1372. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1373. // ->where('website_id',$data['website_id'])
  1374. ->where('other_id', 0)
  1375. ->get();
  1376. $survey['choice'] = $choice_id;
  1377. return Result::success($survey);
  1378. }
  1379. return Result::error("参数必填!");
  1380. }
  1381. return Result::error("此调查问卷不存在", 0);
  1382. }
  1383. return Result::error("参数必填!");
  1384. }
  1385. /**
  1386. * 后端-获取网站调查问卷列表
  1387. * @param array $data
  1388. * @return array
  1389. */
  1390. public function getSurveyList(array $data): array
  1391. {
  1392. $where = [];
  1393. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1394. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1395. }
  1396. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1397. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1398. }
  1399. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1400. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1401. }
  1402. // return Result::success($where);
  1403. if (!empty($where)) {
  1404. $query = Article::where($where)->where(function ($q) {
  1405. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1406. });
  1407. } else {
  1408. $query = Article::where(function ($q) {
  1409. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1410. });
  1411. }
  1412. $count = $query->count();
  1413. $survey = $query->orderByDesc('id')
  1414. ->limit($data['pageSize'])
  1415. ->offset(($data['page'] - 1) * $data['pageSize'])
  1416. ->get();
  1417. if (empty($survey->toArray())) {
  1418. return Result::error("暂无调查问卷!", 0);
  1419. }
  1420. $result = [
  1421. 'rows' => $survey,
  1422. 'count' => $count,
  1423. ];
  1424. return Result::success($result);
  1425. }
  1426. /**
  1427. * 后端-获取网站调查问卷详情
  1428. * @param array $data
  1429. * @return array
  1430. */
  1431. public function getSurveyInfo(array $data): array
  1432. {
  1433. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1434. $where = ['sur_id' => $data['sur_id']];
  1435. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1436. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1437. ->select('article_survey.*', 'article.survey_type')
  1438. ->get()->all();
  1439. if (empty($choose)) {
  1440. return Result::error("此调查问卷不存在", 0);
  1441. }
  1442. $resultsArray = array_column($choose, 'results');
  1443. $total = array_sum($resultsArray);
  1444. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1445. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1446. // $total = 0;
  1447. if (!empty($other)) {
  1448. $total = $total + $other['results'];
  1449. $other['choice_name'] = '(其他)';
  1450. if (!empty($others)) {
  1451. $other['hasChildren'] = true;
  1452. // array_push($other,['hasChildren','=',true]);
  1453. $other['children'] = $others;
  1454. $other_choices = [$other->toArray()];
  1455. $mer_choice = array_merge($choose, $other_choices);
  1456. $value_choice = array_values($mer_choice);
  1457. } else {
  1458. // return Result::error('1111');
  1459. $other_choices = [$other->toArray()];
  1460. $other_choices = array_merge($choose, $other_choices);
  1461. $value_choice = array_values($other_choices);
  1462. // return Result::success($result);
  1463. }
  1464. } else {
  1465. $value_choice = $choose;
  1466. }
  1467. $result = [
  1468. 'choose' => $value_choice,
  1469. 'total' => $total,
  1470. ];
  1471. }
  1472. return Result::success($result);
  1473. }
  1474. /**
  1475. * 前端-搜索新闻列表
  1476. * @param array $data
  1477. * @return array
  1478. */
  1479. public function selectWebsiteArticle(array $data): array
  1480. {
  1481. $website = Website::where('id', $data['website_id'])->first();
  1482. if(empty($website)){
  1483. return Result::error("网站不存在",0);
  1484. }
  1485. // $website_column = $website['column'];
  1486. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1487. $website_column = json_decode($website['website_column_arr_id'],true);
  1488. }
  1489. $website_id = $data['website_id'];
  1490. $categorys = $this->processArticlePro($website_id);
  1491. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1492. // return Result::success($diff_pid_categoryIds);
  1493. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1494. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1495. }
  1496. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1497. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1498. $catiall = $categorys['catiall'];
  1499. $categoryIds = $categorys['categoryIds'];
  1500. // return Result::success($categoryIds);
  1501. $query = Article::where('status', 1)
  1502. ->whereIn('catid', $categoryIds)
  1503. ->leftJoinSub(function ($query) use ($website_id) {
  1504. $query->from('article_ignore')
  1505. ->where('website_id', $website_id);
  1506. }, 'article_ignore', function ($join) {
  1507. $join->on('article_ignore.article_id', '=', 'article.id');
  1508. })
  1509. ->where(function ($query) use ($website_id) {
  1510. $query->whereNull('article_ignore.article_id')
  1511. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1512. });
  1513. // ->get()->all();
  1514. // return Result::success($query);
  1515. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1516. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1517. }
  1518. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1519. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1520. }
  1521. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1522. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1523. }
  1524. // 计算总数
  1525. $count = $query->count();
  1526. // return Result::success($count);
  1527. // 分页查询
  1528. $articles = $query
  1529. ->select(
  1530. 'article.id',
  1531. 'article.title',
  1532. 'article.imgurl',
  1533. 'article.author',
  1534. 'article.updated_at',
  1535. 'article.introduce',
  1536. 'article.islink',
  1537. 'article.linkurl',
  1538. 'article.copyfrom',
  1539. 'article.cat_arr_id',
  1540. 'article.catid',
  1541. 'article.department_arr_id',
  1542. 'article.city_arr_id',
  1543. )
  1544. ->orderBy("updated_at", "desc")
  1545. ->offset(($data['page'] - 1) * $data['pageSize'])
  1546. ->limit($data['pageSize'])
  1547. ->get();
  1548. // return Result::success($articles);
  1549. foreach ($articles as $k => $v) {
  1550. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1551. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1552. }
  1553. if (empty($articles)) {
  1554. return Result::error("没有符合条件的资讯数据");
  1555. }
  1556. $result = [
  1557. 'rows' => $articles,
  1558. 'count' => $count,
  1559. ];
  1560. return Result::success($result);
  1561. }
  1562. /**
  1563. * 模块新闻加强版
  1564. * @param array $data
  1565. * @return array
  1566. */
  1567. public function getWebsiteCatidArticle(array $data): array
  1568. {
  1569. $where = [
  1570. 'website_category.category_id' => $data['catid'],
  1571. 'website_category.website_id' => $data['website_id'],
  1572. ];
  1573. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1574. $child_catnum = $data['child_catnum'] ?? 1;
  1575. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1576. $childCategoryIds = array_column($category['child'], 'category_id');
  1577. if (empty($childCategoryIds)) {
  1578. return Result::error("暂无子栏目", 0);
  1579. }
  1580. $imgArticles = [];
  1581. $textArticles = [];
  1582. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1583. // 初始化子分类图片新闻和文字新闻数组
  1584. // 查询所有子级栏目的图文新闻
  1585. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1586. ->where(function ($query) use ($data) {
  1587. $query->where(function ($subQuery) use ($data) {
  1588. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1589. })->orWhereNull("ignore_ids");
  1590. })
  1591. ->where('status', 1)
  1592. ->where('imgurl', '!=', '')
  1593. ->select('*')
  1594. ->orderBy('updated_at', 'desc')
  1595. ->limit($data['child_imgnum'])
  1596. ->get();
  1597. }
  1598. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1599. // 查询所有子级栏目的文字新闻
  1600. $textArticles = Article::where('catid', $childCategoryIds[0])
  1601. ->where('status', 1)
  1602. ->where(function ($query) use ($data) {
  1603. $query->where(function ($subQuery) use ($data) {
  1604. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1605. })->orWhereNull("ignore_ids");
  1606. })
  1607. ->select('*')
  1608. ->orderBy('updated_at', 'desc')
  1609. ->limit($data['child_textnum'])
  1610. ->get();
  1611. }
  1612. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1613. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1614. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1615. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1616. return $child;
  1617. }, $category['child']);
  1618. }
  1619. // }
  1620. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1621. $category['img'] = WebsiteCategory::where($where)
  1622. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1623. ->where('article.status', 1)
  1624. ->where('article.imgurl', '!=', '')
  1625. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1626. ->orderBy('article.updated_at', 'desc')
  1627. ->limit($data['img_num'])
  1628. ->get();
  1629. }
  1630. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1631. $category['text'] = WebsiteCategory::where($where)
  1632. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1633. ->where('article.status', 1)
  1634. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1635. ->orderBy('article.updated_at', 'desc')
  1636. ->limit($data['text_num'])
  1637. ->get();
  1638. }
  1639. // $category = $category->get();
  1640. if (empty($category)) {
  1641. return Result::error("查询失败", 0);
  1642. }
  1643. return Result::success($category);
  1644. }
  1645. /**
  1646. * 模块新闻加强plus版
  1647. * @param array $data
  1648. * @return array
  1649. */
  1650. public function getWebsiteAllArticle(array $data): array
  1651. {
  1652. // return Result::success($data);
  1653. $time1 = microtime(true);
  1654. $wetbsite_id = $data['website_id'] ?? 2;
  1655. $data = json_decode($data['id'], true);
  1656. $website = Website::where('id', $wetbsite_id)->first();
  1657. if(empty($website)){
  1658. return Result::error("网站不存在",0);
  1659. }
  1660. // return Result::success($website);
  1661. $website_column = $website['website_column_arr_id'] ?? '[]';
  1662. $website_column = json_decode($website_column,true);
  1663. $categorys = $this->processArticlePro($wetbsite_id);
  1664. $cat_1st_arr = $categorys['cat_1st_arr'];
  1665. $catiall = $categorys['catiall'];
  1666. // return Result::success($catiall);
  1667. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1668. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1669. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1670. }
  1671. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1672. // return Result::success($categorys);
  1673. $parent_category = array_column($data, 'parent');
  1674. $parent_cat = [];
  1675. $child_category = array_column($data, 'child');
  1676. if (!empty($parent_category)) {
  1677. foreach ($parent_category as $key => $value) {
  1678. $arr = array_map('intval', explode(',', $value));
  1679. $parent_cat[$key] = $arr[0] ?? 0;
  1680. $parent_category = $arr[0] ?? 0;
  1681. $article_imgnum = $arr[1] ?? 0;
  1682. $article_textnum = $arr[2] ?? 0;
  1683. if ($parent_category != 0) {
  1684. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1685. // return Result::success($category_arr);
  1686. if ($article_imgnum != 0) {
  1687. $img_article = Article::whereIn('catid', $category_arr)
  1688. ->where('status', 1)
  1689. ->where('imgurl', '!=', '')
  1690. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1691. $query->from('article_ignore')
  1692. ->where('website_id', $wetbsite_id);
  1693. }, 'article_ignore', function ($join) {
  1694. $join->on('article_ignore.article_id', '=', 'article.id');
  1695. })
  1696. ->where(function ($query) use ($wetbsite_id) {
  1697. $query->whereNull('article_ignore.article_id')
  1698. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1699. })
  1700. ->select('article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at', 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id', 'article.catid')
  1701. ->orderBy('updated_at', 'desc')
  1702. ->limit($article_imgnum)
  1703. ->get()->all();
  1704. foreach ($img_article as $k => $v) {
  1705. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1706. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1707. }
  1708. } else {
  1709. $img_article = [];
  1710. }
  1711. if ($article_textnum != 0) {
  1712. $text_article = Article::whereIn('catid', $category_arr)
  1713. ->where('status', 1)
  1714. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1715. $query->from('article_ignore')
  1716. ->where('website_id', $wetbsite_id);
  1717. }, 'article_ignore', function ($join) {
  1718. $join->on('article_ignore.article_id', '=', 'article.id');
  1719. })
  1720. ->where(function ($query) use ($wetbsite_id) {
  1721. $query->whereNull('article_ignore.article_id')
  1722. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1723. })
  1724. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1725. ->orderBy('updated_at', 'desc')
  1726. ->limit($article_textnum)
  1727. ->get()->all();
  1728. foreach ($text_article as $k => $v) {
  1729. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1730. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1731. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1732. }
  1733. } else {
  1734. $text_article = [];
  1735. }
  1736. $catiall[$parent_category]['imgnum'] = $img_article;
  1737. $catiall[$parent_category]['textnum'] = $text_article;
  1738. $parent[$key] = $catiall[$parent_category];
  1739. } else {
  1740. $parent[$key] = '';
  1741. }
  1742. }
  1743. }
  1744. if (!empty($child_category)) {
  1745. foreach ($child_category as $key => $value) {
  1746. $arr = array_map('intval', explode(',', $value));
  1747. $parent_category = $parent_cat[$key];
  1748. $child_category = $arr[0] ?? 0;
  1749. $article_imgnum = $arr[1] ?? 0;
  1750. $article_textnum = $arr[2] ?? 0;
  1751. if ($child_category != 0) {
  1752. $all_childcat = $cat_1st_arr[$parent_category];
  1753. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1754. // 从 $websiteInfoIndexed 中获取对应的数据
  1755. $info = $websiteInfoIndexed[$v];
  1756. // 返回一个包含所需信息的数组
  1757. return [
  1758. 'alias' => $info->alias,
  1759. 'category_id' => $info->category_id,
  1760. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1761. 'pid' => $info->pid,
  1762. 'type' => $info->type,
  1763. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1764. 'pinyin' => $info->pinyin,
  1765. ];
  1766. }, $all_childcat);
  1767. if ($article_imgnum != 0) {
  1768. $img_article = Article::where('catid', $child_category)
  1769. ->where('status', 1)
  1770. ->where('imgurl', '!=', '')
  1771. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1772. $query->from('article_ignore')
  1773. ->where('website_id', $wetbsite_id);
  1774. }, 'article_ignore', function ($join) {
  1775. $join->on('article_ignore.article_id', '=', 'article.id');
  1776. })
  1777. ->where(function ($query) use ($wetbsite_id) {
  1778. $query->whereNull('article_ignore.article_id')
  1779. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1780. })
  1781. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1782. ->orderBy('updated_at', 'desc')
  1783. ->limit($article_imgnum)
  1784. ->get()->all();
  1785. foreach ($img_article as $k => $v) {
  1786. // var_dump($v);
  1787. // var_dump($k);
  1788. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1789. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1790. }
  1791. } else {
  1792. $img_article = [];
  1793. }
  1794. if ($article_textnum != 0) {
  1795. $text_article = Article::where('catid', $child_category)
  1796. ->where('status', 1)
  1797. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1798. $query->from('article_ignore')
  1799. ->where('website_id', $wetbsite_id);
  1800. }, 'article_ignore', function ($join) {
  1801. $join->on('article_ignore.article_id', '=', 'article.id');
  1802. })
  1803. ->where(function ($query) use ($wetbsite_id) {
  1804. $query->whereNull('article_ignore.article_id')
  1805. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1806. })
  1807. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1808. ->orderBy('updated_at', 'desc')
  1809. ->limit($article_textnum)
  1810. ->get()->all();
  1811. foreach ($text_article as $k => $v) {
  1812. // var_dump($v);
  1813. // var_dump($k);
  1814. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1815. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1816. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1817. }
  1818. } else {
  1819. $text_article = [];
  1820. }
  1821. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1822. $catiall[$child_category]['imgnum'] = $img_article;
  1823. $catiall[$child_category]['textnum'] = $text_article;
  1824. $child[$key] = $catiall[$child_category];
  1825. // var_dump($pids);
  1826. } else {
  1827. $child[$key] = '';
  1828. }
  1829. }
  1830. }
  1831. foreach ($parent as $key => $value) {
  1832. $result[$key] = $value;
  1833. if (!empty($child[$key])) {
  1834. // var_dump($child[$key]);
  1835. $result[$key]['child'] = $child[$key];
  1836. // $value[$key]['child'] = $child[$key];
  1837. } else {
  1838. $result[$key]['child'] = [
  1839. "alias" => null,
  1840. "category_id" => null,
  1841. "type" => null,
  1842. "pinyin" => null,
  1843. "all_childcat" => [],
  1844. "imgnum" => [],
  1845. "textnum" => []
  1846. ];
  1847. }
  1848. }
  1849. return Result::success($result);
  1850. }
  1851. /**
  1852. * 辅助方法:获取文章列表
  1853. */
  1854. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1855. {
  1856. sleep(1);
  1857. $query = Article::where('article.status', 1)
  1858. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1859. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1860. ->where(function ($query) use ($website) {
  1861. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1862. })
  1863. ->leftJoin('website_category', function ($join) use ($website) {
  1864. $join->on('article.catid', '=', 'website_category.category_id')
  1865. ->where('website_category.website_id', '=', $website['website_id']);
  1866. })
  1867. ->select(
  1868. 'article.id',
  1869. 'article.title',
  1870. 'article.imgurl',
  1871. 'article.author',
  1872. 'article.updated_at',
  1873. 'article.introduce',
  1874. 'article.islink',
  1875. 'article.linkurl',
  1876. 'article.copyfrom',
  1877. 'article.cat_arr_id',
  1878. 'article.catid',
  1879. 'website_category.alias as category_name'
  1880. )
  1881. ->orderBy('updated_at', 'desc')
  1882. ->limit($limit);
  1883. // 如果是图片文章,添加图片URL条件
  1884. if ($isImageArticle) {
  1885. $query->where('imgurl', '!=', '');
  1886. } else {
  1887. // 文字文章不需要imgurl字段
  1888. $query->addSelect('article.introduce');
  1889. }
  1890. $articles = $query->get();
  1891. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1892. }
  1893. /**
  1894. * 乡村网-获取特殊新闻模块
  1895. * @param array $data
  1896. * @return array
  1897. */
  1898. public function getWebsiteArticles(array $data): array
  1899. {
  1900. $website_id = $data['website_id'];
  1901. $website = Website::where('id', $website_id)->first();
  1902. if(empty($website)){
  1903. return Result::error("网站不存在",0);
  1904. }
  1905. // return Result::success($website);
  1906. $website_column = $website['website_column_arr_id'] ?? '[]';
  1907. $website_column = json_decode($website_column, true);
  1908. $catids = json_decode($data['id'], true);
  1909. $parent_category = array_column($catids, 'parent');
  1910. if(!empty($parent_category) && is_array($parent_category)) {
  1911. $categorys = $this->processArticlePro($website_id);
  1912. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1913. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1914. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1915. }
  1916. $catiall = $categorys['catiall'];
  1917. $cat_1st_arr = $categorys['cat_1st_arr'];
  1918. // return Result::success($categorys);
  1919. foreach ($parent_category as $key => $value) {
  1920. $arr = array_map('intval', explode(',', $value));
  1921. $parent_category = $arr[0] ?? 0;
  1922. $article_imgnum = $arr[1] ?? 0;
  1923. $article_textnum = $arr[2] ?? 0;
  1924. if ($parent_category != 0) {
  1925. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1926. // return Result::success($category_arr);
  1927. if ($article_imgnum != 0) {
  1928. $img_article = Article::whereIn('catid', $category_arr)
  1929. ->where('status', 1)
  1930. ->where('imgurl', '!=', '')
  1931. ->leftJoinSub(function ($query) use ($website_id) {
  1932. $query->from('article_ignore')
  1933. ->where('website_id', $website_id);
  1934. }, 'article_ignore', function ($join) {
  1935. $join->on('article_ignore.article_id', '=', 'article.id');
  1936. })
  1937. ->where(function ($query) use ($website_id) {
  1938. $query->whereNull('article_ignore.article_id')
  1939. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1940. })
  1941. ->select(
  1942. 'id',
  1943. 'title',
  1944. 'imgurl',
  1945. 'author',
  1946. 'updated_at',
  1947. 'introduce',
  1948. 'islink',
  1949. 'linkurl',
  1950. 'copyfrom',
  1951. 'cat_arr_id',
  1952. 'catid as category_id'
  1953. )
  1954. ->orderBy('updated_at', 'desc')
  1955. ->limit($article_imgnum)
  1956. ->get()->all();
  1957. foreach ($img_article as $k => $v) {
  1958. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1959. // return Result::success($v);
  1960. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1961. }
  1962. } else {
  1963. $img_article = [];
  1964. }
  1965. if ($article_textnum != 0) {
  1966. $text_article = Article::whereIn('catid', $category_arr)
  1967. ->where('status', 1)
  1968. ->leftJoinSub(function ($query) use ($website_id) {
  1969. $query->from('article_ignore')
  1970. ->where('website_id', $website_id);
  1971. }, 'article_ignore', function ($join) {
  1972. $join->on('article_ignore.article_id', '=', 'article.id');
  1973. })
  1974. ->where(function ($query) use ($website_id) {
  1975. $query->whereNull('article_ignore.article_id')
  1976. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1977. })
  1978. ->select(
  1979. 'id',
  1980. 'title',
  1981. 'author',
  1982. 'updated_at',
  1983. 'introduce',
  1984. 'islink',
  1985. 'linkurl',
  1986. 'copyfrom',
  1987. 'cat_arr_id',
  1988. 'catid as category_id'
  1989. )
  1990. ->orderBy('updated_at', 'desc')
  1991. ->limit($article_textnum)
  1992. ->get()->all();
  1993. foreach ($text_article as $k => $v) {
  1994. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1995. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1996. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1997. }
  1998. } else {
  1999. $text_article = [];
  2000. }
  2001. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2002. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2003. $parent[$key] = $catiall[$parent_category];
  2004. } else {
  2005. $parent[$key] = [];
  2006. }
  2007. }
  2008. }
  2009. return Result::success($parent);
  2010. }
  2011. // 封装处理商品的路由问题
  2012. function processGoods($goods, $data)
  2013. {
  2014. return $goods->map(function ($good) use ($data) {
  2015. $catid = $good->catid ?? 0;
  2016. // $pinyin = '';
  2017. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2018. if (!empty($category->pid) && $category->pid != 0) {
  2019. $level = json_decode($category->category_arr_id, true);
  2020. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2021. ->whereIn('category_id', $level)
  2022. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2023. ->get(['aLIas_pinyin'])
  2024. ->pluck('aLIas_pinyin')
  2025. ->implode('/');
  2026. } else {
  2027. $pinyin = $category->aLIas_pinyin ?? '';
  2028. }
  2029. if (isset($good->city_id) && !empty($good->city_id)) {
  2030. $city = District::where('id', $good->city_id)->first(['name']);
  2031. $good->city_name = $city->name ?? '';
  2032. }
  2033. // 解析imgurl JSON并取第一条数据
  2034. $imgUrls = json_decode($good->imgurl, true);
  2035. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2036. $good->pinyin = $pinyin;
  2037. return $good;
  2038. });
  2039. }
  2040. /**
  2041. * 获取商城首页-根据栏目id
  2042. * @param array $data
  2043. * @return array
  2044. * */
  2045. function getWebsiteCatidshop(array $data): array
  2046. {
  2047. $input['catid'] = $data['catid'];
  2048. $input['website_id'] = $data['website_id'];
  2049. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2050. $result = array_map(function ($item) use ($input) {
  2051. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2052. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2053. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2054. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2055. if (empty($category) || $category->type != 2) {
  2056. return Result::error("暂无此栏目", 0);
  2057. } else {
  2058. $website['website_id'] = $input['website_id'];
  2059. $goods = Good::where('good.status', 2)
  2060. ->where('good.website_id', $website['website_id'])
  2061. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2062. ->select(
  2063. 'good.id',
  2064. 'good.name',
  2065. 'good.imgurl',
  2066. 'good.description',
  2067. 'good.updated_at',
  2068. 'good.catid',
  2069. 'good.type_id',
  2070. 'good.price',
  2071. 'good.com',
  2072. 'good.level',
  2073. 'good.unit'
  2074. )
  2075. ->orderBy('updated_at', 'desc')
  2076. ->offset($goodStart)
  2077. ->limit($goodNum);
  2078. $all_goods = $goods->get();
  2079. $all_goods = $this->processGoods($all_goods, $website);
  2080. }
  2081. return $all_goods ?? [];
  2082. }
  2083. }, $data);
  2084. return Result::success($result);
  2085. }
  2086. /**
  2087. * 获取商品模块
  2088. * @param array $data
  2089. * @return array
  2090. * */
  2091. public function getWebsiteshop(array $data): array
  2092. {
  2093. $input['id'] = $data['id'];
  2094. $input['website_id'] = $data['website_id'];
  2095. $catid = $data['catid'];
  2096. $data = json_decode($input['id'] ?? '', true) ?? [];
  2097. $result['goods'] = array_map(function ($item) use ($input) {
  2098. // 检查parent元素是否存在且不是undefined
  2099. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2100. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2101. $website = $input['website_id'];
  2102. $query = Good::where('good.status', 2)
  2103. ->where('good.website_id', $website);
  2104. switch ($Levelid) {
  2105. case 1:
  2106. case 2:
  2107. case 3:
  2108. $goods = $query->where(function ($q) use ($Levelid) {
  2109. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2110. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2111. });
  2112. break;
  2113. case 4:
  2114. $goods = $query;
  2115. break;
  2116. case 5:
  2117. $goods = $query->where('type_id', 1);
  2118. break;
  2119. case 6:
  2120. $goods = $query->where('type_id', 2);
  2121. break;
  2122. default:
  2123. return [];
  2124. }
  2125. $all_goods = $goods
  2126. ->select(
  2127. 'good.id',
  2128. 'good.name',
  2129. 'good.imgurl',
  2130. 'good.description',
  2131. 'good.updated_at',
  2132. 'good.catid',
  2133. 'good.type_id',
  2134. 'good.price',
  2135. 'good.level',
  2136. 'good.website_id'
  2137. )
  2138. ->orderBy('updated_at', 'desc')
  2139. ->offset($goodStart)
  2140. ->limit($goodNum)
  2141. ->get();
  2142. $web['website_id'] = $website;
  2143. $all_goods = $this->processGoods($all_goods, $web);
  2144. }
  2145. return $all_goods;
  2146. }, $data);
  2147. $website = $input['website_id'];
  2148. $result['article'] = Article::where(function ($query) use ($website) {
  2149. $query->where(function ($subQuery) use ($website) {
  2150. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2151. })->orWhereNull("ignore_ids");
  2152. })
  2153. ->where('catid', $catid)
  2154. ->where('article.status', 1)
  2155. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2156. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2157. ->orderBy('article.updated_at', 'desc')
  2158. ->first();
  2159. return Result::success($result);
  2160. }
  2161. /**
  2162. * 获取商品分类
  2163. * @param array $data
  2164. * @return array
  2165. * */
  2166. public function getWebsiteshopCat(array $data): array
  2167. {
  2168. $website = $data['website_id'];
  2169. $category = WebsiteCategory::where('website_id', $website)
  2170. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2171. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2172. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2173. ->orderBy('sort')
  2174. ->get();
  2175. $cat = $category->map(function ($item) use ($website) {
  2176. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2177. $pid = $item->pid ?? 0;
  2178. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2179. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2180. ->where('website_id', $website)
  2181. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2182. ->get(['aLIas_pinyin'])
  2183. ->pluck('aLIas_pinyin')
  2184. ->implode('/');
  2185. } else {
  2186. $pinyin = $item->aLIas_pinyin ?? '';
  2187. }
  2188. $item->pinyin = $pinyin;
  2189. });
  2190. if (empty($category)) {
  2191. return Result::error("栏目查询失败", 0);
  2192. }
  2193. $cat_tree = Result::buildMenuTree($category);
  2194. $web['website_id'] = $website;
  2195. $goods = Good::where('website_id', $website)
  2196. ->where('status', 2)
  2197. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2198. ->latest('updated_at')
  2199. ->offset(($data['page'] - 1) * $data['pageSize'])
  2200. ->limit($data['pageSize'])
  2201. ->get();
  2202. if (!empty($goods)) {
  2203. if ($goods->count() > 1 && !empty($goods)) {
  2204. $goods = $this->processGoods($goods, $web);
  2205. }
  2206. } else {
  2207. $goods = [];
  2208. }
  2209. $result = [
  2210. 'category' => $cat_tree,
  2211. 'goods' => $goods,
  2212. ];
  2213. // $resul['goods'] = $goods;
  2214. if (empty($result)) {
  2215. return Result::error("查询失败", 0);
  2216. }
  2217. return Result::success($result);
  2218. }
  2219. /*
  2220. * 获取商品列表
  2221. * @param array $data
  2222. * @return array
  2223. * */
  2224. public function getWebsiteshopList(array $data): array
  2225. {
  2226. // return Result::success($data);
  2227. $where = [
  2228. 'status' => 2,
  2229. 'website_id' => $data['website_id'],
  2230. ];
  2231. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2232. // return Result::error("查询失败", 0);
  2233. // }
  2234. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2235. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2236. $data['catid'] = $category->category_id ?? 0;
  2237. }
  2238. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2239. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2240. }
  2241. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2242. array_push($where, ['type_id', $data['type_id']]);
  2243. }
  2244. $query = Good::where($where)
  2245. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2246. $query->where(function ($q) use ($data) {
  2247. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2248. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2249. });
  2250. })
  2251. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2252. $query->where(function ($q) use ($data) {
  2253. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2254. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2255. });
  2256. })
  2257. ->select(
  2258. 'good.id',
  2259. 'good.name',
  2260. 'good.imgurl',
  2261. 'good.description',
  2262. 'good.updated_at',
  2263. 'good.com',
  2264. 'good.catid',
  2265. 'good.type_id',
  2266. 'good.website_id',
  2267. 'good.cat_arr_id',
  2268. 'good.created_at',
  2269. 'good.city_id'
  2270. )
  2271. ->latest('updated_at');
  2272. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2273. $result['count'] = $query->clone()->count();
  2274. $result['goods'] = $this->processGoods(
  2275. $query->clone()
  2276. ->offset(($data['page'] - 1) * $data['pageSize'])
  2277. ->limit($data['pageSize'])
  2278. ->get(),
  2279. $data
  2280. );
  2281. } else {
  2282. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2283. // 获取 type_id 为 1 的数据
  2284. $result['type1'] = $this->processGoods(
  2285. $query->clone()
  2286. ->where('type_id', 1)
  2287. ->offset(($data['page'] - 1) * $data['pageSize'])
  2288. ->limit($data['pageSize'])
  2289. ->get(),
  2290. $data
  2291. );
  2292. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2293. // 获取 type_id 为 2 的数据
  2294. $result['type2'] = $this->processGoods(
  2295. $query->clone()
  2296. ->where('type_id', 2)
  2297. ->offset(($data['page'] - 1) * $data['pageSize'])
  2298. ->limit($data['pageSize'])
  2299. ->get(),
  2300. $data
  2301. );
  2302. }
  2303. if (empty($result)) {
  2304. return Result::error("查询失败", 0);
  2305. }
  2306. return Result::success($result);
  2307. }
  2308. /**
  2309. * 获取商品详情
  2310. * @param array $data
  2311. * @return array
  2312. * */
  2313. public function getWebsiteshopInfo(array $data): array
  2314. {
  2315. $where = [
  2316. 'good.status' => 2,
  2317. 'good.website_id' => $data['website_id'],
  2318. 'good.id' => $data['id'],
  2319. ];
  2320. $goods = Good::where($where)
  2321. ->where('good.id', $data['id'])
  2322. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2323. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2324. ->first();
  2325. if (empty($goods)) {
  2326. return Result::error("查询失败", 0);
  2327. }
  2328. $goods->imgurl = json_decode($goods->imgurl, true);
  2329. return Result::success($goods);
  2330. }
  2331. /**
  2332. * plus pro 处理文章路由问题
  2333. */
  2334. function processArticlePro($website_id)
  2335. {
  2336. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2337. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2338. // // 取出category_id 对应的aLIas_pinyin
  2339. // $categoryIds = array_column($categorys, 'category_id');
  2340. // $categoryPIds = array_column($categorys, 'pid');
  2341. // $aliasPinyins = array_column($categorys, 'path');
  2342. // $alias = array_column($categorys, 'alias');
  2343. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2344. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2345. // // return Result::success($cat_arr);
  2346. // // $catiall = [];
  2347. // //一级所有子级的记录
  2348. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2349. // return [
  2350. // 'cat_1st_arr' => $cat_alias_arr,
  2351. // 'catiall' => $cat_arr,
  2352. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2353. // 'categoryIds' => $categoryIds,
  2354. // ];
  2355. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2356. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2357. // 取出category_id 对应的aLIas_pinyin
  2358. $categoryIds = array_column($categorys, 'category_id');
  2359. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function($pid) {
  2360. return $pid != 0;
  2361. })));
  2362. $category_path = array_column($categorys, 'path');
  2363. $cat_arr = array_combine($categoryIds, $category_path);
  2364. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2365. $catiall = [];
  2366. //一级所有子级的记录
  2367. $cat_1st_arr = [];
  2368. foreach ($categorys as $key => $value) {
  2369. // $category_arr_id = json_decode($value->category_arr_id);
  2370. // $pinyin_str = '';
  2371. // // 算出一级 并且算出子级
  2372. if ($value->pid != 0 && in_array($value->pid,$categoryIds)) {
  2373. $cat_1st_arr[$value->pid][] = $value->category_id;
  2374. }
  2375. // foreach ($category_arr_id as $k => $v) {
  2376. // $pinyin_str .= $cat_arr[$v] . '/';
  2377. // }
  2378. // $pinyin_str = rtrim($pinyin_str, '/');
  2379. $catiall[$value->category_id]['alias'] = $value->alias;
  2380. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2381. $catiall[$value->category_id]['type'] = $value->type;
  2382. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2383. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2384. }
  2385. return [
  2386. 'cat_1st_arr' => $cat_1st_arr,
  2387. 'catiall' => $catiall,
  2388. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2389. 'categoryIds' => $categoryIds,
  2390. 'diff_pid_categoryIds' => array_diff($categoryPIds,$categoryIds),
  2391. 'categoryPIds' => $categoryPIds,
  2392. ];
  2393. }
  2394. /**
  2395. * 封装处理文章的路由问题
  2396. * */
  2397. function processArticles($articles, $data)
  2398. {
  2399. // 检查 $articles 是否为数组或可迭代对象
  2400. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2401. return $articles->map(function ($article) use ($data) {
  2402. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2403. $catid = $article->cat_arr_id ?? '';
  2404. }
  2405. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2406. $catid = $article->category_arr_id ?? '';
  2407. }
  2408. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2409. $level = json_decode($catid, true);
  2410. if (!is_array($level)) {
  2411. return $article;
  2412. } else {
  2413. $level = array_map('intval', $level);
  2414. }
  2415. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2416. ->where($data)
  2417. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2418. ->pluck('aLIas_pinyin')
  2419. ->implode('/');
  2420. $article->pinyin = $pinyin ?? '';
  2421. return $article;
  2422. });
  2423. } else {
  2424. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2425. $catid = $articles->cat_arr_id ?? '';
  2426. $level = json_decode($catid, true);
  2427. if (!is_array($level)) {
  2428. return $articles;
  2429. } else {
  2430. $level = array_map('intval', $level);
  2431. }
  2432. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2433. ->where($data)
  2434. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2435. ->pluck('aLIas_pinyin')
  2436. ->implode('/');
  2437. $articles->pinyin = $pinyin ?? '';
  2438. return $articles;
  2439. }
  2440. }
  2441. // 封装处理由问题
  2442. function processJob($job, $data)
  2443. {
  2444. return $job->map(function ($job) use ($data) {
  2445. $category = $job->cat_arr_id ?? '';
  2446. $cityid = $job->city_arr_id ?? '';
  2447. $city = json_decode($cityid, true);
  2448. $pinyin = '';
  2449. $level = json_decode($category, true);
  2450. // 路由
  2451. if (!empty($level) && is_array($level)) {
  2452. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2453. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2454. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2455. ->get(['aLIas_pinyin'])
  2456. ->pluck('aLIas_pinyin')
  2457. ->implode('/');
  2458. if (empty($pinyin)) {
  2459. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2460. }
  2461. $job->pinyin = $pinyin;
  2462. }
  2463. // 取职位-城市 市??省
  2464. if (!empty($city) && is_array($city)) {
  2465. if (isset($city[1]) && !empty($city[1])) {
  2466. $city = District::where('id', $city[1])->first(['name']);
  2467. $job->city_name = $city->name ?? '';
  2468. } else if (isset($city[0]) && !empty($city[0])) {
  2469. $city = District::where('id', $city[0])->first(['name']);
  2470. $job->city_name = $city->name ?? '';
  2471. } else {
  2472. $job->city_name = '全国';
  2473. }
  2474. }
  2475. // 获取简历最后一级地区
  2476. if (isset($job->city_id) && !empty($job->city_id)) {
  2477. $city = District::where('id', $job->city_id)->first(['name']);
  2478. $job->hunt_cityname = $city->name ?? '';
  2479. }
  2480. // 组合详细地址
  2481. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2482. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2483. if (is_array($address_id) && !empty($address_id)) {
  2484. $address = District::whereIn('id', $address_id)
  2485. ->orderBy('level', 'asc')
  2486. ->get(['name'])
  2487. ->pluck('name')
  2488. ->implode('');
  2489. // $job->address_name = $address ?? '';
  2490. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2491. }
  2492. }
  2493. // 取行业
  2494. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2495. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2496. if (!empty($job->industry)) {
  2497. $query->where('hyid', $job->industry);
  2498. } else if (!empty($job->hy_id)) {
  2499. $query->where('hyid', $job->hy_id);
  2500. } else if (!empty($job->company_hy_id)) {
  2501. $query->where('hyid', $job->company_hy_id);
  2502. } else {
  2503. $query->where('hyid', $job->job_industry);
  2504. }
  2505. })->first(['hyname']);
  2506. $job->hy_name = $hy_name->hyname ?? '';
  2507. }
  2508. // 取职位类别
  2509. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2510. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2511. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2512. $job->zw_name = $zw_name->zwname ?? '';
  2513. }
  2514. // 取具体职位
  2515. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get)) || (isset($job->job_name) && !empty($job->job_name))) {
  2516. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2517. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2518. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2519. }
  2520. // 取工作经验
  2521. if (isset($job->experience) && !empty($job->experience)) {
  2522. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2523. $job->experience_name = $experience->ename ?? '';
  2524. }
  2525. // 取学历
  2526. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2527. $education = $job->educational ?? $job->school_education;
  2528. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2529. $job->education_name = $education->ename ?? '';
  2530. }
  2531. // 语言
  2532. if (isset($job->language) && !empty($job->language)) {
  2533. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2534. $job->language_name = $language->ename ?? '';
  2535. }
  2536. // 薪资
  2537. if (isset($job->salary) && !empty($job->salary)) {
  2538. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2539. $job->salary_name = $salary->ename ?? '';
  2540. }
  2541. // 职位性质
  2542. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2543. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2544. $job->job_nature_name = $job_nature->ename ?? '';
  2545. }
  2546. // 公司规模
  2547. if (isset($job->company_size) && !empty($job->company_size)) {
  2548. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2549. $job->company_size_name = $company_size->ename ?? '';
  2550. }
  2551. // 公司性质
  2552. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2553. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2554. $job->company_nature_name = $company_nature->nature_name ?? '';
  2555. }
  2556. // $job->pinyin = $pinyin;
  2557. return $job;
  2558. });
  2559. }
  2560. /**
  2561. * 获取书籍模块
  2562. * @param array $data
  2563. * @return array
  2564. * */
  2565. public function getWebsiteBook(array $data): array
  2566. {
  2567. $input['id'] = $data['id'];
  2568. $input['website_id'] = $data['website_id'];
  2569. // 将 JSON 字符串转换为 PHP 数组
  2570. $data = json_decode($input['id'], true);
  2571. // 使用 array_map 处理每个元素
  2572. $result = array_map(function ($item) use ($input) {
  2573. // 检查parent元素是否存在且不是undefined
  2574. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2575. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2576. $website = [
  2577. 'website_id' => $input['website_id'],
  2578. ];
  2579. // 查询栏目名称
  2580. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2581. if (empty($category)) {
  2582. $parent_alias = '';
  2583. $parent_pinyin = null;
  2584. $imgBooks = [];
  2585. $textBooks = [];
  2586. } else {
  2587. $parent_alias = $category->alias ?? '';
  2588. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2589. // 查找子分类ID数组
  2590. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2591. array_push($childCategoryIds, $parentCatId);
  2592. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2593. if ($parentImgNum != 0) {
  2594. // 查询图片新闻
  2595. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2596. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2597. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2598. })
  2599. ->where('book.status', 2)
  2600. ->where('book.img_url', '!=', '')
  2601. ->leftJoin('website_category', function ($join) use ($website) {
  2602. $join->on('book.cat_id', '=', 'website_category.category_id')
  2603. ->where('website_category.website_id', '=', $website['website_id']);
  2604. })
  2605. ->select(
  2606. 'book.id',
  2607. 'book.title',
  2608. 'book.img_url',
  2609. 'book.price',
  2610. 'book.market_price',
  2611. 'book.description',
  2612. 'book.cat_id',
  2613. 'book.description',
  2614. 'book.updated_at',
  2615. 'website_category.alias as category_name',
  2616. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2617. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2618. )
  2619. ->orderBy('updated_at', 'desc')
  2620. ->limit($parentImgNum)
  2621. ->get()->all();
  2622. // 查询文字新闻
  2623. }
  2624. if ($parentTextNum != 0) {
  2625. $textBooks = [];
  2626. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2627. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2628. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2629. })
  2630. ->where('book.status', 2)
  2631. ->leftJoin('website_category', function ($join) use ($website) {
  2632. $join->on('book.cat_id', '=', 'website_category.category_id')
  2633. ->where('website_category.website_id', '=', $website['website_id']);
  2634. })
  2635. ->select(
  2636. 'book.id',
  2637. 'book.title',
  2638. 'book.img_url',
  2639. 'book.price',
  2640. 'book.market_price',
  2641. 'book.description',
  2642. 'book.cat_id',
  2643. 'book.description',
  2644. 'book.updated_at',
  2645. 'website_category.alias as category_name',
  2646. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2647. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2648. )
  2649. ->orderBy('updated_at', 'desc')
  2650. ->limit($parentTextNum)
  2651. ->get()->all();
  2652. }
  2653. }
  2654. }
  2655. $resultItem = [
  2656. 'alias' => $parent_alias ?? '',
  2657. 'category_id' => $parentCatId ?? 0,
  2658. 'pinyin' => $parent_pinyin ?? null,
  2659. 'imgnum' => $imgBooks ?? [],
  2660. 'textnum' => $textBooks ?? [],
  2661. ];
  2662. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2663. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2664. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2665. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2666. ->get()->all();
  2667. if (!empty($childCategory)) {
  2668. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2669. // 查询子栏目名称
  2670. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2671. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2672. ->first();
  2673. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2674. $childImgArticles = [];
  2675. $childTextArticles = [];
  2676. $resultItem['child'] = [];
  2677. } else {
  2678. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2679. // 查询子栏目图片新闻
  2680. $childImgArticles = Book::where('cat_id', $childCatId)
  2681. ->where('status', 2)
  2682. ->where('img_url', '!=', '')
  2683. ->leftJoin('website_category', function ($join) use ($website) {
  2684. $join->on('book.cat_id', '=', 'website_category.category_id')
  2685. ->where('website_category.website_id', '=', $website['website_id']);
  2686. })
  2687. ->select(
  2688. 'book.id',
  2689. 'book.title',
  2690. 'book.img_url',
  2691. 'book.price',
  2692. 'book.market_price',
  2693. 'book.description',
  2694. 'book.cat_id',
  2695. 'book.description',
  2696. 'book.updated_at',
  2697. DB::raw("'$child_pinyin' as pinyin")
  2698. )
  2699. ->orderBy('updated_at', 'desc')
  2700. ->limit($childImgNum)
  2701. ->get()->all();
  2702. // 查询子栏目文字新闻
  2703. $childTextArticles = Book::where('cat_id', $childCatId)
  2704. ->where('status', 2)
  2705. ->leftJoin('website_category', function ($join) use ($website) {
  2706. $join->on('book.cat_id', '=', 'website_category.category_id')
  2707. ->where('website_category.website_id', '=', $website['website_id']);
  2708. })
  2709. ->select(
  2710. 'book.id',
  2711. 'book.title',
  2712. 'book.img_url',
  2713. 'book.price',
  2714. 'book.market_price',
  2715. 'book.description',
  2716. 'book.cat_id',
  2717. 'book.description',
  2718. 'book.updated_at',
  2719. DB::raw("'$child_pinyin' as pinyin")
  2720. )
  2721. ->orderBy('updated_at', 'desc')
  2722. ->limit($childTextNum)
  2723. ->get()->all();
  2724. $resultItem['child'] = [
  2725. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2726. 'category_id' => $childCatId,
  2727. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2728. 'all_childcat' => $childCategory,
  2729. 'imgnum' => $childImgArticles,
  2730. 'textnum' => $childTextArticles,
  2731. ];
  2732. }
  2733. }
  2734. } else {
  2735. $resultItem['child'] = [];
  2736. }
  2737. return $resultItem;
  2738. }, $data);
  2739. return Result::success($result);
  2740. }
  2741. /**
  2742. * 获取书刊列表
  2743. * @param array $data
  2744. * @return array
  2745. * */
  2746. public function getWebsiteBookList(array $data): array
  2747. {
  2748. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2749. if (empty($web)) {
  2750. return Result::error("查询失败", 0);
  2751. }
  2752. $catid = $data['id'];
  2753. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2754. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2755. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2756. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2757. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2758. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2759. ->where('pid', $category['pid'])
  2760. ->select(
  2761. 'category_id',
  2762. 'alias',
  2763. 'aLIas_pinyin',
  2764. 'pid',
  2765. 'sort',
  2766. 'is_url',
  2767. 'web_url',
  2768. 'seo_title',
  2769. 'seo_keywords',
  2770. 'seo_description',
  2771. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2772. )
  2773. ->orderBy('sort')
  2774. ->get()->all();
  2775. if (empty($category)) {
  2776. return Result::error("查询失败", 0);
  2777. }
  2778. $query = Book::where('book.status', 2)
  2779. ->where('book.website_id', $data['website_id'])
  2780. ->where('book.cat_id', $catid)
  2781. ->select(
  2782. 'book.id',
  2783. 'book.title',
  2784. 'book.img_url',
  2785. 'book.description',
  2786. 'book.updated_at',
  2787. 'book.cat_id',
  2788. DB::raw("'$pinyin' as pinyin")
  2789. )
  2790. ->orderBy('book.updated_at', 'desc');
  2791. $count = $query->count();
  2792. $query = clone $query;
  2793. $Book = $query
  2794. ->limit($data['pageSize'])
  2795. ->offset(($data['page'] - 1) * $data['pageSize'])
  2796. ->get()->all();
  2797. $result = [
  2798. 'category' => $categorys,
  2799. 'books' => $Book,
  2800. 'count' => $count,
  2801. ];
  2802. // if(empty($result)){
  2803. // return Result::error("查询失败", 0);
  2804. // }
  2805. return Result::success($result);
  2806. }
  2807. /**
  2808. * 获取书刊详情
  2809. * @param array $data
  2810. * @return array
  2811. * */
  2812. public function getWebsiteBookInfo(array $data): array
  2813. {
  2814. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2815. if (empty($web)) {
  2816. return Result::error("查询失败", 0);
  2817. }
  2818. $book = Book::where('status', 2)
  2819. ->where('website_id', $data['website_id'])
  2820. ->where('id', $data['id'])
  2821. ->select(
  2822. 'book.*',
  2823. )
  2824. ->orderBy('updated_at', 'desc')
  2825. ->first();
  2826. if (empty($book)) {
  2827. return Result::error("查询失败", 0);
  2828. }
  2829. // 先查询当前分类的 pid
  2830. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2831. ->where('category_id', $book['cat_id'])
  2832. ->first(['pid', 'category_id']);
  2833. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2834. if (!empty($carpid)) {
  2835. if ($carpid->pid != 0) {
  2836. $pid = $carpid['pid'];
  2837. // $parent_pinyin = '';
  2838. } else {
  2839. $pid = $carpid['category_id'];
  2840. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2841. }
  2842. }
  2843. $categorys = $query->where('pid', $pid)
  2844. ->select(
  2845. 'category_id',
  2846. 'alias',
  2847. 'aLIas_pinyin',
  2848. 'pid',
  2849. 'sort',
  2850. 'is_url',
  2851. 'web_url',
  2852. 'category_arr_id as cat_arr_id',
  2853. )
  2854. ->orderBy('sort')
  2855. ->get();
  2856. $category = $this->processArticle($categorys, $data);
  2857. $result = [
  2858. 'category' => $category,
  2859. 'books' => $book,
  2860. ];
  2861. return Result::success($result);
  2862. }
  2863. /**
  2864. * 尝试
  2865. * @param array $data
  2866. * @return array
  2867. * */
  2868. public function test(array $data): array
  2869. {
  2870. $input['id'] = $data['id'];
  2871. $input['website_id'] = $data['website_id'];
  2872. // 将 JSON 字符串转换为 PHP 数组
  2873. $data = json_decode($input['id'], true);
  2874. $result = [];
  2875. $article = $data;
  2876. $result = array_map(function ($item) use ($input) {
  2877. $website = [
  2878. 'website_id' => $input['website_id'],
  2879. ];
  2880. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2881. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2882. $parent = [
  2883. 0 => $category['category_id'] ?? [],
  2884. 1 => $parentImgNum ?? [],
  2885. 2 => $parentTextNum ?? [],
  2886. ];
  2887. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2888. $child = [];
  2889. $resultItem = [
  2890. // 'alias' => $parent_alias ?? '',
  2891. 'category_id' => $parentCatId ?? 0,
  2892. 'pinyin' => $parentImgNum ?? null,
  2893. 'imgnum' => $parentTextNum ?? [],
  2894. // 'textnum' => $textArticles ?? [],
  2895. ];
  2896. return $parent;
  2897. }, $data);
  2898. return Result::success($result);
  2899. // });
  2900. }
  2901. /**
  2902. * 封装处理文章的路由问题
  2903. * */
  2904. function processArticle($article, $data)
  2905. {
  2906. return $article->map(function ($article) use ($data) {
  2907. $catid = $article->cat_arr_id ?? '';
  2908. $level = json_decode($catid, true);
  2909. $pinyin = '';
  2910. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2911. if (!empty($level) && is_array($level)) {
  2912. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2913. ->where('website_id', $data['website_id'])
  2914. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2915. ->get(['aLIas_pinyin'])
  2916. ->pluck('aLIas_pinyin')
  2917. ->implode('/');
  2918. } else {
  2919. $pinyin = '';
  2920. }
  2921. $article->pinyin = $pinyin;
  2922. return $article;
  2923. });
  2924. }
  2925. /**
  2926. * c端-获取招工招聘下拉选框
  2927. * @param array $data
  2928. * @return array
  2929. * */
  2930. public function getWebsiteJobSelect(array $data): array
  2931. {
  2932. $web = Website::where('id', $data['website_id'])->first();
  2933. if (empty($web)) {
  2934. return Result::error("该网站不存在", 0);
  2935. }
  2936. $hy = JobIndustry::get()->all();
  2937. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2938. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2939. $result = [
  2940. 'hy' => $hy,
  2941. 'zw' => $zw,
  2942. 'jtzw' => $jtzw,
  2943. ];
  2944. if (empty($result)) {
  2945. return Result::error("查询失败", 0);
  2946. }
  2947. return Result::success($result);
  2948. }
  2949. /**
  2950. * c端-获取招工招聘
  2951. * @param array $data
  2952. * @return array
  2953. * */
  2954. public function getWebsiteJob(array $data): array
  2955. {
  2956. $web = Website::where('id', $data['website_id'])->first();
  2957. if (empty($web)) {
  2958. return Result::error("该网站不存在", 0);
  2959. }
  2960. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2961. ->where('job_hunting.website_id', $data['website_id'])
  2962. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2963. $query->where(function ($q) use ($data) {
  2964. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2965. });
  2966. })
  2967. ->select(
  2968. 'job_hunting.id',
  2969. 'job_hunting.cat_arr_id',
  2970. 'job_hunting.job_name_get',
  2971. 'job_hunting.industry',
  2972. 'job_hunting.name',
  2973. 'job_hunting.sexy',
  2974. 'job_hunting.origin',
  2975. 'job_hunting.city_arr_id',
  2976. 'job_hunting.experience',
  2977. 'job_hunting.updated_at',
  2978. 'job_hunting.salary'
  2979. )
  2980. ->orderBy('updated_at', 'desc')
  2981. ->limit($data['job1_num'])
  2982. ->get();
  2983. $web['website_id'] = $data['website_id'];
  2984. if (empty($job_hunting)) {
  2985. $job_huntings = "未查询到相关简历信息";
  2986. } else {
  2987. $job_huntings = $this->processJob($job_hunting, $web);
  2988. }
  2989. // 0:待审核 1:已通过 2:已拒绝
  2990. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2991. ->where('job_recruiting.website_id', $data['website_id'])
  2992. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2993. $query->where(function ($q) use ($data) {
  2994. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2995. });
  2996. })
  2997. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2998. ->select(
  2999. 'job_recruiting.id',
  3000. 'job_recruiting.cat_arr_id',
  3001. 'job_recruiting.title',
  3002. 'job_recruiting.jtzw_id',
  3003. 'job_recruiting.hy_id',
  3004. 'job_recruiting.city_arr_id',
  3005. 'job_recruiting.due_data',
  3006. 'job_recruiting.updated_at',
  3007. 'job_recruiting.experience',
  3008. 'job_recruiting.educational',
  3009. 'job_recruiting.salary',
  3010. 'job_recruiting.zw_id',
  3011. 'job_company.business_name'
  3012. )
  3013. ->orderBy('updated_at', 'desc')
  3014. ->limit($data['job2_num'])
  3015. ->get();
  3016. if (empty($job_recruiting->toArray())) {
  3017. $job_recruitings = "未查询到相关职位信息";
  3018. } else {
  3019. $job_recruitings = $this->processJob($job_recruiting, $web);
  3020. }
  3021. $result = [
  3022. 'job_hunting' => $job_huntings,
  3023. 'job_recuiting' => $job_recruitings,
  3024. ];
  3025. return Result::success($result);
  3026. }
  3027. /**
  3028. * c端-获取招工招聘列表
  3029. * @param array $data
  3030. * @return array
  3031. * */
  3032. public function getWebsiteJobList(array $data): array
  3033. {
  3034. $recruit_where = [];
  3035. $hunt_where = [];
  3036. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3037. if (empty($web)) {
  3038. return Result::error("此网站不存在", 0);
  3039. }
  3040. $website_id['website_id'] = $data['website_id'];
  3041. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3042. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3043. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3044. }
  3045. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3046. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3047. }
  3048. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3049. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3050. }
  3051. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3052. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3053. }
  3054. $query = JobRecruiting::where('job_recruiting.status', 1)
  3055. ->where('job_recruiting.website_id', $data['website_id'])
  3056. ->where($recruit_where)
  3057. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3058. $query->where(function ($q) use ($data) {
  3059. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3060. });
  3061. })
  3062. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3063. $query->where(function ($q) use ($data) {
  3064. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3065. });
  3066. })
  3067. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3068. ->select(
  3069. 'job_recruiting.id',
  3070. 'job_recruiting.hy_id',
  3071. 'job_recruiting.title',
  3072. 'job_recruiting.zw_id',
  3073. 'job_recruiting.educational',
  3074. 'job_recruiting.jtzw_id',
  3075. 'job_recruiting.city_arr_id',
  3076. 'job_recruiting.due_data',
  3077. 'job_recruiting.experience',
  3078. 'job_recruiting.cat_arr_id',
  3079. 'job_recruiting.updated_at',
  3080. 'job_company.business_name'
  3081. )
  3082. ->orderBy('job_recruiting.updated_at', 'desc');
  3083. $recruit_count = $query->count();
  3084. $query = clone $query;
  3085. $JobRecruiting = $query
  3086. ->offset(($data['page'] - 1) * $data['pageSize'])
  3087. ->limit($data['pageSize'])
  3088. ->get();
  3089. if (empty($JobRecruiting)) {
  3090. $JobRecruiting = "暂无相关职位信息";
  3091. } else {
  3092. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3093. }
  3094. }
  3095. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3096. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3097. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3098. }
  3099. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3100. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3101. }
  3102. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3103. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3104. }
  3105. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3106. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3107. }
  3108. $query = JobHunting::where('job_hunting.status', 2)
  3109. ->where('job_hunting.website_id', $data['website_id'])
  3110. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3111. ->where($hunt_where)
  3112. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3113. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3114. // })
  3115. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3116. $query->where(function ($q) use ($data) {
  3117. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3118. });
  3119. })
  3120. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3121. $query->where(function ($q) use ($data) {
  3122. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3123. });
  3124. })
  3125. ->select(
  3126. 'job_hunting.id',
  3127. 'job_hunting.sexy',
  3128. 'job_hunting.experience',
  3129. 'job_hunting.origin',
  3130. 'job_hunting.industry',
  3131. 'job_hunting.name',
  3132. 'job_hunting.job',
  3133. 'job_hunting.job_name_get',
  3134. 'job_hunting.city_arr_id',
  3135. 'job_hunting.cat_arr_id',
  3136. 'job_hunting.created_at',
  3137. 'job_hunting.updated_at',
  3138. 'job_position.zwname as job_name'
  3139. )
  3140. ->orderBy('job_hunting.updated_at', 'desc');
  3141. $hunt_count = $query->count();
  3142. $query = clone $query;
  3143. $JobHunting = $query
  3144. ->offset(($data['page'] - 1) * $data['pageSize'])
  3145. ->limit($data['pageSize'])
  3146. ->get();
  3147. if (empty($JobHunting)) {
  3148. $JobRecruiting = "暂无相关简历信息";
  3149. } else {
  3150. $JobHunting = $this->processJob($JobHunting, $website_id);
  3151. }
  3152. }
  3153. $result = [
  3154. 'JobRecruiting' => $JobRecruiting ?? [],
  3155. 'recruit_count' => $recruit_count ?? 0,
  3156. 'JobHunting' => $JobHunting ?? [],
  3157. 'hunt_count' => $hunt_count ?? 0,
  3158. ];
  3159. return Result::success($result);
  3160. }
  3161. /**
  3162. * c端-获取招工招聘详情
  3163. * @param array $data
  3164. * @return array
  3165. * */
  3166. public function getWebsiteJobInfo(array $data): array
  3167. {
  3168. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3169. if (empty($web)) {
  3170. return Result::error("该网站不存在", 0);
  3171. }
  3172. $webid = [
  3173. 'website_id' => $data['website_id'],
  3174. ];
  3175. // 职位相关信息
  3176. if ($data['type'] == 1) {
  3177. $query = JobRecruiting::where('status', 1)
  3178. ->where('website_id', $data['website_id'])
  3179. ->select('*');
  3180. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3181. $company = JobCompany::where('job_id', $data['id'])->select('id', 'business_name', 'company_hy_id', 'company_size', 'company_nature', 'address_arr_id', 'address', 'job_company.email')->get();
  3182. if (!empty($company)) {
  3183. $result['company'] = $this->processJob($company, $webid);
  3184. }
  3185. $other_job = JobRecruiting::where('status', 1)
  3186. ->where('website_id', $data['website_id'])
  3187. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3188. ->where('id', '!=', $data['id'])
  3189. ->where('user_id', '=', $job[0]['user_id'])
  3190. ->limit($data['pageSize'])
  3191. ->get();
  3192. if (!empty($other_job)) {
  3193. $result['other_job'] = $this->processJob($other_job, $webid);
  3194. }
  3195. } else {
  3196. // 简历相关信息
  3197. $job = JobHunting::where('job_hunting.status', 2)
  3198. ->where('job_hunting.website_id', $data['website_id'])
  3199. ->where('job_hunting.id', $data['id'])
  3200. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3201. ->select('job_hunting.*', 'user_name')
  3202. ->get();
  3203. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3204. if (!empty($resume->toArray())) {
  3205. $result['resume'] = 1;
  3206. } else {
  3207. $result['resume'] = 0;
  3208. }
  3209. }
  3210. if (empty($job->toArray())) {
  3211. return Result::error("id参数错误", 0);
  3212. }
  3213. if (!empty($job[0]['job_experience'])) {
  3214. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3215. if (!empty($job_experience)) {
  3216. // $hy = [];
  3217. foreach ($job_experience as $key => $value) {
  3218. // $id = $value['id'];
  3219. $hy[$key] = $value['job_industry'];
  3220. $zw_id[$key] = $value['job_typename'];
  3221. $jtzw_id[$key] = $value['job_name'];
  3222. }
  3223. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3224. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3225. // 先将关联表转换为索引数组,提高查找效率
  3226. $hyLookup = [];
  3227. foreach ($hy_table as $item) {
  3228. $hyLookup[$item['hyid']] = $item['hyname'];
  3229. }
  3230. $zwLookup = [];
  3231. foreach ($zw_table as $item) {
  3232. $zwLookup[$item['zwid']] = $item['zwname'];
  3233. }
  3234. foreach ($job_experience as $key => &$value) {
  3235. // 处理行业名称
  3236. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3237. $value['hy_name'] = $hyLookup[$hy[$key]];
  3238. }
  3239. // 处理职位名称
  3240. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3241. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3242. }
  3243. // 处理具体职位名称
  3244. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3245. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3246. }
  3247. }
  3248. // 释放引用,防止意外修改后续代码
  3249. unset($value);
  3250. }
  3251. $result['job_experience'] = $job_experience ?? [];
  3252. }
  3253. if (!empty($job[0]['education_experience'])) {
  3254. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3255. if (!empty($education_experience)) {
  3256. foreach ($education_experience as $key => $value) {
  3257. // $id = $value['id'];
  3258. $education[$key] = $value['school_education'];
  3259. }
  3260. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3261. // // 先将关联表转换为索引数组,提高查找效率
  3262. $educationLookup = [];
  3263. foreach ($education_table as $item) {
  3264. $educationLookup[$item['evalue']] = $item['ename'];
  3265. }
  3266. foreach ($education_experience as $key => &$value) {
  3267. // 处理学历名称
  3268. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3269. $value['education_name'] = $educationLookup[$education[$key]];
  3270. }
  3271. }
  3272. }
  3273. $result['education_experience'] = $job_experience ?? [];
  3274. }
  3275. $result['job'] = $this->processJob($job, $webid);
  3276. // // 返现对应的栏目
  3277. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3278. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3279. ->whereIn('category_id', $catid)
  3280. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3281. ->orderBy('pid')->get()->all();
  3282. if (!empty($category)) {
  3283. $result['category'] = $category;
  3284. }
  3285. $result['job'] = $job;
  3286. $result['job_experience'] = $job_experience ?? [];
  3287. $result['education_experience'] = $education_experience ?? [];
  3288. if (empty($result)) {
  3289. return Result::error("参数错误", 0);
  3290. }
  3291. return Result::success($result);
  3292. }
  3293. /**
  3294. * c端-申请职位
  3295. * @param array $data
  3296. * @return array
  3297. * */
  3298. public function getWebsiteJobApply(array $data): array
  3299. {
  3300. // 首先验证网站是否存在
  3301. // return Result::success($data);
  3302. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3303. if (empty($web)) {
  3304. return Result::error("该网站不存在", 0);
  3305. }
  3306. // 验证用户是否存在且为个人会员/管理员
  3307. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3308. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3309. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3310. return Result::error("用户不存在", 0);
  3311. }
  3312. // 去除重复元素和空元素,并保持原始顺序
  3313. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3314. return !empty($value);
  3315. }));
  3316. // 验证职位是否存在 1:审核通过
  3317. $recruiting = JobRecruiting::where('status', 1)
  3318. ->where('website_id', $data['website_id'])
  3319. ->whereIn('id', $data['recruit_id'])
  3320. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3321. if (empty($recruiting)) {
  3322. return Result::error("该职位不存在", 0);
  3323. }
  3324. // 简历是否存在
  3325. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3326. if (empty($hunt_id)) {
  3327. return Result::error("该简历不存在", 0);
  3328. }
  3329. $data['hunt_id'] = $hunt_id['hunt_id'];
  3330. // // 验证是否已投递过该职位
  3331. $apply = JobApply::where('user_id', $data['user_id'])
  3332. ->where('hunt_id', $data['hunt_id'])
  3333. ->where('website_id', $data['website_id'])
  3334. ->whereIn('recruit_id', $data['recruit_id'])
  3335. ->get(['recruit_id']);
  3336. if (!empty($apply->toArray())) {
  3337. return Result::error("您已投递过该职位!");
  3338. }
  3339. $insertData = array_map(function ($recruiting) use ($data) {
  3340. return [
  3341. 'user_id' => $data['user_id'],
  3342. 'hunt_id' => $data['hunt_id'],
  3343. 'website_id' => $data['website_id'],
  3344. 'recruit_id' => $recruiting['recruit_id'],
  3345. 'receiver_id' => $recruiting['receiver_id'],
  3346. 'status' => 1,
  3347. ];
  3348. }, $recruiting);
  3349. // 批量插入数据
  3350. $result = JobApply::insert($insertData);
  3351. if (empty($result)) {
  3352. return Result::error("投递失败", 0);
  3353. }
  3354. return Result::success($result);
  3355. }
  3356. /**
  3357. * 招工招聘-沟通简历
  3358. * @param array $data
  3359. * @return array
  3360. * */
  3361. public function getWebsiteJobResume(array $data): array
  3362. {
  3363. // 首先验证网站是否存在
  3364. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3365. if (empty($web)) {
  3366. return Result::error("该网站不存在", 0);
  3367. }
  3368. // return Result::success($data);
  3369. // 验证用户是否存在且为企业会员/管理员
  3370. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3371. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3372. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3373. return Result::error("用户不存在", 0);
  3374. }
  3375. // 去除重复元素和空元素,并保持原始顺序
  3376. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3377. return !empty($value);
  3378. }));
  3379. // 验证简历是否存在
  3380. $hunting = JobHunting::where('status', 2)
  3381. ->where('website_id', $data['website_id'])
  3382. ->whereIn('id', $data['hunt_id'])
  3383. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3384. if (empty($hunting)) {
  3385. return Result::error("该简历不存在", 0);
  3386. }
  3387. // 验证是否已沟通过该简历
  3388. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3389. ->where('recruit_id', $data['recruit_id'])
  3390. ->where('website_id', $data['website_id'])
  3391. ->whereIn('hunt_id', $data['hunt_id'])
  3392. ->get(['hunt_id']);
  3393. if (!empty($remuse->toArray())) {
  3394. return Result::error("您已沟通过该简历!");
  3395. }
  3396. // 准备要插入的数据数组
  3397. $insertData = array_map(function ($hunting) use ($data) {
  3398. return [
  3399. 'user_id' => $data['user_id'],
  3400. 'recruit_id' => $data['recruit_id'],
  3401. 'website_id' => $data['website_id'],
  3402. 'hunt_id' => $hunting['hunt_id'],
  3403. 'receiver_id' => $hunting['receiver_id'],
  3404. 'status' => 1,
  3405. ];
  3406. }, $hunting);
  3407. // 批量插入数据
  3408. $result = JobRemuse::insert($insertData);
  3409. if (empty($result)) {
  3410. return Result::error("沟通失败", 0);
  3411. }
  3412. return Result::success($result);
  3413. }
  3414. /**
  3415. * 招工招聘 -我的职位(企业会员)
  3416. * @param array $data
  3417. * @return array
  3418. */
  3419. public function getWebsiteJobRecruiting(array $data): array
  3420. {
  3421. $web = Website::where('id', $data['website_id'])->first('id');
  3422. if (empty($web)) {
  3423. return Result::error("该网站不存在", 0);
  3424. }
  3425. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3426. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3427. return Result::error("用户暂无权限!", 0);
  3428. }
  3429. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3430. $result = JobRecruiting::where('website_id', $data['website_id'])
  3431. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3432. $query->where('user_id', $user['id']);
  3433. })
  3434. ->where('status', 1)
  3435. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3436. ->orderBy('updated_at', 'desc')
  3437. ->limit($data['pageSize'])
  3438. ->get();
  3439. if (empty($result)) {
  3440. return Result::error("暂无相关职位信息", 0);
  3441. }
  3442. return Result::success($result);
  3443. }
  3444. /**
  3445. * c端 - 验证路由
  3446. * @param array $data
  3447. * @return array
  3448. */
  3449. /**
  3450. * c端 - 验证路由
  3451. * @param array $data
  3452. * @return array
  3453. */
  3454. public function checkWebsiteRoute(array $data): array
  3455. {
  3456. // 测试001111111222
  3457. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3458. if (empty($web)) {
  3459. return Result::error("该网站不存在", 0);
  3460. } elseif ($web['status'] != 1) {
  3461. return Result::error("网站已经关闭", 0);
  3462. }
  3463. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3464. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3465. // 验证路由是否存在
  3466. if (empty($whiteRouterInfo)) {
  3467. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3468. }
  3469. if (!empty($whiteRouterInfo)) {
  3470. return Result::success($whiteRouterInfo->toArray());
  3471. }
  3472. }
  3473. // 验证栏目路由
  3474. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3475. ->where('aLIas_pinyin', $data['last_route'])
  3476. ->get()->all();
  3477. if (count($last_category) == 0) {
  3478. return Result::error("该栏目不存在", 0);
  3479. }
  3480. if (count($last_category) > 1) {
  3481. return Result::error("该子级栏目存在多个,路由验证失败!", 0);
  3482. }
  3483. if (count($last_category) == 1) {
  3484. $last_category = $last_category[0];
  3485. }
  3486. // return Result::success($last_category);
  3487. if (isset($data['id']) && !empty($data['id'])) {
  3488. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3489. switch ($last_category['type']) {
  3490. case 1:
  3491. // 文章
  3492. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3493. $article = Article::where('status', 1)
  3494. ->where('id', $data['id'])
  3495. ->where(function ($query) use ($data) {
  3496. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3497. ->orWhereNull("ignore_ids");
  3498. })
  3499. ->first(['catid']);
  3500. if (empty($article)) {
  3501. return Result::error("该文章不存在", 0);
  3502. }
  3503. // return Result::success($article);
  3504. break;
  3505. case 2:
  3506. // 商品
  3507. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3508. $article = Good::where('website_id', $data['website_id'])
  3509. ->where('status', 2)
  3510. ->where('id', $data['id'])
  3511. ->first(['cat_arr_id']);
  3512. if (empty($article)) {
  3513. return Result::error("该商品不存在", 0);
  3514. }
  3515. break;
  3516. case 3:
  3517. // 书刊信息
  3518. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3519. $article = Book::where('website_id', $data['website_id'])
  3520. ->where('status', 2)
  3521. ->where('id', $data['id'])
  3522. ->first(['id', 'cat_arr_id']);
  3523. if (empty($article)) {
  3524. return Result::error("该书刊不存在", 0);
  3525. }
  3526. break;
  3527. case 4:
  3528. // 招聘
  3529. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3530. $article = JobRecruiting::where('website_id', $data['website_id'])
  3531. ->where('status', 1)
  3532. ->where('id', $data['id'])
  3533. ->first(['cat_arr_id']);
  3534. if (empty($article)) {
  3535. return Result::error("该招聘不存在", 0);
  3536. }
  3537. break;
  3538. case 5:
  3539. // 求职
  3540. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3541. $article = JobHunting::where('website_id', $data['website_id'])
  3542. ->where('status', 2)
  3543. ->where('id', $data['id'])
  3544. ->first(['cat_arr_id']);
  3545. if (empty($article)) {
  3546. return Result::error("该求职不存在", 0);
  3547. }
  3548. break;
  3549. case 6:
  3550. // 企业
  3551. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3552. $article = Company::
  3553. // where('website_id', $data['website_id'])
  3554. // ->
  3555. where('status', 1)
  3556. ->where('id', $data['id'])
  3557. ->first(['cat_arr_id']);
  3558. if (empty($article)) {
  3559. return Result::error("该企业不存在", 0);
  3560. }
  3561. break;
  3562. case 7:
  3563. // 项目
  3564. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3565. $article = Project::where('website_id', $data['website_id'])
  3566. ->where('status', 1)
  3567. ->where('id', $data['id'])
  3568. ->first(['cat_arr_id']);
  3569. if (empty($article)) {
  3570. return Result::error("该项目不存在", 0);
  3571. }
  3572. break;
  3573. default:
  3574. return Result::error("该数据不存在", 0);
  3575. break;
  3576. }
  3577. // return Result::success($article);
  3578. $catid =0 ;
  3579. if(!isset($article['cat_arr_id'])){
  3580. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3581. }else{
  3582. $catidArray = json_decode($article['cat_arr_id'], true);
  3583. $catid = !empty($catidArray) ? end($catidArray) : null;
  3584. }
  3585. // return Result::success($catid);
  3586. // return Result::success($article['cat_arr_id']);
  3587. if (empty($catid)) {
  3588. return Result::error("该数据不存在", 0);
  3589. }
  3590. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3591. ->where('category_id',$catid)
  3592. ->first('path');
  3593. }else{
  3594. // if ($last_category['pid'] != 0) {
  3595. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3596. $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3597. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3598. ->where('category_id',$catid)
  3599. ->where('path',$data['all_route'])
  3600. ->first('path');
  3601. // } else {
  3602. // $pinyin[0] = $last_category['aLIas_pinyin'];
  3603. // }
  3604. }
  3605. // return Result::success($pinyin);
  3606. if (empty($pinyin) || $pinyin['path'] != $data['all_route']) {
  3607. return Result::error('非法路径!');
  3608. } else {
  3609. return Result::success($pinyin);
  3610. }
  3611. }
  3612. /**
  3613. * 招工招聘 - 获取推荐职位
  3614. * @param array $data
  3615. * @return array
  3616. */
  3617. public function getWebsiteLevelJob(array $data): array
  3618. {
  3619. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3620. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3621. ->where('job_recruiting.status', 1)
  3622. ->where('job_level', $data['job_level'])
  3623. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3624. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3625. ->orderBy('job_recruiting.updated_at', 'desc')
  3626. ->limit($data['pageSize'])
  3627. ->get();
  3628. $web = ['website_id' => $data['website_id']];
  3629. if (!empty($job)) {
  3630. $result = $this->processJob($job, $web);
  3631. }
  3632. if (empty($result)) {
  3633. return Result::error("暂无相关职位信息", 0);
  3634. }
  3635. return Result::success($result);
  3636. }
  3637. /**
  3638. * 验证导航名称是否重复
  3639. * @return void
  3640. */
  3641. //20250226 产品列表
  3642. public function getGoodList(array $data): array
  3643. {
  3644. var_dump($data, '---------1-2--');
  3645. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3646. unset($data['user_type_id']);
  3647. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3648. $where = [];
  3649. if ($type_id != '10000') {
  3650. $where = [
  3651. 'good.user_id' => $user_id,
  3652. ];
  3653. }
  3654. //类型
  3655. if (isset($data['type_id']) && $data['type_id']) {
  3656. $where['good.type_id'] = $data['type_id'];
  3657. }
  3658. //名称
  3659. if (isset($data['name']) && $data['name']) {
  3660. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3661. }
  3662. //status
  3663. if (isset($data['status']) && $data['status'] != '') {
  3664. $where['good.status'] = $data['status'];
  3665. }
  3666. //status1
  3667. // if (isset($data['status1']) && $data['status1'] == 1) {
  3668. // $status1 = 1;
  3669. // }
  3670. $where1 = [];
  3671. //website_id
  3672. // if (isset($data['website_id']) && $data['website_id']) {
  3673. // $where1 = [
  3674. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3675. // ];
  3676. // }
  3677. // website_name
  3678. if (isset($data['website_name']) && $data['website_name']) {
  3679. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3680. }
  3681. // catid
  3682. if (isset($data['category_name']) && $data['category_name']) {
  3683. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3684. }
  3685. // $result = Good::where($where)
  3686. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3687. var_dump($where, '---------1---');
  3688. $result = Good::where($where)
  3689. ->when(!empty($where1), function ($query) use ($where1) {
  3690. return $query->where($where1);
  3691. })
  3692. //status 1待审核2已审核3已拒绝
  3693. ->when(isset($data['status1']), function ($query) {
  3694. return $query->whereIn('good.status', [1, 3]);
  3695. })
  3696. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3697. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3698. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3699. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3700. ->orderBy("updated_at", "desc")
  3701. ->limit($data['page_size'])
  3702. ->offset(($data['page'] - 1) * $data['page_size'])
  3703. ->get();
  3704. $count = Good::where($where)
  3705. ->when(!empty($where1), function ($query) use ($where1) {
  3706. return $query->where($where1);
  3707. })
  3708. //status 1待审核2已审核3已拒绝
  3709. ->when(isset($data['status1']), function ($query) {
  3710. return $query->whereIn('good.status', [1, 3]);
  3711. })
  3712. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3713. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3714. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3715. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3716. ->orderBy("updated_at", "desc")->count();
  3717. $data = [
  3718. 'rows' => $result->toArray(),
  3719. 'count' => $count,
  3720. ];
  3721. if (empty($result)) {
  3722. return Result::error("此栏目暂无相关产品", 0);
  3723. }
  3724. return Result::success($data);
  3725. }
  3726. public function getGoodInfo(array $data): array
  3727. {
  3728. $result = Good::where('id', $data['id'])->first();
  3729. if (empty($result)) {
  3730. return Result::error("此产品不存在", 0);
  3731. }
  3732. return Result::success($result);
  3733. }
  3734. public function addGood(array $data): array
  3735. {
  3736. // unset($data['city_arr_id']);
  3737. // unset($data['cat_arr_id']);
  3738. $data['city_id'] = end($data['city_arr_id']);
  3739. $data['catid'] = end($data['cat_arr_id']);
  3740. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3741. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3742. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3743. unset($data['imgUrl']); //大小写
  3744. if (isset($data['price']) && $data['price'] == '') {
  3745. $data['price'] = 0;
  3746. }
  3747. if ($data['imgurl'] == '') {
  3748. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3749. preg_match_all($reg, $data['detail'], $matches);
  3750. if (isset($matches[1][0])) {
  3751. //截取varchar240
  3752. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3753. }
  3754. }
  3755. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3756. //提取标题+内容中的关键词
  3757. $data['keyword'] = $data['name'];
  3758. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3759. Jieba::init(); // 初始化 jieba-php
  3760. Finalseg::init();
  3761. $segList = Jieba::cut($data['keyword']);
  3762. $segList1 = array_slice($segList, 0, 8);
  3763. $data['keyword'] = implode(',', $segList1);
  3764. }
  3765. if ($data['description'] == '') {
  3766. //提取内容中的描述
  3767. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3768. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3769. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3770. }
  3771. if ($data['status'] == 1) {
  3772. $this->sendMessage([
  3773. 'talk_type' => 200,
  3774. 'title' => $data['name'],
  3775. 'content' => '提交了审核',
  3776. 'messageType' => 3,
  3777. ]);
  3778. }
  3779. $result = Good::insert($data);
  3780. if (empty($result)) {
  3781. return Result::error("添加失败", 0);
  3782. }
  3783. return Result::success($result);
  3784. }
  3785. public function updateGood(array $data): array
  3786. {
  3787. $data['city_id'] = end($data['city_arr_id']);
  3788. $data['catid'] = end($data['cat_arr_id']);
  3789. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3790. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3791. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3792. //设置东八区
  3793. date_default_timezone_set('Asia/Shanghai');
  3794. $data['updated_at'] = date('Y-m-d H:i:s');
  3795. if (isset($data['price']) && $data['price'] == '') {
  3796. $data['price'] = 0;
  3797. }
  3798. if ($data['imgurl'] == '') {
  3799. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3800. preg_match_all($reg, $data['detail'], $matches);
  3801. if (isset($matches[1][0])) {
  3802. //截取varchar240
  3803. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3804. }
  3805. }
  3806. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3807. //提取标题+内容中的关键词
  3808. $data['keyword'] = $data['name'];
  3809. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3810. Jieba::init(); // 初始化 jieba-php
  3811. Finalseg::init();
  3812. $segList = Jieba::cut($data['keyword']);
  3813. $segList1 = array_slice($segList, 0, 8);
  3814. $data['keyword'] = implode(',', $segList1);
  3815. }
  3816. if ($data['description'] == '') {
  3817. //提取内容中的描述
  3818. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3819. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3820. }
  3821. if ($data['status'] == 1) {
  3822. $this->sendMessage([
  3823. 'talk_type' => 200,
  3824. 'title' => $data['name'],
  3825. 'content' => '提交了审核',
  3826. 'messageType' => 3,
  3827. ]);
  3828. }
  3829. $result = Good::where('id', $data['id'])->update($data);
  3830. if (empty($result)) {
  3831. return Result::error("更新失败", 0);
  3832. }
  3833. return Result::success($result);
  3834. }
  3835. public function delGood(array $data): array
  3836. {
  3837. $result = Good::where('id', $data['id'])->delete();
  3838. if (empty($result)) {
  3839. return Result::error("删除失败", 0);
  3840. }
  3841. return Result::success($result);
  3842. }
  3843. //20250226 产品列表
  3844. //20250306 求职信息
  3845. public function getJobHuntingList(array $data): array
  3846. {
  3847. $where = [];
  3848. if (isset($data['username']) && !empty($data['username'])) {
  3849. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3850. }
  3851. //status 1待审核2已审核3已拒绝
  3852. if (isset($data['status']) && $data['status'] != '') {
  3853. $where = [
  3854. 'job_hunting.status' => $data['status'],
  3855. ];
  3856. }
  3857. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3858. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3859. unset($data['type_id']);
  3860. if ($type_id != '10000') {
  3861. $where[] = ['job_hunting.user_id', '=', $user_id];
  3862. }
  3863. $result = JobHunting::where($where)
  3864. ->when(!empty($data['status1']), function ($query) use ($data) {
  3865. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3866. })
  3867. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3868. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3869. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3870. ->orderBy("updated_at", "desc")
  3871. ->limit($data['page_size'])
  3872. ->offset(($data['page'] - 1) * $data['page_size'])
  3873. ->get();
  3874. if (empty($result)) {
  3875. return Result::error("查询失败", 0);
  3876. }
  3877. $count = JobHunting::where($where)
  3878. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3879. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3880. ->count();
  3881. $data = [
  3882. 'rows' => $result->toArray(),
  3883. 'count' => $count,
  3884. ];
  3885. return Result::success($data);
  3886. }
  3887. public function getJobHuntingApply(array $data): array
  3888. {
  3889. var_dump($data, '-----------------test--------1-');
  3890. $where = [];
  3891. if (isset($data['username']) && !empty($data['username'])) {
  3892. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3893. }
  3894. if (isset($data['salary']) && !empty($data['salary'])) {
  3895. $where[] = [
  3896. 'job_hunting.salary',
  3897. '=',
  3898. $data['salary'],
  3899. ];
  3900. }
  3901. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3902. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3903. unset($data['type_id']);
  3904. if ($type_id != '10000') {
  3905. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3906. }
  3907. var_dump($where, '-----------------test---------');
  3908. $result = jobApply::where($where)
  3909. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3910. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3911. // })
  3912. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3913. ->where('job_enum.egroup', '=', 'income')
  3914. ->where('job_hunting.status', 2) //已审核
  3915. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3916. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3917. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3918. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3919. //职位----是申请职位
  3920. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3921. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  3922. ->orderBy("job_hunting.updated_at", "desc")
  3923. ->limit($data['page_size'])
  3924. ->offset(($data['page'] - 1) * $data['page_size'])
  3925. ->get();
  3926. if (empty($result)) {
  3927. return Result::error("查询失败", 0);
  3928. }
  3929. $count = jobApply::where($where)
  3930. ->where('job_enum.egroup', '=', 'income')
  3931. ->where('job_hunting.status', 2) //已审核
  3932. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3933. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3934. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3935. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3936. //职位----是申请职位
  3937. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3938. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  3939. ->count();
  3940. $data = [
  3941. 'rows' => $result->toArray(),
  3942. 'count' => $count,
  3943. ];
  3944. return Result::success($data);
  3945. }
  3946. public function addJobHunting(array $data): array
  3947. {
  3948. date_default_timezone_set('Asia/Shanghai');
  3949. unset($data['company_name']);
  3950. unset($data['job_industry']);
  3951. unset($data['job_name']);
  3952. unset($data['department']);
  3953. unset($data['job_timeList']);
  3954. unset($data['job_content']);
  3955. unset($data['job_typename']); //不知道这是啥,
  3956. $data['created_at'] = date('Y-m-d H:i:s');
  3957. $data['updated_at'] = date('Y-m-d H:i:s');
  3958. //根据用户 user_id 只能添加一次
  3959. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3960. if (!empty($result)) {
  3961. return Result::error("您已添加过求职信息", 0);
  3962. }
  3963. var_dump($result, '-----------------test---------');
  3964. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3965. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3966. $cityArr = json_decode($data['city_arr_id'], true);
  3967. $data['city_id'] = end($cityArr);
  3968. } else {
  3969. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3970. $data['city_id'] = end($data['city_arr_id']);
  3971. }
  3972. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3973. $this->sendMessage([
  3974. 'talk_type' => 600,
  3975. 'title' => $data['name'],
  3976. 'content' => '提交了审核',
  3977. 'messageType' => 11,
  3978. ]);
  3979. }
  3980. $result = JobHunting::create($data);
  3981. if (empty($result)) {
  3982. return Result::error("添加失败", 0);
  3983. }
  3984. return Result::success($result);
  3985. }
  3986. public function delJobHunting(array $data): array
  3987. {
  3988. $result = JobHunting::where('id', $data['id'])->delete();
  3989. if (empty($result)) {
  3990. return Result::error("删除失败", 0);
  3991. }
  3992. return Result::success($result);
  3993. }
  3994. public function updateJobHunting(array $data): array
  3995. {
  3996. //设置东八区
  3997. date_default_timezone_set('Asia/Shanghai');
  3998. unset($data['company_name']);
  3999. unset($data['job_industry']);
  4000. unset($data['job_name']);
  4001. unset($data['department']);
  4002. unset($data['job_timeList']);
  4003. unset($data['job_content']);
  4004. unset($data['job_typename']); //不知道这是啥,
  4005. $data['created_at'] = date('Y-m-d H:i:s');
  4006. $data['updated_at'] = date('Y-m-d H:i:s');
  4007. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4008. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4009. $cityArr = json_decode($data['city_arr_id'], true);
  4010. $data['city_id'] = end($cityArr);
  4011. } else {
  4012. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4013. $data['city_id'] = end($data['city_arr_id']);
  4014. }
  4015. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4016. $this->sendMessage([
  4017. 'talk_type' => 600,
  4018. 'title' => $data['name'],
  4019. 'content' => '提交了审核',
  4020. 'messageType' => 11,
  4021. ]);
  4022. }
  4023. $result = JobHunting::where('id', $data['id'])->update($data);
  4024. if (empty($result)) {
  4025. return Result::error("更新失败", 0);
  4026. }
  4027. return Result::success($result);
  4028. }
  4029. public function getJobHuntingInfo(array $data): array
  4030. {
  4031. $result = JobHunting::where('id', $data['id'])->first();
  4032. if (empty($result)) {
  4033. return Result::error("查询失败", 0);
  4034. }
  4035. return Result::success($result);
  4036. }
  4037. public function getJobHuntingData(array $data): array
  4038. {
  4039. $jobEnum = JobEnum::get();
  4040. $jobIndustry = JobIndustry::get();
  4041. $jobNature = JobNature::get();
  4042. $jobPosition = JobPosition::get();
  4043. $data = [
  4044. 'jobEnum' => $jobEnum,
  4045. 'jobIndustry' => $jobIndustry,
  4046. 'jobNature' => $jobNature,
  4047. 'jobPosition' => $jobPosition,
  4048. ];
  4049. return Result::success($data);
  4050. }
  4051. public function delJobHuntingInfo(array $data): array
  4052. {
  4053. $result = JobHunting::where('id', $data['id'])->delete();
  4054. return Result::success();
  4055. }
  4056. //20250324 通知,公告,消息
  4057. public function delNotice(array $data): array
  4058. {
  4059. $result = Notice::where('id', $data['id'])->delete();
  4060. if ($result) {
  4061. return Result::success();
  4062. } else {
  4063. return Result::error("删除失败", 0);
  4064. }
  4065. }
  4066. public function getNoticeInfo(array $data): array
  4067. {
  4068. $result = Notice::where('id', $data['id'])->first();
  4069. // var_dump($result['re_user_ids'], '--------------------');
  4070. if (empty($result)) {
  4071. return Result::error("查询失败", 0);
  4072. }
  4073. return Result::success($result);
  4074. }
  4075. public function readNotice(array $data): array
  4076. {
  4077. $result = Notice::where('id', $data['id'])->first();
  4078. // var_dump($result['re_user_ids'], '--------------------');
  4079. if (empty($result)) {
  4080. return Result::error("查询失败", 0);
  4081. }
  4082. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4083. $re_user_ids = json_decode($result['re_user_ids'], true);
  4084. var_dump($re_user_ids, '--------------1---test---------');
  4085. var_dump($data, '--------------1---test---------');
  4086. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4087. //如果已经存在,就不再添加
  4088. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4089. $read_id = json_decode($result['read_id'], true);
  4090. if (!is_array($read_id)) {
  4091. $read_id = [];
  4092. }
  4093. if (!in_array($data['user_id'], $read_id)) {
  4094. $read_id[] = $data['user_id'];
  4095. $result['read_id'] = json_encode($read_id);
  4096. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4097. }
  4098. } else {
  4099. //如果不存在,就添加
  4100. $result['read_id'] = json_encode([$data['user_id']]);
  4101. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4102. }
  4103. }
  4104. return Result::success($result);
  4105. }
  4106. public function addNotice(array $data): array
  4107. {
  4108. date_default_timezone_set('Asia/Shanghai');
  4109. $data['created_at'] = date('Y-m-d H:i:s');
  4110. $data['updated_at'] = date('Y-m-d H:i:s');
  4111. $user_id = UserInfo::
  4112. //city_id不是null
  4113. whereNotNull('city_id')
  4114. ->whereNotNull('department_id')
  4115. ->where(function ($query) use ($data) {
  4116. $query->where(function ($subQuery) use ($data) {
  4117. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4118. });
  4119. })
  4120. ->where(function ($query) use ($data) {
  4121. $query->where(function ($subQuery) use ($data) {
  4122. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4123. });
  4124. })
  4125. ->pluck('user_id')->toArray();
  4126. $user_id = array_unique($user_id);
  4127. $chat_ids = $user_id;
  4128. $user_id = json_encode($user_id);
  4129. $data['re_user_ids'] = $user_id;
  4130. $this->sendMessage([
  4131. 'talk_type' => 700,
  4132. 'title' => $data['title'],
  4133. 'content' => '提交了审核',
  4134. 'messageType' => 5,
  4135. ]);
  4136. $result = Notice::insertGetId($data);
  4137. if (empty($result)) {
  4138. return Result::error("添加失败", 0);
  4139. }
  4140. return Result::success($result);
  4141. }
  4142. public function updateNotice(array $data): array
  4143. {
  4144. date_default_timezone_set('Asia/Shanghai');
  4145. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4146. $user_id = UserInfo::
  4147. //city_id不是null
  4148. whereNotNull('city_id')
  4149. ->whereNotNull('department_id')
  4150. ->where(function ($query) use ($data) {
  4151. $query->where(function ($subQuery) use ($data) {
  4152. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4153. });
  4154. })
  4155. ->where(function ($query) use ($data) {
  4156. $query->where(function ($subQuery) use ($data) {
  4157. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4158. });
  4159. })
  4160. ->pluck('user_id')->toArray();
  4161. $user_id = array_unique($user_id);
  4162. $user_id = json_encode($user_id);
  4163. $data['re_user_ids'] = $user_id;
  4164. $data['updated_at'] = date('Y-m-d H:i:s');
  4165. $this->sendMessage([
  4166. 'talk_type' => 700,
  4167. 'title' => $data['title'],
  4168. 'content' => '提交了审核',
  4169. 'messageType' => 5,
  4170. ]);
  4171. $result = Notice::where('id', $data['id'])->update($data);
  4172. return Result::success($result);
  4173. }
  4174. public function getNoticeList(array $data): array
  4175. {
  4176. $where = [];
  4177. //title
  4178. if (isset($data['title']) && !empty($data['title'])) {
  4179. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4180. }
  4181. //level
  4182. if (isset($data['level']) && !empty($data['level'])) {
  4183. $where[] = ['notice.level', '=', $data['level']];
  4184. }
  4185. //status
  4186. if (isset($data['status']) && !empty($data['status'])) {
  4187. $where[] = ['notice.status', '=', $data['status']];
  4188. }
  4189. //type
  4190. if (isset($data['type']) && !empty($data['type'])) {
  4191. $where[] = ['notice.type', '=', $data['type']];
  4192. }
  4193. var_dump($data, '------------11111-2----test---------');
  4194. if ($data['type_id'] == 10000) {
  4195. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4196. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4197. })
  4198. ->where($where)
  4199. ->orderBy('updated_at', 'desc')
  4200. ->limit($data['page_size'])
  4201. ->offset(($data['page'] - 1) * $data['page_size'])
  4202. ->get();
  4203. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4204. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4205. })
  4206. ->where($where)
  4207. ->orderBy('updated_at', 'desc')
  4208. ->count();
  4209. } else {
  4210. $result = Notice::where($where)
  4211. // ->where('user_id', $data['user_id'])
  4212. ->Where(function ($query) use ($data) {
  4213. $query->Where(function ($q) use ($data) {
  4214. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4215. ->orWhere('notice.user_id', $data['user_id']);
  4216. });
  4217. })
  4218. ->when(!empty($data['status1']), function ($query) use ($data) {
  4219. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4220. })
  4221. ->orderBy('updated_at', 'desc')
  4222. ->limit($data['page_size'])
  4223. ->offset(($data['page'] - 1) * $data['page_size'])
  4224. ->get();
  4225. $total = Notice::where($where)
  4226. ->when(!empty($data['status1']), function ($query) use ($data) {
  4227. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4228. })
  4229. // ->where('user_id', $data['user_id'])
  4230. ->Where(function ($query) use ($data) {
  4231. $query->Where(function ($q) use ($data) {
  4232. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4233. ->orWhere('notice.user_id', $data['user_id']);
  4234. });
  4235. })
  4236. ->count();
  4237. }
  4238. if (empty($result)) {
  4239. return Result::error("查询失败", 0);
  4240. }
  4241. $data = [
  4242. 'rows' => $result,
  4243. 'count' => $total,
  4244. ];
  4245. return Result::success($data);
  4246. }
  4247. public function noticeList(array $data): array
  4248. {
  4249. $where = [];
  4250. //title
  4251. if (isset($data['title']) && !empty($data['title'])) {
  4252. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4253. }
  4254. //level
  4255. if (isset($data['level']) && !empty($data['level'])) {
  4256. $where[] = ['notice.level', '=', $data['level']];
  4257. }
  4258. //status
  4259. if (isset($data['status']) && !empty($data['status'])) {
  4260. $where[] = ['notice.status', '=', $data['status']];
  4261. }
  4262. //type
  4263. if (isset($data['type']) && !empty($data['type'])) {
  4264. $where[] = ['notice.type', '=', $data['type']];
  4265. }
  4266. var_dump($data, '------------11111-2----test---------');
  4267. if ($data['type_id'] == 10000) {
  4268. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4269. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4270. })
  4271. ->where($where)
  4272. ->orderBy('updated_at', 'desc')
  4273. ->limit($data['page_size'])
  4274. ->offset(($data['page'] - 1) * $data['page_size'])
  4275. ->get();
  4276. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4277. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4278. })
  4279. ->where($where)
  4280. ->orderBy('updated_at', 'desc')
  4281. ->count();
  4282. } else {
  4283. $result = Notice::where($where)
  4284. // ->where('user_id', $data['user_id'])
  4285. ->Where(function ($query) use ($data) {
  4286. $query->Where(function ($q) use ($data) {
  4287. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4288. ->orWhere('notice.user_id', $data['user_id']);
  4289. });
  4290. })
  4291. ->when(!empty($data['status1']), function ($query) use ($data) {
  4292. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4293. })
  4294. ->orderBy('updated_at', 'desc')
  4295. ->limit($data['page_size'])
  4296. ->offset(($data['page'] - 1) * $data['page_size'])
  4297. ->get();
  4298. $total = Notice::where($where)
  4299. ->when(!empty($data['status1']), function ($query) use ($data) {
  4300. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4301. })
  4302. // ->where('user_id', $data['user_id'])
  4303. ->Where(function ($query) use ($data) {
  4304. $query->Where(function ($q) use ($data) {
  4305. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4306. ->orWhere('notice.user_id', $data['user_id']);
  4307. });
  4308. })
  4309. ->count();
  4310. }
  4311. if (empty($result)) {
  4312. return Result::error("查询失败", 0);
  4313. }
  4314. $data = [
  4315. 'rows' => $result,
  4316. 'count' => $total,
  4317. ];
  4318. return Result::success($data);
  4319. }
  4320. public function getNoticeDetail(array $data): array
  4321. {
  4322. $result = Notice::where('id', $data['id'])->first();
  4323. if (empty($result)) {
  4324. return Result::error("查询失败", 0);
  4325. }
  4326. return Result::success($result);
  4327. }
  4328. public function deleteNotice(array $data): array
  4329. {
  4330. $notice = Notice::where('id', $data['id'])->first();
  4331. if (empty($notice)) {
  4332. return Result::error("删除失败", 0);
  4333. }
  4334. $chat_group_id = $notice->group_id;
  4335. if ($chat_group_id) {
  4336. //删除群聊
  4337. ChatGroups::where('id', $chat_group_id)->delete();
  4338. //删除群成员
  4339. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4340. //删除群聊记录
  4341. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4342. }
  4343. $result = Notice::where('id', $data['id'])->delete();
  4344. return Result::success($result);
  4345. }
  4346. public function complaintList(array $data): array
  4347. {
  4348. var_dump($data, '---------1---------');
  4349. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4350. unset($data['type_id']);
  4351. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4352. $where = [];
  4353. if ($type_id != 10000 && empty($data['deal_user'])) {
  4354. // $where['complaint.user_id'] = $user_id;
  4355. }
  4356. if (!empty($data['title'])) {
  4357. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4358. }
  4359. if (!empty($data['department_id'])) {
  4360. $where['complaint.department_id'] = $data['department_id'];
  4361. }
  4362. if (!empty($data['deal'])) {
  4363. $where['complaint.deal'] = $data['deal'];
  4364. }
  4365. if (!empty($data['status'])) {
  4366. $where['complaint.status'] = $data['status'];
  4367. }
  4368. var_dump(!empty($data['deal_user']), '----------1');
  4369. var_dump($where, '----------2');
  4370. $result = Complaint::where($where)
  4371. ->when(!empty($data['status1']), function ($query) use ($data) {
  4372. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4373. })
  4374. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4375. //json re_user_ids data[user_id]是不是在里面
  4376. $query->Where(function ($q) use ($data) {
  4377. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4378. ->where('complaint.status', 2);
  4379. });
  4380. })
  4381. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4382. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4383. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4384. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4385. ->orderBy('updated_at', 'desc')
  4386. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4387. //sql输出
  4388. if (empty($result)) {
  4389. return Result::error("暂无投诉信息", 0);
  4390. }
  4391. // 取出数据
  4392. $rows = $result->items();
  4393. $count = $result->total();
  4394. $responseData = [
  4395. 'rows' => $rows,
  4396. 'count' => $count,
  4397. ];
  4398. return Result::success($responseData);
  4399. }
  4400. public function getComplaintList(array $data): array
  4401. {
  4402. var_dump($data, '00000001000000000000');
  4403. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4404. unset($data['type_id']);
  4405. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4406. $where = [];
  4407. if ($type_id != 10000 && empty($data['deal_user'])) {
  4408. $where['complaint.user_id'] = $user_id;
  4409. }
  4410. if (!empty($data['title'])) {
  4411. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4412. }
  4413. if (!empty($data['department_id'])) {
  4414. $where['complaint.department_id'] = $data['department_id'];
  4415. }
  4416. if (!empty($data['deal'])) {
  4417. $where['complaint.deal'] = $data['deal'];
  4418. }
  4419. if (!empty($data['status'])) {
  4420. $where['complaint.status'] = $data['status'];
  4421. }
  4422. var_dump(!empty($data['deal_user']), '----------1');
  4423. var_dump($where, '----------2');
  4424. $result = Complaint::where($where)
  4425. ->when(!empty($data['status1']), function ($query) use ($data) {
  4426. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4427. })
  4428. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4429. // //json re_user_ids data[user_id]是不是在里面
  4430. // $query->Where(function ($q) use ($data) {
  4431. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4432. // ->where('complaint.status', 2);
  4433. // });
  4434. // })
  4435. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4436. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4437. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4438. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4439. ->orderBy('updated_at', 'desc')
  4440. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4441. //sql输出
  4442. if (empty($result)) {
  4443. return Result::error("暂无投诉信息", 0);
  4444. }
  4445. // 取出数据
  4446. $rows = $result->items();
  4447. $count = $result->total();
  4448. $responseData = [
  4449. 'rows' => $rows,
  4450. 'count' => $count,
  4451. ];
  4452. return Result::success($responseData);
  4453. }
  4454. public function getComplaintInfo(array $data): array
  4455. {
  4456. $result = Complaint::where('id', $data['id'])->first();
  4457. if (empty($result)) {
  4458. return Result::error("查询失败", 0);
  4459. }
  4460. return Result::success($result);
  4461. }
  4462. public function readComplaint(array $data): array
  4463. {
  4464. $result = Complaint::where('id', $data['id'])->first();
  4465. if (empty($result)) {
  4466. return Result::error("查询失败", 0);
  4467. }
  4468. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4469. $re_user_ids = json_decode($result['re_user_ids'], true);
  4470. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4471. //如果已经存在,就不再添加
  4472. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4473. $read_id = json_decode($result['read_id'], true);
  4474. if (!is_array($read_id)) {
  4475. $read_id = [];
  4476. }
  4477. if (!in_array($data['user_id'], $read_id)) {
  4478. $read_id[] = $data['user_id'];
  4479. $result['read_id'] = json_encode($read_id);
  4480. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4481. }
  4482. } else {
  4483. //如果不存在,就添加
  4484. $result['read_id'] = json_encode([$data['user_id']]);
  4485. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4486. }
  4487. }
  4488. return Result::success($result);
  4489. }
  4490. public function addComplaint(array $data): array
  4491. {
  4492. date_default_timezone_set('Asia/Shanghai');
  4493. $data['created_at'] = date('Y-m-d H:i:s');
  4494. $data['updated_at'] = date('Y-m-d H:i:s');
  4495. $this->sendMessage([
  4496. 'talk_type' => 800,
  4497. 'title' => $data['title'],
  4498. 'content' => '提交了审核',
  4499. 'messageType' => 6,
  4500. ]);
  4501. $result = Complaint::create($data);
  4502. return Result::success($result);
  4503. }
  4504. public function updateComplaint(array $data): array
  4505. {
  4506. date_default_timezone_set('Asia/Shanghai');
  4507. $data['updated_at'] = date('Y-m-d H:i:s');
  4508. $user_id = $data['user_id'] ?? 0;
  4509. $type_id = $data['type_id'] ?? 0;
  4510. unset($data['user_id']);
  4511. unset($data['type_id']);
  4512. $this->sendMessage([
  4513. 'talk_type' => 800,
  4514. 'title' => $data['title'],
  4515. 'content' => '提交了审核',
  4516. 'messageType' => 6,
  4517. ]);
  4518. $result = Complaint::where('id', $data['id'])->update($data);
  4519. return Result::success($result);
  4520. }
  4521. public function deleteComplaint(array $data): array
  4522. {
  4523. $result = Complaint::where('id', $data['id'])->delete();
  4524. return Result::success($result);
  4525. }
  4526. public function getComplainInfo(array $data): array
  4527. {
  4528. $result = Complaint::where('id', $data['id'])->first();
  4529. if (empty($result)) {
  4530. return Result::error("查询失败", 0);
  4531. }
  4532. return Result::success($result);
  4533. }
  4534. public function updateComplaintStatus(array $data): array
  4535. {
  4536. date_default_timezone_set('Asia/Shanghai');
  4537. $data['updated_at'] = date('Y-m-d H:i:s');
  4538. $user_id = $data['user_id'] ?? 0;
  4539. $type_id = $data['type_id'] ?? 0;
  4540. unset($data['user_id']);
  4541. unset($data['type_id']);
  4542. //处理, 写入处理人
  4543. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4544. $data['real_deal_user'] = $user_id;
  4545. }
  4546. //如果是deal 23,则判断是不是处理人
  4547. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4548. $complaintInof = Complaint::where('id', $data['id'])
  4549. ->where('real_deal_user', $user_id)
  4550. ->first();
  4551. if (empty($complaintInof)) {
  4552. return Result::error("处理人错误", 0);
  4553. }
  4554. }
  4555. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4556. if ($data['status'] == 1) {
  4557. $this->sendMessage([
  4558. 'talk_type' => 800,
  4559. 'title' => $complaintInfo['title'],
  4560. 'content' => '提交了审核',
  4561. 'messageType' => 6,
  4562. ]);
  4563. }
  4564. if ($data['status'] == 2 && !isset($data['deal'])) {
  4565. $this->sendMessage([
  4566. 'talk_type' => 801,
  4567. 'title' => $complaintInfo['title'],
  4568. 'content' => '审核通过',
  4569. 'messageType' => 6,
  4570. 'user_id' => $complaintInfo['user_id'],
  4571. ]);
  4572. $this->sendMessage([
  4573. 'talk_type' => 802,
  4574. 'title' => $complaintInfo['title'],
  4575. 'content' => '待处理',
  4576. 'messageType' => 6,
  4577. 'user_id' => $complaintInfo['re_user_ids'],
  4578. ]);
  4579. }
  4580. if ($data['status'] == 3 && !isset($data['deal'])) {
  4581. $this->sendMessage([
  4582. 'talk_type' => 801,
  4583. 'title' => $complaintInfo['title'],
  4584. 'content' => '审核拒绝',
  4585. 'messageType' => 6,
  4586. 'user_id' => $complaintInfo['user_id'],
  4587. ]);
  4588. }
  4589. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4590. $this->sendMessage([
  4591. 'talk_type' => 802,
  4592. 'title' => $complaintInfo['title'],
  4593. 'content' => '处理中',
  4594. 'messageType' => 6,
  4595. 'user_id' => $complaintInfo['re_user_ids'],
  4596. ]);
  4597. }
  4598. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4599. $this->sendMessage([
  4600. 'talk_type' => 802,
  4601. 'title' => $complaintInfo['title'],
  4602. 'content' => '不予处理',
  4603. 'messageType' => 6,
  4604. 'user_id' => $complaintInfo['re_user_ids'],
  4605. ]);
  4606. }
  4607. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4608. $this->sendMessage([
  4609. 'talk_type' => 802,
  4610. 'title' => $complaintInfo['title'],
  4611. 'content' => '已完结',
  4612. 'messageType' => 6,
  4613. 'user_id' => $complaintInfo['re_user_ids'],
  4614. ]);
  4615. }
  4616. $result = complaint::where('id', $data['id'])->update($data);
  4617. return Result::success($result);
  4618. }
  4619. public function updateGoodStatus(array $data): array
  4620. {
  4621. $user_id = $data['user_id'] ?? 0;
  4622. $type_id = $data['type_id'] ?? 0;
  4623. unset($data['user_id']);
  4624. unset($data['type_id']);
  4625. $goodInfo = Good::where('id', $data['id'])->first();
  4626. if ($data['status'] == 2) {
  4627. $this->sendMessage([
  4628. 'talk_type' => 201,
  4629. 'title' => $goodInfo['name'],
  4630. 'content' => '审核通过',
  4631. 'messageType' => 3,
  4632. 'user_id' => $goodInfo['user_id'],
  4633. ]);
  4634. }
  4635. if ($data['status'] == 3) {
  4636. $this->sendMessage([
  4637. 'talk_type' => 201,
  4638. 'title' => $goodInfo['name'],
  4639. 'content' => '审核拒绝',
  4640. 'messageType' => 3,
  4641. 'user_id' => $goodInfo['user_id'],
  4642. ]);
  4643. }
  4644. if ($data['status'] == 1) {
  4645. $this->sendMessage([
  4646. 'talk_type' => 200,
  4647. 'title' => $goodInfo['name'],
  4648. 'content' => '提交了审核',
  4649. 'messageType' => 3,
  4650. ]);
  4651. }
  4652. $result = Good::where('id', $data['id'])->update($data);
  4653. return Result::success($result);
  4654. }
  4655. public function updateJobHuntingStatus(array $data): array
  4656. {
  4657. $user_id = $data['user_id'] ?? 0;
  4658. $type_id = $data['type_id'] ?? 0;
  4659. unset($data['user_id']);
  4660. unset($data['type_id']);
  4661. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4662. if ($data['status'] == 2) {
  4663. $this->sendMessage([
  4664. 'talk_type' => 601,
  4665. 'title' => $jogHuntingInfo['name'],
  4666. 'content' => '审核通过',
  4667. 'messageType' => 11,
  4668. 'user_id' => $jogHuntingInfo['user_id'],
  4669. ]);
  4670. }
  4671. if ($data['status'] == 3) {
  4672. $this->sendMessage([
  4673. 'talk_type' => 601,
  4674. 'title' => $jogHuntingInfo['name'],
  4675. 'content' => '审核拒绝',
  4676. 'messageType' => 11,
  4677. 'user_id' => $jogHuntingInfo['user_id'],
  4678. ]);
  4679. }
  4680. if ($data['status'] == 1) {
  4681. $this->sendMessage([
  4682. 'talk_type' => 600,
  4683. 'title' => $jogHuntingInfo['name'],
  4684. 'content' => '提交了审核',
  4685. 'messageType' => 11,
  4686. ]);
  4687. }
  4688. $result = JobHunting::where('id', $data['id'])->update($data);
  4689. return Result::success($result);
  4690. }
  4691. public function updateNoticeStatus(array $data): array
  4692. {
  4693. $user_id = $data['user_id'] ?? 0;
  4694. $type_id = $data['type_id'] ?? 0;
  4695. unset($data['user_id']);
  4696. unset($data['type_id']);
  4697. //查询公告
  4698. $notice = Notice::where('id', $data['id'])->first();
  4699. if (empty($notice)) {
  4700. return Result::error("公告不存在", 0);
  4701. }
  4702. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4703. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4704. //chat_group
  4705. $group_id = PublicData::uuid();
  4706. $groupData = [
  4707. 'id' => $group_id,
  4708. 'creator_id' => $notice['user_id'],
  4709. 'group_name' => $notice['group_name'] ?? '',
  4710. 'profile' => $notice['profile'] ?? 0,
  4711. ];
  4712. var_dump($groupData, '-----------------groupData-------');
  4713. $groupResult = ChatGroups::insertGetId($groupData);
  4714. var_dump($groupResult, '-----------------groupid-------');
  4715. $groupMemberData = [
  4716. 'id' => PublicData::uuid(),
  4717. 'user_id' => $notice['user_id'],
  4718. 'group_id' => $group_id,
  4719. 'leader' => 2,
  4720. ];
  4721. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4722. //$chat_ids 去除掉$data['user_id']
  4723. $chat_ids = json_decode($notice['re_user_ids'], true);
  4724. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4725. //插入群成员表
  4726. $groupMemberDataUser = [];
  4727. $chatData = [];
  4728. foreach ($chat_ids as $key => $value) {
  4729. $groupMemberDataUser[] = [
  4730. 'id' => PublicData::uuid(),
  4731. 'user_id' => $value,
  4732. 'group_id' => $group_id,
  4733. 'leader' => 1,
  4734. ];
  4735. $chatData[] = [
  4736. 'user_id' => $value,
  4737. 'msg_type' => 1,
  4738. 'receiver_id' => $group_id,
  4739. 'content' => '通过通知创建群聊',
  4740. 'group_receiver_id' => $notice['user_id'],
  4741. 'action' => 'recieved',
  4742. 'created_at' => date('Y-m-d H:i:s'),
  4743. ];
  4744. }
  4745. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4746. ChatGroupsMember::insert($groupMemberDataUser);
  4747. //插入一条管理员聊天记录
  4748. $chatData[] = [
  4749. 'user_id' => $notice['user_id'],
  4750. 'msg_type' => 1,
  4751. 'receiver_id' => $group_id,
  4752. 'content' => '通过通知创建群聊',
  4753. 'group_receiver_id' => $notice['user_id'],
  4754. 'action' => 'said',
  4755. 'created_at' => date('Y-m-d H:i:s'),
  4756. ];
  4757. var_dump($chatData, '-----------------chatData-------');
  4758. $chatResult = ChatRecords::insert($chatData);
  4759. //更新result的 group_id
  4760. $data['group_id'] = $group_id;
  4761. Notice::where(['id' => $data['id']])->update($data);
  4762. }
  4763. $result = Notice::where('id', $data['id'])->update($data);
  4764. $noticeInfo = Notice::where('id', $data['id'])->first();
  4765. if ($data['status'] == 2) {
  4766. $this->sendMessage([
  4767. 'talk_type' => 701,
  4768. 'title' => $noticeInfo['title'],
  4769. 'content' => '审核通过',
  4770. 'messageType' => 3,
  4771. 'user_id' => $noticeInfo['user_id'],
  4772. ]);
  4773. }
  4774. if ($data['status'] == 3) {
  4775. $this->sendMessage([
  4776. 'talk_type' => 701,
  4777. 'title' => $noticeInfo['title'],
  4778. 'content' => '审核拒绝',
  4779. 'messageType' => 3,
  4780. 'user_id' => $noticeInfo['user_id'],
  4781. ]);
  4782. }
  4783. if ($data['status'] == 1) {
  4784. $this->sendMessage([
  4785. 'talk_type' => 700,
  4786. 'title' => $noticeInfo['title'],
  4787. 'content' => '提交了审核',
  4788. 'messageType' => 3,
  4789. ]);
  4790. }
  4791. return Result::success($result);
  4792. }
  4793. public function getDUser(array $data): array
  4794. {
  4795. if (!empty($data['ids'])) {
  4796. $user = User::whereIn('id', $data['ids'])->getall();
  4797. if (empty($user)) {
  4798. return Result::error('无数据', 0);
  4799. }
  4800. return Result::success($user);
  4801. }
  4802. $where = [];
  4803. if (!empty($data['department_id'])) {
  4804. $where['department_id'] = $data['department_id'];
  4805. }
  4806. if (!empty($data['city_id'])) {
  4807. $where['city_id'] = $data['city_id'];
  4808. }
  4809. $result = User::where('type_id', 2)
  4810. ->where('status', 1)
  4811. ->where($where)
  4812. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4813. ->get();
  4814. if (empty($result)) {
  4815. return Result::error("查询失败", 0);
  4816. }
  4817. return Result::success($result);
  4818. }
  4819. /**
  4820. * 验证导航名称是否重复
  4821. * @return void
  4822. */
  4823. public function checkCategoryName(array $data): array
  4824. {
  4825. $result = Category::when($data, function ($query) use ($data) {
  4826. if (isset($data['name']) && $data['name']) {
  4827. $query->where("name", $data['name']);
  4828. }
  4829. if (isset($data['id']) && $data['id']) {
  4830. $query->where("id", "!=", $data['id']);
  4831. }
  4832. })->first();
  4833. if ($result) {
  4834. return Result::error("已存在");
  4835. } else {
  4836. return Result::success();
  4837. }
  4838. }
  4839. //20250226 产品列表
  4840. // 20250306 -------招聘--------fr
  4841. /*
  4842. * 招聘列表
  4843. * */
  4844. public function getJobRecruitingList(array $data): array
  4845. {
  4846. $where = [];
  4847. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4848. if ($data['checkout'] == 0) {
  4849. $job_status = [0, 2];
  4850. } else {
  4851. $job_status = [1];
  4852. }
  4853. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4854. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4855. }
  4856. $user = User::where('id', $data['user_id'])->first();
  4857. if (empty($user)) {
  4858. return Result::error("用户不存在", 0);
  4859. }
  4860. // 3:企业会员
  4861. if ($user['type_id'] == 3) {
  4862. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4863. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4864. }
  4865. // 如果 $where 为空,则不添加 where 条件
  4866. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4867. return $query->where($where);
  4868. })
  4869. ->whereIn('job_recruiting.status', $job_status)
  4870. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4871. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4872. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4873. ->orderBy("updated_at", "desc")
  4874. ->offset(($data['page'] - 1) * $data['page_size'])
  4875. ->limit($data['page_size'])
  4876. ->get()
  4877. ->all();
  4878. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4879. return $query->where($where);
  4880. })
  4881. ->whereIn('job_recruiting.status', $job_status)
  4882. ->count();
  4883. if (empty($result)) {
  4884. return Result::error("暂无招聘信息", 0);
  4885. }
  4886. return Result::success($result);
  4887. }
  4888. /*
  4889. * 招聘信息添加
  4890. * */
  4891. public function addJobRecruiting(array $data): array
  4892. {
  4893. // var_dump('添加招聘进入news------data',$data);
  4894. // return Result::success($data);
  4895. $user = User::where('user.id', $data['user_id'])
  4896. ->where('user.status', 1)
  4897. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4898. ->select(
  4899. 'user.type_id',
  4900. 'user.mobile',
  4901. 'user.email',
  4902. 'user_info.business_name',
  4903. 'user_info.company_hy_id',
  4904. 'user_info.company_nature',
  4905. 'user_info.company_size',
  4906. 'user_info.introduction',
  4907. 'user_info.real_name',
  4908. 'user_info.company_url',
  4909. 'user_info.address_arr_id',
  4910. 'user_info.address'
  4911. )
  4912. ->first();
  4913. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4914. return Result::error("用户不存在", 0);
  4915. }
  4916. $web = Website::where('id', $data['website_id'])->first();
  4917. if (empty($web)) {
  4918. return Result::error("网站不存在", 0);
  4919. }
  4920. // var_dump('添加招聘进入news---user---user',$user);
  4921. // return Result::success($user);
  4922. $data['action_id'] = $data['user_id'] ?? null;
  4923. $data['user_type'] = $user['type_id'] ?? null;
  4924. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  4925. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  4926. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  4927. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  4928. // 公司地址 管理员必填
  4929. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  4930. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  4931. // 管理员-企业相关信息
  4932. $company = [
  4933. // 'user_id' => $data['user_id']?? null,
  4934. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  4935. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  4936. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  4937. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  4938. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  4939. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  4940. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  4941. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  4942. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  4943. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  4944. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  4945. ];
  4946. //去掉相关企业信息
  4947. $job = array_diff_key($data, array_flip(array_keys($company)));
  4948. // var_dump('添加招聘进入news---job---user',$job);
  4949. Db::beginTransaction();
  4950. try {
  4951. // // 先添加职位相关信息
  4952. if ($user['type_id'] == 10000) {
  4953. $job['status'] = 1;
  4954. }
  4955. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  4956. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  4957. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  4958. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  4959. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  4960. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  4961. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  4962. // return Result::success($job);
  4963. $jobId = JobRecruiting::insertGetId($job);
  4964. if (empty($jobId)) {
  4965. Db::rollBack();
  4966. return Result::error("添加失败");
  4967. }
  4968. // 添加公司信息
  4969. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  4970. $company['job_id'] = $jobId;
  4971. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  4972. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  4973. if ($user['type_id'] == 10000) {
  4974. // 管理员添加企业信息
  4975. $companyId = JobCompany::insertGetId($company);
  4976. if (empty($companyId)) {
  4977. Db::rollBack();
  4978. return Result::error("添加失败");
  4979. }
  4980. } else {
  4981. // 企业会员添加企业信息
  4982. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  4983. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  4984. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  4985. $company['job_id'] = $jobId;
  4986. $companyId = JobCompany::insertGetId($company);
  4987. if (empty($companyId)) {
  4988. Db::rollBack();
  4989. return Result::error("添加失败");
  4990. }
  4991. }
  4992. Db::commit();
  4993. $result = [
  4994. 'job_id' => $jobId,
  4995. 'company_id' => $companyId,
  4996. ];
  4997. return Result::success($result);
  4998. } catch (\Exception $e) {
  4999. Db::rollBack();
  5000. return Result::error($e->getMessage(), 0);
  5001. }
  5002. // return Result::success($result);
  5003. }
  5004. /*
  5005. * 获取招聘信息详情
  5006. * */
  5007. public function getJobRecruitingInfo(array $data): array
  5008. {
  5009. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5010. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5011. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5012. ->select(
  5013. 'job_recruiting.*',
  5014. 'website.website_name as website_name',
  5015. 'job_company.business_name',
  5016. 'job_company.company_hy_id',
  5017. 'job_company.company_size',
  5018. 'job_company.company_nature',
  5019. 'job_company.introduction',
  5020. 'job_company.real_name',
  5021. 'job_company.mobile',
  5022. 'job_company.company_url',
  5023. 'job_company.address_arr_id',
  5024. 'job_company.address',
  5025. 'job_company.email'
  5026. )
  5027. ->first();
  5028. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5029. if (!empty($cityId)) {
  5030. if (isset($cityId[1]) && $cityId[1] != null) {
  5031. $city = District::where('id', $cityId[1])->first(['name']);
  5032. } else {
  5033. $city = District::where('id', $cityId[0])->first(['name']);
  5034. }
  5035. $result['city'] = $city['name'] ?? '';
  5036. }
  5037. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5038. if (is_array($addressId) && !empty($addressId)) {
  5039. $address = District::whereIn('id', $addressId)
  5040. ->orderBy('level', 'asc')
  5041. ->get(['name'])
  5042. ->pluck('name')
  5043. ->implode('');
  5044. // $job->address_name = $address ?? '';
  5045. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5046. }
  5047. if (empty($result)) {
  5048. return Result::error("招聘信息不存在", 0);
  5049. }
  5050. // return Result::success($job);
  5051. return Result::success($result);
  5052. }
  5053. /*
  5054. * 修改招聘信息
  5055. * */
  5056. public function upJobRecruiting(array $data): array
  5057. {
  5058. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5059. // return Result::success($job);
  5060. if (empty($job)) {
  5061. return Result::error("招聘信息不存在", 0);
  5062. }
  5063. $user = User::where('id', $data['user_id'])->first();
  5064. // return Result::success($user);
  5065. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5066. return Result::error("用户不存在", 0);
  5067. }
  5068. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5069. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5070. }
  5071. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5072. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5073. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5074. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5075. // 公司地址 管理员必填
  5076. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5077. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5078. // 管理员-企业相关信息
  5079. $company = [
  5080. // 'user_id' => $data['user_id']?? null,
  5081. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5082. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5083. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5084. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5085. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5086. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5087. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5088. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5089. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5090. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5091. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5092. ];
  5093. //去掉相关企业信息
  5094. $data = array_diff_key($data, array_flip(array_keys($company)));
  5095. $jobId = $data['id'];
  5096. $web = $data['website_id'];
  5097. $data['action_id'] = $data['user_id'];
  5098. unset($data['user_id']);
  5099. unset($data['user_type']);
  5100. unset($data['id']);
  5101. unset($data['website_id']);
  5102. // return Result::success($data);
  5103. Db::beginTransaction();
  5104. try {
  5105. // 管理员修改招聘信息
  5106. if ($user['type_id'] == 10000) {
  5107. $data['website_id'] = $web;
  5108. $company['website_id'] = $data['website_id'];
  5109. $data['status'] = 1;
  5110. } else {
  5111. $data['status'] = 0;
  5112. }
  5113. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5114. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5115. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5116. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5117. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5118. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5119. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5120. // return Result::success($job);
  5121. // Db::rollBack();
  5122. // return Result::success($company);
  5123. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5124. $this->sendMessage([
  5125. 'talk_type' => 500,
  5126. 'title' => $data['title'],
  5127. 'content' => '提交了审核',
  5128. 'messageType' => 10,
  5129. ]);
  5130. }
  5131. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5132. if (empty($result['job'])) {
  5133. Db::rollBack();
  5134. return Result::error("修改招聘信息失败");
  5135. }
  5136. // 管理员修改企业相关信息
  5137. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5138. if (empty($result['company'])) {
  5139. Db::rollBack();
  5140. return Result::error("修改企业相关信息失败");
  5141. }
  5142. Db::commit();
  5143. // return Result::success($result);
  5144. } catch (\Exception $e) {
  5145. Db::rollBack();
  5146. return Result::error($e->getMessage(), 0);
  5147. }
  5148. return Result::success($result);
  5149. }
  5150. /*
  5151. * 招聘信息删除
  5152. * */
  5153. public function delJobRecruiting(array $data): array
  5154. {
  5155. $user = User::where('id', $data['user_id'])->first();
  5156. if (empty($user)) {
  5157. return Result::error("用户不存在", 0);
  5158. }
  5159. $job = JobRecruiting::where('id', $data['id'])->first();
  5160. if (empty($job)) {
  5161. return Result::error("招聘信息不存在", 0);
  5162. }
  5163. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5164. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5165. }
  5166. Db::beginTransaction();
  5167. try {
  5168. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5169. if (empty($result['job'])) {
  5170. Db::rollBack();
  5171. return Result::error("删除招聘信息失败");
  5172. }
  5173. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5174. if (empty($result['company'])) {
  5175. Db::rollBack();
  5176. return Result::error("删除企业相关信息失败");
  5177. }
  5178. Db::commit();
  5179. } catch (\Exception $e) {
  5180. Db::rollBack();
  5181. return Result::error($e->getMessage(), 0);
  5182. }
  5183. return Result::success($result);
  5184. }
  5185. /*
  5186. * 获取公司信息
  5187. * */
  5188. public function getJobCompany(array $data): array
  5189. {
  5190. $user = User::where('user.id', $data['user_id'])
  5191. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5192. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5193. ->first();
  5194. // return Result::success($user);
  5195. if (empty($user)) {
  5196. return Result::error("用户不存在", 0);
  5197. }
  5198. if ($user['type_id'] == 3) {
  5199. $result = [
  5200. // 'id' => 0,
  5201. 'user_id' => $data['user_id'],
  5202. 'website_id' => $data['website_id'],
  5203. 'business_name' => $user['business_name'], // 企业名称
  5204. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5205. 'company_nature' => $user['company_nature'], // 公司性质
  5206. 'company_size' => $user['company_size'], // 公司规模
  5207. 'introduction' => $user['introduction'], // 公司简介
  5208. 'real_name' => $user['real_name'], // 企业联系人
  5209. 'mobile' => $user['mobile'], // 企业联系电话
  5210. 'company_url' => $user['company_url'], // 企业网址
  5211. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5212. 'address' => $user['address'], // 企业地址
  5213. 'email' => $user['email'], // 企业邮箱
  5214. ];
  5215. } else {
  5216. return Result::error("用户类型错误", 0);
  5217. }
  5218. if (empty($result)) {
  5219. return Result::error("公司信息不存在", 0);
  5220. }
  5221. return Result::success($result);
  5222. }
  5223. /*
  5224. * 修改公司信息
  5225. * */
  5226. public function upJobCompany(array $data): array
  5227. {
  5228. // return Result::success($data);
  5229. $user = User::where('user.id', $data['user_id'])
  5230. ->where('user.status', 1)
  5231. ->select('user.user_name', 'user.type_id')
  5232. ->first();
  5233. if (empty($user)) {
  5234. return Result::error("用户不存在", 0);
  5235. }
  5236. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5237. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5238. $company = [
  5239. 'business_name' => $data['business_name'], // 企业名称
  5240. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5241. 'company_nature' => $data['company_nature'], // 公司性质
  5242. 'company_size' => $data['company_size'], // 公司规模
  5243. 'introduction' => $data['introduction'], // 公司简介
  5244. // 'real_name' => $data['real_name'], // 企业联系人
  5245. 'company_url' => $data['company_url'], // 企业网址
  5246. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5247. 'address' => $data['address'], // 企业详细地址
  5248. // 'email' => $data['email'], // 企业邮箱
  5249. ];
  5250. if ($user['type_id'] == 3) {
  5251. Db::beginTransaction();
  5252. try {
  5253. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5254. 'business_name' => $data['business_name'], // 企业名称
  5255. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5256. 'company_nature' => $data['company_nature'], // 公司性质
  5257. 'company_size' => $data['company_size'], // 公司规模
  5258. 'introduction' => $data['introduction'], // 公司简介
  5259. // 'real_name' => $data['real_name'], // 企业联系人
  5260. 'company_url' => $data['company_url'], // 企业网址
  5261. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5262. 'address' => $data['address'], // 企业详细地址
  5263. ]);
  5264. if (empty($result['userinfo'])) {
  5265. Db::rollBack();
  5266. return Result::error('修改企业会员信息失败!');
  5267. }
  5268. $result['user'] = User::where('id', $data['user_id'])->update([
  5269. 'email' => $data['email'], // 企业邮箱
  5270. ]);
  5271. if (empty($result['user'])) {
  5272. Db::rollBack();
  5273. return Result::error('修改个人中心信息失败!');
  5274. }
  5275. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5276. if (!empty($job_company)) {
  5277. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5278. if (empty($result['job_company'])) {
  5279. Db::rollBack();
  5280. return Result::error('修改企业会员信息失败!');
  5281. }
  5282. }
  5283. Db::commit();
  5284. return Result::success($result);
  5285. } catch (\Exception $e) {
  5286. Db::rollBack();
  5287. return Result::error($e->getMessage(), 0);
  5288. }
  5289. } else {
  5290. return Result::error("用户类型错误", 0);
  5291. }
  5292. }
  5293. /*
  5294. * 获取省-市
  5295. * */
  5296. public function getJobRecruitingArea(array $data): array
  5297. {
  5298. if (isset($data['pid']) && $data['pid'] != null) {
  5299. $result = District::where('pid', $data['pid'])->get()->all();
  5300. } else {
  5301. $result = District::where('level', 1)->get()->all();
  5302. }
  5303. if (empty($result)) {
  5304. return Result::error("暂无此省市", 0);
  5305. }
  5306. return Result::success($result);
  5307. }
  5308. /*
  5309. * 获取行业分类
  5310. * */
  5311. public function getIndustry(array $data): array
  5312. {
  5313. $result = JobIndustry::get()->all();
  5314. if (empty($result)) {
  5315. return Result::error("暂无行业分类", 0);
  5316. }
  5317. return Result::success($result);
  5318. }
  5319. /*
  5320. * 获取职位
  5321. * */
  5322. public function getPositionList(array $data): array
  5323. {
  5324. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5325. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5326. } else {
  5327. $result = JobPosition::where('zwpid', 0)->get()->all();
  5328. }
  5329. if (empty($result)) {
  5330. return Result::error("暂无此职位", 0);
  5331. }
  5332. return Result::success($result);
  5333. }
  5334. /*
  5335. * 获取工作性质-菜单
  5336. * */
  5337. public function getJobNature(array $data): array
  5338. {
  5339. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5340. if (empty($result)) {
  5341. return Result::error("暂无工作性质", 0);
  5342. }
  5343. return Result::success($result);
  5344. }
  5345. /*
  5346. * 获取工作经验-菜单
  5347. * */
  5348. public function getExperience(array $data): array
  5349. {
  5350. $result = JobEnum::where('egroup', 'years')->get()->all();
  5351. if (empty($result)) {
  5352. return Result::error("暂无工作经验", 0);
  5353. }
  5354. return Result::success($result);
  5355. }
  5356. /*
  5357. * 获取学历-菜单
  5358. * */
  5359. public function getEducation(array $data): array
  5360. {
  5361. $result = JobEnum::where('egroup', 'education')->get()->all();
  5362. if (empty($result)) {
  5363. return Result::error("暂无学历", 0);
  5364. }
  5365. return Result::success($result);
  5366. }
  5367. /*
  5368. * 获取薪资-菜单
  5369. * */
  5370. public function getSalary(array $data): array
  5371. {
  5372. $result = JobEnum::where('egroup', 'income')->get()->all();
  5373. if (empty($result)) {
  5374. return Result::error("暂无薪资", 0);
  5375. }
  5376. return Result::success($result);
  5377. }
  5378. /*
  5379. * 获取语言-菜单
  5380. * */
  5381. public function getLanguage(array $data): array
  5382. {
  5383. $result = JobEnum::where('egroup', 'language')->get()->all();
  5384. if (empty($result)) {
  5385. return Result::error("暂无语言", 0);
  5386. }
  5387. return Result::success($result);
  5388. }
  5389. /*
  5390. * 获取掌握程度-菜单
  5391. * */
  5392. public function getLevel(array $data): array
  5393. {
  5394. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5395. if (empty($result)) {
  5396. return Result::error("暂无工作性质", 0);
  5397. }
  5398. return Result::success($result);
  5399. }
  5400. // 公司信息
  5401. /*
  5402. * 获取公司性质-菜单
  5403. * */
  5404. public function getCompanyNature(array $data): array
  5405. {
  5406. $result = JobNature::get()->all();
  5407. if (empty($result)) {
  5408. return Result::error("暂无公司性质", 0);
  5409. }
  5410. return Result::success($result);
  5411. }
  5412. /*
  5413. * 获取公司规模-菜单
  5414. * */
  5415. public function getCompanySize(array $data): array
  5416. {
  5417. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5418. if (empty($result)) {
  5419. return Result::error("暂无公司规模", 0);
  5420. }
  5421. return Result::success($result);
  5422. }
  5423. /*
  5424. * 招聘信息审核
  5425. * */
  5426. public function checkJobRecruiting(array $data): array
  5427. {
  5428. $user = User::where('id', $data['user_id'])->first();
  5429. if (empty($user)) {
  5430. return Result::error("用户不存在", 0);
  5431. }
  5432. $job = JobRecruiting::where('id', $data['id'])->first();
  5433. if (empty($job)) {
  5434. return Result::error("招聘信息不存在", 0);
  5435. }
  5436. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5437. if ($user['type_id'] != 10000) {
  5438. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5439. }
  5440. // 驳回原因
  5441. if ($data['status'] == 2) {
  5442. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5443. }
  5444. $data['action_id'] = $data['user_id'];
  5445. unset($data['user_id']);
  5446. if ($data['status'] == 1) {
  5447. $this->sendMessage([
  5448. 'talk_type' => 501,
  5449. 'title' => $job['title'],
  5450. 'content' => '审核通过',
  5451. 'messageType' => 10,
  5452. 'user_id' => $job['user_id'],
  5453. ]);
  5454. }
  5455. if ($data['status'] == 2) {
  5456. $this->sendMessage([
  5457. 'talk_type' => 501,
  5458. 'title' => $job['title'],
  5459. 'content' => '审核拒绝',
  5460. 'messageType' => 10,
  5461. 'user_id' => $job['user_id'],
  5462. ]);
  5463. }
  5464. if ($data['status'] == 0) {
  5465. $this->sendMessage([
  5466. 'talk_type' => 500,
  5467. 'title' => $job['title'],
  5468. 'content' => '提交了审核',
  5469. 'messageType' => 10,
  5470. ]);
  5471. }
  5472. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5473. if (empty($result)) {
  5474. return Result::error("审核失败", 0);
  5475. }
  5476. return Result::success($result);
  5477. }
  5478. public function myApplyList(array $data): array
  5479. {
  5480. var_dump($data, '------参数');
  5481. $user = User::where('id', $data['user_id'])->first();
  5482. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5483. return Result::error("用户不存在", 0);
  5484. }
  5485. // 1:个人会员 职场机会
  5486. if ($user['type_id'] == 1) {
  5487. $where['user_id'] = $user['id'];
  5488. }
  5489. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5490. $query->where('user_id', $user['id']);
  5491. })
  5492. ->pluck('recruit_id');
  5493. $where = [];
  5494. if (isset($data['salary']) && $data['salary'] != null) {
  5495. $where['job_recruiting.salary'] = $data['salary'];
  5496. }
  5497. if (isset($data['experience']) && $data['experience'] != null) {
  5498. $where['job_recruiting.experience'] = $data['experience'];
  5499. }
  5500. if (isset($data['business_name']) && $data['business_name'] != null) {
  5501. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5502. }
  5503. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5504. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5505. ->where($where);
  5506. // ->count();
  5507. $count = $query->count();
  5508. $query = clone $query;
  5509. $job = $query
  5510. ->leftJoin('job_enum as income_enum', function ($join) {
  5511. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5512. ->where('income_enum.egroup', 'income');
  5513. })
  5514. ->leftJoin('job_enum as years_enum', function ($join) {
  5515. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5516. ->where('years_enum.egroup', 'years');
  5517. })
  5518. // ->where($where)
  5519. ->orderBy('job_recruiting.updated_at', 'desc')
  5520. ->select(
  5521. 'job_recruiting.id',
  5522. 'job_recruiting.title',
  5523. 'job_company.business_name',
  5524. 'income_enum.evalue as salary_evalue',
  5525. 'income_enum.ename as salary_ename',
  5526. 'years_enum.evalue as experience_evalue',
  5527. 'years_enum.ename as experience_ename',
  5528. 'job_recruiting.updated_at'
  5529. )
  5530. ->offset(($data['page'] - 1) * $data['pageSize'])
  5531. ->limit($data['pageSize'])
  5532. ->get()
  5533. ->all();
  5534. if (empty($job)) {
  5535. return Result::error("暂无招聘信息", 0);
  5536. }
  5537. $result = [
  5538. 'row' => $job,
  5539. 'count' => $count,
  5540. ];
  5541. return Result::success($result);
  5542. }
  5543. public function readJobApply(array $data): array
  5544. {
  5545. $result = JobApply::where('id', $data['id'])->first();
  5546. if (empty($result)) {
  5547. return Result::error("查询失败", 0);
  5548. }
  5549. $result = JobApply::where('id', $data['id'])->update([
  5550. 'status' => 2,
  5551. ]);
  5552. return Result::success($result);
  5553. }
  5554. /*
  5555. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5556. * */
  5557. public function getRecruitingList(array $data): array
  5558. {
  5559. $user = User::where('id', $data['user_id'])->first();
  5560. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5561. return Result::error("用户不存在", 0);
  5562. }
  5563. // 1:个人会员 职场机会
  5564. if ($user['type_id'] == 1) {
  5565. $where['user_id'] = $user['id'];
  5566. }
  5567. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5568. $query->where('receiver_id', $user['id']);
  5569. })
  5570. ->pluck('recruit_id');
  5571. // return Result::success($recruitingId);
  5572. $where = [];
  5573. if (isset($data['salary']) && $data['salary'] != null) {
  5574. $where['job_recruiting.salary'] = $data['salary'];
  5575. }
  5576. if (isset($data['experience']) && $data['experience'] != null) {
  5577. $where['job_recruiting.experience'] = $data['experience'];
  5578. }
  5579. if (isset($data['business_name']) && $data['business_name'] != null) {
  5580. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5581. }
  5582. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5583. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5584. ->where($where);
  5585. // ->count();
  5586. $count = $query->count();
  5587. $query = clone $query;
  5588. $job = $query
  5589. ->leftJoin('job_enum as income_enum', function ($join) {
  5590. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5591. ->where('income_enum.egroup', 'income');
  5592. })
  5593. ->leftJoin('job_enum as years_enum', function ($join) {
  5594. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5595. ->where('years_enum.egroup', 'years');
  5596. })
  5597. // ->where($where)
  5598. ->orderBy('job_recruiting.updated_at', 'desc')
  5599. ->select(
  5600. 'job_recruiting.id',
  5601. 'job_recruiting.title',
  5602. 'job_company.business_name',
  5603. 'income_enum.evalue as salary_evalue',
  5604. 'income_enum.ename as salary_ename',
  5605. 'years_enum.evalue as experience_evalue',
  5606. 'years_enum.ename as experience_ename',
  5607. 'job_recruiting.updated_at'
  5608. )
  5609. ->offset(($data['page'] - 1) * $data['pageSize'])
  5610. ->limit($data['pageSize'])
  5611. ->get()
  5612. ->all();
  5613. if (empty($job)) {
  5614. return Result::error("暂无招聘信息", 0);
  5615. }
  5616. $result = [
  5617. 'row' => $job,
  5618. 'count' => $count,
  5619. ];
  5620. return Result::success($result);
  5621. }
  5622. /*
  5623. * 获取企业会员-招聘信息列表
  5624. * */
  5625. public function getRecruitingInfo(array $data): array
  5626. {
  5627. $user = User::where('id', $data['user_id'])->first();
  5628. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5629. return Result::error("用户不存在", 0);
  5630. }
  5631. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5632. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5633. ->select(
  5634. 'job_recruiting.*',
  5635. 'job_company.business_name',
  5636. 'job_company.company_hy_id',
  5637. 'job_company.company_size',
  5638. 'job_company.company_nature',
  5639. 'job_company.introduction',
  5640. 'job_company.real_name',
  5641. 'job_company.mobile',
  5642. 'job_company.company_url',
  5643. 'job_company.address_arr_id',
  5644. 'job_company.address',
  5645. 'job_company.email'
  5646. )
  5647. ->get();
  5648. if (empty($recruiting)) {
  5649. return Result::error("暂无招聘信息", 0);
  5650. }
  5651. return Result::success($recruiting);
  5652. }
  5653. /*
  5654. * 获取企业会员-我的沟通
  5655. * */
  5656. public function getJobResumeList(array $data): array
  5657. {
  5658. $user = User::where('id', $data['user_id'])->first();
  5659. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5660. return Result::error("用户不存在", 0);
  5661. }
  5662. $where = [];
  5663. if (isset($data['salary']) && $data['salary'] != null) {
  5664. $where['job_hunting.salary'] = $data['salary'];
  5665. }
  5666. if (isset($data['user_name']) && $data['user_name'] != null) {
  5667. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5668. }
  5669. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5670. $query->where('job_resume.user_id', $user['id']);
  5671. })
  5672. ->when(!empty($where), function ($query) use ($where) {
  5673. $query->where($where);
  5674. })
  5675. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5676. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5677. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5678. ->select('job_resume.hunt_id', 'job_resume.recruit_id', 'job_hunting.id', 'job_hunting.salary', 'job_hunting.city_id', 'job_hunting.updated_at', 'job_recruiting.jtzw_id', 'user.user_name');
  5679. $count = $job->count();
  5680. if ($count == 0) {
  5681. return Result::error("暂无沟通记录", 0);
  5682. }
  5683. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5684. ->offset(($data['page'] - 1) * $data['pageSize'])
  5685. ->limit($data['pageSize'])
  5686. ->get();
  5687. if (empty($jobs)) {
  5688. return Result::error("暂无沟通记录", 0);
  5689. }
  5690. $result['row'] = $this->processJob($jobs, '');
  5691. $result['count'] = $count;
  5692. return Result::success($result);
  5693. }
  5694. public function readJobResume(array $data): array
  5695. {
  5696. $result = JobResume::where('id', $data['id'])->first();
  5697. if (empty($result)) {
  5698. return Result::error("查询失败", 0);
  5699. }
  5700. $result = JobResume::where('id', $data['id'])->update([
  5701. 'status' => 2,
  5702. ]);
  5703. return Result::success($result);
  5704. }
  5705. // 20250306 招聘
  5706. //20250422 书刊音像
  5707. public function addBook(array $data): array
  5708. {
  5709. $user_id = $data['user_id'] ?? 0;
  5710. $type_id = $data['type_id'] ?? 0;
  5711. // $website_id = $data['website_id'] ?? 0;
  5712. // unset($data['user_id']);
  5713. unset($data['type_id']);
  5714. // unset($data['website_id']);
  5715. //处理数组
  5716. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5717. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5718. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5719. if ($data['img_url'] == '') {
  5720. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5721. preg_match_all($reg, $data['detail'], $matches);
  5722. if (isset($matches[1][0])) {
  5723. //截取varchar240
  5724. $data['img_url'] = substr($matches[1][0], 0, 240);
  5725. }
  5726. }
  5727. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5728. //提取标题+内容中的关键词
  5729. $data['keyword'] = $data['title'];
  5730. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5731. Jieba::init(); // 初始化 jieba-php
  5732. Finalseg::init();
  5733. $segList = Jieba::cut($data['keyword']);
  5734. $segList1 = array_slice($segList, 0, 8);
  5735. $data['keyword'] = implode(',', $segList1);
  5736. }
  5737. if ($data['description'] == '') {
  5738. //提取内容中的描述
  5739. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5740. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5741. }
  5742. var_dump($data, '--');
  5743. if ($data['status'] == 1) {
  5744. $this->sendMessage([
  5745. 'talk_type' => 400,
  5746. 'title' => $data['title'],
  5747. 'content' => '提交了审核',
  5748. 'messageType' => 7,
  5749. ]);
  5750. }
  5751. $result = Book::insertGetId($data);
  5752. if (empty($result)) {
  5753. return Result::error("添加失败", 0);
  5754. }
  5755. return Result::success($result);
  5756. }
  5757. public function getBookList(array $data): array
  5758. {
  5759. $where = [];
  5760. if (!empty($data["title"])) {
  5761. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5762. }
  5763. if (!empty($data['website_name'])) {
  5764. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5765. }
  5766. if (!empty($data['status'])) {
  5767. $where[] = ['book.status', '=', $data['status']];
  5768. }
  5769. $user_id = $data['user_id'];
  5770. $type_id = $data['type_id'];
  5771. // $type_id = 4;
  5772. var_dump($type_id, '------1--------');
  5773. if ($type_id != 10000) {
  5774. $where[] = ['book.user_id', '=', $user_id];
  5775. }
  5776. var_dump(!empty($data['status1']), '=-===1');
  5777. $result = Book::where($where)
  5778. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5779. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5780. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5781. ->when(isset($data['status1']), function ($query) use ($data) {
  5782. $query->whereIn('book.status', [1, 3]);
  5783. })
  5784. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5785. ->orderBy("updated_at", "desc")
  5786. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5787. if (empty($result)) {
  5788. return Result::error("暂无数据", 0);
  5789. }
  5790. // 取出数据
  5791. $rows = $result->items();
  5792. $count = $result->total();
  5793. $responseData = [
  5794. 'rows' => $rows,
  5795. 'count' => $count,
  5796. ];
  5797. return Result::success($responseData);
  5798. }
  5799. public function deleteBook(array $data): array
  5800. {
  5801. $result = Book::where('id', $data['id'])->delete();
  5802. if (empty($result)) {
  5803. return Result::error("删除失败", 0);
  5804. }
  5805. return Result::success($result);
  5806. }
  5807. public function updateBook(array $data): array
  5808. {
  5809. // $user_id = $data['user_id'] ?? 0;
  5810. $type_id = $data['type_id'] ?? 0;
  5811. // $website_id = $data['website_id'] ?? 0;
  5812. unset($data['user_id']);
  5813. unset($data['type_id']);
  5814. // unset($data['website_id']);
  5815. //处理数组
  5816. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5817. if ($data['img_url'] == '') {
  5818. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5819. preg_match_all($reg, $data['detail'], $matches);
  5820. if (isset($matches[1][0])) {
  5821. //截取varchar240
  5822. $data['img_url'] = substr($matches[1][0], 0, 240);
  5823. }
  5824. }
  5825. if ($data['keyword'] == '') {
  5826. //提取标题+内容中的关键词
  5827. $data['keyword'] = $data['title'];
  5828. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5829. Jieba::init(); // 初始化 jieba-php
  5830. Finalseg::init();
  5831. $segList = Jieba::cut($data['keyword']);
  5832. $segList1 = array_slice($segList, 0, 8);
  5833. $data['keyword'] = implode(',', $segList1);
  5834. }
  5835. if ($data['description'] == '') {
  5836. //提取内容中的描述
  5837. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5838. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5839. }
  5840. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5841. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5842. if ($data['status'] == 1) {
  5843. $this->sendMessage([
  5844. 'talk_type' => 400,
  5845. 'title' => $data['title'],
  5846. 'content' => '提交了审核',
  5847. 'messageType' => 7,
  5848. ]);
  5849. }
  5850. $result = Book::where("id", $data["id"])->update($data);
  5851. if (empty($result)) {
  5852. return Result::error("更新失败", 0);
  5853. }
  5854. return Result::success($result);
  5855. }
  5856. public function getBookInfo(array $data): array
  5857. {
  5858. $result = Book::where("id", $data["id"])->first();
  5859. if (empty($result)) {
  5860. return Result::error("获取失败", 0);
  5861. }
  5862. return Result::success($result);
  5863. }
  5864. public function updateBookStatus(array $data): array
  5865. {
  5866. //审核
  5867. unset($data['user_id']);
  5868. $bookInfo = Book::where("id", $data["id"])->first();
  5869. var_dump($bookInfo, '----');
  5870. if ($data['status'] == 2) {
  5871. $this->sendMessage([
  5872. 'talk_type' => 401,
  5873. 'title' => $bookInfo['title'],
  5874. 'content' => '审核通过',
  5875. 'messageType' => 7,
  5876. 'user_id' => $bookInfo['user_id'],
  5877. ]);
  5878. }
  5879. if ($data['status'] == 3) {
  5880. $this->sendMessage([
  5881. 'talk_type' => 401,
  5882. 'title' => $bookInfo['title'],
  5883. 'content' => '审核拒绝',
  5884. 'messageType' => 7,
  5885. 'user_id' => $bookInfo['user_id'],
  5886. ]);
  5887. }
  5888. if ($data['status'] == 1) {
  5889. $this->sendMessage([
  5890. 'talk_type' => 400,
  5891. 'title' => $bookInfo['title'],
  5892. 'content' => '提交了审核',
  5893. 'messageType' => 7,
  5894. // 'user_id'=>$bookInfo['user_id'],
  5895. ]);
  5896. }
  5897. $result = Book::where("id", $data["id"])->update($data);
  5898. if (empty($result)) {
  5899. return Result::error("更新失败", 0);
  5900. }
  5901. return Result::success($result);
  5902. }
  5903. //20250422 书刊音像
  5904. /**
  5905. * 贴身宝贝
  5906. * @param array $data
  5907. * @return array
  5908. */
  5909. public function getWebsiteTsbb(array $data): array
  5910. {
  5911. $month = $data['month'] ?? date('m');
  5912. $day = $data['day'] ?? date('d');
  5913. // 使用缓存键
  5914. $cacheKey = "tsbb_data_{$month}_{$day}";
  5915. // 尝试从缓存获取数据
  5916. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5917. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5918. if ($cachedData = $cache->get($cacheKey)) {
  5919. return Result::success(unserialize($cachedData));
  5920. }
  5921. //查询老黄历
  5922. try {
  5923. $date = date('Y-m-d');
  5924. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5925. // 使用 curl 替代 file_get_contents
  5926. $ch = curl_init();
  5927. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5928. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5929. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5930. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5931. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5932. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
  5933. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5934. 'Accept: application/json',
  5935. 'Content-Type: application/json',
  5936. 'Referer: https://www.36jxs.com/'
  5937. ]);
  5938. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5939. curl_setopt($ch, CURLOPT_ENCODING, '');
  5940. $almanacResponse = curl_exec($ch);
  5941. var_dump("====:", $almanacResponse);
  5942. if (curl_errno($ch)) {
  5943. var_dump('Curl error:', curl_error($ch));
  5944. throw new \Exception('Curl error: ' . curl_error($ch));
  5945. }
  5946. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5947. curl_close($ch);
  5948. if ($almanacResponse === false) {
  5949. throw new \Exception('Failed to fetch almanac data');
  5950. }
  5951. $almanacData = json_decode($almanacResponse, true);
  5952. if (json_last_error() !== JSON_ERROR_NONE) {
  5953. throw new \Exception('Failed to parse almanac data');
  5954. }
  5955. $almanacInfo = $almanacData['data'] ?? [];
  5956. } catch (\Exception $e) {
  5957. var_dump('Exception:', $e->getMessage());
  5958. $almanacInfo = [];
  5959. }
  5960. // 获取历史上的今天数据
  5961. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5962. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5963. ->orderBy('year', 'asc')
  5964. ->select("title", "id", "year", DB::raw('1 as type'))
  5965. ->limit(16)
  5966. ->get();
  5967. // 获取节日数据 - 从今天开始获取未来4条
  5968. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5969. ->orderBy('showtime', 'asc')
  5970. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5971. ->limit(16)
  5972. ->get();
  5973. //说文解字
  5974. $chartacterList = Character::orderBy('updated_at', 'desc')
  5975. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5976. ->limit(6)
  5977. ->get();
  5978. //谜语沙龙
  5979. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5980. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5981. ->limit(4)
  5982. ->get();
  5983. //成语欣赏
  5984. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5985. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5986. ->limit(32)
  5987. ->get();
  5988. //名联赏析
  5989. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5990. ->select("id", "first", "second", DB::raw('6 as type'))
  5991. ->limit(6)
  5992. ->get();
  5993. // 获取分类文章数据
  5994. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5995. ->pluck('category_id')
  5996. ->toArray();
  5997. $articlesList = [];
  5998. foreach ($categoryIds as $catid) {
  5999. // 先查有图片的
  6000. $withImg = DB::table('article')
  6001. ->where('status', 1)
  6002. ->where('catid', $catid)
  6003. ->whereNotNull('imgurl')
  6004. ->where('imgurl', '!=', '')
  6005. ->orderBy('updated_at', 'desc')
  6006. ->limit(6)
  6007. ->get();
  6008. $count = $withImg->count();
  6009. if ($count < 6) {
  6010. // 不足6条再查无图片的补足
  6011. $withoutImg = DB::table('article')
  6012. ->where('status', 1)
  6013. ->where('catid', $catid)
  6014. ->where(function ($q) {
  6015. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6016. })
  6017. ->orderBy('updated_at', 'desc')
  6018. ->limit(6 - $count)
  6019. ->get();
  6020. $articles = $withImg->concat($withoutImg);
  6021. } else {
  6022. $articles = $withImg;
  6023. }
  6024. // 组装
  6025. $category = \App\Model\Category::find($catid);
  6026. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6027. $articlesList[] = [
  6028. 'category_name' => $category ? $category->name : '',
  6029. 'catid' => $catid,
  6030. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6031. 'type' => 100,
  6032. 'list' => $articles->map(function ($item) {
  6033. return [
  6034. 'id' => $item->id,
  6035. 'title' => $item->title,
  6036. 'imgurl' => $item->imgurl,
  6037. 'created_at' => $item->created_at
  6038. ];
  6039. })->values()
  6040. ];
  6041. }
  6042. $result = [
  6043. 'almanac' => $almanacInfo,
  6044. 'historyTodayList' => [
  6045. 'category_name' => '历史上的今天',
  6046. 'list' => $historyTodayList,
  6047. 'type' => 1
  6048. ],
  6049. 'festivalList' => [
  6050. 'category_name' => '节日预告',
  6051. 'list' => $festivalList,
  6052. 'type' => 2
  6053. ],
  6054. 'chartacterList' => [
  6055. 'category_name' => '说文解字',
  6056. 'list' => $chartacterList,
  6057. 'type' => 3
  6058. ],
  6059. 'coupletList' => [
  6060. 'category_name' => '名联赏析',
  6061. 'list' => $coupletList,
  6062. 'type' => 6
  6063. ],
  6064. 'riddletList' => [
  6065. 'category_name' => '谜语沙龙',
  6066. 'list' => $riddletList,
  6067. 'type' => 4
  6068. ],
  6069. 'idiomList' => [
  6070. 'category_name' => '成语欣赏',
  6071. 'list' => $idiomList,
  6072. 'type' => 5
  6073. ],
  6074. 'articlesList' => $articlesList
  6075. ];
  6076. // 缓存结果,设置1小时过期
  6077. $cache->set($cacheKey, serialize($result), 3600);
  6078. return Result::success($result);
  6079. }
  6080. /**
  6081. * 获取资讯列表
  6082. */
  6083. public function getWebsiteTsbbList(array $data): array
  6084. {
  6085. $page = $data['page'] ?? 1;
  6086. $pageSize = $data['pageSize'] ?? 10;
  6087. // 如果没有传入月份和日期,则使用今天的日期
  6088. $month = $data['month'] ?? date('m');
  6089. $day = $data['day'] ?? date('d');
  6090. $total = 0;
  6091. $result = [];
  6092. $data['type'] = intval($data['type']);
  6093. var_dump("接收参数:", $data);
  6094. switch ($data['type']) {
  6095. case 1:
  6096. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6097. // 当前月份之后的数据
  6098. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6099. // 或者当前月份且日期大于等于当前日期的数据
  6100. ->orWhere(function ($q) use ($month, $day) {
  6101. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6102. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6103. });
  6104. })
  6105. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6106. $total = $query->count();
  6107. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6108. ->offset(($page - 1) * $pageSize)
  6109. ->limit($pageSize)
  6110. ->get();
  6111. break;
  6112. case 2:
  6113. $query = Festival::where(function ($q) use ($month, $day) {
  6114. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6115. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6116. ->orWhere(function ($q) use ($month, $day) {
  6117. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6118. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6119. });
  6120. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6121. $total = $query->count();
  6122. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6123. ->offset(($page - 1) * $pageSize)
  6124. ->limit($pageSize)
  6125. ->get();
  6126. break;
  6127. case 3:
  6128. $query = Character::orderBy("updated_at", "desc");
  6129. $total = $query->count();
  6130. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6131. ->offset(($page - 1) * $pageSize)
  6132. ->limit($pageSize)
  6133. ->get();
  6134. break;
  6135. case 4:
  6136. $query = Riddle::orderBy("updated_at", "desc");
  6137. $total = $query->count();
  6138. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6139. ->offset(($page - 1) * $pageSize)
  6140. ->limit($pageSize)
  6141. ->get();
  6142. break;
  6143. case 5:
  6144. $query = Idiom::orderBy("updated_at", "desc");
  6145. $total = $query->count();
  6146. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6147. ->offset(($page - 1) * $pageSize)
  6148. ->limit($pageSize)
  6149. ->get();
  6150. break;
  6151. case 6:
  6152. $query = Couplet::orderBy("updated_at", "desc");
  6153. $total = $query->count();
  6154. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6155. ->offset(($page - 1) * $pageSize)
  6156. ->limit($pageSize)
  6157. ->get();
  6158. break;
  6159. default:
  6160. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6161. $total = $query->count();
  6162. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6163. ->offset(($page - 1) * $pageSize)
  6164. ->limit($pageSize)
  6165. ->get();
  6166. }
  6167. return Result::success([
  6168. 'list' => $result,
  6169. 'total' => $total,
  6170. 'page' => (int)$page,
  6171. 'pageSize' => (int)$pageSize,
  6172. 'month' => $month,
  6173. 'day' => $day
  6174. ]);
  6175. }
  6176. /**
  6177. * 1:历史上的今天
  6178. * 2:节日
  6179. * 3:文章
  6180. *
  6181. * 资讯详情信息
  6182. */
  6183. public function getWebsiteTsbbDetail(array $data): array
  6184. {
  6185. $data['type'] = intval($data['type']);
  6186. switch ($data['type']) {
  6187. case 1:
  6188. $result = HistoryToday::where("id", $data['id'])->first();
  6189. break;
  6190. case 2:
  6191. $result = Festival::where("id", $data['id'])->first();
  6192. break;
  6193. case 3:
  6194. $result = Character::where("id", $data['id'])->first();
  6195. break;
  6196. case 4:
  6197. $result = Riddle::where("id", $data['id'])->first();
  6198. break;
  6199. case 5:
  6200. $result = Idiom::where("id", $data['id'])->first();
  6201. break;
  6202. case 6:
  6203. $result = Couplet::where("id", $data['id'])->first();
  6204. break;
  6205. default:
  6206. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6207. break;
  6208. }
  6209. return Result::success($result);
  6210. }
  6211. /**
  6212. * 农网导航首页数据
  6213. */
  6214. public function getWebsiteNwHomeList(array $data): array
  6215. {
  6216. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6217. ->pluck('category_id')
  6218. ->toArray();
  6219. // 使用子查询优化
  6220. $articlesList = DB::table('article')
  6221. ->select([
  6222. 'article.id',
  6223. 'article.title',
  6224. 'article.imgurl',
  6225. 'article.created_at',
  6226. 'category.name as category_name',
  6227. 'category.id as category_id',
  6228. 'website_category.aLIas_pinyin as pinyin',
  6229. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6230. DB::raw('100 as type')
  6231. ])
  6232. ->join('category', 'article.catid', '=', 'category.id')
  6233. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6234. ->leftJoin('website_category as parent_wc', function ($join) {
  6235. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6236. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6237. })
  6238. ->where('website_category.website_id', $data['website_id'])
  6239. ->where('article.status', 1)
  6240. ->whereIn('category.id', $categoryIds)
  6241. ->orderBy('article.created_at', 'desc')
  6242. ->get()
  6243. ->groupBy('category_id')
  6244. ->map(function ($group) {
  6245. // 确保第一条数据有图片
  6246. $firstWithImage = $group->first(function ($item) {
  6247. return !empty($item->imgurl);
  6248. });
  6249. if ($firstWithImage) {
  6250. // 如果有带图片的文章,将其放在第一位
  6251. $group = $group->filter(function ($item) use ($firstWithImage) {
  6252. return $item->id !== $firstWithImage->id;
  6253. })->prepend($firstWithImage);
  6254. }
  6255. return [
  6256. 'category_name' => $group->first()->category_name,
  6257. 'catid' => $group->first()->category_id,
  6258. 'pinyin' => $group->first()->pinyin,
  6259. 'parent_pinyin' => $group->first()->parent_pinyin,
  6260. 'list' => $group->take(4)->map(function ($item) {
  6261. return [
  6262. 'id' => $item->id,
  6263. 'title' => $item->title,
  6264. ];
  6265. })->values()
  6266. ];
  6267. })
  6268. ->values()
  6269. ->toArray();
  6270. return Result::success($articlesList);
  6271. }
  6272. /**
  6273. * 企业管理
  6274. * @param array $data
  6275. * @return array
  6276. */
  6277. public function getCompanyList(array $data): array
  6278. {
  6279. // return Result::success($data);
  6280. $where = [];
  6281. $user = User::where('id', $data['user_id'])->first();
  6282. if (empty($user)) {
  6283. return Result::error('用户不存在!');
  6284. }
  6285. if ($user['type_id'] != 10000) {
  6286. $where['user_id'] = $data['user_id'];
  6287. }
  6288. if (isset($data['title']) && !empty($data['title'])) {
  6289. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6290. }
  6291. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6292. array_push($where, ['website.id', $data['website_id']]);
  6293. }
  6294. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6295. if ($data['ischeck'] == 1) {
  6296. if (isset($data['status']) && $data['status'] != '') {
  6297. array_push($where, ['company.status', $data['status']]);
  6298. $query = Company::where($where);
  6299. } else {
  6300. $query = Company::whereIn('company.status', [0, 2]);
  6301. }
  6302. } else {
  6303. $query = Company::where('company.status', 1);
  6304. }
  6305. }
  6306. $result = $query->where($where)
  6307. ->leftJoin('website_category', function ($query) {
  6308. $query->on('website_category.category_id', '=', 'company.category_id')
  6309. ->on('website_category.website_id', '=', 'company.website_id');
  6310. })
  6311. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6312. ->select(
  6313. 'company.id',
  6314. 'company.title',
  6315. 'company.website_id',
  6316. 'company.category_id',
  6317. 'website.website_name',
  6318. 'website_category.alias as category_name',
  6319. 'company.status',
  6320. 'company.updated_at',
  6321. 'company.user_id'
  6322. )
  6323. ->orderBy('company.updated_at', 'desc')
  6324. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6325. if ($result->isEmpty()) {
  6326. return Result::error("暂无企业", 0);
  6327. }
  6328. return Result::success($result);
  6329. }
  6330. /**
  6331. * 添加企业
  6332. * @param array $data
  6333. * @return array
  6334. */
  6335. public function addCompany(array $data): array
  6336. {
  6337. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6338. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6339. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6340. $data['cat_arr_id'] = json_encode($car_arr_id);
  6341. } else {
  6342. $data['cat_arr_id'] = '';
  6343. }
  6344. if ($data['imgurl'] == '') {
  6345. //content中提取图片第一个图,正则提取
  6346. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6347. preg_match_all($reg, $data['content'], $matches);
  6348. if (isset($matches[1][0])) {
  6349. //截取varchar240
  6350. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6351. }
  6352. }
  6353. if ($data['keyword'] == '') {
  6354. //提取标题+内容中的关键词
  6355. $data['keyword'] = $data['title'];
  6356. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6357. Jieba::init(); // 初始化 jieba-php
  6358. Finalseg::init();
  6359. $segList = Jieba::cut($data['keyword']);
  6360. $segList1 = array_slice($segList, 0, 8);
  6361. $data['keyword'] = implode(',', $segList1);
  6362. }
  6363. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6364. //提取内容中的描述
  6365. $content = $data['content'];
  6366. // 去除 <style> 和 <script> 标签及其内容
  6367. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6368. // 去除所有 HTML 标签
  6369. $content = strip_tags($content);
  6370. // 去除 HTML 实体
  6371. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6372. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6373. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6374. // 去除多余空白
  6375. $content = preg_replace('/\s+/u', '', $content);
  6376. // 截取 100 个字符
  6377. $data['introduce'] = mb_substr($content, 0, 100);
  6378. }
  6379. $user = User::where('id', $data['user_id'])->first();
  6380. if (empty($user)) {
  6381. return Result::error('用户不存在!');
  6382. }
  6383. if ($user['type_id'] == 10000) {
  6384. $data['status'] = 1;
  6385. }
  6386. if (isset($data['level']) && $data['level'] != null) {
  6387. $data['level'] = intval($data['level']);
  6388. } else {
  6389. $data['level'] = null;
  6390. }
  6391. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6392. $this->sendMessage([
  6393. 'talk_type' => 900,
  6394. 'title' => $data['title'],
  6395. 'content' => '提交了审核',
  6396. 'messageType' => 8,
  6397. ]);
  6398. }
  6399. $result = Company::insertGetId($data);
  6400. if ($result) {
  6401. return Result::success($result);
  6402. } else {
  6403. return Result::error('添加失败');
  6404. }
  6405. }
  6406. /**
  6407. * 更新企业
  6408. * @param array $data
  6409. * @return array
  6410. */
  6411. public function upCompany(array $data): array
  6412. {
  6413. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6414. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6415. $data['cat_arr_id'] = json_encode($car_arr_id);
  6416. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6417. } else {
  6418. $data['cat_arr_id'] = '';
  6419. }
  6420. if ($data['imgurl'] == '') {
  6421. //content中提取图片第一个图,正则提取
  6422. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6423. preg_match_all($reg, $data['content'], $matches);
  6424. if (isset($matches[1][0])) {
  6425. //截取varchar
  6426. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6427. }
  6428. }
  6429. if ($data['keyword'] == '') {
  6430. //提取标题+内容中的关键词
  6431. $data['keyword'] = $data['title'];
  6432. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6433. Jieba::init(); // 初始化 jieba-php
  6434. Finalseg::init();
  6435. $segList = Jieba::cut($data['keyword']);
  6436. $segList1 = array_slice($segList, 0, 8);
  6437. $data['keyword'] = implode(',', $segList1);
  6438. }
  6439. if ($data['introduce'] == '') {
  6440. //提取内容中的描述
  6441. $content = $data['content'];
  6442. // 去除 <style> 和 <script> 标签及其内容
  6443. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6444. // 去除所有 HTML 标签
  6445. $content = strip_tags($content);
  6446. // 去除 HTML 实体
  6447. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6448. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6449. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6450. // 去除多余空白
  6451. $content = preg_replace('/\s+/u', '', $content);
  6452. // 截取 100 个字符
  6453. $data['introduce'] = mb_substr($content, 0, 100);
  6454. }
  6455. if (isset($data['level']) && $data['level'] != null) {
  6456. $data['level'] = intval($data['level']);
  6457. } else {
  6458. $data['level'] = null;
  6459. }
  6460. $user = User::where('id', $data['user_id'])->first();
  6461. if (empty($user)) {
  6462. return Result::error('用户不存在!');
  6463. }
  6464. if ($user['type_id'] == 10000) {
  6465. $data['status'] = 1;
  6466. } else {
  6467. $data['status'] = 0;
  6468. }
  6469. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6470. $this->sendMessage([
  6471. 'talk_type' => 900,
  6472. 'title' => $data['title'],
  6473. 'content' => '提交了审核',
  6474. 'messageType' => 8,
  6475. ]);
  6476. }
  6477. $result = Company::where('id', $data['id'])->update($data);
  6478. if ($result) {
  6479. return Result::success($result);
  6480. } else {
  6481. return Result::error('修改失败');
  6482. }
  6483. }
  6484. /**
  6485. * 删除企业
  6486. * @param array $data
  6487. * @return array
  6488. */
  6489. public function delCompany(array $data): array
  6490. {
  6491. $result = Company::where('id', $data['id'])->delete();
  6492. if ($result) {
  6493. return Result::success($result);
  6494. } else {
  6495. return Result::error('删除失败');
  6496. }
  6497. }
  6498. /**
  6499. * 审核企业
  6500. * @param array $data
  6501. * @return array
  6502. */
  6503. public function checkCompany(array $data): array
  6504. {
  6505. $user = User::where('id', $data['user_id'])->first();
  6506. if (empty($user)) {
  6507. return Result::error('用户不存在!');
  6508. }
  6509. $company = Company::where('id', $data['id'])->first();
  6510. if (empty($company)) {
  6511. return Result::error('企业不存在!');
  6512. }
  6513. // 状态:0:未审核 1:已审核 2:已拒绝
  6514. if ($data['status'] == 2 || $data['status'] == '2') {
  6515. $this->sendMessage([
  6516. 'talk_type' => 901,
  6517. 'title' => $company['title'],
  6518. 'content' => '审核拒绝',
  6519. 'messageType' => 8,
  6520. 'user_id' => $company['user_id'],
  6521. ]);
  6522. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6523. } else {
  6524. if ($data['status'] == 1) {
  6525. $this->sendMessage([
  6526. 'talk_type' => 901,
  6527. 'title' => $company['title'],
  6528. 'content' => '审核通过',
  6529. 'messageType' => 8,
  6530. 'user_id' => $company['user_id'],
  6531. ]);
  6532. } else if ($data['status'] == 0) {
  6533. $this->sendMessage([
  6534. 'talk_type' => 900,
  6535. 'title' => $company['title'],
  6536. 'content' => '提交了审核',
  6537. 'messageType' => 8,
  6538. ]);
  6539. }
  6540. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6541. }
  6542. if (empty($result)) {
  6543. return Result::error('审核失败!');
  6544. } else {
  6545. return Result::success($result);
  6546. }
  6547. }
  6548. /**
  6549. * 获取企业信息
  6550. * @param array $data
  6551. * @return array
  6552. */
  6553. public function getCompanyInfo(array $data): array
  6554. {
  6555. $result = Company::where('id', $data['id'])->first();
  6556. $city_arr = json_decode($result['city_arr_id']);
  6557. $result['city_name'] = District::whereIn('id', $city_arr)
  6558. ->pluck('name')
  6559. ->implode('-');
  6560. if (empty($result)) {
  6561. return Result::error('企业不存在!');
  6562. } else {
  6563. return Result::success($result);
  6564. }
  6565. }
  6566. /**
  6567. * @param array $data
  6568. * @return array
  6569. */
  6570. public function getWebsiteCompany(array $data): array
  6571. {
  6572. $categorys = json_decode($data['id'], true);
  6573. $category_arr = $this->processArticlePro($data['website_id']);
  6574. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6575. $catiall = $category_arr['catiall'];
  6576. $categoryIds = $category_arr['categoryIds'];
  6577. // return Result::success($category_arr);
  6578. foreach ($categorys as $key => $value) {
  6579. if (array_key_exists('level', $value)) {
  6580. $parts = explode(',', $value['level']);
  6581. $level = $parts[0] ?? null;
  6582. $imgnum = $parts[1] ?? null;
  6583. $textnum = $parts[2] ?? null;
  6584. if (!empty($textnum) && $textnum > 0) {
  6585. $text_num = Company::where('level', $level)
  6586. ->whereIn('category_id', $categoryIds)
  6587. ->where('status', 1)
  6588. ->select(
  6589. 'company.id',
  6590. 'company.title',
  6591. 'company.description',
  6592. 'company.updated_at',
  6593. 'company.category_id',
  6594. 'company.cat_arr_id'
  6595. )
  6596. ->orderBy('updated_at', 'desc')
  6597. ->limit($textnum)
  6598. ->get()->all();
  6599. }
  6600. if (!empty($imgnum) && $imgnum > 0) {
  6601. $img_num = Company::where('level', $level)
  6602. ->whereIn('category_id', $categoryIds)
  6603. ->where('status', 1)
  6604. ->where('imgurl', '!=', '')
  6605. ->whereNotNull('imgurl')
  6606. ->select(
  6607. 'company.id',
  6608. 'company.title',
  6609. 'company.description',
  6610. 'company.updated_at',
  6611. 'company.imgurl as imgs',
  6612. 'company.category_id',
  6613. 'company.cat_arr_id'
  6614. )
  6615. ->orderBy('updated_at', 'desc')
  6616. ->limit($imgnum)
  6617. ->get()->all();
  6618. }
  6619. }
  6620. if (array_key_exists('id', $value)) {
  6621. $parts = explode(',', $value['id']);
  6622. $category_id = $parts[0] ?? null;
  6623. $imgnum = $parts[1] ?? null;
  6624. $textnum = $parts[2] ?? null;
  6625. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6626. if (!empty($textnum) && $textnum > 0) {
  6627. $text_num = Company::whereIn('category_id', $category_arr)
  6628. // ->where('website_id', $data['website_id'])
  6629. ->where('status', 1)
  6630. ->select(
  6631. 'company.id',
  6632. 'company.title',
  6633. 'company.description',
  6634. 'company.updated_at',
  6635. 'company.category_id',
  6636. 'company.cat_arr_id'
  6637. )
  6638. ->orderBy('updated_at', 'desc')
  6639. ->limit($textnum)
  6640. ->get()->all();
  6641. }
  6642. if (!empty($imgnum) && $imgnum > 0) {
  6643. $img_num = Company::whereIn('category_id', $category_arr)
  6644. // ->where('website_id', $data['website_id'])
  6645. ->where('status', 1)
  6646. ->where('imgurl', '!=', '')
  6647. ->whereNotNull('imgurl')
  6648. ->select(
  6649. 'company.id',
  6650. 'company.title',
  6651. 'company.description',
  6652. 'company.updated_at',
  6653. 'company.imgurl as imgs',
  6654. 'company.category_id',
  6655. 'company.cat_arr_id'
  6656. )
  6657. ->orderBy('updated_at', 'desc')
  6658. ->limit($imgnum)
  6659. ->get()->all();
  6660. }
  6661. }
  6662. if (!empty($text_num)) {
  6663. foreach ($text_num as $k => $v) {
  6664. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6665. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6666. }
  6667. }
  6668. if (!empty($img_num)) {
  6669. foreach ($img_num as $k => $v) {
  6670. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6671. $imgurl = json_decode($v['imgs'], true);
  6672. if (!empty($imgurl)) {
  6673. $img_num[$k]->imgurl = $imgurl[0];
  6674. }
  6675. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6676. }
  6677. }
  6678. $company[$key]['img_num'] = $img_num ?? [];
  6679. $company[$key]['text_num'] = $text_num ?? [];
  6680. }
  6681. if (empty($company)) {
  6682. return Result::error("暂无相关企业信息", 0);
  6683. }
  6684. return Result::success($company);
  6685. }
  6686. /**
  6687. * @param array $data
  6688. * @return array
  6689. */
  6690. public function getWebsiteCompanyList(array $data): array
  6691. {
  6692. $where['website_id'] = $data['website_id'];
  6693. $where['status'] = 1;
  6694. $categoryIds = [];
  6695. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6696. $category_id = $data['category_id'];
  6697. }
  6698. $category_arr = $this->processArticlePro($data['website_id']);
  6699. $categoryIds = $category_arr['categoryIds'];
  6700. // return Result::success($cat_1st_arr);
  6701. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6702. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6703. })
  6704. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6705. $query->whereIn('category_id', $categoryIds);
  6706. })
  6707. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6708. $query->where('category_id', $category_id);
  6709. })
  6710. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6711. ->orderBy('updated_at', 'desc')
  6712. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6713. if (empty($company)) {
  6714. return Result::error("暂无相关公司信息", 0);
  6715. }
  6716. $result = [
  6717. 'count' => $company->total(),
  6718. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6719. ];
  6720. return Result::success($result);
  6721. }
  6722. /**
  6723. * 获取项目列表
  6724. * @param array $data
  6725. * @return array
  6726. */
  6727. public function getProjectList(array $data): array
  6728. {
  6729. $where = [];
  6730. $user = User::where('id', $data['user_id'])->first();
  6731. if (empty($user)) {
  6732. return Result::error('用户不存在!');
  6733. }
  6734. if ($user->type_id != 10000) {
  6735. array_push($where, ['project.user_id', $data['user_id']]);
  6736. }
  6737. $query = Project::query();
  6738. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6739. array_push($where, ['project.website_id', $data['website_id']]);
  6740. }
  6741. if (isset($data['title']) && !empty($data['title'])) {
  6742. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6743. }
  6744. if ($data['status'] != 3) {
  6745. array_push($where, ['project.status', $data['status']]);
  6746. }
  6747. $query = Project::where($where)
  6748. ->when($data['status'] == 3, function ($query) {
  6749. $query->whereIn('project.status', [0, 2]);
  6750. });
  6751. $count = $query->clone()
  6752. ->count();
  6753. $rows = $query->clone()
  6754. ->leftJoin('website', 'project.website_id', 'website.id')
  6755. ->leftJoin('website_category', function ($join) {
  6756. $join->on('project.website_id', '=', 'website_category.website_id')
  6757. ->on('project.category_id', '=', 'website_category.category_id');
  6758. })
  6759. ->select(
  6760. 'project.id',
  6761. 'project.title',
  6762. 'project.updated_at',
  6763. 'project.status',
  6764. 'website.website_name',
  6765. 'website_category.alias as category_name',
  6766. 'project.website_id',
  6767. 'project.user_id'
  6768. )
  6769. ->orderBy('project.updated_at', 'desc')
  6770. ->offset(($data['page'] - 1) * $data['pageSize'])
  6771. ->limit($data['pageSize'])
  6772. ->get();
  6773. if ($rows->isEmpty()) {
  6774. return Result::error("暂无相关项目信息", 0);
  6775. }
  6776. $result = [
  6777. 'count' => $count,
  6778. 'rows' => $rows,
  6779. ];
  6780. return Result::success($result);
  6781. }
  6782. /**
  6783. * 添加项目
  6784. * @param array $data
  6785. * @return array
  6786. */
  6787. public function addProject(array $data): array
  6788. {
  6789. $user = User::where('id', $data['user_id'])->first();
  6790. if (empty($user)) {
  6791. return Result::error("暂无相关用户信息", 0);
  6792. }
  6793. if ($user->type_id == 10000) {
  6794. $data['status'] = 1;
  6795. } else {
  6796. $data['status'] = 0;
  6797. }
  6798. if ($data['keyword'] == '') {
  6799. //提取标题+内容中的关键词
  6800. $data['keyword'] = $data['title'];
  6801. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6802. Jieba::init(); // 初始化 jieba-php
  6803. Finalseg::init();
  6804. $segList = Jieba::cut($data['keyword']);
  6805. $segList1 = array_slice($segList, 0, 8);
  6806. $data['keyword'] = implode(',', $segList1);
  6807. }
  6808. if ($data['description'] == '') {
  6809. //提取内容中的描述
  6810. // var_dump(11111);
  6811. //提取内容中的描述
  6812. $content = $data['introduce'];
  6813. // 去除 <style> 和 <script> 标签及其内容
  6814. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6815. // 去除所有 HTML 标签
  6816. $content = strip_tags($content);
  6817. // 去除 HTML 实体
  6818. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6819. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6820. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6821. // 去除多余空白
  6822. $content = preg_replace('/\s+/u', '', $content);
  6823. // 截取 100 个字符
  6824. $data['description'] = mb_substr($content, 0, 100);
  6825. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6826. }
  6827. if ($data['status'] == 0) {
  6828. $this->sendMessage([
  6829. 'talk_type' => 1000,
  6830. 'title' => $data['title'],
  6831. 'content' => '提交了审核',
  6832. 'messageType' => 9,
  6833. ]);
  6834. }
  6835. $project = Project::insertGetId($data);
  6836. if (empty($project)) {
  6837. return Result::error("暂无相关项目信息", 0);
  6838. }
  6839. return Result::success($project);
  6840. }
  6841. /**
  6842. * 更新项目
  6843. * @param array $data
  6844. * @return array
  6845. */
  6846. public function upProject(array $data): array
  6847. {
  6848. $project = Project::where('id', $data['id'])->first();
  6849. if (empty($project)) {
  6850. return Result::error("暂无相关项目信息", 0);
  6851. }
  6852. $id = $data['id'];
  6853. unset($data['id']);
  6854. $user = User::where('id', $data['user_id'])->first();
  6855. if (empty($user)) {
  6856. return Result::error("暂无相关用户信息", 0);
  6857. }
  6858. if ($user->type_id == 10000) {
  6859. $data['status'] = 1;
  6860. } else {
  6861. $data['status'] = 0;
  6862. }
  6863. unset($data['user_id']);
  6864. if ($data['keyword'] == '') {
  6865. //提取标题+内容中的关键词
  6866. $data['keyword'] = $data['title'];
  6867. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6868. Jieba::init(); // 初始化 jieba-php
  6869. Finalseg::init();
  6870. $segList = Jieba::cut($data['keyword']);
  6871. $segList1 = array_slice($segList, 0, 8);
  6872. $data['keyword'] = implode(',', $segList1);
  6873. }
  6874. if ($data['description'] == '') {
  6875. //提取内容中的描述
  6876. // var_dump(11111);
  6877. //提取内容中的描述
  6878. $content = $data['introduce'];
  6879. // 去除 <style> 和 <script> 标签及其内容
  6880. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6881. // 去除所有 HTML 标签
  6882. $content = strip_tags($content);
  6883. // 去除 HTML 实体
  6884. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6885. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6886. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6887. // 去除多余空白
  6888. $content = preg_replace('/\s+/u', '', $content);
  6889. // 截取 100 个字符
  6890. $data['description'] = mb_substr($content, 0, 100);
  6891. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6892. }
  6893. if ($data['status'] == 0) {
  6894. $this->sendMessage([
  6895. 'talk_type' => 1000,
  6896. 'title' => $data['title'],
  6897. 'content' => '提交了审核',
  6898. 'messageType' => 9,
  6899. ]);
  6900. }
  6901. $result = Project::where('id', $id)->update($data);
  6902. if (empty($result)) {
  6903. return Result::error("更新失败", 0);
  6904. }
  6905. return Result::success($result);
  6906. }
  6907. /**
  6908. * 删除项目
  6909. * @param array $data
  6910. * @return array
  6911. */
  6912. public function delProject(array $data): array
  6913. {
  6914. $user = User::where('id', $data['user_id'])->first();
  6915. if (empty($user)) {
  6916. return Result::error("暂无相关用户信息", 0);
  6917. }
  6918. $project = Project::where('id', $data['id'])->first();
  6919. if (empty($project)) {
  6920. return Result::error("暂无相关项目信息", 0);
  6921. }
  6922. $result = Project::where('id', $data['id'])->delete();
  6923. if (empty($result)) {
  6924. return Result::error("删除失败", 0);
  6925. }
  6926. return Result::success($result);
  6927. }
  6928. /**
  6929. * 审核项目
  6930. * @param array $data
  6931. * @return array
  6932. */
  6933. public function checkProject(array $data): array
  6934. {
  6935. $user = User::where('id', $data['user_id'])->first();
  6936. if (empty($user)) {
  6937. return Result::error("暂无相关用户信息", 0);
  6938. }
  6939. // 0:未审核; 1:已审核; 2:已拒绝;
  6940. if ($user->type_id != 10000) {
  6941. if ($data['status'] == 1 || $data['status'] == 2) {
  6942. return Result::error("此用户权限不足", 0);
  6943. }
  6944. }
  6945. $project = Project::where('id', $data['id'])->first();
  6946. if (empty($project)) {
  6947. return Result::error("暂无相关项目信息", 0);
  6948. }
  6949. if ($data['status'] == 2) {
  6950. $this->sendMessage([
  6951. 'talk_type' => 1001,
  6952. 'title' => $project['title'],
  6953. 'content' => '审核拒绝',
  6954. 'messageType' => 9,
  6955. 'user_id' => $project['user_id'],
  6956. ]);
  6957. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6958. } else {
  6959. if ($data['status'] == 1) {
  6960. $this->sendMessage([
  6961. 'talk_type' => 1001,
  6962. 'title' => $project['title'],
  6963. 'content' => '审核通过',
  6964. 'messageType' => 9,
  6965. 'user_id' => $project['user_id'],
  6966. ]);
  6967. } else if ($data['status'] == 0) {
  6968. $this->sendMessage([
  6969. 'talk_type' => 1000,
  6970. 'title' => $project['title'],
  6971. 'content' => '提交了审核',
  6972. 'messageType' => 9,
  6973. ]);
  6974. }
  6975. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6976. }
  6977. if (empty($result)) {
  6978. return Result::error("审核失败", 0);
  6979. }
  6980. return Result::success($result);
  6981. }
  6982. /**
  6983. * 获取项目详情
  6984. * @param array $data
  6985. * @return array
  6986. */
  6987. public function getProjectInfo(array $data): array
  6988. {
  6989. $project = Project::where('id', $data['id'])->first();
  6990. if (empty($project)) {
  6991. return Result::error("暂无相关项目信息", 0);
  6992. }
  6993. return Result::success($project);
  6994. }
  6995. public function getWebsiteCompanyInfo(array $data): array
  6996. {
  6997. $company = Company::where('id', $data['id'])
  6998. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6999. ->where('status', 1)
  7000. // ->where('website_id', $data['website_id'])
  7001. ->select('company.*', 'job_industry.hyname as hy_name')
  7002. ->first();
  7003. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7004. switch ($company->jobnature_id) {
  7005. case null:
  7006. $company->jobnature_name = '';
  7007. break;
  7008. case 0:
  7009. $company->jobnature_name = '市场监督';
  7010. break;
  7011. case 1:
  7012. $company->jobnature_name = '信访纪检';
  7013. break;
  7014. case 2:
  7015. $company->jobnature_name = '公检法司';
  7016. break;
  7017. case 3:
  7018. $company->jobnature_name = '高关注机构';
  7019. break;
  7020. default:
  7021. $company->jobnature_name = '';
  7022. break;
  7023. }
  7024. $city_arr = $company->city_arr_id;
  7025. if (!empty($city_arr)) {
  7026. $city_arr = json_decode($city_arr, true);
  7027. $cityNames = District::whereIn('id', $city_arr)
  7028. ->pluck('name')
  7029. ->implode('-');
  7030. $company->city_name = $cityNames;
  7031. } else {
  7032. $company->city_name = '';
  7033. }
  7034. if (empty($company)) {
  7035. return Result::error("暂无相关公司信息", 0);
  7036. }
  7037. return Result::success($company);
  7038. }
  7039. public function getMSG(array $data): array
  7040. {
  7041. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7042. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7043. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7044. $result = [];
  7045. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7046. //最近的5篇已审的文章
  7047. $apply_articale = Article::where('status', 1)
  7048. ->where('admin_user_id', $user_id)
  7049. ->orderBy('updated_at', 'desc')
  7050. // ->limit(5)
  7051. ->get();
  7052. //获取5条用户的已审核商品
  7053. $good = Good::where('status', 2)
  7054. ->where('user_id', $user_id)
  7055. ->orderBy('updated_at', 'desc')
  7056. // ->limit(5)
  7057. ->get();
  7058. //获取5条用户待审核的公告
  7059. $notice = Notice::where('status', 2)
  7060. ->where('user_id', $user_id)
  7061. ->orderBy('updated_at', 'desc')
  7062. ->limit(5)->get();
  7063. //获取5条用户的待审核投诉
  7064. $complaint = Complaint::where('status', 2)
  7065. ->where('user_id', $user_id)
  7066. ->orderBy('updated_at', 'desc')
  7067. // ->limit(5)
  7068. ->get();
  7069. //获取5条用户的book
  7070. $book = Book::where('status', 2)
  7071. ->where('user_id', $user_id)
  7072. ->orderBy('updated_at', 'desc')
  7073. // ->limit(5)
  7074. ->get();
  7075. //获取5条用户的求职
  7076. //获取5条用户的求职 1
  7077. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7078. ->where('job_hunting.user_id', $user_id)
  7079. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7080. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7081. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7082. ->orderBy('updated_at', 'desc')
  7083. // ->limit(5)
  7084. ->get();
  7085. //获取5条用户的求职 2
  7086. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7087. ->where('job_recruiting.user_id', $user_id)
  7088. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7089. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7090. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7091. ->orderBy('updated_at', 'desc')
  7092. // ->limit(5)
  7093. ->get();
  7094. //人才库 1
  7095. $job_apply = JobApply::where('job_apply.status', 1)
  7096. ->where('job_apply.receiver_id', $user_id)
  7097. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7098. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7099. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7100. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7101. ->select('job_recruiting', 'job_recruiting.', '', '')
  7102. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  7103. ->orderBy('updated_at', 'desc')
  7104. // ->limit(5)
  7105. ->get();
  7106. // 职场机会 2
  7107. $job_resume = JobResume::where('job_resume.status', 1)
  7108. ->where('job_resume.receiver_id', $user_id)
  7109. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7110. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7111. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7112. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  7113. ->orderBy('updated_at', 'desc')
  7114. // ->limit(5)
  7115. ->get();
  7116. //获取5条用户待处理的投诉
  7117. $complaint_deal = Complaint::where('status', 2)
  7118. ->where('deal', 1)
  7119. ->whereJsonContains('re_user_ids', $user_id)
  7120. ->orderBy('updated_at', 'desc')
  7121. // ->limit(5)
  7122. ->get();
  7123. //获取 被通知者未读信息
  7124. $notice_unread = Notice::where('status', 2)
  7125. ->whereJsonContains('re_user_ids', $user_id)
  7126. //未读消息
  7127. ->where(function ($query) use ($user_id) {
  7128. $query->whereJsonDoesntContain('read_id', $user_id)
  7129. ->orWhereNull('read_id');
  7130. })
  7131. ->orderBy('updated_at', 'desc')
  7132. ->get();
  7133. $complaint_unread = Complaint::where('status', 2)
  7134. ->whereJsonContains('re_user_ids', $user_id)
  7135. //未读消息
  7136. ->where(function ($query) use ($user_id) {
  7137. $query->whereJsonDoesntContain('read_id', $user_id)
  7138. ->orWhereNull('read_id');
  7139. })
  7140. ->orderBy('updated_at', 'desc')
  7141. ->get();
  7142. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7143. $complany = Company::where('status', 1)
  7144. ->where('user_id', $user_id)
  7145. ->orderBy('updated_at', 'desc')
  7146. // ->limit(5)
  7147. ->get();
  7148. //获取5条单聊未读聊天消息
  7149. // $chat = ChatRecords::where('is_read', 0)
  7150. // ->where('user_id', $user_id)
  7151. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7152. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7153. // ->where('action', 'recieved')
  7154. // ->where('talk_type', 1)
  7155. // ->orderBy('created_at', 'desc')
  7156. // // ->limit(5)
  7157. // ->get();
  7158. //获取5条未读群聊信息
  7159. // $chat_group = ChatRecords::where('is_read', 0)
  7160. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7161. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7162. // ->where('user_id', $user_id)
  7163. // ->where('talk_type', 2)
  7164. // ->orderBy('created_at', 'desc')
  7165. // // ->limit(5)
  7166. // ->get();
  7167. //获取5条用户的待审核项目
  7168. $project = Project::where('status', 1)
  7169. ->where('user_id', $user_id)
  7170. ->orderBy('updated_at', 'desc')
  7171. // ->limit(5)
  7172. ->get();
  7173. // count($chat) + count($chat_group) +
  7174. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume) + count($complaint_deal)
  7175. + count($complany)
  7176. + count($project)
  7177. + count($notice_unread)
  7178. + count($complaint_unread)
  7179. // + count($chat) + count($chat_group)
  7180. ;
  7181. $result = [
  7182. 'apply_articale' => $apply_articale,
  7183. // 'chat' => $chat,
  7184. // 'chat_group' => $chat_group,
  7185. 'good' => $good,
  7186. 'notice' => $notice,
  7187. 'complaint' => $complaint,
  7188. 'book' => $book,
  7189. 'job_hunting' => $job_hunting,
  7190. 'job_recruiting' => $job_recruiting,
  7191. 'job_apply' => $job_apply,
  7192. 'job_resume' => $job_resume,
  7193. 'complaint_deal' => $complaint_deal,
  7194. 'complany' => $complany,
  7195. 'project' => $project,
  7196. 'notice_unread' => $notice_unread,
  7197. 'complaint_unread' => $complaint_unread,
  7198. 'count' => $count,
  7199. ];
  7200. } elseif ($type_id == 12) {
  7201. //最近的5篇已审的文章
  7202. $apply_articale = Article::where('status', 1)
  7203. ->where('admin_user_id', $user_id)
  7204. ->limit(5)->get();
  7205. //获取5条单聊未读聊天消息
  7206. $chat = ChatRecords::where('is_read', 0)
  7207. ->where('user_id', $user_id)
  7208. ->where('talk_type', 1)
  7209. ->orderBy('created_at', 'desc')
  7210. ->limit(5)->get();
  7211. //获取5条未读群聊信息
  7212. $chat_group = ChatRecords::where('is_read', 0)
  7213. ->where('user_id', $user_id)
  7214. ->where('talk_type', 2)
  7215. ->orderBy('created_at', 'desc')
  7216. ->limit(5)->get();
  7217. //获取5条用户的已审核商品
  7218. $good = Good::where('status', 2)
  7219. ->where('user_id', $user_id)
  7220. ->orderBy('updated_at', 'desc')
  7221. ->limit(5)->get();
  7222. //获取5条用户的book
  7223. $book = Book::where('status', 2)
  7224. ->where('user_id', $user_id)
  7225. ->orderBy('updated_at', 'desc')
  7226. ->limit(5)->get();
  7227. //获取5条用户的求职
  7228. //获取5条用户的求职 1
  7229. //count($chat) + count($chat_group)
  7230. $count = count($apply_articale) + count($good);
  7231. $result = [
  7232. 'apply_articale' => $apply_articale,
  7233. 'chat' => $chat,
  7234. 'chat_group' => $chat_group,
  7235. 'good' => $good,
  7236. 'book' => $book,
  7237. 'count' => $count,
  7238. ];
  7239. } elseif ($type_id == 13) {
  7240. //最近的5篇已审的文章
  7241. $apply_articale = Article::where('status', 1)
  7242. ->where('admin_user_id', $user_id)
  7243. ->limit(5)->get();
  7244. //获取5条单聊未读聊天消息
  7245. $chat = ChatRecords::where('is_read', 0)
  7246. ->where('user_id', $user_id)
  7247. ->where('talk_type', 1)
  7248. ->orderBy('created_at', 'desc')
  7249. ->limit(5)->get();
  7250. //获取5条未读群聊信息
  7251. $chat_group = ChatRecords::where('is_read', 0)
  7252. ->where('user_id', $user_id)
  7253. ->where('talk_type', 2)
  7254. ->orderBy('created_at', 'desc')
  7255. ->limit(5)->get();
  7256. //获取5条用户的已审核商品
  7257. $good = Good::where('status', 2)
  7258. ->where('user_id', $user_id)
  7259. ->orderBy('updated_at', 'desc')
  7260. ->limit(5)->get();
  7261. //count($chat) + count($chat_group) +
  7262. $count = count($apply_articale) + count($good);
  7263. $result = [
  7264. 'apply_articale' => $apply_articale,
  7265. 'chat' => $chat,
  7266. 'chat_group' => $chat_group,
  7267. 'good' => $good,
  7268. 'count' => $count,
  7269. ];
  7270. } elseif ($type_id == 14) {
  7271. //最近的5篇已审的文章
  7272. $apply_articale = Article::where('status', 1)
  7273. ->where('admin_user_id', $user_id)
  7274. // ->limit(5)
  7275. ->get();
  7276. //获取5条用户的已审核商品
  7277. $good = Good::where('status', 2)
  7278. ->where('user_id', $user_id)
  7279. ->orderBy('updated_at', 'desc')
  7280. // ->limit(5)
  7281. ->get();
  7282. $count = count($apply_articale) + count($good);
  7283. $result = [
  7284. 'apply_articale' => $apply_articale,
  7285. 'chat' => '',
  7286. 'chat_group' => '',
  7287. 'good' => $good,
  7288. 'count' => $count,
  7289. ];
  7290. } elseif ($type_id == 10000) {
  7291. //获取未审核的5篇文章
  7292. $apply_articale = Article::where('status', 0)
  7293. ->orderBy('updated_at', 'desc')
  7294. // ->limit(5)
  7295. ->get();
  7296. //获取5条单聊未读聊天消息
  7297. //获取5条单聊未读聊天消息
  7298. // $chat = ChatRecords::where('is_read', 0)
  7299. // ->where('user_id', $user_id)
  7300. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7301. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7302. // ->where('action', 'recieved')
  7303. // ->where('talk_type', 1)
  7304. // ->orderBy('created_at', 'desc')
  7305. // // ->limit(5)
  7306. // ->get();
  7307. // //获取5条未读群聊信息
  7308. // $chat_group = ChatRecords::where('is_read', 0)
  7309. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7310. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7311. // ->where('user_id', $user_id)
  7312. // ->where('talk_type', 2)
  7313. // ->orderBy('created_at', 'desc')
  7314. // // ->limit(5)
  7315. // ->get();
  7316. //获取5条用户的已审核商品
  7317. $good = Good::where('status', 1)
  7318. // ->where('user_id', $user_id)
  7319. ->orderBy('updated_at', 'desc')
  7320. // ->limit(5)
  7321. ->get();
  7322. //获取5条用户待审核的公告
  7323. $notice = Notice::where('status', 1)
  7324. ->orderBy('updated_at', 'desc')
  7325. // ->limit(5)
  7326. ->get();
  7327. //获取5条用户的待审核投诉
  7328. $complaint = Complaint::where('status', 1)
  7329. ->orderBy('updated_at', 'desc')
  7330. // ->limit(5)
  7331. ->get();
  7332. //获取5条用户的book
  7333. $book = Book::where('status', 1)
  7334. ->orderBy('updated_at', 'desc')
  7335. // ->limit(5)
  7336. ->get();
  7337. //获取5条用户的求职 1
  7338. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7339. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7340. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7341. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7342. ->orderBy('updated_at', 'desc')
  7343. // ->limit(5)
  7344. ->get();
  7345. //获取5条用户的求职 2
  7346. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7347. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7348. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7349. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7350. ->orderBy('updated_at', 'desc')
  7351. // ->limit(5)
  7352. ->get();
  7353. //人才库 1
  7354. $job_apply = JobApply::where('job_apply.status', 1)
  7355. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7356. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7357. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7358. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7359. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  7360. ->orderBy('updated_at', 'desc')
  7361. // ->limit(5)
  7362. ->get();
  7363. // 职场机会 2
  7364. $job_resume = JobResume::where('job_resume.status', 1)
  7365. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7366. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7367. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7368. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  7369. ->orderBy('updated_at', 'desc')
  7370. // ->limit(5)
  7371. ->get();
  7372. //待审核数据com pro
  7373. $complany = Company::where('status', 0)
  7374. ->orderBy('updated_at', 'desc')
  7375. // ->limit(5)
  7376. ->get();
  7377. $project = Project::where('status', 0)
  7378. ->orderBy('updated_at', 'desc')
  7379. // ->limit(5)
  7380. ->get();
  7381. $count =
  7382. // count($chat) +
  7383. // count($chat_group) +
  7384. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7385. // + count($job_apply)
  7386. // + count($job_resume)
  7387. + count($complany)
  7388. + count($project);
  7389. $result = [
  7390. 'apply_articale' => $apply_articale,
  7391. // 'chat' => $chat,
  7392. // 'chat_group' => $chat_group,
  7393. 'good' => $good,
  7394. 'notice' => $notice,
  7395. 'complaint' => $complaint,
  7396. 'book' => $book,
  7397. 'job_hunting' => $job_hunting,
  7398. 'job_recruiting' => $job_recruiting,
  7399. // 'job_apply' => $job_apply,
  7400. // 'job_resume' => $job_resume,
  7401. 'complany' => $complany,
  7402. 'project' => $project,
  7403. 'count' => $count,
  7404. ];
  7405. } elseif ($type_id == 20000) {
  7406. }
  7407. var_dump($type_id, '-----------------test---------');
  7408. return Result::success($result);
  7409. }
  7410. /**
  7411. * @param array $data
  7412. * @return array
  7413. */
  7414. public function getWebsiteProject(array $data): array
  7415. {
  7416. $categorys = json_decode($data['id'], true);
  7417. if (!empty($categorys)) {
  7418. $category_arr = $this->processArticlePro($data['website_id']);
  7419. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7420. $catiall = $category_arr['catiall'];
  7421. // return Result::success($catiall);
  7422. foreach ($categorys as $key => $val) {
  7423. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7424. $level = explode(',', $val['level'])[0];
  7425. $imgnum = explode(',', $val['level'])[1] ?? null;
  7426. $textnum = explode(',', $val['level'])[2] ?? null;
  7427. if ($level == 1) {
  7428. if (!empty($textnum) && $textnum > 0) {
  7429. $text_num = Project::where('level', $level)
  7430. ->where('website_id', $data['website_id'])
  7431. ->where('status', 1)
  7432. ->select(
  7433. 'project.id',
  7434. 'project.title',
  7435. 'project.description',
  7436. 'project.updated_at',
  7437. 'project.category_id',
  7438. 'project.cat_arr_id'
  7439. )
  7440. ->orderBy('updated_at', 'desc')
  7441. ->limit($textnum)
  7442. ->get()->all();
  7443. }
  7444. if (!empty($imgnum) && $imgnum > 0) {
  7445. $img_num = Project::where('level', $level)
  7446. ->where('website_id', $data['website_id'])
  7447. ->where('status', 1)
  7448. ->where('imgurl', '!=', '')
  7449. ->whereNotNull('imgurl')
  7450. ->select(
  7451. 'project.id',
  7452. 'project.title',
  7453. 'project.description',
  7454. 'project.updated_at',
  7455. 'project.imgurl as imgs',
  7456. 'project.category_id',
  7457. 'project.cat_arr_id'
  7458. )
  7459. ->orderBy('updated_at', 'desc')
  7460. ->limit($imgnum)
  7461. ->get()->all();
  7462. }
  7463. } else {
  7464. if (!empty($textnum) && $textnum > 0) {
  7465. $text_num = Project::where('website_id', $data['website_id'])
  7466. ->where('status', 1)
  7467. ->select(
  7468. 'project.id',
  7469. 'project.title',
  7470. 'project.description',
  7471. 'project.updated_at',
  7472. 'project.category_id',
  7473. 'project.cat_arr_id',
  7474. 'project.website_id',
  7475. 'project.updated_at',
  7476. 'project.created_at'
  7477. )
  7478. ->orderBy('updated_at', 'desc')
  7479. ->limit($textnum)
  7480. ->get()->all();
  7481. }
  7482. if (!empty($imgnum) && $imgnum > 0) {
  7483. $img_num = Project::where('website_id', $data['website_id'])
  7484. ->where('status', 1)
  7485. ->where('imgurl', '!=', '')
  7486. ->whereNotNull('imgurl')
  7487. ->select(
  7488. 'project.id',
  7489. 'project.title',
  7490. 'project.description',
  7491. 'project.updated_at',
  7492. 'project.imgurl as imgs',
  7493. 'project.category_id',
  7494. 'project.cat_arr_id'
  7495. )
  7496. ->orderBy('updated_at', 'desc')
  7497. ->limit($imgnum)
  7498. ->get()->all();
  7499. }
  7500. }
  7501. }
  7502. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7503. $category_ids = explode(',', $val['id'])[0];
  7504. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7505. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7506. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7507. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7508. $text_num = Project::whereIn('category_id', $category_arr)
  7509. ->where('website_id', $data['website_id'])
  7510. ->where('status', 1)
  7511. ->select(
  7512. 'project.id',
  7513. 'project.title',
  7514. 'project.description',
  7515. 'project.updated_at',
  7516. 'project.category_id',
  7517. 'project.cat_arr_id'
  7518. )
  7519. ->orderBy('updated_at', 'desc')
  7520. ->limit($cat_textnum)
  7521. ->get()->all();
  7522. }
  7523. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7524. $img_num = Project::whereIn('category_id', $category_arr)
  7525. ->where('website_id', $data['website_id'])
  7526. ->where('status', 1)
  7527. ->where('imgurl', '!=', '')
  7528. ->whereNotNull('imgurl')
  7529. ->select(
  7530. 'project.id',
  7531. 'project.title',
  7532. 'project.description',
  7533. 'project.updated_at',
  7534. 'project.imgurl as imgs',
  7535. 'project.category_id',
  7536. 'project.cat_arr_id'
  7537. )
  7538. ->orderBy('updated_at', 'desc')
  7539. ->limit($cat_imgnum)
  7540. ->get()->all();
  7541. }
  7542. }
  7543. if (!empty($img_num)) {
  7544. foreach ($img_num as $k => $v) {
  7545. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7546. $imgurl = json_decode($v['imgs'], true);
  7547. if (!empty($imgurl)) {
  7548. $img_num[$k]->imgurl = $imgurl[0];
  7549. }
  7550. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7551. }
  7552. }
  7553. if (!empty($text_num)) {
  7554. foreach ($text_num as $k => $v) {
  7555. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7556. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7557. }
  7558. }
  7559. $project[$key]['img_num'] = $img_num ?? [];
  7560. $project[$key]['text_num'] = $text_num ?? [];
  7561. }
  7562. }
  7563. if (empty($project)) {
  7564. return Result::error("暂无相关项目信息", 0);
  7565. }
  7566. return Result::success($project);
  7567. }
  7568. /**
  7569. * @param array $data
  7570. * @return array
  7571. */
  7572. public function getWebsiteProjectInfo(array $data): array
  7573. {
  7574. $project = Project::where('id', $data['id'])
  7575. ->where('status', 1)
  7576. ->where('website_id', $data['website_id'])
  7577. ->select('project.*')
  7578. ->first();
  7579. if (empty($project)) {
  7580. return Result::error("暂无相关项目信息", 0);
  7581. }
  7582. return Result::success($project);
  7583. }
  7584. /**
  7585. * @param array $data
  7586. * @return array
  7587. */
  7588. public function getWebsiteProjectList(array $data): array
  7589. {
  7590. $where = [];
  7591. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7592. $where['category_id'] = $data['category_id'];
  7593. }
  7594. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7595. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7596. }
  7597. $query = Project::where($where)
  7598. ->where('status', 1)
  7599. ->where('website_id', $data['website_id'])
  7600. ->select(
  7601. 'project.id',
  7602. 'project.title',
  7603. 'project.description',
  7604. 'project.imgurl as imgs',
  7605. 'project.category_id',
  7606. 'project.cat_arr_id'
  7607. )
  7608. ->orderBy('updated_at', 'desc');
  7609. $count = $query->count();
  7610. $project = $query->clone()
  7611. ->offset(($data['page'] - 1) * $data['pageSize'])
  7612. ->limit($data['pageSize'])
  7613. ->get()->all();
  7614. if (empty($project)) {
  7615. return Result::error("暂无相关项目信息", 0);
  7616. }
  7617. $categorys = $this->processArticlePro($data['website_id']);
  7618. $catiall = $categorys['catiall'];
  7619. foreach ($project as $key => $val) {
  7620. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7621. if (!empty($val['imgs'])) {
  7622. $imgurl = json_decode($val['imgs'], true);
  7623. if (!empty($imgurl)) {
  7624. $project[$key]->imgurl = $imgurl[0];
  7625. }
  7626. } else {
  7627. $project[$key]->imgurl = '';
  7628. }
  7629. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7630. }
  7631. $result = [
  7632. 'rows' => $project,
  7633. 'count' => $count,
  7634. ];
  7635. return Result::success($result);
  7636. }
  7637. /**
  7638. * @param array $data
  7639. * @return array
  7640. */
  7641. public function getWebsiteCategoryJob(array $data): array
  7642. {
  7643. $categorys = json_decode($data['id'], true);
  7644. if (!empty($categorys)) {
  7645. $category_arr = $this->processArticlePro($data['website_id']);
  7646. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7647. $catiall = $category_arr['catiall'];
  7648. foreach ($categorys as $key => $val) {
  7649. if (isset($val['id']) && !empty($val['id'])) {
  7650. $catid = explode(',', $val['id'])[0] ?? null;
  7651. $type = explode(',', $val['id'])[1] ?? null;
  7652. $textnum = explode(',', $val['id'])[2] ?? null;
  7653. }
  7654. // 4:招聘;5:求职;
  7655. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7656. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7657. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7658. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7659. ->where('job_recruiting.status', 1)
  7660. ->where('job_recruiting.website_id', $data['website_id'])
  7661. ->select(
  7662. 'job_recruiting.id',
  7663. 'job_recruiting.title',
  7664. 'job_company.business_name',
  7665. 'job_recruiting.updated_at',
  7666. 'job_recruiting.cat_arr_id'
  7667. )
  7668. ->orderBy('job_recruiting.updated_at', 'desc')
  7669. ->limit($textnum)
  7670. ->get()->all();
  7671. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7672. // 状态 审核状态,1待审核2已审核3已拒绝
  7673. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7674. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7675. ->where('job_hunting.status', 2)
  7676. ->where('job_hunting.website_id', $data['website_id'])
  7677. ->select(
  7678. 'job_hunting.id',
  7679. 'job_hunting.name',
  7680. 'job_hunting.cat_arr_id',
  7681. 'job_position.zwname as job_name',
  7682. 'job_hunting.updated_at'
  7683. )
  7684. ->orderBy('updated_at', 'desc')
  7685. ->limit($textnum)
  7686. ->get()->all();
  7687. } else {
  7688. $job = [];
  7689. }
  7690. // var_dump($catid.'222uuuuuuu'.$key);
  7691. if (!empty($job)) {
  7692. foreach ($job as $k => $value) {
  7693. if (isset($value->cat_arr_id)) {
  7694. $catArr = json_decode($value->cat_arr_id, true);
  7695. $catId = end($catArr);
  7696. } else {
  7697. continue;
  7698. }
  7699. if (isset($catiall[$catId])) {
  7700. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7701. }
  7702. }
  7703. }
  7704. // var_dump($catid.'xxxxx'.$key);
  7705. $result[$key] = $job ?? [];
  7706. }
  7707. }
  7708. if (empty($result)) {
  7709. return Result::error("暂无相关分类信息", 0);
  7710. }
  7711. return Result::success($result);
  7712. }
  7713. /**
  7714. * 发送消息
  7715. * @param array $messageData
  7716. * @return void
  7717. */
  7718. public function sendMessage($messageData)
  7719. {
  7720. $msg = [
  7721. 'talk_type' => $messageData['talk_type'],
  7722. 'title' => $messageData['title'],
  7723. 'content' => $messageData['content'],
  7724. 'messageType' => $messageData['messageType'],
  7725. 'user_id' => $messageData['user_id'] ?? '',
  7726. 'time' => microtime(),
  7727. ];
  7728. $message = new MqProducer($msg);
  7729. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7730. $producer->produce($message);
  7731. }
  7732. }