NewsService.php 236 KB

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