NewsService.php 223 KB

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