NewsService.php 230 KB

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