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