NewsService.php 211 KB

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