NewsService.php 207 KB

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