NewsService.php 222 KB

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