NewsService.php 214 KB

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