NewsService.php 223 KB

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