NewsService.php 222 KB

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