NewsService.php 213 KB

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