NewsService.php 207 KB

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