NewsService.php 204 KB

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