NewsService.php 220 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139
  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. * 获取商城首页-根据栏目id
  1720. * @param array $data
  1721. * @return array
  1722. * */
  1723. function getWebsiteCatidshop(array $data): array
  1724. {
  1725. $input['catid'] = $data['catid'];
  1726. $input['website_id'] = $data['website_id'];
  1727. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1728. $result = array_map(function ($item) use ($input) {
  1729. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid']!= "") {
  1730. list($catid, $goodStart,$goodNum) = explode(',', $item['catid']);
  1731. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1732. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1733. if(empty($category) || $category->type != 2){
  1734. return Result::error("暂无此栏目",0);
  1735. }else{
  1736. $website['website_id'] = $input['website_id'];
  1737. $goods = Good::where('good.status', 2)
  1738. ->where('good.website_id', $website['website_id'])
  1739. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($catid). "') = 1")
  1740. ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at',
  1741. 'good.catid','good.type_id','good.price','good.com','good.level','good.unit')
  1742. ->orderBy('updated_at','desc')
  1743. ->offset($goodStart)
  1744. ->limit($goodNum);
  1745. $all_goods = $goods->get();
  1746. $all_goods = $this->processGoods($all_goods, $website);
  1747. }
  1748. return $all_goods ?? [];
  1749. }
  1750. }, $data);
  1751. return Result::success($result);
  1752. }
  1753. /**
  1754. * 获取商品模块
  1755. * @param array $data
  1756. * @return array
  1757. * */
  1758. public function getWebsiteshop(array $data): array
  1759. {
  1760. $input['id'] = $data['id'];
  1761. $input['website_id'] = $data['website_id'];
  1762. $catid = $data['catid'];
  1763. $data = json_decode($input['id'] ?? '', true) ?? [];
  1764. $result['goods'] = array_map(function ($item) use ($input) {
  1765. // 检查parent元素是否存在且不是undefined
  1766. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1767. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1768. $website = $input['website_id'];
  1769. $query = Good::where('good.status', 2)
  1770. ->where('good.website_id', $website);
  1771. switch ($Levelid) {
  1772. case 1:
  1773. case 2:
  1774. case 3:
  1775. $goods = $query->where(function ($q) use ($Levelid) {
  1776. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1777. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1778. });
  1779. break;
  1780. case 4:
  1781. $goods = $query;
  1782. break;
  1783. case 5:
  1784. $goods = $query->where('type_id', 1);
  1785. break;
  1786. case 6:
  1787. $goods = $query->where('type_id', 2);
  1788. break;
  1789. default:
  1790. return [];
  1791. }
  1792. $all_goods = $goods
  1793. ->select(
  1794. 'good.id',
  1795. 'good.name',
  1796. 'good.imgurl',
  1797. 'good.description',
  1798. 'good.updated_at',
  1799. 'good.catid',
  1800. 'good.type_id',
  1801. 'good.price',
  1802. 'good.level',
  1803. 'good.website_id'
  1804. )
  1805. ->orderBy('updated_at', 'desc')
  1806. ->offset($goodStart)
  1807. ->limit($goodNum)
  1808. ->get();
  1809. $web['website_id'] = $website;
  1810. $all_goods = $this->processGoods($all_goods, $web);
  1811. }
  1812. return $all_goods;
  1813. }, $data);
  1814. $website = $input['website_id'];
  1815. $result['article'] = Article::where(function ($query) use ($website) {
  1816. $query->where(function ($subQuery) use ($website) {
  1817. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1818. })->orWhereNull("ignore_ids");
  1819. })
  1820. ->where('catid', $catid)
  1821. ->where('article.status', 1)
  1822. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1823. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1824. ->orderBy('article.updated_at', 'desc')
  1825. ->first();
  1826. return Result::success($result);
  1827. }
  1828. /**
  1829. * 获取商品分类
  1830. * @param array $data
  1831. * @return array
  1832. * */
  1833. public function getWebsiteshopCat(array $data): array
  1834. {
  1835. $website = $data['website_id'];
  1836. $category = WebsiteCategory::where('website_id', $website)
  1837. ->whereRaw("JSON_CONTAINS(category_arr_id, '". intval($data['id']). "') = 1")
  1838. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"". intval($data['id']). "\"') = 1")
  1839. ->select('category_id', 'alias','aLIas_pinyin','pid','category_arr_id')
  1840. ->orderBy('sort')
  1841. ->get();
  1842. $cat = $category->map(function ($item) use ($website) {
  1843. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1844. $pid = $item->pid?? 0;
  1845. if(!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0){
  1846. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1847. ->where('website_id', $website)
  1848. ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr_id). ')')
  1849. ->get(['aLIas_pinyin'])
  1850. ->pluck('aLIas_pinyin')
  1851. ->implode('/');
  1852. }else{
  1853. $pinyin = $item->aLIas_pinyin ?? '';
  1854. }
  1855. $item->pinyin = $pinyin;
  1856. });
  1857. if(empty($category)){
  1858. return Result::error("栏目查询失败", 0);
  1859. }
  1860. $cat_tree = Result::buildMenuTree($category);
  1861. $web['website_id'] = $website;
  1862. $goods = Good::where('website_id', $website)
  1863. ->where('status', 2)
  1864. ->select('good.id as good_id', 'name','imgurl','description','updated_at','catid','type_id','website_id')
  1865. ->latest('updated_at')
  1866. ->offset(($data['page']-1)*$data['pageSize'])
  1867. ->limit($data['pageSize'])
  1868. ->get();
  1869. if(!empty($goods)){
  1870. if($goods->count() > 1 && !empty($goods)){
  1871. $goods = $this->processGoods($goods, $web);
  1872. }
  1873. }else{
  1874. $goods = [];
  1875. }
  1876. $result = [
  1877. 'category' => $cat_tree,
  1878. 'goods' => $goods,
  1879. ];
  1880. // $resul['goods'] = $goods;
  1881. if (empty($result)) {
  1882. return Result::error("查询失败", 0);
  1883. }
  1884. return Result::success($result);
  1885. }
  1886. /*
  1887. * 获取商品列表
  1888. * @param array $data
  1889. * @return array
  1890. * */
  1891. public function getWebsiteshopList(array $data): array
  1892. {
  1893. // return Result::success($data);
  1894. $where = [
  1895. 'status' => 2,
  1896. 'website_id' => $data['website_id'],
  1897. ];
  1898. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1899. return Result::error("查询失败", 0);
  1900. }
  1901. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1902. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1903. $data['catid'] = $category->category_id ?? 0;
  1904. }
  1905. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1906. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  1907. }
  1908. if (isset($data['type_id']) && !empty($data['type_id'])) {
  1909. array_push($where, ['type_id', $data['type_id']]);
  1910. }
  1911. $query = Good::where($where)
  1912. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  1913. $query->where(function ($q) use ($data) {
  1914. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  1915. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  1916. });
  1917. })
  1918. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1919. $query->where(function ($q) use ($data) {
  1920. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  1921. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  1922. });
  1923. })
  1924. ->select(
  1925. 'good.id',
  1926. 'good.name',
  1927. 'good.imgurl',
  1928. 'good.description',
  1929. 'good.updated_at',
  1930. 'good.com',
  1931. 'good.catid',
  1932. 'good.type_id',
  1933. 'good.website_id',
  1934. 'good.cat_arr_id',
  1935. 'good.created_at',
  1936. 'good.city_id'
  1937. )
  1938. ->latest('updated_at');
  1939. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1940. // 获取 type_id 为 1 的数据
  1941. $result['type1'] = $this->processGoods(
  1942. $query->clone()
  1943. ->where('type_id', 1)
  1944. ->offset(($data['page'] - 1) * $data['pageSize'])
  1945. ->limit($data['pageSize'])
  1946. ->get(),
  1947. $data
  1948. );
  1949. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1950. // 获取 type_id 为 2 的数据
  1951. $result['type2'] = $this->processGoods(
  1952. $query->clone()
  1953. ->where('type_id', 2)
  1954. ->offset(($data['page'] - 1) * $data['pageSize'])
  1955. ->limit($data['pageSize'])
  1956. ->get(),
  1957. $data
  1958. );
  1959. if (empty($result)) {
  1960. return Result::error("查询失败", 0);
  1961. }
  1962. return Result::success($result);
  1963. }
  1964. /**
  1965. * 获取商品详情
  1966. * @param array $data
  1967. * @return array
  1968. * */
  1969. public function getWebsiteshopInfo(array $data): array
  1970. {
  1971. $where = [
  1972. 'good.status' => 2,
  1973. 'good.website_id' => $data['website_id'],
  1974. 'good.id' => $data['id'],
  1975. ];
  1976. $goods = Good::where($where)
  1977. ->where('good.id', $data['id'])
  1978. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  1979. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  1980. ->first();
  1981. if (empty($goods)) {
  1982. return Result::error("查询失败", 0);
  1983. }
  1984. $goods->imgurl = json_decode($goods->imgurl, true);
  1985. return Result::success($goods);
  1986. }
  1987. /**
  1988. * 封装处理文章的路由问题
  1989. * */
  1990. function processArticles($articles, $data) {
  1991. // 检查 $articles 是否为数组或可迭代对象
  1992. if (is_array($articles) || is_iterable($articles) &&!empty($articles)) {
  1993. return $articles->map(function ($article) use ($data) {
  1994. $catid = $article->cat_arr_id?? '';
  1995. $level = json_decode($catid, true);
  1996. if (!is_array($level)) {
  1997. return $article;
  1998. } else {
  1999. $level = array_map('intval', $level);
  2000. }
  2001. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2002. ->where($data)
  2003. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  2004. ->pluck('aLIas_pinyin')
  2005. ->implode('/');
  2006. $article->pinyin = $pinyin ?? '';
  2007. return $article;
  2008. });
  2009. } else {
  2010. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2011. $catid = $articles->cat_arr_id?? '';
  2012. $level = json_decode($catid, true);
  2013. if (!is_array($level)) {
  2014. return $articles;
  2015. } else {
  2016. $level = array_map('intval', $level);
  2017. }
  2018. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2019. ->where($data)
  2020. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  2021. ->pluck('aLIas_pinyin')
  2022. ->implode('/');
  2023. $articles->pinyin = $pinyin ?? '';
  2024. return $articles;
  2025. }
  2026. }
  2027. // 封装处理由问题
  2028. function processJob($job, $data)
  2029. {
  2030. return $job->map(function ($job) use ($data) {
  2031. $category = $job->cat_arr_id ?? '';
  2032. $cityid = $job->city_arr_id ?? '';
  2033. $city = json_decode($cityid, true);
  2034. $pinyin = '';
  2035. $level = json_decode($category, true);
  2036. // 路由
  2037. if (!empty($level) && is_array($level)) {
  2038. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2039. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2040. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2041. ->get(['aLIas_pinyin'])
  2042. ->pluck('aLIas_pinyin')
  2043. ->implode('/');
  2044. if (empty($pinyin)) {
  2045. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2046. }
  2047. $job->pinyin = $pinyin;
  2048. }
  2049. // 取职位-城市 市??省
  2050. if (!empty($city) && is_array($city)) {
  2051. if (isset($city[1]) && !empty($city[1])) {
  2052. $city = District::where('id', $city[1])->first(['name']);
  2053. $job->city_name = $city->name ?? '';
  2054. } else if (isset($city[0]) && !empty($city[0])) {
  2055. $city = District::where('id', $city[0])->first(['name']);
  2056. $job->city_name = $city->name ?? '';
  2057. } else {
  2058. $job->city_name = '全国';
  2059. }
  2060. }
  2061. // 获取简历最后一级地区
  2062. if (isset($job->city_id) && !empty($job->city_id)) {
  2063. $city = District::where('id', $job->city_id)->first(['name']);
  2064. $job->hunt_cityname = $city->name ?? '';
  2065. }
  2066. // 组合详细地址
  2067. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2068. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2069. if (is_array($address_id) && !empty($address_id)) {
  2070. $address = District::whereIn('id', $address_id)
  2071. ->orderBy('level', 'asc')
  2072. ->get(['name'])
  2073. ->pluck('name')
  2074. ->implode('');
  2075. // $job->address_name = $address ?? '';
  2076. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2077. }
  2078. }
  2079. // 取行业
  2080. if(!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))){
  2081. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2082. if (!empty($job->industry)) {
  2083. $query->where('hyid', $job->industry);
  2084. } else if (!empty($job->hy_id)) {
  2085. $query->where('hyid', $job->hy_id);
  2086. }else if(!empty($job->company_hy_id)){
  2087. $query->where('hyid', $job->company_hy_id);
  2088. } else{
  2089. $query->where('hyid', $job->job_industry);
  2090. }
  2091. })->first(['hyname']);
  2092. $job->hy_name = $hy_name->hyname ?? '';
  2093. }
  2094. // 取职位类别
  2095. if((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))){
  2096. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2097. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2098. $job->zw_name = $zw_name->zwname ?? '';
  2099. }
  2100. // 取具体职位
  2101. if((isset($job->jtzw_id) &&!empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get)) || (isset($job->job_name) && !empty($job->job_name))){
  2102. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2103. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2104. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2105. }
  2106. // 取工作经验
  2107. if (isset($job->experience) && !empty($job->experience)) {
  2108. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2109. $job->experience_name = $experience->ename ?? '';
  2110. }
  2111. // 取学历
  2112. if(isset($job->educational) &&!empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2113. $education = $job->educational ?? $job->school_education;
  2114. $education = JobEnum::where('egroup','education')->where('evalue',$education)->first(['ename']);
  2115. $job->education_name = $education->ename?? '';
  2116. }
  2117. // 语言
  2118. if (isset($job->language) && !empty($job->language)) {
  2119. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2120. $job->language_name = $language->ename ?? '';
  2121. }
  2122. // 薪资
  2123. if (isset($job->salary) && !empty($job->salary)) {
  2124. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2125. $job->salary_name = $salary->ename ?? '';
  2126. }
  2127. // 职位性质
  2128. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2129. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2130. $job->job_nature_name = $job_nature->ename ?? '';
  2131. }
  2132. // 公司规模
  2133. if (isset($job->company_size) && !empty($job->company_size)) {
  2134. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2135. $job->company_size_name = $company_size->ename ?? '';
  2136. }
  2137. // 公司性质
  2138. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2139. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2140. $job->company_nature_name = $company_nature->nature_name ?? '';
  2141. }
  2142. // $job->pinyin = $pinyin;
  2143. return $job;
  2144. });
  2145. }
  2146. /**
  2147. * 获取书籍模块
  2148. * @param array $data
  2149. * @return array
  2150. * */
  2151. public function getWebsiteBook(array $data): array
  2152. {
  2153. $input['id'] = $data['id'];
  2154. $input['website_id'] = $data['website_id'];
  2155. // 将 JSON 字符串转换为 PHP 数组
  2156. $data = json_decode($input['id'], true);
  2157. // 使用 array_map 处理每个元素
  2158. $result = array_map(function ($item) use ($input) {
  2159. // 检查parent元素是否存在且不是undefined
  2160. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2161. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2162. $website = [
  2163. 'website_id' => $input['website_id'],
  2164. ];
  2165. // 查询栏目名称
  2166. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2167. if (empty($category)) {
  2168. $parent_alias = '';
  2169. $parent_pinyin = null;
  2170. $imgBooks = [];
  2171. $textBooks = [];
  2172. } else {
  2173. $parent_alias = $category->alias ?? '';
  2174. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2175. // 查找子分类ID数组
  2176. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2177. array_push($childCategoryIds, $parentCatId);
  2178. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2179. if ($parentImgNum != 0) {
  2180. // 查询图片新闻
  2181. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2182. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2183. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2184. })
  2185. ->where('book.status', 2)
  2186. ->where('book.img_url', '!=', '')
  2187. ->leftJoin('website_category', function ($join) use ($website) {
  2188. $join->on('book.cat_id', '=', 'website_category.category_id')
  2189. ->where('website_category.website_id', '=', $website['website_id']);
  2190. })
  2191. ->select(
  2192. 'book.id',
  2193. 'book.title',
  2194. 'book.img_url',
  2195. 'book.price',
  2196. 'book.market_price',
  2197. 'book.description',
  2198. 'book.cat_id',
  2199. 'book.description',
  2200. 'book.updated_at',
  2201. 'website_category.alias as category_name',
  2202. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2203. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2204. )
  2205. ->orderBy('updated_at', 'desc')
  2206. ->limit($parentImgNum)
  2207. ->get()->all();
  2208. // 查询文字新闻
  2209. }
  2210. if ($parentTextNum != 0) {
  2211. $textBooks = [];
  2212. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2213. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2214. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2215. })
  2216. ->where('book.status', 2)
  2217. ->leftJoin('website_category', function ($join) use ($website) {
  2218. $join->on('book.cat_id', '=', 'website_category.category_id')
  2219. ->where('website_category.website_id', '=', $website['website_id']);
  2220. })
  2221. ->select(
  2222. 'book.id',
  2223. 'book.title',
  2224. 'book.img_url',
  2225. 'book.price',
  2226. 'book.market_price',
  2227. 'book.description',
  2228. 'book.cat_id',
  2229. 'book.description',
  2230. 'book.updated_at',
  2231. 'website_category.alias as category_name',
  2232. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2233. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2234. )
  2235. ->orderBy('updated_at', 'desc')
  2236. ->limit($parentTextNum)
  2237. ->get()->all();
  2238. }
  2239. }
  2240. }
  2241. $resultItem = [
  2242. 'alias' => $parent_alias ?? '',
  2243. 'category_id' => $parentCatId ?? 0,
  2244. 'pinyin' => $parent_pinyin ?? null,
  2245. 'imgnum' => $imgBooks ?? [],
  2246. 'textnum' => $textBooks ?? [],
  2247. ];
  2248. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2249. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2250. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2251. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2252. ->get()->all();
  2253. if (!empty($childCategory)) {
  2254. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2255. // 查询子栏目名称
  2256. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2257. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2258. ->first();
  2259. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2260. $childImgArticles = [];
  2261. $childTextArticles = [];
  2262. $resultItem['child'] = [];
  2263. } else {
  2264. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2265. // 查询子栏目图片新闻
  2266. $childImgArticles = Book::where('cat_id', $childCatId)
  2267. ->where('status', 2)
  2268. ->where('img_url', '!=', '')
  2269. ->leftJoin('website_category', function ($join) use ($website) {
  2270. $join->on('book.cat_id', '=', 'website_category.category_id')
  2271. ->where('website_category.website_id', '=', $website['website_id']);
  2272. })
  2273. ->select(
  2274. 'book.id',
  2275. 'book.title',
  2276. 'book.img_url',
  2277. 'book.price',
  2278. 'book.market_price',
  2279. 'book.description',
  2280. 'book.cat_id',
  2281. 'book.description',
  2282. 'book.updated_at',
  2283. DB::raw("'$child_pinyin' as pinyin")
  2284. )
  2285. ->orderBy('updated_at', 'desc')
  2286. ->limit($childImgNum)
  2287. ->get()->all();
  2288. // 查询子栏目文字新闻
  2289. $childTextArticles = Book::where('cat_id', $childCatId)
  2290. ->where('status', 2)
  2291. ->leftJoin('website_category', function ($join) use ($website) {
  2292. $join->on('book.cat_id', '=', 'website_category.category_id')
  2293. ->where('website_category.website_id', '=', $website['website_id']);
  2294. })
  2295. ->select(
  2296. 'book.id',
  2297. 'book.title',
  2298. 'book.img_url',
  2299. 'book.price',
  2300. 'book.market_price',
  2301. 'book.description',
  2302. 'book.cat_id',
  2303. 'book.description',
  2304. 'book.updated_at',
  2305. DB::raw("'$child_pinyin' as pinyin")
  2306. )
  2307. ->orderBy('updated_at', 'desc')
  2308. ->limit($childTextNum)
  2309. ->get()->all();
  2310. $resultItem['child'] = [
  2311. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2312. 'category_id' => $childCatId,
  2313. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2314. 'all_childcat' => $childCategory,
  2315. 'imgnum' => $childImgArticles,
  2316. 'textnum' => $childTextArticles,
  2317. ];
  2318. }
  2319. }
  2320. } else {
  2321. $resultItem['child'] = [];
  2322. }
  2323. return $resultItem;
  2324. }, $data);
  2325. return Result::success($result);
  2326. }
  2327. /**
  2328. * 获取书刊列表
  2329. * @param array $data
  2330. * @return array
  2331. * */
  2332. public function getWebsiteBookList(array $data): array
  2333. {
  2334. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2335. if (empty($web)) {
  2336. return Result::error("查询失败", 0);
  2337. }
  2338. $catid = $data['id'];
  2339. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2340. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2341. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2342. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2343. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2344. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2345. ->where('pid', $category['pid'])
  2346. ->select(
  2347. 'category_id',
  2348. 'alias',
  2349. 'aLIas_pinyin',
  2350. 'pid',
  2351. 'sort',
  2352. 'is_url',
  2353. 'web_url',
  2354. 'seo_title',
  2355. 'seo_keywords',
  2356. 'seo_description',
  2357. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2358. )
  2359. ->orderBy('sort')
  2360. ->get()->all();
  2361. if (empty($category)) {
  2362. return Result::error("查询失败", 0);
  2363. }
  2364. $query = Book::where('book.status', 2)
  2365. ->where('book.website_id', $data['website_id'])
  2366. ->where('book.cat_id', $catid)
  2367. ->select(
  2368. 'book.id',
  2369. 'book.title',
  2370. 'book.img_url',
  2371. 'book.description',
  2372. 'book.updated_at',
  2373. 'book.cat_id',
  2374. DB::raw("'$pinyin' as pinyin")
  2375. )
  2376. ->orderBy('book.updated_at', 'desc');
  2377. $count = $query->count();
  2378. $query = clone $query;
  2379. $Book = $query
  2380. ->limit($data['pageSize'])
  2381. ->offset(($data['page'] - 1) * $data['pageSize'])
  2382. ->get()->all();
  2383. $result = [
  2384. 'category' => $categorys,
  2385. 'books' => $Book,
  2386. 'count' => $count,
  2387. ];
  2388. // if(empty($result)){
  2389. // return Result::error("查询失败", 0);
  2390. // }
  2391. return Result::success($result);
  2392. }
  2393. /**
  2394. * 获取书刊详情
  2395. * @param array $data
  2396. * @return array
  2397. * */
  2398. public function getWebsiteBookInfo(array $data): array
  2399. {
  2400. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2401. if (empty($web)) {
  2402. return Result::error("查询失败", 0);
  2403. }
  2404. $book = Book::where('status', 2)
  2405. ->where('website_id', $data['website_id'])
  2406. ->where('id', $data['id'])
  2407. ->select(
  2408. 'book.*',
  2409. )
  2410. ->orderBy('updated_at', 'desc')
  2411. ->first();
  2412. if (empty($book)) {
  2413. return Result::error("查询失败", 0);
  2414. }
  2415. // 先查询当前分类的 pid
  2416. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2417. ->where('category_id', $book['cat_id'])
  2418. ->first(['pid', 'category_id']);
  2419. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2420. if (!empty($carpid)) {
  2421. if ($carpid->pid != 0) {
  2422. $pid = $carpid['pid'];
  2423. // $parent_pinyin = '';
  2424. } else {
  2425. $pid = $carpid['category_id'];
  2426. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2427. }
  2428. }
  2429. $categorys = $query->where('pid', $pid)
  2430. ->select(
  2431. 'category_id',
  2432. 'alias',
  2433. 'aLIas_pinyin',
  2434. 'pid',
  2435. 'sort',
  2436. 'is_url',
  2437. 'web_url',
  2438. 'category_arr_id as cat_arr_id',
  2439. )
  2440. ->orderBy('sort')
  2441. ->get();
  2442. $category = $this->processArticle($categorys, $data);
  2443. $result = [
  2444. 'category' => $category,
  2445. 'books' => $book,
  2446. ];
  2447. return Result::success($result);
  2448. }
  2449. /**
  2450. * 尝试
  2451. * @param array $data
  2452. * @return array
  2453. * */
  2454. public function test(array $data): array
  2455. {
  2456. $input['id'] = $data['id'];
  2457. $input['website_id'] = $data['website_id'];
  2458. // 将 JSON 字符串转换为 PHP 数组
  2459. $data = json_decode($input['id'], true);
  2460. $result = [];
  2461. $article = $data;
  2462. $result = array_map(function ($item) use ($input) {
  2463. $website = [
  2464. 'website_id' => $input['website_id'],
  2465. ];
  2466. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2467. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2468. $parent = [
  2469. 0 => $category['category_id'] ?? [],
  2470. 1 => $parentImgNum ?? [],
  2471. 2 => $parentTextNum ?? [],
  2472. ];
  2473. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2474. $child = [];
  2475. $resultItem = [
  2476. // 'alias' => $parent_alias ?? '',
  2477. 'category_id' => $parentCatId ?? 0,
  2478. 'pinyin' => $parentImgNum ?? null,
  2479. 'imgnum' => $parentTextNum ?? [],
  2480. // 'textnum' => $textArticles ?? [],
  2481. ];
  2482. return $parent;
  2483. }, $data);
  2484. return Result::success($result);
  2485. // });
  2486. }
  2487. /**
  2488. * 封装处理文章的路由问题
  2489. * */
  2490. function processArticle($article, $data)
  2491. {
  2492. return $article->map(function ($article) use ($data) {
  2493. $catid = $article->cat_arr_id ?? '';
  2494. $level = json_decode($catid, true);
  2495. $pinyin = '';
  2496. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2497. if (!empty($level) && is_array($level)) {
  2498. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2499. ->where('website_id', $data['website_id'])
  2500. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2501. ->get(['aLIas_pinyin'])
  2502. ->pluck('aLIas_pinyin')
  2503. ->implode('/');
  2504. } else {
  2505. $pinyin = '';
  2506. }
  2507. $article->pinyin = $pinyin;
  2508. return $article;
  2509. });
  2510. }
  2511. /**
  2512. * c端-获取招工招聘下拉选框
  2513. * @param array $data
  2514. * @return array
  2515. * */
  2516. public function getWebsiteJobSelect(array $data): array
  2517. {
  2518. $web = Website::where('id', $data['website_id'])->first();
  2519. if (empty($web)) {
  2520. return Result::error("该网站不存在", 0);
  2521. }
  2522. $hy = JobIndustry::get()->all();
  2523. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2524. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2525. $result = [
  2526. 'hy' => $hy,
  2527. 'zw' => $zw,
  2528. 'jtzw' => $jtzw,
  2529. ];
  2530. if (empty($result)) {
  2531. return Result::error("查询失败", 0);
  2532. }
  2533. return Result::success($result);
  2534. }
  2535. /**
  2536. * c端-获取招工招聘
  2537. * @param array $data
  2538. * @return array
  2539. * */
  2540. public function getWebsiteJob(array $data): array
  2541. {
  2542. $web = Website::where('id', $data['website_id'])->first();
  2543. if (empty($web)) {
  2544. return Result::error("该网站不存在", 0);
  2545. }
  2546. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2547. ->where('job_hunting.website_id', $data['website_id'])
  2548. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2549. $query->where(function ($q) use ($data) {
  2550. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2551. });
  2552. })
  2553. ->select(
  2554. 'job_hunting.id',
  2555. 'job_hunting.cat_arr_id',
  2556. 'job_hunting.job_name_get',
  2557. 'job_hunting.industry',
  2558. 'job_hunting.name',
  2559. 'job_hunting.sexy',
  2560. 'job_hunting.origin',
  2561. 'job_hunting.city_arr_id',
  2562. 'job_hunting.experience',
  2563. 'job_hunting.updated_at',
  2564. 'job_hunting.salary'
  2565. )
  2566. ->orderBy('updated_at', 'desc')
  2567. ->limit($data['job1_num'])
  2568. ->get();
  2569. $web['website_id'] = $data['website_id'];
  2570. if (empty($job_hunting)) {
  2571. $job_huntings = "未查询到相关简历信息";
  2572. } else {
  2573. $job_huntings = $this->processJob($job_hunting, $web);
  2574. }
  2575. // 0:待审核 1:已通过 2:已拒绝
  2576. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2577. ->where('job_recruiting.website_id', $data['website_id'])
  2578. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2579. $query->where(function ($q) use ($data) {
  2580. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2581. });
  2582. })
  2583. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2584. ->select(
  2585. 'job_recruiting.id',
  2586. 'job_recruiting.cat_arr_id',
  2587. 'job_recruiting.title',
  2588. 'job_recruiting.jtzw_id',
  2589. 'job_recruiting.hy_id',
  2590. 'job_recruiting.city_arr_id',
  2591. 'job_recruiting.due_data',
  2592. 'job_recruiting.updated_at',
  2593. 'job_recruiting.experience',
  2594. 'job_recruiting.educational',
  2595. 'job_recruiting.salary',
  2596. 'job_recruiting.zw_id',
  2597. 'job_company.business_name'
  2598. )
  2599. ->orderBy('updated_at', 'desc')
  2600. ->limit($data['job2_num'])
  2601. ->get();
  2602. if (empty($job_recruiting->toArray())) {
  2603. $job_recruitings = "未查询到相关职位信息";
  2604. } else {
  2605. $job_recruitings = $this->processJob($job_recruiting, $web);
  2606. }
  2607. $result = [
  2608. 'job_hunting' => $job_huntings,
  2609. 'job_recuiting' => $job_recruitings,
  2610. ];
  2611. return Result::success($result);
  2612. }
  2613. /**
  2614. * c端-获取招工招聘列表
  2615. * @param array $data
  2616. * @return array
  2617. * */
  2618. public function getWebsiteJobList(array $data): array
  2619. {
  2620. $recruit_where = [];
  2621. $hunt_where = [];
  2622. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2623. if(empty($web)){
  2624. return Result::error("此网站不存在", 0);
  2625. }
  2626. $website_id['website_id'] = $data['website_id'];
  2627. if((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])){
  2628. if(isset($data['zw_id']) && !empty($data['zw_id'])){
  2629. array_push($recruit_where, ['zw_id',$data['zw_id']]);
  2630. }
  2631. if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
  2632. array_push($recruit_where, ['jtzw_id',$data['jtzw_id']]);
  2633. }
  2634. if(isset($data['hy_id']) && !empty($data['hy_id'])){
  2635. array_push($recruit_where, ['hy_id',$data['hy_id']]);
  2636. }
  2637. $query = JobRecruiting::where('job_recruiting.status', 1)
  2638. ->where('job_recruiting.website_id', $data['website_id'])
  2639. ->where($recruit_where)
  2640. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2641. $query->where(function($q) use ($data) {
  2642. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2643. });
  2644. })
  2645. ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
  2646. $query->where(function($q) use ($data) {
  2647. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '". intval($data['catid']). "') = 1");
  2648. });
  2649. })
  2650. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2651. ->select('job_recruiting.id','job_recruiting.hy_id','job_recruiting.title','job_recruiting.zw_id','job_recruiting.educational',
  2652. 'job_recruiting.jtzw_id','job_recruiting.city_arr_id','job_recruiting.due_data','job_recruiting.experience',
  2653. 'job_recruiting.cat_arr_id','job_recruiting.updated_at','job_company.business_name')
  2654. ->orderBy('updated_at', 'desc');
  2655. $recruit_count = $query->count();
  2656. $query = clone $query;
  2657. $JobRecruiting = $query
  2658. ->offset(($data['page'] - 1) * $data['pageSize'])
  2659. ->limit($data['pageSize'])
  2660. ->get();
  2661. if (empty($JobRecruiting)) {
  2662. $JobRecruiting = "暂无相关职位信息";
  2663. } else {
  2664. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2665. }
  2666. }
  2667. if((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])){
  2668. if(isset($data['zw_id']) && !empty($data['zw_id'])){
  2669. array_push($hunt_where, ['job',$data['zw_id']]);
  2670. }
  2671. if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
  2672. array_push($hunt_where, ['job_name_get',$data['jtzw_id']]);
  2673. }
  2674. if(isset($data['hy_id']) && !empty($data['hy_id'])){
  2675. array_push($hunt_where, ['industry',$data['hy_id']]);
  2676. }
  2677. $query = JobHunting::where('status', 2)
  2678. ->where('job_hunting.website_id', $data['website_id'])
  2679. ->where($hunt_where)
  2680. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2681. $query->where(function($q) use ($data) {
  2682. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2683. });
  2684. })
  2685. ->when(isset($data['catid_id']) &&!empty($data['catid_id']), function ($query) use ($data) {
  2686. $query->where(function($q) use ($data) {
  2687. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '". intval($data['catid_id']). "') = 1");
  2688. });
  2689. })
  2690. ->select('id','sexy','experience','origin','industry','name','job','job_name_get','city_arr_id','cat_arr_id','created_at','updated_at')
  2691. ->orderBy('updated_at', 'desc');
  2692. $hunt_count = $query->count();
  2693. $query = clone $query;
  2694. $JobHunting = $query
  2695. ->offset(($data['page'] - 1) * $data['pageSize'])
  2696. ->limit($data['pageSize'])
  2697. ->get();
  2698. if (empty($JobHunting)) {
  2699. $JobRecruiting = "暂无相关简历信息";
  2700. } else {
  2701. $JobHunting = $this->processJob($JobHunting, $website_id);
  2702. }
  2703. }
  2704. $result = [
  2705. 'JobRecruiting' => $JobRecruiting ?? [],
  2706. 'recruit_count' => $recruit_count ?? 0,
  2707. 'JobHunting' => $JobHunting ?? [],
  2708. 'hunt_count' => $hunt_count ?? 0,
  2709. ];
  2710. return Result::success($result);
  2711. }
  2712. /**
  2713. * c端-获取招工招聘详情
  2714. * @param array $data
  2715. * @return array
  2716. * */
  2717. public function getWebsiteJobInfo(array $data): array
  2718. {
  2719. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2720. if (empty($web)) {
  2721. return Result::error("该网站不存在", 0);
  2722. }
  2723. $webid = [
  2724. 'website_id' => $data['website_id'],
  2725. ];
  2726. // 职位相关信息
  2727. if ($data['type'] == 1) {
  2728. $query = JobRecruiting::where('status', 1)
  2729. ->where('website_id', $data['website_id'])
  2730. ->select('*');
  2731. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2732. $company = JobCompany::where('job_id', $data['id'])->select('id','business_name','company_hy_id','company_size','company_nature','address_arr_id','address','job_company.email')->get();
  2733. if(!empty($company)){
  2734. $result['company'] = $this->processJob($company, $webid);
  2735. }
  2736. $other_job = JobRecruiting::where('status', 1)
  2737. ->where('website_id', $data['website_id'])
  2738. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2739. ->where('id', '!=', $data['id'])
  2740. ->where('user_id', '=', $job[0]['user_id'])
  2741. ->limit($data['pageSize'])
  2742. ->get();
  2743. if (!empty($other_job)) {
  2744. $result['other_job'] = $this->processJob($other_job, $webid);
  2745. }
  2746. }else{
  2747. // 简历相关信息
  2748. $job = JobHunting::where('job_hunting.status', 2)
  2749. ->where('job_hunting.website_id', $data['website_id'])
  2750. ->where('job_hunting.id', $data['id'])
  2751. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2752. ->select('job_hunting.*', 'user_name')
  2753. ->get();
  2754. $resume = JobRemuse::where('hunt_id',$data['id'])->get();
  2755. if(!empty($resume->toArray())){
  2756. $result['resume'] = 1;
  2757. } else {
  2758. $result['resume'] = 0;
  2759. }
  2760. }
  2761. if (empty($job->toArray())) {
  2762. return Result::error("id参数错误", 0);
  2763. }
  2764. if(!empty($job[0]['job_experience'])){
  2765. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2766. if(!empty($job_experience)){
  2767. // $hy = [];
  2768. foreach($job_experience as $key => $value){
  2769. // $id = $value['id'];
  2770. $hy[$key] = $value['job_industry'];
  2771. $zw_id[$key] = $value['job_typename'];
  2772. $jtzw_id[$key] = $value['job_name'];
  2773. }
  2774. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid','hyname')->get();
  2775. $zw_table = JobPosition::select('zwid','zwname')->get();
  2776. // 先将关联表转换为索引数组,提高查找效率
  2777. $hyLookup = [];
  2778. foreach ($hy_table as $item) {
  2779. $hyLookup[$item['hyid']] = $item['hyname'];
  2780. }
  2781. $zwLookup = [];
  2782. foreach ($zw_table as $item) {
  2783. $zwLookup[$item['zwid']] = $item['zwname'];
  2784. }
  2785. foreach ($job_experience as $key => &$value) {
  2786. // 处理行业名称
  2787. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2788. $value['hy_name'] = $hyLookup[$hy[$key]];
  2789. }
  2790. // 处理职位名称
  2791. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2792. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2793. }
  2794. // 处理具体职位名称
  2795. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2796. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2797. }
  2798. }
  2799. // 释放引用,防止意外修改后续代码
  2800. unset($value);
  2801. }
  2802. $result['job_experience'] = $job_experience?? [];
  2803. }
  2804. if(!empty($job[0]['education_experience'])){
  2805. $education_experience = json_decode($job[0]['education_experience'],true)?? '';
  2806. if(!empty($education_experience)){
  2807. foreach($education_experience as $key => $value){
  2808. // $id = $value['id'];
  2809. $education[$key] = $value['school_education'];
  2810. }
  2811. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue',$education)->select('evalue','ename')->get();
  2812. // // 先将关联表转换为索引数组,提高查找效率
  2813. $educationLookup = [];
  2814. foreach ($education_table as $item) {
  2815. $educationLookup[$item['evalue']] = $item['ename'];
  2816. }
  2817. foreach ($education_experience as $key => &$value) {
  2818. // 处理学历名称
  2819. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2820. $value['education_name'] = $educationLookup[$education[$key]];
  2821. }
  2822. }
  2823. }
  2824. $result['education_experience'] = $job_experience?? [];
  2825. }
  2826. $result['job'] = $this->processJob($job, $webid);
  2827. // // 返现对应的栏目
  2828. $catid = json_decode($job[0]['cat_arr_id'],true) ?? '';
  2829. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2830. ->whereIn('category_id', $catid)
  2831. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2832. ->orderBy('pid')->get()->all();
  2833. if(!empty($category)){
  2834. $result['category'] = $category;
  2835. }
  2836. $result['job'] = $job;
  2837. $result['job_experience'] = $job_experience?? [];
  2838. $result['education_experience'] = $education_experience?? [];
  2839. if(empty($result)){
  2840. return Result::error("参数错误", 0);
  2841. }
  2842. return Result::success($result);
  2843. }
  2844. /**
  2845. * c端-申请职位
  2846. * @param array $data
  2847. * @return array
  2848. * */
  2849. public function getWebsiteJobApply(array $data): array
  2850. {
  2851. // 首先验证网站是否存在
  2852. // return Result::success($data);
  2853. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2854. if (empty($web)) {
  2855. return Result::error("该网站不存在", 0);
  2856. }
  2857. // 验证用户是否存在且为个人会员/管理员
  2858. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2859. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2860. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2861. return Result::error("用户不存在", 0);
  2862. }
  2863. // 去除重复元素和空元素,并保持原始顺序
  2864. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2865. return !empty($value);
  2866. }));
  2867. // 验证职位是否存在 1:审核通过
  2868. $recruiting = JobRecruiting::where('status', 1)
  2869. ->where('website_id', $data['website_id'])
  2870. ->whereIn('id', $data['recruit_id'])
  2871. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2872. if (empty($recruiting)) {
  2873. return Result::error("该职位不存在", 0);
  2874. }
  2875. // 简历是否存在
  2876. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2877. if (empty($hunt_id)) {
  2878. return Result::error("该简历不存在", 0);
  2879. }
  2880. $data['hunt_id'] = $hunt_id['hunt_id'];
  2881. // // 验证是否已投递过该职位
  2882. $apply = JobApply::where('user_id', $data['user_id'])
  2883. ->where('hunt_id', $data['hunt_id'])
  2884. ->where('website_id', $data['website_id'])
  2885. ->whereIn('recruit_id', $data['recruit_id'])
  2886. ->get(['recruit_id']);
  2887. if (!empty($apply->toArray())) {
  2888. return Result::error("您已投递过该职位!");
  2889. }
  2890. $insertData = array_map(function ($recruiting) use ($data) {
  2891. return [
  2892. 'user_id' => $data['user_id'],
  2893. 'hunt_id' => $data['hunt_id'],
  2894. 'website_id' => $data['website_id'],
  2895. 'recruit_id' => $recruiting['recruit_id'],
  2896. 'receiver_id' => $recruiting['receiver_id'],
  2897. 'status' => 1,
  2898. ];
  2899. }, $recruiting);
  2900. // 批量插入数据
  2901. $result = JobApply::insert($insertData);
  2902. if (empty($result)) {
  2903. return Result::error("投递失败", 0);
  2904. }
  2905. return Result::success($result);
  2906. }
  2907. /**
  2908. * 招工招聘-沟通简历
  2909. * @param array $data
  2910. * @return array
  2911. * */
  2912. public function getWebsiteJobResume(array $data): array
  2913. {
  2914. // 首先验证网站是否存在
  2915. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2916. if (empty($web)) {
  2917. return Result::error("该网站不存在", 0);
  2918. }
  2919. // return Result::success($data);
  2920. // 验证用户是否存在且为企业会员/管理员
  2921. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2922. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2923. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2924. return Result::error("用户不存在", 0);
  2925. }
  2926. // 去除重复元素和空元素,并保持原始顺序
  2927. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2928. return !empty($value);
  2929. }));
  2930. // 验证简历是否存在
  2931. $hunting = JobHunting::where('status', 2)
  2932. ->where('website_id', $data['website_id'])
  2933. ->whereIn('id', $data['hunt_id'])
  2934. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2935. if (empty($hunting)) {
  2936. return Result::error("该简历不存在", 0);
  2937. }
  2938. // 验证是否已沟通过该简历
  2939. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2940. ->where('recruit_id', $data['recruit_id'])
  2941. ->where('website_id', $data['website_id'])
  2942. ->whereIn('hunt_id', $data['hunt_id'])
  2943. ->get(['hunt_id']);
  2944. if (!empty($remuse->toArray())) {
  2945. return Result::error("您已沟通过该简历!");
  2946. }
  2947. // 准备要插入的数据数组
  2948. $insertData = array_map(function ($hunting) use ($data) {
  2949. return [
  2950. 'user_id' => $data['user_id'],
  2951. 'recruit_id' => $data['recruit_id'],
  2952. 'website_id' => $data['website_id'],
  2953. 'hunt_id' => $hunting['hunt_id'],
  2954. 'receiver_id' => $hunting['receiver_id'],
  2955. 'status' => 1,
  2956. ];
  2957. }, $hunting);
  2958. // 批量插入数据
  2959. $result = JobRemuse::insert($insertData);
  2960. if (empty($result)) {
  2961. return Result::error("沟通失败", 0);
  2962. }
  2963. return Result::success($result);
  2964. }
  2965. /**
  2966. * 招工招聘 -我的职位(企业会员)
  2967. * @param array $data
  2968. * @return array
  2969. */
  2970. public function getWebsiteJobRecruiting(array $data): array
  2971. {
  2972. $web = Website::where('id', $data['website_id'])->first('id');
  2973. if (empty($web)) {
  2974. return Result::error("该网站不存在", 0);
  2975. }
  2976. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2977. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2978. return Result::error("用户暂无权限!", 0);
  2979. }
  2980. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2981. $result = JobRecruiting::where('website_id', $data['website_id'])
  2982. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  2983. $query->where('user_id', $user['id']);
  2984. })
  2985. ->where('status', 1)
  2986. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  2987. ->orderBy('updated_at', 'desc')
  2988. ->limit($data['pageSize'])
  2989. ->get();
  2990. if (empty($result)) {
  2991. return Result::error("暂无相关职位信息", 0);
  2992. }
  2993. return Result::success($result);
  2994. }
  2995. /**
  2996. * c端 - 验证路由
  2997. * @param array $data
  2998. * @return array
  2999. */
  3000. public function checkWebsiteRoute(array $data): array
  3001. {
  3002. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3003. if (empty($web)) {
  3004. return Result::error("该网站不存在", 0);
  3005. }
  3006. // 验证栏目路由
  3007. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3008. ->where('aLIas_pinyin', $data['last_route'])
  3009. ->first();
  3010. if (empty($last_category)) {
  3011. return Result::error("该栏目不存在", 0);
  3012. }
  3013. if (isset($data['id']) && !empty($data['id'])) {
  3014. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3015. switch ($last_category['type']) {
  3016. case 1:
  3017. // 文章
  3018. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3019. $article = Article::where('status', 1)
  3020. ->where('id', $data['id'])
  3021. ->where(function ($query) use ($data) {
  3022. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3023. ->orWhereNull("ignore_ids");
  3024. })
  3025. ->first(['cat_arr_id']);
  3026. if (empty($article)) {
  3027. return Result::error("该文章不存在", 0);
  3028. }
  3029. // return Result::success($article);
  3030. break;
  3031. case 2:
  3032. // 商品
  3033. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3034. $article = Good::where('website_id', $data['website_id'])
  3035. ->where('status', 2)
  3036. ->where('id', $data['id'])
  3037. ->first(['cat_arr_id']);
  3038. if (empty($article)) {
  3039. return Result::error("该商品不存在", 0);
  3040. }
  3041. break;
  3042. case 3:
  3043. // 书刊信息
  3044. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3045. $article = Book::where('website_id', $data['website_id'])
  3046. ->where('status', 2)
  3047. ->where('id', $data['id'])
  3048. ->first(['id', 'cat_arr_id']);
  3049. if (empty($article)) {
  3050. return Result::error("该书刊不存在", 0);
  3051. }
  3052. break;
  3053. case 4:
  3054. // 招聘
  3055. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3056. $article = JobRecruiting::where('website_id', $data['website_id'])
  3057. ->where('status', 1)
  3058. ->where('id', $data['id'])
  3059. ->first(['cat_arr_id']);
  3060. if (empty($article)) {
  3061. return Result::error("该招聘不存在", 0);
  3062. }
  3063. break;
  3064. case 5:
  3065. // 求职
  3066. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3067. $article = JobHunting::where('website_id', $data['website_id'])
  3068. ->where('status', 2)
  3069. ->where('id', $data['id'])
  3070. ->first(['cat_arr_id']);
  3071. if (empty($article)) {
  3072. return Result::error("该求职不存在", 0);
  3073. }
  3074. break;
  3075. case 6:
  3076. // 招工招聘
  3077. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3078. $article = JobRecruiting::where('website_id', $data['website_id'])
  3079. ->where('status', 1)
  3080. ->where('id', $data['id'])
  3081. ->first(['cat_arr_id']);
  3082. if (empty($article)) {
  3083. $article = JobHunting::where('website_id', $data['website_id'])
  3084. ->where('status', 2)
  3085. ->where('id', $data['id'])
  3086. ->first(['cat_arr_id']);
  3087. }
  3088. if (empty($article)) {
  3089. return Result::error("该招工招聘不存在", 0);
  3090. }
  3091. break;
  3092. default:
  3093. return Result::error("该数据不存在", 0);
  3094. break;
  3095. }
  3096. $catid = json_decode($article['cat_arr_id'], true);
  3097. if (empty($catid)) {
  3098. return Result::error("该数据不存在", 0);
  3099. }
  3100. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3101. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3102. ->whereIn('category_id', $catid)
  3103. ->pluck('aLIas_pinyin')
  3104. ->implode('/');
  3105. }
  3106. if ($last_category['pid'] != 0) {
  3107. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3108. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3109. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3110. ->whereIn('category_id', $cat_arr)
  3111. ->pluck('aLIas_pinyin')
  3112. ->implode('/');
  3113. } else {
  3114. $pinyin = $last_category['aLIas_pinyin'];
  3115. }
  3116. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3117. return Result::error('非法路径!');
  3118. } else {
  3119. return Result::success($pinyin);
  3120. }
  3121. }
  3122. /**
  3123. * 验证导航名称是否重复
  3124. * @return void
  3125. */
  3126. public function checkCategoryName(array $data): array
  3127. {
  3128. $result = Category::when($data, function ($query) use ($data) {
  3129. if (isset($data['name']) && $data['name']) {
  3130. $query->where("name", $data['name']);
  3131. }
  3132. if (isset($data['id']) && $data['id']) {
  3133. $query->where("id", "!=", $data['id']);
  3134. }
  3135. })->first();
  3136. if ($result) {
  3137. return Result::error("已存在");
  3138. } else {
  3139. return Result::success();
  3140. }
  3141. }
  3142. //20250226 产品列表
  3143. public function getGoodList(array $data): array
  3144. {
  3145. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3146. unset($data['type_id']);
  3147. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3148. $where = [];
  3149. if ($type_id != '10000') {
  3150. $where = [
  3151. 'good.user_id' => $user_id,
  3152. ];
  3153. }
  3154. //类型
  3155. if (isset($data['type_id']) && $data['type_id']) {
  3156. $where = [
  3157. 'type_id' => $data['type_id'],
  3158. ];
  3159. }
  3160. //名称
  3161. if (isset($data['name']) && $data['name']) {
  3162. $where = [
  3163. 'good.name' => $data['name'],
  3164. ];
  3165. }
  3166. //status
  3167. if (isset($data['status']) && $data['status'] != '') {
  3168. $where = [
  3169. 'good.status' => $data['status'],
  3170. ];
  3171. }
  3172. //status1
  3173. // if (isset($data['status1']) && $data['status1'] == 1) {
  3174. // $status1 = 1;
  3175. // }
  3176. $where1 = [];
  3177. //website_id
  3178. // if (isset($data['website_id']) && $data['website_id']) {
  3179. // $where1 = [
  3180. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3181. // ];
  3182. // }
  3183. // website_name
  3184. if (isset($data['website_name']) && $data['website_name']) {
  3185. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3186. }
  3187. // catid
  3188. if (isset($data['category_name']) && $data['category_name']) {
  3189. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3190. }
  3191. // $result = Good::where($where)
  3192. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3193. $result = Good::where($where)
  3194. ->when(!empty($where1), function ($query) use ($where1) {
  3195. return $query->where($where1);
  3196. })
  3197. //status 1待审核2已审核3已拒绝
  3198. ->when(isset($data['status1']), function ($query) {
  3199. return $query->whereIn('good.status', [1, 3]);
  3200. })
  3201. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3202. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3203. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3204. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3205. ->orderBy("updated_at", "desc")
  3206. ->limit($data['page_size'])
  3207. ->offset(($data['page'] - 1) * $data['page_size'])
  3208. ->get();
  3209. $count = Good::where($where)
  3210. ->when(!empty($where1), function ($query) use ($where1) {
  3211. return $query->where($where1);
  3212. })
  3213. //status 1待审核2已审核3已拒绝
  3214. ->when(isset($data['status1']), function ($query) {
  3215. return $query->whereIn('good.status', [1, 3]);
  3216. })
  3217. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3218. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3219. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3220. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3221. ->orderBy("updated_at", "desc")->count();
  3222. $data = [
  3223. 'rows' => $result->toArray(),
  3224. 'count' => $count,
  3225. ];
  3226. if (empty($result)) {
  3227. return Result::error("此栏目暂无相关产品", 0);
  3228. }
  3229. return Result::success($data);
  3230. }
  3231. public function getGoodInfo(array $data): array
  3232. {
  3233. $result = Good::where('id', $data['id'])->first();
  3234. if (empty($result)) {
  3235. return Result::error("此产品不存在", 0);
  3236. }
  3237. return Result::success($result);
  3238. }
  3239. public function addGood(array $data): array
  3240. {
  3241. // unset($data['city_arr_id']);
  3242. // unset($data['cat_arr_id']);
  3243. $data['city_id'] = end($data['city_arr_id']);
  3244. $data['catid'] = end($data['cat_arr_id']);
  3245. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3246. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3247. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3248. unset($data['imgUrl']);
  3249. if (isset($data['price']) && $data['price'] == '') {
  3250. $data['price'] = 0;
  3251. }
  3252. $result = Good::insert($data);
  3253. if (empty($result)) {
  3254. return Result::error("添加失败", 0);
  3255. }
  3256. return Result::success($result);
  3257. }
  3258. public function updateGood(array $data): array
  3259. {
  3260. $data['city_id'] = end($data['city_arr_id']);
  3261. $data['catid'] = end($data['cat_arr_id']);
  3262. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3263. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3264. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3265. //设置东八区
  3266. date_default_timezone_set('Asia/Shanghai');
  3267. $data['updated_at'] = date('Y-m-d H:i:s');
  3268. if (isset($data['price']) && $data['price'] == '') {
  3269. $data['price'] = 0;
  3270. }
  3271. $result = Good::where('id', $data['id'])->update($data);
  3272. if (empty($result)) {
  3273. return Result::error("更新失败", 0);
  3274. }
  3275. return Result::success($result);
  3276. }
  3277. public function delGood(array $data): array
  3278. {
  3279. $result = Good::where('id', $data['id'])->delete();
  3280. if (empty($result)) {
  3281. return Result::error("删除失败", 0);
  3282. }
  3283. return Result::success($result);
  3284. }
  3285. //20250226 产品列表
  3286. //20250306 求职信息
  3287. public function getJobHuntingList(array $data): array
  3288. {
  3289. $where = [];
  3290. if (isset($data['username']) && !empty($data['username'])) {
  3291. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3292. }
  3293. //status 1待审核2已审核3已拒绝
  3294. if (isset($data['status']) && $data['status'] != '') {
  3295. $where = [
  3296. 'job_hunting.status' => $data['status'],
  3297. ];
  3298. }
  3299. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3300. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3301. unset($data['type_id']);
  3302. if ($type_id != '10000') {
  3303. $where[] = ['job_hunting.user_id', '=', $user_id];
  3304. }
  3305. $result = JobHunting::where($where)
  3306. ->when(!empty($data['status1']), function ($query) use ($data) {
  3307. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3308. })
  3309. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3310. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3311. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3312. ->orderBy("updated_at", "desc")
  3313. ->limit($data['page_size'])
  3314. ->offset(($data['page'] - 1) * $data['page_size'])
  3315. ->get();
  3316. if (empty($result)) {
  3317. return Result::error("查询失败", 0);
  3318. }
  3319. $count = JobHunting::where($where)
  3320. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3321. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3322. ->count();
  3323. $data = [
  3324. 'rows' => $result->toArray(),
  3325. 'count' => $count,
  3326. ];
  3327. return Result::success($data);
  3328. }
  3329. public function getJobHuntingApply(array $data): array
  3330. {
  3331. $where = [];
  3332. if (isset($data['username']) && !empty($data['username'])) {
  3333. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3334. }
  3335. if (isset($data['salary']) && !empty($data['salary'])) {
  3336. $where = [
  3337. 'job_hunting.salary' => $data['salary'],
  3338. ];
  3339. }
  3340. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3341. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3342. unset($data['type_id']);
  3343. if ($type_id != '10000') {
  3344. $where[] = ['job_apply.user_id', '=', $user_id];
  3345. }
  3346. $result = jobApply::where($where)
  3347. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3348. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3349. // })
  3350. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3351. ->where('job_enum.egroup', '=', 'income')
  3352. ->where('job_hunting.status', 2) //已审核
  3353. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3354. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3355. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3356. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3357. //职位----是申请职位
  3358. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3359. ->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')
  3360. ->orderBy("job_hunting.updated_at", "desc")
  3361. ->limit($data['page_size'])
  3362. ->offset(($data['page'] - 1) * $data['page_size'])
  3363. ->get();
  3364. if (empty($result)) {
  3365. return Result::error("查询失败", 0);
  3366. }
  3367. $count = jobApply::where($where)
  3368. ->where('job_enum.egroup', '=', 'income')
  3369. ->where('job_hunting.status', 2) //已审核
  3370. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3371. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3372. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3373. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3374. //职位----是申请职位
  3375. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3376. ->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')
  3377. ->count();
  3378. $data = [
  3379. 'rows' => $result->toArray(),
  3380. 'count' => $count,
  3381. ];
  3382. return Result::success($data);
  3383. }
  3384. public function addJobHunting(array $data): array
  3385. {
  3386. date_default_timezone_set('Asia/Shanghai');
  3387. unset($data['company_name']);
  3388. unset($data['job_industry']);
  3389. unset($data['job_name']);
  3390. unset($data['department']);
  3391. unset($data['job_timeList']);
  3392. unset($data['job_content']);
  3393. $data['created_at'] = date('Y-m-d H:i:s');
  3394. $data['updated_at'] = date('Y-m-d H:i:s');
  3395. var_dump($data, '-----------------test---------');
  3396. $result = JobHunting::create($data);
  3397. if (empty($result)) {
  3398. return Result::error("添加失败", 0);
  3399. }
  3400. return Result::success($result);
  3401. }
  3402. public function delJobHunting(array $data): array
  3403. {
  3404. $result = JobHunting::where('id', $data['id'])->delete();
  3405. if (empty($result)) {
  3406. return Result::error("删除失败", 0);
  3407. }
  3408. return Result::success($result);
  3409. }
  3410. public function updateJobHunting(array $data): array
  3411. {
  3412. //设置东八区
  3413. date_default_timezone_set('Asia/Shanghai');
  3414. unset($data['company_name']);
  3415. unset($data['job_industry']);
  3416. unset($data['job_name']);
  3417. unset($data['department']);
  3418. unset($data['job_timeList']);
  3419. unset($data['job_content']);
  3420. unset($data['job_typename']); //不知道这是啥,
  3421. $data['created_at'] = date('Y-m-d H:i:s');
  3422. $data['updated_at'] = date('Y-m-d H:i:s');
  3423. $result = JobHunting::where('id', $data['id'])->update($data);
  3424. if (empty($result)) {
  3425. return Result::error("更新失败", 0);
  3426. }
  3427. return Result::success($result);
  3428. }
  3429. public function getJobHuntingInfo(array $data): array
  3430. {
  3431. $result = JobHunting::where('id', $data['id'])->first();
  3432. if (empty($result)) {
  3433. return Result::error("查询失败", 0);
  3434. }
  3435. return Result::success($result);
  3436. }
  3437. public function getJobHuntingData(array $data): array
  3438. {
  3439. $jobEnum = JobEnum::get();
  3440. $jobIndustry = JobIndustry::get();
  3441. $jobNature = JobNature::get();
  3442. $jobPosition = JobPosition::get();
  3443. $data = [
  3444. 'jobEnum' => $jobEnum,
  3445. 'jobIndustry' => $jobIndustry,
  3446. 'jobNature' => $jobNature,
  3447. 'jobPosition' => $jobPosition,
  3448. ];
  3449. return Result::success($data);
  3450. }
  3451. public function delJobHuntingInfo(array $data): array
  3452. {
  3453. $result = JobHunting::where('id', $data['id'])->delete();
  3454. return Result::success();
  3455. }
  3456. //20250324 通知,公告,消息
  3457. public function delNotice(array $data): array
  3458. {
  3459. $result = Notice::where('id', $data['id'])->delete();
  3460. if ($result) {
  3461. return Result::success();
  3462. } else {
  3463. return Result::error("删除失败", 0);
  3464. }
  3465. }
  3466. public function getNoticeInfo(array $data): array
  3467. {
  3468. $result = Notice::where('id', $data['id'])->first();
  3469. if (empty($result)) {
  3470. return Result::error("查询失败", 0);
  3471. }
  3472. return Result::success($result);
  3473. }
  3474. public function addNotice(array $data): array
  3475. {
  3476. date_default_timezone_set('Asia/Shanghai');
  3477. $data['created_at'] = date('Y-m-d H:i:s');
  3478. $data['updated_at'] = date('Y-m-d H:i:s');
  3479. $user_id = UserInfo::
  3480. //city_id不是null
  3481. whereNotNull('city_id')
  3482. ->whereNotNull('department_id')
  3483. ->where(function ($query) use ($data) {
  3484. $query->where(function ($subQuery) use ($data) {
  3485. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3486. });
  3487. })
  3488. ->where(function ($query) use ($data) {
  3489. $query->where(function ($subQuery) use ($data) {
  3490. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3491. });
  3492. })
  3493. ->pluck('user_id')->toArray();
  3494. $user_id = array_unique($user_id);
  3495. $chat_ids = $user_id;
  3496. $user_id = json_encode($user_id);
  3497. $data['re_user_ids'] = $user_id;
  3498. $result = Notice::insertGetId($data);
  3499. if ($result && $data['is_group'] == 1) {
  3500. //chat_group
  3501. $group_id = PublicData::uuid();
  3502. $groupData = [
  3503. 'id' => $group_id,
  3504. 'creator_id' => $data['user_id'],
  3505. 'group_name' => $data['group_name'] ?? '',
  3506. 'profile' => $data['profile'] ?? 0,
  3507. ];
  3508. $groupResult = ChatGroups::insertGetId($groupData);
  3509. var_dump($groupResult, '-----------------groupid-------');
  3510. $groupMemberData = [
  3511. 'id' => PublicData::uuid(),
  3512. 'user_id' => $data['user_id'],
  3513. 'group_id' => $group_id,
  3514. 'leader' => 2,
  3515. ];
  3516. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3517. //$chat_ids 去除掉$data['user_id']
  3518. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3519. //插入群成员表
  3520. $groupMemberDataUser = [];
  3521. foreach ($chat_ids as $key => $value) {
  3522. $groupMemberDataUser[] = [
  3523. 'id' => PublicData::uuid(),
  3524. 'user_id' => $value,
  3525. 'group_id' => $group_id,
  3526. 'leader' => 1,
  3527. ];
  3528. }
  3529. ChatGroupsMember::insert($groupMemberDataUser);
  3530. //更新result的 group_id
  3531. $data['group_id'] = $group_id;
  3532. Notice::where(['id' => $result])->update($data);
  3533. }
  3534. if (empty($result)) {
  3535. return Result::error("添加失败", 0);
  3536. }
  3537. return Result::success($result);
  3538. }
  3539. public function updateNotice(array $data): array
  3540. {
  3541. date_default_timezone_set('Asia/Shanghai');
  3542. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3543. $user_id = UserInfo::
  3544. //city_id不是null
  3545. whereNotNull('city_id')
  3546. ->whereNotNull('department_id')
  3547. ->where(function ($query) use ($data) {
  3548. $query->where(function ($subQuery) use ($data) {
  3549. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3550. });
  3551. })
  3552. ->where(function ($query) use ($data) {
  3553. $query->where(function ($subQuery) use ($data) {
  3554. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3555. });
  3556. })
  3557. ->pluck('user_id')->toArray();
  3558. $user_id = array_unique($user_id);
  3559. $user_id = json_encode($user_id);
  3560. $data['re_user_ids'] = $user_id;
  3561. $data['updated_at'] = date('Y-m-d H:i:s');
  3562. $result = Notice::where('id', $data['id'])->update($data);
  3563. return Result::success($result);
  3564. }
  3565. public function getNoticeList(array $data): array
  3566. {
  3567. $where = [];
  3568. //title
  3569. if (isset($data['title']) && !empty($data['title'])) {
  3570. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3571. }
  3572. //level
  3573. if (isset($data['level']) && !empty($data['level'])) {
  3574. $where[] = ['notice.level', '=', $data['level']];
  3575. }
  3576. //status
  3577. if (isset($data['status']) && !empty($data['status'])) {
  3578. $where[] = ['notice.status', '=', $data['status']];
  3579. }
  3580. var_dump($data, '-----------------test---------');
  3581. if ($data['type_id'] == 10000) {
  3582. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3583. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3584. })
  3585. ->where($where)
  3586. ->orderBy('updated_at', 'desc')
  3587. ->limit($data['page_size'])
  3588. ->offset(($data['page'] - 1) * $data['page_size'])
  3589. ->get();
  3590. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3591. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3592. })
  3593. ->where($where)
  3594. ->orderBy('updated_at', 'desc')
  3595. ->count();
  3596. } else {
  3597. $result = Notice::where('status', 1)
  3598. ->where($where)
  3599. ->where('user_id', $data['user_id'])
  3600. ->orWhere(function ($query) use ($data) {
  3601. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  3602. })
  3603. ->orderBy('updated_at', 'desc')
  3604. ->limit($data['page_size'])
  3605. ->offset(($data['page'] - 1) * $data['page_size'])
  3606. ->get();
  3607. $total = Notice::where('status', 1)
  3608. ->where($where)
  3609. ->where('user_id', $data['user_id'])
  3610. ->orWhere(function ($query) use ($data) {
  3611. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  3612. })
  3613. ->count();
  3614. }
  3615. if (empty($result)) {
  3616. return Result::error("查询失败", 0);
  3617. }
  3618. $data = [
  3619. 'rows' => $result,
  3620. 'count' => $total,
  3621. ];
  3622. return Result::success($data);
  3623. }
  3624. public function getNoticeDetail(array $data): array
  3625. {
  3626. $result = Notice::where('id', $data['id'])->first();
  3627. if (empty($result)) {
  3628. return Result::error("查询失败", 0);
  3629. }
  3630. return Result::success($result);
  3631. }
  3632. public function deleteNotice(array $data): array
  3633. {
  3634. $notice = Notice::where('id', $data['id'])->first();
  3635. if (empty($notice)) {
  3636. return Result::error("删除失败", 0);
  3637. }
  3638. $chat_group_id = $notice->group_id;
  3639. if ($chat_group_id) {
  3640. //删除群聊
  3641. ChatGroups::where('id', $chat_group_id)->delete();
  3642. //删除群成员
  3643. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3644. //删除群聊记录
  3645. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3646. }
  3647. $result = Notice::where('id', $data['id'])->delete();
  3648. return Result::success($result);
  3649. }
  3650. public function getMSG(array $data): array
  3651. {
  3652. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3653. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3654. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3655. $result = [];
  3656. if ($type_id == 1) {
  3657. //最近的5篇已审的文章
  3658. $apply_articale = Article::where('status', 1)
  3659. ->where('admin_user_id', $user_id)
  3660. ->orderBy('updated_at', 'desc')
  3661. ->limit(5)->get();
  3662. //获取5条单聊未读聊天消息
  3663. $chat = ChatRecords::where('is_read', 0)
  3664. ->where('user_id', $user_id)
  3665. ->where('talk_type', 1)
  3666. ->orderBy('created_at', 'desc')
  3667. ->limit(5)->get();
  3668. //获取5条未读群聊信息
  3669. $chat_group = ChatRecords::where('is_read', 0)
  3670. ->where('user_id', $user_id)
  3671. ->where('talk_type', 2)
  3672. ->orderBy('created_at', 'desc')
  3673. ->limit(5)->get();
  3674. //获取5条用户的已审核商品
  3675. $good = Good::where('status', 2)
  3676. ->where('user_id', $user_id)
  3677. ->orderBy('updated_at', 'desc')
  3678. ->limit(5)->get();
  3679. //获取5条用户待审核的公告
  3680. $notice = Notice::where('status', 2)
  3681. ->where('user_id', $user_id)
  3682. ->orderBy('updated_at', 'desc')
  3683. ->limit(5)->get();
  3684. //获取5条用户的待审核投诉
  3685. $complaint = Complaint::where('status', 2)
  3686. ->where('user_id', $user_id)
  3687. ->orderBy('updated_at', 'desc')
  3688. ->limit(5)->get();
  3689. //获取5条用户的book
  3690. $book = Book::where('status', 2)
  3691. ->where('user_id', $user_id)
  3692. ->orderBy('updated_at', 'desc')
  3693. ->limit(5)->get();
  3694. //获取5条用户的求职
  3695. //获取5条用户的求职 1
  3696. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3697. ->where('job_hunting.user_id', $user_id)
  3698. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3699. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3700. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3701. ->orderBy('updated_at', 'desc')
  3702. ->limit(5)->get();
  3703. //获取5条用户的求职 2
  3704. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3705. ->where('job_recruiting.user_id', $user_id)
  3706. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3707. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3708. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3709. ->orderBy('updated_at', 'desc')
  3710. ->limit(5)->get();
  3711. //人才库 1
  3712. $job_apply = JobApply::where('job_apply.status', 1)
  3713. ->where('job_apply.receiver_id', $user_id)
  3714. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3715. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3716. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3717. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3718. ->select('job_recruiting', 'job_recruiting.', '', '')
  3719. ->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')
  3720. ->orderBy('updated_at', 'desc')
  3721. ->limit(5)->get();
  3722. // 职场机会 2
  3723. $job_resume = JobResume::where('job_resume.status', 1)
  3724. ->where('job_resume.receiver_id', $user_id)
  3725. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3726. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3727. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3728. ->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')
  3729. ->orderBy('updated_at', 'desc')
  3730. ->limit(5)->get();
  3731. $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);
  3732. $result = [
  3733. 'apply_articale' => $apply_articale,
  3734. 'chat' => $chat,
  3735. 'chat_group' => $chat_group,
  3736. 'good' => $good,
  3737. 'notice' => $notice,
  3738. 'complaint' => $complaint,
  3739. 'book' => $book,
  3740. 'job_hunting' => $job_hunting,
  3741. 'job_recruiting' => $job_recruiting,
  3742. 'job_apply' => $job_apply,
  3743. 'job_resume' => $job_resume,
  3744. 'count' => $count,
  3745. ];
  3746. } elseif ($type_id == 2) {
  3747. //最近的5篇已审的文章
  3748. $apply_articale = Article::where('status', 1)
  3749. ->where('admin_user_id', $user_id)
  3750. ->limit(5)->get();
  3751. //获取5条单聊未读聊天消息
  3752. $chat = ChatRecords::where('is_read', 0)
  3753. ->where('user_id', $user_id)
  3754. ->where('talk_type', 1)
  3755. ->orderBy('created_at', 'desc')
  3756. ->limit(5)->get();
  3757. //获取5条未读群聊信息
  3758. $chat_group = ChatRecords::where('is_read', 0)
  3759. ->where('user_id', $user_id)
  3760. ->where('talk_type', 2)
  3761. ->orderBy('created_at', 'desc')
  3762. ->limit(5)->get();
  3763. //获取5条用户的已审核商品
  3764. $good = Good::where('status', 2)
  3765. ->where('user_id', $user_id)
  3766. ->orderBy('updated_at', 'desc')
  3767. ->limit(5)->get();
  3768. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3769. $result = [
  3770. 'apply_articale' => $apply_articale,
  3771. 'chat' => $chat,
  3772. 'chat_group' => $chat_group,
  3773. 'good' => $good,
  3774. 'count' => $count,
  3775. ];
  3776. } elseif ($type_id == 3) {
  3777. //最近的5篇已审的文章
  3778. $apply_articale = Article::where('status', 1)
  3779. ->where('admin_user_id', $user_id)
  3780. ->limit(5)->get();
  3781. //获取5条单聊未读聊天消息
  3782. $chat = ChatRecords::where('is_read', 0)
  3783. ->where('user_id', $user_id)
  3784. ->where('talk_type', 1)
  3785. ->orderBy('created_at', 'desc')
  3786. ->limit(5)->get();
  3787. //获取5条未读群聊信息
  3788. $chat_group = ChatRecords::where('is_read', 0)
  3789. ->where('user_id', $user_id)
  3790. ->where('talk_type', 2)
  3791. ->orderBy('created_at', 'desc')
  3792. ->limit(5)->get();
  3793. //获取5条用户的已审核商品
  3794. $good = Good::where('status', 2)
  3795. ->where('user_id', $user_id)
  3796. ->orderBy('updated_at', 'desc')
  3797. ->limit(5)->get();
  3798. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3799. $result = [
  3800. 'apply_articale' => $apply_articale,
  3801. 'chat' => $chat,
  3802. 'chat_group' => $chat_group,
  3803. 'good' => $good,
  3804. 'count' => $count,
  3805. ];
  3806. } elseif ($type_id == 4) {
  3807. //最近的5篇已审的文章
  3808. $apply_articale = Article::where('status', 1)
  3809. ->where('admin_user_id', $user_id)
  3810. ->limit(5)->get();
  3811. //获取5条用户的已审核商品
  3812. $good = Good::where('status', 2)
  3813. ->where('user_id', $user_id)
  3814. ->orderBy('updated_at', 'desc')
  3815. ->limit(5)->get();
  3816. $count = count($apply_articale) + count($good);
  3817. $result = [
  3818. 'apply_articale' => $apply_articale,
  3819. 'chat' => '',
  3820. 'chat_group' => '',
  3821. 'good' => $good,
  3822. 'count' => $count,
  3823. ];
  3824. } elseif ($type_id == 10000) {
  3825. //获取未审核的5篇文章
  3826. $apply_articale = Article::where('status', 0)
  3827. ->orderBy('updated_at', 'desc')
  3828. ->limit(5)->get();
  3829. //获取5条单聊未读聊天消息
  3830. $chat = ChatRecords::where('is_read', 0)
  3831. ->where('user_id', $user_id)
  3832. ->where('talk_type', 1)
  3833. ->orderBy('created_at', 'desc')
  3834. ->limit(5)->get();
  3835. //获取5条未读群聊信息
  3836. $chat_group = ChatRecords::where('is_read', 0)
  3837. ->where('user_id', $user_id)
  3838. ->where('talk_type', 2)
  3839. ->orderBy('created_at', 'desc')
  3840. ->limit(5)->get();
  3841. //获取5条用户的已审核商品
  3842. $good = Good::where('status', 1)
  3843. // ->where('user_id', $user_id)
  3844. ->orderBy('updated_at', 'desc')
  3845. ->limit(5)->get();
  3846. //获取5条用户待审核的公告
  3847. $notice = Notice::where('status', 1)
  3848. ->orderBy('updated_at', 'desc')
  3849. ->limit(5)->get();
  3850. //获取5条用户的待审核投诉
  3851. $complaint = Complaint::where('status', 1)
  3852. ->orderBy('updated_at', 'desc')
  3853. ->limit(5)->get();
  3854. //获取5条用户的book
  3855. $book = Book::where('status', 1)
  3856. ->orderBy('updated_at', 'desc')
  3857. ->limit(5)->get();
  3858. //获取5条用户的求职 1
  3859. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3860. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3861. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3862. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3863. ->orderBy('updated_at', 'desc')
  3864. ->limit(5)->get();
  3865. //获取5条用户的求职 2
  3866. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3867. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3868. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3869. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3870. ->orderBy('updated_at', 'desc')
  3871. ->limit(5)->get();
  3872. //人才库 1
  3873. $job_apply = JobApply::where('job_apply.status', 1)
  3874. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3875. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3876. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3877. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3878. ->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')
  3879. ->orderBy('updated_at', 'desc')
  3880. ->limit(5)->get();
  3881. // 职场机会 2
  3882. $job_resume = JobResume::where('job_resume.status', 1)
  3883. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3884. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3885. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3886. ->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')
  3887. ->orderBy('updated_at', 'desc')
  3888. ->limit(5)->get();
  3889. $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);
  3890. $result = [
  3891. 'apply_articale' => $apply_articale,
  3892. 'chat' => $chat,
  3893. 'chat_group' => $chat_group,
  3894. 'good' => $good,
  3895. 'notice' => $notice,
  3896. 'complaint' => $complaint,
  3897. 'book' => $book,
  3898. 'job_hunting' => $job_hunting,
  3899. 'job_recruiting' => $job_recruiting,
  3900. 'job_apply' => $job_apply,
  3901. 'job_resume' => $job_resume,
  3902. 'count' => $count,
  3903. ];
  3904. } elseif ($type_id == 20000) {
  3905. }
  3906. var_dump($type_id, '-----------------test---------');
  3907. return Result::success($result);
  3908. }
  3909. public function getComplaintList(array $data): array
  3910. {
  3911. var_dump($data, '00000001000000000000');
  3912. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3913. unset($data['type_id']);
  3914. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3915. $where = [];
  3916. if ($type_id != 10000) {
  3917. $where['complaint.user_id'] = $user_id;
  3918. }
  3919. if (!empty($data['title'])) {
  3920. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  3921. }
  3922. if (!empty($data['department_id'])) {
  3923. $where['complaint.department_id'] = $data['department_id'];
  3924. }
  3925. if (!empty($data['deal'])) {
  3926. $where['complaint.deal'] = $data['deal'];
  3927. }
  3928. if (!empty($data['status'])) {
  3929. $where['complaint.status'] = $data['status'];
  3930. }
  3931. var_dump(!empty($data['deal_user']), '----------1');
  3932. $result = Complaint::where($where)
  3933. ->when(!empty($data['status1']), function ($query) use ($data) {
  3934. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  3935. })
  3936. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  3937. //json re_user_ids data[user_id]是不是在里面
  3938. $query->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')');
  3939. })
  3940. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  3941. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  3942. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  3943. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  3944. ->orderBy('updated_at', 'desc')
  3945. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  3946. //sql输出
  3947. if (empty($result)) {
  3948. return Result::error("暂无投诉信息", 0);
  3949. }
  3950. // 取出数据
  3951. $rows = $result->items();
  3952. $count = $result->total();
  3953. $responseData = [
  3954. 'rows' => $rows,
  3955. 'count' => $count,
  3956. ];
  3957. return Result::success($responseData);
  3958. }
  3959. public function getComplaintInfo(array $data): array
  3960. {
  3961. $result = Complaint::where('id', $data['id'])->first();
  3962. if (empty($result)) {
  3963. return Result::error("查询失败", 0);
  3964. }
  3965. return Result::success($result);
  3966. }
  3967. public function addComplaint(array $data): array
  3968. {
  3969. date_default_timezone_set('Asia/Shanghai');
  3970. $data['created_at'] = date('Y-m-d H:i:s');
  3971. $data['updated_at'] = date('Y-m-d H:i:s');
  3972. $result = Complaint::create($data);
  3973. return Result::success($result);
  3974. }
  3975. public function updateComplaint(array $data): array
  3976. {
  3977. date_default_timezone_set('Asia/Shanghai');
  3978. $data['updated_at'] = date('Y-m-d H:i:s');
  3979. $user_id = $data['user_id'] ?? 0;
  3980. $type_id = $data['type_id'] ?? 0;
  3981. unset($data['user_id']);
  3982. unset($data['type_id']);
  3983. $result = Complaint::where('id', $data['id'])->update($data);
  3984. return Result::success($result);
  3985. }
  3986. public function deleteComplaint(array $data): array
  3987. {
  3988. $result = Complaint::where('id', $data['id'])->delete();
  3989. return Result::success($result);
  3990. }
  3991. public function getComplainInfo(array $data): array
  3992. {
  3993. $result = Complaint::where('id', $data['id'])->first();
  3994. if (empty($result)) {
  3995. return Result::error("查询失败", 0);
  3996. }
  3997. return Result::success($result);
  3998. }
  3999. public function updateComplaintStatus(array $data): array
  4000. {
  4001. date_default_timezone_set('Asia/Shanghai');
  4002. $data['updated_at'] = date('Y-m-d H:i:s');
  4003. $user_id = $data['user_id'] ?? 0;
  4004. $type_id = $data['type_id'] ?? 0;
  4005. unset($data['user_id']);
  4006. unset($data['type_id']);
  4007. //处理, 写入处理人
  4008. if (isset($data['deal']) && ($data['deal'] == 1 || $data['deal'] == 4)) {
  4009. $data['real_deal_user'] = $user_id;
  4010. }
  4011. //如果是deal 23,则判断是不是处理人
  4012. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 3) && $type_id != 10000) {
  4013. $complaintInof = Complaint::where('id', $data['id'])
  4014. ->where('real_deal_user', $user_id)
  4015. ->first();
  4016. if (empty($complaintInof)) {
  4017. return Result::error("处理人错误", 0);
  4018. }
  4019. }
  4020. $result = complaint::where('id', $data['id'])->update($data);
  4021. return Result::success($result);
  4022. }
  4023. public function updateGoodStatus(array $data): array
  4024. {
  4025. $user_id = $data['user_id'] ?? 0;
  4026. $type_id = $data['type_id'] ?? 0;
  4027. unset($data['user_id']);
  4028. unset($data['type_id']);
  4029. $result = Good::where('id', $data['id'])->update($data);
  4030. return Result::success($result);
  4031. }
  4032. public function updateJobHuntingStatus(array $data): array
  4033. {
  4034. $user_id = $data['user_id'] ?? 0;
  4035. $type_id = $data['type_id'] ?? 0;
  4036. unset($data['user_id']);
  4037. unset($data['type_id']);
  4038. $result = JobHunting::where('id', $data['id'])->update($data);
  4039. return Result::success($result);
  4040. }
  4041. public function updateNoticeStatus(array $data): array
  4042. {
  4043. $user_id = $data['user_id'] ?? 0;
  4044. $type_id = $data['type_id'] ?? 0;
  4045. unset($data['user_id']);
  4046. unset($data['type_id']);
  4047. $result = Notice::where('id', $data['id'])->update($data);
  4048. return Result::success($result);
  4049. }
  4050. public function getDUser(array $data): array
  4051. {
  4052. if (!empty($data['ids'])) {
  4053. $user = User::whereIn('id', $data['ids'])->getall();
  4054. if (empty($user)) {
  4055. return Result::error('无数据', 0);
  4056. }
  4057. return Result::success($user);
  4058. }
  4059. $where = [];
  4060. if (!empty($data['department_id'])) {
  4061. $where['department_id'] = $data['department_id'];
  4062. }
  4063. if (!empty($data['city_id'])) {
  4064. $where['city_id'] = $data['city_id'];
  4065. }
  4066. $result = User::where('type_id', 2)
  4067. ->where('status', 1)
  4068. ->where($where)
  4069. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4070. ->get();
  4071. if (empty($result)) {
  4072. return Result::error("查询失败", 0);
  4073. }
  4074. return Result::success($result);
  4075. }
  4076. //20250324 通知,公告,消息
  4077. // 20250306 -------招聘--------fr
  4078. /*
  4079. * 招聘列表
  4080. * */
  4081. public function getJobRecruitingList(array $data): array
  4082. {
  4083. $where = [];
  4084. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4085. if ($data['checkout'] == 0) {
  4086. $job_status = [0, 2];
  4087. } else {
  4088. $job_status = [1];
  4089. }
  4090. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4091. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4092. }
  4093. $user = User::where('id', $data['user_id'])->first();
  4094. if (empty($user)) {
  4095. return Result::error("用户不存在", 0);
  4096. }
  4097. // 3:企业会员
  4098. if ($user['type_id'] == 3) {
  4099. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4100. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4101. }
  4102. // 如果 $where 为空,则不添加 where 条件
  4103. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4104. return $query->where($where);
  4105. })
  4106. ->whereIn('job_recruiting.status', $job_status)
  4107. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4108. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4109. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4110. ->orderBy("updated_at", "desc")
  4111. ->offset(($data['page'] - 1) * $data['page_size'])
  4112. ->limit($data['page_size'])
  4113. ->get()
  4114. ->all();
  4115. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4116. return $query->where($where);
  4117. })
  4118. ->whereIn('job_recruiting.status', $job_status)
  4119. ->count();
  4120. if (empty($result)) {
  4121. return Result::error("暂无招聘信息", 0);
  4122. }
  4123. return Result::success($result);
  4124. }
  4125. /*
  4126. * 招聘信息添加
  4127. * */
  4128. public function addJobRecruiting(array $data): array
  4129. {
  4130. // return Result::success($data);
  4131. $user = User::where('user.id', $data['user_id'])
  4132. ->where('user.status', 1)
  4133. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4134. ->select(
  4135. 'user.type_id',
  4136. 'user.mobile',
  4137. 'user.email',
  4138. 'user_info.business_name',
  4139. 'user_info.company_hy_id',
  4140. 'user_info.company_nature',
  4141. 'user_info.company_size',
  4142. 'user_info.introduction',
  4143. 'user_info.real_name',
  4144. 'user_info.company_url',
  4145. 'user_info.address_arr_id',
  4146. 'user_info.address'
  4147. )
  4148. ->first();
  4149. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4150. return Result::error("用户不存在", 0);
  4151. }
  4152. $web = Website::where('id', $data['website_id'])->first();
  4153. if (empty($web)) {
  4154. return Result::error("网站不存在", 0);
  4155. }
  4156. // return Result::success($user);
  4157. $data['action_id'] = $data['user_id'];
  4158. $data['user_type'] = $user['type_id'];
  4159. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4160. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4161. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4162. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4163. // 公司地址 管理员必填
  4164. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4165. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4166. // 管理员-企业相关信息
  4167. $company = [
  4168. // 'user_id' => $data['user_id']?? null,
  4169. 'business_name' => $data['business_name'] ?? null,
  4170. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4171. 'company_size' => $data['company_size'] ?? null,
  4172. 'company_nature' => $data['company_nature'] ?? null,
  4173. 'introduction' => $data['introduction'] ?? null,
  4174. 'real_name' => $data['real_name'] ?? null,
  4175. 'mobile' => $data['mobile'] ?? null,
  4176. 'company_url' => $data['company_url'] ?? null,
  4177. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4178. 'address' => $data['address'] ?? null,
  4179. 'email' => $data['email'] ?? null,
  4180. ];
  4181. //去掉相关企业信息
  4182. $job = array_diff_key($data, array_flip(array_keys($company)));
  4183. Db::beginTransaction();
  4184. try {
  4185. // 先添加职位相关信息
  4186. if ($user['type_id'] == 10000) {
  4187. $job['status'] = 1;
  4188. }
  4189. $jobId = JobRecruiting::insertGetId($job);
  4190. if (empty($jobId)) {
  4191. Db::rollBack();
  4192. return Result::error("添加失败");
  4193. }
  4194. // 添加公司信息
  4195. $company['user_id'] = $data['user_id'] ?? null;
  4196. $company['job_id'] = $jobId;
  4197. $company['user_type'] = $user['type_id'] ?? null;
  4198. $company['website_id'] = $data['website_id'] ?? null;
  4199. if ($user['type_id'] == 10000) {
  4200. // 管理员添加企业信息
  4201. // return Result::success($company);
  4202. $companyId = JobCompany::insertGetId($company);
  4203. if (empty($companyId)) {
  4204. Db::rollBack();
  4205. return Result::error("添加失败");
  4206. }
  4207. } else {
  4208. // 企业会员添加企业信息
  4209. $company = [
  4210. 'user_id' => $data['user_id'] ?? null,
  4211. 'business_name' => $user['business_name'] ?? null,
  4212. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4213. 'company_size' => $user['company_size'] ?? null,
  4214. 'company_nature' => $user['company_nature'] ?? null,
  4215. 'introduction' => $user['introduction'] ?? null,
  4216. 'real_name' => $user['real_name'] ?? null,
  4217. 'mobile' => $user['mobile'] ?? null,
  4218. 'company_url' => $user['company_url'] ?? null,
  4219. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4220. 'address' => $user['address'] ?? null,
  4221. 'email' => $user['email'] ?? null,
  4222. 'website_id' => $data['website_id'] ?? null,
  4223. 'user_type' => $user['type_id'] ?? null,
  4224. 'job_id' => $jobId,
  4225. ];
  4226. $companyId = JobCompany::insertGetId($company);
  4227. if (empty($companyId)) {
  4228. Db::rollBack();
  4229. return Result::error("添加失败");
  4230. }
  4231. // return Result::success($company);
  4232. }
  4233. Db::commit();
  4234. } catch (\Exception $e) {
  4235. Db::rollBack();
  4236. return Result::error($e->getMessage(), 0);
  4237. }
  4238. $result = [
  4239. 'job_id' => $jobId,
  4240. 'company_id' => $companyId,
  4241. ];
  4242. if (empty($result)) {
  4243. return Result::error("添加失败", 0);
  4244. }
  4245. return Result::success($result);
  4246. }
  4247. /*
  4248. * 获取招聘信息详情
  4249. * */
  4250. public function getJobRecruitingInfo(array $data): array
  4251. {
  4252. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4253. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4254. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4255. ->select(
  4256. 'job_recruiting.*',
  4257. 'website.website_name as website_name',
  4258. 'job_company.business_name',
  4259. 'job_company.company_hy_id',
  4260. 'job_company.company_size',
  4261. 'job_company.company_nature',
  4262. 'job_company.introduction',
  4263. 'job_company.real_name',
  4264. 'job_company.mobile',
  4265. 'job_company.company_url',
  4266. 'job_company.address_arr_id',
  4267. 'job_company.address',
  4268. 'job_company.email'
  4269. )
  4270. ->first();
  4271. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4272. if (!empty($cityId)) {
  4273. if (isset($cityId[1]) && $cityId[1] != null) {
  4274. $city = District::where('id', $cityId[1])->first(['name']);
  4275. } else {
  4276. $city = District::where('id', $cityId[0])->first(['name']);
  4277. }
  4278. $result['city'] = $city['name'] ?? '';
  4279. }
  4280. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4281. if (is_array($addressId) && !empty($addressId)) {
  4282. $address = District::whereIn('id', $addressId)
  4283. ->orderBy('level', 'asc')
  4284. ->get(['name'])
  4285. ->pluck('name')
  4286. ->implode('');
  4287. // $job->address_name = $address ?? '';
  4288. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4289. }
  4290. if (empty($result)) {
  4291. return Result::error("招聘信息不存在", 0);
  4292. }
  4293. // return Result::success($job);
  4294. return Result::success($result);
  4295. }
  4296. /*
  4297. * 修改招聘信息
  4298. * */
  4299. public function upJobRecruiting(array $data): array
  4300. {
  4301. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4302. // return Result::success($job);
  4303. if (empty($job)) {
  4304. return Result::error("招聘信息不存在", 0);
  4305. }
  4306. $user = User::where('id', $data['user_id'])->first();
  4307. // return Result::success($user);
  4308. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4309. return Result::error("用户不存在", 0);
  4310. }
  4311. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4312. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4313. }
  4314. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4315. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4316. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4317. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4318. // 公司地址 管理员必填
  4319. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4320. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4321. // 管理员-企业相关信息
  4322. $company = [
  4323. 'business_name' => $data['business_name'] ?? null,
  4324. 'company_hy_id' => $data['hy_id'] ?? null,
  4325. 'company_size' => $data['company_size'] ?? null,
  4326. 'company_nature' => $data['company_nature'] ?? null,
  4327. 'introduction' => $data['introduction'] ?? null,
  4328. 'real_name' => $data['real_name'] ?? null,
  4329. 'mobile' => $data['mobile'] ?? null,
  4330. 'company_url' => $data['company_url'] ?? null,
  4331. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4332. 'address' => $data['address'] ?? null,
  4333. 'email' => $data['email'] ?? null,
  4334. ];
  4335. //去掉相关企业信息
  4336. $data = array_diff_key($data, array_flip(array_keys($company)));
  4337. $jobId = $data['id'];
  4338. $web = $data['website_id'];
  4339. $data['action_id'] = $data['user_id'];
  4340. unset($data['user_id']);
  4341. unset($data['user_type']);
  4342. unset($data['id']);
  4343. unset($data['website_id']);
  4344. // return Result::success($data);
  4345. Db::beginTransaction();
  4346. try {
  4347. // 管理员修改招聘信息
  4348. if ($user['type_id'] == 10000) {
  4349. $data['website_id'] = $web;
  4350. $company['website_id'] = $data['website_id'];
  4351. $data['status'] = 1;
  4352. } else {
  4353. $data['status'] = 0;
  4354. }
  4355. // Db::rollBack();
  4356. // return Result::success($company);
  4357. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4358. if (empty($result['job'])) {
  4359. Db::rollBack();
  4360. return Result::error("修改招聘信息失败");
  4361. }
  4362. // 管理员修改企业相关信息
  4363. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4364. if (empty($result['company'])) {
  4365. Db::rollBack();
  4366. return Result::error("修改企业相关信息失败");
  4367. }
  4368. Db::commit();
  4369. // return Result::success($result);
  4370. } catch (\Exception $e) {
  4371. Db::rollBack();
  4372. return Result::error($e->getMessage(), 0);
  4373. }
  4374. return Result::success($result);
  4375. }
  4376. /*
  4377. * 招聘信息删除
  4378. * */
  4379. public function delJobRecruiting(array $data): array
  4380. {
  4381. $user = User::where('id', $data['user_id'])->first();
  4382. if (empty($user)) {
  4383. return Result::error("用户不存在", 0);
  4384. }
  4385. $job = JobRecruiting::where('id', $data['id'])->first();
  4386. if (empty($job)) {
  4387. return Result::error("招聘信息不存在", 0);
  4388. }
  4389. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4390. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4391. }
  4392. Db::beginTransaction();
  4393. try {
  4394. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4395. if (empty($result['job'])) {
  4396. Db::rollBack();
  4397. return Result::error("删除招聘信息失败");
  4398. }
  4399. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4400. if (empty($result['company'])) {
  4401. Db::rollBack();
  4402. return Result::error("删除企业相关信息失败");
  4403. }
  4404. Db::commit();
  4405. } catch (\Exception $e) {
  4406. Db::rollBack();
  4407. return Result::error($e->getMessage(), 0);
  4408. }
  4409. return Result::success($result);
  4410. }
  4411. /*
  4412. * 获取公司信息
  4413. * */
  4414. public function getJobCompany(array $data): array
  4415. {
  4416. $user = User::where('user.id', $data['user_id'])
  4417. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4418. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4419. ->first();
  4420. // return Result::success($user);
  4421. if (empty($user)) {
  4422. return Result::error("用户不存在", 0);
  4423. }
  4424. if ($user['type_id'] == 3) {
  4425. $result = [
  4426. // 'id' => 0,
  4427. 'user_id' => $data['user_id'],
  4428. 'website_id' => $data['website_id'],
  4429. 'business_name' => $user['business_name'], // 企业名称
  4430. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4431. 'company_nature' => $user['company_nature'], // 公司性质
  4432. 'company_size' => $user['company_size'], // 公司规模
  4433. 'introduction' => $user['introduction'], // 公司简介
  4434. 'real_name' => $user['real_name'], // 企业联系人
  4435. 'mobile' => $user['mobile'], // 企业联系电话
  4436. 'company_url' => $user['company_url'], // 企业网址
  4437. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4438. 'address' => $user['address'], // 企业地址
  4439. 'email' => $user['email'], // 企业邮箱
  4440. ];
  4441. } else {
  4442. return Result::error("用户类型错误", 0);
  4443. }
  4444. if (empty($result)) {
  4445. return Result::error("公司信息不存在", 0);
  4446. }
  4447. return Result::success($result);
  4448. }
  4449. /*
  4450. * 修改公司信息
  4451. * */
  4452. public function upJobCompany(array $data): array
  4453. {
  4454. // return Result::success($data);
  4455. $user = User::where('user.id', $data['user_id'])
  4456. ->where('user.status', 1)
  4457. ->select('user.user_name', 'user.type_id')
  4458. ->first();
  4459. if (empty($user)) {
  4460. return Result::error("用户不存在", 0);
  4461. }
  4462. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4463. $company = [
  4464. 'business_name' => $data['business_name'], // 企业名称
  4465. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4466. 'company_nature' => $data['company_nature'], // 公司性质
  4467. 'company_size' => $data['company_size'], // 公司规模
  4468. 'introduction' => $data['introduction'], // 公司简介
  4469. // 'real_name' => $data['real_name'], // 企业联系人
  4470. 'company_url' => $data['company_url'], // 企业网址
  4471. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4472. 'address' => $data['address'], // 企业详细地址
  4473. ];
  4474. if ($user['type_id'] == 3) {
  4475. Db::beginTransaction();
  4476. try {
  4477. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4478. 'business_name' => $data['business_name'], // 企业名称
  4479. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4480. 'company_nature' => $data['company_nature'], // 公司性质
  4481. 'company_size' => $data['company_size'], // 公司规模
  4482. 'introduction' => $data['introduction'], // 公司简介
  4483. // 'real_name' => $data['real_name'], // 企业联系人
  4484. 'company_url' => $data['company_url'], // 企业网址
  4485. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4486. 'address' => $data['address'], // 企业详细地址
  4487. ]);
  4488. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4489. Db::commit();
  4490. } catch (\Exception $e) {
  4491. Db::rollBack();
  4492. return Result::error($e->getMessage(), 0);
  4493. }
  4494. } else {
  4495. return Result::error("用户类型错误", 0);
  4496. }
  4497. if (empty($result)) {
  4498. return Result::error("修改失败", 0);
  4499. }
  4500. return Result::success($result);
  4501. }
  4502. /*
  4503. * 获取省-市
  4504. * */
  4505. public function getJobRecruitingArea(array $data): array
  4506. {
  4507. if (isset($data['pid']) && $data['pid'] != null) {
  4508. $result = District::where('pid', $data['pid'])->get()->all();
  4509. } else {
  4510. $result = District::where('level', 1)->get()->all();
  4511. }
  4512. if (empty($result)) {
  4513. return Result::error("暂无此省市", 0);
  4514. }
  4515. return Result::success($result);
  4516. }
  4517. /*
  4518. * 获取行业分类
  4519. * */
  4520. public function getIndustry(array $data): array
  4521. {
  4522. $result = JobIndustry::get()->all();
  4523. if (empty($result)) {
  4524. return Result::error("暂无行业分类", 0);
  4525. }
  4526. return Result::success($result);
  4527. }
  4528. /*
  4529. * 获取职位
  4530. * */
  4531. public function getPositionList(array $data): array
  4532. {
  4533. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4534. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4535. } else {
  4536. $result = JobPosition::where('zwpid', 0)->get()->all();
  4537. }
  4538. if (empty($result)) {
  4539. return Result::error("暂无此职位", 0);
  4540. }
  4541. return Result::success($result);
  4542. }
  4543. /*
  4544. * 获取工作性质-菜单
  4545. * */
  4546. public function getJobNature(array $data): array
  4547. {
  4548. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4549. if (empty($result)) {
  4550. return Result::error("暂无工作性质", 0);
  4551. }
  4552. return Result::success($result);
  4553. }
  4554. /*
  4555. * 获取工作经验-菜单
  4556. * */
  4557. public function getExperience(array $data): array
  4558. {
  4559. $result = JobEnum::where('egroup', 'years')->get()->all();
  4560. if (empty($result)) {
  4561. return Result::error("暂无工作经验", 0);
  4562. }
  4563. return Result::success($result);
  4564. }
  4565. /*
  4566. * 获取学历-菜单
  4567. * */
  4568. public function getEducation(array $data): array
  4569. {
  4570. $result = JobEnum::where('egroup', 'education')->get()->all();
  4571. if (empty($result)) {
  4572. return Result::error("暂无学历", 0);
  4573. }
  4574. return Result::success($result);
  4575. }
  4576. /*
  4577. * 获取薪资-菜单
  4578. * */
  4579. public function getSalary(array $data): array
  4580. {
  4581. $result = JobEnum::where('egroup', 'income')->get()->all();
  4582. if (empty($result)) {
  4583. return Result::error("暂无薪资", 0);
  4584. }
  4585. return Result::success($result);
  4586. }
  4587. /*
  4588. * 获取语言-菜单
  4589. * */
  4590. public function getLanguage(array $data): array
  4591. {
  4592. $result = JobEnum::where('egroup', 'language')->get()->all();
  4593. if (empty($result)) {
  4594. return Result::error("暂无语言", 0);
  4595. }
  4596. return Result::success($result);
  4597. }
  4598. /*
  4599. * 获取掌握程度-菜单
  4600. * */
  4601. public function getLevel(array $data): array
  4602. {
  4603. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4604. if (empty($result)) {
  4605. return Result::error("暂无工作性质", 0);
  4606. }
  4607. return Result::success($result);
  4608. }
  4609. // 公司信息
  4610. /*
  4611. * 获取公司性质-菜单
  4612. * */
  4613. public function getCompanyNature(array $data): array
  4614. {
  4615. $result = JobNature::get()->all();
  4616. if (empty($result)) {
  4617. return Result::error("暂无公司性质", 0);
  4618. }
  4619. return Result::success($result);
  4620. }
  4621. /*
  4622. * 获取公司规模-菜单
  4623. * */
  4624. public function getCompanySize(array $data): array
  4625. {
  4626. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4627. if (empty($result)) {
  4628. return Result::error("暂无公司规模", 0);
  4629. }
  4630. return Result::success($result);
  4631. }
  4632. /*
  4633. * 招聘信息审核
  4634. * */
  4635. public function checkJobRecruiting(array $data): array
  4636. {
  4637. $user = User::where('id', $data['user_id'])->first();
  4638. if (empty($user)) {
  4639. return Result::error("用户不存在", 0);
  4640. }
  4641. $job = JobRecruiting::where('id', $data['id'])->first();
  4642. if (empty($job)) {
  4643. return Result::error("招聘信息不存在", 0);
  4644. }
  4645. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4646. if ($user['type_id'] != 10000) {
  4647. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4648. }
  4649. // 驳回原因
  4650. if ($data['status'] == 2) {
  4651. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4652. }
  4653. $data['action_id'] = $data['user_id'];
  4654. unset($data['user_id']);
  4655. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4656. if (empty($result)) {
  4657. return Result::error("审核失败", 0);
  4658. }
  4659. return Result::success($result);
  4660. }
  4661. public function myApplyList(array $data): array
  4662. {
  4663. $user = User::where('id', $data['user_id'])->first();
  4664. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4665. return Result::error("用户不存在", 0);
  4666. }
  4667. // 1:个人会员 职场机会
  4668. if ($user['type_id'] == 1) {
  4669. $where['user_id'] = $user['id'];
  4670. }
  4671. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4672. $query->where('recruit_id', $user['id']);
  4673. })
  4674. ->pluck('recruit_id');
  4675. $where = [];
  4676. if (isset($data['salary']) && $data['salary'] != null) {
  4677. $where['job_recruiting.salary'] = $data['salary'];
  4678. }
  4679. if (isset($data['experience']) && $data['experience'] != null) {
  4680. $where['job_recruiting.experience'] = $data['experience'];
  4681. }
  4682. if (isset($data['business_name']) && $data['business_name'] != null) {
  4683. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4684. }
  4685. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4686. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4687. ->where($where);
  4688. // ->count();
  4689. $count = $query->count();
  4690. $query = clone $query;
  4691. $job = $query
  4692. ->leftJoin('job_enum as income_enum', function ($join) {
  4693. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4694. ->where('income_enum.egroup', 'income');
  4695. })
  4696. ->leftJoin('job_enum as years_enum', function ($join) {
  4697. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4698. ->where('years_enum.egroup', 'years');
  4699. })
  4700. // ->where($where)
  4701. ->orderBy('job_recruiting.updated_at', 'desc')
  4702. ->select(
  4703. 'job_recruiting.id',
  4704. 'job_recruiting.title',
  4705. 'job_company.business_name',
  4706. 'income_enum.evalue as salary_evalue',
  4707. 'income_enum.ename as salary_ename',
  4708. 'years_enum.evalue as experience_evalue',
  4709. 'years_enum.ename as experience_ename',
  4710. 'job_recruiting.updated_at'
  4711. )
  4712. ->offset(($data['page'] - 1) * $data['pageSize'])
  4713. ->limit($data['pageSize'])
  4714. ->get()
  4715. ->all();
  4716. if (empty($job)) {
  4717. return Result::error("暂无招聘信息", 0);
  4718. }
  4719. $result = [
  4720. 'row' => $job,
  4721. 'count' => $count,
  4722. ];
  4723. return Result::success($result);
  4724. }
  4725. /*
  4726. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4727. * */
  4728. public function getRecruitingList(array $data): array
  4729. {
  4730. $user = User::where('id', $data['user_id'])->first();
  4731. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4732. return Result::error("用户不存在", 0);
  4733. }
  4734. // 1:个人会员 职场机会
  4735. if ($user['type_id'] == 1) {
  4736. $where['user_id'] = $user['id'];
  4737. }
  4738. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4739. $query->where('recruit_id', $user['id']);
  4740. })
  4741. ->pluck('recruit_id');
  4742. $where = [];
  4743. if (isset($data['salary']) && $data['salary'] != null) {
  4744. $where['job_recruiting.salary'] = $data['salary'];
  4745. }
  4746. if (isset($data['experience']) && $data['experience'] != null) {
  4747. $where['job_recruiting.experience'] = $data['experience'];
  4748. }
  4749. if (isset($data['business_name']) && $data['business_name'] != null) {
  4750. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4751. }
  4752. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4753. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4754. ->where($where);
  4755. // ->count();
  4756. $count = $query->count();
  4757. $query = clone $query;
  4758. $job = $query
  4759. ->leftJoin('job_enum as income_enum', function ($join) {
  4760. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4761. ->where('income_enum.egroup', 'income');
  4762. })
  4763. ->leftJoin('job_enum as years_enum', function ($join) {
  4764. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4765. ->where('years_enum.egroup', 'years');
  4766. })
  4767. // ->where($where)
  4768. ->orderBy('job_recruiting.updated_at', 'desc')
  4769. ->select(
  4770. 'job_recruiting.id',
  4771. 'job_recruiting.title',
  4772. 'job_company.business_name',
  4773. 'income_enum.evalue as salary_evalue',
  4774. 'income_enum.ename as salary_ename',
  4775. 'years_enum.evalue as experience_evalue',
  4776. 'years_enum.ename as experience_ename',
  4777. 'job_recruiting.updated_at'
  4778. )
  4779. ->offset(($data['page'] - 1) * $data['pageSize'])
  4780. ->limit($data['pageSize'])
  4781. ->get()
  4782. ->all();
  4783. if (empty($job)) {
  4784. return Result::error("暂无招聘信息", 0);
  4785. }
  4786. $result = [
  4787. 'row' => $job,
  4788. 'count' => $count,
  4789. ];
  4790. return Result::success($result);
  4791. }
  4792. /*
  4793. * 获取企业会员-招聘信息列表
  4794. * */
  4795. public function getRecruitingInfo(array $data): array
  4796. {
  4797. $user = User::where('id', $data['user_id'])->first();
  4798. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4799. return Result::error("用户不存在", 0);
  4800. }
  4801. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4802. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4803. ->select(
  4804. 'job_recruiting.*',
  4805. 'job_company.business_name',
  4806. 'job_company.company_hy_id',
  4807. 'job_company.company_size',
  4808. 'job_company.company_nature',
  4809. 'job_company.introduction',
  4810. 'job_company.real_name',
  4811. 'job_company.mobile',
  4812. 'job_company.company_url',
  4813. 'job_company.address_arr_id',
  4814. 'job_company.address',
  4815. 'job_company.email'
  4816. )
  4817. ->get();
  4818. if (empty($recruiting)) {
  4819. return Result::error("暂无招聘信息", 0);
  4820. }
  4821. return Result::success($recruiting);
  4822. }
  4823. /*
  4824. * 获取企业会员-我的沟通
  4825. * */
  4826. public function getJobResumeList(array $data): array
  4827. {
  4828. $user = User::where('id', $data['user_id'])->first();
  4829. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4830. return Result::error("用户不存在", 0);
  4831. }
  4832. $where = [];
  4833. if (isset($data['salary']) && $data['salary'] != null) {
  4834. $where['job_hunting.salary'] = $data['salary'];
  4835. }
  4836. if (isset($data['user_name']) && $data['user_name'] != null) {
  4837. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4838. }
  4839. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4840. $query->where('job_resume.user_id', $user['id']);
  4841. })
  4842. ->when(!empty($where), function ($query) use ($where) {
  4843. $query->where($where);
  4844. })
  4845. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  4846. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  4847. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  4848. ->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');
  4849. $count = $job->count();
  4850. if ($count == 0) {
  4851. return Result::error("暂无沟通记录", 0);
  4852. }
  4853. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  4854. ->offset(($data['page'] - 1) * $data['pageSize'])
  4855. ->limit($data['pageSize'])
  4856. ->get();
  4857. if (empty($jobs)) {
  4858. return Result::error("暂无沟通记录", 0);
  4859. }
  4860. $result['row'] = $this->processJob($jobs, '');
  4861. $result['count'] = $count;
  4862. return Result::success($result);
  4863. }
  4864. // 20250306 招聘
  4865. //20250422 书刊音像
  4866. public function addBook(array $data): array
  4867. {
  4868. // $user_id = $data['user_id'] ?? 0;
  4869. $type_id = $data['type_id'] ?? 0;
  4870. // $website_id = $data['website_id'] ?? 0;
  4871. // unset($data['user_id']);
  4872. unset($data['type_id']);
  4873. // unset($data['website_id']);
  4874. //处理数组
  4875. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4876. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4877. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4878. if ($data['img_url'] == '') {
  4879. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4880. preg_match_all($reg, $data['detail'], $matches);
  4881. if (isset($matches[1][0])) {
  4882. //截取varchar240
  4883. $data['img_url'] = substr($matches[1][0], 0, 240);
  4884. }
  4885. }
  4886. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4887. //提取标题+内容中的关键词
  4888. $data['keyword'] = $data['title'];
  4889. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4890. Jieba::init(); // 初始化 jieba-php
  4891. Finalseg::init();
  4892. $segList = Jieba::cut($data['keyword']);
  4893. $segList1 = array_slice($segList, 0, 8);
  4894. $data['keyword'] = implode(',', $segList1);
  4895. }
  4896. if ($data['description'] == '') {
  4897. //提取内容中的描述
  4898. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4899. }
  4900. var_dump($data, '--');
  4901. $result = Book::insertGetId($data);
  4902. if (empty($result)) {
  4903. return Result::error("添加失败", 0);
  4904. }
  4905. return Result::success($result);
  4906. }
  4907. public function getBookList(array $data): array
  4908. {
  4909. $where = [];
  4910. if (!empty($data["title"])) {
  4911. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  4912. }
  4913. if (!empty($data['website_name'])) {
  4914. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4915. }
  4916. if (!empty($data['status'])) {
  4917. $where[] = ['book.status', '=', $data['status']];
  4918. }
  4919. $user_id = $data['user_id'];
  4920. $type_id = $data['type_id'];
  4921. // $type_id = 4;
  4922. var_dump($type_id, '------1--------');
  4923. if ($type_id != 10000) {
  4924. $where[] = ['book.user_id', '=', $user_id];
  4925. }
  4926. var_dump(!empty($data['status1']), '=-===1');
  4927. $result = Book::where($where)
  4928. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  4929. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  4930. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  4931. ->when(isset($data['status1']), function ($query) use ($data) {
  4932. $query->whereIn('book.status', [1, 3]);
  4933. })
  4934. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  4935. ->orderBy("updated_at", "desc")
  4936. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4937. if (empty($result)) {
  4938. return Result::error("暂无数据", 0);
  4939. }
  4940. // 取出数据
  4941. $rows = $result->items();
  4942. $count = $result->total();
  4943. $responseData = [
  4944. 'rows' => $rows,
  4945. 'count' => $count,
  4946. ];
  4947. return Result::success($responseData);
  4948. }
  4949. public function deleteBook(array $data): array
  4950. {
  4951. $result = Book::where('id', $data['id'])->delete();
  4952. if (empty($result)) {
  4953. return Result::error("删除失败", 0);
  4954. }
  4955. return Result::success($result);
  4956. }
  4957. public function updateBook(array $data): array
  4958. {
  4959. // $user_id = $data['user_id'] ?? 0;
  4960. $type_id = $data['type_id'] ?? 0;
  4961. // $website_id = $data['website_id'] ?? 0;
  4962. unset($data['user_id']);
  4963. unset($data['type_id']);
  4964. // unset($data['website_id']);
  4965. //处理数组
  4966. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4967. if ($data['img_url'] == '') {
  4968. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4969. preg_match_all($reg, $data['detail'], $matches);
  4970. if (isset($matches[1][0])) {
  4971. //截取varchar240
  4972. $data['img_url'] = substr($matches[1][0], 0, 240);
  4973. }
  4974. }
  4975. if ($data['keyword'] == '') {
  4976. //提取标题+内容中的关键词
  4977. $data['keyword'] = $data['title'];
  4978. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4979. Jieba::init(); // 初始化 jieba-php
  4980. Finalseg::init();
  4981. $segList = Jieba::cut($data['keyword']);
  4982. $segList1 = array_slice($segList, 0, 8);
  4983. $data['keyword'] = implode(',', $segList1);
  4984. }
  4985. if ($data['description'] == '') {
  4986. //提取内容中的描述
  4987. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4988. }
  4989. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4990. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4991. $result = Book::where("id", $data["id"])->update($data);
  4992. if (empty($result)) {
  4993. return Result::error("更新失败", 0);
  4994. }
  4995. return Result::success($result);
  4996. }
  4997. public function getBookInfo(array $data): array
  4998. {
  4999. $result = Book::where("id", $data["id"])->first();
  5000. if (empty($result)) {
  5001. return Result::error("获取失败", 0);
  5002. }
  5003. return Result::success($result);
  5004. }
  5005. public function updateBookStatus(array $data): array
  5006. {
  5007. //审核
  5008. unset($data['user_id']);
  5009. $result = Book::where("id", $data["id"])->update($data);
  5010. if (empty($result)) {
  5011. return Result::error("更新失败", 0);
  5012. }
  5013. return Result::success($result);
  5014. }
  5015. //20250422 书刊音像
  5016. }