NewsService.php 220 KB

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