NewsService.php 208 KB

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