NewsService.php 211 KB

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