NewsService.php 221 KB

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