NewsService.php 219 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128
  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}%")->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)->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',
  2636. 'job_hunting.industry',
  2637. 'job_hunting.city_arr_id',
  2638. 'job_hunting.experience',
  2639. 'job_hunting.updated_at',
  2640. 'job_hunting.salary'
  2641. )
  2642. ->orderBy('updated_at', 'desc')
  2643. ->limit($data['job1_num'])
  2644. ->get();
  2645. $web['website_id'] = $data['website_id'];
  2646. if (empty($job_hunting)) {
  2647. $job_huntings = "未查询到相关简历信息";
  2648. } else {
  2649. $job_huntings = $this->processJob($job_hunting, $web);
  2650. }
  2651. // 0:待审核 1:已通过 2:已拒绝
  2652. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2653. ->where('job_recruiting.website_id', $data['website_id'])
  2654. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2655. $query->where(function ($q) use ($data) {
  2656. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2657. });
  2658. })
  2659. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2660. ->select(
  2661. 'job_recruiting.id',
  2662. 'job_recruiting.cat_arr_id',
  2663. 'job_recruiting.title',
  2664. 'job_recruiting.jtzw_id',
  2665. 'job_recruiting.hy_id',
  2666. 'job_recruiting.city_arr_id',
  2667. 'job_recruiting.due_data',
  2668. 'job_recruiting.updated_at',
  2669. 'job_recruiting.experience',
  2670. 'job_recruiting.educational',
  2671. 'job_recruiting.salary',
  2672. 'job_recruiting.zw_id',
  2673. 'job_company.business_name'
  2674. )
  2675. ->orderBy('updated_at', 'desc')
  2676. ->limit($data['job2_num'])
  2677. ->get();
  2678. if (empty($job_recruiting->toArray())) {
  2679. $job_recruitings = "未查询到相关职位信息";
  2680. } else {
  2681. $job_recruitings = $this->processJob($job_recruiting, $web);
  2682. }
  2683. $result = [
  2684. 'job_hunting' => $job_huntings,
  2685. 'job_recuiting' => $job_recruitings,
  2686. ];
  2687. return Result::success($result);
  2688. }
  2689. /**
  2690. * c端-获取招工招聘列表
  2691. * @param array $data
  2692. * @return array
  2693. * */
  2694. public function getWebsiteJobList(array $data): array
  2695. {
  2696. $where = [];
  2697. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2698. if (empty($web)) {
  2699. return Result::error("此网站不存在", 0);
  2700. }
  2701. $website_id['website_id'] = $data['website_id'];
  2702. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2703. array_push($where, ['hy_id', $data['hy_id']]);
  2704. }
  2705. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2706. array_push($where, ['zw_id', $data['zw_id']]);
  2707. }
  2708. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2709. array_push($where, ['jtzw_id', $data['jtzw_id']]);
  2710. }
  2711. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2712. $query = JobRecruiting::where('job_recruiting.status', 1)
  2713. ->where('job_recruiting.website_id', $data['website_id'])
  2714. ->where($where)
  2715. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2716. $query->where(function ($q) use ($data) {
  2717. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2718. });
  2719. })
  2720. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2721. $query->where(function ($q) use ($data) {
  2722. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2723. });
  2724. })
  2725. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2726. ->select(
  2727. 'job_recruiting.id',
  2728. 'job_recruiting.hy_id',
  2729. 'job_recruiting.title',
  2730. 'job_recruiting.zw_id',
  2731. 'job_recruiting.jtzw_id',
  2732. 'job_recruiting.city_arr_id',
  2733. 'job_recruiting.due_data',
  2734. 'job_recruiting.cat_arr_id',
  2735. 'job_recruiting.updated_at'
  2736. )
  2737. ->orderBy('updated_at', 'desc');
  2738. $recruit_count = $query->count();
  2739. $query = clone $query;
  2740. $JobRecruiting = $query
  2741. ->offset(($data['page'] - 1) * $data['pageSize'])
  2742. ->limit($data['pageSize'])
  2743. ->get();
  2744. if (empty($JobRecruiting)) {
  2745. $JobRecruiting = "暂无相关职位信息";
  2746. } else {
  2747. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2748. }
  2749. }
  2750. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2751. $query = JobHunting::where('status', 2)
  2752. ->where('job_hunting.website_id', $data['website_id'])
  2753. ->where($where)
  2754. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2755. $query->where(function ($q) use ($data) {
  2756. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2757. });
  2758. })
  2759. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2760. $query->where(function ($q) use ($data) {
  2761. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2762. });
  2763. })
  2764. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2765. ->orderBy('updated_at', 'desc');
  2766. $hunt_count = $query->count();
  2767. $query = clone $query;
  2768. $JobHunting = $query
  2769. ->offset(($data['page'] - 1) * $data['pageSize'])
  2770. ->limit($data['pageSize'])
  2771. ->get();
  2772. if (empty($JobHunting)) {
  2773. $JobRecruiting = "暂无相关简历信息";
  2774. } else {
  2775. $JobHunting = $this->processJob($JobHunting, $website_id);
  2776. }
  2777. }
  2778. $result = [
  2779. 'JobRecruiting' => $JobRecruiting ?? [],
  2780. 'recruit_count' => $recruit_count ?? 0,
  2781. 'JobHunting' => $JobHunting ?? [],
  2782. 'hunt_count' => $hunt_count ?? 0,
  2783. ];
  2784. return Result::success($result);
  2785. }
  2786. /**
  2787. * c端-获取招工招聘详情
  2788. * @param array $data
  2789. * @return array
  2790. * */
  2791. public function getWebsiteJobInfo(array $data): array
  2792. {
  2793. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2794. if (empty($web)) {
  2795. return Result::error("该网站不存在", 0);
  2796. }
  2797. $webid = [
  2798. 'website_id' => $data['website_id'],
  2799. ];
  2800. // 职位相关信息
  2801. if ($data['type'] == 1) {
  2802. $query = JobRecruiting::where('status', 1)
  2803. ->where('website_id', $data['website_id'])
  2804. ->select('*');
  2805. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2806. $company = JobCompany::where('job_id', $data['id'])->select('id', 'business_name', 'company_hy_id', 'company_size', 'company_nature', 'address_arr_id', 'address')->get();
  2807. if (!empty($company)) {
  2808. $result['company'] = $this->processJob($company, $webid);
  2809. }
  2810. $other_job = JobRecruiting::where('status', 1)
  2811. ->where('website_id', $data['website_id'])
  2812. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2813. ->where('id', '!=', $data['id'])
  2814. ->where('user_id', '=', $job[0]['user_id'])
  2815. ->limit($data['pageSize'])
  2816. ->get();
  2817. if (!empty($other_job)) {
  2818. $result['other_job'] = $this->processJob($other_job, $webid);
  2819. }
  2820. } else {
  2821. $job = JobHunting::where('job_hunting.status', 2)
  2822. ->where('job_hunting.website_id', $data['website_id'])
  2823. ->where('job_hunting.id', $data['id'])
  2824. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2825. ->select('job_hunting.*', 'user_name')
  2826. ->get();
  2827. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2828. if (!empty($resume->toArray())) {
  2829. $result['resume'] = 1;
  2830. } else {
  2831. $result['resume'] = 0;
  2832. }
  2833. }
  2834. if (empty($job->toArray())) {
  2835. return Result::error("id参数错误", 0);
  2836. }
  2837. $result['job'] = $this->processJob($job, $webid);
  2838. // 返现对应的栏目
  2839. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2840. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2841. ->whereIn('category_id', $catid)
  2842. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2843. ->orderBy('pid')->get()->all();
  2844. if (!empty($category)) {
  2845. $result['category'] = $category;
  2846. }
  2847. if (empty($result)) {
  2848. return Result::error("参数错误", 0);
  2849. }
  2850. return Result::success($result);
  2851. }
  2852. /**
  2853. * c端-申请职位
  2854. * @param array $data
  2855. * @return array
  2856. * */
  2857. public function getWebsiteJobApply(array $data): array
  2858. {
  2859. // 首先验证网站是否存在
  2860. // return Result::success($data);
  2861. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2862. if (empty($web)) {
  2863. return Result::error("该网站不存在", 0);
  2864. }
  2865. // 验证用户是否存在且为个人会员/管理员
  2866. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2867. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2868. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2869. return Result::error("用户不存在", 0);
  2870. }
  2871. // 去除重复元素和空元素,并保持原始顺序
  2872. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2873. return !empty($value);
  2874. }));
  2875. // 验证职位是否存在 1:审核通过
  2876. $recruiting = JobRecruiting::where('status', 1)
  2877. ->where('website_id', $data['website_id'])
  2878. ->whereIn('id', $data['recruit_id'])
  2879. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2880. if (empty($recruiting)) {
  2881. return Result::error("该职位不存在", 0);
  2882. }
  2883. // 简历是否存在
  2884. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2885. if (empty($hunt_id)) {
  2886. return Result::error("该简历不存在", 0);
  2887. }
  2888. $data['hunt_id'] = $hunt_id['hunt_id'];
  2889. // // 验证是否已投递过该职位
  2890. $apply = JobApply::where('user_id', $data['user_id'])
  2891. ->where('hunt_id', $data['hunt_id'])
  2892. ->where('website_id', $data['website_id'])
  2893. ->whereIn('recruit_id', $data['recruit_id'])
  2894. ->get(['recruit_id']);
  2895. if (!empty($apply->toArray())) {
  2896. return Result::error("您已投递过该职位!");
  2897. }
  2898. $insertData = array_map(function ($recruiting) use ($data) {
  2899. return [
  2900. 'user_id' => $data['user_id'],
  2901. 'hunt_id' => $data['hunt_id'],
  2902. 'website_id' => $data['website_id'],
  2903. 'recruit_id' => $recruiting['recruit_id'],
  2904. 'receiver_id' => $recruiting['receiver_id'],
  2905. 'status' => 1,
  2906. ];
  2907. }, $recruiting);
  2908. // 批量插入数据
  2909. $result = JobApply::insert($insertData);
  2910. if (empty($result)) {
  2911. return Result::error("投递失败", 0);
  2912. }
  2913. return Result::success($result);
  2914. }
  2915. /**
  2916. * 招工招聘-沟通简历
  2917. * @param array $data
  2918. * @return array
  2919. * */
  2920. public function getWebsiteJobResume(array $data): array
  2921. {
  2922. // 首先验证网站是否存在
  2923. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2924. if (empty($web)) {
  2925. return Result::error("该网站不存在", 0);
  2926. }
  2927. // return Result::success($data);
  2928. // 验证用户是否存在且为企业会员/管理员
  2929. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2930. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2931. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2932. return Result::error("用户不存在", 0);
  2933. }
  2934. // 去除重复元素和空元素,并保持原始顺序
  2935. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2936. return !empty($value);
  2937. }));
  2938. // 验证简历是否存在
  2939. $hunting = JobHunting::where('status', 2)
  2940. ->where('website_id', $data['website_id'])
  2941. ->whereIn('id', $data['hunt_id'])
  2942. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2943. if (empty($hunting)) {
  2944. return Result::error("该简历不存在", 0);
  2945. }
  2946. // 验证是否已沟通过该简历
  2947. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2948. ->where('recruit_id', $data['recruit_id'])
  2949. ->where('website_id', $data['website_id'])
  2950. ->whereIn('hunt_id', $data['hunt_id'])
  2951. ->get(['hunt_id']);
  2952. if (!empty($remuse->toArray())) {
  2953. return Result::error("您已沟通过该简历!");
  2954. }
  2955. // 准备要插入的数据数组
  2956. $insertData = array_map(function ($hunting) use ($data) {
  2957. return [
  2958. 'user_id' => $data['user_id'],
  2959. 'recruit_id' => $data['recruit_id'],
  2960. 'website_id' => $data['website_id'],
  2961. 'hunt_id' => $hunting['hunt_id'],
  2962. 'receiver_id' => $hunting['receiver_id'],
  2963. 'status' => 1,
  2964. ];
  2965. }, $hunting);
  2966. // 批量插入数据
  2967. $result = JobRemuse::insert($insertData);
  2968. if (empty($result)) {
  2969. return Result::error("沟通失败", 0);
  2970. }
  2971. return Result::success($result);
  2972. }
  2973. /**
  2974. * 招工招聘 -我的职位(企业会员)
  2975. * @param array $data
  2976. * @return array
  2977. */
  2978. public function getWebsiteJobRecruiting(array $data): array
  2979. {
  2980. $web = Website::where('id', $data['website_id'])->first('id');
  2981. if (empty($web)) {
  2982. return Result::error("该网站不存在", 0);
  2983. }
  2984. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2985. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2986. return Result::error("用户暂无权限!", 0);
  2987. }
  2988. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2989. $result = JobRecruiting::where('website_id', $data['website_id'])
  2990. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  2991. $query->where('user_id', $user['id']);
  2992. })
  2993. ->where('status', 1)
  2994. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  2995. ->orderBy('updated_at', 'desc')
  2996. ->limit($data['pageSize'])
  2997. ->get();
  2998. if (empty($result)) {
  2999. return Result::error("暂无相关职位信息", 0);
  3000. }
  3001. return Result::success($result);
  3002. }
  3003. /**
  3004. * c端 - 验证路由
  3005. * @param array $data
  3006. * @return array
  3007. */
  3008. public function checkWebsiteRoute(array $data): array
  3009. {
  3010. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  3011. if(empty($web)){
  3012. return Result::error("该网站不存在", 0);
  3013. }
  3014. // 验证栏目路由
  3015. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3016. ->where('aLIas_pinyin', $data['last_route'])
  3017. ->first();
  3018. if(empty($last_category)){
  3019. return Result::error("该栏目不存在", 0);
  3020. }
  3021. if(isset($data['id']) && !empty($data['id'])){
  3022. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3023. switch ($last_category['type']) {
  3024. case 1:
  3025. // 文章
  3026. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3027. $article = Article::where('status', 1)
  3028. ->where('id', $data['id'])
  3029. ->where(function ($query) use ($data) {
  3030. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3031. ->orWhereNull("ignore_ids");
  3032. })
  3033. ->first(['cat_arr_id']);
  3034. if(empty($article)){
  3035. return Result::error("该文章不存在", 0);
  3036. }
  3037. // return Result::success($article);
  3038. break;
  3039. case 2:
  3040. // 商品
  3041. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3042. $article = Good::where('website_id', $data['website_id'])
  3043. ->where('status', 2)
  3044. ->where('id', $data['id'])
  3045. ->first(['cat_arr_id']);
  3046. if(empty($article)){
  3047. return Result::error("该商品不存在", 0);
  3048. }
  3049. break;
  3050. case 3:
  3051. // 书刊信息
  3052. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3053. $article = Book::where('website_id', $data['website_id'])
  3054. ->where('status', 2)
  3055. ->where('id', $data['id'])
  3056. ->first(['id','cat_arr_id']);
  3057. if(empty($article)){
  3058. return Result::error("该书刊不存在", 0);
  3059. }
  3060. break;
  3061. case 4:
  3062. // 招聘
  3063. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3064. $article = JobRecruiting::where('website_id', $data['website_id'])
  3065. ->where('status', 1)
  3066. ->where('id', $data['id'])
  3067. ->first(['cat_arr_id']);
  3068. if(empty($article)){
  3069. return Result::error("该招聘不存在", 0);
  3070. }
  3071. break;
  3072. case 5:
  3073. // 求职
  3074. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3075. $article = JobHunting::where('website_id', $data['website_id'])
  3076. ->where('status', 2)
  3077. ->where('id', $data['id'])
  3078. ->first(['cat_arr_id']);
  3079. if(empty($article)){
  3080. return Result::error("该求职不存在", 0);
  3081. }
  3082. break;
  3083. case 6:
  3084. // 招工招聘
  3085. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3086. $article = JobRecruiting::where('website_id', $data['website_id'])
  3087. ->where('status', 1)
  3088. ->where('id', $data['id'])
  3089. ->first(['cat_arr_id']);
  3090. if(empty($article)){
  3091. $article = JobHunting::where('website_id', $data['website_id'])
  3092. ->where('status', 2)
  3093. ->where('id', $data['id'])
  3094. ->first(['cat_arr_id']);
  3095. }
  3096. if(empty($article)){
  3097. return Result::error("该招工招聘不存在", 0);
  3098. }
  3099. break;
  3100. default:
  3101. return Result::error("该数据不存在", 0);
  3102. break;
  3103. }
  3104. $catid = json_decode($article['cat_arr_id'], true);
  3105. if(empty($catid)){
  3106. return Result::error("该数据不存在", 0);
  3107. }
  3108. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3109. ->orderByRaw('FIELD(category_id, '. implode(',', $catid). ')')
  3110. ->whereIn('category_id', $catid)
  3111. ->pluck('aLIas_pinyin')
  3112. ->implode('/');
  3113. }
  3114. if($last_category['pid']!=0){
  3115. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3116. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3117. ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr). ')')
  3118. ->whereIn('category_id', $cat_arr)
  3119. ->pluck('aLIas_pinyin')
  3120. ->implode('/');
  3121. }else{
  3122. $pinyin = $last_category['aLIas_pinyin'];
  3123. }
  3124. if(empty($pinyin) || $pinyin!=$data['all_route']){
  3125. return Result::error('非法路径!');
  3126. }else{
  3127. return Result::success($pinyin);
  3128. }
  3129. }
  3130. /**
  3131. * 验证导航名称是否重复
  3132. * @return void
  3133. */
  3134. public function checkCategoryName(array $data): array
  3135. {
  3136. $result = Category::when($data, function ($query) use ($data) {
  3137. if (isset($data['name']) && $data['name']) {
  3138. $query->where("name", $data['name']);
  3139. }
  3140. if (isset($data['id']) && $data['id']) {
  3141. $query->where("id", "!=", $data['id']);
  3142. }
  3143. })->first();
  3144. if ($result) {
  3145. return Result::error("已存在");
  3146. } else {
  3147. return Result::success();
  3148. }
  3149. }
  3150. //20250226 产品列表
  3151. public function getGoodList(array $data): array
  3152. {
  3153. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3154. unset($data['type_id']);
  3155. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3156. $where = [];
  3157. if ($type_id != '10000') {
  3158. $where = [
  3159. 'good.user_id' => $user_id,
  3160. ];
  3161. }
  3162. //类型
  3163. if (isset($data['type_id']) && $data['type_id']) {
  3164. $where = [
  3165. 'type_id' => $data['type_id'],
  3166. ];
  3167. }
  3168. //名称
  3169. if (isset($data['name']) && $data['name']) {
  3170. $where = [
  3171. 'good.name' => $data['name'],
  3172. ];
  3173. }
  3174. //status
  3175. if (isset($data['status']) && $data['status'] != '') {
  3176. $where = [
  3177. 'good.status' => $data['status'],
  3178. ];
  3179. }
  3180. //status1
  3181. // if (isset($data['status1']) && $data['status1'] == 1) {
  3182. // $status1 = 1;
  3183. // }
  3184. $where1 = [];
  3185. //website_id
  3186. // if (isset($data['website_id']) && $data['website_id']) {
  3187. // $where1 = [
  3188. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3189. // ];
  3190. // }
  3191. // website_name
  3192. if (isset($data['website_name']) && $data['website_name']) {
  3193. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3194. }
  3195. // catid
  3196. if (isset($data['category_name']) && $data['category_name']) {
  3197. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3198. }
  3199. // $result = Good::where($where)
  3200. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3201. $result = Good::where($where)
  3202. ->when(!empty($where1), function ($query) use ($where1) {
  3203. return $query->where($where1);
  3204. })
  3205. //status 1待审核2已审核3已拒绝
  3206. ->when(isset($data['status1']), function ($query) {
  3207. return $query->whereIn('good.status', [1, 3]);
  3208. })
  3209. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3210. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3211. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3212. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3213. ->orderBy("updated_at", "desc")
  3214. ->limit($data['page_size'])
  3215. ->offset(($data['page'] - 1) * $data['page_size'])
  3216. ->get();
  3217. $count = Good::where($where)
  3218. ->when(!empty($where1), function ($query) use ($where1) {
  3219. return $query->where($where1);
  3220. })
  3221. //status 1待审核2已审核3已拒绝
  3222. ->when(isset($data['status1']), function ($query) {
  3223. return $query->whereIn('good.status', [1, 3]);
  3224. })
  3225. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3226. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3227. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3228. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3229. ->orderBy("updated_at", "desc")->count();
  3230. $data = [
  3231. 'rows' => $result->toArray(),
  3232. 'count' => $count,
  3233. ];
  3234. if (empty($result)) {
  3235. return Result::error("此栏目暂无相关产品", 0);
  3236. }
  3237. return Result::success($data);
  3238. }
  3239. public function getGoodInfo(array $data): array
  3240. {
  3241. $result = Good::where('id', $data['id'])->first();
  3242. if (empty($result)) {
  3243. return Result::error("此产品不存在", 0);
  3244. }
  3245. return Result::success($result);
  3246. }
  3247. public function addGood(array $data): array
  3248. {
  3249. // unset($data['city_arr_id']);
  3250. // unset($data['cat_arr_id']);
  3251. $data['city_id'] = end($data['city_arr_id']);
  3252. $data['catid'] = end($data['cat_arr_id']);
  3253. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3254. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3255. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3256. unset($data['imgUrl']);
  3257. if (isset($data['price']) && $data['price'] == '') {
  3258. $data['price'] = 0;
  3259. }
  3260. $result = Good::insert($data);
  3261. if (empty($result)) {
  3262. return Result::error("添加失败", 0);
  3263. }
  3264. return Result::success($result);
  3265. }
  3266. public function updateGood(array $data): array
  3267. {
  3268. $data['city_id'] = end($data['city_arr_id']);
  3269. $data['catid'] = end($data['cat_arr_id']);
  3270. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3271. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3272. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3273. //设置东八区
  3274. date_default_timezone_set('Asia/Shanghai');
  3275. $data['updated_at'] = date('Y-m-d H:i:s');
  3276. if (isset($data['price']) && $data['price'] == '') {
  3277. $data['price'] = 0;
  3278. }
  3279. $result = Good::where('id', $data['id'])->update($data);
  3280. if (empty($result)) {
  3281. return Result::error("更新失败", 0);
  3282. }
  3283. return Result::success($result);
  3284. }
  3285. public function delGood(array $data): array
  3286. {
  3287. $result = Good::where('id', $data['id'])->delete();
  3288. if (empty($result)) {
  3289. return Result::error("删除失败", 0);
  3290. }
  3291. return Result::success($result);
  3292. }
  3293. //20250226 产品列表
  3294. //20250306 求职信息
  3295. public function getJobHuntingList(array $data): array
  3296. {
  3297. $where = [];
  3298. if (isset($data['username']) && !empty($data['username'])) {
  3299. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3300. }
  3301. //status 1待审核2已审核3已拒绝
  3302. if (isset($data['status']) && $data['status'] != '') {
  3303. $where = [
  3304. 'job_hunting.status' => $data['status'],
  3305. ];
  3306. }
  3307. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3308. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3309. unset($data['type_id']);
  3310. if ($type_id != '10000') {
  3311. $where[] = ['job_hunting.user_id', '=', $user_id];
  3312. }
  3313. $result = JobHunting::where($where)
  3314. ->when(!empty($data['status1']), function ($query) use ($data) {
  3315. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3316. })
  3317. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3318. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3319. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3320. ->orderBy("updated_at", "desc")
  3321. ->limit($data['page_size'])
  3322. ->offset(($data['page'] - 1) * $data['page_size'])
  3323. ->get();
  3324. if (empty($result)) {
  3325. return Result::error("查询失败", 0);
  3326. }
  3327. $count = JobHunting::where($where)
  3328. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3329. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3330. ->count();
  3331. $data = [
  3332. 'rows' => $result->toArray(),
  3333. 'count' => $count,
  3334. ];
  3335. return Result::success($data);
  3336. }
  3337. public function getJobHuntingApply(array $data): array
  3338. {
  3339. $where = [];
  3340. if (isset($data['username']) && !empty($data['username'])) {
  3341. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3342. }
  3343. if (isset($data['salary']) && !empty($data['salary'])) {
  3344. $where = [
  3345. 'job_hunting.salary' => $data['salary'],
  3346. ];
  3347. }
  3348. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3349. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3350. unset($data['type_id']);
  3351. if ($type_id != '10000') {
  3352. $where[] = ['job_apply.user_id', '=', $user_id];
  3353. }
  3354. $result = jobApply::where($where)
  3355. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3356. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3357. // })
  3358. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3359. ->where('job_enum.egroup', '=', 'income')
  3360. ->where('job_hunting.status', 2) //已审核
  3361. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3362. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3363. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3364. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3365. //职位----是申请职位
  3366. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3367. ->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')
  3368. ->orderBy("job_hunting.updated_at", "desc")
  3369. ->limit($data['page_size'])
  3370. ->offset(($data['page'] - 1) * $data['page_size'])
  3371. ->get();
  3372. if (empty($result)) {
  3373. return Result::error("查询失败", 0);
  3374. }
  3375. $count = jobApply::where($where)
  3376. ->where('job_enum.egroup', '=', 'income')
  3377. ->where('job_hunting.status', 2) //已审核
  3378. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3379. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3380. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3381. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3382. //职位----是申请职位
  3383. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3384. ->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')
  3385. ->count();
  3386. $data = [
  3387. 'rows' => $result->toArray(),
  3388. 'count' => $count,
  3389. ];
  3390. return Result::success($data);
  3391. }
  3392. public function addJobHunting(array $data): array
  3393. {
  3394. date_default_timezone_set('Asia/Shanghai');
  3395. unset($data['company_name']);
  3396. unset($data['job_industry']);
  3397. unset($data['job_name']);
  3398. unset($data['department']);
  3399. unset($data['job_timeList']);
  3400. unset($data['job_content']);
  3401. $data['created_at'] = date('Y-m-d H:i:s');
  3402. $data['updated_at'] = date('Y-m-d H:i:s');
  3403. var_dump($data, '-----------------test---------');
  3404. $result = JobHunting::create($data);
  3405. if (empty($result)) {
  3406. return Result::error("添加失败", 0);
  3407. }
  3408. return Result::success($result);
  3409. }
  3410. public function delJobHunting(array $data): array
  3411. {
  3412. $result = JobHunting::where('id', $data['id'])->delete();
  3413. if (empty($result)) {
  3414. return Result::error("删除失败", 0);
  3415. }
  3416. return Result::success($result);
  3417. }
  3418. public function updateJobHunting(array $data): array
  3419. {
  3420. //设置东八区
  3421. date_default_timezone_set('Asia/Shanghai');
  3422. unset($data['company_name']);
  3423. unset($data['job_industry']);
  3424. unset($data['job_name']);
  3425. unset($data['department']);
  3426. unset($data['job_timeList']);
  3427. unset($data['job_content']);
  3428. $data['created_at'] = date('Y-m-d H:i:s');
  3429. $data['updated_at'] = date('Y-m-d H:i:s');
  3430. $result = JobHunting::where('id', $data['id'])->update($data);
  3431. if (empty($result)) {
  3432. return Result::error("更新失败", 0);
  3433. }
  3434. return Result::success($result);
  3435. }
  3436. public function getJobHuntingInfo(array $data): array
  3437. {
  3438. $result = JobHunting::where('id', $data['id'])->first();
  3439. if (empty($result)) {
  3440. return Result::error("查询失败", 0);
  3441. }
  3442. return Result::success($result);
  3443. }
  3444. public function getJobHuntingData(array $data): array
  3445. {
  3446. $jobEnum = JobEnum::get();
  3447. $jobIndustry = JobIndustry::get();
  3448. $jobNature = JobNature::get();
  3449. $jobPosition = JobPosition::get();
  3450. $data = [
  3451. 'jobEnum' => $jobEnum,
  3452. 'jobIndustry' => $jobIndustry,
  3453. 'jobNature' => $jobNature,
  3454. 'jobPosition' => $jobPosition,
  3455. ];
  3456. return Result::success($data);
  3457. }
  3458. public function delJobHuntingInfo(array $data): array
  3459. {
  3460. $result = JobHunting::where('id', $data['id'])->delete();
  3461. return Result::success();
  3462. }
  3463. //20250324 通知,公告,消息
  3464. public function delNotice(array $data): array
  3465. {
  3466. $result = Notice::where('id', $data['id'])->delete();
  3467. if ($result) {
  3468. return Result::success();
  3469. } else {
  3470. return Result::error("删除失败", 0);
  3471. }
  3472. }
  3473. public function getNoticeInfo(array $data): array
  3474. {
  3475. $result = Notice::where('id', $data['id'])->first();
  3476. if (empty($result)) {
  3477. return Result::error("查询失败", 0);
  3478. }
  3479. return Result::success($result);
  3480. }
  3481. public function addNotice(array $data): array
  3482. {
  3483. date_default_timezone_set('Asia/Shanghai');
  3484. $data['created_at'] = date('Y-m-d H:i:s');
  3485. $data['updated_at'] = date('Y-m-d H:i:s');
  3486. $user_id = UserInfo::
  3487. //city_id不是null
  3488. whereNotNull('city_id')
  3489. ->whereNotNull('department_id')
  3490. ->where(function ($query) use ($data) {
  3491. $query->where(function ($subQuery) use ($data) {
  3492. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3493. });
  3494. })
  3495. ->where(function ($query) use ($data) {
  3496. $query->where(function ($subQuery) use ($data) {
  3497. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3498. });
  3499. })
  3500. ->pluck('user_id')->toArray();
  3501. $user_id = array_unique($user_id);
  3502. $chat_ids = $user_id;
  3503. $user_id = json_encode($user_id);
  3504. $data['re_user_ids'] = $user_id;
  3505. $result = Notice::insertGetId($data);
  3506. if ($result && $data['is_group'] == 1) {
  3507. //chat_group
  3508. $group_id = PublicData::uuid();
  3509. $groupData = [
  3510. 'id' => $group_id,
  3511. 'creator_id' => $data['user_id'],
  3512. 'group_name' => $data['group_name'] ?? '',
  3513. 'profile' => $data['profile'] ?? 0,
  3514. ];
  3515. $groupResult = ChatGroups::insertGetId($groupData);
  3516. var_dump($groupResult, '-----------------groupid-------');
  3517. $groupMemberData = [
  3518. 'id' => PublicData::uuid(),
  3519. 'user_id' => $data['user_id'],
  3520. 'group_id' => $group_id,
  3521. 'leader' => 2,
  3522. ];
  3523. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3524. //$chat_ids 去除掉$data['user_id']
  3525. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3526. //插入群成员表
  3527. $groupMemberDataUser = [];
  3528. foreach ($chat_ids as $key => $value) {
  3529. $groupMemberDataUser[] = [
  3530. 'id' => PublicData::uuid(),
  3531. 'user_id' => $value,
  3532. 'group_id' => $group_id,
  3533. 'leader' => 1,
  3534. ];
  3535. }
  3536. ChatGroupsMember::insert($groupMemberDataUser);
  3537. //更新result的 group_id
  3538. $data['group_id'] = $group_id;
  3539. Notice::where(['id' => $result])->update($data);
  3540. }
  3541. if (empty($result)) {
  3542. return Result::error("添加失败", 0);
  3543. }
  3544. return Result::success($result);
  3545. }
  3546. public function updateNotice(array $data): array
  3547. {
  3548. date_default_timezone_set('Asia/Shanghai');
  3549. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3550. $user_id = UserInfo::
  3551. //city_id不是null
  3552. whereNotNull('city_id')
  3553. ->whereNotNull('department_id')
  3554. ->where(function ($query) use ($data) {
  3555. $query->where(function ($subQuery) use ($data) {
  3556. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3557. });
  3558. })
  3559. ->where(function ($query) use ($data) {
  3560. $query->where(function ($subQuery) use ($data) {
  3561. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3562. });
  3563. })
  3564. ->pluck('user_id')->toArray();
  3565. $user_id = array_unique($user_id);
  3566. $user_id = json_encode($user_id);
  3567. $data['re_user_ids'] = $user_id;
  3568. $data['updated_at'] = date('Y-m-d H:i:s');
  3569. $result = Notice::where('id', $data['id'])->update($data);
  3570. return Result::success($result);
  3571. }
  3572. public function getNoticeList(array $data): array
  3573. {
  3574. $where = [];
  3575. //title
  3576. if (isset($data['title']) && !empty($data['title'])) {
  3577. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3578. }
  3579. //level
  3580. if (isset($data['level']) && !empty($data['level'])) {
  3581. $where[] = ['notice.level', '=', $data['level']];
  3582. }
  3583. //status
  3584. if (isset($data['status']) && !empty($data['status'])) {
  3585. $where[] = ['notice.status', '=', $data['status']];
  3586. }
  3587. var_dump($data['type_id'], '-----------------test---------');
  3588. if ($data['type_id'] == 10000) {
  3589. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3590. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3591. })
  3592. ->where($where)
  3593. ->orderBy('updated_at', 'desc')
  3594. ->limit($data['page_size'])
  3595. ->offset(($data['page'] - 1) * $data['page_size'])
  3596. ->get();
  3597. } else {
  3598. $result = Notice::where('status', 1)
  3599. ->where($where)
  3600. ->where('user_id', $data['user_id'])
  3601. ->orWhere(function ($query) use ($data) {
  3602. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  3603. })
  3604. ->orderBy('updated_at', 'desc')
  3605. ->limit($data['page_size'])
  3606. ->offset(($data['page'] - 1) * $data['page_size'])
  3607. ->get();
  3608. }
  3609. if (empty($result)) {
  3610. return Result::error("查询失败", 0);
  3611. }
  3612. $count = Notice::where('status', 1)->count();
  3613. $data = [
  3614. 'rows' => $result,
  3615. 'count' => $count,
  3616. ];
  3617. return Result::success($data);
  3618. }
  3619. public function getNoticeDetail(array $data): array
  3620. {
  3621. $result = Notice::where('id', $data['id'])->first();
  3622. if (empty($result)) {
  3623. return Result::error("查询失败", 0);
  3624. }
  3625. return Result::success($result);
  3626. }
  3627. public function deleteNotice(array $data): array
  3628. {
  3629. $notice = Notice::where('id', $data['id'])->first();
  3630. if (empty($notice)) {
  3631. return Result::error("删除失败", 0);
  3632. }
  3633. $chat_group_id = $notice->group_id;
  3634. if ($chat_group_id) {
  3635. //删除群聊
  3636. ChatGroups::where('id', $chat_group_id)->delete();
  3637. //删除群成员
  3638. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3639. //删除群聊记录
  3640. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3641. }
  3642. $result = Notice::where('id', $data['id'])->delete();
  3643. return Result::success($result);
  3644. }
  3645. public function getMSG(array $data): array
  3646. {
  3647. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3648. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3649. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3650. $result = [];
  3651. if ($type_id == 1) {
  3652. //最近的5篇已审的文章
  3653. $apply_articale = Article::where('status', 1)
  3654. ->where('admin_user_id', $user_id)
  3655. ->orderBy('updated_at', 'desc')
  3656. ->limit(5)->get();
  3657. //获取5条单聊未读聊天消息
  3658. $chat = ChatRecords::where('is_read', 0)
  3659. ->where('user_id', $user_id)
  3660. ->where('talk_type', 1)
  3661. ->orderBy('created_at', 'desc')
  3662. ->limit(5)->get();
  3663. //获取5条未读群聊信息
  3664. $chat_group = ChatRecords::where('is_read', 0)
  3665. ->where('user_id', $user_id)
  3666. ->where('talk_type', 2)
  3667. ->orderBy('created_at', 'desc')
  3668. ->limit(5)->get();
  3669. //获取5条用户的已审核商品
  3670. $good = Good::where('status', 2)
  3671. ->where('user_id', $user_id)
  3672. ->orderBy('updated_at', 'desc')
  3673. ->limit(5)->get();
  3674. //获取5条用户待审核的公告
  3675. $notice = Notice::where('status', 2)
  3676. ->where('user_id', $user_id)
  3677. ->orderBy('updated_at', 'desc')
  3678. ->limit(5)->get();
  3679. //获取5条用户的待审核投诉
  3680. $complaint = Complaint::where('status', 2)
  3681. ->where('user_id', $user_id)
  3682. ->orderBy('updated_at', 'desc')
  3683. ->limit(5)->get();
  3684. //获取5条用户的book
  3685. $book = Book::where('status', 2)
  3686. ->where('user_id', $user_id)
  3687. ->orderBy('updated_at', 'desc')
  3688. ->limit(5)->get();
  3689. //获取5条用户的求职
  3690. //获取5条用户的求职 1
  3691. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3692. ->where('job_hunting.user_id', $user_id)
  3693. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3694. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3695. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3696. ->orderBy('updated_at', 'desc')
  3697. ->limit(5)->get();
  3698. //获取5条用户的求职 2
  3699. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3700. ->where('job_recruiting.user_id', $user_id)
  3701. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3702. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3703. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3704. ->orderBy('updated_at', 'desc')
  3705. ->limit(5)->get();
  3706. //人才库 1
  3707. $job_apply = JobApply::where('job_apply.status', 1)
  3708. ->where('job_apply.receiver_id', $user_id)
  3709. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3710. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3711. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3712. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3713. ->select('job_recruiting', 'job_recruiting.', '', '')
  3714. ->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')
  3715. ->orderBy('updated_at', 'desc')
  3716. ->limit(5)->get();
  3717. // 职场机会 2
  3718. $job_resume = JobResume::where('job_resume.status', 1)
  3719. ->where('job_resume.receiver_id', $user_id)
  3720. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3721. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3722. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3723. ->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')
  3724. ->orderBy('updated_at', 'desc')
  3725. ->limit(5)->get();
  3726. $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);
  3727. $result = [
  3728. 'apply_articale' => $apply_articale,
  3729. 'chat' => $chat,
  3730. 'chat_group' => $chat_group,
  3731. 'good' => $good,
  3732. 'notice' => $notice,
  3733. 'complaint' => $complaint,
  3734. 'book' => $book,
  3735. 'job_hunting' => $job_hunting,
  3736. 'job_recruiting' => $job_recruiting,
  3737. 'job_apply' => $job_apply,
  3738. 'job_resume' => $job_resume,
  3739. 'count' => $count,
  3740. ];
  3741. } elseif ($type_id == 2) {
  3742. //最近的5篇已审的文章
  3743. $apply_articale = Article::where('status', 1)
  3744. ->where('admin_user_id', $user_id)
  3745. ->limit(5)->get();
  3746. //获取5条单聊未读聊天消息
  3747. $chat = ChatRecords::where('is_read', 0)
  3748. ->where('user_id', $user_id)
  3749. ->where('talk_type', 1)
  3750. ->orderBy('created_at', 'desc')
  3751. ->limit(5)->get();
  3752. //获取5条未读群聊信息
  3753. $chat_group = ChatRecords::where('is_read', 0)
  3754. ->where('user_id', $user_id)
  3755. ->where('talk_type', 2)
  3756. ->orderBy('created_at', 'desc')
  3757. ->limit(5)->get();
  3758. //获取5条用户的已审核商品
  3759. $good = Good::where('status', 2)
  3760. ->where('user_id', $user_id)
  3761. ->orderBy('updated_at', 'desc')
  3762. ->limit(5)->get();
  3763. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3764. $result = [
  3765. 'apply_articale' => $apply_articale,
  3766. 'chat' => $chat,
  3767. 'chat_group' => $chat_group,
  3768. 'good' => $good,
  3769. 'count' => $count,
  3770. ];
  3771. } elseif ($type_id == 3) {
  3772. //最近的5篇已审的文章
  3773. $apply_articale = Article::where('status', 1)
  3774. ->where('admin_user_id', $user_id)
  3775. ->limit(5)->get();
  3776. //获取5条单聊未读聊天消息
  3777. $chat = ChatRecords::where('is_read', 0)
  3778. ->where('user_id', $user_id)
  3779. ->where('talk_type', 1)
  3780. ->orderBy('created_at', 'desc')
  3781. ->limit(5)->get();
  3782. //获取5条未读群聊信息
  3783. $chat_group = ChatRecords::where('is_read', 0)
  3784. ->where('user_id', $user_id)
  3785. ->where('talk_type', 2)
  3786. ->orderBy('created_at', 'desc')
  3787. ->limit(5)->get();
  3788. //获取5条用户的已审核商品
  3789. $good = Good::where('status', 2)
  3790. ->where('user_id', $user_id)
  3791. ->orderBy('updated_at', 'desc')
  3792. ->limit(5)->get();
  3793. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3794. $result = [
  3795. 'apply_articale' => $apply_articale,
  3796. 'chat' => $chat,
  3797. 'chat_group' => $chat_group,
  3798. 'good' => $good,
  3799. 'count' => $count,
  3800. ];
  3801. } elseif ($type_id == 4) {
  3802. //最近的5篇已审的文章
  3803. $apply_articale = Article::where('status', 1)
  3804. ->where('admin_user_id', $user_id)
  3805. ->limit(5)->get();
  3806. //获取5条用户的已审核商品
  3807. $good = Good::where('status', 2)
  3808. ->where('user_id', $user_id)
  3809. ->orderBy('updated_at', 'desc')
  3810. ->limit(5)->get();
  3811. $count = count($apply_articale) + count($good);
  3812. $result = [
  3813. 'apply_articale' => $apply_articale,
  3814. 'chat' => '',
  3815. 'chat_group' => '',
  3816. 'good' => $good,
  3817. 'count' => $count,
  3818. ];
  3819. } elseif ($type_id == 10000) {
  3820. //获取未审核的5篇文章
  3821. $apply_articale = Article::where('status', 0)
  3822. ->orderBy('updated_at', 'desc')
  3823. ->limit(5)->get();
  3824. //获取5条单聊未读聊天消息
  3825. $chat = ChatRecords::where('is_read', 0)
  3826. ->where('user_id', $user_id)
  3827. ->where('talk_type', 1)
  3828. ->orderBy('created_at', 'desc')
  3829. ->limit(5)->get();
  3830. //获取5条未读群聊信息
  3831. $chat_group = ChatRecords::where('is_read', 0)
  3832. ->where('user_id', $user_id)
  3833. ->where('talk_type', 2)
  3834. ->orderBy('created_at', 'desc')
  3835. ->limit(5)->get();
  3836. //获取5条用户的已审核商品
  3837. $good = Good::where('status', 1)
  3838. // ->where('user_id', $user_id)
  3839. ->orderBy('updated_at', 'desc')
  3840. ->limit(5)->get();
  3841. //获取5条用户待审核的公告
  3842. $notice = Notice::where('status', 1)
  3843. ->orderBy('updated_at', 'desc')
  3844. ->limit(5)->get();
  3845. //获取5条用户的待审核投诉
  3846. $complaint = Complaint::where('status', 1)
  3847. ->orderBy('updated_at', 'desc')
  3848. ->limit(5)->get();
  3849. //获取5条用户的book
  3850. $book = Book::where('status', 1)
  3851. ->orderBy('updated_at', 'desc')
  3852. ->limit(5)->get();
  3853. //获取5条用户的求职 1
  3854. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3855. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3856. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3857. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3858. ->orderBy('updated_at', 'desc')
  3859. ->limit(5)->get();
  3860. //获取5条用户的求职 2
  3861. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3862. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3863. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3864. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3865. ->orderBy('updated_at', 'desc')
  3866. ->limit(5)->get();
  3867. //人才库 1
  3868. $job_apply = JobApply::where('job_apply.status', 1)
  3869. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3870. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3871. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3872. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3873. ->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')
  3874. ->orderBy('updated_at', 'desc')
  3875. ->limit(5)->get();
  3876. // 职场机会 2
  3877. $job_resume = JobResume::where('job_resume.status', 1)
  3878. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3879. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3880. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3881. ->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')
  3882. ->orderBy('updated_at', 'desc')
  3883. ->limit(5)->get();
  3884. $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);
  3885. $result = [
  3886. 'apply_articale' => $apply_articale,
  3887. 'chat' => $chat,
  3888. 'chat_group' => $chat_group,
  3889. 'good' => $good,
  3890. 'notice' => $notice,
  3891. 'complaint' => $complaint,
  3892. 'book' => $book,
  3893. 'job_hunting' => $job_hunting,
  3894. 'job_recruiting' => $job_recruiting,
  3895. 'job_apply' => $job_apply,
  3896. 'job_resume' => $job_resume,
  3897. 'count' => $count,
  3898. ];
  3899. } elseif ($type_id == 20000) {
  3900. }
  3901. var_dump($type_id, '-----------------test---------');
  3902. return Result::success($result);
  3903. }
  3904. public function getComplaintList(array $data): array
  3905. {
  3906. var_dump($data, '00000001000000000000');
  3907. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3908. unset($data['type_id']);
  3909. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3910. $where = [];
  3911. if ($type_id != 10000) {
  3912. $where['complaint.user_id'] = $user_id;
  3913. }
  3914. if (!empty($data['title'])) {
  3915. $where['complaint.title'] = ['like', '%' . $data['title'] . '%'];
  3916. }
  3917. if (!empty($data['deal'])) {
  3918. $where['complaint.deal'] = $data['deal'];
  3919. }
  3920. if (!empty($data['status'])) {
  3921. $where['complaint.status'] = $data['status'];
  3922. }
  3923. var_dump(!empty($data['deal_user']), '----------1');
  3924. $result = Complaint::where($where)
  3925. ->when(!empty($data['status1']), function ($query) use ($data) {
  3926. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  3927. })
  3928. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  3929. //json re_user_ids data[user_id]是不是在里面
  3930. $query->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')');
  3931. })
  3932. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  3933. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  3934. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  3935. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  3936. ->orderBy('updated_at', 'desc')
  3937. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  3938. //sql输出
  3939. if (empty($result)) {
  3940. return Result::error("暂无投诉信息", 0);
  3941. }
  3942. // 取出数据
  3943. $rows = $result->items();
  3944. $count = $result->total();
  3945. $responseData = [
  3946. 'rows' => $rows,
  3947. 'count' => $count,
  3948. ];
  3949. return Result::success($responseData);
  3950. }
  3951. public function getComplaintInfo(array $data): array
  3952. {
  3953. $result = Complaint::where('id', $data['id'])->first();
  3954. if (empty($result)) {
  3955. return Result::error("查询失败", 0);
  3956. }
  3957. return Result::success($result);
  3958. }
  3959. public function addComplaint(array $data): array
  3960. {
  3961. date_default_timezone_set('Asia/Shanghai');
  3962. $data['created_at'] = date('Y-m-d H:i:s');
  3963. $data['updated_at'] = date('Y-m-d H:i:s');
  3964. $result = Complaint::create($data);
  3965. return Result::success($result);
  3966. }
  3967. public function updateComplaint(array $data): array
  3968. {
  3969. date_default_timezone_set('Asia/Shanghai');
  3970. $data['updated_at'] = date('Y-m-d H:i:s');
  3971. $user_id = $data['user_id'] ?? 0;
  3972. $type_id = $data['type_id'] ?? 0;
  3973. unset($data['user_id']);
  3974. unset($data['type_id']);
  3975. $result = Complaint::where('id', $data['id'])->update($data);
  3976. return Result::success($result);
  3977. }
  3978. public function deleteComplaint(array $data): array
  3979. {
  3980. $result = Complaint::where('id', $data['id'])->delete();
  3981. return Result::success($result);
  3982. }
  3983. public function getComplainInfo(array $data): array
  3984. {
  3985. $result = Complaint::where('id', $data['id'])->first();
  3986. if (empty($result)) {
  3987. return Result::error("查询失败", 0);
  3988. }
  3989. return Result::success($result);
  3990. }
  3991. public function updateComplaintStatus(array $data): array
  3992. {
  3993. date_default_timezone_set('Asia/Shanghai');
  3994. $data['updated_at'] = date('Y-m-d H:i:s');
  3995. $user_id = $data['user_id'] ?? 0;
  3996. $type_id = $data['type_id'] ?? 0;
  3997. unset($data['user_id']);
  3998. unset($data['type_id']);
  3999. //处理, 写入处理人
  4000. if (isset($data['deal']) && ($data['deal'] == 1 || $data['deal'] == 4)) {
  4001. $data['real_deal_user'] = $user_id;
  4002. }
  4003. //如果是deal 23,则判断是不是处理人
  4004. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 3) && $type_id != 10000) {
  4005. $complaintInof = Complaint::where('id', $data['id'])
  4006. ->where('real_deal_user', $user_id)
  4007. ->first();
  4008. if (empty($complaintInof)) {
  4009. return Result::error("处理人错误", 0);
  4010. }
  4011. }
  4012. $result = complaint::where('id', $data['id'])->update($data);
  4013. return Result::success($result);
  4014. }
  4015. public function updateGoodStatus(array $data): array
  4016. {
  4017. $user_id = $data['user_id'] ?? 0;
  4018. $type_id = $data['type_id'] ?? 0;
  4019. unset($data['user_id']);
  4020. unset($data['type_id']);
  4021. $result = Good::where('id', $data['id'])->update($data);
  4022. return Result::success($result);
  4023. }
  4024. public function updateJobHuntingStatus(array $data): array
  4025. {
  4026. $user_id = $data['user_id'] ?? 0;
  4027. $type_id = $data['type_id'] ?? 0;
  4028. unset($data['user_id']);
  4029. unset($data['type_id']);
  4030. $result = JobHunting::where('id', $data['id'])->update($data);
  4031. return Result::success($result);
  4032. }
  4033. public function updateNoticeStatus(array $data): array
  4034. {
  4035. $user_id = $data['user_id'] ?? 0;
  4036. $type_id = $data['type_id'] ?? 0;
  4037. unset($data['user_id']);
  4038. unset($data['type_id']);
  4039. $result = Notice::where('id', $data['id'])->update($data);
  4040. return Result::success($result);
  4041. }
  4042. public function getDUser(array $data): array
  4043. {
  4044. if (!empty($data['ids'])) {
  4045. $user = User::whereIn('id', $data['ids'])->getall();
  4046. if (empty($user)) {
  4047. return Result::error('无数据', 0);
  4048. }
  4049. return Result::success($user);
  4050. }
  4051. $where = [];
  4052. if (!empty($data['department_id'])) {
  4053. $where['department_id'] = $data['department_id'];
  4054. }
  4055. if (!empty($data['city_id'])) {
  4056. $where['city_id'] = $data['city_id'];
  4057. }
  4058. $result = User::where('type_id', 2)
  4059. ->where('status', 1)
  4060. ->where($where)
  4061. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4062. ->get();
  4063. if (empty($result)) {
  4064. return Result::error("查询失败", 0);
  4065. }
  4066. return Result::success($result);
  4067. }
  4068. //20250324 通知,公告,消息
  4069. // 20250306 -------招聘--------fr
  4070. /*
  4071. * 招聘列表
  4072. * */
  4073. public function getJobRecruitingList(array $data): array
  4074. {
  4075. $where = [];
  4076. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4077. if ($data['checkout'] == 0) {
  4078. $job_status = [0, 2];
  4079. } else {
  4080. $job_status = [1];
  4081. }
  4082. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4083. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4084. }
  4085. $user = User::where('id', $data['user_id'])->first();
  4086. if (empty($user)) {
  4087. return Result::error("用户不存在", 0);
  4088. }
  4089. // 3:企业会员
  4090. if ($user['type_id'] == 3) {
  4091. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4092. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4093. }
  4094. // 如果 $where 为空,则不添加 where 条件
  4095. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4096. return $query->where($where);
  4097. })
  4098. ->whereIn('job_recruiting.status', $job_status)
  4099. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4100. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4101. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4102. ->orderBy("updated_at", "desc")
  4103. ->offset(($data['page'] - 1) * $data['page_size'])
  4104. ->limit($data['page_size'])
  4105. ->get()
  4106. ->all();
  4107. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4108. return $query->where($where);
  4109. })
  4110. ->whereIn('job_recruiting.status', $job_status)
  4111. ->count();
  4112. if (empty($result)) {
  4113. return Result::error("暂无招聘信息", 0);
  4114. }
  4115. return Result::success($result);
  4116. }
  4117. /*
  4118. * 招聘信息添加
  4119. * */
  4120. public function addJobRecruiting(array $data): array
  4121. {
  4122. // return Result::success($data);
  4123. $user = User::where('user.id', $data['user_id'])
  4124. ->where('user.status', 1)
  4125. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4126. ->select(
  4127. 'user.type_id',
  4128. 'user.mobile',
  4129. 'user.email',
  4130. 'user_info.business_name',
  4131. 'user_info.company_hy_id',
  4132. 'user_info.company_nature',
  4133. 'user_info.company_size',
  4134. 'user_info.introduction',
  4135. 'user_info.real_name',
  4136. 'user_info.company_url',
  4137. 'user_info.address_arr_id',
  4138. 'user_info.address'
  4139. )
  4140. ->first();
  4141. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4142. return Result::error("用户不存在", 0);
  4143. }
  4144. $web = Website::where('id', $data['website_id'])->first();
  4145. if (empty($web)) {
  4146. return Result::error("网站不存在", 0);
  4147. }
  4148. // return Result::success($user);
  4149. $data['action_id'] = $data['user_id'];
  4150. $data['user_type'] = $user['type_id'];
  4151. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4152. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4153. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4154. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4155. // 公司地址 管理员必填
  4156. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4157. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4158. // 管理员-企业相关信息
  4159. $company = [
  4160. // 'user_id' => $data['user_id']?? null,
  4161. 'business_name' => $data['business_name'] ?? null,
  4162. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4163. 'company_size' => $data['company_size'] ?? null,
  4164. 'company_nature' => $data['company_nature'] ?? null,
  4165. 'introduction' => $data['introduction'] ?? null,
  4166. 'real_name' => $data['real_name'] ?? null,
  4167. 'mobile' => $data['mobile'] ?? null,
  4168. 'company_url' => $data['company_url'] ?? null,
  4169. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4170. 'address' => $data['address'] ?? null,
  4171. 'email' => $data['email'] ?? null,
  4172. ];
  4173. //去掉相关企业信息
  4174. $job = array_diff_key($data, array_flip(array_keys($company)));
  4175. Db::beginTransaction();
  4176. try {
  4177. // 先添加职位相关信息
  4178. if ($user['type_id'] == 10000) {
  4179. $job['status'] = 1;
  4180. }
  4181. $jobId = JobRecruiting::insertGetId($job);
  4182. if (empty($jobId)) {
  4183. Db::rollBack();
  4184. return Result::error("添加失败");
  4185. }
  4186. // 添加公司信息
  4187. $company['user_id'] = $data['user_id'] ?? null;
  4188. $company['job_id'] = $jobId;
  4189. $company['user_type'] = $user['type_id'] ?? null;
  4190. $company['website_id'] = $data['website_id'] ?? null;
  4191. if ($user['type_id'] == 10000) {
  4192. // 管理员添加企业信息
  4193. // return Result::success($company);
  4194. $companyId = JobCompany::insertGetId($company);
  4195. if (empty($companyId)) {
  4196. Db::rollBack();
  4197. return Result::error("添加失败");
  4198. }
  4199. } else {
  4200. // 企业会员添加企业信息
  4201. $company = [
  4202. 'user_id' => $data['user_id'] ?? null,
  4203. 'business_name' => $user['business_name'] ?? null,
  4204. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4205. 'company_size' => $user['company_size'] ?? null,
  4206. 'company_nature' => $user['company_nature'] ?? null,
  4207. 'introduction' => $user['introduction'] ?? null,
  4208. 'real_name' => $user['real_name'] ?? null,
  4209. 'mobile' => $user['mobile'] ?? null,
  4210. 'company_url' => $user['company_url'] ?? null,
  4211. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4212. 'address' => $user['address'] ?? null,
  4213. 'email' => $user['email'] ?? null,
  4214. 'website_id' => $data['website_id'] ?? null,
  4215. 'user_type' => $user['type_id'] ?? null,
  4216. 'job_id' => $jobId,
  4217. ];
  4218. $companyId = JobCompany::insertGetId($company);
  4219. if (empty($companyId)) {
  4220. Db::rollBack();
  4221. return Result::error("添加失败");
  4222. }
  4223. // return Result::success($company);
  4224. }
  4225. Db::commit();
  4226. } catch (\Exception $e) {
  4227. Db::rollBack();
  4228. return Result::error($e->getMessage(), 0);
  4229. }
  4230. $result = [
  4231. 'job_id' => $jobId,
  4232. 'company_id' => $companyId,
  4233. ];
  4234. if (empty($result)) {
  4235. return Result::error("添加失败", 0);
  4236. }
  4237. return Result::success($result);
  4238. }
  4239. /*
  4240. * 获取招聘信息详情
  4241. * */
  4242. public function getJobRecruitingInfo(array $data): array
  4243. {
  4244. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4245. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4246. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4247. ->select(
  4248. 'job_recruiting.*',
  4249. 'website.website_name as website_name',
  4250. 'job_company.business_name',
  4251. 'job_company.company_hy_id',
  4252. 'job_company.company_size',
  4253. 'job_company.company_nature',
  4254. 'job_company.introduction',
  4255. 'job_company.real_name',
  4256. 'job_company.mobile',
  4257. 'job_company.company_url',
  4258. 'job_company.address_arr_id',
  4259. 'job_company.address',
  4260. 'job_company.email'
  4261. )
  4262. ->first();
  4263. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4264. if (!empty($cityId)) {
  4265. if (isset($cityId[1]) && $cityId[1] != null) {
  4266. $city = District::where('id', $cityId[1])->first(['name']);
  4267. } else {
  4268. $city = District::where('id', $cityId[0])->first(['name']);
  4269. }
  4270. $result['city'] = $city['name'] ?? '';
  4271. }
  4272. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4273. if (is_array($addressId) && !empty($addressId)) {
  4274. $address = District::whereIn('id', $addressId)
  4275. ->orderBy('level', 'asc')
  4276. ->get(['name'])
  4277. ->pluck('name')
  4278. ->implode('');
  4279. // $job->address_name = $address ?? '';
  4280. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4281. }
  4282. if (empty($result)) {
  4283. return Result::error("招聘信息不存在", 0);
  4284. }
  4285. // return Result::success($job);
  4286. return Result::success($result);
  4287. }
  4288. /*
  4289. * 修改招聘信息
  4290. * */
  4291. public function upJobRecruiting(array $data): array
  4292. {
  4293. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4294. // return Result::success($job);
  4295. if (empty($job)) {
  4296. return Result::error("招聘信息不存在", 0);
  4297. }
  4298. $user = User::where('id', $data['user_id'])->first();
  4299. // return Result::success($user);
  4300. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4301. return Result::error("用户不存在", 0);
  4302. }
  4303. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4304. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4305. }
  4306. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4307. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4308. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4309. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4310. // 公司地址 管理员必填
  4311. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4312. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4313. // 管理员-企业相关信息
  4314. $company = [
  4315. 'business_name' => $data['business_name'] ?? null,
  4316. 'company_hy_id' => $data['hy_id'] ?? null,
  4317. 'company_size' => $data['company_size'] ?? null,
  4318. 'company_nature' => $data['company_nature'] ?? null,
  4319. 'introduction' => $data['introduction'] ?? null,
  4320. 'real_name' => $data['real_name'] ?? null,
  4321. 'mobile' => $data['mobile'] ?? null,
  4322. 'company_url' => $data['company_url'] ?? null,
  4323. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4324. 'address' => $data['address'] ?? null,
  4325. 'email' => $data['email'] ?? null,
  4326. ];
  4327. //去掉相关企业信息
  4328. $data = array_diff_key($data, array_flip(array_keys($company)));
  4329. $jobId = $data['id'];
  4330. $web = $data['website_id'];
  4331. $data['action_id'] = $data['user_id'];
  4332. unset($data['user_id']);
  4333. unset($data['user_type']);
  4334. unset($data['id']);
  4335. unset($data['website_id']);
  4336. // return Result::success($data);
  4337. Db::beginTransaction();
  4338. try {
  4339. // 管理员修改招聘信息
  4340. if ($user['type_id'] == 10000) {
  4341. $data['website_id'] = $web;
  4342. $company['website_id'] = $data['website_id'];
  4343. $data['status'] = 1;
  4344. } else {
  4345. $data['status'] = 0;
  4346. }
  4347. // Db::rollBack();
  4348. // return Result::success($company);
  4349. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4350. if (empty($result['job'])) {
  4351. Db::rollBack();
  4352. return Result::error("修改招聘信息失败");
  4353. }
  4354. // 管理员修改企业相关信息
  4355. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4356. if (empty($result['company'])) {
  4357. Db::rollBack();
  4358. return Result::error("修改企业相关信息失败");
  4359. }
  4360. Db::commit();
  4361. // return Result::success($result);
  4362. } catch (\Exception $e) {
  4363. Db::rollBack();
  4364. return Result::error($e->getMessage(), 0);
  4365. }
  4366. return Result::success($result);
  4367. }
  4368. /*
  4369. * 招聘信息删除
  4370. * */
  4371. public function delJobRecruiting(array $data): array
  4372. {
  4373. $user = User::where('id', $data['user_id'])->first();
  4374. if (empty($user)) {
  4375. return Result::error("用户不存在", 0);
  4376. }
  4377. $job = JobRecruiting::where('id', $data['id'])->first();
  4378. if (empty($job)) {
  4379. return Result::error("招聘信息不存在", 0);
  4380. }
  4381. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4382. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4383. }
  4384. Db::beginTransaction();
  4385. try {
  4386. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4387. if (empty($result['job'])) {
  4388. Db::rollBack();
  4389. return Result::error("删除招聘信息失败");
  4390. }
  4391. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4392. if (empty($result['company'])) {
  4393. Db::rollBack();
  4394. return Result::error("删除企业相关信息失败");
  4395. }
  4396. Db::commit();
  4397. } catch (\Exception $e) {
  4398. Db::rollBack();
  4399. return Result::error($e->getMessage(), 0);
  4400. }
  4401. return Result::success($result);
  4402. }
  4403. /*
  4404. * 获取公司信息
  4405. * */
  4406. public function getJobCompany(array $data): array
  4407. {
  4408. $user = User::where('user.id', $data['user_id'])
  4409. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4410. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4411. ->first();
  4412. // return Result::success($user);
  4413. if (empty($user)) {
  4414. return Result::error("用户不存在", 0);
  4415. }
  4416. if ($user['type_id'] == 3) {
  4417. $result = [
  4418. // 'id' => 0,
  4419. 'user_id' => $data['user_id'],
  4420. 'website_id' => $data['website_id'],
  4421. 'business_name' => $user['business_name'], // 企业名称
  4422. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4423. 'company_nature' => $user['company_nature'], // 公司性质
  4424. 'company_size' => $user['company_size'], // 公司规模
  4425. 'introduction' => $user['introduction'], // 公司简介
  4426. 'real_name' => $user['real_name'], // 企业联系人
  4427. 'mobile' => $user['mobile'], // 企业联系电话
  4428. 'company_url' => $user['company_url'], // 企业网址
  4429. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4430. 'address' => $user['address'], // 企业地址
  4431. 'email' => $user['email'], // 企业邮箱
  4432. ];
  4433. } else {
  4434. return Result::error("用户类型错误", 0);
  4435. }
  4436. if (empty($result)) {
  4437. return Result::error("公司信息不存在", 0);
  4438. }
  4439. return Result::success($result);
  4440. }
  4441. /*
  4442. * 修改公司信息
  4443. * */
  4444. public function upJobCompany(array $data): array
  4445. {
  4446. // return Result::success($data);
  4447. $user = User::where('user.id', $data['user_id'])
  4448. ->where('user.status', 1)
  4449. ->select('user.user_name', 'user.type_id')
  4450. ->first();
  4451. if (empty($user)) {
  4452. return Result::error("用户不存在", 0);
  4453. }
  4454. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4455. $company = [
  4456. 'business_name' => $data['business_name'], // 企业名称
  4457. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4458. 'company_nature' => $data['company_nature'], // 公司性质
  4459. 'company_size' => $data['company_size'], // 公司规模
  4460. 'introduction' => $data['introduction'], // 公司简介
  4461. // 'real_name' => $data['real_name'], // 企业联系人
  4462. 'company_url' => $data['company_url'], // 企业网址
  4463. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4464. 'address' => $data['address'], // 企业详细地址
  4465. ];
  4466. if ($user['type_id'] == 3) {
  4467. Db::beginTransaction();
  4468. try {
  4469. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4470. 'business_name' => $data['business_name'], // 企业名称
  4471. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4472. 'company_nature' => $data['company_nature'], // 公司性质
  4473. 'company_size' => $data['company_size'], // 公司规模
  4474. 'introduction' => $data['introduction'], // 公司简介
  4475. // 'real_name' => $data['real_name'], // 企业联系人
  4476. 'company_url' => $data['company_url'], // 企业网址
  4477. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4478. 'address' => $data['address'], // 企业详细地址
  4479. ]);
  4480. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4481. Db::commit();
  4482. } catch (\Exception $e) {
  4483. Db::rollBack();
  4484. return Result::error($e->getMessage(), 0);
  4485. }
  4486. } else {
  4487. return Result::error("用户类型错误", 0);
  4488. }
  4489. if (empty($result)) {
  4490. return Result::error("修改失败", 0);
  4491. }
  4492. return Result::success($result);
  4493. }
  4494. /*
  4495. * 获取省-市
  4496. * */
  4497. public function getJobRecruitingArea(array $data): array
  4498. {
  4499. if (isset($data['pid']) && $data['pid'] != null) {
  4500. $result = District::where('pid', $data['pid'])->get()->all();
  4501. } else {
  4502. $result = District::where('level', 1)->get()->all();
  4503. }
  4504. if (empty($result)) {
  4505. return Result::error("暂无此省市", 0);
  4506. }
  4507. return Result::success($result);
  4508. }
  4509. /*
  4510. * 获取行业分类
  4511. * */
  4512. public function getIndustry(array $data): array
  4513. {
  4514. $result = JobIndustry::get()->all();
  4515. if (empty($result)) {
  4516. return Result::error("暂无行业分类", 0);
  4517. }
  4518. return Result::success($result);
  4519. }
  4520. /*
  4521. * 获取职位
  4522. * */
  4523. public function getPositionList(array $data): array
  4524. {
  4525. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4526. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4527. } else {
  4528. $result = JobPosition::where('zwpid', 0)->get()->all();
  4529. }
  4530. if (empty($result)) {
  4531. return Result::error("暂无此职位", 0);
  4532. }
  4533. return Result::success($result);
  4534. }
  4535. /*
  4536. * 获取工作性质-菜单
  4537. * */
  4538. public function getJobNature(array $data): array
  4539. {
  4540. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4541. if (empty($result)) {
  4542. return Result::error("暂无工作性质", 0);
  4543. }
  4544. return Result::success($result);
  4545. }
  4546. /*
  4547. * 获取工作经验-菜单
  4548. * */
  4549. public function getExperience(array $data): array
  4550. {
  4551. $result = JobEnum::where('egroup', 'years')->get()->all();
  4552. if (empty($result)) {
  4553. return Result::error("暂无工作经验", 0);
  4554. }
  4555. return Result::success($result);
  4556. }
  4557. /*
  4558. * 获取学历-菜单
  4559. * */
  4560. public function getEducation(array $data): array
  4561. {
  4562. $result = JobEnum::where('egroup', 'education')->get()->all();
  4563. if (empty($result)) {
  4564. return Result::error("暂无学历", 0);
  4565. }
  4566. return Result::success($result);
  4567. }
  4568. /*
  4569. * 获取薪资-菜单
  4570. * */
  4571. public function getSalary(array $data): array
  4572. {
  4573. $result = JobEnum::where('egroup', 'income')->get()->all();
  4574. if (empty($result)) {
  4575. return Result::error("暂无薪资", 0);
  4576. }
  4577. return Result::success($result);
  4578. }
  4579. /*
  4580. * 获取语言-菜单
  4581. * */
  4582. public function getLanguage(array $data): array
  4583. {
  4584. $result = JobEnum::where('egroup', 'language')->get()->all();
  4585. if (empty($result)) {
  4586. return Result::error("暂无语言", 0);
  4587. }
  4588. return Result::success($result);
  4589. }
  4590. /*
  4591. * 获取掌握程度-菜单
  4592. * */
  4593. public function getLevel(array $data): array
  4594. {
  4595. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4596. if (empty($result)) {
  4597. return Result::error("暂无工作性质", 0);
  4598. }
  4599. return Result::success($result);
  4600. }
  4601. // 公司信息
  4602. /*
  4603. * 获取公司性质-菜单
  4604. * */
  4605. public function getCompanyNature(array $data): array
  4606. {
  4607. $result = JobNature::get()->all();
  4608. if (empty($result)) {
  4609. return Result::error("暂无公司性质", 0);
  4610. }
  4611. return Result::success($result);
  4612. }
  4613. /*
  4614. * 获取公司规模-菜单
  4615. * */
  4616. public function getCompanySize(array $data): array
  4617. {
  4618. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4619. if (empty($result)) {
  4620. return Result::error("暂无公司规模", 0);
  4621. }
  4622. return Result::success($result);
  4623. }
  4624. /*
  4625. * 招聘信息审核
  4626. * */
  4627. public function checkJobRecruiting(array $data): array
  4628. {
  4629. $user = User::where('id', $data['user_id'])->first();
  4630. if (empty($user)) {
  4631. return Result::error("用户不存在", 0);
  4632. }
  4633. $job = JobRecruiting::where('id', $data['id'])->first();
  4634. if (empty($job)) {
  4635. return Result::error("招聘信息不存在", 0);
  4636. }
  4637. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4638. if ($user['type_id'] != 10000) {
  4639. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4640. }
  4641. // 驳回原因
  4642. if ($data['status'] == 2) {
  4643. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4644. }
  4645. $data['action_id'] = $data['user_id'];
  4646. unset($data['user_id']);
  4647. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4648. if (empty($result)) {
  4649. return Result::error("审核失败", 0);
  4650. }
  4651. return Result::success($result);
  4652. }
  4653. public function myApplyList(array $data): array
  4654. {
  4655. $user = User::where('id', $data['user_id'])->first();
  4656. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4657. return Result::error("用户不存在", 0);
  4658. }
  4659. // 1:个人会员 职场机会
  4660. if ($user['type_id'] == 1) {
  4661. $where['user_id'] = $user['id'];
  4662. }
  4663. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4664. $query->where('recruit_id', $user['id']);
  4665. })
  4666. ->pluck('recruit_id');
  4667. $where = [];
  4668. if (isset($data['salary']) && $data['salary'] != null) {
  4669. $where['job_recruiting.salary'] = $data['salary'];
  4670. }
  4671. if (isset($data['experience']) && $data['experience'] != null) {
  4672. $where['job_recruiting.experience'] = $data['experience'];
  4673. }
  4674. if (isset($data['business_name']) && $data['business_name'] != null) {
  4675. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4676. }
  4677. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4678. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4679. ->where($where);
  4680. // ->count();
  4681. $count = $query->count();
  4682. $query = clone $query;
  4683. $job = $query
  4684. ->leftJoin('job_enum as income_enum', function ($join) {
  4685. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4686. ->where('income_enum.egroup', 'income');
  4687. })
  4688. ->leftJoin('job_enum as years_enum', function ($join) {
  4689. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4690. ->where('years_enum.egroup', 'years');
  4691. })
  4692. // ->where($where)
  4693. ->orderBy('job_recruiting.updated_at', 'desc')
  4694. ->select(
  4695. 'job_recruiting.id',
  4696. 'job_recruiting.title',
  4697. 'job_company.business_name',
  4698. 'income_enum.evalue as salary_evalue',
  4699. 'income_enum.ename as salary_ename',
  4700. 'years_enum.evalue as experience_evalue',
  4701. 'years_enum.ename as experience_ename',
  4702. 'job_recruiting.updated_at'
  4703. )
  4704. ->offset(($data['page'] - 1) * $data['pageSize'])
  4705. ->limit($data['pageSize'])
  4706. ->get()
  4707. ->all();
  4708. if (empty($job)) {
  4709. return Result::error("暂无招聘信息", 0);
  4710. }
  4711. $result = [
  4712. 'row' => $job,
  4713. 'count' => $count,
  4714. ];
  4715. return Result::success($result);
  4716. }
  4717. /*
  4718. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4719. * */
  4720. public function getRecruitingList(array $data): array
  4721. {
  4722. $user = User::where('id', $data['user_id'])->first();
  4723. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4724. return Result::error("用户不存在", 0);
  4725. }
  4726. // 1:个人会员 职场机会
  4727. if ($user['type_id'] == 1) {
  4728. $where['user_id'] = $user['id'];
  4729. }
  4730. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4731. $query->where('recruit_id', $user['id']);
  4732. })
  4733. ->pluck('recruit_id');
  4734. $where = [];
  4735. if (isset($data['salary']) && $data['salary'] != null) {
  4736. $where['job_recruiting.salary'] = $data['salary'];
  4737. }
  4738. if (isset($data['experience']) && $data['experience'] != null) {
  4739. $where['job_recruiting.experience'] = $data['experience'];
  4740. }
  4741. if (isset($data['business_name']) && $data['business_name'] != null) {
  4742. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4743. }
  4744. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4745. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4746. ->where($where);
  4747. // ->count();
  4748. $count = $query->count();
  4749. $query = clone $query;
  4750. $job = $query
  4751. ->leftJoin('job_enum as income_enum', function ($join) {
  4752. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4753. ->where('income_enum.egroup', 'income');
  4754. })
  4755. ->leftJoin('job_enum as years_enum', function ($join) {
  4756. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4757. ->where('years_enum.egroup', 'years');
  4758. })
  4759. // ->where($where)
  4760. ->orderBy('job_recruiting.updated_at', 'desc')
  4761. ->select(
  4762. 'job_recruiting.id',
  4763. 'job_recruiting.title',
  4764. 'job_company.business_name',
  4765. 'income_enum.evalue as salary_evalue',
  4766. 'income_enum.ename as salary_ename',
  4767. 'years_enum.evalue as experience_evalue',
  4768. 'years_enum.ename as experience_ename',
  4769. 'job_recruiting.updated_at'
  4770. )
  4771. ->offset(($data['page'] - 1) * $data['pageSize'])
  4772. ->limit($data['pageSize'])
  4773. ->get()
  4774. ->all();
  4775. if (empty($job)) {
  4776. return Result::error("暂无招聘信息", 0);
  4777. }
  4778. $result = [
  4779. 'row' => $job,
  4780. 'count' => $count,
  4781. ];
  4782. return Result::success($result);
  4783. }
  4784. /*
  4785. * 获取企业会员-招聘信息列表
  4786. * */
  4787. public function getRecruitingInfo(array $data): array
  4788. {
  4789. $user = User::where('id', $data['user_id'])->first();
  4790. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4791. return Result::error("用户不存在", 0);
  4792. }
  4793. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4794. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4795. ->select(
  4796. 'job_recruiting.*',
  4797. 'job_company.business_name',
  4798. 'job_company.company_hy_id',
  4799. 'job_company.company_size',
  4800. 'job_company.company_nature',
  4801. 'job_company.introduction',
  4802. 'job_company.real_name',
  4803. 'job_company.mobile',
  4804. 'job_company.company_url',
  4805. 'job_company.address_arr_id',
  4806. 'job_company.address',
  4807. 'job_company.email'
  4808. )
  4809. ->get();
  4810. if (empty($recruiting)) {
  4811. return Result::error("暂无招聘信息", 0);
  4812. }
  4813. return Result::success($recruiting);
  4814. }
  4815. /*
  4816. * 获取企业会员-我的沟通
  4817. * */
  4818. public function getJobResumeList(array $data): array
  4819. {
  4820. $user = User::where('id', $data['user_id'])->first();
  4821. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4822. return Result::error("用户不存在", 0);
  4823. }
  4824. $where = [];
  4825. if (isset($data['salary']) && $data['salary'] != null) {
  4826. $where['job_hunting.salary'] = $data['salary'];
  4827. }
  4828. if (isset($data['user_name']) && $data['user_name'] != null) {
  4829. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4830. }
  4831. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4832. $query->where('job_resume.user_id', $user['id']);
  4833. })
  4834. ->when(!empty($where), function ($query) use ($where) {
  4835. $query->where($where);
  4836. })
  4837. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  4838. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  4839. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  4840. ->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');
  4841. $count = $job->count();
  4842. if ($count == 0) {
  4843. return Result::error("暂无沟通记录", 0);
  4844. }
  4845. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  4846. ->offset(($data['page'] - 1) * $data['pageSize'])
  4847. ->limit($data['pageSize'])
  4848. ->get();
  4849. if (empty($jobs)) {
  4850. return Result::error("暂无沟通记录", 0);
  4851. }
  4852. $result['row'] = $this->processJob($jobs, '');
  4853. $result['count'] = $count;
  4854. return Result::success($result);
  4855. }
  4856. // 20250306 招聘
  4857. //20250422 书刊音像
  4858. public function addBook(array $data): array
  4859. {
  4860. // $user_id = $data['user_id'] ?? 0;
  4861. $type_id = $data['type_id'] ?? 0;
  4862. // $website_id = $data['website_id'] ?? 0;
  4863. // unset($data['user_id']);
  4864. unset($data['type_id']);
  4865. // unset($data['website_id']);
  4866. //处理数组
  4867. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4868. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4869. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4870. if ($data['img_url'] == '') {
  4871. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4872. preg_match_all($reg, $data['detail'], $matches);
  4873. if (isset($matches[1][0])) {
  4874. //截取varchar240
  4875. $data['img_url'] = substr($matches[1][0], 0, 240);
  4876. }
  4877. }
  4878. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4879. //提取标题+内容中的关键词
  4880. $data['keyword'] = $data['title'];
  4881. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4882. Jieba::init(); // 初始化 jieba-php
  4883. Finalseg::init();
  4884. $segList = Jieba::cut($data['keyword']);
  4885. $segList1 = array_slice($segList, 0, 8);
  4886. $data['keyword'] = implode(',', $segList1);
  4887. }
  4888. if ($data['description'] == '') {
  4889. //提取内容中的描述
  4890. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4891. }
  4892. var_dump($data, '--');
  4893. $result = Book::insertGetId($data);
  4894. if (empty($result)) {
  4895. return Result::error("添加失败", 0);
  4896. }
  4897. return Result::success($result);
  4898. }
  4899. public function getBookList(array $data): array
  4900. {
  4901. $where = [];
  4902. if (!empty($data["title"])) {
  4903. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  4904. }
  4905. if (!empty($data['website_name'])) {
  4906. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4907. }
  4908. if (!empty($data['status'])) {
  4909. $where[] = ['book.status', '=', $data['status']];
  4910. }
  4911. $user_id = $data['user_id'];
  4912. $type_id = $data['type_id'];
  4913. // $type_id = 4;
  4914. var_dump($type_id, '------1--------');
  4915. if ($type_id != 10000) {
  4916. $where[] = ['book.user_id', '=', $user_id];
  4917. }
  4918. var_dump(!empty($data['status1']), '=-===1');
  4919. $result = Book::where($where)
  4920. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  4921. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  4922. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  4923. ->when(isset($data['status1']), function ($query) use ($data) {
  4924. $query->whereIn('book.status', [1, 3]);
  4925. })
  4926. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  4927. ->orderBy("updated_at", "desc")
  4928. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4929. if (empty($result)) {
  4930. return Result::error("暂无数据", 0);
  4931. }
  4932. // 取出数据
  4933. $rows = $result->items();
  4934. $count = $result->total();
  4935. $responseData = [
  4936. 'rows' => $rows,
  4937. 'count' => $count,
  4938. ];
  4939. return Result::success($responseData);
  4940. }
  4941. public function deleteBook(array $data): array
  4942. {
  4943. $result = Book::where('id', $data['id'])->delete();
  4944. if (empty($result)) {
  4945. return Result::error("删除失败", 0);
  4946. }
  4947. return Result::success($result);
  4948. }
  4949. public function updateBook(array $data): array
  4950. {
  4951. // $user_id = $data['user_id'] ?? 0;
  4952. $type_id = $data['type_id'] ?? 0;
  4953. // $website_id = $data['website_id'] ?? 0;
  4954. unset($data['user_id']);
  4955. unset($data['type_id']);
  4956. // unset($data['website_id']);
  4957. //处理数组
  4958. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4959. if ($data['img_url'] == '') {
  4960. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4961. preg_match_all($reg, $data['detail'], $matches);
  4962. if (isset($matches[1][0])) {
  4963. //截取varchar240
  4964. $data['img_url'] = substr($matches[1][0], 0, 240);
  4965. }
  4966. }
  4967. if ($data['keyword'] == '') {
  4968. //提取标题+内容中的关键词
  4969. $data['keyword'] = $data['title'];
  4970. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4971. Jieba::init(); // 初始化 jieba-php
  4972. Finalseg::init();
  4973. $segList = Jieba::cut($data['keyword']);
  4974. $segList1 = array_slice($segList, 0, 8);
  4975. $data['keyword'] = implode(',', $segList1);
  4976. }
  4977. if ($data['description'] == '') {
  4978. //提取内容中的描述
  4979. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4980. }
  4981. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4982. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4983. $result = Book::where("id", $data["id"])->update($data);
  4984. if (empty($result)) {
  4985. return Result::error("更新失败", 0);
  4986. }
  4987. return Result::success($result);
  4988. }
  4989. public function getBookInfo(array $data): array
  4990. {
  4991. $result = Book::where("id", $data["id"])->first();
  4992. if (empty($result)) {
  4993. return Result::error("获取失败", 0);
  4994. }
  4995. return Result::success($result);
  4996. }
  4997. public function updateBookStatus(array $data): array
  4998. {
  4999. //审核
  5000. unset($data['user_id']);
  5001. $result = Book::where("id", $data["id"])->update($data);
  5002. if (empty($result)) {
  5003. return Result::error("更新失败", 0);
  5004. }
  5005. return Result::success($result);
  5006. }
  5007. //20250422 书刊音像
  5008. }