NewsService.php 229 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  59. class NewsService implements NewsServiceInterface
  60. {
  61. #[Inject]
  62. protected Redis $redis;
  63. /**
  64. * 获取导航池列表
  65. * @param array $data
  66. * @return array
  67. */
  68. public function getCategoryList(array $data): array
  69. {
  70. $search = $data['name'] ?? '';
  71. $page = (int)($data['page'] ?? 1);
  72. $perPage = (int)($data['pageSize'] ?? 10);
  73. // 1. 查出所有匹配的分类id
  74. if ($search) {
  75. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  76. if (empty($matchedIds)) {
  77. return Result::success(['rows' => [], 'total' => 0]);
  78. }
  79. // 2. 递归查所有父级,直到一级分类
  80. $idsStr = implode(',', $matchedIds);
  81. $sql = "
  82. WITH RECURSIVE parents AS (
  83. SELECT * FROM category WHERE id IN ($idsStr)
  84. UNION ALL
  85. SELECT c.* FROM category c
  86. INNER JOIN parents p ON c.id = p.pid
  87. )
  88. SELECT * FROM parents
  89. ";
  90. $parents = Db::select($sql);
  91. $parentIds = [];
  92. foreach ($parents as $row) {
  93. if ($row->pid == 0) {
  94. $parentIds[] = $row->id;
  95. }
  96. }
  97. $parentIds = array_unique($parentIds);
  98. } else {
  99. // 没有搜索,一级分类就是根
  100. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  101. }
  102. // 3. 一级分类分页
  103. $total = count($parentIds);
  104. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  105. if (empty($parentIds)) {
  106. return Result::success(['rows' => [], 'total' => $total]);
  107. }
  108. // 4. 递归查所有子孙
  109. $idsStr = implode(',', $parentIds);
  110. $sql = "
  111. WITH RECURSIVE subcategories AS (
  112. SELECT * FROM category WHERE id IN ($idsStr)
  113. UNION ALL
  114. SELECT c.* FROM category c
  115. INNER JOIN subcategories s ON c.pid = s.id
  116. )
  117. SELECT * FROM subcategories ORDER BY updated_at DESC
  118. ";
  119. $allCategories = Db::select($sql);
  120. // 5. 组装树结构
  121. $categoryMap = [];
  122. foreach ($allCategories as $cat) {
  123. $cat = (array)$cat;
  124. $cat['children'] = [];
  125. $categoryMap[$cat['id']] = $cat;
  126. }
  127. foreach ($categoryMap as $id => &$cat) {
  128. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  129. $categoryMap[$cat['pid']]['children'][] = &$cat;
  130. }
  131. }
  132. unset($cat);
  133. $categoryTree = [];
  134. foreach ($parentIds as $id) {
  135. if (isset($categoryMap[$id])) {
  136. $categoryTree[] = $categoryMap[$id];
  137. }
  138. }
  139. return Result::success([
  140. 'rows' => $categoryTree,
  141. 'total' => $total,
  142. ]);
  143. }
  144. private function findMatchedCategories($search)
  145. {
  146. if ($search) {
  147. return Category::where('name', 'like', "%{$search}%")
  148. ->orderBy('updated_at', 'desc')
  149. ->get();
  150. }
  151. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  152. ->get();
  153. }
  154. private function findAllParents($categories)
  155. {
  156. $allCategories = [];
  157. foreach ($categories as $category) {
  158. $parentId = $category->pid;
  159. while ($parentId > 0) {
  160. $parent = Category::find($parentId);
  161. if ($parent) {
  162. $allCategories[$parent->id] = $parent;
  163. $parentId = $parent->pid;
  164. } else {
  165. break;
  166. }
  167. }
  168. $allCategories[$category->id] = $category;
  169. }
  170. return array_values($allCategories);
  171. }
  172. private function buildCategoryTree($category, $allRequiredCategories)
  173. {
  174. $categoryData = $category->toArray();
  175. $children = [];
  176. foreach ($allRequiredCategories as $c) {
  177. if ($c->pid === $category->id) {
  178. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  179. }
  180. }
  181. if (!empty($children)) {
  182. $categoryData['children'] = $children;
  183. }
  184. return $categoryData;
  185. }
  186. public function myCategoryList(array $data): array
  187. {
  188. $sszq = $data['sszq'] ?? '';
  189. unset($data['sszq']);
  190. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  191. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  192. $where[] = [
  193. 'pid',
  194. '=',
  195. $data['pid'],
  196. ];
  197. if (isset($data['name'])) {
  198. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  199. }
  200. var_dump($where);
  201. //根据分类id,从category表中取出分类信息
  202. $result = Category::where($where)
  203. ->whereIn('category.id', $catorytids)
  204. ->select('category.*', 'category.id as category_id')->get();
  205. if (empty($result)) {
  206. return Result::error("没有栏目数据");
  207. }
  208. return Result::success($result);
  209. }
  210. /**
  211. * @param array $data
  212. * @return array
  213. */
  214. public function categoryList(array $data): array
  215. {
  216. $where[] = [
  217. 'pid',
  218. '=',
  219. $data['pid']
  220. ];
  221. if (isset($data['name'])) {
  222. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  223. }
  224. var_dump($where);
  225. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  226. if (empty($result)) {
  227. return Result::error("没有栏目数据");
  228. }
  229. return Result::success($result);
  230. }
  231. /**
  232. * @param array $data
  233. * @return array
  234. */
  235. public function addCategory(array $data): array
  236. {
  237. if (isset($data['id'])) {
  238. unset($data['id']);
  239. }
  240. $id = Category::insertGetId($data);
  241. if (empty($id)) {
  242. return Result::error("添加失败");
  243. }
  244. return Result::success(['id' => $id]);
  245. }
  246. /**
  247. * @param array $data
  248. * @return array
  249. */
  250. public function delCategory(array $data): array
  251. {
  252. Db::beginTransaction();
  253. try {
  254. $categoryList = Category::where(['pid' => $data['id']])->get();
  255. if ($categoryList->toArray()) {
  256. Db::rollBack();
  257. return Result::error("分类下面有子分类不能删除");
  258. }
  259. $articleList = Article::where(['catid' => $data['id']])->get();
  260. if ($articleList->toArray()) {
  261. Db::rollBack();
  262. return Result::error("分类下面有资讯不能删除");
  263. }
  264. $result = Category::where($data)->delete();
  265. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  266. if (!$result) {
  267. return Result::error("删除失败");
  268. }
  269. return Result::success($result);
  270. Db::commit();
  271. } catch (\Exception $e) {
  272. Db::rollBack();
  273. return Result::error("删除失败");
  274. }
  275. }
  276. /**
  277. * @param array $data
  278. * @return array
  279. */
  280. public function updateCategory(array $data): array
  281. {
  282. $where = [
  283. 'id' => $data['id'],
  284. ];
  285. $result = Category::where($where)->update($data);
  286. if ($result) {
  287. return Result::success($result);
  288. } else {
  289. return Result::error("更新失败");
  290. }
  291. }
  292. /**
  293. * 获取导航池信息
  294. * @param array $data
  295. * @return array
  296. */
  297. public function getCategoryInfo(array $data): array
  298. {
  299. $where = [
  300. 'id' => $data['id'],
  301. ];
  302. $result = Category::where($where)->first();
  303. if ($result) {
  304. return Result::success($result);
  305. } else {
  306. return Result::error("更新失败");
  307. }
  308. }
  309. /**
  310. * @param array $data
  311. * @return array
  312. */
  313. public function getArticleList(array $data): array
  314. {
  315. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  316. $type_id = $data['type_id'];
  317. unset($data['type_id']);
  318. $user_id = $data['user_id'];
  319. unset($data['user_id']);
  320. $where = [];
  321. $status1 = [];
  322. if (isset($data['id']) && $data['id']) {
  323. array_push($where, ['article.id', '=', $data['id']]);
  324. }
  325. if (isset($data['title']) && $data['title']) {
  326. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  327. }
  328. if (isset($data['category_name']) && $data['category_name']) {
  329. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  330. }
  331. if (isset($data['author']) && $data['author']) {
  332. array_push($where, ['article.author', '=', $data['author']]);
  333. }
  334. if (isset($data['islink']) && $data['islink'] !== "") {
  335. array_push($where, ['article.islink', '=', $data['islink']]);
  336. }
  337. if (isset($data['status']) && $data['status'] !== "") {
  338. array_push($where, ['article.status', '=', $data['status']]);
  339. }
  340. if (isset($data['status1'])) {
  341. $status1 = json_decode(($data['status1']));
  342. }
  343. //不是管理员展示个人数据;
  344. if ($type_id != 10000) {
  345. $where[] = ['article.admin_user_id', '=', $user_id];
  346. }
  347. $rep = Article::where($where)
  348. ->whereNotIn('article.status', [404])
  349. ->when($status1, function ($query) use ($status1) {
  350. if (isset($status1) && $status1) {
  351. $query->whereIn('article.status', $status1);
  352. }
  353. })
  354. ->leftJoin('category', 'article.catid', 'category.id')
  355. ->leftJoin('website_category', function ($join) {
  356. $join->on('article.web_site_id', '=', 'website_category.website_id')
  357. ->on('article.catid', '=', 'website_category.category_id');
  358. })
  359. ->select("article.*", "category.name as category_name", "website_category.alias")
  360. ->orderBy("article.updated_at", "desc")
  361. ->limit($data['pageSize'])
  362. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  363. $count = Article::where($where)->whereNotIn('article.status', [404])
  364. ->when($status1, function ($query) use ($status1) {
  365. if (isset($status1) && $status1) {
  366. $query->whereIn('article.status', $status1);
  367. }
  368. })
  369. ->leftJoin('category', 'article.catid', 'category.id')->count();
  370. $data = [
  371. 'rows' => $rep->toArray(),
  372. 'count' => $count,
  373. ];
  374. if (empty($rep)) {
  375. return Result::error("没有信息数据");
  376. }
  377. return Result::success($data);
  378. }
  379. /**
  380. * @param array $data
  381. * @return array
  382. */
  383. public function addArticle(array $data): array
  384. {
  385. var_dump($data, '----------12-----------1');
  386. unset($data['user_type']);
  387. unset($data['nav_add_pool_id']);
  388. // unset($data['commend_id']);
  389. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  390. Db::beginTransaction();
  391. try {
  392. //处理投票
  393. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  394. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  395. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  396. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  397. unset($data['is_survey']);
  398. unset($data['survey_name']);
  399. unset($data['suvey_array']);
  400. // unset($data['website_id']);
  401. // unset($data['web_site_id']);
  402. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  403. if ($data['hits'] == '') {
  404. $data['hits'] = 0;
  405. }
  406. if ($data['is_original'] == '') {
  407. $data['is_original'] = 0;
  408. }
  409. if ($data['status'] == '') {
  410. $data['status'] = 0;
  411. }
  412. $articleData = $data;
  413. unset($articleData['content']);
  414. //自动处理缩略图、关键字、描述
  415. if ($articleData['imgurl'] == '') {
  416. //如果没有图,设置level=0
  417. $levelArr = json_decode($articleData['level'], true);
  418. var_dump($levelArr, '----------levelArr-----------1');
  419. //content中提取图片第一个图,正则提取
  420. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  421. preg_match_all($reg, $data['content'], $matches);
  422. if (isset($matches[1][0])) {
  423. //截取varchar240
  424. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  425. //如果有图,设置level=3
  426. if (!in_array(3, $levelArr)) {
  427. $levelArr[] = 3;
  428. }
  429. $articleData['level'] = json_encode($levelArr);
  430. } else {
  431. if (!in_array(0, $levelArr)) {
  432. $levelArr[] = 0;
  433. }
  434. $articleData['level'] = json_encode($levelArr);
  435. }
  436. }
  437. var_dump($articleData['level'], '----------$articleData[level]----------1');
  438. if ($articleData['keyword'] == '') {
  439. //提取标题+内容中的关键词
  440. $articleData['keyword'] = $data['title'];
  441. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  442. Jieba::init(); // 初始化 jieba-php
  443. Finalseg::init();
  444. $segList = Jieba::cut($articleData['keyword']);
  445. $segList1 = array_slice($segList, 0, 8);
  446. $articleData['keyword'] = implode(',', $segList1);
  447. }
  448. if ($articleData['introduce'] == '') {
  449. //提取内容中的描述
  450. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  451. }
  452. $id = Article::insertGetId($articleData);
  453. $articleDataContent = [
  454. 'article_id' => $id,
  455. 'content' => $data['content'],
  456. ];
  457. ArticleData::insertGetId($articleDataContent);
  458. //处理投票
  459. if ($is_survey == 1) {
  460. //生成年月日时分秒+8位随机数
  461. $uuid = date('YmdHis') . rand(10000000, 99999999);
  462. var_dump($suvey_array, 'suvey_array________');
  463. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  464. var_dump($suveys_array, '---------------------1');
  465. var_dump($suvey_array, '---------------------2');
  466. $suvey_data = [];
  467. foreach ($suveys_array as $key => $value) {
  468. if ($value == '') {
  469. continue;
  470. }
  471. if (is_array($value)) {
  472. $suvey_data[] = [
  473. 'sur_id' => $uuid,
  474. 'art_id' => $id,
  475. 'website_id' => $website_id ?? 2,
  476. 'survey_name' => $survey_name,
  477. 'choice_name' => $value[1],
  478. 'is_other' => 1,
  479. 'other_id' => 0,
  480. 'results' => 0,
  481. ];
  482. } else {
  483. $suvey_data[] = [
  484. 'sur_id' => $uuid,
  485. 'art_id' => $id,
  486. 'website_id' => $website_id ?? 2,
  487. 'survey_name' => $survey_name,
  488. 'choice_name' => $value,
  489. 'is_other' => 0,
  490. 'other_id' => 0,
  491. 'results' => 0,
  492. ];
  493. }
  494. if (empty($suvey_data)) {
  495. throw new \Exception("投票数据为空");
  496. }
  497. }
  498. $result = ArticleSurvey::insert($suvey_data);
  499. if (!$result) {
  500. throw new \Exception("投票失败,ArticleSurvey插入失败");
  501. }
  502. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  503. if (!$result) {
  504. throw new \Exception("投票失败,更新主表失败");
  505. }
  506. }
  507. Db::commit();
  508. return Result::success(['id' => $id]);
  509. } catch (\Throwable $ex) {
  510. Db::rollBack();
  511. var_dump($ex->getMessage());
  512. return Result::error("创建失败", 0);
  513. }
  514. }
  515. /**
  516. * @param array $data
  517. * @return array
  518. */
  519. public function delArticle(array $data): array
  520. {
  521. $result = Article::where($data)->delete();
  522. //survey投票删除
  523. articleSurvey::where(['art_id' => $data['id']])->delete();
  524. if (!$result) {
  525. return Result::error("删除失败");
  526. }
  527. return Result::success($result);
  528. }
  529. /**
  530. * @param array $data
  531. * @return array
  532. */
  533. public function updateArticle(array $data): array
  534. {
  535. var_dump($data, '----------12-----------1');
  536. Db::beginTransaction();
  537. unset($data['user_type']);
  538. // unset($data['web_site_id']);
  539. unset($data['nav_add_pool_id']);
  540. try {
  541. //处理投票
  542. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  543. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  544. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  545. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  546. unset($data['is_survey']);
  547. unset($data['survey_name']);
  548. unset($data['suvey_array']);
  549. unset($data['website_id']);
  550. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  551. if ($data['hits'] == '') {
  552. $data['hits'] = 0;
  553. }
  554. if ($data['is_original'] == '') {
  555. $data['is_original'] = 0;
  556. }
  557. if ($data['status'] == '') {
  558. $data['status'] = 0;
  559. }
  560. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  561. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  562. $articleData = $data;
  563. unset($articleData['content']);
  564. unset($articleData['status_name']);
  565. unset($articleData['name']);
  566. unset($articleData['content']);
  567. unset($articleData['pid_arr']);
  568. unset($articleData['pid']);
  569. //自动处理缩略图、关键字、描述
  570. if ($articleData['imgurl'] == '') {
  571. //如果没有图,设置level=0
  572. $levelArr = json_decode($articleData['level'], true);
  573. var_dump($levelArr, '----------levelArr-----------1');
  574. //content中提取图片第一个图,正则提取
  575. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  576. preg_match_all($reg, $data['content'], $matches);
  577. if (isset($matches[1][0])) {
  578. //截取varchar240
  579. // 截取到第一个<
  580. $articleData['imgurl'] = $matches[1][0];
  581. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  582. $pos = strpos($articleData['imgurl'], '"');
  583. if ($pos !== false) {
  584. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  585. }
  586. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  587. //如果有图,设置level=3
  588. if (!in_array(3, $levelArr)) {
  589. $levelArr[] = 3;
  590. }
  591. $articleData['level'] = json_encode($levelArr);
  592. } else {
  593. if (!in_array(0, $levelArr)) {
  594. $levelArr[] = 0;
  595. }
  596. $articleData['level'] = json_encode($levelArr);
  597. }
  598. }
  599. var_dump($articleData['level'], '----------$articleData[level]----------1');
  600. if ($articleData['keyword'] == '') {
  601. //提取标题+内容中的关键词
  602. $articleData['keyword'] = $data['title'];
  603. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  604. Jieba::init(); // 初始化 jieba-php
  605. Finalseg::init();
  606. $segList = Jieba::cut($articleData['keyword']);
  607. $segList1 = array_slice($segList, 0, 8);
  608. $articleData['keyword'] = implode(',', $segList1);
  609. }
  610. if ($articleData['introduce'] == '') {
  611. //提取内容中的描述
  612. $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
  613. // substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  614. }
  615. $id = Article::where(['id' => $data['id']])->update($articleData);
  616. $articleDataContent = [
  617. 'content' => $data['content'],
  618. ];
  619. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  620. //处理投票
  621. $id = $data['id'];
  622. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  623. var_dump($suvey_array, 'suvey_array________delete');
  624. //处理投票
  625. if ($is_survey == 1) {
  626. //生成年月日时分秒+8位随机数
  627. $uuid = date('YmdHis') . rand(10000000, 99999999);
  628. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  629. var_dump($suveys_array, '---------------------1');
  630. $suvey_data = [];
  631. if (is_array($suveys_array)) {
  632. foreach ($suveys_array as $key => $value) {
  633. if ($value == '') {
  634. continue;
  635. }
  636. if (is_array($value)) {
  637. $suvey_data[] = [
  638. 'sur_id' => $uuid,
  639. 'art_id' => $id,
  640. 'website_id' => $website_id ?? 2,
  641. 'survey_name' => $survey_name,
  642. 'choice_name' => $value[1],
  643. 'is_other' => 1,
  644. 'other_id' => 0,
  645. 'results' => 0,
  646. ];
  647. } else {
  648. $suvey_data[] = [
  649. 'sur_id' => $uuid,
  650. 'art_id' => $id,
  651. 'website_id' => $website_id ?? 2,
  652. 'survey_name' => $survey_name,
  653. 'choice_name' => $value,
  654. 'is_other' => 0,
  655. 'other_id' => 0,
  656. 'results' => 0,
  657. ];
  658. }
  659. if (empty($suvey_data)) {
  660. throw new \Exception("投票数据为空");
  661. }
  662. }
  663. }
  664. $result = ArticleSurvey::insert($suvey_data);
  665. if (!$result) {
  666. throw new \Exception("投票失败");
  667. }
  668. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  669. if (!$result) {
  670. throw new \Exception("投票失败");
  671. }
  672. } else {
  673. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  674. }
  675. Db::commit();
  676. return Result::success([]);
  677. } catch (\Throwable $ex) {
  678. Db::rollBack();
  679. var_dump($ex->getMessage());
  680. return Result::error("更新失败" . $ex->getMessage(), 0);
  681. }
  682. }
  683. /**
  684. * 更新资讯状态
  685. * @param array $data
  686. * @return array
  687. */
  688. public function upArticleStatus(array $data): array
  689. {
  690. $result = Article::where(['id' => $data['id']])->update($data);
  691. if ($result) {
  692. return Result::success();
  693. } else {
  694. return Result::error("更新状态失败", 0);
  695. }
  696. }
  697. /**
  698. * 获取新闻详情
  699. * @param array $data
  700. * @return array
  701. */
  702. public function getArticleInfo(array $data): array
  703. {
  704. $where = [
  705. 'article.id' => $data['id'],
  706. // 'article.status' => 1,
  707. ];
  708. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  709. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  710. $info = $result;
  711. // var_dump($info, 'info');
  712. $info['survey_array'] = $articleSurvey;
  713. if ($result) {
  714. return Result::success($info);
  715. } else {
  716. return Result::error("查询失败", 0);
  717. }
  718. }
  719. /**
  720. * 获取头条新闻
  721. * @param array $data
  722. * @return array
  723. */
  724. public function getWebsiteArticlett(array $data): array
  725. {
  726. // return Result::success($data['website_id']);
  727. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  728. $category = array_values(array_unique($category->toArray()));
  729. $web['website_id'] = $data['website_id'];
  730. if ($category) {
  731. $where = [
  732. 'status' => 1,
  733. ];
  734. var_dump($data, 'data-----------------');
  735. // level=7 根据文章key来匹配文章
  736. if (isset($data['level']) && $data['level'] == 7) {
  737. // 根据文章id获取key
  738. // $data['id'] = 50142;
  739. if (isset($data['id']) && !empty($data['id'])) {
  740. $keyword = Article::where('id', $data['id'])->value('keyword');
  741. $keywordArray = explode(',', $keyword);
  742. $whereL7 = [];
  743. foreach ($keywordArray as $k => $v) {
  744. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  745. }
  746. // 原始查询
  747. $result['level7'] = Article::where($whereL7)
  748. ->when(!empty($data['imgnum']), function ($query) use ($data) {
  749. $query->where('article.imgurl', '!=', '')
  750. ->select('article.*')
  751. ->offset($data['placeid'])
  752. ->limit($data['imgnum']);
  753. })
  754. ->when(!empty($data['textnum']), function ($query) use ($data) {
  755. $query->select('article.*')
  756. ->offset($data['placeid'])
  757. ->limit($data['textnum']);
  758. })
  759. ->orderBy('updated_at', 'desc')
  760. ->get();
  761. $result['level7'] = $this->processArticle($result['level7'], $web);
  762. if (empty($result)) {
  763. return Result::success();
  764. }
  765. return Result::success($result);
  766. } else {
  767. return Result::error("参数错误level=7,id不能为空", 0);
  768. }
  769. }
  770. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  771. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  772. var_dump($where, 'where-----------------');
  773. // 初始化基础查询
  774. $query = Article::where($where)
  775. ->whereIn("catid", $category)
  776. ->where(function ($query) use ($data) {
  777. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  778. ->orWhereNull("ignore_ids");
  779. });
  780. // 处理 level 相关查询条件
  781. $query->when($data['level'] == 5, function ($query) {
  782. $query->inRandomOrder()
  783. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  784. })->when($data['level'] == 4, function ($query) {
  785. $query->orderBy("article.updated_at", "desc");
  786. })->when(!empty($data['level']), function ($query) use ($data) {
  787. if ($data['level'] != 4 && $data['level'] != 5) {
  788. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  789. ->orderBy("article.updated_at", "desc");
  790. }
  791. });
  792. // 初始化结果数组
  793. $result = [];
  794. // $input = $data['website_id'];
  795. // 处理图片新闻查询
  796. if (!empty($data['imgnum'])) {
  797. // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
  798. // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
  799. $imgQuery = clone $query;
  800. if ($imgQuery->getBindings() === null) {
  801. $imgQuery->setBindings([]);
  802. }
  803. $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
  804. ->select(
  805. 'article.id',
  806. 'article.title',
  807. 'article.imgurl',
  808. 'article.author',
  809. 'article.updated_at',
  810. 'article.introduce',
  811. 'article.islink',
  812. 'article.linkurl',
  813. 'article.copyfrom',
  814. 'article.cat_arr_id',
  815. 'article.catid'
  816. )
  817. ->offset($data['placeid'])
  818. ->limit($data['imgnum'])
  819. ->get();
  820. $result['img'] = $this->processArticles($result['img'], $web);
  821. }
  822. // 处理文字新闻查询
  823. if (!empty($data['textnum'])) {
  824. $textQuery = clone $query;
  825. $result['text'] = $textQuery
  826. ->select(
  827. 'article.id',
  828. 'article.title',
  829. 'article.imgurl',
  830. 'article.author',
  831. 'article.updated_at',
  832. 'article.introduce',
  833. 'article.islink',
  834. 'article.linkurl',
  835. 'article.copyfrom',
  836. 'article.cat_arr_id',
  837. 'article.catid'
  838. )
  839. ->offset($data['placeid'])
  840. ->limit($data['textnum'])
  841. ->get();
  842. $result['text'] = $this->processArticles($result['text'], $web);
  843. }
  844. if (empty($result) || count($result) == 0) {
  845. return Result::error("暂无头条新闻");
  846. }
  847. return Result::success($result);
  848. } else {
  849. return Result::error("本网站下暂无相关栏目", 0);
  850. }
  851. }
  852. /**
  853. * 获取模块新闻
  854. * @param array $data
  855. * @return array
  856. */
  857. public function getWebsiteModelArticles(array $data): array
  858. {
  859. $catid = $data['catid'];
  860. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  861. $category = $category->toArray();
  862. if (!empty($category)) {
  863. $where = [
  864. 'status' => 1,
  865. 'catid' => $catid,
  866. ];
  867. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  868. // 1:文字新闻;2:轮播图;3:图文;
  869. // 级别:0:未分类
  870. // 3:推荐图片
  871. if ($data['level'] == 1) {
  872. $data['level'] = 0;
  873. }
  874. $result = Article::where($where)
  875. ->where(function ($query) use ($data) {
  876. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  877. ->orWhereNull("level")
  878. ->orWhereRaw("level = '[]'");
  879. })
  880. ->where(function ($query) use ($data) {
  881. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  882. ->orWhereNull("ignore_ids");
  883. })
  884. ->orderBy("updated_at", "desc")
  885. ->offset($placeid)
  886. ->limit($data['pagesize'])
  887. ->get();
  888. if (empty($result)) {
  889. return Result::error("此栏目暂无相关新闻", 0);
  890. }
  891. } else {
  892. return Result::error("此网站暂无此栏目", 0);
  893. }
  894. return Result::success($result);
  895. }
  896. /**
  897. *获取新闻列表
  898. * @param array $data
  899. * @return array
  900. */
  901. public function getWebsiteArticleList(array $data): array
  902. {
  903. // return Result::success($data);
  904. $where[] = ['status', '=', 1];
  905. if (isset($data['catid']) && !empty($data['catid'])) {
  906. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  907. array_push($where, ['catid', '=', $data['catid']]);
  908. if (empty($category)) {
  909. return Result::error("此网站暂无此栏目", 0);
  910. }
  911. }
  912. // return Result::success($where);
  913. $rep = Article::where($where)
  914. ->where(function ($query) use ($data) {
  915. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  916. ->orWhereNull("ignore_ids");
  917. })
  918. ->select(
  919. 'article.id',
  920. 'article.title',
  921. 'article.imgurl',
  922. 'article.author',
  923. 'article.updated_at',
  924. 'article.introduce',
  925. 'article.islink',
  926. 'article.linkurl',
  927. 'article.copyfrom',
  928. 'article.cat_arr_id',
  929. 'article.catid'
  930. )
  931. ->orderBy("updated_at", "desc")
  932. ->offset(($data['page'] - 1) * $data['pageSize'])
  933. ->limit($data['pageSize'])
  934. ->get();
  935. $web['website_id'] = $data['website_id'];
  936. $rep = $this->processArticles($rep, $web);
  937. $count = Article::where($where)
  938. ->where(function ($query) use ($data) {
  939. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  940. ->orWhereNull("ignore_ids");
  941. })->count();
  942. $data = [
  943. 'rows' => $rep->toArray(),
  944. 'count' => $count,
  945. ];
  946. if (empty($rep)) {
  947. return Result::error("没有信息数据");
  948. }
  949. return Result::success($data);
  950. }
  951. /**
  952. * 前端-获取新闻详情
  953. * @param array $data
  954. * @return array
  955. */
  956. public function selectWebsiteArticleInfo(array $data): array
  957. {
  958. $where = [
  959. 'article.id' => $data['id'],
  960. 'article.status' => 1,
  961. ];
  962. $result = Article::where($where)
  963. ->leftJoin("article_data", "article.id", "article_data.article_id")
  964. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  965. ->where(function ($query) use ($data) {
  966. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  967. ->orWhereNull("ignore_ids");
  968. })
  969. ->first();
  970. if (empty($result)) {
  971. return Result::error("暂无此新闻!", 0);
  972. }
  973. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  974. ->select('website_category.*', 'website.website_name', 'website.suffix')
  975. ->where('website_category.website_id', $data['website_id'])
  976. ->where(['website_category.category_id' => $result['catid']])
  977. ->first();
  978. if (empty($category)) {
  979. return Result::error("查询失败", 0);
  980. }
  981. //手动推荐文章
  982. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  983. $commendArticle = Article::whereIn('id', $commend_ids)
  984. ->where('status', 1)
  985. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  986. ->orderBy('updated_at', 'desc')
  987. ->limit(5)
  988. ->get();
  989. $result['category_id'] = $category['category_id'];
  990. $result['cat_name'] = $category['alias'];
  991. $result['website_name'] = $category['website_name'] ?? "";
  992. $result['suffix'] = $category['suffix'] ?? "";
  993. $result['commendArticle'] = $commendArticle;
  994. return Result::success($result);
  995. }
  996. /**
  997. * 前端-获取网站调查问卷
  998. * @param array $data
  999. * @return array
  1000. */
  1001. public function getWebsiteSurvey(array $data): array
  1002. {
  1003. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1004. $website = Website::where('id', $data['website_id'])->first();
  1005. if (empty($website)) {
  1006. return Result::error("暂无此网站", 0);
  1007. }
  1008. }
  1009. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1010. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1011. if (empty($article)) {
  1012. return Result::error("暂无此文章", 0);
  1013. }
  1014. // return Result::error($data,0);
  1015. $where['art_id'] = $data['art_id'];
  1016. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1017. } else {
  1018. $survey = Article::where(function ($query) {
  1019. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1020. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1021. })
  1022. ->where('status', 1)
  1023. ->where('is_survey', 1)
  1024. ->select('survey_id')
  1025. ->orderBy('updated_at', 'desc')
  1026. ->first();
  1027. if (empty($survey)) {
  1028. return Result::error("暂无调查问卷", 0);
  1029. }
  1030. $where['sur_id'] = $survey['survey_id'];
  1031. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1032. }
  1033. // return Result::success($where);
  1034. $result = ArticleSurvey::where($where)
  1035. ->where(function ($query) {
  1036. $query->where('is_other', 0)
  1037. ->orWhere(function ($subQuery) {
  1038. $subQuery->where('is_other', 1)
  1039. ->where('other_id', 0);
  1040. });
  1041. })
  1042. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1043. ->select('article_survey.*', 'article.survey_type')
  1044. ->get()->all();
  1045. if (empty($result)) {
  1046. return Result::error("此文章暂无调查问卷", 0);
  1047. }
  1048. return Result::success($result);
  1049. }
  1050. /**
  1051. * 前端-添加网站调查问卷选项
  1052. * @param array $data
  1053. * @return array
  1054. */
  1055. public function addWebsiteSurveyOption(array $data): array
  1056. {
  1057. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1058. $website = Website::where('id', $data['website_id'])->first();
  1059. if (empty($website)) {
  1060. return Result::error("暂无此网站", 0);
  1061. }
  1062. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1063. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1064. if (empty($survey)) {
  1065. return Result::error("此调查问卷不可添加选项", 0);
  1066. }
  1067. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1068. $choice = [
  1069. 'art_id' => $survey['art_id'],
  1070. 'website_id' => $data['website_id'],
  1071. 'survey_name' => $survey['survey_name'],
  1072. 'choice_name' => $data['choice_name'],
  1073. 'sur_id' => $survey['sur_id'],
  1074. 'is_other' => 1,
  1075. 'other_id' => $survey['id'],
  1076. ];
  1077. $result = ArticleSurvey::insertGetId($choice);
  1078. if (empty($result)) {
  1079. return Result::error("添加失败", 0);
  1080. }
  1081. return Result::success($result);
  1082. }
  1083. }
  1084. return Result::error("添加失败", 0);
  1085. }
  1086. return Result::error("添加失败", 0);
  1087. }
  1088. /**
  1089. * 前端-调查问卷投票
  1090. * @param array $data
  1091. * @return array
  1092. */
  1093. public function addWebsiteSurveyVote(array $data): array
  1094. {
  1095. // return Result::success($data);
  1096. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1097. $website = Website::where('id', $data['website_id'])->first();
  1098. if (empty($website)) {
  1099. return Result::error("暂无此网站", 0);
  1100. }
  1101. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1102. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1103. // return Result::success($survey);
  1104. if (empty($is_survey)) {
  1105. return Result::error("此调查问卷不存在", 0);
  1106. }
  1107. // return Result::success($survey);
  1108. // 调查问卷类型
  1109. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1110. //多选 若是json型则转化成数组类型
  1111. if (strpos($data['choice_id'], '[') === 0) {
  1112. $data['choice_id'] = json_decode($data['choice_id'], true);
  1113. } else {
  1114. // 单选 也转换成数组
  1115. $data['choice_id'] = [$data['choice_id']];
  1116. }
  1117. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1118. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1119. // ->where('website_id',$data['website_id'])
  1120. ->where('is_other', 1)
  1121. ->where('other_id', 0)
  1122. ->first();
  1123. if (!empty($other)) {
  1124. return Result::error("请选择已有的选项!", 0);
  1125. }
  1126. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1127. // ->where('website_id',$data['website_id'])
  1128. ->where('is_other', 1)
  1129. ->where('other_id', '!=', 0)
  1130. ->first();
  1131. // return Result::success($choice['other']);
  1132. $choice_id = $data['choice_id'];
  1133. if (!empty($choice['other'])) {
  1134. // array_push($data['choice_id'],$choice['other']['other_id']);
  1135. if (!empty($choice_id)) {
  1136. $key = array_search($choice['other']['id'], $choice_id);
  1137. if ($key !== false) {
  1138. unset($choice_id[$key]);
  1139. $choice_id = array_values($choice_id);
  1140. }
  1141. array_push($choice_id, $choice['other']['other_id']);
  1142. } else {
  1143. $choice_id[0] = $choice['other']['other_id'];
  1144. }
  1145. array_push($data['choice_id'], $choice['other']['other_id']);
  1146. }
  1147. // return Result::success($data);
  1148. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1149. // ->where('website_id',$data['website_id'])
  1150. ->increment('results', 1);
  1151. if (empty($choice)) {
  1152. return Result::error("请选择已有的选项!", 0);
  1153. }
  1154. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1155. // ->where('website_id',$data['website_id'])
  1156. ->where('other_id', 0)
  1157. ->get();
  1158. $survey['choice'] = $choice_id;
  1159. return Result::success($survey);
  1160. }
  1161. return Result::error("参数必填!");
  1162. }
  1163. return Result::error("此调查问卷不存在", 0);
  1164. }
  1165. return Result::error("参数必填!");
  1166. }
  1167. /**
  1168. * 后端-获取网站调查问卷列表
  1169. * @param array $data
  1170. * @return array
  1171. */
  1172. public function getSurveyList(array $data): array
  1173. {
  1174. $where = [];
  1175. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1176. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1177. }
  1178. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1179. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1180. }
  1181. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1182. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1183. }
  1184. // return Result::success($where);
  1185. if (!empty($where)) {
  1186. $query = Article::where($where)->where(function ($q) {
  1187. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1188. });
  1189. } else {
  1190. $query = Article::where(function ($q) {
  1191. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1192. });
  1193. }
  1194. $count = $query->count();
  1195. $survey = $query->orderByDesc('id')
  1196. ->limit($data['pageSize'])
  1197. ->offset(($data['page'] - 1) * $data['pageSize'])
  1198. ->get();
  1199. if (empty($survey->toArray())) {
  1200. return Result::error("暂无调查问卷!", 0);
  1201. }
  1202. $result = [
  1203. 'rows' => $survey,
  1204. 'count' => $count,
  1205. ];
  1206. return Result::success($result);
  1207. }
  1208. /**
  1209. * 后端-获取网站调查问卷详情
  1210. * @param array $data
  1211. * @return array
  1212. */
  1213. public function getSurveyInfo(array $data): array
  1214. {
  1215. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1216. $where = ['sur_id' => $data['sur_id']];
  1217. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1218. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1219. ->select('article_survey.*', 'article.survey_type')
  1220. ->get()->all();
  1221. if (empty($choose)) {
  1222. return Result::error("此调查问卷不存在", 0);
  1223. }
  1224. $resultsArray = array_column($choose, 'results');
  1225. $total = array_sum($resultsArray);
  1226. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1227. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1228. // $total = 0;
  1229. if (!empty($other)) {
  1230. $total = $total + $other['results'];
  1231. $other['choice_name'] = '(其他)';
  1232. if (!empty($others)) {
  1233. $other['hasChildren'] = true;
  1234. // array_push($other,['hasChildren','=',true]);
  1235. $other['children'] = $others;
  1236. $other_choices = [$other->toArray()];
  1237. $mer_choice = array_merge($choose, $other_choices);
  1238. $value_choice = array_values($mer_choice);
  1239. } else {
  1240. // return Result::error('1111');
  1241. $other_choices = [$other->toArray()];
  1242. $other_choices = array_merge($choose, $other_choices);
  1243. $value_choice = array_values($other_choices);
  1244. // return Result::success($result);
  1245. }
  1246. } else {
  1247. $value_choice = $choose;
  1248. }
  1249. $result = [
  1250. 'choose' => $value_choice,
  1251. 'total' => $total,
  1252. ];
  1253. }
  1254. return Result::success($result);
  1255. }
  1256. /**
  1257. * 前端-搜索新闻列表
  1258. * @param array $data
  1259. * @return array
  1260. */
  1261. public function selectWebsiteArticle(array $data): array
  1262. {
  1263. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1264. $query = Article::where('status', 1)
  1265. ->whereIn('catid', $category)
  1266. ->where(function ($query) use ($data) {
  1267. $query->where(function ($subQuery) use ($data) {
  1268. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1269. })->orWhereNull("ignore_ids");
  1270. });
  1271. // return Result::success($all_articles);
  1272. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1273. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1274. }
  1275. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1276. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1277. }
  1278. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1279. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1280. }
  1281. // 计算总数
  1282. $count = $query->count();
  1283. // 分页查询
  1284. $articles = $query
  1285. ->select(
  1286. 'article.id',
  1287. 'article.title',
  1288. 'article.imgurl',
  1289. 'article.author',
  1290. 'article.updated_at',
  1291. 'article.introduce',
  1292. 'article.islink',
  1293. 'article.linkurl',
  1294. 'article.copyfrom',
  1295. 'article.cat_arr_id',
  1296. 'article.catid',
  1297. 'article.department_arr_id',
  1298. 'article.city_arr_id',
  1299. )
  1300. ->orderBy("updated_at", "desc")
  1301. ->offset(($data['page'] - 1) * $data['pageSize'])
  1302. ->limit($data['pageSize'])
  1303. ->get();
  1304. $web['website_id'] = $data['website_id'];
  1305. $articles = $this->processArticles($articles, $web);
  1306. if (empty($articles)) {
  1307. return Result::error("没有符合条件的资讯数据");
  1308. }
  1309. $result = [
  1310. 'rows' => $articles,
  1311. 'count' => $count,
  1312. ];
  1313. return Result::success($result);
  1314. }
  1315. /**
  1316. * 模块新闻加强版
  1317. * @param array $data
  1318. * @return array
  1319. */
  1320. public function getWebsiteCatidArticle(array $data): array
  1321. {
  1322. $where = [
  1323. 'website_category.category_id' => $data['catid'],
  1324. 'website_category.website_id' => $data['website_id'],
  1325. ];
  1326. // $category = WebsiteCategory::where($where);
  1327. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1328. $child_catnum = $data['child_catnum'] ?? 1;
  1329. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1330. $childCategoryIds = array_column($category['child'], 'category_id');
  1331. if (empty($childCategoryIds)) {
  1332. return Result::error("暂无子栏目", 0);
  1333. }
  1334. $imgArticles = [];
  1335. $textArticles = [];
  1336. // return Result::success($childCategoryIds);
  1337. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1338. // 初始化子分类图片新闻和文字新闻数组
  1339. // 查询所有子级栏目的图文新闻
  1340. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1341. ->where(function ($query) use ($data) {
  1342. $query->where(function ($subQuery) use ($data) {
  1343. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1344. })->orWhereNull("ignore_ids");
  1345. })
  1346. ->where('status', 1)
  1347. ->where('imgurl', '!=', '')
  1348. ->select('*')
  1349. ->orderBy('updated_at', 'desc')
  1350. ->limit($data['child_imgnum'])
  1351. ->get();
  1352. }
  1353. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1354. // 查询所有子级栏目的文字新闻
  1355. $textArticles = Article::where('catid', $childCategoryIds[0])
  1356. ->where('status', 1)
  1357. ->where(function ($query) use ($data) {
  1358. $query->where(function ($subQuery) use ($data) {
  1359. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1360. })->orWhereNull("ignore_ids");
  1361. })
  1362. ->select('*')
  1363. ->orderBy('updated_at', 'desc')
  1364. ->limit($data['child_textnum'])
  1365. ->get();
  1366. }
  1367. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1368. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1369. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1370. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1371. return $child;
  1372. }, $category['child']);
  1373. }
  1374. // }
  1375. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1376. $category['img'] = WebsiteCategory::where($where)
  1377. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1378. ->where('article.status', 1)
  1379. ->where('article.imgurl', '!=', '')
  1380. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1381. ->orderBy('article.updated_at', 'desc')
  1382. ->limit($data['img_num'])
  1383. ->get();
  1384. }
  1385. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1386. $category['text'] = WebsiteCategory::where($where)
  1387. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1388. ->where('article.status', 1)
  1389. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1390. ->orderBy('article.updated_at', 'desc')
  1391. ->limit($data['text_num'])
  1392. ->get();
  1393. }
  1394. // $category = $category->get();
  1395. if(empty($category)){
  1396. return Result::error("查询失败", 0);
  1397. }
  1398. return Result::success($category);
  1399. }
  1400. /**
  1401. * 模块新闻加强plus版
  1402. * @param array $data
  1403. * @return array
  1404. */
  1405. public function getWebsiteAllArticle(array $data): array
  1406. {
  1407. $time1 = microtime(true);
  1408. $wetbsite_id = $data['website_id'] ?? 2;
  1409. $data = json_decode($data['id'], true);
  1410. $categorys = $this->processArticlePro($wetbsite_id);
  1411. $cat_1st_arr = $categorys['cat_1st_arr'];
  1412. $catiall = $categorys['catiall'];
  1413. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1414. $parent_category = array_column($data, 'parent');
  1415. $parent_cat = [];
  1416. $child_category = array_column($data,'child');
  1417. if(!empty($parent_category)){
  1418. foreach($parent_category as $key => $value){
  1419. $arr = array_map('intval', explode(',', $value));
  1420. $parent_cat[$key] = $arr[0] ?? 0;
  1421. $parent_category = $arr[0] ?? 0;
  1422. $article_imgnum = $arr[1] ?? 0;
  1423. $article_textnum = $arr[2] ?? 0;
  1424. if($parent_category != 0){
  1425. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1426. // return Result::success($category_arr);
  1427. if($article_imgnum != 0){
  1428. $img_article = Article::whereIn('catid', $category_arr)
  1429. ->where('status',1)
  1430. ->where('imgurl','!=', '')
  1431. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1432. $query->from('article_ignore')
  1433. ->where('website_id', $wetbsite_id);
  1434. }, 'article_ignore', function ($join) {
  1435. $join->on('article_ignore.article_id', '=', 'article.id');
  1436. })
  1437. ->where(function ($query) use ($wetbsite_id) {
  1438. $query->whereNull('article_ignore.article_id')
  1439. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1440. })
  1441. ->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')
  1442. ->orderBy('updated_at', 'desc')
  1443. ->limit($article_imgnum)
  1444. ->get()->all();
  1445. foreach ($img_article as $k => $v) {
  1446. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1447. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1448. }
  1449. }else{
  1450. $img_article = [];
  1451. }
  1452. if($article_textnum != 0){
  1453. $text_article = Article::whereIn('catid', $category_arr)
  1454. ->where('status',1)
  1455. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1456. $query->from('article_ignore')
  1457. ->where('website_id', $wetbsite_id);
  1458. }, 'article_ignore', function ($join) {
  1459. $join->on('article_ignore.article_id', '=', 'article.id');
  1460. })
  1461. ->where(function ($query) use ($wetbsite_id) {
  1462. $query->whereNull('article_ignore.article_id')
  1463. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1464. })
  1465. ->select('id','title','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
  1466. ->orderBy('updated_at', 'desc')
  1467. ->limit($article_textnum)
  1468. ->get()->all();
  1469. foreach ($text_article as $k => $v) {
  1470. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1471. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1472. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1473. }
  1474. }else{
  1475. $text_article = [];
  1476. }
  1477. $catiall[$parent_category]['imgnum'] = $img_article;
  1478. $catiall[$parent_category]['textnum'] = $text_article;
  1479. $parent[$key] = $catiall[$parent_category];
  1480. }else{
  1481. $parent[$key] = '';
  1482. }
  1483. }
  1484. }
  1485. if(!empty($child_category)){
  1486. foreach($child_category as $key => $value){
  1487. $arr = array_map('intval', explode(',', $value));
  1488. $parent_category = $parent_cat[$key];
  1489. $child_category = $arr[0] ?? 0;
  1490. $article_imgnum = $arr[1] ?? 0;
  1491. $article_textnum = $arr[2] ?? 0;
  1492. if($child_category != 0){
  1493. $all_childcat = $cat_1st_arr[$parent_category];
  1494. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1495. // 从 $websiteInfoIndexed 中获取对应的数据
  1496. $info = $websiteInfoIndexed[$v];
  1497. // 返回一个包含所需信息的数组
  1498. return [
  1499. 'alias' => $info->alias,
  1500. 'category_id' => $info->category_id,
  1501. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1502. 'pid' => $info->pid,
  1503. 'type' => $info->type,
  1504. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1505. 'pinyin' => $info->pinyin,
  1506. ];
  1507. }, $all_childcat);
  1508. if($article_imgnum != 0){
  1509. $img_article = Article::where('catid', $child_category)
  1510. ->where('status',1)
  1511. ->where('imgurl','!=', '')
  1512. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1513. $query->from('article_ignore')
  1514. ->where('website_id', $wetbsite_id);
  1515. }, 'article_ignore', function ($join) {
  1516. $join->on('article_ignore.article_id', '=', 'article.id');
  1517. })
  1518. ->where(function ($query) use ($wetbsite_id) {
  1519. $query->whereNull('article_ignore.article_id')
  1520. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1521. })
  1522. ->select('id','title','imgurl','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
  1523. ->orderBy('updated_at', 'desc')
  1524. ->limit($article_imgnum)
  1525. ->get()->all();
  1526. foreach ($img_article as $k => $v) {
  1527. // var_dump($v);
  1528. // var_dump($k);
  1529. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1530. $img_article[$k]->alias = $catiall[$v->catid]['alias'];
  1531. }
  1532. }else{
  1533. $img_article = [];
  1534. }
  1535. if($article_textnum != 0){
  1536. $text_article = Article::where('catid', $child_category)
  1537. ->where('status',1)
  1538. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1539. $query->from('article_ignore')
  1540. ->where('website_id', $wetbsite_id);
  1541. }, 'article_ignore', function ($join) {
  1542. $join->on('article_ignore.article_id', '=', 'article.id');
  1543. })
  1544. ->where(function ($query) use ($wetbsite_id) {
  1545. $query->whereNull('article_ignore.article_id')
  1546. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1547. })
  1548. ->select('id','title','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
  1549. ->orderBy('updated_at', 'desc')
  1550. ->limit($article_textnum)
  1551. ->get()->all();
  1552. foreach ($text_article as $k => $v) {
  1553. // var_dump($v);
  1554. // var_dump($k);
  1555. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1556. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1557. $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1558. }
  1559. }else{
  1560. $text_article = [];
  1561. }
  1562. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1563. $catiall[$child_category]['imgnum'] = $img_article;
  1564. $catiall[$child_category]['textnum'] = $text_article;
  1565. $child[$key] = $catiall[$child_category];
  1566. // var_dump($pids);
  1567. }else{
  1568. $child[$key] = '';
  1569. }
  1570. }
  1571. }
  1572. foreach($parent as $key => $value){
  1573. $result[$key] = $value;
  1574. if(!empty($child[$key])){
  1575. // var_dump($child[$key]);
  1576. $result[$key]['child'] = $child[$key];
  1577. // $value[$key]['child'] = $child[$key];
  1578. }else{
  1579. $result[$key]['child'] = [
  1580. "alias" => null,
  1581. "category_id" => null,
  1582. "type" => null,
  1583. "pinyin" => null,
  1584. "all_childcat" => [],
  1585. "imgnum" => [],
  1586. "textnum" => []
  1587. ];
  1588. }
  1589. }
  1590. return Result::success($result);
  1591. }
  1592. /**
  1593. * 辅助方法:获取文章列表
  1594. */
  1595. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1596. {
  1597. sleep(1);
  1598. $query = Article::where('article.status', 1)
  1599. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1600. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1601. ->where(function ($query) use ($website) {
  1602. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1603. })
  1604. ->leftJoin('website_category', function ($join) use ($website) {
  1605. $join->on('article.catid', '=', 'website_category.category_id')
  1606. ->where('website_category.website_id', '=', $website['website_id']);
  1607. })
  1608. ->select(
  1609. 'article.id',
  1610. 'article.title',
  1611. 'article.imgurl',
  1612. 'article.author',
  1613. 'article.updated_at',
  1614. 'article.introduce',
  1615. 'article.islink',
  1616. 'article.linkurl',
  1617. 'article.copyfrom',
  1618. 'article.cat_arr_id',
  1619. 'article.catid',
  1620. 'website_category.alias as category_name'
  1621. )
  1622. ->orderBy('updated_at', 'desc')
  1623. ->limit($limit);
  1624. // 如果是图片文章,添加图片URL条件
  1625. if ($isImageArticle) {
  1626. $query->where('imgurl', '!=', '');
  1627. } else {
  1628. // 文字文章不需要imgurl字段
  1629. $query->addSelect('article.introduce');
  1630. }
  1631. $articles = $query->get();
  1632. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1633. }
  1634. /**
  1635. * 乡村网-获取特殊新闻模块
  1636. * @param array $data
  1637. * @return array
  1638. */
  1639. public function getWebsiteArticles(array $data): array
  1640. {
  1641. $input['id'] = $data['id'];
  1642. $input['website_id'] = $data['website_id'];
  1643. $data = json_decode($input['id'], true);
  1644. // 使用 array_map 处理每个元素
  1645. $result = array_map(function ($item) use ($input) {
  1646. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1647. $website = [
  1648. 'website_id' => $input['website_id']
  1649. ];
  1650. // 查询栏目名称
  1651. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1652. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1653. if (empty($category)) {
  1654. $imgArticles = [];
  1655. $textArticles = [];
  1656. // return Result::error("暂无此栏目",0);
  1657. } else {
  1658. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1659. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1660. // return Result::success($website);
  1661. // 查询图片新闻
  1662. // 合并查询条件
  1663. $baseQuery = Article::where(function ($query) use ($website) {
  1664. $query->where(function ($subQuery) use ($website) {
  1665. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1666. })->orWhereNull("ignore_ids");
  1667. })
  1668. ->where('article.status', 1)
  1669. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1670. ->where('website_category.website_id', $website['website_id']);
  1671. // 查询文字新闻
  1672. $textArticles = clone $baseQuery;
  1673. $textArticles = $textArticles->whereIn('catid', $child_category)
  1674. ->select(
  1675. 'article.id',
  1676. 'article.title',
  1677. // 'article.imgurl',
  1678. 'article.author',
  1679. 'article.updated_at',
  1680. 'article.introduce',
  1681. 'article.islink',
  1682. 'article.linkurl',
  1683. 'article.copyfrom',
  1684. 'website_category.category_id',
  1685. 'website_category.alias',
  1686. 'website_category.aLIas_pinyin'
  1687. )
  1688. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1689. ->orderBy('article.updated_at', 'desc')
  1690. ->limit($parentTextNum)
  1691. ->get()
  1692. ->all();
  1693. if (empty($textArticles)) {
  1694. $textArticles = clone $baseQuery;
  1695. $textArticles = $textArticles->where('catid', $parentCatId)
  1696. ->select(
  1697. 'article.id',
  1698. 'article.title',
  1699. // 'article.imgurl',
  1700. 'article.author',
  1701. 'article.updated_at',
  1702. 'article.introduce',
  1703. 'article.islink',
  1704. 'article.linkurl',
  1705. 'article.copyfrom',
  1706. 'website_category.category_id',
  1707. 'website_category.alias',
  1708. 'website_category.aLIas_pinyin'
  1709. )
  1710. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1711. ->orderBy('article.updated_at', 'desc')
  1712. ->limit($parentTextNum)
  1713. ->get()
  1714. ->all();
  1715. }
  1716. // 查询图片新闻
  1717. $imgArticles = clone $baseQuery;
  1718. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1719. ->select(
  1720. 'article.id',
  1721. 'article.title',
  1722. 'article.imgurl',
  1723. 'article.author',
  1724. 'article.updated_at',
  1725. 'article.introduce',
  1726. 'article.islink',
  1727. 'article.linkurl',
  1728. 'article.copyfrom',
  1729. 'website_category.category_id',
  1730. 'website_category.alias',
  1731. 'website_category.aLIas_pinyin'
  1732. )
  1733. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1734. ->orderBy('article.updated_at', 'desc')
  1735. ->limit($parentImgNum)
  1736. ->get()
  1737. ->all();
  1738. if (empty($imgArticles)) {
  1739. $imgArticles = clone $baseQuery;
  1740. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1741. ->select(
  1742. 'article.id',
  1743. 'article.title',
  1744. 'article.imgurl',
  1745. 'article.author',
  1746. 'article.updated_at',
  1747. 'article.introduce',
  1748. 'article.islink',
  1749. 'article.linkurl',
  1750. 'article.copyfrom',
  1751. 'website_category.category_id',
  1752. 'website_category.alias',
  1753. 'website_category.aLIas_pinyin'
  1754. )
  1755. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1756. ->orderBy('article.updated_at', 'desc')
  1757. ->limit($parentImgNum)
  1758. ->get()
  1759. ->all();
  1760. }
  1761. }
  1762. $resultItem = [
  1763. 'alias' => $category ? $category->alias : null,
  1764. 'category_id' => $parentCatId,
  1765. 'pinyin' => $pinyin ? $pinyin : null,
  1766. 'imgnum' => $imgArticles ?? [],
  1767. 'textnum' => $textArticles ?? [],
  1768. ];
  1769. return $resultItem;
  1770. }, $data);
  1771. return Result::success($result);
  1772. }
  1773. // 封装处理商品的路由问题
  1774. function processGoods($goods, $data)
  1775. {
  1776. return $goods->map(function ($good) use ($data) {
  1777. $catid = $good->catid ?? 0;
  1778. // $pinyin = '';
  1779. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1780. if (!empty($category->pid) && $category->pid != 0) {
  1781. $level = json_decode($category->category_arr_id, true);
  1782. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1783. ->whereIn('category_id', $level)
  1784. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1785. ->get(['aLIas_pinyin'])
  1786. ->pluck('aLIas_pinyin')
  1787. ->implode('/');
  1788. } else {
  1789. $pinyin = $category->aLIas_pinyin ?? '';
  1790. }
  1791. if (isset($good->city_id) && !empty($good->city_id)) {
  1792. $city = District::where('id', $good->city_id)->first(['name']);
  1793. $good->city_name = $city->name ?? '';
  1794. }
  1795. // 解析imgurl JSON并取第一条数据
  1796. $imgUrls = json_decode($good->imgurl, true);
  1797. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1798. $good->pinyin = $pinyin;
  1799. return $good;
  1800. });
  1801. }
  1802. /**
  1803. * 获取商城首页-根据栏目id
  1804. * @param array $data
  1805. * @return array
  1806. * */
  1807. function getWebsiteCatidshop(array $data): array
  1808. {
  1809. $input['catid'] = $data['catid'];
  1810. $input['website_id'] = $data['website_id'];
  1811. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1812. $result = array_map(function ($item) use ($input) {
  1813. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1814. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1815. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1816. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1817. if (empty($category) || $category->type != 2) {
  1818. return Result::error("暂无此栏目", 0);
  1819. } else {
  1820. $website['website_id'] = $input['website_id'];
  1821. $goods = Good::where('good.status', 2)
  1822. ->where('good.website_id', $website['website_id'])
  1823. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1824. ->select(
  1825. 'good.id',
  1826. 'good.name',
  1827. 'good.imgurl',
  1828. 'good.description',
  1829. 'good.updated_at',
  1830. 'good.catid',
  1831. 'good.type_id',
  1832. 'good.price',
  1833. 'good.com',
  1834. 'good.level',
  1835. 'good.unit'
  1836. )
  1837. ->orderBy('updated_at', 'desc')
  1838. ->offset($goodStart)
  1839. ->limit($goodNum);
  1840. $all_goods = $goods->get();
  1841. $all_goods = $this->processGoods($all_goods, $website);
  1842. }
  1843. return $all_goods ?? [];
  1844. }
  1845. }, $data);
  1846. return Result::success($result);
  1847. }
  1848. /**
  1849. * 获取商品模块
  1850. * @param array $data
  1851. * @return array
  1852. * */
  1853. public function getWebsiteshop(array $data): array
  1854. {
  1855. $input['id'] = $data['id'];
  1856. $input['website_id'] = $data['website_id'];
  1857. $catid = $data['catid'];
  1858. $data = json_decode($input['id'] ?? '', true) ?? [];
  1859. $result['goods'] = array_map(function ($item) use ($input) {
  1860. // 检查parent元素是否存在且不是undefined
  1861. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1862. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1863. $website = $input['website_id'];
  1864. $query = Good::where('good.status', 2)
  1865. ->where('good.website_id', $website);
  1866. switch ($Levelid) {
  1867. case 1:
  1868. case 2:
  1869. case 3:
  1870. $goods = $query->where(function ($q) use ($Levelid) {
  1871. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1872. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1873. });
  1874. break;
  1875. case 4:
  1876. $goods = $query;
  1877. break;
  1878. case 5:
  1879. $goods = $query->where('type_id', 1);
  1880. break;
  1881. case 6:
  1882. $goods = $query->where('type_id', 2);
  1883. break;
  1884. default:
  1885. return [];
  1886. }
  1887. $all_goods = $goods
  1888. ->select(
  1889. 'good.id',
  1890. 'good.name',
  1891. 'good.imgurl',
  1892. 'good.description',
  1893. 'good.updated_at',
  1894. 'good.catid',
  1895. 'good.type_id',
  1896. 'good.price',
  1897. 'good.level',
  1898. 'good.website_id'
  1899. )
  1900. ->orderBy('updated_at', 'desc')
  1901. ->offset($goodStart)
  1902. ->limit($goodNum)
  1903. ->get();
  1904. $web['website_id'] = $website;
  1905. $all_goods = $this->processGoods($all_goods, $web);
  1906. }
  1907. return $all_goods;
  1908. }, $data);
  1909. $website = $input['website_id'];
  1910. $result['article'] = Article::where(function ($query) use ($website) {
  1911. $query->where(function ($subQuery) use ($website) {
  1912. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1913. })->orWhereNull("ignore_ids");
  1914. })
  1915. ->where('catid', $catid)
  1916. ->where('article.status', 1)
  1917. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1918. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1919. ->orderBy('article.updated_at', 'desc')
  1920. ->first();
  1921. return Result::success($result);
  1922. }
  1923. /**
  1924. * 获取商品分类
  1925. * @param array $data
  1926. * @return array
  1927. * */
  1928. public function getWebsiteshopCat(array $data): array
  1929. {
  1930. $website = $data['website_id'];
  1931. $category = WebsiteCategory::where('website_id', $website)
  1932. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1933. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1934. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  1935. ->orderBy('sort')
  1936. ->get();
  1937. $cat = $category->map(function ($item) use ($website) {
  1938. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1939. $pid = $item->pid ?? 0;
  1940. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1941. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1942. ->where('website_id', $website)
  1943. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1944. ->get(['aLIas_pinyin'])
  1945. ->pluck('aLIas_pinyin')
  1946. ->implode('/');
  1947. } else {
  1948. $pinyin = $item->aLIas_pinyin ?? '';
  1949. }
  1950. $item->pinyin = $pinyin;
  1951. });
  1952. if (empty($category)) {
  1953. return Result::error("栏目查询失败", 0);
  1954. }
  1955. $cat_tree = Result::buildMenuTree($category);
  1956. $web['website_id'] = $website;
  1957. $goods = Good::where('website_id', $website)
  1958. ->where('status', 2)
  1959. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1960. ->latest('updated_at')
  1961. ->offset(($data['page'] - 1) * $data['pageSize'])
  1962. ->limit($data['pageSize'])
  1963. ->get();
  1964. if (!empty($goods)) {
  1965. if ($goods->count() > 1 && !empty($goods)) {
  1966. $goods = $this->processGoods($goods, $web);
  1967. }
  1968. } else {
  1969. $goods = [];
  1970. }
  1971. $result = [
  1972. 'category' => $cat_tree,
  1973. 'goods' => $goods,
  1974. ];
  1975. // $resul['goods'] = $goods;
  1976. if (empty($result)) {
  1977. return Result::error("查询失败", 0);
  1978. }
  1979. return Result::success($result);
  1980. }
  1981. /*
  1982. * 获取商品列表
  1983. * @param array $data
  1984. * @return array
  1985. * */
  1986. public function getWebsiteshopList(array $data): array
  1987. {
  1988. // return Result::success($data);
  1989. $where = [
  1990. 'status' => 2,
  1991. 'website_id' => $data['website_id'],
  1992. ];
  1993. if((empty($data['catid']) ||!isset($data['catid'])) && (empty($data['keyword']) ||!isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))){
  1994. return Result::error("查询失败", 0);
  1995. }
  1996. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1997. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid',$data['id'])->orderBy('sort')->first(['category_id']);
  1998. $data['catid'] = $category->category_id ?? 0;
  1999. }
  2000. if(isset($data['keyword']) &&!empty($data['keyword'])){
  2001. array_push($where, ['name', 'like', '%'. $data['keyword'].'%']);
  2002. }
  2003. if(isset($data['type_id']) && !empty($data['type_id'])){
  2004. array_push($where, ['type_id', $data['type_id']]);
  2005. }
  2006. $query = Good::where($where)
  2007. ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
  2008. $query->where(function($q) use ($data) {
  2009. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($data['catid']). "') = 1")
  2010. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"". intval($data['catid']). "\"') = 1");
  2011. });
  2012. })
  2013. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2014. $query->where(function($q) use ($data) {
  2015. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '". intval($data['city_id']). "') = 1")
  2016. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"". intval($data['city_id']). "\"') = 1");
  2017. });
  2018. })
  2019. ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at', 'good.com',
  2020. 'good.catid','good.type_id','good.website_id','good.cat_arr_id','good.created_at','good.city_id')
  2021. ->latest('updated_at');
  2022. if(isset($data['ismix']) && $data['ismix'] == 1){
  2023. $result['count'] = $query->clone()->count();
  2024. $result['goods'] = $this->processGoods(
  2025. $query->clone()
  2026. ->offset(($data['page'] - 1) * $data['pageSize'])
  2027. ->limit($data['pageSize'])
  2028. ->get(),
  2029. $data
  2030. );
  2031. }else{
  2032. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2033. // 获取 type_id 为 1 的数据
  2034. $result['type1'] = $this->processGoods(
  2035. $query->clone()
  2036. ->where('type_id', 1)
  2037. ->offset(($data['page'] - 1) * $data['pageSize'])
  2038. ->limit($data['pageSize'])
  2039. ->get(),
  2040. $data
  2041. );
  2042. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2043. // 获取 type_id 为 2 的数据
  2044. $result['type2'] = $this->processGoods(
  2045. $query->clone()
  2046. ->where('type_id', 2)
  2047. ->offset(($data['page'] - 1) * $data['pageSize'])
  2048. ->limit($data['pageSize'])
  2049. ->get(),
  2050. $data
  2051. );
  2052. }
  2053. if(empty($result)){
  2054. return Result::error("查询失败", 0);
  2055. }
  2056. return Result::success($result);
  2057. }
  2058. /**
  2059. * 获取商品详情
  2060. * @param array $data
  2061. * @return array
  2062. * */
  2063. public function getWebsiteshopInfo(array $data): array
  2064. {
  2065. $where = [
  2066. 'good.status' => 2,
  2067. 'good.website_id' => $data['website_id'],
  2068. 'good.id' => $data['id'],
  2069. ];
  2070. $goods = Good::where($where)
  2071. ->where('good.id', $data['id'])
  2072. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2073. ->select('good.*','website_category.alias','website_category.category_id')
  2074. ->first();
  2075. if(empty($goods)){
  2076. return Result::error("查询失败", 0);
  2077. }
  2078. $goods->imgurl = json_decode($goods->imgurl, true);
  2079. return Result::success($goods);
  2080. }
  2081. /**
  2082. * plus pro 处理文章路由问题
  2083. */
  2084. function processArticlePro($website_id){
  2085. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2086. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2087. // 取出category_id 对应的aLIas_pinyin
  2088. $categoryIds = array_column($categorys, 'category_id');
  2089. $categoryPIds = array_column($categorys, 'pid');
  2090. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2091. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2092. // return Result::success($categorys);
  2093. $catiall = [];
  2094. //一级所有子级的记录
  2095. $cat_1st_arr = [];
  2096. foreach ($categorys as $key => $value) {
  2097. $category_arr_id = json_decode($value->category_arr_id);
  2098. $pinyin_str = '';
  2099. // 算出一级 并且算出子级
  2100. if ($value->pid != 0) {
  2101. $cat_1st_arr[$value->pid][] = $value->category_id;
  2102. }
  2103. foreach ($category_arr_id as $k => $v) {
  2104. $pinyin_str .= $cat_arr[$v] . '/';
  2105. }
  2106. $pinyin_str = rtrim($pinyin_str, '/');
  2107. $catiall[$value->category_id]['alias'] = $value->alias;
  2108. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2109. $catiall[$value->category_id]['type'] = $value->type;
  2110. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2111. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2112. }
  2113. return [
  2114. 'cat_1st_arr' => $cat_1st_arr,
  2115. 'catiall' => $catiall,
  2116. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2117. ];
  2118. }
  2119. /**
  2120. * 封装处理文章的路由问题
  2121. * */
  2122. function processArticles($articles, $data) {
  2123. // 检查 $articles 是否为数组或可迭代对象
  2124. if (is_array($articles) || is_iterable($articles) &&!empty($articles)) {
  2125. return $articles->map(function ($article) use ($data) {
  2126. if(isset($article->cat_arr_id) &&!empty($article->cat_arr_id)){
  2127. $catid = $article->cat_arr_id?? '';
  2128. }
  2129. if(isset($article->category_arr_id) &&!empty($article->category_arr_id)){
  2130. $catid = $article->category_arr_id?? '';
  2131. }
  2132. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2133. $level = json_decode($catid, true);
  2134. if (!is_array($level)) {
  2135. return $article;
  2136. } else {
  2137. $level = array_map('intval', $level);
  2138. }
  2139. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2140. ->where($data)
  2141. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  2142. ->pluck('aLIas_pinyin')
  2143. ->implode('/');
  2144. $article->pinyin = $pinyin ?? '';
  2145. return $article;
  2146. });
  2147. } else {
  2148. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2149. $catid = $articles->cat_arr_id?? '';
  2150. $level = json_decode($catid, true);
  2151. if (!is_array($level)) {
  2152. return $articles;
  2153. } else {
  2154. $level = array_map('intval', $level);
  2155. }
  2156. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2157. ->where($data)
  2158. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  2159. ->pluck('aLIas_pinyin')
  2160. ->implode('/');
  2161. $articles->pinyin = $pinyin ?? '';
  2162. return $articles;
  2163. }
  2164. }
  2165. // 封装处理由问题
  2166. function processJob($job, $data) {
  2167. return $job->map(function ($job) use ($data) {
  2168. $category = $job->cat_arr_id?? '';
  2169. $cityid = $job->city_arr_id?? '';
  2170. $city = json_decode($cityid, true);
  2171. $pinyin = '';
  2172. $level = json_decode($category, true);
  2173. // 路由
  2174. if(!empty($level) && is_array($level)){
  2175. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2176. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2177. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  2178. ->get(['aLIas_pinyin'])
  2179. ->pluck('aLIas_pinyin')
  2180. ->implode('/');
  2181. if(empty($pinyin)){
  2182. $pinyin = $pinyin->aLIas_pinyin?? '';
  2183. }
  2184. $job->pinyin = $pinyin;
  2185. }
  2186. // 取职位-城市 市??省
  2187. if(!empty($city) && is_array($city)){
  2188. if(isset($city[1] ) && !empty($city[1])){
  2189. $city = District::where('id', $city[1])->first(['name']);
  2190. $job->city_name = $city->name?? '';
  2191. }else if(isset($city[0] ) && !empty($city[0])){
  2192. $city = District::where('id', $city[0])->first(['name']);
  2193. $job->city_name = $city->name?? '';
  2194. }else{
  2195. $job->city_name = '全国';
  2196. }
  2197. }
  2198. // 获取简历最后一级地区
  2199. if(isset($job->city_id) &&!empty($job->city_id)){
  2200. $city = District::where('id', $job->city_id)->first(['name']);
  2201. $job->hunt_cityname = $city->name?? '';
  2202. }
  2203. // 组合详细地址
  2204. if(isset($job->address_arr_id) && !empty($job->address_arr_id)){
  2205. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2206. if(is_array($address_id) && !empty($address_id)){
  2207. $address = District::whereIn('id', $address_id)
  2208. ->orderBy('level', 'asc')
  2209. ->get(['name'])
  2210. ->pluck('name')
  2211. ->implode('');
  2212. // $job->address_name = $address ?? '';
  2213. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2214. }
  2215. }
  2216. // 取行业
  2217. if(!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))){
  2218. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2219. if(!empty($job->industry)){
  2220. $query->where('hyid', $job->industry);
  2221. }else if(!empty($job->hy_id)){
  2222. $query->where('hyid', $job->hy_id);
  2223. }else if(!empty($job->company_hy_id)){
  2224. $query->where('hyid', $job->company_hy_id);
  2225. } else{
  2226. $query->where('hyid', $job->job_industry);
  2227. }
  2228. })->first(['hyname']);
  2229. $job->hy_name = $hy_name->hyname?? '';
  2230. }
  2231. // 取职位类别
  2232. if((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))){
  2233. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2234. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2235. $job->zw_name = $zw_name->zwname?? '';
  2236. }
  2237. // 取具体职位
  2238. 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))){
  2239. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2240. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2241. $job->jtzw_name = $jtzw_name->zwname?? '';
  2242. }
  2243. // 取工作经验
  2244. if(isset($job->experience) &&!empty($job->experience)){
  2245. $experience = JobEnum::where('egroup','years')->where('evalue',$job->experience)->first(['ename']);
  2246. $job->experience_name = $experience->ename?? '';
  2247. }
  2248. // 取学历
  2249. if(isset($job->educational) &&!empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2250. $education = $job->educational ?? $job->school_education;
  2251. $education = JobEnum::where('egroup','education')->where('evalue',$education)->first(['ename']);
  2252. $job->education_name = $education->ename?? '';
  2253. }
  2254. // 语言
  2255. if(isset($job->language) &&!empty($job->language)){
  2256. $language = JobEnum::where('egroup','language')->where('evalue',$job->language)->first(['ename']);
  2257. $job->language_name = $language->ename?? '';
  2258. }
  2259. // 薪资
  2260. if(isset($job->salary) &&!empty($job->salary)){
  2261. $salary = JobEnum::where('egroup','income')->where('evalue',$job->salary)->first(['ename']);
  2262. $job->salary_name = $salary->ename?? '';
  2263. }
  2264. // 职位性质
  2265. if(isset($job->nature_id) &&!empty($job->nature_id)){
  2266. $job_nature = JobEnum::where('egroup','nature')->where('evalue',$job->nature_id)->first(['ename']);
  2267. $job->job_nature_name = $job_nature->ename?? '';
  2268. }
  2269. // 公司规模
  2270. if(isset($job->company_size) &&!empty($job->company_size)){
  2271. $company_size = JobEnum::where('egroup','cosize')->where('evalue',$job->company_size)->first(['ename']);
  2272. $job->company_size_name = $company_size->ename?? '';
  2273. }
  2274. // 公司性质
  2275. if(isset($job->company_nature) && !empty($job->company_nature)){
  2276. $company_nature = JobNature::where('id',$job->company_nature)->first(['nature_name']);
  2277. $job->company_nature_name = $company_nature->nature_name?? '';
  2278. }
  2279. // $job->pinyin = $pinyin;
  2280. return $job;
  2281. });
  2282. }
  2283. /**
  2284. * 获取书籍模块
  2285. * @param array $data
  2286. * @return array
  2287. * */
  2288. public function getWebsiteBook(array $data): array
  2289. {
  2290. $input['id'] = $data['id'];
  2291. $input['website_id'] = $data['website_id'];
  2292. // 将 JSON 字符串转换为 PHP 数组
  2293. $data = json_decode($input['id'], true);
  2294. // 使用 array_map 处理每个元素
  2295. $result = array_map(function ($item) use ($input) {
  2296. // 检查parent元素是否存在且不是undefined
  2297. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "") {
  2298. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2299. $website = [
  2300. 'website_id' => $input['website_id'],
  2301. ];
  2302. // 查询栏目名称
  2303. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  2304. if(empty($category)){
  2305. $parent_alias = '';
  2306. $parent_pinyin = null;
  2307. $imgBooks = [];
  2308. $textBooks = [];
  2309. }else{
  2310. $parent_alias = $category->alias ?? '';
  2311. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2312. // 查找子分类ID数组
  2313. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2314. array_push($childCategoryIds,$parentCatId);
  2315. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2316. if($parentImgNum!=0){
  2317. // 查询图片新闻
  2318. $imgBooks = Book::where(function($query) use ($parentCatId) {
  2319. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2320. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2321. })
  2322. ->where('book.status', 2)
  2323. ->where('book.img_url', '!=', '')
  2324. ->leftJoin('website_category', function($join) use ($website) {
  2325. $join->on('book.cat_id', '=', 'website_category.category_id')
  2326. ->where('website_category.website_id', '=', $website['website_id']);
  2327. })
  2328. ->select(
  2329. 'book.id',
  2330. 'book.title',
  2331. 'book.img_url',
  2332. 'book.price',
  2333. 'book.market_price',
  2334. 'book.description',
  2335. 'book.cat_id',
  2336. 'book.description',
  2337. 'book.updated_at',
  2338. 'website_category.alias as category_name',
  2339. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2340. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2341. )
  2342. ->orderBy('updated_at', 'desc')
  2343. ->limit($parentImgNum)
  2344. ->get()->all();
  2345. // 查询文字新闻
  2346. }
  2347. if ($parentTextNum != 0) {
  2348. $textBooks = [];
  2349. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2350. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2351. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2352. })
  2353. ->where('book.status', 2)
  2354. ->leftJoin('website_category', function ($join) use ($website) {
  2355. $join->on('book.cat_id', '=', 'website_category.category_id')
  2356. ->where('website_category.website_id', '=', $website['website_id']);
  2357. })
  2358. ->select(
  2359. 'book.id',
  2360. 'book.title',
  2361. 'book.img_url',
  2362. 'book.price',
  2363. 'book.market_price',
  2364. 'book.description',
  2365. 'book.cat_id',
  2366. 'book.description',
  2367. 'book.updated_at',
  2368. 'website_category.alias as category_name',
  2369. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2370. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2371. )
  2372. ->orderBy('updated_at', 'desc')
  2373. ->limit($parentTextNum)
  2374. ->get()->all();
  2375. }
  2376. }
  2377. }
  2378. $resultItem = [
  2379. 'alias' => $parent_alias ?? '',
  2380. 'category_id' => $parentCatId ?? 0,
  2381. 'pinyin' => $parent_pinyin ?? null,
  2382. 'imgnum' => $imgBooks ?? [],
  2383. 'textnum' => $textBooks ?? [],
  2384. ];
  2385. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2386. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2387. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2388. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2389. ->get()->all();
  2390. if (!empty($childCategory)) {
  2391. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2392. // 查询子栏目名称
  2393. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2394. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2395. ->first();
  2396. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2397. $childImgArticles = [];
  2398. $childTextArticles = [];
  2399. $resultItem['child'] = [];
  2400. } else {
  2401. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2402. // 查询子栏目图片新闻
  2403. $childImgArticles = Book::where('cat_id', $childCatId)
  2404. ->where('status', 2)
  2405. ->where('img_url', '!=', '')
  2406. ->leftJoin('website_category', function ($join) use ($website) {
  2407. $join->on('book.cat_id', '=', 'website_category.category_id')
  2408. ->where('website_category.website_id', '=', $website['website_id']);
  2409. })
  2410. ->select(
  2411. 'book.id',
  2412. 'book.title',
  2413. 'book.img_url',
  2414. 'book.price',
  2415. 'book.market_price',
  2416. 'book.description',
  2417. 'book.cat_id',
  2418. 'book.description',
  2419. 'book.updated_at',
  2420. DB::raw("'$child_pinyin' as pinyin")
  2421. )
  2422. ->orderBy('updated_at', 'desc')
  2423. ->limit($childImgNum)
  2424. ->get()->all();
  2425. // 查询子栏目文字新闻
  2426. $childTextArticles = Book::where('cat_id', $childCatId)
  2427. ->where('status', 2)
  2428. ->leftJoin('website_category', function ($join) use ($website) {
  2429. $join->on('book.cat_id', '=', 'website_category.category_id')
  2430. ->where('website_category.website_id', '=', $website['website_id']);
  2431. })
  2432. ->select(
  2433. 'book.id',
  2434. 'book.title',
  2435. 'book.img_url',
  2436. 'book.price',
  2437. 'book.market_price',
  2438. 'book.description',
  2439. 'book.cat_id',
  2440. 'book.description',
  2441. 'book.updated_at',
  2442. DB::raw("'$child_pinyin' as pinyin")
  2443. )
  2444. ->orderBy('updated_at', 'desc')
  2445. ->limit($childTextNum)
  2446. ->get()->all();
  2447. $resultItem['child'] = [
  2448. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2449. 'category_id' => $childCatId,
  2450. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2451. 'all_childcat' => $childCategory,
  2452. 'imgnum' => $childImgArticles,
  2453. 'textnum' => $childTextArticles,
  2454. ];
  2455. }
  2456. }
  2457. } else {
  2458. $resultItem['child'] = [];
  2459. }
  2460. return $resultItem;
  2461. }, $data);
  2462. return Result::success($result);
  2463. }
  2464. /**
  2465. * 获取书刊列表
  2466. * @param array $data
  2467. * @return array
  2468. * */
  2469. public function getWebsiteBookList(array $data): array
  2470. {
  2471. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2472. if (empty($web)) {
  2473. return Result::error("查询失败", 0);
  2474. }
  2475. $catid = $data['id'];
  2476. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2477. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2478. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2479. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2480. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2481. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2482. ->where('pid', $category['pid'])
  2483. ->select(
  2484. 'category_id',
  2485. 'alias',
  2486. 'aLIas_pinyin',
  2487. 'pid',
  2488. 'sort',
  2489. 'is_url',
  2490. 'web_url',
  2491. 'seo_title',
  2492. 'seo_keywords',
  2493. 'seo_description',
  2494. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2495. )
  2496. ->orderBy('sort')
  2497. ->get()->all();
  2498. if (empty($category)) {
  2499. return Result::error("查询失败", 0);
  2500. }
  2501. $query = Book::where('book.status', 2)
  2502. ->where('book.website_id', $data['website_id'])
  2503. ->where('book.cat_id', $catid)
  2504. ->select(
  2505. 'book.id',
  2506. 'book.title',
  2507. 'book.img_url',
  2508. 'book.description',
  2509. 'book.updated_at',
  2510. 'book.cat_id',
  2511. DB::raw("'$pinyin' as pinyin")
  2512. )
  2513. ->orderBy('book.updated_at', 'desc');
  2514. $count = $query->count();
  2515. $query = clone $query;
  2516. $Book = $query
  2517. ->limit($data['pageSize'])
  2518. ->offset(($data['page'] - 1) * $data['pageSize'])
  2519. ->get()->all();
  2520. $result = [
  2521. 'category' => $categorys,
  2522. 'books' => $Book,
  2523. 'count' => $count,
  2524. ];
  2525. // if(empty($result)){
  2526. // return Result::error("查询失败", 0);
  2527. // }
  2528. return Result::success($result);
  2529. }
  2530. /**
  2531. * 获取书刊详情
  2532. * @param array $data
  2533. * @return array
  2534. * */
  2535. public function getWebsiteBookInfo(array $data): array
  2536. {
  2537. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2538. if (empty($web)) {
  2539. return Result::error("查询失败", 0);
  2540. }
  2541. $book = Book::where('status', 2)
  2542. ->where('website_id', $data['website_id'])
  2543. ->where('id', $data['id'])
  2544. ->select(
  2545. 'book.*',
  2546. )
  2547. ->orderBy('updated_at', 'desc')
  2548. ->first();
  2549. if (empty($book)) {
  2550. return Result::error("查询失败", 0);
  2551. }
  2552. // 先查询当前分类的 pid
  2553. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2554. ->where('category_id', $book['cat_id'])
  2555. ->first(['pid', 'category_id']);
  2556. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2557. if (!empty($carpid)) {
  2558. if ($carpid->pid != 0) {
  2559. $pid = $carpid['pid'];
  2560. // $parent_pinyin = '';
  2561. } else {
  2562. $pid = $carpid['category_id'];
  2563. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2564. }
  2565. }
  2566. $categorys = $query->where('pid', $pid)
  2567. ->select(
  2568. 'category_id',
  2569. 'alias',
  2570. 'aLIas_pinyin',
  2571. 'pid',
  2572. 'sort',
  2573. 'is_url',
  2574. 'web_url',
  2575. 'category_arr_id as cat_arr_id',
  2576. )
  2577. ->orderBy('sort')
  2578. ->get();
  2579. $category = $this->processArticle($categorys, $data);
  2580. $result = [
  2581. 'category' => $category,
  2582. 'books' => $book,
  2583. ];
  2584. return Result::success($result);
  2585. }
  2586. /**
  2587. * 尝试
  2588. * @param array $data
  2589. * @return array
  2590. * */
  2591. public function test(array $data): array
  2592. {
  2593. $input['id'] = $data['id'];
  2594. $input['website_id'] = $data['website_id'];
  2595. // 将 JSON 字符串转换为 PHP 数组
  2596. $data = json_decode($input['id'], true);
  2597. $result = [];
  2598. $article = $data;
  2599. $result = array_map(function ($item) use ($input) {
  2600. $website = [
  2601. 'website_id' => $input['website_id'],
  2602. ];
  2603. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2604. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2605. $parent = [
  2606. 0 => $category['category_id'] ?? [],
  2607. 1 => $parentImgNum ?? [],
  2608. 2 => $parentTextNum ?? [],
  2609. ];
  2610. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2611. $child = [];
  2612. $resultItem = [
  2613. // 'alias' => $parent_alias ?? '',
  2614. 'category_id' => $parentCatId ?? 0,
  2615. 'pinyin' => $parentImgNum ?? null,
  2616. 'imgnum' => $parentTextNum ?? [],
  2617. // 'textnum' => $textArticles ?? [],
  2618. ];
  2619. return $parent;
  2620. }, $data);
  2621. return Result::success($result);
  2622. // });
  2623. }
  2624. /**
  2625. * 封装处理文章的路由问题
  2626. * */
  2627. function processArticle($article, $data)
  2628. {
  2629. return $article->map(function ($article) use ($data) {
  2630. $catid = $article->cat_arr_id ?? '';
  2631. $level = json_decode($catid, true);
  2632. $pinyin = '';
  2633. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2634. if (!empty($level) && is_array($level)) {
  2635. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2636. ->where('website_id', $data['website_id'])
  2637. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2638. ->get(['aLIas_pinyin'])
  2639. ->pluck('aLIas_pinyin')
  2640. ->implode('/');
  2641. } else {
  2642. $pinyin = '';
  2643. }
  2644. $article->pinyin = $pinyin;
  2645. return $article;
  2646. });
  2647. }
  2648. /**
  2649. * c端-获取招工招聘下拉选框
  2650. * @param array $data
  2651. * @return array
  2652. * */
  2653. public function getWebsiteJobSelect(array $data): array
  2654. {
  2655. $web = Website::where('id', $data['website_id'])->first();
  2656. if (empty($web)) {
  2657. return Result::error("该网站不存在", 0);
  2658. }
  2659. $hy = JobIndustry::get()->all();
  2660. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2661. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2662. $result = [
  2663. 'hy' => $hy,
  2664. 'zw' => $zw,
  2665. 'jtzw' => $jtzw,
  2666. ];
  2667. if (empty($result)) {
  2668. return Result::error("查询失败", 0);
  2669. }
  2670. return Result::success($result);
  2671. }
  2672. /**
  2673. * c端-获取招工招聘
  2674. * @param array $data
  2675. * @return array
  2676. * */
  2677. public function getWebsiteJob(array $data): array
  2678. {
  2679. $web = Website::where('id', $data['website_id'])->first();
  2680. if (empty($web)) {
  2681. return Result::error("该网站不存在", 0);
  2682. }
  2683. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2684. ->where('job_hunting.website_id', $data['website_id'])
  2685. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2686. $query->where(function ($q) use ($data) {
  2687. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2688. });
  2689. })
  2690. ->select(
  2691. 'job_hunting.id',
  2692. 'job_hunting.cat_arr_id',
  2693. 'job_hunting.job_name_get',
  2694. 'job_hunting.industry',
  2695. 'job_hunting.name',
  2696. 'job_hunting.sexy',
  2697. 'job_hunting.origin',
  2698. 'job_hunting.city_arr_id',
  2699. 'job_hunting.experience',
  2700. 'job_hunting.updated_at',
  2701. 'job_hunting.salary'
  2702. )
  2703. ->orderBy('updated_at', 'desc')
  2704. ->limit($data['job1_num'])
  2705. ->get();
  2706. $web['website_id'] = $data['website_id'];
  2707. if (empty($job_hunting)) {
  2708. $job_huntings = "未查询到相关简历信息";
  2709. } else {
  2710. $job_huntings = $this->processJob($job_hunting, $web);
  2711. }
  2712. // 0:待审核 1:已通过 2:已拒绝
  2713. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2714. ->where('job_recruiting.website_id', $data['website_id'])
  2715. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2716. $query->where(function ($q) use ($data) {
  2717. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2718. });
  2719. })
  2720. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2721. ->select(
  2722. 'job_recruiting.id',
  2723. 'job_recruiting.cat_arr_id',
  2724. 'job_recruiting.title',
  2725. 'job_recruiting.jtzw_id',
  2726. 'job_recruiting.hy_id',
  2727. 'job_recruiting.city_arr_id',
  2728. 'job_recruiting.due_data',
  2729. 'job_recruiting.updated_at',
  2730. 'job_recruiting.experience',
  2731. 'job_recruiting.educational',
  2732. 'job_recruiting.salary',
  2733. 'job_recruiting.zw_id',
  2734. 'job_company.business_name'
  2735. )
  2736. ->orderBy('updated_at', 'desc')
  2737. ->limit($data['job2_num'])
  2738. ->get();
  2739. if (empty($job_recruiting->toArray())) {
  2740. $job_recruitings = "未查询到相关职位信息";
  2741. } else {
  2742. $job_recruitings = $this->processJob($job_recruiting, $web);
  2743. }
  2744. $result = [
  2745. 'job_hunting' => $job_huntings,
  2746. 'job_recuiting' => $job_recruitings,
  2747. ];
  2748. return Result::success($result);
  2749. }
  2750. /**
  2751. * c端-获取招工招聘列表
  2752. * @param array $data
  2753. * @return array
  2754. * */
  2755. public function getWebsiteJobList(array $data): array
  2756. {
  2757. $recruit_where = [];
  2758. $hunt_where = [];
  2759. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2760. if (empty($web)) {
  2761. return Result::error("此网站不存在", 0);
  2762. }
  2763. $website_id['website_id'] = $data['website_id'];
  2764. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2765. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2766. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2767. }
  2768. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2769. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2770. }
  2771. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2772. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2773. }
  2774. if(isset($data['keyword']) && !empty($data['keyword'])){
  2775. array_push($recruit_where, ['title','like','%'.$data['keyword'].'%']);
  2776. }
  2777. $query = JobRecruiting::where('job_recruiting.status', 1)
  2778. ->where('job_recruiting.website_id', $data['website_id'])
  2779. ->where($recruit_where)
  2780. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2781. $query->where(function ($q) use ($data) {
  2782. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2783. });
  2784. })
  2785. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2786. $query->where(function ($q) use ($data) {
  2787. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2788. });
  2789. })
  2790. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2791. ->select(
  2792. 'job_recruiting.id',
  2793. 'job_recruiting.hy_id',
  2794. 'job_recruiting.title',
  2795. 'job_recruiting.zw_id',
  2796. 'job_recruiting.educational',
  2797. 'job_recruiting.jtzw_id',
  2798. 'job_recruiting.city_arr_id',
  2799. 'job_recruiting.due_data',
  2800. 'job_recruiting.experience',
  2801. 'job_recruiting.cat_arr_id',
  2802. 'job_recruiting.updated_at',
  2803. 'job_company.business_name'
  2804. )
  2805. ->orderBy('updated_at', 'desc');
  2806. $recruit_count = $query->count();
  2807. $query = clone $query;
  2808. $JobRecruiting = $query
  2809. ->offset(($data['page'] - 1) * $data['pageSize'])
  2810. ->limit($data['pageSize'])
  2811. ->get();
  2812. if (empty($JobRecruiting)) {
  2813. $JobRecruiting = "暂无相关职位信息";
  2814. } else {
  2815. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2816. }
  2817. }
  2818. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2819. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2820. array_push($hunt_where, ['job', $data['zw_id']]);
  2821. }
  2822. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2823. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2824. }
  2825. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2826. array_push($hunt_where, ['industry', $data['hy_id']]);
  2827. }
  2828. $query = JobHunting::where('status', 2)
  2829. ->where('job_hunting.website_id', $data['website_id'])
  2830. ->where($hunt_where)
  2831. ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  2832. $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  2833. })
  2834. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2835. $query->where(function ($q) use ($data) {
  2836. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2837. });
  2838. })
  2839. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2840. $query->where(function ($q) use ($data) {
  2841. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2842. });
  2843. })
  2844. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2845. ->orderBy('updated_at', 'desc');
  2846. $hunt_count = $query->count();
  2847. $query = clone $query;
  2848. $JobHunting = $query
  2849. ->offset(($data['page'] - 1) * $data['pageSize'])
  2850. ->limit($data['pageSize'])
  2851. ->get();
  2852. if (empty($JobHunting)) {
  2853. $JobRecruiting = "暂无相关简历信息";
  2854. } else {
  2855. $JobHunting = $this->processJob($JobHunting, $website_id);
  2856. }
  2857. }
  2858. $result = [
  2859. 'JobRecruiting' => $JobRecruiting ?? [],
  2860. 'recruit_count' => $recruit_count ?? 0,
  2861. 'JobHunting' => $JobHunting ?? [],
  2862. 'hunt_count' => $hunt_count ?? 0,
  2863. ];
  2864. return Result::success($result);
  2865. }
  2866. /**
  2867. * c端-获取招工招聘详情
  2868. * @param array $data
  2869. * @return array
  2870. * */
  2871. public function getWebsiteJobInfo(array $data): array
  2872. {
  2873. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2874. if (empty($web)) {
  2875. return Result::error("该网站不存在", 0);
  2876. }
  2877. $webid = [
  2878. 'website_id' => $data['website_id'],
  2879. ];
  2880. // 职位相关信息
  2881. if ($data['type'] == 1) {
  2882. $query = JobRecruiting::where('status', 1)
  2883. ->where('website_id', $data['website_id'])
  2884. ->select('*');
  2885. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2886. $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();
  2887. if (!empty($company)) {
  2888. $result['company'] = $this->processJob($company, $webid);
  2889. }
  2890. $other_job = JobRecruiting::where('status', 1)
  2891. ->where('website_id', $data['website_id'])
  2892. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2893. ->where('id', '!=', $data['id'])
  2894. ->where('user_id', '=', $job[0]['user_id'])
  2895. ->limit($data['pageSize'])
  2896. ->get();
  2897. if (!empty($other_job)) {
  2898. $result['other_job'] = $this->processJob($other_job, $webid);
  2899. }
  2900. } else {
  2901. // 简历相关信息
  2902. $job = JobHunting::where('job_hunting.status', 2)
  2903. ->where('job_hunting.website_id', $data['website_id'])
  2904. ->where('job_hunting.id', $data['id'])
  2905. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2906. ->select('job_hunting.*', 'user_name')
  2907. ->get();
  2908. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2909. if (!empty($resume->toArray())) {
  2910. $result['resume'] = 1;
  2911. } else {
  2912. $result['resume'] = 0;
  2913. }
  2914. }
  2915. if (empty($job->toArray())) {
  2916. return Result::error("id参数错误", 0);
  2917. }
  2918. if (!empty($job[0]['job_experience'])) {
  2919. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2920. if (!empty($job_experience)) {
  2921. // $hy = [];
  2922. foreach ($job_experience as $key => $value) {
  2923. // $id = $value['id'];
  2924. $hy[$key] = $value['job_industry'];
  2925. $zw_id[$key] = $value['job_typename'];
  2926. $jtzw_id[$key] = $value['job_name'];
  2927. }
  2928. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2929. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2930. // 先将关联表转换为索引数组,提高查找效率
  2931. $hyLookup = [];
  2932. foreach ($hy_table as $item) {
  2933. $hyLookup[$item['hyid']] = $item['hyname'];
  2934. }
  2935. $zwLookup = [];
  2936. foreach ($zw_table as $item) {
  2937. $zwLookup[$item['zwid']] = $item['zwname'];
  2938. }
  2939. foreach ($job_experience as $key => &$value) {
  2940. // 处理行业名称
  2941. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2942. $value['hy_name'] = $hyLookup[$hy[$key]];
  2943. }
  2944. // 处理职位名称
  2945. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2946. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2947. }
  2948. // 处理具体职位名称
  2949. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2950. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2951. }
  2952. }
  2953. // 释放引用,防止意外修改后续代码
  2954. unset($value);
  2955. }
  2956. $result['job_experience'] = $job_experience ?? [];
  2957. }
  2958. if (!empty($job[0]['education_experience'])) {
  2959. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2960. if (!empty($education_experience)) {
  2961. foreach ($education_experience as $key => $value) {
  2962. // $id = $value['id'];
  2963. $education[$key] = $value['school_education'];
  2964. }
  2965. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2966. // // 先将关联表转换为索引数组,提高查找效率
  2967. $educationLookup = [];
  2968. foreach ($education_table as $item) {
  2969. $educationLookup[$item['evalue']] = $item['ename'];
  2970. }
  2971. foreach ($education_experience as $key => &$value) {
  2972. // 处理学历名称
  2973. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2974. $value['education_name'] = $educationLookup[$education[$key]];
  2975. }
  2976. }
  2977. }
  2978. $result['education_experience'] = $job_experience ?? [];
  2979. }
  2980. $result['job'] = $this->processJob($job, $webid);
  2981. // // 返现对应的栏目
  2982. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2983. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2984. ->whereIn('category_id', $catid)
  2985. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2986. ->orderBy('pid')->get()->all();
  2987. if (!empty($category)) {
  2988. $result['category'] = $category;
  2989. }
  2990. $result['job'] = $job;
  2991. $result['job_experience'] = $job_experience ?? [];
  2992. $result['education_experience'] = $education_experience ?? [];
  2993. if (empty($result)) {
  2994. return Result::error("参数错误", 0);
  2995. }
  2996. return Result::success($result);
  2997. }
  2998. /**
  2999. * c端-申请职位
  3000. * @param array $data
  3001. * @return array
  3002. * */
  3003. public function getWebsiteJobApply(array $data): array
  3004. {
  3005. // 首先验证网站是否存在
  3006. // return Result::success($data);
  3007. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3008. if (empty($web)) {
  3009. return Result::error("该网站不存在", 0);
  3010. }
  3011. // 验证用户是否存在且为个人会员/管理员
  3012. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3013. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3014. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3015. return Result::error("用户不存在", 0);
  3016. }
  3017. // 去除重复元素和空元素,并保持原始顺序
  3018. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3019. return !empty($value);
  3020. }));
  3021. // 验证职位是否存在 1:审核通过
  3022. $recruiting = JobRecruiting::where('status', 1)
  3023. ->where('website_id', $data['website_id'])
  3024. ->whereIn('id', $data['recruit_id'])
  3025. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3026. if (empty($recruiting)) {
  3027. return Result::error("该职位不存在", 0);
  3028. }
  3029. // 简历是否存在
  3030. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3031. if (empty($hunt_id)) {
  3032. return Result::error("该简历不存在", 0);
  3033. }
  3034. $data['hunt_id'] = $hunt_id['hunt_id'];
  3035. // // 验证是否已投递过该职位
  3036. $apply = JobApply::where('user_id', $data['user_id'])
  3037. ->where('hunt_id', $data['hunt_id'])
  3038. ->where('website_id', $data['website_id'])
  3039. ->whereIn('recruit_id', $data['recruit_id'])
  3040. ->get(['recruit_id']);
  3041. if (!empty($apply->toArray())) {
  3042. return Result::error("您已投递过该职位!");
  3043. }
  3044. $insertData = array_map(function ($recruiting) use ($data) {
  3045. return [
  3046. 'user_id' => $data['user_id'],
  3047. 'hunt_id' => $data['hunt_id'],
  3048. 'website_id' => $data['website_id'],
  3049. 'recruit_id' => $recruiting['recruit_id'],
  3050. 'receiver_id' => $recruiting['receiver_id'],
  3051. 'status' => 1,
  3052. ];
  3053. }, $recruiting);
  3054. // 批量插入数据
  3055. $result = JobApply::insert($insertData);
  3056. if (empty($result)) {
  3057. return Result::error("投递失败", 0);
  3058. }
  3059. return Result::success($result);
  3060. }
  3061. /**
  3062. * 招工招聘-沟通简历
  3063. * @param array $data
  3064. * @return array
  3065. * */
  3066. public function getWebsiteJobResume(array $data): array
  3067. {
  3068. // 首先验证网站是否存在
  3069. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3070. if (empty($web)) {
  3071. return Result::error("该网站不存在", 0);
  3072. }
  3073. // return Result::success($data);
  3074. // 验证用户是否存在且为企业会员/管理员
  3075. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3076. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3077. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3078. return Result::error("用户不存在", 0);
  3079. }
  3080. // 去除重复元素和空元素,并保持原始顺序
  3081. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3082. return !empty($value);
  3083. }));
  3084. // 验证简历是否存在
  3085. $hunting = JobHunting::where('status', 2)
  3086. ->where('website_id', $data['website_id'])
  3087. ->whereIn('id', $data['hunt_id'])
  3088. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3089. if (empty($hunting)) {
  3090. return Result::error("该简历不存在", 0);
  3091. }
  3092. // 验证是否已沟通过该简历
  3093. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3094. ->where('recruit_id', $data['recruit_id'])
  3095. ->where('website_id', $data['website_id'])
  3096. ->whereIn('hunt_id', $data['hunt_id'])
  3097. ->get(['hunt_id']);
  3098. if (!empty($remuse->toArray())) {
  3099. return Result::error("您已沟通过该简历!");
  3100. }
  3101. // 准备要插入的数据数组
  3102. $insertData = array_map(function ($hunting) use ($data) {
  3103. return [
  3104. 'user_id' => $data['user_id'],
  3105. 'recruit_id' => $data['recruit_id'],
  3106. 'website_id' => $data['website_id'],
  3107. 'hunt_id' => $hunting['hunt_id'],
  3108. 'receiver_id' => $hunting['receiver_id'],
  3109. 'status' => 1,
  3110. ];
  3111. }, $hunting);
  3112. // 批量插入数据
  3113. $result = JobRemuse::insert($insertData);
  3114. if (empty($result)) {
  3115. return Result::error("沟通失败", 0);
  3116. }
  3117. return Result::success($result);
  3118. }
  3119. /**
  3120. * 招工招聘 -我的职位(企业会员)
  3121. * @param array $data
  3122. * @return array
  3123. */
  3124. public function getWebsiteJobRecruiting(array $data): array
  3125. {
  3126. $web = Website::where('id', $data['website_id'])->first('id');
  3127. if (empty($web)) {
  3128. return Result::error("该网站不存在", 0);
  3129. }
  3130. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3131. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3132. return Result::error("用户暂无权限!", 0);
  3133. }
  3134. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3135. $result = JobRecruiting::where('website_id', $data['website_id'])
  3136. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3137. $query->where('user_id', $user['id']);
  3138. })
  3139. ->where('status', 1)
  3140. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3141. ->orderBy('updated_at', 'desc')
  3142. ->limit($data['pageSize'])
  3143. ->get();
  3144. if (empty($result)) {
  3145. return Result::error("暂无相关职位信息", 0);
  3146. }
  3147. return Result::success($result);
  3148. }
  3149. /**
  3150. * c端 - 验证路由
  3151. * @param array $data
  3152. * @return array
  3153. */
  3154. /**
  3155. * c端 - 验证路由
  3156. * @param array $data
  3157. * @return array
  3158. */
  3159. public function checkWebsiteRoute(array $data): array
  3160. {
  3161. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name','status']);
  3162. if (empty($web)) {
  3163. return Result::error("该网站不存在", 0);
  3164. }elseif ($web['status'] != 1){
  3165. return Result::error("网站已经关闭", 0);
  3166. }
  3167. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3168. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3169. if (empty($whiteRouterInfo)) {
  3170. return Result::error("非法路径地址", 0);
  3171. } else {
  3172. return Result::success($whiteRouterInfo->toArray());
  3173. }
  3174. } else {
  3175. // 验证栏目路由
  3176. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3177. ->where('aLIas_pinyin', $data['last_route'])
  3178. ->first();
  3179. if (empty($last_category)) {
  3180. return Result::error("该栏目不存在", 0);
  3181. }
  3182. if (isset($data['id']) && !empty($data['id'])) {
  3183. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3184. switch ($last_category['type']) {
  3185. case 1:
  3186. // 文章
  3187. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3188. $article = Article::where('status', 1)
  3189. ->where('id', $data['id'])
  3190. ->where(function ($query) use ($data) {
  3191. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3192. ->orWhereNull("ignore_ids");
  3193. })
  3194. ->first(['cat_arr_id']);
  3195. if (empty($article)) {
  3196. return Result::error("该文章不存在", 0);
  3197. }
  3198. // return Result::success($article);
  3199. break;
  3200. case 2:
  3201. // 商品
  3202. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3203. $article = Good::where('website_id', $data['website_id'])
  3204. ->where('status', 2)
  3205. ->where('id', $data['id'])
  3206. ->first(['cat_arr_id']);
  3207. if (empty($article)) {
  3208. return Result::error("该商品不存在", 0);
  3209. }
  3210. break;
  3211. case 3:
  3212. // 书刊信息
  3213. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3214. $article = Book::where('website_id', $data['website_id'])
  3215. ->where('status', 2)
  3216. ->where('id', $data['id'])
  3217. ->first(['id', 'cat_arr_id']);
  3218. if (empty($article)) {
  3219. return Result::error("该书刊不存在", 0);
  3220. }
  3221. break;
  3222. case 4:
  3223. // 招聘
  3224. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3225. $article = JobRecruiting::where('website_id', $data['website_id'])
  3226. ->where('status', 1)
  3227. ->where('id', $data['id'])
  3228. ->first(['cat_arr_id']);
  3229. if (empty($article)) {
  3230. return Result::error("该招聘不存在", 0);
  3231. }
  3232. break;
  3233. case 5:
  3234. // 求职
  3235. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3236. $article = JobHunting::where('website_id', $data['website_id'])
  3237. ->where('status', 2)
  3238. ->where('id', $data['id'])
  3239. ->first(['cat_arr_id']);
  3240. if (empty($article)) {
  3241. return Result::error("该求职不存在", 0);
  3242. }
  3243. break;
  3244. case 6:
  3245. // 招工招聘
  3246. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3247. $article = JobRecruiting::where('website_id', $data['website_id'])
  3248. ->where('status', 1)
  3249. ->where('id', $data['id'])
  3250. ->first(['cat_arr_id']);
  3251. if (empty($article)) {
  3252. $article = JobHunting::where('website_id', $data['website_id'])
  3253. ->where('status', 2)
  3254. ->where('id', $data['id'])
  3255. ->first(['cat_arr_id']);
  3256. }
  3257. if (empty($article)) {
  3258. return Result::error("该招工招聘不存在", 0);
  3259. }
  3260. break;
  3261. default:
  3262. return Result::error("该数据不存在", 0);
  3263. break;
  3264. }
  3265. $catid = json_decode($article['cat_arr_id'], true);
  3266. if (empty($catid)) {
  3267. return Result::error("该数据不存在", 0);
  3268. }
  3269. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3270. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3271. ->whereIn('category_id', $catid)
  3272. ->pluck('aLIas_pinyin')
  3273. ->implode('/');
  3274. }
  3275. if ($last_category['pid'] != 0) {
  3276. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3277. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3278. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3279. ->whereIn('category_id', $cat_arr)
  3280. ->pluck('aLIas_pinyin')
  3281. ->implode('/');
  3282. } else {
  3283. $pinyin = $last_category['aLIas_pinyin'];
  3284. }
  3285. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3286. return Result::error('非法路径!');
  3287. } else {
  3288. return Result::success($pinyin);
  3289. }
  3290. }
  3291. }
  3292. /**
  3293. * 招工招聘 - 获取推荐职位
  3294. * @param array $data
  3295. * @return array
  3296. */
  3297. public function getWebsiteLevelJob(array $data): array
  3298. {
  3299. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3300. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3301. ->where('job_recruiting.status', 1)
  3302. ->where('job_level', $data['job_level'])
  3303. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3304. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3305. ->orderBy('job_recruiting.updated_at', 'desc')
  3306. ->limit($data['pageSize'])
  3307. ->get();
  3308. $web = ['website_id' => $data['website_id']];
  3309. if (!empty($job)) {
  3310. $result = $this->processJob($job, $web);
  3311. }
  3312. if (empty($result)) {
  3313. return Result::error("暂无相关职位信息", 0);
  3314. }
  3315. return Result::success($result);
  3316. }
  3317. /**
  3318. * 验证导航名称是否重复
  3319. * @return void
  3320. */
  3321. //20250226 产品列表
  3322. public function getGoodList(array $data): array
  3323. {
  3324. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3325. unset($data['type_id']);
  3326. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3327. $where = [];
  3328. if ($type_id != '10000') {
  3329. $where = [
  3330. 'good.user_id' => $user_id,
  3331. ];
  3332. }
  3333. //类型
  3334. if (isset($data['type_id']) && $data['type_id']) {
  3335. $where = [
  3336. 'type_id' => $data['type_id'],
  3337. ];
  3338. }
  3339. //名称
  3340. if (isset($data['name']) && $data['name']) {
  3341. $where = [
  3342. 'good.name' => $data['name'],
  3343. ];
  3344. }
  3345. //status
  3346. if (isset($data['status']) && $data['status'] != '') {
  3347. $where = [
  3348. 'good.status' => $data['status'],
  3349. ];
  3350. }
  3351. //status1
  3352. // if (isset($data['status1']) && $data['status1'] == 1) {
  3353. // $status1 = 1;
  3354. // }
  3355. $where1 = [];
  3356. //website_id
  3357. // if (isset($data['website_id']) && $data['website_id']) {
  3358. // $where1 = [
  3359. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3360. // ];
  3361. // }
  3362. // website_name
  3363. if (isset($data['website_name']) && $data['website_name']) {
  3364. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3365. }
  3366. // catid
  3367. if (isset($data['category_name']) && $data['category_name']) {
  3368. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3369. }
  3370. // $result = Good::where($where)
  3371. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3372. $result = Good::where($where)
  3373. ->when(!empty($where1), function ($query) use ($where1) {
  3374. return $query->where($where1);
  3375. })
  3376. //status 1待审核2已审核3已拒绝
  3377. ->when(isset($data['status1']), function ($query) {
  3378. return $query->whereIn('good.status', [1, 3]);
  3379. })
  3380. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3381. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3382. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3383. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3384. ->orderBy("updated_at", "desc")
  3385. ->limit($data['page_size'])
  3386. ->offset(($data['page'] - 1) * $data['page_size'])
  3387. ->get();
  3388. $count = Good::where($where)
  3389. ->when(!empty($where1), function ($query) use ($where1) {
  3390. return $query->where($where1);
  3391. })
  3392. //status 1待审核2已审核3已拒绝
  3393. ->when(isset($data['status1']), function ($query) {
  3394. return $query->whereIn('good.status', [1, 3]);
  3395. })
  3396. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3397. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3398. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3399. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3400. ->orderBy("updated_at", "desc")->count();
  3401. $data = [
  3402. 'rows' => $result->toArray(),
  3403. 'count' => $count,
  3404. ];
  3405. if (empty($result)) {
  3406. return Result::error("此栏目暂无相关产品", 0);
  3407. }
  3408. return Result::success($data);
  3409. }
  3410. public function getGoodInfo(array $data): array
  3411. {
  3412. $result = Good::where('id', $data['id'])->first();
  3413. if (empty($result)) {
  3414. return Result::error("此产品不存在", 0);
  3415. }
  3416. return Result::success($result);
  3417. }
  3418. public function addGood(array $data): array
  3419. {
  3420. // unset($data['city_arr_id']);
  3421. // unset($data['cat_arr_id']);
  3422. $data['city_id'] = end($data['city_arr_id']);
  3423. $data['catid'] = end($data['cat_arr_id']);
  3424. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3425. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3426. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3427. unset($data['imgUrl']); //大小写
  3428. if (isset($data['price']) && $data['price'] == '') {
  3429. $data['price'] = 0;
  3430. }
  3431. if ($data['imgurl'] == '') {
  3432. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3433. preg_match_all($reg, $data['detail'], $matches);
  3434. if (isset($matches[1][0])) {
  3435. //截取varchar240
  3436. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3437. }
  3438. }
  3439. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3440. //提取标题+内容中的关键词
  3441. $data['keyword'] = $data['name'];
  3442. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3443. Jieba::init(); // 初始化 jieba-php
  3444. Finalseg::init();
  3445. $segList = Jieba::cut($data['keyword']);
  3446. $segList1 = array_slice($segList, 0, 8);
  3447. $data['keyword'] = implode(',', $segList1);
  3448. }
  3449. if ($data['description'] == '') {
  3450. //提取内容中的描述
  3451. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3452. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3453. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3454. }
  3455. $result = Good::insert($data);
  3456. if (empty($result)) {
  3457. return Result::error("添加失败", 0);
  3458. }
  3459. return Result::success($result);
  3460. }
  3461. public function updateGood(array $data): array
  3462. {
  3463. $data['city_id'] = end($data['city_arr_id']);
  3464. $data['catid'] = end($data['cat_arr_id']);
  3465. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3466. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3467. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3468. //设置东八区
  3469. date_default_timezone_set('Asia/Shanghai');
  3470. $data['updated_at'] = date('Y-m-d H:i:s');
  3471. if (isset($data['price']) && $data['price'] == '') {
  3472. $data['price'] = 0;
  3473. }
  3474. if ($data['imgurl'] == '') {
  3475. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3476. preg_match_all($reg, $data['detail'], $matches);
  3477. if (isset($matches[1][0])) {
  3478. //截取varchar240
  3479. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3480. }
  3481. }
  3482. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3483. //提取标题+内容中的关键词
  3484. $data['keyword'] = $data['name'];
  3485. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3486. Jieba::init(); // 初始化 jieba-php
  3487. Finalseg::init();
  3488. $segList = Jieba::cut($data['keyword']);
  3489. $segList1 = array_slice($segList, 0, 8);
  3490. $data['keyword'] = implode(',', $segList1);
  3491. }
  3492. if ($data['description'] == '') {
  3493. //提取内容中的描述
  3494. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3495. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3496. }
  3497. $result = Good::where('id', $data['id'])->update($data);
  3498. if (empty($result)) {
  3499. return Result::error("更新失败", 0);
  3500. }
  3501. return Result::success($result);
  3502. }
  3503. public function delGood(array $data): array
  3504. {
  3505. $result = Good::where('id', $data['id'])->delete();
  3506. if (empty($result)) {
  3507. return Result::error("删除失败", 0);
  3508. }
  3509. return Result::success($result);
  3510. }
  3511. //20250226 产品列表
  3512. //20250306 求职信息
  3513. public function getJobHuntingList(array $data): array
  3514. {
  3515. $where = [];
  3516. if (isset($data['username']) && !empty($data['username'])) {
  3517. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3518. }
  3519. //status 1待审核2已审核3已拒绝
  3520. if (isset($data['status']) && $data['status'] != '') {
  3521. $where = [
  3522. 'job_hunting.status' => $data['status'],
  3523. ];
  3524. }
  3525. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3526. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3527. unset($data['type_id']);
  3528. if ($type_id != '10000') {
  3529. $where[] = ['job_hunting.user_id', '=', $user_id];
  3530. }
  3531. $result = JobHunting::where($where)
  3532. ->when(!empty($data['status1']), function ($query) use ($data) {
  3533. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3534. })
  3535. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3536. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3537. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3538. ->orderBy("updated_at", "desc")
  3539. ->limit($data['page_size'])
  3540. ->offset(($data['page'] - 1) * $data['page_size'])
  3541. ->get();
  3542. if (empty($result)) {
  3543. return Result::error("查询失败", 0);
  3544. }
  3545. $count = JobHunting::where($where)
  3546. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3547. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3548. ->count();
  3549. $data = [
  3550. 'rows' => $result->toArray(),
  3551. 'count' => $count,
  3552. ];
  3553. return Result::success($data);
  3554. }
  3555. public function getJobHuntingApply(array $data): array
  3556. {
  3557. var_dump($data, '-----------------test--------1-');
  3558. $where = [];
  3559. if (isset($data['username']) && !empty($data['username'])) {
  3560. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3561. }
  3562. if (isset($data['salary']) && !empty($data['salary'])) {
  3563. $where[] = [
  3564. 'job_hunting.salary',
  3565. '=',
  3566. $data['salary'],
  3567. ];
  3568. }
  3569. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3570. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3571. unset($data['type_id']);
  3572. if ($type_id != '10000') {
  3573. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3574. }
  3575. var_dump($where, '-----------------test---------');
  3576. $result = jobApply::where($where)
  3577. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3578. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3579. // })
  3580. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3581. ->where('job_enum.egroup', '=', 'income')
  3582. ->where('job_hunting.status', 2) //已审核
  3583. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3584. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3585. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3586. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3587. //职位----是申请职位
  3588. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3589. ->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')
  3590. ->orderBy("job_hunting.updated_at", "desc")
  3591. ->limit($data['page_size'])
  3592. ->offset(($data['page'] - 1) * $data['page_size'])
  3593. ->get();
  3594. if (empty($result)) {
  3595. return Result::error("查询失败", 0);
  3596. }
  3597. $count = jobApply::where($where)
  3598. ->where('job_enum.egroup', '=', 'income')
  3599. ->where('job_hunting.status', 2) //已审核
  3600. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3601. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3602. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3603. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3604. //职位----是申请职位
  3605. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3606. ->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')
  3607. ->count();
  3608. $data = [
  3609. 'rows' => $result->toArray(),
  3610. 'count' => $count,
  3611. ];
  3612. return Result::success($data);
  3613. }
  3614. public function addJobHunting(array $data): array
  3615. {
  3616. date_default_timezone_set('Asia/Shanghai');
  3617. unset($data['company_name']);
  3618. unset($data['job_industry']);
  3619. unset($data['job_name']);
  3620. unset($data['department']);
  3621. unset($data['job_timeList']);
  3622. unset($data['job_content']);
  3623. unset($data['job_typename']); //不知道这是啥,
  3624. $data['created_at'] = date('Y-m-d H:i:s');
  3625. $data['updated_at'] = date('Y-m-d H:i:s');
  3626. //根据用户 user_id 只能添加一次
  3627. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3628. if (!empty($result)) {
  3629. return Result::error("您已添加过求职信息", 0);
  3630. }
  3631. var_dump($result, '-----------------test---------');
  3632. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3633. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3634. $cityArr = json_decode($data['city_arr_id'], true);
  3635. $data['city_id'] = end($cityArr);
  3636. } else {
  3637. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3638. $data['city_id'] = end($data['city_arr_id']);
  3639. }
  3640. $result = JobHunting::create($data);
  3641. if (empty($result)) {
  3642. return Result::error("添加失败", 0);
  3643. }
  3644. return Result::success($result);
  3645. }
  3646. public function delJobHunting(array $data): array
  3647. {
  3648. $result = JobHunting::where('id', $data['id'])->delete();
  3649. if (empty($result)) {
  3650. return Result::error("删除失败", 0);
  3651. }
  3652. return Result::success($result);
  3653. }
  3654. public function updateJobHunting(array $data): array
  3655. {
  3656. //设置东八区
  3657. date_default_timezone_set('Asia/Shanghai');
  3658. unset($data['company_name']);
  3659. unset($data['job_industry']);
  3660. unset($data['job_name']);
  3661. unset($data['department']);
  3662. unset($data['job_timeList']);
  3663. unset($data['job_content']);
  3664. unset($data['job_typename']); //不知道这是啥,
  3665. $data['created_at'] = date('Y-m-d H:i:s');
  3666. $data['updated_at'] = date('Y-m-d H:i:s');
  3667. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3668. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3669. $cityArr = json_decode($data['city_arr_id'], true);
  3670. $data['city_id'] = end($cityArr);
  3671. } else {
  3672. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3673. $data['city_id'] = end($data['city_arr_id']);
  3674. }
  3675. $result = JobHunting::where('id', $data['id'])->update($data);
  3676. if (empty($result)) {
  3677. return Result::error("更新失败", 0);
  3678. }
  3679. return Result::success($result);
  3680. }
  3681. public function getJobHuntingInfo(array $data): array
  3682. {
  3683. $result = JobHunting::where('id', $data['id'])->first();
  3684. if (empty($result)) {
  3685. return Result::error("查询失败", 0);
  3686. }
  3687. return Result::success($result);
  3688. }
  3689. public function getJobHuntingData(array $data): array
  3690. {
  3691. $jobEnum = JobEnum::get();
  3692. $jobIndustry = JobIndustry::get();
  3693. $jobNature = JobNature::get();
  3694. $jobPosition = JobPosition::get();
  3695. $data = [
  3696. 'jobEnum' => $jobEnum,
  3697. 'jobIndustry' => $jobIndustry,
  3698. 'jobNature' => $jobNature,
  3699. 'jobPosition' => $jobPosition,
  3700. ];
  3701. return Result::success($data);
  3702. }
  3703. public function delJobHuntingInfo(array $data): array
  3704. {
  3705. $result = JobHunting::where('id', $data['id'])->delete();
  3706. return Result::success();
  3707. }
  3708. //20250324 通知,公告,消息
  3709. public function delNotice(array $data): array
  3710. {
  3711. $result = Notice::where('id', $data['id'])->delete();
  3712. if ($result) {
  3713. return Result::success();
  3714. } else {
  3715. return Result::error("删除失败", 0);
  3716. }
  3717. }
  3718. public function getNoticeInfo(array $data): array
  3719. {
  3720. $result = Notice::where('id', $data['id'])->first();
  3721. if (empty($result)) {
  3722. return Result::error("查询失败", 0);
  3723. }
  3724. return Result::success($result);
  3725. }
  3726. public function addNotice(array $data): array
  3727. {
  3728. date_default_timezone_set('Asia/Shanghai');
  3729. $data['created_at'] = date('Y-m-d H:i:s');
  3730. $data['updated_at'] = date('Y-m-d H:i:s');
  3731. $user_id = UserInfo::
  3732. //city_id不是null
  3733. whereNotNull('city_id')
  3734. ->whereNotNull('department_id')
  3735. ->where(function ($query) use ($data) {
  3736. $query->where(function ($subQuery) use ($data) {
  3737. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3738. });
  3739. })
  3740. ->where(function ($query) use ($data) {
  3741. $query->where(function ($subQuery) use ($data) {
  3742. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3743. });
  3744. })
  3745. ->pluck('user_id')->toArray();
  3746. $user_id = array_unique($user_id);
  3747. $chat_ids = $user_id;
  3748. $user_id = json_encode($user_id);
  3749. $data['re_user_ids'] = $user_id;
  3750. $result = Notice::insertGetId($data);
  3751. if ($result && $data['is_group'] == 1) {
  3752. //chat_group
  3753. $group_id = PublicData::uuid();
  3754. $groupData = [
  3755. 'id' => $group_id,
  3756. 'creator_id' => $data['user_id'],
  3757. 'group_name' => $data['group_name'] ?? '',
  3758. 'profile' => $data['profile'] ?? 0,
  3759. ];
  3760. var_dump($groupData, '-----------------groupData-------');
  3761. $groupResult = ChatGroups::insertGetId($groupData);
  3762. var_dump($groupResult, '-----------------groupid-------');
  3763. $groupMemberData = [
  3764. 'id' => PublicData::uuid(),
  3765. 'user_id' => $data['user_id'],
  3766. 'group_id' => $group_id,
  3767. 'leader' => 2,
  3768. ];
  3769. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3770. //$chat_ids 去除掉$data['user_id']
  3771. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3772. //插入群成员表
  3773. $groupMemberDataUser = [];
  3774. $chatData = [];
  3775. foreach ($chat_ids as $key => $value) {
  3776. $groupMemberDataUser[] = [
  3777. 'id' => PublicData::uuid(),
  3778. 'user_id' => $value,
  3779. 'group_id' => $group_id,
  3780. 'leader' => 1,
  3781. ];
  3782. $chatData[] = [
  3783. 'user_id' => $value,
  3784. 'msg_type' => 1,
  3785. 'receiver_id' => $group_id,
  3786. 'content' => '通过通知创建群聊',
  3787. 'group_receiver_id' => $data['user_id'],
  3788. 'action' => 'recieved',
  3789. 'created_at' => date('Y-m-d H:i:s'),
  3790. ];
  3791. }
  3792. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3793. ChatGroupsMember::insert($groupMemberDataUser);
  3794. //插入一条管理员聊天记录
  3795. $chatData[] = [
  3796. 'user_id' => $data['user_id'],
  3797. 'msg_type' => 1,
  3798. 'receiver_id' => $group_id,
  3799. 'content' => '通过通知创建群聊',
  3800. 'group_receiver_id' => $data['user_id'],
  3801. 'action' => 'said',
  3802. 'created_at' => date('Y-m-d H:i:s'),
  3803. ];
  3804. var_dump($chatData, '-----------------chatData-------');
  3805. $chatResult = ChatRecords::insert($chatData);
  3806. //更新result的 group_id
  3807. $data['group_id'] = $group_id;
  3808. Notice::where(['id' => $result])->update($data);
  3809. }
  3810. if (empty($result)) {
  3811. return Result::error("添加失败", 0);
  3812. }
  3813. return Result::success($result);
  3814. }
  3815. public function updateNotice(array $data): array
  3816. {
  3817. date_default_timezone_set('Asia/Shanghai');
  3818. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3819. $user_id = UserInfo::
  3820. //city_id不是null
  3821. whereNotNull('city_id')
  3822. ->whereNotNull('department_id')
  3823. ->where(function ($query) use ($data) {
  3824. $query->where(function ($subQuery) use ($data) {
  3825. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3826. });
  3827. })
  3828. ->where(function ($query) use ($data) {
  3829. $query->where(function ($subQuery) use ($data) {
  3830. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3831. });
  3832. })
  3833. ->pluck('user_id')->toArray();
  3834. $user_id = array_unique($user_id);
  3835. $user_id = json_encode($user_id);
  3836. $data['re_user_ids'] = $user_id;
  3837. $data['updated_at'] = date('Y-m-d H:i:s');
  3838. $result = Notice::where('id', $data['id'])->update($data);
  3839. return Result::success($result);
  3840. }
  3841. public function getNoticeList(array $data): array
  3842. {
  3843. $where = [];
  3844. //title
  3845. if (isset($data['title']) && !empty($data['title'])) {
  3846. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3847. }
  3848. //level
  3849. if (isset($data['level']) && !empty($data['level'])) {
  3850. $where[] = ['notice.level', '=', $data['level']];
  3851. }
  3852. //status
  3853. if (isset($data['status']) && !empty($data['status'])) {
  3854. $where[] = ['notice.status', '=', $data['status']];
  3855. }
  3856. var_dump($data, '------------11111-2----test---------');
  3857. if ($data['type_id'] == 10000) {
  3858. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3859. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3860. })
  3861. ->where($where)
  3862. ->orderBy('updated_at', 'desc')
  3863. ->limit($data['page_size'])
  3864. ->offset(($data['page'] - 1) * $data['page_size'])
  3865. ->get();
  3866. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3867. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3868. })
  3869. ->where($where)
  3870. ->orderBy('updated_at', 'desc')
  3871. ->count();
  3872. } else {
  3873. $result = Notice::where($where)
  3874. // ->where('user_id', $data['user_id'])
  3875. ->Where(function ($query) use ($data) {
  3876. $query->Where(function ($q) use ($data) {
  3877. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3878. ->orWhere('notice.user_id', $data['user_id']);
  3879. });
  3880. })
  3881. ->when(!empty($data['status1']), function ($query) use ($data) {
  3882. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3883. })
  3884. ->orderBy('updated_at', 'desc')
  3885. ->limit($data['page_size'])
  3886. ->offset(($data['page'] - 1) * $data['page_size'])
  3887. ->get();
  3888. $total = Notice::where($where)
  3889. ->when(!empty($data['status1']), function ($query) use ($data) {
  3890. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3891. })
  3892. // ->where('user_id', $data['user_id'])
  3893. ->Where(function ($query) use ($data) {
  3894. $query->Where(function ($q) use ($data) {
  3895. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3896. ->orWhere('notice.user_id', $data['user_id']);
  3897. });
  3898. })
  3899. ->count();
  3900. }
  3901. if (empty($result)) {
  3902. return Result::error("查询失败", 0);
  3903. }
  3904. $data = [
  3905. 'rows' => $result,
  3906. 'count' => $total,
  3907. ];
  3908. return Result::success($data);
  3909. }
  3910. public function getNoticeDetail(array $data): array
  3911. {
  3912. $result = Notice::where('id', $data['id'])->first();
  3913. if (empty($result)) {
  3914. return Result::error("查询失败", 0);
  3915. }
  3916. return Result::success($result);
  3917. }
  3918. public function deleteNotice(array $data): array
  3919. {
  3920. $notice = Notice::where('id', $data['id'])->first();
  3921. if (empty($notice)) {
  3922. return Result::error("删除失败", 0);
  3923. }
  3924. $chat_group_id = $notice->group_id;
  3925. if ($chat_group_id) {
  3926. //删除群聊
  3927. ChatGroups::where('id', $chat_group_id)->delete();
  3928. //删除群成员
  3929. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3930. //删除群聊记录
  3931. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3932. }
  3933. $result = Notice::where('id', $data['id'])->delete();
  3934. return Result::success($result);
  3935. }
  3936. public function getMSG(array $data): array
  3937. {
  3938. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3939. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3940. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3941. $result = [];
  3942. if ($type_id == 1) {
  3943. //最近的5篇已审的文章
  3944. $apply_articale = Article::where('status', 1)
  3945. ->where('admin_user_id', $user_id)
  3946. ->orderBy('updated_at', 'desc')
  3947. ->limit(5)->get();
  3948. //获取5条单聊未读聊天消息
  3949. $chat = ChatRecords::where('is_read', 0)
  3950. ->where('user_id', $user_id)
  3951. ->where('talk_type', 1)
  3952. ->orderBy('created_at', 'desc')
  3953. ->limit(5)->get();
  3954. //获取5条未读群聊信息
  3955. $chat_group = ChatRecords::where('is_read', 0)
  3956. ->where('user_id', $user_id)
  3957. ->where('talk_type', 2)
  3958. ->orderBy('created_at', 'desc')
  3959. ->limit(5)->get();
  3960. //获取5条用户的已审核商品
  3961. $good = Good::where('status', 2)
  3962. ->where('user_id', $user_id)
  3963. ->orderBy('updated_at', 'desc')
  3964. ->limit(5)->get();
  3965. //获取5条用户待审核的公告
  3966. $notice = Notice::where('status', 2)
  3967. ->where('user_id', $user_id)
  3968. ->orderBy('updated_at', 'desc')
  3969. ->limit(5)->get();
  3970. //获取5条用户的待审核投诉
  3971. $complaint = Complaint::where('status', 2)
  3972. ->where('user_id', $user_id)
  3973. ->orderBy('updated_at', 'desc')
  3974. ->limit(5)->get();
  3975. //获取5条用户的book
  3976. $book = Book::where('status', 2)
  3977. ->where('user_id', $user_id)
  3978. ->orderBy('updated_at', 'desc')
  3979. ->limit(5)->get();
  3980. //获取5条用户的求职
  3981. //获取5条用户的求职 1
  3982. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3983. ->where('job_hunting.user_id', $user_id)
  3984. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3985. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3986. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3987. ->orderBy('updated_at', 'desc')
  3988. ->limit(5)->get();
  3989. //获取5条用户的求职 2
  3990. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3991. ->where('job_recruiting.user_id', $user_id)
  3992. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3993. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3994. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3995. ->orderBy('updated_at', 'desc')
  3996. ->limit(5)->get();
  3997. //人才库 1
  3998. $job_apply = JobApply::where('job_apply.status', 1)
  3999. ->where('job_apply.receiver_id', $user_id)
  4000. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  4001. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  4002. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  4003. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  4004. ->select('job_recruiting', 'job_recruiting.', '', '')
  4005. ->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')
  4006. ->orderBy('updated_at', 'desc')
  4007. ->limit(5)->get();
  4008. // 职场机会 2
  4009. $job_resume = JobResume::where('job_resume.status', 1)
  4010. ->where('job_resume.receiver_id', $user_id)
  4011. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  4012. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  4013. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  4014. ->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')
  4015. ->orderBy('updated_at', 'desc')
  4016. ->limit(5)->get();
  4017. // count($chat) + count($chat_group) +
  4018. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  4019. $result = [
  4020. 'apply_articale' => $apply_articale,
  4021. 'chat' => $chat,
  4022. 'chat_group' => $chat_group,
  4023. 'good' => $good,
  4024. 'notice' => $notice,
  4025. 'complaint' => $complaint,
  4026. 'book' => $book,
  4027. 'job_hunting' => $job_hunting,
  4028. 'job_recruiting' => $job_recruiting,
  4029. 'job_apply' => $job_apply,
  4030. 'job_resume' => $job_resume,
  4031. 'count' => $count,
  4032. ];
  4033. } elseif ($type_id == 2) {
  4034. //最近的5篇已审的文章
  4035. $apply_articale = Article::where('status', 1)
  4036. ->where('admin_user_id', $user_id)
  4037. ->limit(5)->get();
  4038. //获取5条单聊未读聊天消息
  4039. $chat = ChatRecords::where('is_read', 0)
  4040. ->where('user_id', $user_id)
  4041. ->where('talk_type', 1)
  4042. ->orderBy('created_at', 'desc')
  4043. ->limit(5)->get();
  4044. //获取5条未读群聊信息
  4045. $chat_group = ChatRecords::where('is_read', 0)
  4046. ->where('user_id', $user_id)
  4047. ->where('talk_type', 2)
  4048. ->orderBy('created_at', 'desc')
  4049. ->limit(5)->get();
  4050. //获取5条用户的已审核商品
  4051. $good = Good::where('status', 2)
  4052. ->where('user_id', $user_id)
  4053. ->orderBy('updated_at', 'desc')
  4054. ->limit(5)->get();
  4055. //count($chat) + count($chat_group)
  4056. $count = count($apply_articale) + count($good);
  4057. $result = [
  4058. 'apply_articale' => $apply_articale,
  4059. 'chat' => $chat,
  4060. 'chat_group' => $chat_group,
  4061. 'good' => $good,
  4062. 'count' => $count,
  4063. ];
  4064. } elseif ($type_id == 3) {
  4065. //最近的5篇已审的文章
  4066. $apply_articale = Article::where('status', 1)
  4067. ->where('admin_user_id', $user_id)
  4068. ->limit(5)->get();
  4069. //获取5条单聊未读聊天消息
  4070. $chat = ChatRecords::where('is_read', 0)
  4071. ->where('user_id', $user_id)
  4072. ->where('talk_type', 1)
  4073. ->orderBy('created_at', 'desc')
  4074. ->limit(5)->get();
  4075. //获取5条未读群聊信息
  4076. $chat_group = ChatRecords::where('is_read', 0)
  4077. ->where('user_id', $user_id)
  4078. ->where('talk_type', 2)
  4079. ->orderBy('created_at', 'desc')
  4080. ->limit(5)->get();
  4081. //获取5条用户的已审核商品
  4082. $good = Good::where('status', 2)
  4083. ->where('user_id', $user_id)
  4084. ->orderBy('updated_at', 'desc')
  4085. ->limit(5)->get();
  4086. //count($chat) + count($chat_group) +
  4087. $count = count($apply_articale) + count($good);
  4088. $result = [
  4089. 'apply_articale' => $apply_articale,
  4090. 'chat' => $chat,
  4091. 'chat_group' => $chat_group,
  4092. 'good' => $good,
  4093. 'count' => $count,
  4094. ];
  4095. } elseif ($type_id == 4) {
  4096. //最近的5篇已审的文章
  4097. $apply_articale = Article::where('status', 1)
  4098. ->where('admin_user_id', $user_id)
  4099. ->limit(5)->get();
  4100. //获取5条用户的已审核商品
  4101. $good = Good::where('status', 2)
  4102. ->where('user_id', $user_id)
  4103. ->orderBy('updated_at', 'desc')
  4104. ->limit(5)->get();
  4105. $count = count($apply_articale) + count($good);
  4106. $result = [
  4107. 'apply_articale' => $apply_articale,
  4108. 'chat' => '',
  4109. 'chat_group' => '',
  4110. 'good' => $good,
  4111. 'count' => $count,
  4112. ];
  4113. } elseif ($type_id == 10000) {
  4114. //获取未审核的5篇文章
  4115. $apply_articale = Article::where('status', 0)
  4116. ->orderBy('updated_at', 'desc')
  4117. ->limit(5)->get();
  4118. //获取5条单聊未读聊天消息
  4119. $chat = ChatRecords::where('is_read', 0)
  4120. ->where('user_id', $user_id)
  4121. ->where('talk_type', 1)
  4122. ->orderBy('created_at', 'desc')
  4123. ->limit(5)->get();
  4124. //获取5条未读群聊信息
  4125. $chat_group = ChatRecords::where('is_read', 0)
  4126. ->where('user_id', $user_id)
  4127. ->where('talk_type', 2)
  4128. ->orderBy('created_at', 'desc')
  4129. ->limit(5)->get();
  4130. //获取5条用户的已审核商品
  4131. $good = Good::where('status', 1)
  4132. // ->where('user_id', $user_id)
  4133. ->orderBy('updated_at', 'desc')
  4134. ->limit(5)->get();
  4135. //获取5条用户待审核的公告
  4136. $notice = Notice::where('status', 1)
  4137. ->orderBy('updated_at', 'desc')
  4138. ->limit(5)->get();
  4139. //获取5条用户的待审核投诉
  4140. $complaint = Complaint::where('status', 1)
  4141. ->orderBy('updated_at', 'desc')
  4142. ->limit(5)->get();
  4143. //获取5条用户的book
  4144. $book = Book::where('status', 1)
  4145. ->orderBy('updated_at', 'desc')
  4146. ->limit(5)->get();
  4147. //获取5条用户的求职 1
  4148. $job_hunting = JobHunting::where('job_hunting.status', 1)
  4149. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4150. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  4151. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4152. ->orderBy('updated_at', 'desc')
  4153. ->limit(5)->get();
  4154. //获取5条用户的求职 2
  4155. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  4156. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4157. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4158. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4159. ->orderBy('updated_at', 'desc')
  4160. ->limit(5)->get();
  4161. //人才库 1
  4162. $job_apply = JobApply::where('job_apply.status', 1)
  4163. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  4164. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  4165. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  4166. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  4167. ->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')
  4168. ->orderBy('updated_at', 'desc')
  4169. ->limit(5)->get();
  4170. // 职场机会 2
  4171. $job_resume = JobResume::where('job_resume.status', 1)
  4172. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  4173. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  4174. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  4175. ->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')
  4176. ->orderBy('updated_at', 'desc')
  4177. ->limit(5)->get();
  4178. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  4179. $result = [
  4180. 'apply_articale' => $apply_articale,
  4181. 'chat' => $chat,
  4182. 'chat_group' => $chat_group,
  4183. 'good' => $good,
  4184. 'notice' => $notice,
  4185. 'complaint' => $complaint,
  4186. 'book' => $book,
  4187. 'job_hunting' => $job_hunting,
  4188. 'job_recruiting' => $job_recruiting,
  4189. 'job_apply' => $job_apply,
  4190. 'job_resume' => $job_resume,
  4191. 'count' => $count,
  4192. ];
  4193. } elseif ($type_id == 20000) {
  4194. }
  4195. var_dump($type_id, '-----------------test---------');
  4196. return Result::success($result);
  4197. }
  4198. public function getComplaintList(array $data): array
  4199. {
  4200. var_dump($data, '00000001000000000000');
  4201. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4202. unset($data['type_id']);
  4203. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4204. $where = [];
  4205. if ($type_id != 10000 && empty($data['deal_user'])) {
  4206. $where['complaint.user_id'] = $user_id;
  4207. }
  4208. if (!empty($data['title'])) {
  4209. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4210. }
  4211. if (!empty($data['department_id'])) {
  4212. $where['complaint.department_id'] = $data['department_id'];
  4213. }
  4214. if (!empty($data['deal'])) {
  4215. $where['complaint.deal'] = $data['deal'];
  4216. }
  4217. if (!empty($data['status'])) {
  4218. $where['complaint.status'] = $data['status'];
  4219. }
  4220. var_dump(!empty($data['deal_user']), '----------1');
  4221. var_dump($where, '----------2');
  4222. $result = Complaint::where($where)
  4223. ->when(!empty($data['status1']), function ($query) use ($data) {
  4224. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4225. })
  4226. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4227. //json re_user_ids data[user_id]是不是在里面
  4228. $query->Where(function ($q) use ($data) {
  4229. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4230. ->where('complaint.status', 2);
  4231. });
  4232. })
  4233. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4234. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4235. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4236. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4237. ->orderBy('updated_at', 'desc')
  4238. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4239. //sql输出
  4240. if (empty($result)) {
  4241. return Result::error("暂无投诉信息", 0);
  4242. }
  4243. // 取出数据
  4244. $rows = $result->items();
  4245. $count = $result->total();
  4246. $responseData = [
  4247. 'rows' => $rows,
  4248. 'count' => $count,
  4249. ];
  4250. return Result::success($responseData);
  4251. }
  4252. public function getComplaintInfo(array $data): array
  4253. {
  4254. $result = Complaint::where('id', $data['id'])->first();
  4255. if (empty($result)) {
  4256. return Result::error("查询失败", 0);
  4257. }
  4258. return Result::success($result);
  4259. }
  4260. public function addComplaint(array $data): array
  4261. {
  4262. date_default_timezone_set('Asia/Shanghai');
  4263. $data['created_at'] = date('Y-m-d H:i:s');
  4264. $data['updated_at'] = date('Y-m-d H:i:s');
  4265. $result = Complaint::create($data);
  4266. return Result::success($result);
  4267. }
  4268. public function updateComplaint(array $data): array
  4269. {
  4270. date_default_timezone_set('Asia/Shanghai');
  4271. $data['updated_at'] = date('Y-m-d H:i:s');
  4272. $user_id = $data['user_id'] ?? 0;
  4273. $type_id = $data['type_id'] ?? 0;
  4274. unset($data['user_id']);
  4275. unset($data['type_id']);
  4276. $result = Complaint::where('id', $data['id'])->update($data);
  4277. return Result::success($result);
  4278. }
  4279. public function deleteComplaint(array $data): array
  4280. {
  4281. $result = Complaint::where('id', $data['id'])->delete();
  4282. return Result::success($result);
  4283. }
  4284. public function getComplainInfo(array $data): array
  4285. {
  4286. $result = Complaint::where('id', $data['id'])->first();
  4287. if (empty($result)) {
  4288. return Result::error("查询失败", 0);
  4289. }
  4290. return Result::success($result);
  4291. }
  4292. public function updateComplaintStatus(array $data): array
  4293. {
  4294. date_default_timezone_set('Asia/Shanghai');
  4295. $data['updated_at'] = date('Y-m-d H:i:s');
  4296. $user_id = $data['user_id'] ?? 0;
  4297. $type_id = $data['type_id'] ?? 0;
  4298. unset($data['user_id']);
  4299. unset($data['type_id']);
  4300. //处理, 写入处理人
  4301. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4302. $data['real_deal_user'] = $user_id;
  4303. }
  4304. //如果是deal 23,则判断是不是处理人
  4305. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4306. $complaintInof = Complaint::where('id', $data['id'])
  4307. ->where('real_deal_user', $user_id)
  4308. ->first();
  4309. if (empty($complaintInof)) {
  4310. return Result::error("处理人错误", 0);
  4311. }
  4312. }
  4313. $result = complaint::where('id', $data['id'])->update($data);
  4314. return Result::success($result);
  4315. }
  4316. public function updateGoodStatus(array $data): array
  4317. {
  4318. $user_id = $data['user_id'] ?? 0;
  4319. $type_id = $data['type_id'] ?? 0;
  4320. unset($data['user_id']);
  4321. unset($data['type_id']);
  4322. $result = Good::where('id', $data['id'])->update($data);
  4323. return Result::success($result);
  4324. }
  4325. public function updateJobHuntingStatus(array $data): array
  4326. {
  4327. $user_id = $data['user_id'] ?? 0;
  4328. $type_id = $data['type_id'] ?? 0;
  4329. unset($data['user_id']);
  4330. unset($data['type_id']);
  4331. $result = JobHunting::where('id', $data['id'])->update($data);
  4332. return Result::success($result);
  4333. }
  4334. public function updateNoticeStatus(array $data): array
  4335. {
  4336. $user_id = $data['user_id'] ?? 0;
  4337. $type_id = $data['type_id'] ?? 0;
  4338. unset($data['user_id']);
  4339. unset($data['type_id']);
  4340. $result = Notice::where('id', $data['id'])->update($data);
  4341. return Result::success($result);
  4342. }
  4343. public function getDUser(array $data): array
  4344. {
  4345. if (!empty($data['ids'])) {
  4346. $user = User::whereIn('id', $data['ids'])->getall();
  4347. if (empty($user)) {
  4348. return Result::error('无数据', 0);
  4349. }
  4350. return Result::success($user);
  4351. }
  4352. $where = [];
  4353. if (!empty($data['department_id'])) {
  4354. $where['department_id'] = $data['department_id'];
  4355. }
  4356. if (!empty($data['city_id'])) {
  4357. $where['city_id'] = $data['city_id'];
  4358. }
  4359. $result = User::where('type_id', 2)
  4360. ->where('status', 1)
  4361. ->where($where)
  4362. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4363. ->get();
  4364. if (empty($result)) {
  4365. return Result::error("查询失败", 0);
  4366. }
  4367. return Result::success($result);
  4368. }
  4369. /**
  4370. * 验证导航名称是否重复
  4371. * @return void
  4372. */
  4373. public function checkCategoryName(array $data): array
  4374. {
  4375. $result = Category::when($data, function ($query) use ($data) {
  4376. if (isset($data['name']) && $data['name']) {
  4377. $query->where("name", $data['name']);
  4378. }
  4379. if (isset($data['id']) && $data['id']) {
  4380. $query->where("id", "!=", $data['id']);
  4381. }
  4382. })->first();
  4383. if ($result) {
  4384. return Result::error("已存在");
  4385. } else {
  4386. return Result::success();
  4387. }
  4388. }
  4389. //20250226 产品列表
  4390. // 20250306 -------招聘--------fr
  4391. /*
  4392. * 招聘列表
  4393. * */
  4394. public function getJobRecruitingList(array $data): array
  4395. {
  4396. $where = [];
  4397. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4398. if ($data['checkout'] == 0) {
  4399. $job_status = [0, 2];
  4400. } else {
  4401. $job_status = [1];
  4402. }
  4403. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4404. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4405. }
  4406. $user = User::where('id', $data['user_id'])->first();
  4407. if (empty($user)) {
  4408. return Result::error("用户不存在", 0);
  4409. }
  4410. // 3:企业会员
  4411. if ($user['type_id'] == 3) {
  4412. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4413. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4414. }
  4415. // 如果 $where 为空,则不添加 where 条件
  4416. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4417. return $query->where($where);
  4418. })
  4419. ->whereIn('job_recruiting.status', $job_status)
  4420. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4421. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4422. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4423. ->orderBy("updated_at", "desc")
  4424. ->offset(($data['page'] - 1) * $data['page_size'])
  4425. ->limit($data['page_size'])
  4426. ->get()
  4427. ->all();
  4428. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4429. return $query->where($where);
  4430. })
  4431. ->whereIn('job_recruiting.status', $job_status)
  4432. ->count();
  4433. if (empty($result)) {
  4434. return Result::error("暂无招聘信息", 0);
  4435. }
  4436. return Result::success($result);
  4437. }
  4438. /*
  4439. * 招聘信息添加
  4440. * */
  4441. public function addJobRecruiting(array $data): array
  4442. {
  4443. // return Result::success($data);
  4444. $user = User::where('user.id', $data['user_id'])
  4445. ->where('user.status', 1)
  4446. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4447. ->select(
  4448. 'user.type_id',
  4449. 'user.mobile',
  4450. 'user.email',
  4451. 'user_info.business_name',
  4452. 'user_info.company_hy_id',
  4453. 'user_info.company_nature',
  4454. 'user_info.company_size',
  4455. 'user_info.introduction',
  4456. 'user_info.real_name',
  4457. 'user_info.company_url',
  4458. 'user_info.address_arr_id',
  4459. 'user_info.address'
  4460. )
  4461. ->first();
  4462. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4463. return Result::error("用户不存在", 0);
  4464. }
  4465. $web = Website::where('id', $data['website_id'])->first();
  4466. if (empty($web)) {
  4467. return Result::error("网站不存在", 0);
  4468. }
  4469. // return Result::success($user);
  4470. $data['action_id'] = $data['user_id'];
  4471. $data['user_type'] = $user['type_id'];
  4472. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4473. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4474. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4475. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4476. // 公司地址 管理员必填
  4477. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4478. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4479. // 管理员-企业相关信息
  4480. $company = [
  4481. // 'user_id' => $data['user_id']?? null,
  4482. 'business_name' => $data['business_name'] ?? null,
  4483. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4484. 'company_size' => $data['company_size'] ?? null,
  4485. 'company_nature' => $data['company_nature'] ?? null,
  4486. 'introduction' => $data['introduction'] ?? null,
  4487. 'real_name' => $data['real_name'] ?? null,
  4488. 'mobile' => $data['mobile'] ?? null,
  4489. 'company_url' => $data['company_url'] ?? null,
  4490. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4491. 'address' => $data['address'] ?? null,
  4492. 'email' => $data['email'] ?? null,
  4493. ];
  4494. //去掉相关企业信息
  4495. $job = array_diff_key($data, array_flip(array_keys($company)));
  4496. Db::beginTransaction();
  4497. try {
  4498. // 先添加职位相关信息
  4499. if ($user['type_id'] == 10000) {
  4500. $job['status'] = 1;
  4501. }
  4502. if (empty($data['experience']) || $data['experience'] == '') {
  4503. $job['experience'] = null;
  4504. } else {
  4505. $job['experience'] = $data['experience'];
  4506. }
  4507. $jobId = JobRecruiting::insertGetId($job);
  4508. if (empty($jobId)) {
  4509. Db::rollBack();
  4510. return Result::error("添加失败");
  4511. }
  4512. // 添加公司信息
  4513. $company['user_id'] = $data['user_id'] ?? null;
  4514. $company['job_id'] = $jobId;
  4515. $company['user_type'] = $user['type_id'] ?? null;
  4516. $company['website_id'] = $data['website_id'] ?? null;
  4517. if ($user['type_id'] == 10000) {
  4518. // 管理员添加企业信息
  4519. // return Result::success($company);
  4520. $companyId = JobCompany::insertGetId($company);
  4521. if (empty($companyId)) {
  4522. Db::rollBack();
  4523. return Result::error("添加失败");
  4524. }
  4525. } else {
  4526. // 企业会员添加企业信息
  4527. $company = [
  4528. 'user_id' => $data['user_id'] ?? null,
  4529. 'business_name' => $user['business_name'] ?? null,
  4530. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4531. 'company_size' => $user['company_size'] ?? null,
  4532. 'company_nature' => $user['company_nature'] ?? null,
  4533. 'introduction' => $user['introduction'] ?? null,
  4534. 'real_name' => $user['real_name'] ?? null,
  4535. 'mobile' => $user['mobile'] ?? null,
  4536. 'company_url' => $user['company_url'] ?? null,
  4537. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4538. 'address' => $user['address'] ?? null,
  4539. 'email' => $user['email'] ?? null,
  4540. 'website_id' => $data['website_id'] ?? null,
  4541. 'user_type' => $user['type_id'] ?? null,
  4542. 'job_id' => $jobId,
  4543. ];
  4544. $companyId = JobCompany::insertGetId($company);
  4545. if (empty($companyId)) {
  4546. Db::rollBack();
  4547. return Result::error("添加失败");
  4548. }
  4549. // return Result::success($company);
  4550. }
  4551. Db::commit();
  4552. } catch (\Exception $e) {
  4553. Db::rollBack();
  4554. return Result::error($e->getMessage(), 0);
  4555. }
  4556. $result = [
  4557. 'job_id' => $jobId,
  4558. 'company_id' => $companyId,
  4559. ];
  4560. if (empty($result)) {
  4561. return Result::error("添加失败", 0);
  4562. }
  4563. return Result::success($result);
  4564. }
  4565. /*
  4566. * 获取招聘信息详情
  4567. * */
  4568. public function getJobRecruitingInfo(array $data): array
  4569. {
  4570. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4571. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4572. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4573. ->select(
  4574. 'job_recruiting.*',
  4575. 'website.website_name as website_name',
  4576. 'job_company.business_name',
  4577. 'job_company.company_hy_id',
  4578. 'job_company.company_size',
  4579. 'job_company.company_nature',
  4580. 'job_company.introduction',
  4581. 'job_company.real_name',
  4582. 'job_company.mobile',
  4583. 'job_company.company_url',
  4584. 'job_company.address_arr_id',
  4585. 'job_company.address',
  4586. 'job_company.email'
  4587. )
  4588. ->first();
  4589. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4590. if (!empty($cityId)) {
  4591. if (isset($cityId[1]) && $cityId[1] != null) {
  4592. $city = District::where('id', $cityId[1])->first(['name']);
  4593. } else {
  4594. $city = District::where('id', $cityId[0])->first(['name']);
  4595. }
  4596. $result['city'] = $city['name'] ?? '';
  4597. }
  4598. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4599. if (is_array($addressId) && !empty($addressId)) {
  4600. $address = District::whereIn('id', $addressId)
  4601. ->orderBy('level', 'asc')
  4602. ->get(['name'])
  4603. ->pluck('name')
  4604. ->implode('');
  4605. // $job->address_name = $address ?? '';
  4606. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4607. }
  4608. if (empty($result)) {
  4609. return Result::error("招聘信息不存在", 0);
  4610. }
  4611. // return Result::success($job);
  4612. return Result::success($result);
  4613. }
  4614. /*
  4615. * 修改招聘信息
  4616. * */
  4617. public function upJobRecruiting(array $data): array
  4618. {
  4619. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4620. // return Result::success($job);
  4621. if (empty($job)) {
  4622. return Result::error("招聘信息不存在", 0);
  4623. }
  4624. $user = User::where('id', $data['user_id'])->first();
  4625. // return Result::success($user);
  4626. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4627. return Result::error("用户不存在", 0);
  4628. }
  4629. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4630. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4631. }
  4632. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4633. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4634. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4635. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4636. // 公司地址 管理员必填
  4637. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4638. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4639. // 管理员-企业相关信息
  4640. $company = [
  4641. 'business_name' => $data['business_name'] ?? null,
  4642. 'company_hy_id' => $data['hy_id'] ?? null,
  4643. 'company_size' => $data['company_size'] ?? null,
  4644. 'company_nature' => $data['company_nature'] ?? null,
  4645. 'introduction' => $data['introduction'] ?? null,
  4646. 'real_name' => $data['real_name'] ?? null,
  4647. 'mobile' => $data['mobile'] ?? null,
  4648. 'company_url' => $data['company_url'] ?? null,
  4649. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4650. 'address' => $data['address'] ?? null,
  4651. 'email' => $data['email'] ?? null,
  4652. ];
  4653. //去掉相关企业信息
  4654. $data = array_diff_key($data, array_flip(array_keys($company)));
  4655. $jobId = $data['id'];
  4656. $web = $data['website_id'];
  4657. $data['action_id'] = $data['user_id'];
  4658. unset($data['user_id']);
  4659. unset($data['user_type']);
  4660. unset($data['id']);
  4661. unset($data['website_id']);
  4662. // return Result::success($data);
  4663. Db::beginTransaction();
  4664. try {
  4665. // 管理员修改招聘信息
  4666. if ($user['type_id'] == 10000) {
  4667. $data['website_id'] = $web;
  4668. $company['website_id'] = $data['website_id'];
  4669. $data['status'] = 1;
  4670. } else {
  4671. $data['status'] = 0;
  4672. }
  4673. if (empty($data['experience']) || $data['experience'] == '') {
  4674. $job['experience'] = null;
  4675. } else {
  4676. $job['experience'] = $data['experience'];
  4677. }
  4678. // Db::rollBack();
  4679. // return Result::success($company);
  4680. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4681. if (empty($result['job'])) {
  4682. Db::rollBack();
  4683. return Result::error("修改招聘信息失败");
  4684. }
  4685. // 管理员修改企业相关信息
  4686. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4687. if (empty($result['company'])) {
  4688. Db::rollBack();
  4689. return Result::error("修改企业相关信息失败");
  4690. }
  4691. Db::commit();
  4692. // return Result::success($result);
  4693. } catch (\Exception $e) {
  4694. Db::rollBack();
  4695. return Result::error($e->getMessage(), 0);
  4696. }
  4697. return Result::success($result);
  4698. }
  4699. /*
  4700. * 招聘信息删除
  4701. * */
  4702. public function delJobRecruiting(array $data): array
  4703. {
  4704. $user = User::where('id', $data['user_id'])->first();
  4705. if (empty($user)) {
  4706. return Result::error("用户不存在", 0);
  4707. }
  4708. $job = JobRecruiting::where('id', $data['id'])->first();
  4709. if (empty($job)) {
  4710. return Result::error("招聘信息不存在", 0);
  4711. }
  4712. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4713. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4714. }
  4715. Db::beginTransaction();
  4716. try {
  4717. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4718. if (empty($result['job'])) {
  4719. Db::rollBack();
  4720. return Result::error("删除招聘信息失败");
  4721. }
  4722. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4723. if (empty($result['company'])) {
  4724. Db::rollBack();
  4725. return Result::error("删除企业相关信息失败");
  4726. }
  4727. Db::commit();
  4728. } catch (\Exception $e) {
  4729. Db::rollBack();
  4730. return Result::error($e->getMessage(), 0);
  4731. }
  4732. return Result::success($result);
  4733. }
  4734. /*
  4735. * 获取公司信息
  4736. * */
  4737. public function getJobCompany(array $data): array
  4738. {
  4739. $user = User::where('user.id', $data['user_id'])
  4740. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4741. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4742. ->first();
  4743. // return Result::success($user);
  4744. if (empty($user)) {
  4745. return Result::error("用户不存在", 0);
  4746. }
  4747. if ($user['type_id'] == 3) {
  4748. $result = [
  4749. // 'id' => 0,
  4750. 'user_id' => $data['user_id'],
  4751. 'website_id' => $data['website_id'],
  4752. 'business_name' => $user['business_name'], // 企业名称
  4753. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4754. 'company_nature' => $user['company_nature'], // 公司性质
  4755. 'company_size' => $user['company_size'], // 公司规模
  4756. 'introduction' => $user['introduction'], // 公司简介
  4757. 'real_name' => $user['real_name'], // 企业联系人
  4758. 'mobile' => $user['mobile'], // 企业联系电话
  4759. 'company_url' => $user['company_url'], // 企业网址
  4760. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4761. 'address' => $user['address'], // 企业地址
  4762. 'email' => $user['email'], // 企业邮箱
  4763. ];
  4764. } else {
  4765. return Result::error("用户类型错误", 0);
  4766. }
  4767. if (empty($result)) {
  4768. return Result::error("公司信息不存在", 0);
  4769. }
  4770. return Result::success($result);
  4771. }
  4772. /*
  4773. * 修改公司信息
  4774. * */
  4775. public function upJobCompany(array $data): array
  4776. {
  4777. // return Result::success($data);
  4778. $user = User::where('user.id', $data['user_id'])
  4779. ->where('user.status', 1)
  4780. ->select('user.user_name', 'user.type_id')
  4781. ->first();
  4782. if (empty($user)) {
  4783. return Result::error("用户不存在", 0);
  4784. }
  4785. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4786. $company = [
  4787. 'business_name' => $data['business_name'], // 企业名称
  4788. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4789. 'company_nature' => $data['company_nature'], // 公司性质
  4790. 'company_size' => $data['company_size'], // 公司规模
  4791. 'introduction' => $data['introduction'], // 公司简介
  4792. // 'real_name' => $data['real_name'], // 企业联系人
  4793. 'company_url' => $data['company_url'], // 企业网址
  4794. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4795. 'address' => $data['address'], // 企业详细地址
  4796. ];
  4797. if ($user['type_id'] == 3) {
  4798. Db::beginTransaction();
  4799. try {
  4800. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4801. 'business_name' => $data['business_name'], // 企业名称
  4802. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4803. 'company_nature' => $data['company_nature'], // 公司性质
  4804. 'company_size' => $data['company_size'], // 公司规模
  4805. 'introduction' => $data['introduction'], // 公司简介
  4806. // 'real_name' => $data['real_name'], // 企业联系人
  4807. 'company_url' => $data['company_url'], // 企业网址
  4808. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4809. 'address' => $data['address'], // 企业详细地址
  4810. ]);
  4811. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4812. Db::commit();
  4813. } catch (\Exception $e) {
  4814. Db::rollBack();
  4815. return Result::error($e->getMessage(), 0);
  4816. }
  4817. } else {
  4818. return Result::error("用户类型错误", 0);
  4819. }
  4820. if (empty($result)) {
  4821. return Result::error("修改失败", 0);
  4822. }
  4823. return Result::success($result);
  4824. }
  4825. /*
  4826. * 获取省-市
  4827. * */
  4828. public function getJobRecruitingArea(array $data): array
  4829. {
  4830. if (isset($data['pid']) && $data['pid'] != null) {
  4831. $result = District::where('pid', $data['pid'])->get()->all();
  4832. } else {
  4833. $result = District::where('level', 1)->get()->all();
  4834. }
  4835. if (empty($result)) {
  4836. return Result::error("暂无此省市", 0);
  4837. }
  4838. return Result::success($result);
  4839. }
  4840. /*
  4841. * 获取行业分类
  4842. * */
  4843. public function getIndustry(array $data): array
  4844. {
  4845. $result = JobIndustry::get()->all();
  4846. if (empty($result)) {
  4847. return Result::error("暂无行业分类", 0);
  4848. }
  4849. return Result::success($result);
  4850. }
  4851. /*
  4852. * 获取职位
  4853. * */
  4854. public function getPositionList(array $data): array
  4855. {
  4856. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4857. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4858. } else {
  4859. $result = JobPosition::where('zwpid', 0)->get()->all();
  4860. }
  4861. if (empty($result)) {
  4862. return Result::error("暂无此职位", 0);
  4863. }
  4864. return Result::success($result);
  4865. }
  4866. /*
  4867. * 获取工作性质-菜单
  4868. * */
  4869. public function getJobNature(array $data): array
  4870. {
  4871. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4872. if (empty($result)) {
  4873. return Result::error("暂无工作性质", 0);
  4874. }
  4875. return Result::success($result);
  4876. }
  4877. /*
  4878. * 获取工作经验-菜单
  4879. * */
  4880. public function getExperience(array $data): array
  4881. {
  4882. $result = JobEnum::where('egroup', 'years')->get()->all();
  4883. if (empty($result)) {
  4884. return Result::error("暂无工作经验", 0);
  4885. }
  4886. return Result::success($result);
  4887. }
  4888. /*
  4889. * 获取学历-菜单
  4890. * */
  4891. public function getEducation(array $data): array
  4892. {
  4893. $result = JobEnum::where('egroup', 'education')->get()->all();
  4894. if (empty($result)) {
  4895. return Result::error("暂无学历", 0);
  4896. }
  4897. return Result::success($result);
  4898. }
  4899. /*
  4900. * 获取薪资-菜单
  4901. * */
  4902. public function getSalary(array $data): array
  4903. {
  4904. $result = JobEnum::where('egroup', 'income')->get()->all();
  4905. if (empty($result)) {
  4906. return Result::error("暂无薪资", 0);
  4907. }
  4908. return Result::success($result);
  4909. }
  4910. /*
  4911. * 获取语言-菜单
  4912. * */
  4913. public function getLanguage(array $data): array
  4914. {
  4915. $result = JobEnum::where('egroup', 'language')->get()->all();
  4916. if (empty($result)) {
  4917. return Result::error("暂无语言", 0);
  4918. }
  4919. return Result::success($result);
  4920. }
  4921. /*
  4922. * 获取掌握程度-菜单
  4923. * */
  4924. public function getLevel(array $data): array
  4925. {
  4926. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4927. if (empty($result)) {
  4928. return Result::error("暂无工作性质", 0);
  4929. }
  4930. return Result::success($result);
  4931. }
  4932. // 公司信息
  4933. /*
  4934. * 获取公司性质-菜单
  4935. * */
  4936. public function getCompanyNature(array $data): array
  4937. {
  4938. $result = JobNature::get()->all();
  4939. if (empty($result)) {
  4940. return Result::error("暂无公司性质", 0);
  4941. }
  4942. return Result::success($result);
  4943. }
  4944. /*
  4945. * 获取公司规模-菜单
  4946. * */
  4947. public function getCompanySize(array $data): array
  4948. {
  4949. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4950. if (empty($result)) {
  4951. return Result::error("暂无公司规模", 0);
  4952. }
  4953. return Result::success($result);
  4954. }
  4955. /*
  4956. * 招聘信息审核
  4957. * */
  4958. public function checkJobRecruiting(array $data): array
  4959. {
  4960. $user = User::where('id', $data['user_id'])->first();
  4961. if (empty($user)) {
  4962. return Result::error("用户不存在", 0);
  4963. }
  4964. $job = JobRecruiting::where('id', $data['id'])->first();
  4965. if (empty($job)) {
  4966. return Result::error("招聘信息不存在", 0);
  4967. }
  4968. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4969. if ($user['type_id'] != 10000) {
  4970. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4971. }
  4972. // 驳回原因
  4973. if ($data['status'] == 2) {
  4974. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4975. }
  4976. $data['action_id'] = $data['user_id'];
  4977. unset($data['user_id']);
  4978. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4979. if (empty($result)) {
  4980. return Result::error("审核失败", 0);
  4981. }
  4982. return Result::success($result);
  4983. }
  4984. public function myApplyList(array $data): array
  4985. {
  4986. var_dump($data, '------参数');
  4987. $user = User::where('id', $data['user_id'])->first();
  4988. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4989. return Result::error("用户不存在", 0);
  4990. }
  4991. // 1:个人会员 职场机会
  4992. if ($user['type_id'] == 1) {
  4993. $where['user_id'] = $user['id'];
  4994. }
  4995. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4996. $query->where('user_id', $user['id']);
  4997. })
  4998. ->pluck('recruit_id');
  4999. $where = [];
  5000. if (isset($data['salary']) && $data['salary'] != null) {
  5001. $where['job_recruiting.salary'] = $data['salary'];
  5002. }
  5003. if (isset($data['experience']) && $data['experience'] != null) {
  5004. $where['job_recruiting.experience'] = $data['experience'];
  5005. }
  5006. if (isset($data['business_name']) && $data['business_name'] != null) {
  5007. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5008. }
  5009. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5010. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5011. ->where($where);
  5012. // ->count();
  5013. $count = $query->count();
  5014. $query = clone $query;
  5015. $job = $query
  5016. ->leftJoin('job_enum as income_enum', function ($join) {
  5017. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5018. ->where('income_enum.egroup', 'income');
  5019. })
  5020. ->leftJoin('job_enum as years_enum', function ($join) {
  5021. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5022. ->where('years_enum.egroup', 'years');
  5023. })
  5024. // ->where($where)
  5025. ->orderBy('job_recruiting.updated_at', 'desc')
  5026. ->select(
  5027. 'job_recruiting.id',
  5028. 'job_recruiting.title',
  5029. 'job_company.business_name',
  5030. 'income_enum.evalue as salary_evalue',
  5031. 'income_enum.ename as salary_ename',
  5032. 'years_enum.evalue as experience_evalue',
  5033. 'years_enum.ename as experience_ename',
  5034. 'job_recruiting.updated_at'
  5035. )
  5036. ->offset(($data['page'] - 1) * $data['pageSize'])
  5037. ->limit($data['pageSize'])
  5038. ->get()
  5039. ->all();
  5040. if (empty($job)) {
  5041. return Result::error("暂无招聘信息", 0);
  5042. }
  5043. $result = [
  5044. 'row' => $job,
  5045. 'count' => $count,
  5046. ];
  5047. return Result::success($result);
  5048. }
  5049. /*
  5050. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5051. * */
  5052. public function getRecruitingList(array $data): array
  5053. {
  5054. $user = User::where('id', $data['user_id'])->first();
  5055. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5056. return Result::error("用户不存在", 0);
  5057. }
  5058. // 1:个人会员 职场机会
  5059. if ($user['type_id'] == 1) {
  5060. $where['user_id'] = $user['id'];
  5061. }
  5062. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5063. $query->where('receiver_id', $user['id']);
  5064. })
  5065. ->pluck('recruit_id');
  5066. // return Result::success($recruitingId);
  5067. $where = [];
  5068. if (isset($data['salary']) && $data['salary'] != null) {
  5069. $where['job_recruiting.salary'] = $data['salary'];
  5070. }
  5071. if (isset($data['experience']) && $data['experience'] != null) {
  5072. $where['job_recruiting.experience'] = $data['experience'];
  5073. }
  5074. if (isset($data['business_name']) && $data['business_name'] != null) {
  5075. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5076. }
  5077. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5078. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5079. ->where($where);
  5080. // ->count();
  5081. $count = $query->count();
  5082. $query = clone $query;
  5083. $job = $query
  5084. ->leftJoin('job_enum as income_enum', function ($join) {
  5085. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5086. ->where('income_enum.egroup', 'income');
  5087. })
  5088. ->leftJoin('job_enum as years_enum', function ($join) {
  5089. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5090. ->where('years_enum.egroup', 'years');
  5091. })
  5092. // ->where($where)
  5093. ->orderBy('job_recruiting.updated_at', 'desc')
  5094. ->select(
  5095. 'job_recruiting.id',
  5096. 'job_recruiting.title',
  5097. 'job_company.business_name',
  5098. 'income_enum.evalue as salary_evalue',
  5099. 'income_enum.ename as salary_ename',
  5100. 'years_enum.evalue as experience_evalue',
  5101. 'years_enum.ename as experience_ename',
  5102. 'job_recruiting.updated_at'
  5103. )
  5104. ->offset(($data['page'] - 1) * $data['pageSize'])
  5105. ->limit($data['pageSize'])
  5106. ->get()
  5107. ->all();
  5108. if (empty($job)) {
  5109. return Result::error("暂无招聘信息", 0);
  5110. }
  5111. $result = [
  5112. 'row' => $job,
  5113. 'count' => $count,
  5114. ];
  5115. return Result::success($result);
  5116. }
  5117. /*
  5118. * 获取企业会员-招聘信息列表
  5119. * */
  5120. public function getRecruitingInfo(array $data): array
  5121. {
  5122. $user = User::where('id', $data['user_id'])->first();
  5123. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5124. return Result::error("用户不存在", 0);
  5125. }
  5126. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5127. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5128. ->select(
  5129. 'job_recruiting.*',
  5130. 'job_company.business_name',
  5131. 'job_company.company_hy_id',
  5132. 'job_company.company_size',
  5133. 'job_company.company_nature',
  5134. 'job_company.introduction',
  5135. 'job_company.real_name',
  5136. 'job_company.mobile',
  5137. 'job_company.company_url',
  5138. 'job_company.address_arr_id',
  5139. 'job_company.address',
  5140. 'job_company.email'
  5141. )
  5142. ->get();
  5143. if (empty($recruiting)) {
  5144. return Result::error("暂无招聘信息", 0);
  5145. }
  5146. return Result::success($recruiting);
  5147. }
  5148. /*
  5149. * 获取企业会员-我的沟通
  5150. * */
  5151. public function getJobResumeList(array $data): array
  5152. {
  5153. $user = User::where('id', $data['user_id'])->first();
  5154. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5155. return Result::error("用户不存在", 0);
  5156. }
  5157. $where = [];
  5158. if (isset($data['salary']) && $data['salary'] != null) {
  5159. $where['job_hunting.salary'] = $data['salary'];
  5160. }
  5161. if (isset($data['user_name']) && $data['user_name'] != null) {
  5162. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5163. }
  5164. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5165. $query->where('job_resume.user_id', $user['id']);
  5166. })
  5167. ->when(!empty($where), function ($query) use ($where) {
  5168. $query->where($where);
  5169. })
  5170. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5171. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5172. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5173. ->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');
  5174. $count = $job->count();
  5175. if ($count == 0) {
  5176. return Result::error("暂无沟通记录", 0);
  5177. }
  5178. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5179. ->offset(($data['page'] - 1) * $data['pageSize'])
  5180. ->limit($data['pageSize'])
  5181. ->get();
  5182. if (empty($jobs)) {
  5183. return Result::error("暂无沟通记录", 0);
  5184. }
  5185. $result['row'] = $this->processJob($jobs, '');
  5186. $result['count'] = $count;
  5187. return Result::success($result);
  5188. }
  5189. // 20250306 招聘
  5190. //20250422 书刊音像
  5191. public function addBook(array $data): array
  5192. {
  5193. // $user_id = $data['user_id'] ?? 0;
  5194. $type_id = $data['type_id'] ?? 0;
  5195. // $website_id = $data['website_id'] ?? 0;
  5196. // unset($data['user_id']);
  5197. unset($data['type_id']);
  5198. // unset($data['website_id']);
  5199. //处理数组
  5200. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5201. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5202. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5203. if ($data['img_url'] == '') {
  5204. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5205. preg_match_all($reg, $data['detail'], $matches);
  5206. if (isset($matches[1][0])) {
  5207. //截取varchar240
  5208. $data['img_url'] = substr($matches[1][0], 0, 240);
  5209. }
  5210. }
  5211. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5212. //提取标题+内容中的关键词
  5213. $data['keyword'] = $data['title'];
  5214. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5215. Jieba::init(); // 初始化 jieba-php
  5216. Finalseg::init();
  5217. $segList = Jieba::cut($data['keyword']);
  5218. $segList1 = array_slice($segList, 0, 8);
  5219. $data['keyword'] = implode(',', $segList1);
  5220. }
  5221. if ($data['description'] == '') {
  5222. //提取内容中的描述
  5223. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5224. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5225. }
  5226. var_dump($data, '--');
  5227. $result = Book::insertGetId($data);
  5228. if (empty($result)) {
  5229. return Result::error("添加失败", 0);
  5230. }
  5231. return Result::success($result);
  5232. }
  5233. public function getBookList(array $data): array
  5234. {
  5235. $where = [];
  5236. if (!empty($data["title"])) {
  5237. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5238. }
  5239. if (!empty($data['website_name'])) {
  5240. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5241. }
  5242. if (!empty($data['status'])) {
  5243. $where[] = ['book.status', '=', $data['status']];
  5244. }
  5245. $user_id = $data['user_id'];
  5246. $type_id = $data['type_id'];
  5247. // $type_id = 4;
  5248. var_dump($type_id, '------1--------');
  5249. if ($type_id != 10000) {
  5250. $where[] = ['book.user_id', '=', $user_id];
  5251. }
  5252. var_dump(!empty($data['status1']), '=-===1');
  5253. $result = Book::where($where)
  5254. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5255. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5256. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5257. ->when(isset($data['status1']), function ($query) use ($data) {
  5258. $query->whereIn('book.status', [1, 3]);
  5259. })
  5260. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5261. ->orderBy("updated_at", "desc")
  5262. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5263. if (empty($result)) {
  5264. return Result::error("暂无数据", 0);
  5265. }
  5266. // 取出数据
  5267. $rows = $result->items();
  5268. $count = $result->total();
  5269. $responseData = [
  5270. 'rows' => $rows,
  5271. 'count' => $count,
  5272. ];
  5273. return Result::success($responseData);
  5274. }
  5275. public function deleteBook(array $data): array
  5276. {
  5277. $result = Book::where('id', $data['id'])->delete();
  5278. if (empty($result)) {
  5279. return Result::error("删除失败", 0);
  5280. }
  5281. return Result::success($result);
  5282. }
  5283. public function updateBook(array $data): array
  5284. {
  5285. // $user_id = $data['user_id'] ?? 0;
  5286. $type_id = $data['type_id'] ?? 0;
  5287. // $website_id = $data['website_id'] ?? 0;
  5288. unset($data['user_id']);
  5289. unset($data['type_id']);
  5290. // unset($data['website_id']);
  5291. //处理数组
  5292. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5293. if ($data['img_url'] == '') {
  5294. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5295. preg_match_all($reg, $data['detail'], $matches);
  5296. if (isset($matches[1][0])) {
  5297. //截取varchar240
  5298. $data['img_url'] = substr($matches[1][0], 0, 240);
  5299. }
  5300. }
  5301. if ($data['keyword'] == '') {
  5302. //提取标题+内容中的关键词
  5303. $data['keyword'] = $data['title'];
  5304. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5305. Jieba::init(); // 初始化 jieba-php
  5306. Finalseg::init();
  5307. $segList = Jieba::cut($data['keyword']);
  5308. $segList1 = array_slice($segList, 0, 8);
  5309. $data['keyword'] = implode(',', $segList1);
  5310. }
  5311. if ($data['description'] == '') {
  5312. //提取内容中的描述
  5313. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5314. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5315. }
  5316. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5317. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5318. $result = Book::where("id", $data["id"])->update($data);
  5319. if (empty($result)) {
  5320. return Result::error("更新失败", 0);
  5321. }
  5322. return Result::success($result);
  5323. }
  5324. public function getBookInfo(array $data): array
  5325. {
  5326. $result = Book::where("id", $data["id"])->first();
  5327. if (empty($result)) {
  5328. return Result::error("获取失败", 0);
  5329. }
  5330. return Result::success($result);
  5331. }
  5332. public function updateBookStatus(array $data): array
  5333. {
  5334. //审核
  5335. unset($data['user_id']);
  5336. $result = Book::where("id", $data["id"])->update($data);
  5337. if (empty($result)) {
  5338. return Result::error("更新失败", 0);
  5339. }
  5340. return Result::success($result);
  5341. }
  5342. //20250422 书刊音像
  5343. /**
  5344. * 贴身宝贝
  5345. * @param array $data
  5346. * @return array
  5347. */
  5348. public function getWebsiteTsbb(array $data): array
  5349. {
  5350. $month = $data['month'] ?? date('m');
  5351. $day = $data['day'] ?? date('d');
  5352. // 使用缓存键
  5353. $cacheKey = "tsbb_data_{$month}_{$day}";
  5354. // 尝试从缓存获取数据
  5355. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5356. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5357. if ($cachedData = $cache->get($cacheKey)) {
  5358. return Result::success(unserialize($cachedData));
  5359. }
  5360. //查询老黄历
  5361. try {
  5362. $date = date('Y-m-d');
  5363. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5364. // 使用 curl 替代 file_get_contents
  5365. $ch = curl_init();
  5366. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5367. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5368. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5369. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5370. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5371. 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');
  5372. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5373. 'Accept: application/json',
  5374. 'Content-Type: application/json',
  5375. 'Referer: https://www.36jxs.com/'
  5376. ]);
  5377. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5378. curl_setopt($ch, CURLOPT_ENCODING, '');
  5379. $almanacResponse = curl_exec($ch);
  5380. var_dump("====:", $almanacResponse);
  5381. if (curl_errno($ch)) {
  5382. var_dump('Curl error:', curl_error($ch));
  5383. throw new \Exception('Curl error: ' . curl_error($ch));
  5384. }
  5385. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5386. curl_close($ch);
  5387. if ($almanacResponse === false) {
  5388. throw new \Exception('Failed to fetch almanac data');
  5389. }
  5390. $almanacData = json_decode($almanacResponse, true);
  5391. if (json_last_error() !== JSON_ERROR_NONE) {
  5392. throw new \Exception('Failed to parse almanac data');
  5393. }
  5394. $almanacInfo = $almanacData['data'] ?? [];
  5395. } catch (\Exception $e) {
  5396. var_dump('Exception:', $e->getMessage());
  5397. $almanacInfo = [];
  5398. }
  5399. // 获取历史上的今天数据
  5400. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5401. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5402. ->orderBy('year', 'asc')
  5403. ->select("title", "id", "year", DB::raw('1 as type'))
  5404. ->limit(16)
  5405. ->get();
  5406. // 获取节日数据 - 从今天开始获取未来4条
  5407. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5408. ->orderBy('showtime', 'asc')
  5409. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5410. ->limit(16)
  5411. ->get();
  5412. //说文解字
  5413. $chartacterList = Character::orderBy('updated_at', 'desc')
  5414. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5415. ->limit(6)
  5416. ->get();
  5417. //谜语沙龙
  5418. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5419. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5420. ->limit(4)
  5421. ->get();
  5422. //成语欣赏
  5423. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5424. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5425. ->limit(32)
  5426. ->get();
  5427. //名联赏析
  5428. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5429. ->select("id", "first", "second", DB::raw('6 as type'))
  5430. ->limit(6)
  5431. ->get();
  5432. // 获取分类文章数据
  5433. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5434. ->pluck('category_id')
  5435. ->toArray();
  5436. $articlesList = [];
  5437. foreach ($categoryIds as $catid) {
  5438. // 先查有图片的
  5439. $withImg = DB::table('article')
  5440. ->where('status', 1)
  5441. ->where('catid', $catid)
  5442. ->whereNotNull('imgurl')
  5443. ->where('imgurl', '!=', '')
  5444. ->orderBy('updated_at', 'desc')
  5445. ->limit(6)
  5446. ->get();
  5447. $count = $withImg->count();
  5448. if ($count < 6) {
  5449. // 不足6条再查无图片的补足
  5450. $withoutImg = DB::table('article')
  5451. ->where('status', 1)
  5452. ->where('catid', $catid)
  5453. ->where(function($q){
  5454. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5455. })
  5456. ->orderBy('updated_at', 'desc')
  5457. ->limit(6 - $count)
  5458. ->get();
  5459. $articles = $withImg->concat($withoutImg);
  5460. } else {
  5461. $articles = $withImg;
  5462. }
  5463. // 组装
  5464. $category = \App\Model\Category::find($catid);
  5465. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5466. $articlesList[] = [
  5467. 'category_name' => $category ? $category->name : '',
  5468. 'catid' => $catid,
  5469. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5470. 'type' => 100,
  5471. 'list' => $articles->map(function ($item) {
  5472. return [
  5473. 'id' => $item->id,
  5474. 'title' => $item->title,
  5475. 'imgurl' => $item->imgurl,
  5476. 'created_at' => $item->created_at
  5477. ];
  5478. })->values()
  5479. ];
  5480. }
  5481. $result = [
  5482. 'almanac' => $almanacInfo,
  5483. 'historyTodayList' => [
  5484. 'category_name' => '历史上的今天',
  5485. 'list' => $historyTodayList,
  5486. 'type' => 1
  5487. ],
  5488. 'festivalList' => [
  5489. 'category_name' => '节日预告',
  5490. 'list' => $festivalList,
  5491. 'type' => 2
  5492. ],
  5493. 'chartacterList' => [
  5494. 'category_name' => '说文解字',
  5495. 'list' => $chartacterList,
  5496. 'type' => 3
  5497. ],
  5498. 'coupletList' => [
  5499. 'category_name' => '名联赏析',
  5500. 'list' => $coupletList,
  5501. 'type' => 6
  5502. ],
  5503. 'riddletList' => [
  5504. 'category_name' => '谜语沙龙',
  5505. 'list' => $riddletList,
  5506. 'type' => 4
  5507. ],
  5508. 'idiomList' => [
  5509. 'category_name' => '成语欣赏',
  5510. 'list' => $idiomList,
  5511. 'type' => 5
  5512. ],
  5513. 'articlesList' => $articlesList
  5514. ];
  5515. // 缓存结果,设置1小时过期
  5516. $cache->set($cacheKey, serialize($result), 3600);
  5517. return Result::success($result);
  5518. }
  5519. /**
  5520. * 获取资讯列表
  5521. */
  5522. public function getWebsiteTsbbList(array $data): array
  5523. {
  5524. $page = $data['page'] ?? 1;
  5525. $pageSize = $data['pageSize'] ?? 10;
  5526. // 如果没有传入月份和日期,则使用今天的日期
  5527. $month = $data['month'] ?? date('m');
  5528. $day = $data['day'] ?? date('d');
  5529. $total = 0;
  5530. $result = [];
  5531. $data['type'] = intval($data['type']);
  5532. var_dump("接收参数:", $data);
  5533. switch ($data['type']) {
  5534. case 1:
  5535. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5536. // 当前月份之后的数据
  5537. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5538. // 或者当前月份且日期大于等于当前日期的数据
  5539. ->orWhere(function ($q) use ($month, $day) {
  5540. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5541. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5542. });
  5543. })
  5544. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5545. $total = $query->count();
  5546. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5547. ->offset(($page - 1) * $pageSize)
  5548. ->limit($pageSize)
  5549. ->get();
  5550. break;
  5551. case 2:
  5552. $query = Festival::where(function ($q) use ($month, $day) {
  5553. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5554. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5555. ->orWhere(function ($q) use ($month, $day) {
  5556. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5557. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5558. });
  5559. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5560. $total = $query->count();
  5561. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5562. ->offset(($page - 1) * $pageSize)
  5563. ->limit($pageSize)
  5564. ->get();
  5565. break;
  5566. case 3:
  5567. $query = Character::orderBy("updated_at", "desc");
  5568. $total = $query->count();
  5569. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5570. ->offset(($page - 1) * $pageSize)
  5571. ->limit($pageSize)
  5572. ->get();
  5573. break;
  5574. case 4:
  5575. $query = Riddle::orderBy("updated_at", "desc");
  5576. $total = $query->count();
  5577. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5578. ->offset(($page - 1) * $pageSize)
  5579. ->limit($pageSize)
  5580. ->get();
  5581. break;
  5582. case 5:
  5583. $query = Idiom::orderBy("updated_at", "desc");
  5584. $total = $query->count();
  5585. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5586. ->offset(($page - 1) * $pageSize)
  5587. ->limit($pageSize)
  5588. ->get();
  5589. break;
  5590. case 6:
  5591. $query = Couplet::orderBy("updated_at", "desc");
  5592. $total = $query->count();
  5593. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5594. ->offset(($page - 1) * $pageSize)
  5595. ->limit($pageSize)
  5596. ->get();
  5597. break;
  5598. default:
  5599. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5600. $total = $query->count();
  5601. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5602. ->offset(($page - 1) * $pageSize)
  5603. ->limit($pageSize)
  5604. ->get();
  5605. }
  5606. return Result::success([
  5607. 'list' => $result,
  5608. 'total' => $total,
  5609. 'page' => (int)$page,
  5610. 'pageSize' => (int)$pageSize,
  5611. 'month' => $month,
  5612. 'day' => $day
  5613. ]);
  5614. }
  5615. /**
  5616. * 1:历史上的今天
  5617. * 2:节日
  5618. * 3:文章
  5619. *
  5620. * 资讯详情信息
  5621. */
  5622. public function getWebsiteTsbbDetail(array $data): array
  5623. {
  5624. $data['type'] = intval($data['type']);
  5625. switch ($data['type']) {
  5626. case 1:
  5627. $result = HistoryToday::where("id", $data['id'])->first();
  5628. break;
  5629. case 2:
  5630. $result = Festival::where("id", $data['id'])->first();
  5631. break;
  5632. case 3:
  5633. $result = Character::where("id", $data['id'])->first();
  5634. break;
  5635. case 4:
  5636. $result = Riddle::where("id", $data['id'])->first();
  5637. break;
  5638. case 5:
  5639. $result = Idiom::where("id", $data['id'])->first();
  5640. break;
  5641. case 6:
  5642. $result = Couplet::where("id", $data['id'])->first();
  5643. break;
  5644. default:
  5645. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5646. break;
  5647. }
  5648. return Result::success($result);
  5649. }
  5650. /**
  5651. * 农网导航首页数据
  5652. */
  5653. public function getWebsiteNwHomeList(array $data): array
  5654. {
  5655. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5656. ->pluck('category_id')
  5657. ->toArray();
  5658. // 使用子查询优化
  5659. $articlesList = DB::table('article')
  5660. ->select([
  5661. 'article.id',
  5662. 'article.title',
  5663. 'article.imgurl',
  5664. 'article.created_at',
  5665. 'category.name as category_name',
  5666. 'category.id as category_id',
  5667. 'website_category.aLIas_pinyin as pinyin',
  5668. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5669. DB::raw('100 as type')
  5670. ])
  5671. ->join('category', 'article.catid', '=', 'category.id')
  5672. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5673. ->leftJoin('website_category as parent_wc', function ($join) {
  5674. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5675. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5676. })
  5677. ->where('website_category.website_id', $data['website_id'])
  5678. ->where('article.status', 1)
  5679. ->whereIn('category.id', $categoryIds)
  5680. ->orderBy('article.created_at', 'desc')
  5681. ->get()
  5682. ->groupBy('category_id')
  5683. ->map(function ($group) {
  5684. // 确保第一条数据有图片
  5685. $firstWithImage = $group->first(function ($item) {
  5686. return !empty($item->imgurl);
  5687. });
  5688. if ($firstWithImage) {
  5689. // 如果有带图片的文章,将其放在第一位
  5690. $group = $group->filter(function ($item) use ($firstWithImage) {
  5691. return $item->id !== $firstWithImage->id;
  5692. })->prepend($firstWithImage);
  5693. }
  5694. return [
  5695. 'category_name' => $group->first()->category_name,
  5696. 'catid' => $group->first()->category_id,
  5697. 'pinyin' => $group->first()->pinyin,
  5698. 'parent_pinyin' => $group->first()->parent_pinyin,
  5699. 'list' => $group->take(4)->map(function ($item) {
  5700. return [
  5701. 'id' => $item->id,
  5702. 'title' => $item->title,
  5703. ];
  5704. })->values()
  5705. ];
  5706. })
  5707. ->values()
  5708. ->toArray();
  5709. return Result::success($articlesList);
  5710. }
  5711. /**
  5712. * 企业管理
  5713. * @param array $data
  5714. * @return array
  5715. */
  5716. public function getCompanyList(array $data): array
  5717. {
  5718. // return Result::success($data);
  5719. $where = [];
  5720. $user = User::where('id', $data['user_id'])->first();
  5721. if(empty($user)){
  5722. return Result::error('用户不存在!');
  5723. }
  5724. if($user['type_id']!= 10000){
  5725. $where['user_id'] = $data['user_id'];
  5726. }
  5727. if(isset($data['title']) && !empty($data['title'])){
  5728. array_push($where, ['company.title', 'like', '%'. $data['title']. '%']);
  5729. }
  5730. if(isset($data['website_name']) && !empty($data['website_name'])){
  5731. array_push($where, ['website.website_name', 'like', '%'. $data['website_name']. '%']);
  5732. }
  5733. if(isset($data['ischeck']) && !empty($data['ischeck'])){
  5734. if($data['ischeck'] == 1){
  5735. if(isset($data['status']) && $data['status'] != ''){
  5736. array_push($where, ['company.status', $data['status']]);
  5737. $query = Company::where($where);
  5738. }else{
  5739. $query = Company::whereIn('company.status', [0,2]);
  5740. }
  5741. }else{
  5742. $query = Company::where('company.status', 1);
  5743. }
  5744. }
  5745. $result = $query->where($where)
  5746. ->leftJoin('website_category', function ($query) {
  5747. $query->on('website_category.category_id', '=', 'company.category_id')
  5748. ->on('website_category.website_id', '=', 'company.website_id');
  5749. })
  5750. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  5751. ->select(
  5752. 'company.id',
  5753. 'company.title',
  5754. 'company.website_id',
  5755. 'company.category_id',
  5756. 'website.website_name',
  5757. 'website_category.alias as category_name',
  5758. 'company.status',
  5759. 'company.updated_at',
  5760. )
  5761. ->orderBy('company.updated_at', 'desc')
  5762. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  5763. if($result->isEmpty()){
  5764. return Result::error("暂无企业", 0);
  5765. }
  5766. return Result::success($result);
  5767. }
  5768. /**
  5769. * 添加企业
  5770. * @param array $data
  5771. * @return array
  5772. */
  5773. public function addCompany(array $data): array
  5774. {
  5775. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  5776. if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5777. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5778. $data['cat_arr_id'] = json_encode($car_arr_id);
  5779. }else{
  5780. $data['cat_arr_id'] = '';
  5781. }
  5782. if ($data['imgurl'] == '') {
  5783. //content中提取图片第一个图,正则提取
  5784. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5785. preg_match_all($reg, $data['content'], $matches);
  5786. if (isset($matches[1][0])) {
  5787. //截取varchar240
  5788. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5789. }
  5790. }
  5791. if ($data['keyword'] == '') {
  5792. //提取标题+内容中的关键词
  5793. $data['keyword'] = $data['title'];
  5794. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5795. Jieba::init(); // 初始化 jieba-php
  5796. Finalseg::init();
  5797. $segList = Jieba::cut($data['keyword']);
  5798. $segList1 = array_slice($segList, 0, 8);
  5799. $data['keyword'] = implode(',', $segList1);
  5800. }
  5801. if ($data['introduce'] == '' || empty($data['introduce'])) {
  5802. //提取内容中的描述
  5803. $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100) ?? '';
  5804. }
  5805. $user = User::where('id', $data['user_id'])->first();
  5806. if(empty($user)){
  5807. return Result::error('用户不存在!');
  5808. }
  5809. if($user['type_id']== 10000){
  5810. $data['status'] = 1;
  5811. }
  5812. if(isset($data['level']) && $data['level'] != null){
  5813. $data['level'] = intval($data['level']);
  5814. }else{
  5815. $data['level'] = null;
  5816. }
  5817. $result = Company::insertGetId($data);
  5818. if ($result) {
  5819. return Result::success($result);
  5820. } else {
  5821. return Result::error('添加失败');
  5822. }
  5823. }
  5824. /**
  5825. * 更新企业
  5826. * @param array $data
  5827. * @return array
  5828. */
  5829. public function upCompany(array $data): array
  5830. {
  5831. if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5832. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5833. $data['cat_arr_id'] = json_encode($car_arr_id);
  5834. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  5835. }else{
  5836. $data['cat_arr_id'] = '';
  5837. }
  5838. if ($data['imgurl'] == '') {
  5839. //content中提取图片第一个图,正则提取
  5840. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5841. preg_match_all($reg, $data['content'], $matches);
  5842. if (isset($matches[1][0])) {
  5843. //截取varchar
  5844. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5845. }
  5846. }
  5847. if ($data['keyword'] == '') {
  5848. //提取标题+内容中的关键词
  5849. $data['keyword'] = $data['title'];
  5850. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5851. Jieba::init(); // 初始化 jieba-php
  5852. Finalseg::init();
  5853. $segList = Jieba::cut($data['keyword']);
  5854. $segList1 = array_slice($segList, 0, 8);
  5855. $data['keyword'] = implode(',', $segList1);
  5856. }
  5857. if ($data['introduce'] == '') {
  5858. //提取内容中的描述
  5859. // var_dump(11111);
  5860. $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  5861. }
  5862. if(isset($data['level']) && $data['level'] != null){
  5863. $data['level'] = intval($data['level']);
  5864. }else{
  5865. $data['level'] = null;
  5866. }
  5867. $user = User::where('id', $data['user_id'])->first();
  5868. if(empty($user)){
  5869. return Result::error('用户不存在!');
  5870. }
  5871. if($user['type_id']== 10000){
  5872. $data['status'] = 1;
  5873. }else{
  5874. $data['status'] = 0;
  5875. }
  5876. $result = Company::where('id', $data['id'])->update($data);
  5877. if ($result) {
  5878. return Result::success($result);
  5879. } else {
  5880. return Result::error('修改失败');
  5881. }
  5882. }
  5883. /**
  5884. * 删除企业
  5885. * @param array $data
  5886. * @return array
  5887. */
  5888. public function delCompany(array $data): array
  5889. {
  5890. $result = Company::where('id', $data['id'])->delete();
  5891. if ($result) {
  5892. return Result::success($result);
  5893. } else {
  5894. return Result::error('删除失败');
  5895. }
  5896. }
  5897. /**
  5898. * 审核企业
  5899. * @param array $data
  5900. * @return array
  5901. */
  5902. public function checkCompany(array $data): array
  5903. {
  5904. $user = User::where('id', $data['user_id'])->first();
  5905. if(empty($user)){
  5906. return Result::error('用户不存在!');
  5907. }
  5908. $company = Company::where('id', $data['id'])->first();
  5909. if(empty($company)){
  5910. return Result::error('企业不存在!');
  5911. }
  5912. // 状态:0:未审核 1:已审核 2:已拒绝
  5913. if($data['status'] == 2 || $data['status'] == '2'){
  5914. $result = Company::where('id', $data['id'])->update(['status' => $data['status'],'reject_reason'=> $data['reason']]);
  5915. }else{
  5916. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  5917. }
  5918. if(empty($result)){
  5919. return Result::error('审核失败!');
  5920. }else{
  5921. return Result::success($result);
  5922. }
  5923. }
  5924. /**
  5925. * 获取企业信息
  5926. * @param array $data
  5927. * @return array
  5928. */
  5929. public function getCompanyInfo(array $data): array
  5930. {
  5931. $result = Company::where('id', $data['id'])->first();
  5932. if(empty($result)){
  5933. return Result::error('企业不存在!');
  5934. }else{
  5935. return Result::success($result);
  5936. }
  5937. }
  5938. /**
  5939. * @param array $data
  5940. * @return array
  5941. */
  5942. public function getWebsiteCompany(array $data): array
  5943. {
  5944. $where['website_id'] = $data['website_id'];
  5945. $where['status'] = 1;
  5946. if(isset($data['category_id']) && !empty($data['category_id'])){
  5947. $where['category_id'] = $data['category_id'];
  5948. }
  5949. if(isset($data['level']) && !empty($data['level'])){
  5950. $where['level'] = $data['level'];
  5951. }
  5952. // return Result::success($where);
  5953. $query = Company::where($where);
  5954. $result['img'] = $this->processArticle(
  5955. $query->clone()
  5956. ->where('imgurl','!=', '')
  5957. ->whereNotNull('imgurl')
  5958. ->select('id','imgurl','title','introduce','description','content','category_id','cat_arr_id')
  5959. ->orderBy('updated_at', 'desc')
  5960. ->limit($data['imgnum'])
  5961. ->get(),
  5962. $data
  5963. );
  5964. $result['text'] = $this->processArticle(
  5965. $query->clone()
  5966. ->select('id','title','introduce','description','content','category_id','cat_arr_id')
  5967. ->orderBy('updated_at', 'desc')
  5968. ->limit($data['textnum'])
  5969. ->get(),
  5970. $data
  5971. );
  5972. if(empty($result)){
  5973. return Result::error("暂无相关公司信息", 0);
  5974. }
  5975. return Result::success($result);
  5976. }
  5977. /**
  5978. * @param array $data
  5979. * @return array
  5980. */
  5981. public function getWebsiteCompanyList(array $data): array
  5982. {
  5983. $where['website_id'] = $data['website_id'];
  5984. $where['status'] = 1;
  5985. if(isset($data['category_id']) && !empty($data['category_id'])){
  5986. $where['category_id'] = $data['category_id'];
  5987. }
  5988. if(isset($data['keyword']) && !empty($data['keyword'])){
  5989. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  5990. }
  5991. $query = Company::where($where);
  5992. $company = $this->processArticle(
  5993. $query->select('id','title','introduce','description','content','category_id','cat_arr_id')
  5994. ->orderBy('updated_at', 'desc')
  5995. ->offset(($data['page'] - 1) * $data['pageSize'])
  5996. ->limit($data['pageSize'])
  5997. ->get(),
  5998. $data
  5999. );
  6000. if(empty($company)){
  6001. return Result::error("暂无相关公司信息", 0);
  6002. }
  6003. $result = [
  6004. 'count' => $query->clone()->count(),
  6005. 'data' => $company,
  6006. ];
  6007. return Result::success($result);
  6008. }
  6009. /**
  6010. * @param array $data
  6011. * @return array
  6012. */
  6013. public function getWebsiteCompanyInfo(array $data): array
  6014. {
  6015. $company = Company::where('id', $data['id'])
  6016. ->where('status', 1)
  6017. ->where('website_id', $data['website_id'])
  6018. ->select('company.*')
  6019. ->first();
  6020. if(empty($company)){
  6021. return Result::error("暂无相关公司信息", 0);
  6022. }
  6023. return Result::success($company);
  6024. }
  6025. }