NewsService.php 191 KB

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