NewsService.php 235 KB

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