NewsService.php 219 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121
  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. if ($category) {
  716. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  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. ->map(function ($article) use ($data) {
  748. $catid = $article->catid;
  749. $pinyin = '';
  750. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  751. if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
  752. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  753. if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
  754. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  755. }
  756. } else {
  757. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  758. }
  759. $article->pinyin = $pinyin;
  760. return $article;
  761. });
  762. if (empty($result)) {
  763. return Result::success();
  764. }
  765. return Result::success($result);
  766. } else {
  767. return Result::error("参数错误level=7,id不能为空", 0);
  768. }
  769. }
  770. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  771. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  772. var_dump($where, 'where-----------------');
  773. // 初始化基础查询
  774. $query = Article::where($where)
  775. ->whereIn("catid", $category)
  776. ->where(function ($query) use ($data) {
  777. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  778. ->orWhereNull("ignore_ids");
  779. });
  780. // 处理 level 相关查询条件
  781. $query->when($data['level'] == 5, function ($query) {
  782. $query->inRandomOrder()
  783. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  784. })->when($data['level'] == 4, function ($query) {
  785. $query->orderBy("article.updated_at", "desc");
  786. })->when(!empty($data['level']), function ($query) use ($data) {
  787. if ($data['level'] != 4 && $data['level'] != 5) {
  788. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  789. ->orderBy("article.updated_at", "desc");
  790. }
  791. });
  792. // 初始化结果数组
  793. $result = [];
  794. // $input = $data['website_id'];
  795. // 处理图片新闻查询
  796. if (!empty($data['imgnum'])) {
  797. // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
  798. // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
  799. $imgQuery = clone $query;
  800. if ($imgQuery->getBindings() === null) {
  801. $imgQuery->setBindings([]);
  802. }
  803. $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
  804. ->select(
  805. 'article.id',
  806. 'article.title',
  807. 'article.imgurl',
  808. 'article.author',
  809. 'article.updated_at',
  810. 'article.introduce',
  811. 'article.islink',
  812. 'article.linkurl',
  813. 'article.copyfrom',
  814. 'article.catid'
  815. )
  816. ->offset($data['placeid'])
  817. ->limit($data['imgnum'])
  818. ->get()
  819. ->map(function ($article) use ($data) {
  820. $catid = $article->catid;
  821. $pinyin = '';
  822. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  823. if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
  824. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  825. if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
  826. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  827. }
  828. } else {
  829. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  830. }
  831. $article->pinyin = $pinyin;
  832. return $article;
  833. });
  834. // $result['img'] = $this->processArticles($img_article, $input);
  835. }
  836. // 处理文字新闻查询
  837. if (!empty($data['textnum'])) {
  838. $textQuery = clone $query;
  839. $result['text'] = $textQuery
  840. ->select(
  841. 'article.id',
  842. 'article.title',
  843. 'article.imgurl',
  844. 'article.author',
  845. 'article.updated_at',
  846. 'article.introduce',
  847. 'article.islink',
  848. 'article.linkurl',
  849. 'article.copyfrom',
  850. 'article.catid'
  851. )
  852. ->offset($data['placeid'])
  853. ->limit($data['textnum'])
  854. ->get()
  855. ->map(function ($article) use ($data) {
  856. $catid = $article->catid;
  857. $pinyin = '';
  858. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  859. if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
  860. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  861. if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
  862. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  863. }
  864. } else {
  865. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  866. }
  867. $article->pinyin = $pinyin;
  868. return $article;
  869. });
  870. // $result['text'] = $this->processArticles($text_article, $input);
  871. }
  872. if (empty($result) || count($result) == 0) {
  873. return Result::error("暂无头条新闻");
  874. }
  875. return Result::success($result);
  876. } else {
  877. return Result::error("本网站下暂无相关栏目", 0);
  878. }
  879. }
  880. /**
  881. * 获取模块新闻
  882. * @param array $data
  883. * @return array
  884. */
  885. public function getWebsiteModelArticles(array $data): array
  886. {
  887. $catid = $data['catid'];
  888. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  889. $category = $category->toArray();
  890. if (!empty($category)) {
  891. $where = [
  892. 'status' => 1,
  893. 'catid' => $catid,
  894. ];
  895. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  896. // 1:文字新闻;2:轮播图;3:图文;
  897. // 级别:0:未分类
  898. // 3:推荐图片
  899. if ($data['level'] == 1) {
  900. $data['level'] = 0;
  901. }
  902. $result = Article::where($where)
  903. ->where(function ($query) use ($data) {
  904. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  905. ->orWhereNull("level")
  906. ->orWhereRaw("level = '[]'");
  907. })
  908. ->where(function ($query) use ($data) {
  909. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  910. ->orWhereNull("ignore_ids");
  911. })
  912. ->orderBy("updated_at", "desc")
  913. ->offset($placeid)
  914. ->limit($data['pagesize'])
  915. ->get();
  916. if (empty($result)) {
  917. return Result::error("此栏目暂无相关新闻", 0);
  918. }
  919. } else {
  920. return Result::error("此网站暂无此栏目", 0);
  921. }
  922. return Result::success($result);
  923. }
  924. /**
  925. *获取新闻列表
  926. * @param array $data
  927. * @return array
  928. */
  929. public function getWebsiteArticleList(array $data): array
  930. {
  931. // return Result::success($data);
  932. $where[] = ['status', '=', 1];
  933. if (isset($data['catid']) && !empty($data['catid'])) {
  934. if (is_array($data['catid'])) {
  935. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  936. array_push($where, ['catid', 'in', $data['catid']]);
  937. } else {
  938. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  939. array_push($where, ['catid', '=', $data['catid']]);
  940. }
  941. if (empty($category)) {
  942. return Result::error("此网站暂无此栏目", 0);
  943. }
  944. }
  945. // return Result::success($where);
  946. $rep = Article::where(function ($query) use ($where) {
  947. foreach ($where as $condition) {
  948. if ($condition[1] === 'in') {
  949. $query->whereIn($condition[0], $condition[2]);
  950. } else {
  951. $query->where($condition[0], $condition[1], $condition[2]);
  952. }
  953. }
  954. })
  955. ->where(function ($query) use ($data) {
  956. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  957. ->orWhereNull("ignore_ids");
  958. })
  959. ->select(
  960. 'article.id',
  961. 'article.title',
  962. 'article.imgurl',
  963. 'article.author',
  964. 'article.updated_at',
  965. 'article.introduce',
  966. 'article.islink',
  967. 'article.linkurl',
  968. 'article.copyfrom',
  969. 'article.catid'
  970. )
  971. ->orderBy("updated_at", "desc")
  972. ->offset(($data['page'] - 1) * $data['pageSize'])
  973. ->limit($data['pageSize'])
  974. ->get()
  975. ->map(function ($article) use ($data) {
  976. $catid = $article->catid ?? 0;
  977. $pinyin = '';
  978. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  979. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  980. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  981. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  982. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  983. }
  984. $article->pinyin = $pinyin;
  985. return $article;
  986. });
  987. $count = Article::where(function ($query) use ($where) {
  988. foreach ($where as $condition) {
  989. if ($condition[1] === 'in') {
  990. $query->whereIn($condition[0], $condition[2]);
  991. } else {
  992. $query->where($condition[0], $condition[1], $condition[2]);
  993. }
  994. }
  995. })->count();
  996. $data = [
  997. 'rows' => $rep->toArray(),
  998. 'count' => $count,
  999. ];
  1000. if (empty($rep)) {
  1001. return Result::error("没有信息数据");
  1002. }
  1003. return Result::success($data);
  1004. }
  1005. /**
  1006. * 前端-获取新闻详情
  1007. * @param array $data
  1008. * @return array
  1009. */
  1010. public function selectWebsiteArticleInfo(array $data): array
  1011. {
  1012. $where = [
  1013. 'article.id' => $data['id'],
  1014. 'article.status' => 1,
  1015. ];
  1016. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  1017. ->where(function ($query) use ($data) {
  1018. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1019. ->orWhereNull("ignore_ids");
  1020. })
  1021. ->first();
  1022. if (empty($result)) {
  1023. return Result::error("暂无此新闻!", 0);
  1024. }
  1025. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1026. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1027. ->where('website_category.website_id', $data['website_id'])
  1028. ->where(['website_category.category_id' => $result['catid']])
  1029. ->first();
  1030. if (empty($category)) {
  1031. return Result::error("查询失败", 0);
  1032. }
  1033. //手动推荐文章
  1034. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1035. $commendArticle = Article::whereIn('id', $commend_ids)
  1036. ->where('status', 1)
  1037. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  1038. ->orderBy('updated_at', 'desc')
  1039. ->limit(5)
  1040. ->get();
  1041. $result['category_id'] = $category['category_id'];
  1042. $result['cat_name'] = $category['alias'];
  1043. $result['website_name'] = $category['website_name'] ?? "";
  1044. $result['suffix'] = $category['suffix'] ?? "";
  1045. $result['commendArticle'] = $commendArticle;
  1046. return Result::success($result);
  1047. }
  1048. /**
  1049. * 前端-获取网站调查问卷
  1050. * @param array $data
  1051. * @return array
  1052. */
  1053. public function getWebsiteSurvey(array $data): array
  1054. {
  1055. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1056. $website = Website::where('id', $data['website_id'])->first();
  1057. if (empty($website)) {
  1058. return Result::error("暂无此网站", 0);
  1059. }
  1060. }
  1061. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1062. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1063. if (empty($article)) {
  1064. return Result::error("暂无此文章", 0);
  1065. }
  1066. // return Result::error($data,0);
  1067. $where['art_id'] = $data['art_id'];
  1068. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1069. } else {
  1070. $survey = Article::where(function ($query) {
  1071. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1072. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1073. })
  1074. ->where('status', 1)
  1075. ->where('is_survey', 1)
  1076. ->select('survey_id')
  1077. ->orderBy('updated_at', 'desc')
  1078. ->first();
  1079. if (empty($survey)) {
  1080. return Result::error("暂无调查问卷", 0);
  1081. }
  1082. $where['sur_id'] = $survey['survey_id'];
  1083. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1084. }
  1085. // return Result::success($where);
  1086. $result = ArticleSurvey::where($where)
  1087. ->where(function ($query) {
  1088. $query->where('is_other', 0)
  1089. ->orWhere(function ($subQuery) {
  1090. $subQuery->where('is_other', 1)
  1091. ->where('other_id', 0);
  1092. });
  1093. })
  1094. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1095. ->select('article_survey.*', 'article.survey_type')
  1096. ->get()->all();
  1097. if (empty($result)) {
  1098. return Result::error("此文章暂无调查问卷", 0);
  1099. }
  1100. return Result::success($result);
  1101. }
  1102. /**
  1103. * 前端-添加网站调查问卷选项
  1104. * @param array $data
  1105. * @return array
  1106. */
  1107. public function addWebsiteSurveyOption(array $data): array
  1108. {
  1109. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1110. $website = Website::where('id', $data['website_id'])->first();
  1111. if (empty($website)) {
  1112. return Result::error("暂无此网站", 0);
  1113. }
  1114. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1115. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1116. if (empty($survey)) {
  1117. return Result::error("此调查问卷不可添加选项", 0);
  1118. }
  1119. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1120. $choice = [
  1121. 'art_id' => $survey['art_id'],
  1122. 'website_id' => $data['website_id'],
  1123. 'survey_name' => $survey['survey_name'],
  1124. 'choice_name' => $data['choice_name'],
  1125. 'sur_id' => $survey['sur_id'],
  1126. 'is_other' => 1,
  1127. 'other_id' => $survey['id'],
  1128. ];
  1129. $result = ArticleSurvey::insertGetId($choice);
  1130. if (empty($result)) {
  1131. return Result::error("添加失败", 0);
  1132. }
  1133. return Result::success($result);
  1134. }
  1135. }
  1136. return Result::error("添加失败", 0);
  1137. }
  1138. return Result::error("添加失败", 0);
  1139. }
  1140. /**
  1141. * 前端-调查问卷投票
  1142. * @param array $data
  1143. * @return array
  1144. */
  1145. public function addWebsiteSurveyVote(array $data): array
  1146. {
  1147. // return Result::success($data);
  1148. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1149. $website = Website::where('id', $data['website_id'])->first();
  1150. if (empty($website)) {
  1151. return Result::error("暂无此网站", 0);
  1152. }
  1153. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1154. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1155. // return Result::success($survey);
  1156. if (empty($is_survey)) {
  1157. return Result::error("此调查问卷不存在", 0);
  1158. }
  1159. // return Result::success($survey);
  1160. // 调查问卷类型
  1161. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1162. //多选 若是json型则转化成数组类型
  1163. if (strpos($data['choice_id'], '[') === 0) {
  1164. $data['choice_id'] = json_decode($data['choice_id'], true);
  1165. } else {
  1166. // 单选 也转换成数组
  1167. $data['choice_id'] = [$data['choice_id']];
  1168. }
  1169. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1170. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1171. // ->where('website_id',$data['website_id'])
  1172. ->where('is_other', 1)
  1173. ->where('other_id', 0)
  1174. ->first();
  1175. if (!empty($other)) {
  1176. return Result::error("请选择已有的选项!", 0);
  1177. }
  1178. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1179. // ->where('website_id',$data['website_id'])
  1180. ->where('is_other', 1)
  1181. ->where('other_id', '!=', 0)
  1182. ->first();
  1183. // return Result::success($choice['other']);
  1184. $choice_id = $data['choice_id'];
  1185. if (!empty($choice['other'])) {
  1186. // array_push($data['choice_id'],$choice['other']['other_id']);
  1187. if (!empty($choice_id)) {
  1188. $key = array_search($choice['other']['id'], $choice_id);
  1189. if ($key !== false) {
  1190. unset($choice_id[$key]);
  1191. $choice_id = array_values($choice_id);
  1192. }
  1193. array_push($choice_id, $choice['other']['other_id']);
  1194. } else {
  1195. $choice_id[0] = $choice['other']['other_id'];
  1196. }
  1197. array_push($data['choice_id'], $choice['other']['other_id']);
  1198. }
  1199. // return Result::success($data);
  1200. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1201. // ->where('website_id',$data['website_id'])
  1202. ->increment('results', 1);
  1203. if (empty($choice)) {
  1204. return Result::error("请选择已有的选项!", 0);
  1205. }
  1206. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1207. // ->where('website_id',$data['website_id'])
  1208. ->where('other_id', 0)
  1209. ->get();
  1210. $survey['choice'] = $choice_id;
  1211. return Result::success($survey);
  1212. }
  1213. return Result::error("参数必填!");
  1214. }
  1215. return Result::error("此调查问卷不存在", 0);
  1216. }
  1217. return Result::error("参数必填!");
  1218. }
  1219. /**
  1220. * 后端-获取网站调查问卷列表
  1221. * @param array $data
  1222. * @return array
  1223. */
  1224. public function getSurveyList(array $data): array
  1225. {
  1226. $where = [];
  1227. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1228. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1229. }
  1230. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1231. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1232. }
  1233. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1234. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1235. }
  1236. // return Result::success($where);
  1237. if (!empty($where)) {
  1238. $query = Article::where($where)->where(function ($q) {
  1239. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1240. });
  1241. } else {
  1242. $query = Article::where(function ($q) {
  1243. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1244. });
  1245. }
  1246. $count = $query->count();
  1247. $survey = $query->orderByDesc('id')
  1248. ->limit($data['pageSize'])
  1249. ->offset(($data['page'] - 1) * $data['pageSize'])
  1250. ->get();
  1251. if (empty($survey->toArray())) {
  1252. return Result::error("暂无调查问卷!", 0);
  1253. }
  1254. $result = [
  1255. 'rows' => $survey,
  1256. 'count' => $count,
  1257. ];
  1258. return Result::success($result);
  1259. }
  1260. /**
  1261. * 后端-获取网站调查问卷详情
  1262. * @param array $data
  1263. * @return array
  1264. */
  1265. public function getSurveyInfo(array $data): array
  1266. {
  1267. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1268. $where = ['sur_id' => $data['sur_id']];
  1269. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1270. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1271. ->select('article_survey.*', 'article.survey_type')
  1272. ->get()->all();
  1273. if (empty($choose)) {
  1274. return Result::error("此调查问卷不存在", 0);
  1275. }
  1276. $resultsArray = array_column($choose, 'results');
  1277. $total = array_sum($resultsArray);
  1278. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1279. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1280. // $total = 0;
  1281. if (!empty($other)) {
  1282. $total = $total + $other['results'];
  1283. $other['choice_name'] = '(其他)';
  1284. if (!empty($others)) {
  1285. $other['hasChildren'] = true;
  1286. // array_push($other,['hasChildren','=',true]);
  1287. $other['children'] = $others;
  1288. $other_choices = [$other->toArray()];
  1289. $mer_choice = array_merge($choose, $other_choices);
  1290. $value_choice = array_values($mer_choice);
  1291. } else {
  1292. // return Result::error('1111');
  1293. $other_choices = [$other->toArray()];
  1294. $other_choices = array_merge($choose, $other_choices);
  1295. $value_choice = array_values($other_choices);
  1296. // return Result::success($result);
  1297. }
  1298. } else {
  1299. $value_choice = $choose;
  1300. }
  1301. $result = [
  1302. 'choose' => $value_choice,
  1303. 'total' => $total,
  1304. ];
  1305. }
  1306. return Result::success($result);
  1307. }
  1308. /**
  1309. * 前端-搜索新闻列表
  1310. * @param array $data
  1311. * @return array
  1312. */
  1313. public function selectWebsiteArticle(array $data): array
  1314. {
  1315. $where = [];
  1316. // 初始化查询构造器
  1317. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1318. $query = Article::where('status', 1)
  1319. ->whereIn('catid', $category)
  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. // return Result::success($all_articles);
  1326. // 检查是否存在 cityid 参数
  1327. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1328. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1329. }
  1330. // 检查是否存在 department_id 参数
  1331. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1332. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1333. }
  1334. // 检查是否存在 keyword 参数
  1335. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1336. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1337. }
  1338. // 计算总数
  1339. $count = $query->count();
  1340. // 分页查询
  1341. $articles = $query
  1342. ->select(
  1343. 'article.id',
  1344. 'article.title',
  1345. 'article.imgurl',
  1346. 'article.author',
  1347. 'article.updated_at',
  1348. 'article.introduce',
  1349. 'article.islink',
  1350. 'article.linkurl',
  1351. 'article.copyfrom',
  1352. 'article.catid',
  1353. 'article.department_arr_id',
  1354. 'article.city_arr_id',
  1355. )
  1356. ->orderBy("updated_at", "desc")
  1357. ->offset(($data['page'] - 1) * $data['pageSize'])
  1358. ->limit($data['pageSize'])
  1359. ->get()
  1360. ->map(function ($article) use ($data) {
  1361. $catid = $article->catid ?? 0;
  1362. $pinyin = '';
  1363. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  1364. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1365. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  1366. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  1367. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  1368. }
  1369. $article->pinyin = $pinyin;
  1370. return $article;
  1371. });
  1372. if (empty($articles)) {
  1373. return Result::error("没有符合条件的资讯数据");
  1374. }
  1375. $data = [
  1376. 'rows' => $articles,
  1377. 'count' => $count,
  1378. ];
  1379. return Result::success($data);
  1380. }
  1381. /**
  1382. * 模块新闻加强版
  1383. * @param array $data
  1384. * @return array
  1385. */
  1386. public function getWebsiteCatidArticle(array $data): array
  1387. {
  1388. $where = [
  1389. 'website_category.category_id' => $data['catid'],
  1390. 'website_category.website_id' => $data['website_id'],
  1391. ];
  1392. // $category = WebsiteCategory::where($where);
  1393. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1394. $child_catnum = $data['child_catnum'] ?? 1;
  1395. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1396. $childCategoryIds = array_column($category['child'], 'category_id');
  1397. if (empty($childCategoryIds)) {
  1398. return Result::error("暂无子栏目", 0);
  1399. }
  1400. $imgArticles = [];
  1401. $textArticles = [];
  1402. // return Result::success($childCategoryIds);
  1403. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1404. // 初始化子分类图片新闻和文字新闻数组
  1405. // 查询所有子级栏目的图文新闻
  1406. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1407. ->where(function ($query) use ($data) {
  1408. $query->where(function ($subQuery) use ($data) {
  1409. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1410. })->orWhereNull("ignore_ids");
  1411. })
  1412. ->where('status', 1)
  1413. ->where('imgurl', '!=', '')
  1414. ->select('*')
  1415. ->orderBy('updated_at', 'desc')
  1416. ->limit($data['child_imgnum'])
  1417. ->get();
  1418. }
  1419. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1420. // 查询所有子级栏目的文字新闻
  1421. $textArticles = Article::where('catid', $childCategoryIds[0])
  1422. ->where('status', 1)
  1423. ->where(function ($query) use ($data) {
  1424. $query->where(function ($subQuery) use ($data) {
  1425. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1426. })->orWhereNull("ignore_ids");
  1427. })
  1428. ->select('*')
  1429. ->orderBy('updated_at', 'desc')
  1430. ->limit($data['child_textnum'])
  1431. ->get();
  1432. }
  1433. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1434. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1435. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1436. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1437. return $child;
  1438. }, $category['child']);
  1439. }
  1440. // }
  1441. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1442. $category['img'] = WebsiteCategory::where($where)
  1443. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1444. ->where('article.status', 1)
  1445. ->where('article.imgurl', '!=', '')
  1446. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1447. ->orderBy('article.updated_at', 'desc')
  1448. ->limit($data['img_num'])
  1449. ->get();
  1450. }
  1451. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1452. $category['text'] = WebsiteCategory::where($where)
  1453. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1454. ->where('article.status', 1)
  1455. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1456. ->orderBy('article.updated_at', 'desc')
  1457. ->limit($data['text_num'])
  1458. ->get();
  1459. }
  1460. // $category = $category->get();
  1461. if (empty($category)) {
  1462. return Result::error("查询失败", 0);
  1463. }
  1464. return Result::success($category);
  1465. }
  1466. /**
  1467. * 模块新闻加强plus版
  1468. * @param array $data
  1469. * @return array
  1470. */
  1471. public function getWebsiteAllArticle(array $data): array
  1472. {
  1473. // 修正传入的字符串,将单引号替换为双引号
  1474. $input['id'] = $data['id'];
  1475. $input['website_id'] = $data['website_id'];
  1476. // 将 JSON 字符串转换为 PHP 数组
  1477. $data = json_decode($input['id'], true);
  1478. // 使用 array_map 处理每个元素
  1479. $result = array_map(function ($item) use ($input) {
  1480. // 检查parent元素是否存在且不是undefined
  1481. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  1482. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1483. $website = [
  1484. 'website_id' => $input['website_id'],
  1485. ];
  1486. // 查询栏目名称
  1487. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1488. if (empty($category)) {
  1489. $parent_alias = '';
  1490. $parent_pinyin = null;
  1491. $imgArticles = [];
  1492. $textArticles = [];
  1493. } else {
  1494. $parent_alias = $category->alias ?? '';
  1495. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1496. // 查找子分类ID数组
  1497. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1498. array_push($childCategoryIds, $parentCatId);
  1499. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  1500. if ($parentImgNum != 0) {
  1501. // 查询图片新闻
  1502. $imgArticles = Article::where('article.status', 1)
  1503. ->where(function ($query) use ($parentCatId) {
  1504. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1505. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1506. })
  1507. ->where(function ($query) use ($website) {
  1508. $query->where(function ($subQuery) use ($website) {
  1509. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0")
  1510. ->orWhereNull("ignore_ids");
  1511. });
  1512. })
  1513. ->where('imgurl', '!=', '')
  1514. ->leftJoin('website_category', function ($join) use ($website) {
  1515. $join->on('article.catid', '=', 'website_category.category_id')
  1516. ->where('website_category.website_id', '=', $website['website_id']);
  1517. })
  1518. ->select(
  1519. 'article.id',
  1520. 'article.title',
  1521. 'article.imgurl',
  1522. 'article.author',
  1523. 'article.updated_at',
  1524. 'article.introduce',
  1525. 'article.islink',
  1526. 'article.linkurl',
  1527. 'article.copyfrom',
  1528. 'article.catid',
  1529. 'website_category.alias as category_name',
  1530. DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
  1531. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1532. )
  1533. ->orderBy('updated_at', 'desc')
  1534. ->limit($parentImgNum)
  1535. ->get()->all();
  1536. // 查询文字新闻
  1537. }
  1538. if ($parentTextNum != 0) {
  1539. $textArticles = [];
  1540. $textArticles = Article::where('article.status', 1)
  1541. ->where(function ($query) use ($parentCatId) {
  1542. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1543. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1544. })
  1545. ->where(function ($query) use ($website) {
  1546. $query->where(function ($subQuery) use ($website) {
  1547. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0")
  1548. ->orWhereNull("ignore_ids");
  1549. });
  1550. })
  1551. ->leftJoin('website_category', function ($join) use ($website) {
  1552. $join->on('article.catid', '=', 'website_category.category_id')
  1553. ->where('website_category.website_id', '=', $website['website_id']);
  1554. })
  1555. ->select(
  1556. 'article.id',
  1557. 'article.title',
  1558. 'article.imgurl',
  1559. 'article.author',
  1560. 'article.updated_at',
  1561. 'article.introduce',
  1562. 'article.islink',
  1563. 'article.linkurl',
  1564. 'article.copyfrom',
  1565. 'article.catid',
  1566. 'website_category.alias as category_name',
  1567. DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
  1568. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1569. )
  1570. ->orderBy('updated_at', 'desc')
  1571. ->limit($parentTextNum)
  1572. ->get()->all();
  1573. }
  1574. }
  1575. }
  1576. $resultItem = [
  1577. 'alias' => $parent_alias ?? '',
  1578. 'category_id' => $parentCatId ?? 0,
  1579. 'pinyin' => $parent_pinyin ?? null,
  1580. 'imgnum' => $imgArticles ?? [],
  1581. 'textnum' => $textArticles ?? [],
  1582. ];
  1583. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  1584. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  1585. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1586. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1587. ->get()->all();
  1588. if (!empty($childCategory)) {
  1589. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1590. // 查询子栏目名称
  1591. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1592. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1593. ->first();
  1594. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  1595. $childImgArticles = [];
  1596. $childTextArticles = [];
  1597. $resultItem['child'] = [];
  1598. } else {
  1599. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1600. // 查询子栏目图片新闻
  1601. $childImgArticles = Article::where('catid', $childCatId)
  1602. ->where('status', 1)
  1603. ->where(function ($query) use ($website) {
  1604. $query->where(function ($subQuery) use ($website) {
  1605. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1606. })->orWhereNull("ignore_ids");
  1607. })
  1608. ->select(
  1609. 'article.id',
  1610. 'article.title',
  1611. 'article.imgurl',
  1612. 'article.author',
  1613. 'article.updated_at',
  1614. 'article.introduce',
  1615. 'article.islink',
  1616. 'article.linkurl',
  1617. 'article.copyfrom',
  1618. DB::raw("'$child_pinyin' as pinyin")
  1619. )
  1620. ->where('imgurl', '!=', '')
  1621. ->orderBy('updated_at', 'desc')
  1622. ->limit($childImgNum)
  1623. ->get()->all();
  1624. // 查询子栏目文字新闻
  1625. $childTextArticles = Article::where('catid', $childCatId)
  1626. ->where('status', 1)
  1627. ->where(function ($query) use ($website) {
  1628. $query->where(function ($subQuery) use ($website) {
  1629. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1630. })->orWhereNull("ignore_ids");
  1631. })
  1632. ->select(
  1633. 'article.id',
  1634. 'article.title',
  1635. 'article.author',
  1636. 'article.updated_at',
  1637. 'article.introduce',
  1638. 'article.islink',
  1639. 'article.linkurl',
  1640. 'article.copyfrom',
  1641. DB::raw("'$child_pinyin' as pinyin")
  1642. )
  1643. ->orderBy('updated_at', 'desc')
  1644. ->limit($childTextNum)
  1645. ->get()->all();
  1646. $resultItem['child'] = [
  1647. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1648. 'category_id' => $childCatId,
  1649. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1650. 'all_childcat' => $childCategory,
  1651. 'imgnum' => $childImgArticles,
  1652. 'textnum' => $childTextArticles,
  1653. ];
  1654. }
  1655. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1656. }
  1657. } else {
  1658. $resultItem['child'] = [];
  1659. }
  1660. return $resultItem;
  1661. }, $data);
  1662. return Result::success($result);
  1663. // return Result::success($data);
  1664. }
  1665. /**
  1666. * 乡村网-获取特殊新闻模块
  1667. * @param array $data
  1668. * @return array
  1669. */
  1670. public function getWebsiteArticles(array $data): array
  1671. {
  1672. $input['id'] = $data['id'];
  1673. $input['website_id'] = $data['website_id'];
  1674. $data = json_decode($input['id'], true);
  1675. // 使用 array_map 处理每个元素
  1676. $result = array_map(function ($item) use ($input) {
  1677. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1678. $website = [
  1679. 'website_id' => $input['website_id']
  1680. ];
  1681. // 查询栏目名称
  1682. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1683. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1684. if (empty($category)) {
  1685. $imgArticles = [];
  1686. $textArticles = [];
  1687. // return Result::error("暂无此栏目",0);
  1688. } else {
  1689. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1690. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1691. // return Result::success($website);
  1692. // 查询图片新闻
  1693. // 合并查询条件
  1694. $baseQuery = Article::where(function ($query) use ($website) {
  1695. $query->where(function ($subQuery) use ($website) {
  1696. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1697. })->orWhereNull("ignore_ids");
  1698. })
  1699. ->where('article.status', 1)
  1700. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1701. ->where('website_category.website_id', $website['website_id']);
  1702. // 查询文字新闻
  1703. $textArticles = clone $baseQuery;
  1704. $textArticles = $textArticles->whereIn('catid', $child_category)
  1705. ->select(
  1706. 'article.id',
  1707. 'article.title',
  1708. // 'article.imgurl',
  1709. 'article.author',
  1710. 'article.updated_at',
  1711. 'article.introduce',
  1712. 'article.islink',
  1713. 'article.linkurl',
  1714. 'article.copyfrom',
  1715. 'website_category.category_id',
  1716. 'website_category.alias',
  1717. 'website_category.aLIas_pinyin'
  1718. )
  1719. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1720. ->orderBy('article.updated_at', 'desc')
  1721. ->limit($parentTextNum)
  1722. ->get()
  1723. ->all();
  1724. if (empty($textArticles)) {
  1725. $textArticles = clone $baseQuery;
  1726. $textArticles = $textArticles->where('catid', $parentCatId)
  1727. ->select(
  1728. 'article.id',
  1729. 'article.title',
  1730. // 'article.imgurl',
  1731. 'article.author',
  1732. 'article.updated_at',
  1733. 'article.introduce',
  1734. 'article.islink',
  1735. 'article.linkurl',
  1736. 'article.copyfrom',
  1737. 'website_category.category_id',
  1738. 'website_category.alias',
  1739. 'website_category.aLIas_pinyin'
  1740. )
  1741. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1742. ->orderBy('article.updated_at', 'desc')
  1743. ->limit($parentTextNum)
  1744. ->get()
  1745. ->all();
  1746. }
  1747. // 查询图片新闻
  1748. $imgArticles = clone $baseQuery;
  1749. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1750. ->select(
  1751. 'article.id',
  1752. 'article.title',
  1753. 'article.imgurl',
  1754. 'article.author',
  1755. 'article.updated_at',
  1756. 'article.introduce',
  1757. 'article.islink',
  1758. 'article.linkurl',
  1759. 'article.copyfrom',
  1760. 'website_category.category_id',
  1761. 'website_category.alias',
  1762. 'website_category.aLIas_pinyin'
  1763. )
  1764. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1765. ->orderBy('article.updated_at', 'desc')
  1766. ->limit($parentImgNum)
  1767. ->get()
  1768. ->all();
  1769. if (empty($imgArticles)) {
  1770. $imgArticles = clone $baseQuery;
  1771. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1772. ->select(
  1773. 'article.id',
  1774. 'article.title',
  1775. 'article.imgurl',
  1776. 'article.author',
  1777. 'article.updated_at',
  1778. 'article.introduce',
  1779. 'article.islink',
  1780. 'article.linkurl',
  1781. 'article.copyfrom',
  1782. 'website_category.category_id',
  1783. 'website_category.alias',
  1784. 'website_category.aLIas_pinyin'
  1785. )
  1786. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1787. ->orderBy('article.updated_at', 'desc')
  1788. ->limit($parentImgNum)
  1789. ->get()
  1790. ->all();
  1791. }
  1792. }
  1793. $resultItem = [
  1794. 'alias' => $category ? $category->alias : null,
  1795. 'category_id' => $parentCatId,
  1796. 'pinyin' => $pinyin ? $pinyin : null,
  1797. 'imgnum' => $imgArticles ?? [],
  1798. 'textnum' => $textArticles ?? [],
  1799. ];
  1800. return $resultItem;
  1801. }, $data);
  1802. return Result::success($result);
  1803. }
  1804. // 封装处理商品的路由问题
  1805. function processGoods($goods, $data)
  1806. {
  1807. return $goods->map(function ($good) use ($data) {
  1808. $catid = $good->catid ?? 0;
  1809. // $pinyin = '';
  1810. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1811. if (!empty($category->pid) && $category->pid != 0) {
  1812. $level = json_decode($category->category_arr_id);
  1813. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1814. ->whereIn('category_id', $level)
  1815. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1816. ->get(['aLIas_pinyin'])
  1817. ->pluck('aLIas_pinyin')
  1818. ->implode('/');
  1819. } else {
  1820. $pinyin = $category->aLIas_pinyin ?? '';
  1821. }
  1822. if (isset($good->city_id) && !empty($good->city_id)) {
  1823. $city = District::where('id', $good->city_id)->first(['name']);
  1824. $good->city_name = $city->name ?? '';
  1825. }
  1826. // 解析imgurl JSON并取第一条数据
  1827. $imgUrls = json_decode($good->imgurl, true);
  1828. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1829. $good->pinyin = $pinyin;
  1830. return $good;
  1831. });
  1832. }
  1833. /**
  1834. * 获取商品模块
  1835. * @param array $data
  1836. * @return array
  1837. * */
  1838. public function getWebsiteshop(array $data): array
  1839. {
  1840. $input['id'] = $data['id'];
  1841. $input['website_id'] = $data['website_id'];
  1842. $catid = $data['catid'];
  1843. $data = json_decode($input['id'] ?? '', true) ?? [];
  1844. $result['goods'] = array_map(function ($item) use ($input) {
  1845. // 检查parent元素是否存在且不是undefined
  1846. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1847. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1848. $website = $input['website_id'];
  1849. $query = Good::where('good.status', 2)
  1850. ->where('good.website_id', $website);
  1851. switch ($Levelid) {
  1852. case 1:
  1853. case 2:
  1854. case 3:
  1855. $goods = $query->where(function ($q) use ($Levelid) {
  1856. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1857. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1858. });
  1859. break;
  1860. case 4:
  1861. $goods = $query;
  1862. break;
  1863. case 5:
  1864. $goods = $query->where('type_id', 1);
  1865. break;
  1866. case 6:
  1867. $goods = $query->where('type_id', 2);
  1868. break;
  1869. default:
  1870. return [];
  1871. }
  1872. $all_goods = $goods
  1873. ->select(
  1874. 'good.id',
  1875. 'good.name',
  1876. 'good.imgurl',
  1877. 'good.description',
  1878. 'good.updated_at',
  1879. 'good.catid',
  1880. 'good.type_id',
  1881. 'good.price',
  1882. 'good.level',
  1883. 'good.website_id'
  1884. )
  1885. ->orderBy('updated_at', 'desc')
  1886. ->offset($goodStart)
  1887. ->limit($goodNum)
  1888. ->get();
  1889. $web['website_id'] = $website;
  1890. $all_goods = $this->processGoods($all_goods, $web);
  1891. }
  1892. return $all_goods;
  1893. }, $data);
  1894. $website = $input['website_id'];
  1895. $result['article'] = Article::where(function ($query) use ($website) {
  1896. $query->where(function ($subQuery) use ($website) {
  1897. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1898. })->orWhereNull("ignore_ids");
  1899. })
  1900. ->where('catid', $catid)
  1901. ->where('article.status', 1)
  1902. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1903. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1904. ->orderBy('article.updated_at', 'desc')
  1905. ->first();
  1906. return Result::success($result);
  1907. }
  1908. /**
  1909. * 获取商品分类
  1910. * @param array $data
  1911. * @return array
  1912. * */
  1913. public function getWebsiteshopCat(array $data): array
  1914. {
  1915. $website = $data['website_id'];
  1916. $category = WebsiteCategory::where('website_id', $website)
  1917. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1918. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1919. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id')
  1920. ->orderBy('sort')
  1921. ->get();
  1922. $cat = $category->map(function ($item) use ($website) {
  1923. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1924. $pid = $item->pid ?? 0;
  1925. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1926. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1927. ->where('website_id', $website)
  1928. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1929. ->get(['aLIas_pinyin'])
  1930. ->pluck('aLIas_pinyin')
  1931. ->implode('/');
  1932. } else {
  1933. $pinyin = $item->aLIas_pinyin ?? '';
  1934. }
  1935. $item->pinyin = $pinyin;
  1936. });
  1937. if (empty($category)) {
  1938. return Result::error("栏目查询失败", 0);
  1939. }
  1940. $cat_tree = Result::buildMenuTree($category);
  1941. $web['website_id'] = $website;
  1942. $goods = Good::where('website_id', $website)
  1943. ->where('status', 2)
  1944. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1945. ->latest('updated_at')
  1946. ->offset(($data['page'] - 1) * $data['pageSize'])
  1947. ->limit($data['pageSize'])
  1948. ->get();
  1949. if ($goods->isEmpty()) {
  1950. return Result::error("商品查询失败", 0);
  1951. }
  1952. if ($goods->count() > 1) {
  1953. $goods = $this->processGoods($goods, $web);
  1954. } else {
  1955. $catid = $goods[0]['catid'] ?? 0;
  1956. $good_category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1957. if (!empty($good_category->pid) && $good_category->pid != 0) {
  1958. $level = json_decode($good_category->category_arr_id);
  1959. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1960. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1961. ->get(['aLIas_pinyin'])
  1962. ->pluck('aLIas_pinyin')
  1963. ->implode('/');
  1964. } else {
  1965. $pinyin = $good_category->aLIas_pinyin ?? '';
  1966. }
  1967. $goods[0]['pinyin'] = $pinyin;
  1968. }
  1969. $result = [
  1970. 'category' => $cat_tree,
  1971. 'goods' => $goods,
  1972. ];
  1973. // $resul['goods'] = $goods;
  1974. if (empty($result)) {
  1975. return Result::error("查询失败", 0);
  1976. }
  1977. return Result::success($result);
  1978. }
  1979. /*
  1980. * 获取商品列表
  1981. * @param array $data
  1982. * @return array
  1983. * */
  1984. public function getWebsiteshopList(array $data): array
  1985. {
  1986. // return Result::success($data);
  1987. $where = [
  1988. 'status' => 2,
  1989. 'website_id' => $data['website_id'],
  1990. ];
  1991. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1992. return Result::error("查询失败", 0);
  1993. }
  1994. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1995. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1996. $data['catid'] = $category->category_id ?? 0;
  1997. }
  1998. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1999. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2000. }
  2001. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2002. array_push($where, ['type_id', $data['type_id']]);
  2003. }
  2004. $query = Good::where($where)
  2005. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2006. $query->where(function ($q) use ($data) {
  2007. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2008. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2009. });
  2010. })
  2011. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2012. $query->where(function ($q) use ($data) {
  2013. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2014. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2015. });
  2016. })
  2017. ->select(
  2018. 'good.id',
  2019. 'good.name',
  2020. 'good.imgurl',
  2021. 'good.description',
  2022. 'good.updated_at',
  2023. 'good.com',
  2024. 'good.catid',
  2025. 'good.type_id',
  2026. 'good.website_id',
  2027. 'good.cat_arr_id',
  2028. 'good.created_at',
  2029. 'good.city_id'
  2030. )
  2031. ->latest('updated_at');
  2032. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2033. // 获取 type_id 为 1 的数据
  2034. $result['type1'] = $this->processGoods(
  2035. $query->clone()
  2036. ->where('type_id', 1)
  2037. ->offset(($data['page'] - 1) * $data['pageSize'])
  2038. ->limit($data['pageSize'])
  2039. ->get(),
  2040. $data
  2041. );
  2042. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2043. // 获取 type_id 为 2 的数据
  2044. $result['type2'] = $this->processGoods(
  2045. $query->clone()
  2046. ->where('type_id', 2)
  2047. ->offset(($data['page'] - 1) * $data['pageSize'])
  2048. ->limit($data['pageSize'])
  2049. ->get(),
  2050. $data
  2051. );
  2052. if (empty($result)) {
  2053. return Result::error("查询失败", 0);
  2054. }
  2055. return Result::success($result);
  2056. }
  2057. /**
  2058. * 获取商品详情
  2059. * @param array $data
  2060. * @return array
  2061. * */
  2062. public function getWebsiteshopInfo(array $data): array
  2063. {
  2064. $where = [
  2065. 'good.status' => 2,
  2066. 'good.website_id' => $data['website_id'],
  2067. 'good.id' => $data['id'],
  2068. ];
  2069. $goods = Good::where($where)
  2070. ->where('good.id', $data['id'])
  2071. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2072. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2073. ->first();
  2074. if (empty($goods)) {
  2075. return Result::error("查询失败", 0);
  2076. }
  2077. $goods->imgurl = json_decode($goods->imgurl, true);
  2078. return Result::success($goods);
  2079. }
  2080. /**
  2081. * 封装处理文章的路由问题
  2082. * */
  2083. function processArticles($articles, $data)
  2084. {
  2085. if (!is_array($data)) {
  2086. // 可以根据实际情况进行日志记录或抛出异常
  2087. // 这里简单输出错误信息
  2088. echo "Error: \$data is not an array in processArticles. It is of type " . gettype($data) . PHP_EOL;
  2089. return $articles;
  2090. }
  2091. return $articles->map(function ($article) use ($data) {
  2092. $catid = $article->cat_arr_id ?? '';
  2093. $level = json_decode($catid, true);
  2094. $pinyin = '';
  2095. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2096. if (!empty($category->pid) && $category->pid != 0) {
  2097. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2098. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2099. ->get(['aLIas_pinyin'])
  2100. ->pluck('aLIas_pinyin')
  2101. ->implode('/');
  2102. } else {
  2103. $pinyin = $category->aLIas_pinyin ?? '';
  2104. }
  2105. $article->pinyin = $pinyin;
  2106. return $article;
  2107. });
  2108. }
  2109. // 封装处理由问题
  2110. function processJob($job, $data)
  2111. {
  2112. return $job->map(function ($job) use ($data) {
  2113. $category = $job->cat_arr_id ?? '';
  2114. $cityid = $job->city_arr_id ?? '';
  2115. $city = json_decode($cityid, true);
  2116. $pinyin = '';
  2117. $level = json_decode($category, true);
  2118. // 路由
  2119. if (!empty($level) && is_array($level)) {
  2120. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2121. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2122. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2123. ->get(['aLIas_pinyin'])
  2124. ->pluck('aLIas_pinyin')
  2125. ->implode('/');
  2126. if (empty($pinyin)) {
  2127. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2128. }
  2129. $job->pinyin = $pinyin;
  2130. }
  2131. // 取职位-城市 市??省
  2132. if (!empty($city) && is_array($city)) {
  2133. if (isset($city[1]) && !empty($city[1])) {
  2134. $city = District::where('id', $city[1])->first(['name']);
  2135. $job->city_name = $city->name ?? '';
  2136. } else if (isset($city[0]) && !empty($city[0])) {
  2137. $city = District::where('id', $city[0])->first(['name']);
  2138. $job->city_name = $city->name ?? '';
  2139. } else {
  2140. $job->city_name = '全国';
  2141. }
  2142. }
  2143. // 获取简历最后一级地区
  2144. if (isset($job->city_id) && !empty($job->city_id)) {
  2145. $city = District::where('id', $job->city_id)->first(['name']);
  2146. $job->hunt_cityname = $city->name ?? '';
  2147. }
  2148. // 组合详细地址
  2149. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2150. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2151. if (is_array($address_id) && !empty($address_id)) {
  2152. $address = District::whereIn('id', $address_id)
  2153. ->orderBy('level', 'asc')
  2154. ->get(['name'])
  2155. ->pluck('name')
  2156. ->implode('');
  2157. // $job->address_name = $address ?? '';
  2158. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2159. }
  2160. }
  2161. // 取行业
  2162. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id)) {
  2163. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2164. if (!empty($job->industry)) {
  2165. $query->where('hyid', $job->industry);
  2166. } else if (!empty($job->hy_id)) {
  2167. $query->where('hyid', $job->hy_id);
  2168. } else {
  2169. $query->where('hyid', $job->company_hy_id);
  2170. }
  2171. })->first(['hyname']);
  2172. $job->hy_name = $hy_name->hyname ?? '';
  2173. }
  2174. // 取职位
  2175. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job))) {
  2176. $zwid = $job->job ?? $job->zw_id;
  2177. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2178. $job->zw_name = $zw_name->zwname ?? '';
  2179. }
  2180. // 取具体职位
  2181. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get))) {
  2182. $jtzwid = $job->job_name_get ?? $job->jtzw_id;
  2183. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2184. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2185. }
  2186. // 取工作经验
  2187. if (isset($job->experience) && !empty($job->experience)) {
  2188. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2189. $job->experience_name = $experience->ename ?? '';
  2190. }
  2191. // 取学历
  2192. if (isset($job->educational) && !empty($job->educational)) {
  2193. $education = JobEnum::where('egroup', 'education')->where('evalue', $job->educational)->first(['ename']);
  2194. $job->education_name = $education->ename ?? '';
  2195. }
  2196. // 语言
  2197. if (isset($job->language) && !empty($job->language)) {
  2198. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2199. $job->language_name = $language->ename ?? '';
  2200. }
  2201. // 薪资
  2202. if (isset($job->salary) && !empty($job->salary)) {
  2203. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2204. $job->salary_name = $salary->ename ?? '';
  2205. }
  2206. // 职位性质
  2207. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2208. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2209. $job->job_nature_name = $job_nature->ename ?? '';
  2210. }
  2211. // 公司规模
  2212. if (isset($job->company_size) && !empty($job->company_size)) {
  2213. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2214. $job->company_size_name = $company_size->ename ?? '';
  2215. }
  2216. // 公司性质
  2217. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2218. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2219. $job->company_nature_name = $company_nature->nature_name ?? '';
  2220. }
  2221. // $job->pinyin = $pinyin;
  2222. return $job;
  2223. });
  2224. }
  2225. /**
  2226. * 获取书籍模块
  2227. * @param array $data
  2228. * @return array
  2229. * */
  2230. public function getWebsiteBook(array $data): array
  2231. {
  2232. $input['id'] = $data['id'];
  2233. $input['website_id'] = $data['website_id'];
  2234. // 将 JSON 字符串转换为 PHP 数组
  2235. $data = json_decode($input['id'], true);
  2236. // 使用 array_map 处理每个元素
  2237. $result = array_map(function ($item) use ($input) {
  2238. // 检查parent元素是否存在且不是undefined
  2239. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2240. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2241. $website = [
  2242. 'website_id' => $input['website_id'],
  2243. ];
  2244. // 查询栏目名称
  2245. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2246. if (empty($category)) {
  2247. $parent_alias = '';
  2248. $parent_pinyin = null;
  2249. $imgBooks = [];
  2250. $textBooks = [];
  2251. } else {
  2252. $parent_alias = $category->alias ?? '';
  2253. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2254. // 查找子分类ID数组
  2255. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2256. array_push($childCategoryIds, $parentCatId);
  2257. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2258. if ($parentImgNum != 0) {
  2259. // 查询图片新闻
  2260. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2261. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2262. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2263. })
  2264. ->where('book.status', 2)
  2265. ->where('book.img_url', '!=', '')
  2266. ->leftJoin('website_category', function ($join) use ($website) {
  2267. $join->on('book.cat_id', '=', 'website_category.category_id')
  2268. ->where('website_category.website_id', '=', $website['website_id']);
  2269. })
  2270. ->select(
  2271. 'book.id',
  2272. 'book.title',
  2273. 'book.img_url',
  2274. 'book.price',
  2275. 'book.market_price',
  2276. 'book.description',
  2277. 'book.cat_id',
  2278. 'book.description',
  2279. 'book.updated_at',
  2280. 'website_category.alias as category_name',
  2281. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2282. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2283. )
  2284. ->orderBy('updated_at', 'desc')
  2285. ->limit($parentImgNum)
  2286. ->get()->all();
  2287. // 查询文字新闻
  2288. }
  2289. if ($parentTextNum != 0) {
  2290. $textBooks = [];
  2291. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2292. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2293. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2294. })
  2295. ->where('book.status', 2)
  2296. ->leftJoin('website_category', function ($join) use ($website) {
  2297. $join->on('book.cat_id', '=', 'website_category.category_id')
  2298. ->where('website_category.website_id', '=', $website['website_id']);
  2299. })
  2300. ->select(
  2301. 'book.id',
  2302. 'book.title',
  2303. 'book.img_url',
  2304. 'book.price',
  2305. 'book.market_price',
  2306. 'book.description',
  2307. 'book.cat_id',
  2308. 'book.description',
  2309. 'book.updated_at',
  2310. 'website_category.alias as category_name',
  2311. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2312. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2313. )
  2314. ->orderBy('updated_at', 'desc')
  2315. ->limit($parentTextNum)
  2316. ->get()->all();
  2317. }
  2318. }
  2319. }
  2320. $resultItem = [
  2321. 'alias' => $parent_alias ?? '',
  2322. 'category_id' => $parentCatId ?? 0,
  2323. 'pinyin' => $parent_pinyin ?? null,
  2324. 'imgnum' => $imgBooks ?? [],
  2325. 'textnum' => $textBooks ?? [],
  2326. ];
  2327. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2328. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2329. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2330. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2331. ->get()->all();
  2332. if (!empty($childCategory)) {
  2333. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2334. // 查询子栏目名称
  2335. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2336. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2337. ->first();
  2338. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2339. $childImgArticles = [];
  2340. $childTextArticles = [];
  2341. $resultItem['child'] = [];
  2342. } else {
  2343. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2344. // 查询子栏目图片新闻
  2345. $childImgArticles = Book::where('cat_id', $childCatId)
  2346. ->where('status', 2)
  2347. ->where('img_url', '!=', '')
  2348. ->leftJoin('website_category', function ($join) use ($website) {
  2349. $join->on('book.cat_id', '=', 'website_category.category_id')
  2350. ->where('website_category.website_id', '=', $website['website_id']);
  2351. })
  2352. ->select(
  2353. 'book.id',
  2354. 'book.title',
  2355. 'book.img_url',
  2356. 'book.price',
  2357. 'book.market_price',
  2358. 'book.description',
  2359. 'book.cat_id',
  2360. 'book.description',
  2361. 'book.updated_at',
  2362. DB::raw("'$child_pinyin' as pinyin")
  2363. )
  2364. ->orderBy('updated_at', 'desc')
  2365. ->limit($childImgNum)
  2366. ->get()->all();
  2367. // 查询子栏目文字新闻
  2368. $childTextArticles = Book::where('cat_id', $childCatId)
  2369. ->where('status', 2)
  2370. ->leftJoin('website_category', function ($join) use ($website) {
  2371. $join->on('book.cat_id', '=', 'website_category.category_id')
  2372. ->where('website_category.website_id', '=', $website['website_id']);
  2373. })
  2374. ->select(
  2375. 'book.id',
  2376. 'book.title',
  2377. 'book.img_url',
  2378. 'book.price',
  2379. 'book.market_price',
  2380. 'book.description',
  2381. 'book.cat_id',
  2382. 'book.description',
  2383. 'book.updated_at',
  2384. DB::raw("'$child_pinyin' as pinyin")
  2385. )
  2386. ->orderBy('updated_at', 'desc')
  2387. ->limit($childTextNum)
  2388. ->get()->all();
  2389. $resultItem['child'] = [
  2390. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2391. 'category_id' => $childCatId,
  2392. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2393. 'all_childcat' => $childCategory,
  2394. 'imgnum' => $childImgArticles,
  2395. 'textnum' => $childTextArticles,
  2396. ];
  2397. }
  2398. }
  2399. } else {
  2400. $resultItem['child'] = [];
  2401. }
  2402. return $resultItem;
  2403. }, $data);
  2404. return Result::success($result);
  2405. }
  2406. /**
  2407. * 获取书刊列表
  2408. * @param array $data
  2409. * @return array
  2410. * */
  2411. public function getWebsiteBookList(array $data): array
  2412. {
  2413. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2414. if (empty($web)) {
  2415. return Result::error("查询失败", 0);
  2416. }
  2417. $catid = $data['id'];
  2418. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2419. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2420. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2421. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2422. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2423. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2424. ->where('pid', $category['pid'])
  2425. ->select(
  2426. 'category_id',
  2427. 'alias',
  2428. 'aLIas_pinyin',
  2429. 'pid',
  2430. 'sort',
  2431. 'is_url',
  2432. 'web_url',
  2433. 'seo_title',
  2434. 'seo_keywords',
  2435. 'seo_description',
  2436. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2437. )
  2438. ->orderBy('sort')
  2439. ->get()->all();
  2440. if (empty($category)) {
  2441. return Result::error("查询失败", 0);
  2442. }
  2443. $query = Book::where('book.status', 2)
  2444. ->where('book.website_id', $data['website_id'])
  2445. ->where('book.cat_id', $catid)
  2446. ->select(
  2447. 'book.id',
  2448. 'book.title',
  2449. 'book.img_url',
  2450. 'book.description',
  2451. 'book.updated_at',
  2452. 'book.cat_id',
  2453. DB::raw("'$pinyin' as pinyin")
  2454. )
  2455. ->orderBy('book.updated_at', 'desc');
  2456. $count = $query->count();
  2457. $query = clone $query;
  2458. $Book = $query
  2459. ->limit($data['pageSize'])
  2460. ->offset(($data['page'] - 1) * $data['pageSize'])
  2461. ->get()->all();
  2462. $result = [
  2463. 'category' => $categorys,
  2464. 'books' => $Book,
  2465. 'count' => $count,
  2466. ];
  2467. // if(empty($result)){
  2468. // return Result::error("查询失败", 0);
  2469. // }
  2470. return Result::success($result);
  2471. }
  2472. /**
  2473. * 获取书刊详情
  2474. * @param array $data
  2475. * @return array
  2476. * */
  2477. public function getWebsiteBookInfo(array $data): array
  2478. {
  2479. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2480. if (empty($web)) {
  2481. return Result::error("查询失败", 0);
  2482. }
  2483. $book = Book::where('status', 2)
  2484. ->where('website_id', $data['website_id'])
  2485. ->where('id', $data['id'])
  2486. ->select(
  2487. 'book.*',
  2488. )
  2489. ->orderBy('updated_at', 'desc')
  2490. ->first();
  2491. if (empty($book)) {
  2492. return Result::error("查询失败", 0);
  2493. }
  2494. // 先查询当前分类的 pid
  2495. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2496. ->where('category_id', $book['cat_id'])
  2497. ->first(['pid', 'category_id']);
  2498. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2499. if (!empty($carpid)) {
  2500. if ($carpid->pid != 0) {
  2501. $pid = $carpid['pid'];
  2502. // $parent_pinyin = '';
  2503. } else {
  2504. $pid = $carpid['category_id'];
  2505. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2506. }
  2507. }
  2508. $categorys = $query->where('pid', $pid)
  2509. ->select(
  2510. 'category_id',
  2511. 'alias',
  2512. 'aLIas_pinyin',
  2513. 'pid',
  2514. 'sort',
  2515. 'is_url',
  2516. 'web_url',
  2517. 'category_arr_id as cat_arr_id',
  2518. )
  2519. ->orderBy('sort')
  2520. ->get();
  2521. $category = $this->processArticle($categorys, $data);
  2522. $result = [
  2523. 'category' => $category,
  2524. 'books' => $book,
  2525. ];
  2526. return Result::success($result);
  2527. }
  2528. /**
  2529. * 尝试
  2530. * @param array $data
  2531. * @return array
  2532. * */
  2533. public function test(array $data): array
  2534. {
  2535. $input['id'] = $data['id'];
  2536. $input['website_id'] = $data['website_id'];
  2537. // 将 JSON 字符串转换为 PHP 数组
  2538. $data = json_decode($input['id'], true);
  2539. $result = [];
  2540. $article = $data;
  2541. $result = array_map(function ($item) use ($input) {
  2542. $website = [
  2543. 'website_id' => $input['website_id'],
  2544. ];
  2545. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2546. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2547. $parent = [
  2548. 0 => $category['category_id'] ?? [],
  2549. 1 => $parentImgNum ?? [],
  2550. 2 => $parentTextNum ?? [],
  2551. ];
  2552. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2553. $child = [];
  2554. $resultItem = [
  2555. // 'alias' => $parent_alias ?? '',
  2556. 'category_id' => $parentCatId ?? 0,
  2557. 'pinyin' => $parentImgNum ?? null,
  2558. 'imgnum' => $parentTextNum ?? [],
  2559. // 'textnum' => $textArticles ?? [],
  2560. ];
  2561. return $parent;
  2562. }, $data);
  2563. return Result::success($result);
  2564. // });
  2565. }
  2566. /**
  2567. * 封装处理文章的路由问题
  2568. * */
  2569. function processArticle($article, $data)
  2570. {
  2571. return $article->map(function ($article) use ($data) {
  2572. $catid = $article->cat_arr_id ?? '';
  2573. $level = json_decode($catid, true);
  2574. $pinyin = '';
  2575. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2576. if (!empty($level) && is_array($level)) {
  2577. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2578. ->where('website_id', $data['website_id'])
  2579. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2580. ->get(['aLIas_pinyin'])
  2581. ->pluck('aLIas_pinyin')
  2582. ->implode('/');
  2583. } else {
  2584. $pinyin = '';
  2585. }
  2586. $article->pinyin = $pinyin;
  2587. return $article;
  2588. });
  2589. }
  2590. /**
  2591. * c端-获取招工招聘下拉选框
  2592. * @param array $data
  2593. * @return array
  2594. * */
  2595. public function getWebsiteJobSelect(array $data): array
  2596. {
  2597. $web = Website::where('id', $data['website_id'])->first();
  2598. if(empty($web)){
  2599. return Result::error("该网站不存在", 0);
  2600. }
  2601. $hy = JobIndustry::get()->all();
  2602. $zw = JobPosition::where('zwpid',0)->get()->all();
  2603. $jtzw = JobPosition::where('zwpid','!=',0)->get()->all();
  2604. $result = [
  2605. 'hy' => $hy,
  2606. 'zw' => $zw,
  2607. 'jtzw' => $jtzw,
  2608. ];
  2609. if(empty($result)){
  2610. return Result::error("查询失败", 0);
  2611. }
  2612. return Result::success($result);
  2613. }
  2614. /**
  2615. * c端-获取招工招聘
  2616. * @param array $data
  2617. * @return array
  2618. * */
  2619. public function getWebsiteJob(array $data): array
  2620. {
  2621. $web = Website::where('id', $data['website_id'])->first();
  2622. if (empty($web)) {
  2623. return Result::error("该网站不存在", 0);
  2624. }
  2625. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2626. ->where('job_hunting.website_id', $data['website_id'])
  2627. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2628. $query->where(function ($q) use ($data) {
  2629. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2630. });
  2631. })
  2632. ->select('job_hunting.id','job_hunting.cat_arr_id','job_hunting.job_name_get','job_hunting.industry','job_hunting.name','job_hunting.sexy'
  2633. ,'job_hunting.origin','job_hunting.city_arr_id','job_hunting.experience','job_hunting.updated_at','job_hunting.salary')
  2634. ->orderBy('updated_at', 'desc')
  2635. ->limit($data['job1_num'])
  2636. ->get();
  2637. $web['website_id'] = $data['website_id'];
  2638. if (empty($job_hunting)) {
  2639. $job_huntings = "未查询到相关简历信息";
  2640. } else {
  2641. $job_huntings = $this->processJob($job_hunting, $web);
  2642. }
  2643. // 0:待审核 1:已通过 2:已拒绝
  2644. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2645. ->where('job_recruiting.website_id', $data['website_id'])
  2646. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2647. $query->where(function ($q) use ($data) {
  2648. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2649. });
  2650. })
  2651. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2652. ->select(
  2653. 'job_recruiting.id',
  2654. 'job_recruiting.cat_arr_id',
  2655. 'job_recruiting.title',
  2656. 'job_recruiting.jtzw_id',
  2657. 'job_recruiting.hy_id',
  2658. 'job_recruiting.city_arr_id',
  2659. 'job_recruiting.due_data',
  2660. 'job_recruiting.updated_at',
  2661. 'job_recruiting.experience',
  2662. 'job_recruiting.educational',
  2663. 'job_recruiting.salary',
  2664. 'job_recruiting.zw_id',
  2665. 'job_company.business_name'
  2666. )
  2667. ->orderBy('updated_at', 'desc')
  2668. ->limit($data['job2_num'])
  2669. ->get();
  2670. if (empty($job_recruiting->toArray())) {
  2671. $job_recruitings = "未查询到相关职位信息";
  2672. } else {
  2673. $job_recruitings = $this->processJob($job_recruiting, $web);
  2674. }
  2675. $result = [
  2676. 'job_hunting' => $job_huntings,
  2677. 'job_recuiting' => $job_recruitings,
  2678. ];
  2679. return Result::success($result);
  2680. }
  2681. /**
  2682. * c端-获取招工招聘列表
  2683. * @param array $data
  2684. * @return array
  2685. * */
  2686. public function getWebsiteJobList(array $data): array
  2687. {
  2688. $where = [];
  2689. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2690. if (empty($web)) {
  2691. return Result::error("此网站不存在", 0);
  2692. }
  2693. $website_id['website_id'] = $data['website_id'];
  2694. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2695. array_push($where, ['hy_id', $data['hy_id']]);
  2696. }
  2697. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2698. array_push($where, ['zw_id', $data['zw_id']]);
  2699. }
  2700. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2701. array_push($where, ['jtzw_id', $data['jtzw_id']]);
  2702. }
  2703. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2704. $query = JobRecruiting::where('job_recruiting.status', 1)
  2705. ->where('job_recruiting.website_id', $data['website_id'])
  2706. ->where($where)
  2707. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2708. $query->where(function ($q) use ($data) {
  2709. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2710. });
  2711. })
  2712. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2713. $query->where(function ($q) use ($data) {
  2714. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2715. });
  2716. })
  2717. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2718. ->select(
  2719. 'job_recruiting.id',
  2720. 'job_recruiting.hy_id',
  2721. 'job_recruiting.title',
  2722. 'job_recruiting.zw_id',
  2723. 'job_recruiting.jtzw_id',
  2724. 'job_recruiting.city_arr_id',
  2725. 'job_recruiting.due_data',
  2726. 'job_recruiting.cat_arr_id',
  2727. 'job_recruiting.updated_at'
  2728. )
  2729. ->orderBy('updated_at', 'desc');
  2730. $recruit_count = $query->count();
  2731. $query = clone $query;
  2732. $JobRecruiting = $query
  2733. ->offset(($data['page'] - 1) * $data['pageSize'])
  2734. ->limit($data['pageSize'])
  2735. ->get();
  2736. if (empty($JobRecruiting)) {
  2737. $JobRecruiting = "暂无相关职位信息";
  2738. } else {
  2739. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2740. }
  2741. }
  2742. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2743. $query = JobHunting::where('status', 2)
  2744. ->where('job_hunting.website_id', $data['website_id'])
  2745. ->where($where)
  2746. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2747. $query->where(function ($q) use ($data) {
  2748. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2749. });
  2750. })
  2751. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2752. $query->where(function ($q) use ($data) {
  2753. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2754. });
  2755. })
  2756. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2757. ->orderBy('updated_at', 'desc');
  2758. $hunt_count = $query->count();
  2759. $query = clone $query;
  2760. $JobHunting = $query
  2761. ->offset(($data['page'] - 1) * $data['pageSize'])
  2762. ->limit($data['pageSize'])
  2763. ->get();
  2764. if (empty($JobHunting)) {
  2765. $JobRecruiting = "暂无相关简历信息";
  2766. } else {
  2767. $JobHunting = $this->processJob($JobHunting, $website_id);
  2768. }
  2769. }
  2770. $result = [
  2771. 'JobRecruiting' => $JobRecruiting ?? [],
  2772. 'recruit_count' => $recruit_count ?? 0,
  2773. 'JobHunting' => $JobHunting ?? [],
  2774. 'hunt_count' => $hunt_count ?? 0,
  2775. ];
  2776. return Result::success($result);
  2777. }
  2778. /**
  2779. * c端-获取招工招聘详情
  2780. * @param array $data
  2781. * @return array
  2782. * */
  2783. public function getWebsiteJobInfo(array $data): array
  2784. {
  2785. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2786. if (empty($web)) {
  2787. return Result::error("该网站不存在", 0);
  2788. }
  2789. $webid = [
  2790. 'website_id' => $data['website_id'],
  2791. ];
  2792. // 职位相关信息
  2793. if ($data['type'] == 1) {
  2794. $query = JobRecruiting::where('status', 1)
  2795. ->where('website_id', $data['website_id'])
  2796. ->select('*');
  2797. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2798. $company = JobCompany::where('job_id', $data['id'])->select('id', 'business_name', 'company_hy_id', 'company_size', 'company_nature', 'address_arr_id', 'address')->get();
  2799. if (!empty($company)) {
  2800. $result['company'] = $this->processJob($company, $webid);
  2801. }
  2802. $other_job = JobRecruiting::where('status', 1)
  2803. ->where('website_id', $data['website_id'])
  2804. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2805. ->where('id', '!=', $data['id'])
  2806. ->where('user_id', '=', $job[0]['user_id'])
  2807. ->limit($data['pageSize'])
  2808. ->get();
  2809. if (!empty($other_job)) {
  2810. $result['other_job'] = $this->processJob($other_job, $webid);
  2811. }
  2812. } else {
  2813. $job = JobHunting::where('job_hunting.status', 2)
  2814. ->where('job_hunting.website_id', $data['website_id'])
  2815. ->where('job_hunting.id', $data['id'])
  2816. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2817. ->select('job_hunting.*', 'user_name')
  2818. ->get();
  2819. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2820. if (!empty($resume->toArray())) {
  2821. $result['resume'] = 1;
  2822. } else {
  2823. $result['resume'] = 0;
  2824. }
  2825. }
  2826. if (empty($job->toArray())) {
  2827. return Result::error("id参数错误", 0);
  2828. }
  2829. $result['job'] = $this->processJob($job, $webid);
  2830. // 返现对应的栏目
  2831. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2832. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2833. ->whereIn('category_id', $catid)
  2834. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2835. ->orderBy('pid')->get()->all();
  2836. if (!empty($category)) {
  2837. $result['category'] = $category;
  2838. }
  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['type_id'], '-----------------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. } else {
  3591. $result = Notice::where('status', 1)
  3592. ->where($where)
  3593. ->where('user_id', $data['user_id'])
  3594. ->orWhere(function ($query) use ($data) {
  3595. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  3596. })
  3597. ->orderBy('updated_at', 'desc')
  3598. ->limit($data['page_size'])
  3599. ->offset(($data['page'] - 1) * $data['page_size'])
  3600. ->get();
  3601. }
  3602. if (empty($result)) {
  3603. return Result::error("查询失败", 0);
  3604. }
  3605. $count = Notice::where('status', 1)->count();
  3606. $data = [
  3607. 'rows' => $result,
  3608. 'count' => $count,
  3609. ];
  3610. return Result::success($data);
  3611. }
  3612. public function getNoticeDetail(array $data): array
  3613. {
  3614. $result = Notice::where('id', $data['id'])->first();
  3615. if (empty($result)) {
  3616. return Result::error("查询失败", 0);
  3617. }
  3618. return Result::success($result);
  3619. }
  3620. public function deleteNotice(array $data): array
  3621. {
  3622. $notice = Notice::where('id', $data['id'])->first();
  3623. if (empty($notice)) {
  3624. return Result::error("删除失败", 0);
  3625. }
  3626. $chat_group_id = $notice->group_id;
  3627. if ($chat_group_id) {
  3628. //删除群聊
  3629. ChatGroups::where('id', $chat_group_id)->delete();
  3630. //删除群成员
  3631. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3632. //删除群聊记录
  3633. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3634. }
  3635. $result = Notice::where('id', $data['id'])->delete();
  3636. return Result::success($result);
  3637. }
  3638. public function getMSG(array $data): array
  3639. {
  3640. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3641. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3642. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3643. $result = [];
  3644. if ($type_id == 1) {
  3645. //最近的5篇已审的文章
  3646. $apply_articale = Article::where('status', 1)
  3647. ->where('admin_user_id', $user_id)
  3648. ->orderBy('updated_at', 'desc')
  3649. ->limit(5)->get();
  3650. //获取5条单聊未读聊天消息
  3651. $chat = ChatRecords::where('is_read', 0)
  3652. ->where('user_id', $user_id)
  3653. ->where('talk_type', 1)
  3654. ->orderBy('created_at', 'desc')
  3655. ->limit(5)->get();
  3656. //获取5条未读群聊信息
  3657. $chat_group = ChatRecords::where('is_read', 0)
  3658. ->where('user_id', $user_id)
  3659. ->where('talk_type', 2)
  3660. ->orderBy('created_at', 'desc')
  3661. ->limit(5)->get();
  3662. //获取5条用户的已审核商品
  3663. $good = Good::where('status', 2)
  3664. ->where('user_id', $user_id)
  3665. ->orderBy('updated_at', 'desc')
  3666. ->limit(5)->get();
  3667. //获取5条用户待审核的公告
  3668. $notice = Notice::where('status', 2)
  3669. ->where('user_id', $user_id)
  3670. ->orderBy('updated_at', 'desc')
  3671. ->limit(5)->get();
  3672. //获取5条用户的待审核投诉
  3673. $complaint = Complaint::where('status', 2)
  3674. ->where('user_id', $user_id)
  3675. ->orderBy('updated_at', 'desc')
  3676. ->limit(5)->get();
  3677. //获取5条用户的book
  3678. $book = Book::where('status', 2)
  3679. ->where('user_id', $user_id)
  3680. ->orderBy('updated_at', 'desc')
  3681. ->limit(5)->get();
  3682. //获取5条用户的求职
  3683. //获取5条用户的求职 1
  3684. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3685. ->where('job_hunting.user_id', $user_id)
  3686. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3687. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3688. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3689. ->orderBy('updated_at', 'desc')
  3690. ->limit(5)->get();
  3691. //获取5条用户的求职 2
  3692. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3693. ->where('job_recruiting.user_id', $user_id)
  3694. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3695. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3696. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3697. ->orderBy('updated_at', 'desc')
  3698. ->limit(5)->get();
  3699. //人才库 1
  3700. $job_apply = JobApply::where('job_apply.status', 1)
  3701. ->where('job_apply.receiver_id', $user_id)
  3702. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3703. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3704. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3705. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3706. ->select('job_recruiting', 'job_recruiting.', '', '')
  3707. ->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')
  3708. ->orderBy('updated_at', 'desc')
  3709. ->limit(5)->get();
  3710. // 职场机会 2
  3711. $job_resume = JobResume::where('job_resume.status', 1)
  3712. ->where('job_resume.receiver_id', $user_id)
  3713. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3714. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3715. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3716. ->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')
  3717. ->orderBy('updated_at', 'desc')
  3718. ->limit(5)->get();
  3719. $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);
  3720. $result = [
  3721. 'apply_articale' => $apply_articale,
  3722. 'chat' => $chat,
  3723. 'chat_group' => $chat_group,
  3724. 'good' => $good,
  3725. 'notice' => $notice,
  3726. 'complaint' => $complaint,
  3727. 'book' => $book,
  3728. 'job_hunting' => $job_hunting,
  3729. 'job_recruiting' => $job_recruiting,
  3730. 'job_apply' => $job_apply,
  3731. 'job_resume' => $job_resume,
  3732. 'count' => $count,
  3733. ];
  3734. } elseif ($type_id == 2) {
  3735. //最近的5篇已审的文章
  3736. $apply_articale = Article::where('status', 1)
  3737. ->where('admin_user_id', $user_id)
  3738. ->limit(5)->get();
  3739. //获取5条单聊未读聊天消息
  3740. $chat = ChatRecords::where('is_read', 0)
  3741. ->where('user_id', $user_id)
  3742. ->where('talk_type', 1)
  3743. ->orderBy('created_at', 'desc')
  3744. ->limit(5)->get();
  3745. //获取5条未读群聊信息
  3746. $chat_group = ChatRecords::where('is_read', 0)
  3747. ->where('user_id', $user_id)
  3748. ->where('talk_type', 2)
  3749. ->orderBy('created_at', 'desc')
  3750. ->limit(5)->get();
  3751. //获取5条用户的已审核商品
  3752. $good = Good::where('status', 2)
  3753. ->where('user_id', $user_id)
  3754. ->orderBy('updated_at', 'desc')
  3755. ->limit(5)->get();
  3756. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3757. $result = [
  3758. 'apply_articale' => $apply_articale,
  3759. 'chat' => $chat,
  3760. 'chat_group' => $chat_group,
  3761. 'good' => $good,
  3762. 'count' => $count,
  3763. ];
  3764. } elseif ($type_id == 3) {
  3765. //最近的5篇已审的文章
  3766. $apply_articale = Article::where('status', 1)
  3767. ->where('admin_user_id', $user_id)
  3768. ->limit(5)->get();
  3769. //获取5条单聊未读聊天消息
  3770. $chat = ChatRecords::where('is_read', 0)
  3771. ->where('user_id', $user_id)
  3772. ->where('talk_type', 1)
  3773. ->orderBy('created_at', 'desc')
  3774. ->limit(5)->get();
  3775. //获取5条未读群聊信息
  3776. $chat_group = ChatRecords::where('is_read', 0)
  3777. ->where('user_id', $user_id)
  3778. ->where('talk_type', 2)
  3779. ->orderBy('created_at', 'desc')
  3780. ->limit(5)->get();
  3781. //获取5条用户的已审核商品
  3782. $good = Good::where('status', 2)
  3783. ->where('user_id', $user_id)
  3784. ->orderBy('updated_at', 'desc')
  3785. ->limit(5)->get();
  3786. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3787. $result = [
  3788. 'apply_articale' => $apply_articale,
  3789. 'chat' => $chat,
  3790. 'chat_group' => $chat_group,
  3791. 'good' => $good,
  3792. 'count' => $count,
  3793. ];
  3794. } elseif ($type_id == 4) {
  3795. //最近的5篇已审的文章
  3796. $apply_articale = Article::where('status', 1)
  3797. ->where('admin_user_id', $user_id)
  3798. ->limit(5)->get();
  3799. //获取5条用户的已审核商品
  3800. $good = Good::where('status', 2)
  3801. ->where('user_id', $user_id)
  3802. ->orderBy('updated_at', 'desc')
  3803. ->limit(5)->get();
  3804. $count = count($apply_articale) + count($good);
  3805. $result = [
  3806. 'apply_articale' => $apply_articale,
  3807. 'chat' => '',
  3808. 'chat_group' => '',
  3809. 'good' => $good,
  3810. 'count' => $count,
  3811. ];
  3812. } elseif ($type_id == 10000) {
  3813. //获取未审核的5篇文章
  3814. $apply_articale = Article::where('status', 0)
  3815. ->orderBy('updated_at', 'desc')
  3816. ->limit(5)->get();
  3817. //获取5条单聊未读聊天消息
  3818. $chat = ChatRecords::where('is_read', 0)
  3819. ->where('user_id', $user_id)
  3820. ->where('talk_type', 1)
  3821. ->orderBy('created_at', 'desc')
  3822. ->limit(5)->get();
  3823. //获取5条未读群聊信息
  3824. $chat_group = ChatRecords::where('is_read', 0)
  3825. ->where('user_id', $user_id)
  3826. ->where('talk_type', 2)
  3827. ->orderBy('created_at', 'desc')
  3828. ->limit(5)->get();
  3829. //获取5条用户的已审核商品
  3830. $good = Good::where('status', 1)
  3831. // ->where('user_id', $user_id)
  3832. ->orderBy('updated_at', 'desc')
  3833. ->limit(5)->get();
  3834. //获取5条用户待审核的公告
  3835. $notice = Notice::where('status', 1)
  3836. ->orderBy('updated_at', 'desc')
  3837. ->limit(5)->get();
  3838. //获取5条用户的待审核投诉
  3839. $complaint = Complaint::where('status', 1)
  3840. ->orderBy('updated_at', 'desc')
  3841. ->limit(5)->get();
  3842. //获取5条用户的book
  3843. $book = Book::where('status', 1)
  3844. ->orderBy('updated_at', 'desc')
  3845. ->limit(5)->get();
  3846. //获取5条用户的求职 1
  3847. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3848. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3849. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3850. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3851. ->orderBy('updated_at', 'desc')
  3852. ->limit(5)->get();
  3853. //获取5条用户的求职 2
  3854. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3855. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3856. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3857. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3858. ->orderBy('updated_at', 'desc')
  3859. ->limit(5)->get();
  3860. //人才库 1
  3861. $job_apply = JobApply::where('job_apply.status', 1)
  3862. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3863. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3864. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3865. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3866. ->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')
  3867. ->orderBy('updated_at', 'desc')
  3868. ->limit(5)->get();
  3869. // 职场机会 2
  3870. $job_resume = JobResume::where('job_resume.status', 1)
  3871. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3872. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3873. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3874. ->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')
  3875. ->orderBy('updated_at', 'desc')
  3876. ->limit(5)->get();
  3877. $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);
  3878. $result = [
  3879. 'apply_articale' => $apply_articale,
  3880. 'chat' => $chat,
  3881. 'chat_group' => $chat_group,
  3882. 'good' => $good,
  3883. 'notice' => $notice,
  3884. 'complaint' => $complaint,
  3885. 'book' => $book,
  3886. 'job_hunting' => $job_hunting,
  3887. 'job_recruiting' => $job_recruiting,
  3888. 'job_apply' => $job_apply,
  3889. 'job_resume' => $job_resume,
  3890. 'count' => $count,
  3891. ];
  3892. } elseif ($type_id == 20000) {
  3893. }
  3894. var_dump($type_id, '-----------------test---------');
  3895. return Result::success($result);
  3896. }
  3897. public function getComplaintList(array $data): array
  3898. {
  3899. var_dump($data, '00000001000000000000');
  3900. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3901. unset($data['type_id']);
  3902. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3903. $where = [];
  3904. if ($type_id != 10000) {
  3905. $where['complaint.user_id'] = $user_id;
  3906. }
  3907. if (!empty($data['title'])) {
  3908. $where['complaint.title'] = ['like', '%' . $data['title'] . '%'];
  3909. }
  3910. if (!empty($data['deal'])) {
  3911. $where['complaint.deal'] = $data['deal'];
  3912. }
  3913. if (!empty($data['status'])) {
  3914. $where['complaint.status'] = $data['status'];
  3915. }
  3916. var_dump(!empty($data['deal_user']), '----------1');
  3917. $result = Complaint::where($where)
  3918. ->when(!empty($data['status1']), function ($query) use ($data) {
  3919. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  3920. })
  3921. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  3922. //json re_user_ids data[user_id]是不是在里面
  3923. $query->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')');
  3924. })
  3925. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  3926. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  3927. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  3928. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  3929. ->orderBy('updated_at', 'desc')
  3930. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  3931. //sql输出
  3932. if (empty($result)) {
  3933. return Result::error("暂无投诉信息", 0);
  3934. }
  3935. // 取出数据
  3936. $rows = $result->items();
  3937. $count = $result->total();
  3938. $responseData = [
  3939. 'rows' => $rows,
  3940. 'count' => $count,
  3941. ];
  3942. return Result::success($responseData);
  3943. }
  3944. public function getComplaintInfo(array $data): array
  3945. {
  3946. $result = Complaint::where('id', $data['id'])->first();
  3947. if (empty($result)) {
  3948. return Result::error("查询失败", 0);
  3949. }
  3950. return Result::success($result);
  3951. }
  3952. public function addComplaint(array $data): array
  3953. {
  3954. date_default_timezone_set('Asia/Shanghai');
  3955. $data['created_at'] = date('Y-m-d H:i:s');
  3956. $data['updated_at'] = date('Y-m-d H:i:s');
  3957. $result = Complaint::create($data);
  3958. return Result::success($result);
  3959. }
  3960. public function updateComplaint(array $data): array
  3961. {
  3962. date_default_timezone_set('Asia/Shanghai');
  3963. $data['updated_at'] = date('Y-m-d H:i:s');
  3964. $user_id = $data['user_id'] ?? 0;
  3965. $type_id = $data['type_id'] ?? 0;
  3966. unset($data['user_id']);
  3967. unset($data['type_id']);
  3968. $result = Complaint::where('id', $data['id'])->update($data);
  3969. return Result::success($result);
  3970. }
  3971. public function deleteComplaint(array $data): array
  3972. {
  3973. $result = Complaint::where('id', $data['id'])->delete();
  3974. return Result::success($result);
  3975. }
  3976. public function getComplainInfo(array $data): array
  3977. {
  3978. $result = Complaint::where('id', $data['id'])->first();
  3979. if (empty($result)) {
  3980. return Result::error("查询失败", 0);
  3981. }
  3982. return Result::success($result);
  3983. }
  3984. public function updateComplaintStatus(array $data): array
  3985. {
  3986. date_default_timezone_set('Asia/Shanghai');
  3987. $data['updated_at'] = date('Y-m-d H:i:s');
  3988. $user_id = $data['user_id'] ?? 0;
  3989. $type_id = $data['type_id'] ?? 0;
  3990. unset($data['user_id']);
  3991. unset($data['type_id']);
  3992. //处理, 写入处理人
  3993. if (isset($data['deal']) && ($data['deal'] == 1 || $data['deal'] == 4)) {
  3994. $data['real_deal_user'] = $user_id;
  3995. }
  3996. //如果是deal 23,则判断是不是处理人
  3997. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 3) && $type_id != 10000) {
  3998. $complaintInof = Complaint::where('id', $data['id'])
  3999. ->where('real_deal_user', $user_id)
  4000. ->first();
  4001. if (empty($complaintInof)) {
  4002. return Result::error("处理人错误", 0);
  4003. }
  4004. }
  4005. $result = complaint::where('id', $data['id'])->update($data);
  4006. return Result::success($result);
  4007. }
  4008. public function updateGoodStatus(array $data): array
  4009. {
  4010. $user_id = $data['user_id'] ?? 0;
  4011. $type_id = $data['type_id'] ?? 0;
  4012. unset($data['user_id']);
  4013. unset($data['type_id']);
  4014. $result = Good::where('id', $data['id'])->update($data);
  4015. return Result::success($result);
  4016. }
  4017. public function updateJobHuntingStatus(array $data): array
  4018. {
  4019. $user_id = $data['user_id'] ?? 0;
  4020. $type_id = $data['type_id'] ?? 0;
  4021. unset($data['user_id']);
  4022. unset($data['type_id']);
  4023. $result = JobHunting::where('id', $data['id'])->update($data);
  4024. return Result::success($result);
  4025. }
  4026. public function updateNoticeStatus(array $data): array
  4027. {
  4028. $user_id = $data['user_id'] ?? 0;
  4029. $type_id = $data['type_id'] ?? 0;
  4030. unset($data['user_id']);
  4031. unset($data['type_id']);
  4032. $result = Notice::where('id', $data['id'])->update($data);
  4033. return Result::success($result);
  4034. }
  4035. public function getDUser(array $data): array
  4036. {
  4037. if (!empty($data['ids'])) {
  4038. $user = User::whereIn('id', $data['ids'])->getall();
  4039. if (empty($user)) {
  4040. return Result::error('无数据', 0);
  4041. }
  4042. return Result::success($user);
  4043. }
  4044. $where = [];
  4045. if (!empty($data['department_id'])) {
  4046. $where['department_id'] = $data['department_id'];
  4047. }
  4048. if (!empty($data['city_id'])) {
  4049. $where['city_id'] = $data['city_id'];
  4050. }
  4051. $result = User::where('type_id', 2)
  4052. ->where('status', 1)
  4053. ->where($where)
  4054. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4055. ->get();
  4056. if (empty($result)) {
  4057. return Result::error("查询失败", 0);
  4058. }
  4059. return Result::success($result);
  4060. }
  4061. //20250324 通知,公告,消息
  4062. // 20250306 -------招聘--------fr
  4063. /*
  4064. * 招聘列表
  4065. * */
  4066. public function getJobRecruitingList(array $data): array
  4067. {
  4068. $where = [];
  4069. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4070. if ($data['checkout'] == 0) {
  4071. $job_status = [0, 2];
  4072. } else {
  4073. $job_status = [1];
  4074. }
  4075. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4076. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4077. }
  4078. $user = User::where('id', $data['user_id'])->first();
  4079. if (empty($user)) {
  4080. return Result::error("用户不存在", 0);
  4081. }
  4082. // 3:企业会员
  4083. if ($user['type_id'] == 3) {
  4084. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4085. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4086. }
  4087. // 如果 $where 为空,则不添加 where 条件
  4088. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4089. return $query->where($where);
  4090. })
  4091. ->whereIn('job_recruiting.status', $job_status)
  4092. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4093. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4094. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4095. ->orderBy("updated_at", "desc")
  4096. ->offset(($data['page'] - 1) * $data['page_size'])
  4097. ->limit($data['page_size'])
  4098. ->get()
  4099. ->all();
  4100. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4101. return $query->where($where);
  4102. })
  4103. ->whereIn('job_recruiting.status', $job_status)
  4104. ->count();
  4105. if (empty($result)) {
  4106. return Result::error("暂无招聘信息", 0);
  4107. }
  4108. return Result::success($result);
  4109. }
  4110. /*
  4111. * 招聘信息添加
  4112. * */
  4113. public function addJobRecruiting(array $data): array
  4114. {
  4115. // return Result::success($data);
  4116. $user = User::where('user.id', $data['user_id'])
  4117. ->where('user.status', 1)
  4118. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4119. ->select(
  4120. 'user.type_id',
  4121. 'user.mobile',
  4122. 'user.email',
  4123. 'user_info.business_name',
  4124. 'user_info.company_hy_id',
  4125. 'user_info.company_nature',
  4126. 'user_info.company_size',
  4127. 'user_info.introduction',
  4128. 'user_info.real_name',
  4129. 'user_info.company_url',
  4130. 'user_info.address_arr_id',
  4131. 'user_info.address'
  4132. )
  4133. ->first();
  4134. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4135. return Result::error("用户不存在", 0);
  4136. }
  4137. $web = Website::where('id', $data['website_id'])->first();
  4138. if (empty($web)) {
  4139. return Result::error("网站不存在", 0);
  4140. }
  4141. // return Result::success($user);
  4142. $data['action_id'] = $data['user_id'];
  4143. $data['user_type'] = $user['type_id'];
  4144. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4145. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4146. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4147. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4148. // 公司地址 管理员必填
  4149. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4150. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4151. // 管理员-企业相关信息
  4152. $company = [
  4153. // 'user_id' => $data['user_id']?? null,
  4154. 'business_name' => $data['business_name'] ?? null,
  4155. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4156. 'company_size' => $data['company_size'] ?? null,
  4157. 'company_nature' => $data['company_nature'] ?? null,
  4158. 'introduction' => $data['introduction'] ?? null,
  4159. 'real_name' => $data['real_name'] ?? null,
  4160. 'mobile' => $data['mobile'] ?? null,
  4161. 'company_url' => $data['company_url'] ?? null,
  4162. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4163. 'address' => $data['address'] ?? null,
  4164. 'email' => $data['email'] ?? null,
  4165. ];
  4166. //去掉相关企业信息
  4167. $job = array_diff_key($data, array_flip(array_keys($company)));
  4168. Db::beginTransaction();
  4169. try {
  4170. // 先添加职位相关信息
  4171. if ($user['type_id'] == 10000) {
  4172. $job['status'] = 1;
  4173. }
  4174. $jobId = JobRecruiting::insertGetId($job);
  4175. if (empty($jobId)) {
  4176. Db::rollBack();
  4177. return Result::error("添加失败");
  4178. }
  4179. // 添加公司信息
  4180. $company['user_id'] = $data['user_id'] ?? null;
  4181. $company['job_id'] = $jobId;
  4182. $company['user_type'] = $user['type_id'] ?? null;
  4183. $company['website_id'] = $data['website_id'] ?? null;
  4184. if ($user['type_id'] == 10000) {
  4185. // 管理员添加企业信息
  4186. // return Result::success($company);
  4187. $companyId = JobCompany::insertGetId($company);
  4188. if (empty($companyId)) {
  4189. Db::rollBack();
  4190. return Result::error("添加失败");
  4191. }
  4192. } else {
  4193. // 企业会员添加企业信息
  4194. $company = [
  4195. 'user_id' => $data['user_id'] ?? null,
  4196. 'business_name' => $user['business_name'] ?? null,
  4197. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4198. 'company_size' => $user['company_size'] ?? null,
  4199. 'company_nature' => $user['company_nature'] ?? null,
  4200. 'introduction' => $user['introduction'] ?? null,
  4201. 'real_name' => $user['real_name'] ?? null,
  4202. 'mobile' => $user['mobile'] ?? null,
  4203. 'company_url' => $user['company_url'] ?? null,
  4204. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4205. 'address' => $user['address'] ?? null,
  4206. 'email' => $user['email'] ?? null,
  4207. 'website_id' => $data['website_id'] ?? null,
  4208. 'user_type' => $user['type_id'] ?? null,
  4209. 'job_id' => $jobId,
  4210. ];
  4211. $companyId = JobCompany::insertGetId($company);
  4212. if (empty($companyId)) {
  4213. Db::rollBack();
  4214. return Result::error("添加失败");
  4215. }
  4216. // return Result::success($company);
  4217. }
  4218. Db::commit();
  4219. } catch (\Exception $e) {
  4220. Db::rollBack();
  4221. return Result::error($e->getMessage(), 0);
  4222. }
  4223. $result = [
  4224. 'job_id' => $jobId,
  4225. 'company_id' => $companyId,
  4226. ];
  4227. if (empty($result)) {
  4228. return Result::error("添加失败", 0);
  4229. }
  4230. return Result::success($result);
  4231. }
  4232. /*
  4233. * 获取招聘信息详情
  4234. * */
  4235. public function getJobRecruitingInfo(array $data): array
  4236. {
  4237. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4238. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4239. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4240. ->select(
  4241. 'job_recruiting.*',
  4242. 'website.website_name as website_name',
  4243. 'job_company.business_name',
  4244. 'job_company.company_hy_id',
  4245. 'job_company.company_size',
  4246. 'job_company.company_nature',
  4247. 'job_company.introduction',
  4248. 'job_company.real_name',
  4249. 'job_company.mobile',
  4250. 'job_company.company_url',
  4251. 'job_company.address_arr_id',
  4252. 'job_company.address',
  4253. 'job_company.email'
  4254. )
  4255. ->first();
  4256. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4257. if (!empty($cityId)) {
  4258. if (isset($cityId[1]) && $cityId[1] != null) {
  4259. $city = District::where('id', $cityId[1])->first(['name']);
  4260. } else {
  4261. $city = District::where('id', $cityId[0])->first(['name']);
  4262. }
  4263. $result['city'] = $city['name'] ?? '';
  4264. }
  4265. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4266. if (is_array($addressId) && !empty($addressId)) {
  4267. $address = District::whereIn('id', $addressId)
  4268. ->orderBy('level', 'asc')
  4269. ->get(['name'])
  4270. ->pluck('name')
  4271. ->implode('');
  4272. // $job->address_name = $address ?? '';
  4273. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4274. }
  4275. if (empty($result)) {
  4276. return Result::error("招聘信息不存在", 0);
  4277. }
  4278. // return Result::success($job);
  4279. return Result::success($result);
  4280. }
  4281. /*
  4282. * 修改招聘信息
  4283. * */
  4284. public function upJobRecruiting(array $data): array
  4285. {
  4286. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4287. // return Result::success($job);
  4288. if (empty($job)) {
  4289. return Result::error("招聘信息不存在", 0);
  4290. }
  4291. $user = User::where('id', $data['user_id'])->first();
  4292. // return Result::success($user);
  4293. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4294. return Result::error("用户不存在", 0);
  4295. }
  4296. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4297. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4298. }
  4299. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4300. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4301. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4302. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4303. // 公司地址 管理员必填
  4304. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4305. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4306. // 管理员-企业相关信息
  4307. $company = [
  4308. 'business_name' => $data['business_name'] ?? null,
  4309. 'company_hy_id' => $data['hy_id'] ?? null,
  4310. 'company_size' => $data['company_size'] ?? null,
  4311. 'company_nature' => $data['company_nature'] ?? null,
  4312. 'introduction' => $data['introduction'] ?? null,
  4313. 'real_name' => $data['real_name'] ?? null,
  4314. 'mobile' => $data['mobile'] ?? null,
  4315. 'company_url' => $data['company_url'] ?? null,
  4316. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4317. 'address' => $data['address'] ?? null,
  4318. 'email' => $data['email'] ?? null,
  4319. ];
  4320. //去掉相关企业信息
  4321. $data = array_diff_key($data, array_flip(array_keys($company)));
  4322. $jobId = $data['id'];
  4323. $web = $data['website_id'];
  4324. $data['action_id'] = $data['user_id'];
  4325. unset($data['user_id']);
  4326. unset($data['user_type']);
  4327. unset($data['id']);
  4328. unset($data['website_id']);
  4329. // return Result::success($data);
  4330. Db::beginTransaction();
  4331. try {
  4332. // 管理员修改招聘信息
  4333. if ($user['type_id'] == 10000) {
  4334. $data['website_id'] = $web;
  4335. $company['website_id'] = $data['website_id'];
  4336. $data['status'] = 1;
  4337. } else {
  4338. $data['status'] = 0;
  4339. }
  4340. // Db::rollBack();
  4341. // return Result::success($company);
  4342. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4343. if (empty($result['job'])) {
  4344. Db::rollBack();
  4345. return Result::error("修改招聘信息失败");
  4346. }
  4347. // 管理员修改企业相关信息
  4348. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4349. if (empty($result['company'])) {
  4350. Db::rollBack();
  4351. return Result::error("修改企业相关信息失败");
  4352. }
  4353. Db::commit();
  4354. // return Result::success($result);
  4355. } catch (\Exception $e) {
  4356. Db::rollBack();
  4357. return Result::error($e->getMessage(), 0);
  4358. }
  4359. return Result::success($result);
  4360. }
  4361. /*
  4362. * 招聘信息删除
  4363. * */
  4364. public function delJobRecruiting(array $data): array
  4365. {
  4366. $user = User::where('id', $data['user_id'])->first();
  4367. if (empty($user)) {
  4368. return Result::error("用户不存在", 0);
  4369. }
  4370. $job = JobRecruiting::where('id', $data['id'])->first();
  4371. if (empty($job)) {
  4372. return Result::error("招聘信息不存在", 0);
  4373. }
  4374. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4375. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4376. }
  4377. Db::beginTransaction();
  4378. try {
  4379. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4380. if (empty($result['job'])) {
  4381. Db::rollBack();
  4382. return Result::error("删除招聘信息失败");
  4383. }
  4384. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4385. if (empty($result['company'])) {
  4386. Db::rollBack();
  4387. return Result::error("删除企业相关信息失败");
  4388. }
  4389. Db::commit();
  4390. } catch (\Exception $e) {
  4391. Db::rollBack();
  4392. return Result::error($e->getMessage(), 0);
  4393. }
  4394. return Result::success($result);
  4395. }
  4396. /*
  4397. * 获取公司信息
  4398. * */
  4399. public function getJobCompany(array $data): array
  4400. {
  4401. $user = User::where('user.id', $data['user_id'])
  4402. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4403. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4404. ->first();
  4405. // return Result::success($user);
  4406. if (empty($user)) {
  4407. return Result::error("用户不存在", 0);
  4408. }
  4409. if ($user['type_id'] == 3) {
  4410. $result = [
  4411. // 'id' => 0,
  4412. 'user_id' => $data['user_id'],
  4413. 'website_id' => $data['website_id'],
  4414. 'business_name' => $user['business_name'], // 企业名称
  4415. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4416. 'company_nature' => $user['company_nature'], // 公司性质
  4417. 'company_size' => $user['company_size'], // 公司规模
  4418. 'introduction' => $user['introduction'], // 公司简介
  4419. 'real_name' => $user['real_name'], // 企业联系人
  4420. 'mobile' => $user['mobile'], // 企业联系电话
  4421. 'company_url' => $user['company_url'], // 企业网址
  4422. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4423. 'address' => $user['address'], // 企业地址
  4424. 'email' => $user['email'], // 企业邮箱
  4425. ];
  4426. } else {
  4427. return Result::error("用户类型错误", 0);
  4428. }
  4429. if (empty($result)) {
  4430. return Result::error("公司信息不存在", 0);
  4431. }
  4432. return Result::success($result);
  4433. }
  4434. /*
  4435. * 修改公司信息
  4436. * */
  4437. public function upJobCompany(array $data): array
  4438. {
  4439. // return Result::success($data);
  4440. $user = User::where('user.id', $data['user_id'])
  4441. ->where('user.status', 1)
  4442. ->select('user.user_name', 'user.type_id')
  4443. ->first();
  4444. if (empty($user)) {
  4445. return Result::error("用户不存在", 0);
  4446. }
  4447. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4448. $company = [
  4449. 'business_name' => $data['business_name'], // 企业名称
  4450. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4451. 'company_nature' => $data['company_nature'], // 公司性质
  4452. 'company_size' => $data['company_size'], // 公司规模
  4453. 'introduction' => $data['introduction'], // 公司简介
  4454. // 'real_name' => $data['real_name'], // 企业联系人
  4455. 'company_url' => $data['company_url'], // 企业网址
  4456. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4457. 'address' => $data['address'], // 企业详细地址
  4458. ];
  4459. if ($user['type_id'] == 3) {
  4460. Db::beginTransaction();
  4461. try {
  4462. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4463. 'business_name' => $data['business_name'], // 企业名称
  4464. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4465. 'company_nature' => $data['company_nature'], // 公司性质
  4466. 'company_size' => $data['company_size'], // 公司规模
  4467. 'introduction' => $data['introduction'], // 公司简介
  4468. // 'real_name' => $data['real_name'], // 企业联系人
  4469. 'company_url' => $data['company_url'], // 企业网址
  4470. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4471. 'address' => $data['address'], // 企业详细地址
  4472. ]);
  4473. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4474. Db::commit();
  4475. } catch (\Exception $e) {
  4476. Db::rollBack();
  4477. return Result::error($e->getMessage(), 0);
  4478. }
  4479. } else {
  4480. return Result::error("用户类型错误", 0);
  4481. }
  4482. if (empty($result)) {
  4483. return Result::error("修改失败", 0);
  4484. }
  4485. return Result::success($result);
  4486. }
  4487. /*
  4488. * 获取省-市
  4489. * */
  4490. public function getJobRecruitingArea(array $data): array
  4491. {
  4492. if (isset($data['pid']) && $data['pid'] != null) {
  4493. $result = District::where('pid', $data['pid'])->get()->all();
  4494. } else {
  4495. $result = District::where('level', 1)->get()->all();
  4496. }
  4497. if (empty($result)) {
  4498. return Result::error("暂无此省市", 0);
  4499. }
  4500. return Result::success($result);
  4501. }
  4502. /*
  4503. * 获取行业分类
  4504. * */
  4505. public function getIndustry(array $data): array
  4506. {
  4507. $result = JobIndustry::get()->all();
  4508. if (empty($result)) {
  4509. return Result::error("暂无行业分类", 0);
  4510. }
  4511. return Result::success($result);
  4512. }
  4513. /*
  4514. * 获取职位
  4515. * */
  4516. public function getPositionList(array $data): array
  4517. {
  4518. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4519. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4520. } else {
  4521. $result = JobPosition::where('zwpid', 0)->get()->all();
  4522. }
  4523. if (empty($result)) {
  4524. return Result::error("暂无此职位", 0);
  4525. }
  4526. return Result::success($result);
  4527. }
  4528. /*
  4529. * 获取工作性质-菜单
  4530. * */
  4531. public function getJobNature(array $data): array
  4532. {
  4533. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4534. if (empty($result)) {
  4535. return Result::error("暂无工作性质", 0);
  4536. }
  4537. return Result::success($result);
  4538. }
  4539. /*
  4540. * 获取工作经验-菜单
  4541. * */
  4542. public function getExperience(array $data): array
  4543. {
  4544. $result = JobEnum::where('egroup', 'years')->get()->all();
  4545. if (empty($result)) {
  4546. return Result::error("暂无工作经验", 0);
  4547. }
  4548. return Result::success($result);
  4549. }
  4550. /*
  4551. * 获取学历-菜单
  4552. * */
  4553. public function getEducation(array $data): array
  4554. {
  4555. $result = JobEnum::where('egroup', 'education')->get()->all();
  4556. if (empty($result)) {
  4557. return Result::error("暂无学历", 0);
  4558. }
  4559. return Result::success($result);
  4560. }
  4561. /*
  4562. * 获取薪资-菜单
  4563. * */
  4564. public function getSalary(array $data): array
  4565. {
  4566. $result = JobEnum::where('egroup', 'income')->get()->all();
  4567. if (empty($result)) {
  4568. return Result::error("暂无薪资", 0);
  4569. }
  4570. return Result::success($result);
  4571. }
  4572. /*
  4573. * 获取语言-菜单
  4574. * */
  4575. public function getLanguage(array $data): array
  4576. {
  4577. $result = JobEnum::where('egroup', 'language')->get()->all();
  4578. if (empty($result)) {
  4579. return Result::error("暂无语言", 0);
  4580. }
  4581. return Result::success($result);
  4582. }
  4583. /*
  4584. * 获取掌握程度-菜单
  4585. * */
  4586. public function getLevel(array $data): array
  4587. {
  4588. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4589. if (empty($result)) {
  4590. return Result::error("暂无工作性质", 0);
  4591. }
  4592. return Result::success($result);
  4593. }
  4594. // 公司信息
  4595. /*
  4596. * 获取公司性质-菜单
  4597. * */
  4598. public function getCompanyNature(array $data): array
  4599. {
  4600. $result = JobNature::get()->all();
  4601. if (empty($result)) {
  4602. return Result::error("暂无公司性质", 0);
  4603. }
  4604. return Result::success($result);
  4605. }
  4606. /*
  4607. * 获取公司规模-菜单
  4608. * */
  4609. public function getCompanySize(array $data): array
  4610. {
  4611. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4612. if (empty($result)) {
  4613. return Result::error("暂无公司规模", 0);
  4614. }
  4615. return Result::success($result);
  4616. }
  4617. /*
  4618. * 招聘信息审核
  4619. * */
  4620. public function checkJobRecruiting(array $data): array
  4621. {
  4622. $user = User::where('id', $data['user_id'])->first();
  4623. if (empty($user)) {
  4624. return Result::error("用户不存在", 0);
  4625. }
  4626. $job = JobRecruiting::where('id', $data['id'])->first();
  4627. if (empty($job)) {
  4628. return Result::error("招聘信息不存在", 0);
  4629. }
  4630. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4631. if ($user['type_id'] != 10000) {
  4632. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4633. }
  4634. // 驳回原因
  4635. if ($data['status'] == 2) {
  4636. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4637. }
  4638. $data['action_id'] = $data['user_id'];
  4639. unset($data['user_id']);
  4640. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4641. if (empty($result)) {
  4642. return Result::error("审核失败", 0);
  4643. }
  4644. return Result::success($result);
  4645. }
  4646. public function myApplyList(array $data): array
  4647. {
  4648. $user = User::where('id', $data['user_id'])->first();
  4649. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4650. return Result::error("用户不存在", 0);
  4651. }
  4652. // 1:个人会员 职场机会
  4653. if ($user['type_id'] == 1) {
  4654. $where['user_id'] = $user['id'];
  4655. }
  4656. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4657. $query->where('recruit_id', $user['id']);
  4658. })
  4659. ->pluck('recruit_id');
  4660. $where = [];
  4661. if (isset($data['salary']) && $data['salary'] != null) {
  4662. $where['job_recruiting.salary'] = $data['salary'];
  4663. }
  4664. if (isset($data['experience']) && $data['experience'] != null) {
  4665. $where['job_recruiting.experience'] = $data['experience'];
  4666. }
  4667. if (isset($data['business_name']) && $data['business_name'] != null) {
  4668. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4669. }
  4670. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4671. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4672. ->where($where);
  4673. // ->count();
  4674. $count = $query->count();
  4675. $query = clone $query;
  4676. $job = $query
  4677. ->leftJoin('job_enum as income_enum', function ($join) {
  4678. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4679. ->where('income_enum.egroup', 'income');
  4680. })
  4681. ->leftJoin('job_enum as years_enum', function ($join) {
  4682. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4683. ->where('years_enum.egroup', 'years');
  4684. })
  4685. // ->where($where)
  4686. ->orderBy('job_recruiting.updated_at', 'desc')
  4687. ->select(
  4688. 'job_recruiting.id',
  4689. 'job_recruiting.title',
  4690. 'job_company.business_name',
  4691. 'income_enum.evalue as salary_evalue',
  4692. 'income_enum.ename as salary_ename',
  4693. 'years_enum.evalue as experience_evalue',
  4694. 'years_enum.ename as experience_ename',
  4695. 'job_recruiting.updated_at'
  4696. )
  4697. ->offset(($data['page'] - 1) * $data['pageSize'])
  4698. ->limit($data['pageSize'])
  4699. ->get()
  4700. ->all();
  4701. if (empty($job)) {
  4702. return Result::error("暂无招聘信息", 0);
  4703. }
  4704. $result = [
  4705. 'row' => $job,
  4706. 'count' => $count,
  4707. ];
  4708. return Result::success($result);
  4709. }
  4710. /*
  4711. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4712. * */
  4713. public function getRecruitingList(array $data): array
  4714. {
  4715. $user = User::where('id', $data['user_id'])->first();
  4716. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4717. return Result::error("用户不存在", 0);
  4718. }
  4719. // 1:个人会员 职场机会
  4720. if ($user['type_id'] == 1) {
  4721. $where['user_id'] = $user['id'];
  4722. }
  4723. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4724. $query->where('recruit_id', $user['id']);
  4725. })
  4726. ->pluck('recruit_id');
  4727. $where = [];
  4728. if (isset($data['salary']) && $data['salary'] != null) {
  4729. $where['job_recruiting.salary'] = $data['salary'];
  4730. }
  4731. if (isset($data['experience']) && $data['experience'] != null) {
  4732. $where['job_recruiting.experience'] = $data['experience'];
  4733. }
  4734. if (isset($data['business_name']) && $data['business_name'] != null) {
  4735. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4736. }
  4737. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4738. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4739. ->where($where);
  4740. // ->count();
  4741. $count = $query->count();
  4742. $query = clone $query;
  4743. $job = $query
  4744. ->leftJoin('job_enum as income_enum', function ($join) {
  4745. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4746. ->where('income_enum.egroup', 'income');
  4747. })
  4748. ->leftJoin('job_enum as years_enum', function ($join) {
  4749. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4750. ->where('years_enum.egroup', 'years');
  4751. })
  4752. // ->where($where)
  4753. ->orderBy('job_recruiting.updated_at', 'desc')
  4754. ->select(
  4755. 'job_recruiting.id',
  4756. 'job_recruiting.title',
  4757. 'job_company.business_name',
  4758. 'income_enum.evalue as salary_evalue',
  4759. 'income_enum.ename as salary_ename',
  4760. 'years_enum.evalue as experience_evalue',
  4761. 'years_enum.ename as experience_ename',
  4762. 'job_recruiting.updated_at'
  4763. )
  4764. ->offset(($data['page'] - 1) * $data['pageSize'])
  4765. ->limit($data['pageSize'])
  4766. ->get()
  4767. ->all();
  4768. if (empty($job)) {
  4769. return Result::error("暂无招聘信息", 0);
  4770. }
  4771. $result = [
  4772. 'row' => $job,
  4773. 'count' => $count,
  4774. ];
  4775. return Result::success($result);
  4776. }
  4777. /*
  4778. * 获取企业会员-招聘信息列表
  4779. * */
  4780. public function getRecruitingInfo(array $data): array
  4781. {
  4782. $user = User::where('id', $data['user_id'])->first();
  4783. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4784. return Result::error("用户不存在", 0);
  4785. }
  4786. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4787. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4788. ->select(
  4789. 'job_recruiting.*',
  4790. 'job_company.business_name',
  4791. 'job_company.company_hy_id',
  4792. 'job_company.company_size',
  4793. 'job_company.company_nature',
  4794. 'job_company.introduction',
  4795. 'job_company.real_name',
  4796. 'job_company.mobile',
  4797. 'job_company.company_url',
  4798. 'job_company.address_arr_id',
  4799. 'job_company.address',
  4800. 'job_company.email'
  4801. )
  4802. ->get();
  4803. if (empty($recruiting)) {
  4804. return Result::error("暂无招聘信息", 0);
  4805. }
  4806. return Result::success($recruiting);
  4807. }
  4808. /*
  4809. * 获取企业会员-我的沟通
  4810. * */
  4811. public function getJobResumeList(array $data): array
  4812. {
  4813. $user = User::where('id', $data['user_id'])->first();
  4814. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4815. return Result::error("用户不存在", 0);
  4816. }
  4817. $where = [];
  4818. if (isset($data['salary']) && $data['salary'] != null) {
  4819. $where['job_hunting.salary'] = $data['salary'];
  4820. }
  4821. if (isset($data['user_name']) && $data['user_name'] != null) {
  4822. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4823. }
  4824. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4825. $query->where('job_resume.user_id', $user['id']);
  4826. })
  4827. ->when(!empty($where), function ($query) use ($where) {
  4828. $query->where($where);
  4829. })
  4830. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  4831. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  4832. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  4833. ->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');
  4834. $count = $job->count();
  4835. if ($count == 0) {
  4836. return Result::error("暂无沟通记录", 0);
  4837. }
  4838. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  4839. ->offset(($data['page'] - 1) * $data['pageSize'])
  4840. ->limit($data['pageSize'])
  4841. ->get();
  4842. if (empty($jobs)) {
  4843. return Result::error("暂无沟通记录", 0);
  4844. }
  4845. $result['row'] = $this->processJob($jobs, '');
  4846. $result['count'] = $count;
  4847. return Result::success($result);
  4848. }
  4849. // 20250306 招聘
  4850. //20250422 书刊音像
  4851. public function addBook(array $data): array
  4852. {
  4853. // $user_id = $data['user_id'] ?? 0;
  4854. $type_id = $data['type_id'] ?? 0;
  4855. // $website_id = $data['website_id'] ?? 0;
  4856. // unset($data['user_id']);
  4857. unset($data['type_id']);
  4858. // unset($data['website_id']);
  4859. //处理数组
  4860. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4861. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4862. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4863. if ($data['img_url'] == '') {
  4864. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4865. preg_match_all($reg, $data['detail'], $matches);
  4866. if (isset($matches[1][0])) {
  4867. //截取varchar240
  4868. $data['img_url'] = substr($matches[1][0], 0, 240);
  4869. }
  4870. }
  4871. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4872. //提取标题+内容中的关键词
  4873. $data['keyword'] = $data['title'];
  4874. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4875. Jieba::init(); // 初始化 jieba-php
  4876. Finalseg::init();
  4877. $segList = Jieba::cut($data['keyword']);
  4878. $segList1 = array_slice($segList, 0, 8);
  4879. $data['keyword'] = implode(',', $segList1);
  4880. }
  4881. if ($data['description'] == '') {
  4882. //提取内容中的描述
  4883. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4884. }
  4885. var_dump($data, '--');
  4886. $result = Book::insertGetId($data);
  4887. if (empty($result)) {
  4888. return Result::error("添加失败", 0);
  4889. }
  4890. return Result::success($result);
  4891. }
  4892. public function getBookList(array $data): array
  4893. {
  4894. $where = [];
  4895. if (!empty($data["title"])) {
  4896. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  4897. }
  4898. if (!empty($data['website_name'])) {
  4899. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4900. }
  4901. if (!empty($data['status'])) {
  4902. $where[] = ['book.status', '=', $data['status']];
  4903. }
  4904. $user_id = $data['user_id'];
  4905. $type_id = $data['type_id'];
  4906. // $type_id = 4;
  4907. var_dump($type_id, '------1--------');
  4908. if ($type_id != 10000) {
  4909. $where[] = ['book.user_id', '=', $user_id];
  4910. }
  4911. var_dump(!empty($data['status1']), '=-===1');
  4912. $result = Book::where($where)
  4913. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  4914. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  4915. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  4916. ->when(isset($data['status1']), function ($query) use ($data) {
  4917. $query->whereIn('book.status', [1, 3]);
  4918. })
  4919. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  4920. ->orderBy("updated_at", "desc")
  4921. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4922. if (empty($result)) {
  4923. return Result::error("暂无数据", 0);
  4924. }
  4925. // 取出数据
  4926. $rows = $result->items();
  4927. $count = $result->total();
  4928. $responseData = [
  4929. 'rows' => $rows,
  4930. 'count' => $count,
  4931. ];
  4932. return Result::success($responseData);
  4933. }
  4934. public function deleteBook(array $data): array
  4935. {
  4936. $result = Book::where('id', $data['id'])->delete();
  4937. if (empty($result)) {
  4938. return Result::error("删除失败", 0);
  4939. }
  4940. return Result::success($result);
  4941. }
  4942. public function updateBook(array $data): array
  4943. {
  4944. // $user_id = $data['user_id'] ?? 0;
  4945. $type_id = $data['type_id'] ?? 0;
  4946. // $website_id = $data['website_id'] ?? 0;
  4947. unset($data['user_id']);
  4948. unset($data['type_id']);
  4949. // unset($data['website_id']);
  4950. //处理数组
  4951. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4952. if ($data['img_url'] == '') {
  4953. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4954. preg_match_all($reg, $data['detail'], $matches);
  4955. if (isset($matches[1][0])) {
  4956. //截取varchar240
  4957. $data['img_url'] = substr($matches[1][0], 0, 240);
  4958. }
  4959. }
  4960. if ($data['keyword'] == '') {
  4961. //提取标题+内容中的关键词
  4962. $data['keyword'] = $data['title'];
  4963. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4964. Jieba::init(); // 初始化 jieba-php
  4965. Finalseg::init();
  4966. $segList = Jieba::cut($data['keyword']);
  4967. $segList1 = array_slice($segList, 0, 8);
  4968. $data['keyword'] = implode(',', $segList1);
  4969. }
  4970. if ($data['description'] == '') {
  4971. //提取内容中的描述
  4972. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4973. }
  4974. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4975. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4976. $result = Book::where("id", $data["id"])->update($data);
  4977. if (empty($result)) {
  4978. return Result::error("更新失败", 0);
  4979. }
  4980. return Result::success($result);
  4981. }
  4982. public function getBookInfo(array $data): array
  4983. {
  4984. $result = Book::where("id", $data["id"])->first();
  4985. if (empty($result)) {
  4986. return Result::error("获取失败", 0);
  4987. }
  4988. return Result::success($result);
  4989. }
  4990. public function updateBookStatus(array $data): array
  4991. {
  4992. //审核
  4993. unset($data['user_id']);
  4994. $result = Book::where("id", $data["id"])->update($data);
  4995. if (empty($result)) {
  4996. return Result::error("更新失败", 0);
  4997. }
  4998. return Result::success($result);
  4999. }
  5000. //20250422 书刊音像
  5001. }