NewsService.php 254 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769
  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. sleep(1);
  1545. $query = Article::where('article.status', 1)
  1546. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1547. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1548. ->where(function ($query) use ($website) {
  1549. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1550. })
  1551. ->leftJoin('website_category', function ($join) use ($website) {
  1552. $join->on('article.catid', '=', 'website_category.category_id')
  1553. ->where('website_category.website_id', '=', $website['website_id']);
  1554. })
  1555. ->select(
  1556. 'article.id',
  1557. 'article.title',
  1558. 'article.imgurl',
  1559. 'article.author',
  1560. 'article.updated_at',
  1561. 'article.introduce',
  1562. 'article.islink',
  1563. 'article.linkurl',
  1564. 'article.copyfrom',
  1565. 'article.cat_arr_id',
  1566. 'article.catid',
  1567. 'website_category.alias as category_name'
  1568. )
  1569. ->orderBy('updated_at', 'desc')
  1570. ->limit($limit);
  1571. // 如果是图片文章,添加图片URL条件
  1572. if ($isImageArticle) {
  1573. $query->where('imgurl', '!=', '');
  1574. } else {
  1575. // 文字文章不需要imgurl字段
  1576. $query->addSelect('article.introduce');
  1577. }
  1578. $articles = $query->get();
  1579. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1580. }
  1581. /**
  1582. * 乡村网-获取特殊新闻模块
  1583. * @param array $data
  1584. * @return array
  1585. */
  1586. public function getWebsiteArticles(array $data): array
  1587. {
  1588. $input['id'] = $data['id'];
  1589. $input['website_id'] = $data['website_id'];
  1590. $data = json_decode($input['id'], true);
  1591. // 使用 array_map 处理每个元素
  1592. $result = array_map(function ($item) use ($input) {
  1593. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1594. $website = [
  1595. 'website_id' => $input['website_id']
  1596. ];
  1597. // 查询栏目名称
  1598. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1599. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1600. if (empty($category)) {
  1601. $imgArticles = [];
  1602. $textArticles = [];
  1603. // return Result::error("暂无此栏目",0);
  1604. } else {
  1605. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1606. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1607. // return Result::success($website);
  1608. // 查询图片新闻
  1609. // 合并查询条件
  1610. $baseQuery = Article::where(function ($query) use ($website) {
  1611. $query->where(function ($subQuery) use ($website) {
  1612. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1613. })->orWhereNull("ignore_ids");
  1614. })
  1615. ->where('article.status', 1)
  1616. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1617. ->where('website_category.website_id', $website['website_id']);
  1618. // 查询文字新闻
  1619. $textArticles = clone $baseQuery;
  1620. $textArticles = $textArticles->whereIn('catid', $child_category)
  1621. ->select(
  1622. 'article.id',
  1623. 'article.title',
  1624. // 'article.imgurl',
  1625. 'article.author',
  1626. 'article.updated_at',
  1627. 'article.introduce',
  1628. 'article.islink',
  1629. 'article.linkurl',
  1630. 'article.copyfrom',
  1631. 'website_category.category_id',
  1632. 'website_category.alias',
  1633. 'website_category.aLIas_pinyin'
  1634. )
  1635. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1636. ->orderBy('article.updated_at', 'desc')
  1637. ->limit($parentTextNum)
  1638. ->get()
  1639. ->all();
  1640. if (empty($textArticles)) {
  1641. $textArticles = clone $baseQuery;
  1642. $textArticles = $textArticles->where('catid', $parentCatId)
  1643. ->select(
  1644. 'article.id',
  1645. 'article.title',
  1646. // 'article.imgurl',
  1647. 'article.author',
  1648. 'article.updated_at',
  1649. 'article.introduce',
  1650. 'article.islink',
  1651. 'article.linkurl',
  1652. 'article.copyfrom',
  1653. 'website_category.category_id',
  1654. 'website_category.alias',
  1655. 'website_category.aLIas_pinyin'
  1656. )
  1657. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1658. ->orderBy('article.updated_at', 'desc')
  1659. ->limit($parentTextNum)
  1660. ->get()
  1661. ->all();
  1662. }
  1663. // 查询图片新闻
  1664. $imgArticles = clone $baseQuery;
  1665. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1666. ->select(
  1667. 'article.id',
  1668. 'article.title',
  1669. 'article.imgurl',
  1670. 'article.author',
  1671. 'article.updated_at',
  1672. 'article.introduce',
  1673. 'article.islink',
  1674. 'article.linkurl',
  1675. 'article.copyfrom',
  1676. 'website_category.category_id',
  1677. 'website_category.alias',
  1678. 'website_category.aLIas_pinyin'
  1679. )
  1680. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1681. ->orderBy('article.updated_at', 'desc')
  1682. ->limit($parentImgNum)
  1683. ->get()
  1684. ->all();
  1685. if (empty($imgArticles)) {
  1686. $imgArticles = clone $baseQuery;
  1687. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1688. ->select(
  1689. 'article.id',
  1690. 'article.title',
  1691. 'article.imgurl',
  1692. 'article.author',
  1693. 'article.updated_at',
  1694. 'article.introduce',
  1695. 'article.islink',
  1696. 'article.linkurl',
  1697. 'article.copyfrom',
  1698. 'website_category.category_id',
  1699. 'website_category.alias',
  1700. 'website_category.aLIas_pinyin'
  1701. )
  1702. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1703. ->orderBy('article.updated_at', 'desc')
  1704. ->limit($parentImgNum)
  1705. ->get()
  1706. ->all();
  1707. }
  1708. }
  1709. $resultItem = [
  1710. 'alias' => $category ? $category->alias : null,
  1711. 'category_id' => $parentCatId,
  1712. 'pinyin' => $pinyin ? $pinyin : null,
  1713. 'imgnum' => $imgArticles ?? [],
  1714. 'textnum' => $textArticles ?? [],
  1715. ];
  1716. return $resultItem;
  1717. }, $data);
  1718. return Result::success($result);
  1719. }
  1720. // 封装处理商品的路由问题
  1721. function processGoods($goods, $data)
  1722. {
  1723. return $goods->map(function ($good) use ($data) {
  1724. $catid = $good->catid ?? 0;
  1725. // $pinyin = '';
  1726. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1727. if (!empty($category->pid) && $category->pid != 0) {
  1728. $level = json_decode($category->category_arr_id);
  1729. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1730. ->whereIn('category_id', $level)
  1731. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1732. ->get(['aLIas_pinyin'])
  1733. ->pluck('aLIas_pinyin')
  1734. ->implode('/');
  1735. } else {
  1736. $pinyin = $category->aLIas_pinyin ?? '';
  1737. }
  1738. if (isset($good->city_id) && !empty($good->city_id)) {
  1739. $city = District::where('id', $good->city_id)->first(['name']);
  1740. $good->city_name = $city->name ?? '';
  1741. }
  1742. // 解析imgurl JSON并取第一条数据
  1743. $imgUrls = json_decode($good->imgurl, true);
  1744. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1745. $good->pinyin = $pinyin;
  1746. return $good;
  1747. });
  1748. }
  1749. /**
  1750. * 获取商城首页-根据栏目id
  1751. * @param array $data
  1752. * @return array
  1753. * */
  1754. function getWebsiteCatidshop(array $data): array
  1755. {
  1756. $input['catid'] = $data['catid'];
  1757. $input['website_id'] = $data['website_id'];
  1758. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1759. $result = array_map(function ($item) use ($input) {
  1760. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1761. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1762. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1763. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1764. if (empty($category) || $category->type != 2) {
  1765. return Result::error("暂无此栏目", 0);
  1766. } else {
  1767. $website['website_id'] = $input['website_id'];
  1768. $goods = Good::where('good.status', 2)
  1769. ->where('good.website_id', $website['website_id'])
  1770. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1771. ->select(
  1772. 'good.id',
  1773. 'good.name',
  1774. 'good.imgurl',
  1775. 'good.description',
  1776. 'good.updated_at',
  1777. 'good.catid',
  1778. 'good.type_id',
  1779. 'good.price',
  1780. 'good.com',
  1781. 'good.level',
  1782. 'good.unit'
  1783. )
  1784. ->orderBy('updated_at', 'desc')
  1785. ->offset($goodStart)
  1786. ->limit($goodNum);
  1787. $all_goods = $goods->get();
  1788. $all_goods = $this->processGoods($all_goods, $website);
  1789. }
  1790. return $all_goods ?? [];
  1791. }
  1792. }, $data);
  1793. return Result::success($result);
  1794. }
  1795. /**
  1796. * 获取商品模块
  1797. * @param array $data
  1798. * @return array
  1799. * */
  1800. public function getWebsiteshop(array $data): array
  1801. {
  1802. $input['id'] = $data['id'];
  1803. $input['website_id'] = $data['website_id'];
  1804. $catid = $data['catid'];
  1805. $data = json_decode($input['id'] ?? '', true) ?? [];
  1806. $result['goods'] = array_map(function ($item) use ($input) {
  1807. // 检查parent元素是否存在且不是undefined
  1808. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1809. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1810. $website = $input['website_id'];
  1811. $query = Good::where('good.status', 2)
  1812. ->where('good.website_id', $website);
  1813. switch ($Levelid) {
  1814. case 1:
  1815. case 2:
  1816. case 3:
  1817. $goods = $query->where(function ($q) use ($Levelid) {
  1818. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1819. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1820. });
  1821. break;
  1822. case 4:
  1823. $goods = $query;
  1824. break;
  1825. case 5:
  1826. $goods = $query->where('type_id', 1);
  1827. break;
  1828. case 6:
  1829. $goods = $query->where('type_id', 2);
  1830. break;
  1831. default:
  1832. return [];
  1833. }
  1834. $all_goods = $goods
  1835. ->select(
  1836. 'good.id',
  1837. 'good.name',
  1838. 'good.imgurl',
  1839. 'good.description',
  1840. 'good.updated_at',
  1841. 'good.catid',
  1842. 'good.type_id',
  1843. 'good.price',
  1844. 'good.level',
  1845. 'good.website_id'
  1846. )
  1847. ->orderBy('updated_at', 'desc')
  1848. ->offset($goodStart)
  1849. ->limit($goodNum)
  1850. ->get();
  1851. $web['website_id'] = $website;
  1852. $all_goods = $this->processGoods($all_goods, $web);
  1853. }
  1854. return $all_goods;
  1855. }, $data);
  1856. $website = $input['website_id'];
  1857. $result['article'] = Article::where(function ($query) use ($website) {
  1858. $query->where(function ($subQuery) use ($website) {
  1859. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1860. })->orWhereNull("ignore_ids");
  1861. })
  1862. ->where('catid', $catid)
  1863. ->where('article.status', 1)
  1864. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1865. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1866. ->orderBy('article.updated_at', 'desc')
  1867. ->first();
  1868. return Result::success($result);
  1869. }
  1870. /**
  1871. * 获取商品分类
  1872. * @param array $data
  1873. * @return array
  1874. * */
  1875. public function getWebsiteshopCat(array $data): array
  1876. {
  1877. $website = $data['website_id'];
  1878. $category = WebsiteCategory::where('website_id', $website)
  1879. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1880. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1881. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  1882. ->orderBy('sort')
  1883. ->get();
  1884. $cat = $category->map(function ($item) use ($website) {
  1885. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1886. $pid = $item->pid ?? 0;
  1887. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1888. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1889. ->where('website_id', $website)
  1890. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1891. ->get(['aLIas_pinyin'])
  1892. ->pluck('aLIas_pinyin')
  1893. ->implode('/');
  1894. } else {
  1895. $pinyin = $item->aLIas_pinyin ?? '';
  1896. }
  1897. $item->pinyin = $pinyin;
  1898. });
  1899. if (empty($category)) {
  1900. return Result::error("栏目查询失败", 0);
  1901. }
  1902. $cat_tree = Result::buildMenuTree($category);
  1903. $web['website_id'] = $website;
  1904. $goods = Good::where('website_id', $website)
  1905. ->where('status', 2)
  1906. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1907. ->latest('updated_at')
  1908. ->offset(($data['page'] - 1) * $data['pageSize'])
  1909. ->limit($data['pageSize'])
  1910. ->get();
  1911. if (!empty($goods)) {
  1912. if ($goods->count() > 1 && !empty($goods)) {
  1913. $goods = $this->processGoods($goods, $web);
  1914. }
  1915. } else {
  1916. $goods = [];
  1917. }
  1918. $result = [
  1919. 'category' => $cat_tree,
  1920. 'goods' => $goods,
  1921. ];
  1922. // $resul['goods'] = $goods;
  1923. if (empty($result)) {
  1924. return Result::error("查询失败", 0);
  1925. }
  1926. return Result::success($result);
  1927. }
  1928. /*
  1929. * 获取商品列表
  1930. * @param array $data
  1931. * @return array
  1932. * */
  1933. public function getWebsiteshopList(array $data): array
  1934. {
  1935. // return Result::success($data);
  1936. $where = [
  1937. 'status' => 2,
  1938. 'website_id' => $data['website_id'],
  1939. ];
  1940. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1941. return Result::error("查询失败", 0);
  1942. }
  1943. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1944. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1945. $data['catid'] = $category->category_id ?? 0;
  1946. }
  1947. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1948. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  1949. }
  1950. if (isset($data['type_id']) && !empty($data['type_id'])) {
  1951. array_push($where, ['type_id', $data['type_id']]);
  1952. }
  1953. $query = Good::where($where)
  1954. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  1955. $query->where(function ($q) use ($data) {
  1956. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  1957. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  1958. });
  1959. })
  1960. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1961. $query->where(function ($q) use ($data) {
  1962. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  1963. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  1964. });
  1965. })
  1966. ->select(
  1967. 'good.id',
  1968. 'good.name',
  1969. 'good.imgurl',
  1970. 'good.description',
  1971. 'good.updated_at',
  1972. 'good.com',
  1973. 'good.catid',
  1974. 'good.type_id',
  1975. 'good.website_id',
  1976. 'good.cat_arr_id',
  1977. 'good.created_at',
  1978. 'good.city_id'
  1979. )
  1980. ->latest('updated_at');
  1981. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1982. // 获取 type_id 为 1 的数据
  1983. $result['type1'] = $this->processGoods(
  1984. $query->clone()
  1985. ->where('type_id', 1)
  1986. ->offset(($data['page'] - 1) * $data['pageSize'])
  1987. ->limit($data['pageSize'])
  1988. ->get(),
  1989. $data
  1990. );
  1991. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1992. // 获取 type_id 为 2 的数据
  1993. $result['type2'] = $this->processGoods(
  1994. $query->clone()
  1995. ->where('type_id', 2)
  1996. ->offset(($data['page'] - 1) * $data['pageSize'])
  1997. ->limit($data['pageSize'])
  1998. ->get(),
  1999. $data
  2000. );
  2001. if (empty($result)) {
  2002. return Result::error("查询失败", 0);
  2003. }
  2004. return Result::success($result);
  2005. }
  2006. /**
  2007. * 获取商品详情
  2008. * @param array $data
  2009. * @return array
  2010. * */
  2011. public function getWebsiteshopInfo(array $data): array
  2012. {
  2013. $where = [
  2014. 'good.status' => 2,
  2015. 'good.website_id' => $data['website_id'],
  2016. 'good.id' => $data['id'],
  2017. ];
  2018. $goods = Good::where($where)
  2019. ->where('good.id', $data['id'])
  2020. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2021. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2022. ->first();
  2023. if (empty($goods)) {
  2024. return Result::error("查询失败", 0);
  2025. }
  2026. $goods->imgurl = json_decode($goods->imgurl, true);
  2027. return Result::success($goods);
  2028. }
  2029. /**
  2030. * 封装处理文章的路由问题
  2031. * */
  2032. function processArticles($articles, $data)
  2033. {
  2034. // 检查 $articles 是否为数组或可迭代对象
  2035. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2036. return $articles->map(function ($article) use ($data) {
  2037. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2038. $catid = $article->cat_arr_id ?? '';
  2039. }
  2040. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2041. $catid = $article->category_arr_id ?? '';
  2042. }
  2043. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2044. $level = json_decode($catid, true);
  2045. if (!is_array($level)) {
  2046. return $article;
  2047. } else {
  2048. $level = array_map('intval', $level);
  2049. }
  2050. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2051. ->where($data)
  2052. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2053. ->pluck('aLIas_pinyin')
  2054. ->implode('/');
  2055. $article->pinyin = $pinyin ?? '';
  2056. return $article;
  2057. });
  2058. } else {
  2059. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2060. $catid = $articles->cat_arr_id ?? '';
  2061. $level = json_decode($catid, true);
  2062. if (!is_array($level)) {
  2063. return $articles;
  2064. } else {
  2065. $level = array_map('intval', $level);
  2066. }
  2067. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2068. ->where($data)
  2069. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2070. ->pluck('aLIas_pinyin')
  2071. ->implode('/');
  2072. $articles->pinyin = $pinyin ?? '';
  2073. return $articles;
  2074. }
  2075. }
  2076. // 封装处理由问题
  2077. function processJob($job, $data)
  2078. {
  2079. return $job->map(function ($job) use ($data) {
  2080. $category = $job->cat_arr_id ?? '';
  2081. $cityid = $job->city_arr_id ?? '';
  2082. $city = json_decode($cityid, true);
  2083. $pinyin = '';
  2084. $level = json_decode($category, true);
  2085. // 路由
  2086. if (!empty($level) && is_array($level)) {
  2087. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2088. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2089. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2090. ->get(['aLIas_pinyin'])
  2091. ->pluck('aLIas_pinyin')
  2092. ->implode('/');
  2093. if (empty($pinyin)) {
  2094. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2095. }
  2096. $job->pinyin = $pinyin;
  2097. }
  2098. // 取职位-城市 市??省
  2099. if (!empty($city) && is_array($city)) {
  2100. if (isset($city[1]) && !empty($city[1])) {
  2101. $city = District::where('id', $city[1])->first(['name']);
  2102. $job->city_name = $city->name ?? '';
  2103. } else if (isset($city[0]) && !empty($city[0])) {
  2104. $city = District::where('id', $city[0])->first(['name']);
  2105. $job->city_name = $city->name ?? '';
  2106. } else {
  2107. $job->city_name = '全国';
  2108. }
  2109. }
  2110. // 获取简历最后一级地区
  2111. if (isset($job->city_id) && !empty($job->city_id)) {
  2112. $city = District::where('id', $job->city_id)->first(['name']);
  2113. $job->hunt_cityname = $city->name ?? '';
  2114. }
  2115. // 组合详细地址
  2116. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2117. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2118. if (is_array($address_id) && !empty($address_id)) {
  2119. $address = District::whereIn('id', $address_id)
  2120. ->orderBy('level', 'asc')
  2121. ->get(['name'])
  2122. ->pluck('name')
  2123. ->implode('');
  2124. // $job->address_name = $address ?? '';
  2125. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2126. }
  2127. }
  2128. // 取行业
  2129. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2130. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2131. if (!empty($job->industry)) {
  2132. $query->where('hyid', $job->industry);
  2133. } else if (!empty($job->hy_id)) {
  2134. $query->where('hyid', $job->hy_id);
  2135. } else if (!empty($job->company_hy_id)) {
  2136. $query->where('hyid', $job->company_hy_id);
  2137. } else {
  2138. $query->where('hyid', $job->job_industry);
  2139. }
  2140. })->first(['hyname']);
  2141. $job->hy_name = $hy_name->hyname ?? '';
  2142. }
  2143. // 取职位类别
  2144. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2145. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2146. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2147. $job->zw_name = $zw_name->zwname ?? '';
  2148. }
  2149. // 取具体职位
  2150. 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))) {
  2151. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2152. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2153. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2154. }
  2155. // 取工作经验
  2156. if (isset($job->experience) && !empty($job->experience)) {
  2157. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2158. $job->experience_name = $experience->ename ?? '';
  2159. }
  2160. // 取学历
  2161. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2162. $education = $job->educational ?? $job->school_education;
  2163. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2164. $job->education_name = $education->ename ?? '';
  2165. }
  2166. // 语言
  2167. if (isset($job->language) && !empty($job->language)) {
  2168. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2169. $job->language_name = $language->ename ?? '';
  2170. }
  2171. // 薪资
  2172. if (isset($job->salary) && !empty($job->salary)) {
  2173. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2174. $job->salary_name = $salary->ename ?? '';
  2175. }
  2176. // 职位性质
  2177. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2178. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2179. $job->job_nature_name = $job_nature->ename ?? '';
  2180. }
  2181. // 公司规模
  2182. if (isset($job->company_size) && !empty($job->company_size)) {
  2183. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2184. $job->company_size_name = $company_size->ename ?? '';
  2185. }
  2186. // 公司性质
  2187. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2188. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2189. $job->company_nature_name = $company_nature->nature_name ?? '';
  2190. }
  2191. // $job->pinyin = $pinyin;
  2192. return $job;
  2193. });
  2194. }
  2195. /**
  2196. * 获取书籍模块
  2197. * @param array $data
  2198. * @return array
  2199. * */
  2200. public function getWebsiteBook(array $data): array
  2201. {
  2202. $input['id'] = $data['id'];
  2203. $input['website_id'] = $data['website_id'];
  2204. // 将 JSON 字符串转换为 PHP 数组
  2205. $data = json_decode($input['id'], true);
  2206. // 使用 array_map 处理每个元素
  2207. $result = array_map(function ($item) use ($input) {
  2208. // 检查parent元素是否存在且不是undefined
  2209. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2210. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2211. $website = [
  2212. 'website_id' => $input['website_id'],
  2213. ];
  2214. // 查询栏目名称
  2215. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2216. if (empty($category)) {
  2217. $parent_alias = '';
  2218. $parent_pinyin = null;
  2219. $imgBooks = [];
  2220. $textBooks = [];
  2221. } else {
  2222. $parent_alias = $category->alias ?? '';
  2223. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2224. // 查找子分类ID数组
  2225. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2226. array_push($childCategoryIds, $parentCatId);
  2227. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2228. if ($parentImgNum != 0) {
  2229. // 查询图片新闻
  2230. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2231. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2232. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2233. })
  2234. ->where('book.status', 2)
  2235. ->where('book.img_url', '!=', '')
  2236. ->leftJoin('website_category', function ($join) use ($website) {
  2237. $join->on('book.cat_id', '=', 'website_category.category_id')
  2238. ->where('website_category.website_id', '=', $website['website_id']);
  2239. })
  2240. ->select(
  2241. 'book.id',
  2242. 'book.title',
  2243. 'book.img_url',
  2244. 'book.price',
  2245. 'book.market_price',
  2246. 'book.description',
  2247. 'book.cat_id',
  2248. 'book.description',
  2249. 'book.updated_at',
  2250. 'website_category.alias as category_name',
  2251. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2252. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2253. )
  2254. ->orderBy('updated_at', 'desc')
  2255. ->limit($parentImgNum)
  2256. ->get()->all();
  2257. // 查询文字新闻
  2258. }
  2259. if ($parentTextNum != 0) {
  2260. $textBooks = [];
  2261. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2262. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2263. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2264. })
  2265. ->where('book.status', 2)
  2266. ->leftJoin('website_category', function ($join) use ($website) {
  2267. $join->on('book.cat_id', '=', 'website_category.category_id')
  2268. ->where('website_category.website_id', '=', $website['website_id']);
  2269. })
  2270. ->select(
  2271. 'book.id',
  2272. 'book.title',
  2273. 'book.img_url',
  2274. 'book.price',
  2275. 'book.market_price',
  2276. 'book.description',
  2277. 'book.cat_id',
  2278. 'book.description',
  2279. 'book.updated_at',
  2280. 'website_category.alias as category_name',
  2281. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2282. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2283. )
  2284. ->orderBy('updated_at', 'desc')
  2285. ->limit($parentTextNum)
  2286. ->get()->all();
  2287. }
  2288. }
  2289. }
  2290. $resultItem = [
  2291. 'alias' => $parent_alias ?? '',
  2292. 'category_id' => $parentCatId ?? 0,
  2293. 'pinyin' => $parent_pinyin ?? null,
  2294. 'imgnum' => $imgBooks ?? [],
  2295. 'textnum' => $textBooks ?? [],
  2296. ];
  2297. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2298. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2299. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2300. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2301. ->get()->all();
  2302. if (!empty($childCategory)) {
  2303. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2304. // 查询子栏目名称
  2305. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2306. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2307. ->first();
  2308. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2309. $childImgArticles = [];
  2310. $childTextArticles = [];
  2311. $resultItem['child'] = [];
  2312. } else {
  2313. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2314. // 查询子栏目图片新闻
  2315. $childImgArticles = Book::where('cat_id', $childCatId)
  2316. ->where('status', 2)
  2317. ->where('img_url', '!=', '')
  2318. ->leftJoin('website_category', function ($join) use ($website) {
  2319. $join->on('book.cat_id', '=', 'website_category.category_id')
  2320. ->where('website_category.website_id', '=', $website['website_id']);
  2321. })
  2322. ->select(
  2323. 'book.id',
  2324. 'book.title',
  2325. 'book.img_url',
  2326. 'book.price',
  2327. 'book.market_price',
  2328. 'book.description',
  2329. 'book.cat_id',
  2330. 'book.description',
  2331. 'book.updated_at',
  2332. DB::raw("'$child_pinyin' as pinyin")
  2333. )
  2334. ->orderBy('updated_at', 'desc')
  2335. ->limit($childImgNum)
  2336. ->get()->all();
  2337. // 查询子栏目文字新闻
  2338. $childTextArticles = Book::where('cat_id', $childCatId)
  2339. ->where('status', 2)
  2340. ->leftJoin('website_category', function ($join) use ($website) {
  2341. $join->on('book.cat_id', '=', 'website_category.category_id')
  2342. ->where('website_category.website_id', '=', $website['website_id']);
  2343. })
  2344. ->select(
  2345. 'book.id',
  2346. 'book.title',
  2347. 'book.img_url',
  2348. 'book.price',
  2349. 'book.market_price',
  2350. 'book.description',
  2351. 'book.cat_id',
  2352. 'book.description',
  2353. 'book.updated_at',
  2354. DB::raw("'$child_pinyin' as pinyin")
  2355. )
  2356. ->orderBy('updated_at', 'desc')
  2357. ->limit($childTextNum)
  2358. ->get()->all();
  2359. $resultItem['child'] = [
  2360. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2361. 'category_id' => $childCatId,
  2362. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2363. 'all_childcat' => $childCategory,
  2364. 'imgnum' => $childImgArticles,
  2365. 'textnum' => $childTextArticles,
  2366. ];
  2367. }
  2368. }
  2369. } else {
  2370. $resultItem['child'] = [];
  2371. }
  2372. return $resultItem;
  2373. }, $data);
  2374. return Result::success($result);
  2375. }
  2376. /**
  2377. * 获取书刊列表
  2378. * @param array $data
  2379. * @return array
  2380. * */
  2381. public function getWebsiteBookList(array $data): array
  2382. {
  2383. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2384. if (empty($web)) {
  2385. return Result::error("查询失败", 0);
  2386. }
  2387. $catid = $data['id'];
  2388. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2389. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2390. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2391. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2392. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2393. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2394. ->where('pid', $category['pid'])
  2395. ->select(
  2396. 'category_id',
  2397. 'alias',
  2398. 'aLIas_pinyin',
  2399. 'pid',
  2400. 'sort',
  2401. 'is_url',
  2402. 'web_url',
  2403. 'seo_title',
  2404. 'seo_keywords',
  2405. 'seo_description',
  2406. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2407. )
  2408. ->orderBy('sort')
  2409. ->get()->all();
  2410. if (empty($category)) {
  2411. return Result::error("查询失败", 0);
  2412. }
  2413. $query = Book::where('book.status', 2)
  2414. ->where('book.website_id', $data['website_id'])
  2415. ->where('book.cat_id', $catid)
  2416. ->select(
  2417. 'book.id',
  2418. 'book.title',
  2419. 'book.img_url',
  2420. 'book.description',
  2421. 'book.updated_at',
  2422. 'book.cat_id',
  2423. DB::raw("'$pinyin' as pinyin")
  2424. )
  2425. ->orderBy('book.updated_at', 'desc');
  2426. $count = $query->count();
  2427. $query = clone $query;
  2428. $Book = $query
  2429. ->limit($data['pageSize'])
  2430. ->offset(($data['page'] - 1) * $data['pageSize'])
  2431. ->get()->all();
  2432. $result = [
  2433. 'category' => $categorys,
  2434. 'books' => $Book,
  2435. 'count' => $count,
  2436. ];
  2437. // if(empty($result)){
  2438. // return Result::error("查询失败", 0);
  2439. // }
  2440. return Result::success($result);
  2441. }
  2442. /**
  2443. * 获取书刊详情
  2444. * @param array $data
  2445. * @return array
  2446. * */
  2447. public function getWebsiteBookInfo(array $data): array
  2448. {
  2449. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2450. if (empty($web)) {
  2451. return Result::error("查询失败", 0);
  2452. }
  2453. $book = Book::where('status', 2)
  2454. ->where('website_id', $data['website_id'])
  2455. ->where('id', $data['id'])
  2456. ->select(
  2457. 'book.*',
  2458. )
  2459. ->orderBy('updated_at', 'desc')
  2460. ->first();
  2461. if (empty($book)) {
  2462. return Result::error("查询失败", 0);
  2463. }
  2464. // 先查询当前分类的 pid
  2465. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2466. ->where('category_id', $book['cat_id'])
  2467. ->first(['pid', 'category_id']);
  2468. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2469. if (!empty($carpid)) {
  2470. if ($carpid->pid != 0) {
  2471. $pid = $carpid['pid'];
  2472. // $parent_pinyin = '';
  2473. } else {
  2474. $pid = $carpid['category_id'];
  2475. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2476. }
  2477. }
  2478. $categorys = $query->where('pid', $pid)
  2479. ->select(
  2480. 'category_id',
  2481. 'alias',
  2482. 'aLIas_pinyin',
  2483. 'pid',
  2484. 'sort',
  2485. 'is_url',
  2486. 'web_url',
  2487. 'category_arr_id as cat_arr_id',
  2488. )
  2489. ->orderBy('sort')
  2490. ->get();
  2491. $category = $this->processArticle($categorys, $data);
  2492. $result = [
  2493. 'category' => $category,
  2494. 'books' => $book,
  2495. ];
  2496. return Result::success($result);
  2497. }
  2498. /**
  2499. * 尝试
  2500. * @param array $data
  2501. * @return array
  2502. * */
  2503. public function test(array $data): array
  2504. {
  2505. $input['id'] = $data['id'];
  2506. $input['website_id'] = $data['website_id'];
  2507. // 将 JSON 字符串转换为 PHP 数组
  2508. $data = json_decode($input['id'], true);
  2509. $result = [];
  2510. $article = $data;
  2511. $result = array_map(function ($item) use ($input) {
  2512. $website = [
  2513. 'website_id' => $input['website_id'],
  2514. ];
  2515. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2516. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2517. $parent = [
  2518. 0 => $category['category_id'] ?? [],
  2519. 1 => $parentImgNum ?? [],
  2520. 2 => $parentTextNum ?? [],
  2521. ];
  2522. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2523. $child = [];
  2524. $resultItem = [
  2525. // 'alias' => $parent_alias ?? '',
  2526. 'category_id' => $parentCatId ?? 0,
  2527. 'pinyin' => $parentImgNum ?? null,
  2528. 'imgnum' => $parentTextNum ?? [],
  2529. // 'textnum' => $textArticles ?? [],
  2530. ];
  2531. return $parent;
  2532. }, $data);
  2533. return Result::success($result);
  2534. // });
  2535. }
  2536. /**
  2537. * 封装处理文章的路由问题
  2538. * */
  2539. function processArticle($article, $data)
  2540. {
  2541. return $article->map(function ($article) use ($data) {
  2542. $catid = $article->cat_arr_id ?? '';
  2543. $level = json_decode($catid, true);
  2544. $pinyin = '';
  2545. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2546. if (!empty($level) && is_array($level)) {
  2547. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2548. ->where('website_id', $data['website_id'])
  2549. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2550. ->get(['aLIas_pinyin'])
  2551. ->pluck('aLIas_pinyin')
  2552. ->implode('/');
  2553. } else {
  2554. $pinyin = '';
  2555. }
  2556. $article->pinyin = $pinyin;
  2557. return $article;
  2558. });
  2559. }
  2560. /**
  2561. * c端-获取招工招聘下拉选框
  2562. * @param array $data
  2563. * @return array
  2564. * */
  2565. public function getWebsiteJobSelect(array $data): array
  2566. {
  2567. $web = Website::where('id', $data['website_id'])->first();
  2568. if (empty($web)) {
  2569. return Result::error("该网站不存在", 0);
  2570. }
  2571. $hy = JobIndustry::get()->all();
  2572. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2573. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2574. $result = [
  2575. 'hy' => $hy,
  2576. 'zw' => $zw,
  2577. 'jtzw' => $jtzw,
  2578. ];
  2579. if (empty($result)) {
  2580. return Result::error("查询失败", 0);
  2581. }
  2582. return Result::success($result);
  2583. }
  2584. /**
  2585. * c端-获取招工招聘
  2586. * @param array $data
  2587. * @return array
  2588. * */
  2589. public function getWebsiteJob(array $data): array
  2590. {
  2591. $web = Website::where('id', $data['website_id'])->first();
  2592. if (empty($web)) {
  2593. return Result::error("该网站不存在", 0);
  2594. }
  2595. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2596. ->where('job_hunting.website_id', $data['website_id'])
  2597. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2598. $query->where(function ($q) use ($data) {
  2599. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2600. });
  2601. })
  2602. ->select(
  2603. 'job_hunting.id',
  2604. 'job_hunting.cat_arr_id',
  2605. 'job_hunting.job_name_get',
  2606. 'job_hunting.industry',
  2607. 'job_hunting.name',
  2608. 'job_hunting.sexy',
  2609. 'job_hunting.origin',
  2610. 'job_hunting.city_arr_id',
  2611. 'job_hunting.experience',
  2612. 'job_hunting.updated_at',
  2613. 'job_hunting.salary'
  2614. )
  2615. ->orderBy('updated_at', 'desc')
  2616. ->limit($data['job1_num'])
  2617. ->get();
  2618. $web['website_id'] = $data['website_id'];
  2619. if (empty($job_hunting)) {
  2620. $job_huntings = "未查询到相关简历信息";
  2621. } else {
  2622. $job_huntings = $this->processJob($job_hunting, $web);
  2623. }
  2624. // 0:待审核 1:已通过 2:已拒绝
  2625. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2626. ->where('job_recruiting.website_id', $data['website_id'])
  2627. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2628. $query->where(function ($q) use ($data) {
  2629. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2630. });
  2631. })
  2632. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2633. ->select(
  2634. 'job_recruiting.id',
  2635. 'job_recruiting.cat_arr_id',
  2636. 'job_recruiting.title',
  2637. 'job_recruiting.jtzw_id',
  2638. 'job_recruiting.hy_id',
  2639. 'job_recruiting.city_arr_id',
  2640. 'job_recruiting.due_data',
  2641. 'job_recruiting.updated_at',
  2642. 'job_recruiting.experience',
  2643. 'job_recruiting.educational',
  2644. 'job_recruiting.salary',
  2645. 'job_recruiting.zw_id',
  2646. 'job_company.business_name'
  2647. )
  2648. ->orderBy('updated_at', 'desc')
  2649. ->limit($data['job2_num'])
  2650. ->get();
  2651. if (empty($job_recruiting->toArray())) {
  2652. $job_recruitings = "未查询到相关职位信息";
  2653. } else {
  2654. $job_recruitings = $this->processJob($job_recruiting, $web);
  2655. }
  2656. $result = [
  2657. 'job_hunting' => $job_huntings,
  2658. 'job_recuiting' => $job_recruitings,
  2659. ];
  2660. return Result::success($result);
  2661. }
  2662. /**
  2663. * c端-获取招工招聘列表
  2664. * @param array $data
  2665. * @return array
  2666. * */
  2667. public function getWebsiteJobList(array $data): array
  2668. {
  2669. $recruit_where = [];
  2670. $hunt_where = [];
  2671. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2672. if (empty($web)) {
  2673. return Result::error("此网站不存在", 0);
  2674. }
  2675. $website_id['website_id'] = $data['website_id'];
  2676. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2677. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2678. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2679. }
  2680. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2681. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2682. }
  2683. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2684. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2685. }
  2686. $query = JobRecruiting::where('job_recruiting.status', 1)
  2687. ->where('job_recruiting.website_id', $data['website_id'])
  2688. ->where($recruit_where)
  2689. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2690. $query->where(function ($q) use ($data) {
  2691. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2692. });
  2693. })
  2694. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2695. $query->where(function ($q) use ($data) {
  2696. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2697. });
  2698. })
  2699. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2700. ->select(
  2701. 'job_recruiting.id',
  2702. 'job_recruiting.hy_id',
  2703. 'job_recruiting.title',
  2704. 'job_recruiting.zw_id',
  2705. 'job_recruiting.educational',
  2706. 'job_recruiting.jtzw_id',
  2707. 'job_recruiting.city_arr_id',
  2708. 'job_recruiting.due_data',
  2709. 'job_recruiting.experience',
  2710. 'job_recruiting.cat_arr_id',
  2711. 'job_recruiting.updated_at',
  2712. 'job_company.business_name'
  2713. )
  2714. ->orderBy('updated_at', 'desc');
  2715. $recruit_count = $query->count();
  2716. $query = clone $query;
  2717. $JobRecruiting = $query
  2718. ->offset(($data['page'] - 1) * $data['pageSize'])
  2719. ->limit($data['pageSize'])
  2720. ->get();
  2721. if (empty($JobRecruiting)) {
  2722. $JobRecruiting = "暂无相关职位信息";
  2723. } else {
  2724. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2725. }
  2726. }
  2727. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2728. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2729. array_push($hunt_where, ['job', $data['zw_id']]);
  2730. }
  2731. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2732. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2733. }
  2734. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2735. array_push($hunt_where, ['industry', $data['hy_id']]);
  2736. }
  2737. $query = JobHunting::where('status', 2)
  2738. ->where('job_hunting.website_id', $data['website_id'])
  2739. ->where($hunt_where)
  2740. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2741. $query->where(function ($q) use ($data) {
  2742. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2743. });
  2744. })
  2745. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2746. $query->where(function ($q) use ($data) {
  2747. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2748. });
  2749. })
  2750. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2751. ->orderBy('updated_at', 'desc');
  2752. $hunt_count = $query->count();
  2753. $query = clone $query;
  2754. $JobHunting = $query
  2755. ->offset(($data['page'] - 1) * $data['pageSize'])
  2756. ->limit($data['pageSize'])
  2757. ->get();
  2758. if (empty($JobHunting)) {
  2759. $JobRecruiting = "暂无相关简历信息";
  2760. } else {
  2761. $JobHunting = $this->processJob($JobHunting, $website_id);
  2762. }
  2763. }
  2764. $result = [
  2765. 'JobRecruiting' => $JobRecruiting ?? [],
  2766. 'recruit_count' => $recruit_count ?? 0,
  2767. 'JobHunting' => $JobHunting ?? [],
  2768. 'hunt_count' => $hunt_count ?? 0,
  2769. ];
  2770. return Result::success($result);
  2771. }
  2772. /**
  2773. * c端-获取招工招聘详情
  2774. * @param array $data
  2775. * @return array
  2776. * */
  2777. public function getWebsiteJobInfo(array $data): array
  2778. {
  2779. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2780. if (empty($web)) {
  2781. return Result::error("该网站不存在", 0);
  2782. }
  2783. $webid = [
  2784. 'website_id' => $data['website_id'],
  2785. ];
  2786. // 职位相关信息
  2787. if ($data['type'] == 1) {
  2788. $query = JobRecruiting::where('status', 1)
  2789. ->where('website_id', $data['website_id'])
  2790. ->select('*');
  2791. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2792. $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();
  2793. if (!empty($company)) {
  2794. $result['company'] = $this->processJob($company, $webid);
  2795. }
  2796. $other_job = JobRecruiting::where('status', 1)
  2797. ->where('website_id', $data['website_id'])
  2798. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2799. ->where('id', '!=', $data['id'])
  2800. ->where('user_id', '=', $job[0]['user_id'])
  2801. ->limit($data['pageSize'])
  2802. ->get();
  2803. if (!empty($other_job)) {
  2804. $result['other_job'] = $this->processJob($other_job, $webid);
  2805. }
  2806. } else {
  2807. // 简历相关信息
  2808. $job = JobHunting::where('job_hunting.status', 2)
  2809. ->where('job_hunting.website_id', $data['website_id'])
  2810. ->where('job_hunting.id', $data['id'])
  2811. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2812. ->select('job_hunting.*', 'user_name')
  2813. ->get();
  2814. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2815. if (!empty($resume->toArray())) {
  2816. $result['resume'] = 1;
  2817. } else {
  2818. $result['resume'] = 0;
  2819. }
  2820. }
  2821. if (empty($job->toArray())) {
  2822. return Result::error("id参数错误", 0);
  2823. }
  2824. if (!empty($job[0]['job_experience'])) {
  2825. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2826. if (!empty($job_experience)) {
  2827. // $hy = [];
  2828. foreach ($job_experience as $key => $value) {
  2829. // $id = $value['id'];
  2830. $hy[$key] = $value['job_industry'];
  2831. $zw_id[$key] = $value['job_typename'];
  2832. $jtzw_id[$key] = $value['job_name'];
  2833. }
  2834. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2835. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2836. // 先将关联表转换为索引数组,提高查找效率
  2837. $hyLookup = [];
  2838. foreach ($hy_table as $item) {
  2839. $hyLookup[$item['hyid']] = $item['hyname'];
  2840. }
  2841. $zwLookup = [];
  2842. foreach ($zw_table as $item) {
  2843. $zwLookup[$item['zwid']] = $item['zwname'];
  2844. }
  2845. foreach ($job_experience as $key => &$value) {
  2846. // 处理行业名称
  2847. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2848. $value['hy_name'] = $hyLookup[$hy[$key]];
  2849. }
  2850. // 处理职位名称
  2851. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2852. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2853. }
  2854. // 处理具体职位名称
  2855. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2856. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2857. }
  2858. }
  2859. // 释放引用,防止意外修改后续代码
  2860. unset($value);
  2861. }
  2862. $result['job_experience'] = $job_experience ?? [];
  2863. }
  2864. if (!empty($job[0]['education_experience'])) {
  2865. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2866. if (!empty($education_experience)) {
  2867. foreach ($education_experience as $key => $value) {
  2868. // $id = $value['id'];
  2869. $education[$key] = $value['school_education'];
  2870. }
  2871. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2872. // // 先将关联表转换为索引数组,提高查找效率
  2873. $educationLookup = [];
  2874. foreach ($education_table as $item) {
  2875. $educationLookup[$item['evalue']] = $item['ename'];
  2876. }
  2877. foreach ($education_experience as $key => &$value) {
  2878. // 处理学历名称
  2879. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2880. $value['education_name'] = $educationLookup[$education[$key]];
  2881. }
  2882. }
  2883. }
  2884. $result['education_experience'] = $job_experience ?? [];
  2885. }
  2886. $result['job'] = $this->processJob($job, $webid);
  2887. // // 返现对应的栏目
  2888. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2889. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2890. ->whereIn('category_id', $catid)
  2891. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2892. ->orderBy('pid')->get()->all();
  2893. if (!empty($category)) {
  2894. $result['category'] = $category;
  2895. }
  2896. $result['job'] = $job;
  2897. $result['job_experience'] = $job_experience ?? [];
  2898. $result['education_experience'] = $education_experience ?? [];
  2899. if (empty($result)) {
  2900. return Result::error("参数错误", 0);
  2901. }
  2902. return Result::success($result);
  2903. }
  2904. /**
  2905. * c端-申请职位
  2906. * @param array $data
  2907. * @return array
  2908. * */
  2909. public function getWebsiteJobApply(array $data): array
  2910. {
  2911. // 首先验证网站是否存在
  2912. // return Result::success($data);
  2913. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2914. if (empty($web)) {
  2915. return Result::error("该网站不存在", 0);
  2916. }
  2917. // 验证用户是否存在且为个人会员/管理员
  2918. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2919. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2920. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2921. return Result::error("用户不存在", 0);
  2922. }
  2923. // 去除重复元素和空元素,并保持原始顺序
  2924. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2925. return !empty($value);
  2926. }));
  2927. // 验证职位是否存在 1:审核通过
  2928. $recruiting = JobRecruiting::where('status', 1)
  2929. ->where('website_id', $data['website_id'])
  2930. ->whereIn('id', $data['recruit_id'])
  2931. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2932. if (empty($recruiting)) {
  2933. return Result::error("该职位不存在", 0);
  2934. }
  2935. // 简历是否存在
  2936. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2937. if (empty($hunt_id)) {
  2938. return Result::error("该简历不存在", 0);
  2939. }
  2940. $data['hunt_id'] = $hunt_id['hunt_id'];
  2941. // // 验证是否已投递过该职位
  2942. $apply = JobApply::where('user_id', $data['user_id'])
  2943. ->where('hunt_id', $data['hunt_id'])
  2944. ->where('website_id', $data['website_id'])
  2945. ->whereIn('recruit_id', $data['recruit_id'])
  2946. ->get(['recruit_id']);
  2947. if (!empty($apply->toArray())) {
  2948. return Result::error("您已投递过该职位!");
  2949. }
  2950. $insertData = array_map(function ($recruiting) use ($data) {
  2951. return [
  2952. 'user_id' => $data['user_id'],
  2953. 'hunt_id' => $data['hunt_id'],
  2954. 'website_id' => $data['website_id'],
  2955. 'recruit_id' => $recruiting['recruit_id'],
  2956. 'receiver_id' => $recruiting['receiver_id'],
  2957. 'status' => 1,
  2958. ];
  2959. }, $recruiting);
  2960. // 批量插入数据
  2961. $result = JobApply::insert($insertData);
  2962. if (empty($result)) {
  2963. return Result::error("投递失败", 0);
  2964. }
  2965. return Result::success($result);
  2966. }
  2967. /**
  2968. * 招工招聘-沟通简历
  2969. * @param array $data
  2970. * @return array
  2971. * */
  2972. public function getWebsiteJobResume(array $data): array
  2973. {
  2974. // 首先验证网站是否存在
  2975. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2976. if (empty($web)) {
  2977. return Result::error("该网站不存在", 0);
  2978. }
  2979. // return Result::success($data);
  2980. // 验证用户是否存在且为企业会员/管理员
  2981. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2982. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2983. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2984. return Result::error("用户不存在", 0);
  2985. }
  2986. // 去除重复元素和空元素,并保持原始顺序
  2987. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2988. return !empty($value);
  2989. }));
  2990. // 验证简历是否存在
  2991. $hunting = JobHunting::where('status', 2)
  2992. ->where('website_id', $data['website_id'])
  2993. ->whereIn('id', $data['hunt_id'])
  2994. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2995. if (empty($hunting)) {
  2996. return Result::error("该简历不存在", 0);
  2997. }
  2998. // 验证是否已沟通过该简历
  2999. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3000. ->where('recruit_id', $data['recruit_id'])
  3001. ->where('website_id', $data['website_id'])
  3002. ->whereIn('hunt_id', $data['hunt_id'])
  3003. ->get(['hunt_id']);
  3004. if (!empty($remuse->toArray())) {
  3005. return Result::error("您已沟通过该简历!");
  3006. }
  3007. // 准备要插入的数据数组
  3008. $insertData = array_map(function ($hunting) use ($data) {
  3009. return [
  3010. 'user_id' => $data['user_id'],
  3011. 'recruit_id' => $data['recruit_id'],
  3012. 'website_id' => $data['website_id'],
  3013. 'hunt_id' => $hunting['hunt_id'],
  3014. 'receiver_id' => $hunting['receiver_id'],
  3015. 'status' => 1,
  3016. ];
  3017. }, $hunting);
  3018. // 批量插入数据
  3019. $result = JobRemuse::insert($insertData);
  3020. if (empty($result)) {
  3021. return Result::error("沟通失败", 0);
  3022. }
  3023. return Result::success($result);
  3024. }
  3025. /**
  3026. * 招工招聘 -我的职位(企业会员)
  3027. * @param array $data
  3028. * @return array
  3029. */
  3030. public function getWebsiteJobRecruiting(array $data): array
  3031. {
  3032. $web = Website::where('id', $data['website_id'])->first('id');
  3033. if (empty($web)) {
  3034. return Result::error("该网站不存在", 0);
  3035. }
  3036. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3037. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3038. return Result::error("用户暂无权限!", 0);
  3039. }
  3040. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3041. $result = JobRecruiting::where('website_id', $data['website_id'])
  3042. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3043. $query->where('user_id', $user['id']);
  3044. })
  3045. ->where('status', 1)
  3046. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3047. ->orderBy('updated_at', 'desc')
  3048. ->limit($data['pageSize'])
  3049. ->get();
  3050. if (empty($result)) {
  3051. return Result::error("暂无相关职位信息", 0);
  3052. }
  3053. return Result::success($result);
  3054. }
  3055. /**
  3056. * c端 - 验证路由
  3057. * @param array $data
  3058. * @return array
  3059. */
  3060. public function checkWebsiteRoute(array $data): array
  3061. {
  3062. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3063. if (empty($web)) {
  3064. return Result::error("该网站不存在", 0);
  3065. }
  3066. // 验证栏目路由
  3067. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3068. ->where('aLIas_pinyin', $data['last_route'])
  3069. ->first();
  3070. if (empty($last_category)) {
  3071. return Result::error("该栏目不存在", 0);
  3072. }
  3073. if (isset($data['id']) && !empty($data['id'])) {
  3074. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3075. switch ($last_category['type']) {
  3076. case 1:
  3077. // 文章
  3078. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3079. $article = Article::where('status', 1)
  3080. ->where('id', $data['id'])
  3081. ->where(function ($query) use ($data) {
  3082. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3083. ->orWhereNull("ignore_ids");
  3084. })
  3085. ->first(['cat_arr_id']);
  3086. if (empty($article)) {
  3087. return Result::error("该文章不存在", 0);
  3088. }
  3089. // return Result::success($article);
  3090. break;
  3091. case 2:
  3092. // 商品
  3093. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3094. $article = Good::where('website_id', $data['website_id'])
  3095. ->where('status', 2)
  3096. ->where('id', $data['id'])
  3097. ->first(['cat_arr_id']);
  3098. if (empty($article)) {
  3099. return Result::error("该商品不存在", 0);
  3100. }
  3101. break;
  3102. case 3:
  3103. // 书刊信息
  3104. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3105. $article = Book::where('website_id', $data['website_id'])
  3106. ->where('status', 2)
  3107. ->where('id', $data['id'])
  3108. ->first(['id', 'cat_arr_id']);
  3109. if (empty($article)) {
  3110. return Result::error("该书刊不存在", 0);
  3111. }
  3112. break;
  3113. case 4:
  3114. // 招聘
  3115. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3116. $article = JobRecruiting::where('website_id', $data['website_id'])
  3117. ->where('status', 1)
  3118. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3119. ->orderBy('updated_at', 'desc')
  3120. ->limit($data['pageSize'])
  3121. ->get();
  3122. break;
  3123. if (empty($result)) {
  3124. return Result::error("暂无相关职位信息", 0);
  3125. }
  3126. return Result::success($result);
  3127. }
  3128. }
  3129. }
  3130. /**
  3131. * c端 - 验证路由
  3132. * @param array $data
  3133. * @return array
  3134. */
  3135. public function checkWebsiteRoute(array $data): array
  3136. {
  3137. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3138. if (empty($web)) {
  3139. return Result::error("该网站不存在", 0);
  3140. }
  3141. // 验证栏目路由
  3142. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3143. ->where('aLIas_pinyin', $data['last_route'])
  3144. ->first();
  3145. if (empty($last_category)) {
  3146. return Result::error("该栏目不存在", 0);
  3147. }
  3148. if (isset($data['id']) && !empty($data['id'])) {
  3149. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3150. switch ($last_category['type']) {
  3151. case 1:
  3152. // 文章
  3153. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3154. $article = Article::where('status', 1)
  3155. ->where('id', $data['id'])
  3156. ->where(function ($query) use ($data) {
  3157. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3158. ->orWhereNull("ignore_ids");
  3159. })
  3160. ->first(['cat_arr_id']);
  3161. if (empty($article)) {
  3162. return Result::error("该文章不存在", 0);
  3163. }
  3164. // return Result::success($article);
  3165. break;
  3166. case 2:
  3167. // 商品
  3168. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3169. $article = Good::where('website_id', $data['website_id'])
  3170. ->where('status', 2)
  3171. ->where('id', $data['id'])
  3172. ->first(['cat_arr_id']);
  3173. if (empty($article)) {
  3174. return Result::error("该商品不存在", 0);
  3175. }
  3176. break;
  3177. case 3:
  3178. // 书刊信息
  3179. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3180. $article = Book::where('website_id', $data['website_id'])
  3181. ->where('status', 2)
  3182. ->where('id', $data['id'])
  3183. ->first(['id', 'cat_arr_id']);
  3184. if (empty($article)) {
  3185. return Result::error("该书刊不存在", 0);
  3186. }
  3187. break;
  3188. case 4:
  3189. // 招聘
  3190. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3191. $article = JobRecruiting::where('website_id', $data['website_id'])
  3192. ->where('status', 1)
  3193. ->where('id', $data['id'])
  3194. ->first(['cat_arr_id']);
  3195. if (empty($article)) {
  3196. return Result::error("该招聘不存在", 0);
  3197. }
  3198. break;
  3199. case 5:
  3200. // 求职
  3201. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3202. $article = JobHunting::where('website_id', $data['website_id'])
  3203. ->where('status', 2)
  3204. ->where('id', $data['id'])
  3205. ->first(['cat_arr_id']);
  3206. if (empty($article)) {
  3207. return Result::error("该求职不存在", 0);
  3208. }
  3209. break;
  3210. case 6:
  3211. // 招工招聘
  3212. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3213. $article = JobRecruiting::where('website_id', $data['website_id'])
  3214. ->where('status', 1)
  3215. ->where('id', $data['id'])
  3216. ->first(['cat_arr_id']);
  3217. if (empty($article)) {
  3218. $article = JobHunting::where('website_id', $data['website_id'])
  3219. ->where('status', 2)
  3220. ->where('id', $data['id'])
  3221. ->first(['cat_arr_id']);
  3222. }
  3223. if (empty($article)) {
  3224. return Result::error("该招工招聘不存在", 0);
  3225. }
  3226. break;
  3227. default:
  3228. return Result::error("该数据不存在", 0);
  3229. break;
  3230. }
  3231. $catid = json_decode($article['cat_arr_id'], true);
  3232. if (empty($catid)) {
  3233. return Result::error("该数据不存在", 0);
  3234. }
  3235. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3236. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3237. ->whereIn('category_id', $catid)
  3238. ->pluck('aLIas_pinyin')
  3239. ->implode('/');
  3240. }
  3241. if ($last_category['pid'] != 0) {
  3242. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3243. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3244. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3245. ->whereIn('category_id', $cat_arr)
  3246. ->pluck('aLIas_pinyin')
  3247. ->implode('/');
  3248. } else {
  3249. $pinyin = $last_category['aLIas_pinyin'];
  3250. }
  3251. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3252. return Result::error('非法路径!');
  3253. } else {
  3254. return Result::success($pinyin);
  3255. }
  3256. }
  3257. /**
  3258. * 招工招聘 - 获取推荐职位
  3259. * @param array $data
  3260. * @return array
  3261. */
  3262. public function getWebsiteLevelJob(array $data): array
  3263. {
  3264. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3265. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3266. ->where('job_recruiting.status', 1)
  3267. ->where('job_level', $data['job_level'])
  3268. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3269. ->select('job_recruiting.id','job_recruiting.title','job_recruiting.cat_arr_id','job_company.business_name','job_recruiting.updated_at')
  3270. ->orderBy('job_recruiting.updated_at', 'desc')
  3271. ->limit($data['pageSize'])
  3272. ->get();
  3273. $web = ['website_id' => $data['website_id']];
  3274. if(!empty($job)){
  3275. $result = $this->processJob($job, $web);
  3276. }
  3277. if(empty($result)){
  3278. return Result::error("暂无相关职位信息", 0);
  3279. }
  3280. return Result::success($result);
  3281. }
  3282. /**
  3283. * 验证导航名称是否重复
  3284. * @return void
  3285. */
  3286. public function checkCategoryName(array $data): array
  3287. {
  3288. $result = Category::when($data, function ($query) use ($data) {
  3289. if (isset($data['name']) && $data['name']) {
  3290. $query->where("name", $data['name']);
  3291. }
  3292. if (isset($data['id']) && $data['id']) {
  3293. $query->where("id", "!=", $data['id']);
  3294. }
  3295. })->first();
  3296. if ($result) {
  3297. return Result::error("已存在");
  3298. } else {
  3299. return Result::success();
  3300. }
  3301. }
  3302. //20250226 产品列表
  3303. public function getGoodList(array $data): array
  3304. {
  3305. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3306. unset($data['type_id']);
  3307. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3308. $where = [];
  3309. if ($type_id != '10000') {
  3310. $where = [
  3311. 'good.user_id' => $user_id,
  3312. ];
  3313. }
  3314. //类型
  3315. if (isset($data['type_id']) && $data['type_id']) {
  3316. $where = [
  3317. 'type_id' => $data['type_id'],
  3318. ];
  3319. }
  3320. //名称
  3321. if (isset($data['name']) && $data['name']) {
  3322. $where = [
  3323. 'good.name' => $data['name'],
  3324. ];
  3325. }
  3326. //status
  3327. if (isset($data['status']) && $data['status'] != '') {
  3328. $where = [
  3329. 'good.status' => $data['status'],
  3330. ];
  3331. }
  3332. //status1
  3333. // if (isset($data['status1']) && $data['status1'] == 1) {
  3334. // $status1 = 1;
  3335. // }
  3336. $where1 = [];
  3337. //website_id
  3338. // if (isset($data['website_id']) && $data['website_id']) {
  3339. // $where1 = [
  3340. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3341. // ];
  3342. // }
  3343. // website_name
  3344. if (isset($data['website_name']) && $data['website_name']) {
  3345. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3346. }
  3347. // catid
  3348. if (isset($data['category_name']) && $data['category_name']) {
  3349. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3350. }
  3351. // $result = Good::where($where)
  3352. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3353. $result = Good::where($where)
  3354. ->when(!empty($where1), function ($query) use ($where1) {
  3355. return $query->where($where1);
  3356. })
  3357. //status 1待审核2已审核3已拒绝
  3358. ->when(isset($data['status1']), function ($query) {
  3359. return $query->whereIn('good.status', [1, 3]);
  3360. })
  3361. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3362. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3363. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3364. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3365. ->orderBy("updated_at", "desc")
  3366. ->limit($data['page_size'])
  3367. ->offset(($data['page'] - 1) * $data['page_size'])
  3368. ->get();
  3369. $count = Good::where($where)
  3370. ->when(!empty($where1), function ($query) use ($where1) {
  3371. return $query->where($where1);
  3372. })
  3373. //status 1待审核2已审核3已拒绝
  3374. ->when(isset($data['status1']), function ($query) {
  3375. return $query->whereIn('good.status', [1, 3]);
  3376. })
  3377. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3378. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3379. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3380. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3381. ->orderBy("updated_at", "desc")->count();
  3382. $data = [
  3383. 'rows' => $result->toArray(),
  3384. 'count' => $count,
  3385. ];
  3386. if (empty($result)) {
  3387. return Result::error("此栏目暂无相关产品", 0);
  3388. }
  3389. return Result::success($data);
  3390. }
  3391. public function getGoodInfo(array $data): array
  3392. {
  3393. $result = Good::where('id', $data['id'])->first();
  3394. if (empty($result)) {
  3395. return Result::error("此产品不存在", 0);
  3396. }
  3397. return Result::success($result);
  3398. }
  3399. public function addGood(array $data): array
  3400. {
  3401. // unset($data['city_arr_id']);
  3402. // unset($data['cat_arr_id']);
  3403. $data['city_id'] = end($data['city_arr_id']);
  3404. $data['catid'] = end($data['cat_arr_id']);
  3405. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3406. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3407. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3408. unset($data['imgUrl']);
  3409. if (isset($data['price']) && $data['price'] == '') {
  3410. $data['price'] = 0;
  3411. }
  3412. $result = Good::insert($data);
  3413. if (empty($result)) {
  3414. return Result::error("添加失败", 0);
  3415. }
  3416. return Result::success($result);
  3417. }
  3418. public function updateGood(array $data): array
  3419. {
  3420. $data['city_id'] = end($data['city_arr_id']);
  3421. $data['catid'] = end($data['cat_arr_id']);
  3422. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3423. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3424. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3425. //设置东八区
  3426. date_default_timezone_set('Asia/Shanghai');
  3427. $data['updated_at'] = date('Y-m-d H:i:s');
  3428. if (isset($data['price']) && $data['price'] == '') {
  3429. $data['price'] = 0;
  3430. }
  3431. $result = Good::where('id', $data['id'])->update($data);
  3432. if (empty($result)) {
  3433. return Result::error("更新失败", 0);
  3434. }
  3435. return Result::success($result);
  3436. }
  3437. public function delGood(array $data): array
  3438. {
  3439. $result = Good::where('id', $data['id'])->delete();
  3440. if (empty($result)) {
  3441. return Result::error("删除失败", 0);
  3442. }
  3443. return Result::success($result);
  3444. }
  3445. //20250226 产品列表
  3446. //20250306 求职信息
  3447. public function getJobHuntingList(array $data): array
  3448. {
  3449. $where = [];
  3450. if (isset($data['username']) && !empty($data['username'])) {
  3451. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3452. }
  3453. //status 1待审核2已审核3已拒绝
  3454. if (isset($data['status']) && $data['status'] != '') {
  3455. $where = [
  3456. 'job_hunting.status' => $data['status'],
  3457. ];
  3458. }
  3459. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3460. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3461. unset($data['type_id']);
  3462. if ($type_id != '10000') {
  3463. $where[] = ['job_hunting.user_id', '=', $user_id];
  3464. }
  3465. $result = JobHunting::where($where)
  3466. ->when(!empty($data['status1']), function ($query) use ($data) {
  3467. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3468. })
  3469. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3470. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3471. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3472. ->orderBy("updated_at", "desc")
  3473. ->limit($data['page_size'])
  3474. ->offset(($data['page'] - 1) * $data['page_size'])
  3475. ->get();
  3476. if (empty($result)) {
  3477. return Result::error("查询失败", 0);
  3478. }
  3479. $count = JobHunting::where($where)
  3480. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3481. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3482. ->count();
  3483. $data = [
  3484. 'rows' => $result->toArray(),
  3485. 'count' => $count,
  3486. ];
  3487. return Result::success($data);
  3488. }
  3489. public function getJobHuntingApply(array $data): array
  3490. {
  3491. var_dump($data, '-----------------test--------1-');
  3492. $where = [];
  3493. if (isset($data['username']) && !empty($data['username'])) {
  3494. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3495. }
  3496. if (isset($data['salary']) && !empty($data['salary'])) {
  3497. $where[] = [
  3498. 'job_hunting.salary',
  3499. '=',
  3500. $data['salary'],
  3501. ];
  3502. }
  3503. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3504. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3505. unset($data['type_id']);
  3506. if ($type_id != '10000') {
  3507. $where[] = ['job_apply.user_id', '=', $user_id];
  3508. }
  3509. var_dump($where, '-----------------test---------');
  3510. $result = jobApply::where($where)
  3511. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3512. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3513. // })
  3514. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3515. ->where('job_enum.egroup', '=', 'income')
  3516. ->where('job_hunting.status', 2) //已审核
  3517. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3518. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3519. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3520. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3521. //职位----是申请职位
  3522. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3523. ->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')
  3524. ->orderBy("job_hunting.updated_at", "desc")
  3525. ->limit($data['page_size'])
  3526. ->offset(($data['page'] - 1) * $data['page_size'])
  3527. ->get();
  3528. if (empty($result)) {
  3529. return Result::error("查询失败", 0);
  3530. }
  3531. $count = jobApply::where($where)
  3532. ->where('job_enum.egroup', '=', 'income')
  3533. ->where('job_hunting.status', 2) //已审核
  3534. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3535. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3536. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3537. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3538. //职位----是申请职位
  3539. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3540. ->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')
  3541. ->count();
  3542. $data = [
  3543. 'rows' => $result->toArray(),
  3544. 'count' => $count,
  3545. ];
  3546. return Result::success($data);
  3547. }
  3548. public function addJobHunting(array $data): array
  3549. {
  3550. date_default_timezone_set('Asia/Shanghai');
  3551. unset($data['company_name']);
  3552. unset($data['job_industry']);
  3553. unset($data['job_name']);
  3554. unset($data['department']);
  3555. unset($data['job_timeList']);
  3556. unset($data['job_content']);
  3557. unset($data['job_typename']); //不知道这是啥,
  3558. $data['created_at'] = date('Y-m-d H:i:s');
  3559. $data['updated_at'] = date('Y-m-d H:i:s');
  3560. //根据用户 user_id 只能添加一次
  3561. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3562. if (!empty($result)) {
  3563. return Result::error("您已添加过求职信息", 0);
  3564. }
  3565. var_dump($result, '-----------------test---------');
  3566. $result = JobHunting::create($data);
  3567. if (empty($result)) {
  3568. return Result::error("添加失败", 0);
  3569. }
  3570. return Result::success($result);
  3571. }
  3572. public function delJobHunting(array $data): array
  3573. {
  3574. $result = JobHunting::where('id', $data['id'])->delete();
  3575. if (empty($result)) {
  3576. return Result::error("删除失败", 0);
  3577. }
  3578. return Result::success($result);
  3579. }
  3580. public function updateJobHunting(array $data): array
  3581. {
  3582. //设置东八区
  3583. date_default_timezone_set('Asia/Shanghai');
  3584. unset($data['company_name']);
  3585. unset($data['job_industry']);
  3586. unset($data['job_name']);
  3587. unset($data['department']);
  3588. unset($data['job_timeList']);
  3589. unset($data['job_content']);
  3590. unset($data['job_typename']); //不知道这是啥,
  3591. $data['created_at'] = date('Y-m-d H:i:s');
  3592. $data['updated_at'] = date('Y-m-d H:i:s');
  3593. $result = JobHunting::where('id', $data['id'])->update($data);
  3594. if (empty($result)) {
  3595. return Result::error("更新失败", 0);
  3596. }
  3597. return Result::success($result);
  3598. }
  3599. public function getJobHuntingInfo(array $data): array
  3600. {
  3601. $result = JobHunting::where('id', $data['id'])->first();
  3602. if (empty($result)) {
  3603. return Result::error("查询失败", 0);
  3604. }
  3605. return Result::success($result);
  3606. }
  3607. public function getJobHuntingData(array $data): array
  3608. {
  3609. $jobEnum = JobEnum::get();
  3610. $jobIndustry = JobIndustry::get();
  3611. $jobNature = JobNature::get();
  3612. $jobPosition = JobPosition::get();
  3613. $data = [
  3614. 'jobEnum' => $jobEnum,
  3615. 'jobIndustry' => $jobIndustry,
  3616. 'jobNature' => $jobNature,
  3617. 'jobPosition' => $jobPosition,
  3618. ];
  3619. return Result::success($data);
  3620. }
  3621. public function delJobHuntingInfo(array $data): array
  3622. {
  3623. $result = JobHunting::where('id', $data['id'])->delete();
  3624. return Result::success();
  3625. }
  3626. //20250324 通知,公告,消息
  3627. public function delNotice(array $data): array
  3628. {
  3629. $result = Notice::where('id', $data['id'])->delete();
  3630. if ($result) {
  3631. return Result::success();
  3632. } else {
  3633. return Result::error("删除失败", 0);
  3634. }
  3635. }
  3636. public function getNoticeInfo(array $data): array
  3637. {
  3638. $result = Notice::where('id', $data['id'])->first();
  3639. if (empty($result)) {
  3640. return Result::error("查询失败", 0);
  3641. }
  3642. return Result::success($result);
  3643. }
  3644. public function addNotice(array $data): array
  3645. {
  3646. date_default_timezone_set('Asia/Shanghai');
  3647. $data['created_at'] = date('Y-m-d H:i:s');
  3648. $data['updated_at'] = date('Y-m-d H:i:s');
  3649. $user_id = UserInfo::
  3650. //city_id不是null
  3651. whereNotNull('city_id')
  3652. ->whereNotNull('department_id')
  3653. ->where(function ($query) use ($data) {
  3654. $query->where(function ($subQuery) use ($data) {
  3655. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3656. });
  3657. })
  3658. ->where(function ($query) use ($data) {
  3659. $query->where(function ($subQuery) use ($data) {
  3660. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3661. });
  3662. })
  3663. ->pluck('user_id')->toArray();
  3664. $user_id = array_unique($user_id);
  3665. $chat_ids = $user_id;
  3666. $user_id = json_encode($user_id);
  3667. $data['re_user_ids'] = $user_id;
  3668. $result = Notice::insertGetId($data);
  3669. if ($result && $data['is_group'] == 1) {
  3670. //chat_group
  3671. $group_id = PublicData::uuid();
  3672. $groupData = [
  3673. 'id' => $group_id,
  3674. 'creator_id' => $data['user_id'],
  3675. 'group_name' => $data['group_name'] ?? '',
  3676. 'profile' => $data['profile'] ?? 0,
  3677. ];
  3678. var_dump($groupData, '-----------------groupData-------');
  3679. $groupResult = ChatGroups::insertGetId($groupData);
  3680. var_dump($groupResult, '-----------------groupid-------');
  3681. $groupMemberData = [
  3682. 'id' => PublicData::uuid(),
  3683. 'user_id' => $data['user_id'],
  3684. 'group_id' => $group_id,
  3685. 'leader' => 2,
  3686. ];
  3687. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3688. //$chat_ids 去除掉$data['user_id']
  3689. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3690. //插入群成员表
  3691. $groupMemberDataUser = [];
  3692. $chatData = [];
  3693. foreach ($chat_ids as $key => $value) {
  3694. $groupMemberDataUser[] = [
  3695. 'id' => PublicData::uuid(),
  3696. 'user_id' => $value,
  3697. 'group_id' => $group_id,
  3698. 'leader' => 1,
  3699. ];
  3700. $chatData[] = [
  3701. 'user_id' => $value,
  3702. 'msg_type' => 1,
  3703. 'receiver_id' => $group_id,
  3704. 'content' => '通过通知创建群聊',
  3705. 'group_receiver_id' => $data['user_id'],
  3706. 'action' => 'recieved',
  3707. 'created_at' => date('Y-m-d H:i:s'),
  3708. ];
  3709. }
  3710. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3711. ChatGroupsMember::insert($groupMemberDataUser);
  3712. //插入一条管理员聊天记录
  3713. $chatData[] = [
  3714. 'user_id' => $data['user_id'],
  3715. 'msg_type' => 1,
  3716. 'receiver_id' => $group_id,
  3717. 'content' => '通过通知创建群聊',
  3718. 'group_receiver_id' => $data['user_id'],
  3719. 'action' => 'said',
  3720. 'created_at' => date('Y-m-d H:i:s'),
  3721. ];
  3722. var_dump($chatData, '-----------------chatData-------');
  3723. $chatResult = ChatRecords::insert($chatData);
  3724. //更新result的 group_id
  3725. $data['group_id'] = $group_id;
  3726. Notice::where(['id' => $result])->update($data);
  3727. }
  3728. if (empty($result)) {
  3729. return Result::error("添加失败", 0);
  3730. }
  3731. return Result::success($result);
  3732. }
  3733. public function updateNotice(array $data): array
  3734. {
  3735. date_default_timezone_set('Asia/Shanghai');
  3736. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3737. $user_id = UserInfo::
  3738. //city_id不是null
  3739. whereNotNull('city_id')
  3740. ->whereNotNull('department_id')
  3741. ->where(function ($query) use ($data) {
  3742. $query->where(function ($subQuery) use ($data) {
  3743. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3744. });
  3745. })
  3746. ->where(function ($query) use ($data) {
  3747. $query->where(function ($subQuery) use ($data) {
  3748. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3749. });
  3750. })
  3751. ->pluck('user_id')->toArray();
  3752. $user_id = array_unique($user_id);
  3753. $user_id = json_encode($user_id);
  3754. $data['re_user_ids'] = $user_id;
  3755. $data['updated_at'] = date('Y-m-d H:i:s');
  3756. $result = Notice::where('id', $data['id'])->update($data);
  3757. return Result::success($result);
  3758. }
  3759. public function getNoticeList(array $data): array
  3760. {
  3761. $where = [];
  3762. //title
  3763. if (isset($data['title']) && !empty($data['title'])) {
  3764. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3765. }
  3766. //level
  3767. if (isset($data['level']) && !empty($data['level'])) {
  3768. $where[] = ['notice.level', '=', $data['level']];
  3769. }
  3770. //status
  3771. if (isset($data['status']) && !empty($data['status'])) {
  3772. $where[] = ['notice.status', '=', $data['status']];
  3773. }
  3774. var_dump($data, '-----------------test---------');
  3775. if ($data['type_id'] == 10000) {
  3776. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3777. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3778. })
  3779. ->where($where)
  3780. ->orderBy('updated_at', 'desc')
  3781. ->limit($data['page_size'])
  3782. ->offset(($data['page'] - 1) * $data['page_size'])
  3783. ->get();
  3784. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3785. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3786. })
  3787. ->where($where)
  3788. ->orderBy('updated_at', 'desc')
  3789. ->count();
  3790. } else {
  3791. $result = Notice::where($where)
  3792. // ->where('user_id', $data['user_id'])
  3793. ->Where(function ($query) use ($data) {
  3794. $query->Where(function ($q) use ($data) {
  3795. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3796. ->orWhere('notice.user_id', $data['user_id']);
  3797. });
  3798. })
  3799. ->orderBy('updated_at', 'desc')
  3800. ->limit($data['page_size'])
  3801. ->offset(($data['page'] - 1) * $data['page_size'])
  3802. ->get();
  3803. $total = Notice::where($where)
  3804. // ->where('user_id', $data['user_id'])
  3805. ->Where(function ($query) use ($data) {
  3806. $query->Where(function ($q) use ($data) {
  3807. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3808. ->orWhere('notice.user_id', $data['user_id']);
  3809. });
  3810. })
  3811. ->count();
  3812. }
  3813. if (empty($result)) {
  3814. return Result::error("查询失败", 0);
  3815. }
  3816. $data = [
  3817. 'rows' => $result,
  3818. 'count' => $total,
  3819. ];
  3820. return Result::success($data);
  3821. }
  3822. public function getNoticeDetail(array $data): array
  3823. {
  3824. $result = Notice::where('id', $data['id'])->first();
  3825. if (empty($result)) {
  3826. return Result::error("查询失败", 0);
  3827. }
  3828. return Result::success($result);
  3829. }
  3830. public function deleteNotice(array $data): array
  3831. {
  3832. $notice = Notice::where('id', $data['id'])->first();
  3833. if (empty($notice)) {
  3834. return Result::error("删除失败", 0);
  3835. }
  3836. $chat_group_id = $notice->group_id;
  3837. if ($chat_group_id) {
  3838. //删除群聊
  3839. ChatGroups::where('id', $chat_group_id)->delete();
  3840. //删除群成员
  3841. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3842. //删除群聊记录
  3843. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3844. }
  3845. $result = Notice::where('id', $data['id'])->delete();
  3846. return Result::success($result);
  3847. }
  3848. public function getMSG(array $data): array
  3849. {
  3850. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3851. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3852. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3853. $result = [];
  3854. if ($type_id == 1) {
  3855. //最近的5篇已审的文章
  3856. $apply_articale = Article::where('status', 1)
  3857. ->where('admin_user_id', $user_id)
  3858. ->orderBy('updated_at', 'desc')
  3859. ->limit(5)->get();
  3860. //获取5条单聊未读聊天消息
  3861. $chat = ChatRecords::where('is_read', 0)
  3862. ->where('user_id', $user_id)
  3863. ->where('talk_type', 1)
  3864. ->orderBy('created_at', 'desc')
  3865. ->limit(5)->get();
  3866. //获取5条未读群聊信息
  3867. $chat_group = ChatRecords::where('is_read', 0)
  3868. ->where('user_id', $user_id)
  3869. ->where('talk_type', 2)
  3870. ->orderBy('created_at', 'desc')
  3871. ->limit(5)->get();
  3872. //获取5条用户的已审核商品
  3873. $good = Good::where('status', 2)
  3874. ->where('user_id', $user_id)
  3875. ->orderBy('updated_at', 'desc')
  3876. ->limit(5)->get();
  3877. //获取5条用户待审核的公告
  3878. $notice = Notice::where('status', 2)
  3879. ->where('user_id', $user_id)
  3880. ->orderBy('updated_at', 'desc')
  3881. ->limit(5)->get();
  3882. //获取5条用户的待审核投诉
  3883. $complaint = Complaint::where('status', 2)
  3884. ->where('user_id', $user_id)
  3885. ->orderBy('updated_at', 'desc')
  3886. ->limit(5)->get();
  3887. //获取5条用户的book
  3888. $book = Book::where('status', 2)
  3889. ->where('user_id', $user_id)
  3890. ->orderBy('updated_at', 'desc')
  3891. ->limit(5)->get();
  3892. //获取5条用户的求职
  3893. //获取5条用户的求职 1
  3894. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3895. ->where('job_hunting.user_id', $user_id)
  3896. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3897. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3898. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3899. ->orderBy('updated_at', 'desc')
  3900. ->limit(5)->get();
  3901. //获取5条用户的求职 2
  3902. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3903. ->where('job_recruiting.user_id', $user_id)
  3904. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3905. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3906. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3907. ->orderBy('updated_at', 'desc')
  3908. ->limit(5)->get();
  3909. //人才库 1
  3910. $job_apply = JobApply::where('job_apply.status', 1)
  3911. ->where('job_apply.receiver_id', $user_id)
  3912. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3913. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3914. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3915. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3916. ->select('job_recruiting', 'job_recruiting.', '', '')
  3917. ->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')
  3918. ->orderBy('updated_at', 'desc')
  3919. ->limit(5)->get();
  3920. // 职场机会 2
  3921. $job_resume = JobResume::where('job_resume.status', 1)
  3922. ->where('job_resume.receiver_id', $user_id)
  3923. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3924. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3925. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3926. ->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')
  3927. ->orderBy('updated_at', 'desc')
  3928. ->limit(5)->get();
  3929. $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);
  3930. $result = [
  3931. 'apply_articale' => $apply_articale,
  3932. 'chat' => $chat,
  3933. 'chat_group' => $chat_group,
  3934. 'good' => $good,
  3935. 'notice' => $notice,
  3936. 'complaint' => $complaint,
  3937. 'book' => $book,
  3938. 'job_hunting' => $job_hunting,
  3939. 'job_recruiting' => $job_recruiting,
  3940. 'job_apply' => $job_apply,
  3941. 'job_resume' => $job_resume,
  3942. 'count' => $count,
  3943. ];
  3944. } elseif ($type_id == 2) {
  3945. //最近的5篇已审的文章
  3946. $apply_articale = Article::where('status', 1)
  3947. ->where('admin_user_id', $user_id)
  3948. ->limit(5)->get();
  3949. //获取5条单聊未读聊天消息
  3950. $chat = ChatRecords::where('is_read', 0)
  3951. ->where('user_id', $user_id)
  3952. ->where('talk_type', 1)
  3953. ->orderBy('created_at', 'desc')
  3954. ->limit(5)->get();
  3955. //获取5条未读群聊信息
  3956. $chat_group = ChatRecords::where('is_read', 0)
  3957. ->where('user_id', $user_id)
  3958. ->where('talk_type', 2)
  3959. ->orderBy('created_at', 'desc')
  3960. ->limit(5)->get();
  3961. //获取5条用户的已审核商品
  3962. $good = Good::where('status', 2)
  3963. ->where('user_id', $user_id)
  3964. ->orderBy('updated_at', 'desc')
  3965. ->limit(5)->get();
  3966. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3967. $result = [
  3968. 'apply_articale' => $apply_articale,
  3969. 'chat' => $chat,
  3970. 'chat_group' => $chat_group,
  3971. 'good' => $good,
  3972. 'count' => $count,
  3973. ];
  3974. } elseif ($type_id == 3) {
  3975. //最近的5篇已审的文章
  3976. $apply_articale = Article::where('status', 1)
  3977. ->where('admin_user_id', $user_id)
  3978. ->limit(5)->get();
  3979. //获取5条单聊未读聊天消息
  3980. $chat = ChatRecords::where('is_read', 0)
  3981. ->where('user_id', $user_id)
  3982. ->where('talk_type', 1)
  3983. ->orderBy('created_at', 'desc')
  3984. ->limit(5)->get();
  3985. //获取5条未读群聊信息
  3986. $chat_group = ChatRecords::where('is_read', 0)
  3987. ->where('user_id', $user_id)
  3988. ->where('talk_type', 2)
  3989. ->orderBy('created_at', 'desc')
  3990. ->limit(5)->get();
  3991. //获取5条用户的已审核商品
  3992. $good = Good::where('status', 2)
  3993. ->where('user_id', $user_id)
  3994. ->orderBy('updated_at', 'desc')
  3995. ->limit(5)->get();
  3996. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3997. $result = [
  3998. 'apply_articale' => $apply_articale,
  3999. 'chat' => $chat,
  4000. 'chat_group' => $chat_group,
  4001. 'good' => $good,
  4002. 'count' => $count,
  4003. ];
  4004. } elseif ($type_id == 4) {
  4005. //最近的5篇已审的文章
  4006. $apply_articale = Article::where('status', 1)
  4007. ->where('admin_user_id', $user_id)
  4008. ->limit(5)->get();
  4009. //获取5条用户的已审核商品
  4010. $good = Good::where('status', 2)
  4011. ->where('user_id', $user_id)
  4012. ->orderBy('updated_at', 'desc')
  4013. ->limit(5)->get();
  4014. $count = count($apply_articale) + count($good);
  4015. $result = [
  4016. 'apply_articale' => $apply_articale,
  4017. 'chat' => '',
  4018. 'chat_group' => '',
  4019. 'good' => $good,
  4020. 'count' => $count,
  4021. ];
  4022. } elseif ($type_id == 10000) {
  4023. //获取未审核的5篇文章
  4024. $apply_articale = Article::where('status', 0)
  4025. ->orderBy('updated_at', 'desc')
  4026. ->limit(5)->get();
  4027. //获取5条单聊未读聊天消息
  4028. $chat = ChatRecords::where('is_read', 0)
  4029. ->where('user_id', $user_id)
  4030. ->where('talk_type', 1)
  4031. ->orderBy('created_at', 'desc')
  4032. ->limit(5)->get();
  4033. //获取5条未读群聊信息
  4034. $chat_group = ChatRecords::where('is_read', 0)
  4035. ->where('user_id', $user_id)
  4036. ->where('talk_type', 2)
  4037. ->orderBy('created_at', 'desc')
  4038. ->limit(5)->get();
  4039. //获取5条用户的已审核商品
  4040. $good = Good::where('status', 1)
  4041. // ->where('user_id', $user_id)
  4042. ->orderBy('updated_at', 'desc')
  4043. ->limit(5)->get();
  4044. //获取5条用户待审核的公告
  4045. $notice = Notice::where('status', 1)
  4046. ->orderBy('updated_at', 'desc')
  4047. ->limit(5)->get();
  4048. //获取5条用户的待审核投诉
  4049. $complaint = Complaint::where('status', 1)
  4050. ->orderBy('updated_at', 'desc')
  4051. ->limit(5)->get();
  4052. //获取5条用户的book
  4053. $book = Book::where('status', 1)
  4054. ->orderBy('updated_at', 'desc')
  4055. ->limit(5)->get();
  4056. //获取5条用户的求职 1
  4057. $job_hunting = JobHunting::where('job_hunting.status', 1)
  4058. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4059. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  4060. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4061. ->orderBy('updated_at', 'desc')
  4062. ->limit(5)->get();
  4063. //获取5条用户的求职 2
  4064. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  4065. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4066. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4067. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4068. ->orderBy('updated_at', 'desc')
  4069. ->limit(5)->get();
  4070. //人才库 1
  4071. $job_apply = JobApply::where('job_apply.status', 1)
  4072. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  4073. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  4074. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  4075. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  4076. ->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')
  4077. ->orderBy('updated_at', 'desc')
  4078. ->limit(5)->get();
  4079. // 职场机会 2
  4080. $job_resume = JobResume::where('job_resume.status', 1)
  4081. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  4082. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  4083. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  4084. ->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')
  4085. ->orderBy('updated_at', 'desc')
  4086. ->limit(5)->get();
  4087. $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);
  4088. $result = [
  4089. 'apply_articale' => $apply_articale,
  4090. 'chat' => $chat,
  4091. 'chat_group' => $chat_group,
  4092. 'good' => $good,
  4093. 'notice' => $notice,
  4094. 'complaint' => $complaint,
  4095. 'book' => $book,
  4096. 'job_hunting' => $job_hunting,
  4097. 'job_recruiting' => $job_recruiting,
  4098. 'job_apply' => $job_apply,
  4099. 'job_resume' => $job_resume,
  4100. 'count' => $count,
  4101. ];
  4102. } elseif ($type_id == 20000) {
  4103. }
  4104. var_dump($type_id, '-----------------test---------');
  4105. return Result::success($result);
  4106. }
  4107. public function getComplaintList(array $data): array
  4108. {
  4109. var_dump($data, '00000001000000000000');
  4110. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4111. unset($data['type_id']);
  4112. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4113. $where = [];
  4114. if ($type_id != 10000 && empty($data['deal_user'])) {
  4115. $where['complaint.user_id'] = $user_id;
  4116. }
  4117. if (!empty($data['title'])) {
  4118. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4119. }
  4120. if (!empty($data['department_id'])) {
  4121. $where['complaint.department_id'] = $data['department_id'];
  4122. }
  4123. if (!empty($data['deal'])) {
  4124. $where['complaint.deal'] = $data['deal'];
  4125. }
  4126. if (!empty($data['status'])) {
  4127. $where['complaint.status'] = $data['status'];
  4128. }
  4129. var_dump(!empty($data['deal_user']), '----------1');
  4130. var_dump($where, '----------2');
  4131. $result = Complaint::where($where)
  4132. ->when(!empty($data['status1']), function ($query) use ($data) {
  4133. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4134. })
  4135. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4136. //json re_user_ids data[user_id]是不是在里面
  4137. $query->Where(function ($q) use ($data) {
  4138. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4139. ->where('complaint.status', 2);
  4140. });
  4141. })
  4142. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4143. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4144. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4145. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4146. ->orderBy('updated_at', 'desc')
  4147. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4148. //sql输出
  4149. if (empty($result)) {
  4150. return Result::error("暂无投诉信息", 0);
  4151. }
  4152. // 取出数据
  4153. $rows = $result->items();
  4154. $count = $result->total();
  4155. $responseData = [
  4156. 'rows' => $rows,
  4157. 'count' => $count,
  4158. ];
  4159. return Result::success($responseData);
  4160. }
  4161. public function getComplaintInfo(array $data): array
  4162. {
  4163. $result = Complaint::where('id', $data['id'])->first();
  4164. if (empty($result)) {
  4165. return Result::error("查询失败", 0);
  4166. }
  4167. return Result::success($result);
  4168. }
  4169. public function addComplaint(array $data): array
  4170. {
  4171. date_default_timezone_set('Asia/Shanghai');
  4172. $data['created_at'] = date('Y-m-d H:i:s');
  4173. $data['updated_at'] = date('Y-m-d H:i:s');
  4174. $result = Complaint::create($data);
  4175. return Result::success($result);
  4176. }
  4177. public function updateComplaint(array $data): array
  4178. {
  4179. date_default_timezone_set('Asia/Shanghai');
  4180. $data['updated_at'] = date('Y-m-d H:i:s');
  4181. $user_id = $data['user_id'] ?? 0;
  4182. $type_id = $data['type_id'] ?? 0;
  4183. unset($data['user_id']);
  4184. unset($data['type_id']);
  4185. $result = Complaint::where('id', $data['id'])->update($data);
  4186. return Result::success($result);
  4187. }
  4188. public function deleteComplaint(array $data): array
  4189. {
  4190. $result = Complaint::where('id', $data['id'])->delete();
  4191. return Result::success($result);
  4192. }
  4193. public function getComplainInfo(array $data): array
  4194. {
  4195. $result = Complaint::where('id', $data['id'])->first();
  4196. if (empty($result)) {
  4197. return Result::error("查询失败", 0);
  4198. }
  4199. return Result::success($result);
  4200. }
  4201. public function updateComplaintStatus(array $data): array
  4202. {
  4203. date_default_timezone_set('Asia/Shanghai');
  4204. $data['updated_at'] = date('Y-m-d H:i:s');
  4205. $user_id = $data['user_id'] ?? 0;
  4206. $type_id = $data['type_id'] ?? 0;
  4207. unset($data['user_id']);
  4208. unset($data['type_id']);
  4209. //处理, 写入处理人
  4210. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4211. $data['real_deal_user'] = $user_id;
  4212. }
  4213. //如果是deal 23,则判断是不是处理人
  4214. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4215. $complaintInof = Complaint::where('id', $data['id'])
  4216. ->where('real_deal_user', $user_id)
  4217. ->first();
  4218. if (empty($complaintInof)) {
  4219. return Result::error("处理人错误", 0);
  4220. }
  4221. }
  4222. $result = complaint::where('id', $data['id'])->update($data);
  4223. return Result::success($result);
  4224. }
  4225. public function updateGoodStatus(array $data): array
  4226. {
  4227. $user_id = $data['user_id'] ?? 0;
  4228. $type_id = $data['type_id'] ?? 0;
  4229. unset($data['user_id']);
  4230. unset($data['type_id']);
  4231. $result = Good::where('id', $data['id'])->update($data);
  4232. return Result::success($result);
  4233. }
  4234. public function updateJobHuntingStatus(array $data): array
  4235. {
  4236. $user_id = $data['user_id'] ?? 0;
  4237. $type_id = $data['type_id'] ?? 0;
  4238. unset($data['user_id']);
  4239. unset($data['type_id']);
  4240. $result = JobHunting::where('id', $data['id'])->update($data);
  4241. return Result::success($result);
  4242. }
  4243. public function updateNoticeStatus(array $data): array
  4244. {
  4245. $user_id = $data['user_id'] ?? 0;
  4246. $type_id = $data['type_id'] ?? 0;
  4247. unset($data['user_id']);
  4248. unset($data['type_id']);
  4249. $result = Notice::where('id', $data['id'])->update($data);
  4250. return Result::success($result);
  4251. }
  4252. public function getDUser(array $data): array
  4253. {
  4254. if (!empty($data['ids'])) {
  4255. $user = User::whereIn('id', $data['ids'])->getall();
  4256. if (empty($user)) {
  4257. return Result::error('无数据', 0);
  4258. }
  4259. return Result::success($user);
  4260. }
  4261. $where = [];
  4262. if (!empty($data['department_id'])) {
  4263. $where['department_id'] = $data['department_id'];
  4264. }
  4265. if (!empty($data['city_id'])) {
  4266. $where['city_id'] = $data['city_id'];
  4267. }
  4268. $result = User::where('type_id', 2)
  4269. ->where('status', 1)
  4270. ->where('id', $data['id'])
  4271. ->first(['cat_arr_id']);
  4272. if (empty($article)) {
  4273. $article = JobHunting::where('website_id', $data['website_id'])
  4274. ->where('status', 2)
  4275. ->where('id', $data['id'])
  4276. ->first(['cat_arr_id']);
  4277. }
  4278. if (empty($article)) {
  4279. return Result::error("该招工招聘不存在", 0);
  4280. }
  4281. break;
  4282. default:
  4283. return Result::error("该数据不存在", 0);
  4284. break;
  4285. }
  4286. $catid = json_decode($article['cat_arr_id'], true);
  4287. if (empty($catid)) {
  4288. return Result::error("该数据不存在", 0);
  4289. }
  4290. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4291. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  4292. ->whereIn('category_id', $catid)
  4293. ->pluck('aLIas_pinyin')
  4294. ->implode('/');
  4295. }
  4296. if ($last_category['pid'] != 0) {
  4297. $cat_arr = json_decode($last_category['category_arr_id'], true);
  4298. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4299. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  4300. ->whereIn('category_id', $cat_arr)
  4301. ->pluck('aLIas_pinyin')
  4302. ->implode('/');
  4303. } else {
  4304. $pinyin = $last_category['aLIas_pinyin'];
  4305. }
  4306. if (empty($pinyin) || $pinyin != $data['all_route']) {
  4307. return Result::error('非法路径!');
  4308. } else {
  4309. return Result::success($pinyin);
  4310. }
  4311. }
  4312. /**
  4313. * 验证导航名称是否重复
  4314. * @return void
  4315. */
  4316. public function checkCategoryName(array $data): array
  4317. {
  4318. $result = Category::when($data, function ($query) use ($data) {
  4319. if (isset($data['name']) && $data['name']) {
  4320. $query->where("name", $data['name']);
  4321. }
  4322. if (isset($data['id']) && $data['id']) {
  4323. $query->where("id", "!=", $data['id']);
  4324. }
  4325. })->first();
  4326. if ($result) {
  4327. return Result::error("已存在");
  4328. } else {
  4329. return Result::success();
  4330. }
  4331. }
  4332. //20250226 产品列表
  4333. public function getGoodList(array $data): array
  4334. {
  4335. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4336. unset($data['type_id']);
  4337. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4338. $where = [];
  4339. if ($type_id != '10000') {
  4340. $where = [
  4341. 'good.user_id' => $user_id,
  4342. ];
  4343. }
  4344. //类型
  4345. if (isset($data['type_id']) && $data['type_id']) {
  4346. $where = [
  4347. 'type_id' => $data['type_id'],
  4348. ];
  4349. }
  4350. //名称
  4351. if (isset($data['name']) && $data['name']) {
  4352. $where = [
  4353. 'good.name' => $data['name'],
  4354. ];
  4355. }
  4356. //status
  4357. if (isset($data['status']) && $data['status'] != '') {
  4358. $where = [
  4359. 'good.status' => $data['status'],
  4360. ];
  4361. }
  4362. //status1
  4363. // if (isset($data['status1']) && $data['status1'] == 1) {
  4364. // $status1 = 1;
  4365. // }
  4366. $where1 = [];
  4367. //website_id
  4368. // if (isset($data['website_id']) && $data['website_id']) {
  4369. // $where1 = [
  4370. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4371. // ];
  4372. // }
  4373. // website_name
  4374. if (isset($data['website_name']) && $data['website_name']) {
  4375. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4376. }
  4377. // catid
  4378. if (isset($data['category_name']) && $data['category_name']) {
  4379. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4380. }
  4381. // $result = Good::where($where)
  4382. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4383. $result = Good::where($where)
  4384. ->when(!empty($where1), function ($query) use ($where1) {
  4385. return $query->where($where1);
  4386. })
  4387. //status 1待审核2已审核3已拒绝
  4388. ->when(isset($data['status1']), function ($query) {
  4389. return $query->whereIn('good.status', [1, 3]);
  4390. })
  4391. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4392. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4393. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4394. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4395. ->orderBy("updated_at", "desc")
  4396. ->limit($data['page_size'])
  4397. ->offset(($data['page'] - 1) * $data['page_size'])
  4398. ->get();
  4399. $count = Good::where($where)
  4400. ->when(!empty($where1), function ($query) use ($where1) {
  4401. return $query->where($where1);
  4402. })
  4403. //status 1待审核2已审核3已拒绝
  4404. ->when(isset($data['status1']), function ($query) {
  4405. return $query->whereIn('good.status', [1, 3]);
  4406. })
  4407. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4408. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4409. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4410. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4411. ->orderBy("updated_at", "desc")->count();
  4412. $data = [
  4413. 'rows' => $result->toArray(),
  4414. 'count' => $count,
  4415. ];
  4416. if (empty($result)) {
  4417. return Result::error("此栏目暂无相关产品", 0);
  4418. }
  4419. return Result::success($data);
  4420. }
  4421. public function getGoodInfo(array $data): array
  4422. {
  4423. $result = Good::where('id', $data['id'])->first();
  4424. if (empty($result)) {
  4425. return Result::error("此产品不存在", 0);
  4426. }
  4427. return Result::success($result);
  4428. }
  4429. public function addGood(array $data): array
  4430. {
  4431. // unset($data['city_arr_id']);
  4432. // unset($data['cat_arr_id']);
  4433. $data['city_id'] = end($data['city_arr_id']);
  4434. $data['catid'] = end($data['cat_arr_id']);
  4435. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4436. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4437. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4438. unset($data['imgUrl']);
  4439. if (isset($data['price']) && $data['price'] == '') {
  4440. $data['price'] = 0;
  4441. }
  4442. $result = Good::insert($data);
  4443. if (empty($result)) {
  4444. return Result::error("添加失败", 0);
  4445. }
  4446. return Result::success($result);
  4447. }
  4448. public function updateGood(array $data): array
  4449. {
  4450. $data['city_id'] = end($data['city_arr_id']);
  4451. $data['catid'] = end($data['cat_arr_id']);
  4452. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4453. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4454. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4455. //设置东八区
  4456. date_default_timezone_set('Asia/Shanghai');
  4457. $data['updated_at'] = date('Y-m-d H:i:s');
  4458. if (isset($data['price']) && $data['price'] == '') {
  4459. $data['price'] = 0;
  4460. }
  4461. $result = Good::where('id', $data['id'])->update($data);
  4462. if (empty($result)) {
  4463. return Result::error("更新失败", 0);
  4464. }
  4465. return Result::success($result);
  4466. }
  4467. public function delGood(array $data): array
  4468. {
  4469. $result = Good::where('id', $data['id'])->delete();
  4470. if (empty($result)) {
  4471. return Result::error("删除失败", 0);
  4472. }
  4473. return Result::success($result);
  4474. }
  4475. //20250226 产品列表
  4476. //20250306 求职信息
  4477. public function getJobHuntingList(array $data): array
  4478. {
  4479. $where = [];
  4480. if (isset($data['username']) && !empty($data['username'])) {
  4481. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4482. }
  4483. //status 1待审核2已审核3已拒绝
  4484. if (isset($data['status']) && $data['status'] != '') {
  4485. $where = [
  4486. 'job_hunting.status' => $data['status'],
  4487. ];
  4488. }
  4489. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4490. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4491. unset($data['type_id']);
  4492. if ($type_id != '10000') {
  4493. $where[] = ['job_hunting.user_id', '=', $user_id];
  4494. }
  4495. $result = JobHunting::where($where)
  4496. ->when(!empty($data['status1']), function ($query) use ($data) {
  4497. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4498. })
  4499. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4500. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4501. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4502. ->orderBy("updated_at", "desc")
  4503. ->limit($data['page_size'])
  4504. ->offset(($data['page'] - 1) * $data['page_size'])
  4505. ->get();
  4506. if (empty($result)) {
  4507. return Result::error("查询失败", 0);
  4508. }
  4509. $count = JobHunting::where($where)
  4510. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4511. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4512. ->count();
  4513. $data = [
  4514. 'rows' => $result->toArray(),
  4515. 'count' => $count,
  4516. ];
  4517. return Result::success($data);
  4518. }
  4519. public function getJobHuntingApply(array $data): array
  4520. {
  4521. var_dump($data, '-----------------test--------1-');
  4522. $where = [];
  4523. if (isset($data['username']) && !empty($data['username'])) {
  4524. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4525. }
  4526. if (isset($data['salary']) && !empty($data['salary'])) {
  4527. $where[] = [
  4528. 'job_hunting.salary',
  4529. '=',
  4530. $data['salary'],
  4531. ];
  4532. }
  4533. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4534. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4535. unset($data['type_id']);
  4536. if ($type_id != '10000') {
  4537. $where[] = ['job_apply.user_id', '=', $user_id];
  4538. }
  4539. var_dump($where, '-----------------test---------');
  4540. $result = jobApply::where($where)
  4541. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4542. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4543. // })
  4544. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4545. ->where('job_enum.egroup', '=', 'income')
  4546. ->where('job_hunting.status', 2) //已审核
  4547. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4548. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4549. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4550. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4551. //职位----是申请职位
  4552. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4553. ->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')
  4554. ->orderBy("job_hunting.updated_at", "desc")
  4555. ->limit($data['page_size'])
  4556. ->offset(($data['page'] - 1) * $data['page_size'])
  4557. ->get();
  4558. if (empty($result)) {
  4559. return Result::error("查询失败", 0);
  4560. }
  4561. $count = jobApply::where($where)
  4562. ->where('job_enum.egroup', '=', 'income')
  4563. ->where('job_hunting.status', 2) //已审核
  4564. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4565. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4566. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4567. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4568. //职位----是申请职位
  4569. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4570. ->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')
  4571. ->count();
  4572. $data = [
  4573. 'rows' => $result->toArray(),
  4574. 'count' => $count,
  4575. ];
  4576. return Result::success($data);
  4577. }
  4578. public function addJobHunting(array $data): array
  4579. {
  4580. date_default_timezone_set('Asia/Shanghai');
  4581. unset($data['company_name']);
  4582. unset($data['job_industry']);
  4583. unset($data['job_name']);
  4584. unset($data['department']);
  4585. unset($data['job_timeList']);
  4586. unset($data['job_content']);
  4587. unset($data['job_typename']); //不知道这是啥,
  4588. $data['created_at'] = date('Y-m-d H:i:s');
  4589. $data['updated_at'] = date('Y-m-d H:i:s');
  4590. //根据用户 user_id 只能添加一次
  4591. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4592. if (!empty($result)) {
  4593. return Result::error("您已添加过求职信息", 0);
  4594. }
  4595. var_dump($result, '-----------------test---------');
  4596. $result = JobHunting::create($data);
  4597. if (empty($result)) {
  4598. return Result::error("添加失败", 0);
  4599. }
  4600. return Result::success($result);
  4601. }
  4602. public function delJobHunting(array $data): array
  4603. {
  4604. $result = JobHunting::where('id', $data['id'])->delete();
  4605. if (empty($result)) {
  4606. return Result::error("删除失败", 0);
  4607. }
  4608. return Result::success($result);
  4609. }
  4610. public function updateJobHunting(array $data): array
  4611. {
  4612. //设置东八区
  4613. date_default_timezone_set('Asia/Shanghai');
  4614. unset($data['company_name']);
  4615. unset($data['job_industry']);
  4616. unset($data['job_name']);
  4617. unset($data['department']);
  4618. unset($data['job_timeList']);
  4619. unset($data['job_content']);
  4620. unset($data['job_typename']); //不知道这是啥,
  4621. $data['created_at'] = date('Y-m-d H:i:s');
  4622. $data['updated_at'] = date('Y-m-d H:i:s');
  4623. $result = JobHunting::where('id', $data['id'])->update($data);
  4624. if (empty($result)) {
  4625. return Result::error("更新失败", 0);
  4626. }
  4627. return Result::success($result);
  4628. }
  4629. public function getJobHuntingInfo(array $data): array
  4630. {
  4631. $result = JobHunting::where('id', $data['id'])->first();
  4632. if (empty($result)) {
  4633. return Result::error("查询失败", 0);
  4634. }
  4635. return Result::success($result);
  4636. }
  4637. public function getJobHuntingData(array $data): array
  4638. {
  4639. $jobEnum = JobEnum::get();
  4640. $jobIndustry = JobIndustry::get();
  4641. $jobNature = JobNature::get();
  4642. $jobPosition = JobPosition::get();
  4643. $data = [
  4644. 'jobEnum' => $jobEnum,
  4645. 'jobIndustry' => $jobIndustry,
  4646. 'jobNature' => $jobNature,
  4647. 'jobPosition' => $jobPosition,
  4648. ];
  4649. return Result::success($data);
  4650. }
  4651. public function delJobHuntingInfo(array $data): array
  4652. {
  4653. $result = JobHunting::where('id', $data['id'])->delete();
  4654. return Result::success();
  4655. }
  4656. //20250324 通知,公告,消息
  4657. public function delNotice(array $data): array
  4658. {
  4659. $result = Notice::where('id', $data['id'])->delete();
  4660. if ($result) {
  4661. return Result::success();
  4662. } else {
  4663. return Result::error("删除失败", 0);
  4664. }
  4665. }
  4666. public function getNoticeInfo(array $data): array
  4667. {
  4668. $result = Notice::where('id', $data['id'])->first();
  4669. if (empty($result)) {
  4670. return Result::error("查询失败", 0);
  4671. }
  4672. return Result::success($result);
  4673. }
  4674. public function addNotice(array $data): array
  4675. {
  4676. date_default_timezone_set('Asia/Shanghai');
  4677. $data['created_at'] = date('Y-m-d H:i:s');
  4678. $data['updated_at'] = date('Y-m-d H:i:s');
  4679. $user_id = UserInfo::
  4680. //city_id不是null
  4681. whereNotNull('city_id')
  4682. ->whereNotNull('department_id')
  4683. ->where(function ($query) use ($data) {
  4684. $query->where(function ($subQuery) use ($data) {
  4685. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4686. });
  4687. })
  4688. ->where(function ($query) use ($data) {
  4689. $query->where(function ($subQuery) use ($data) {
  4690. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4691. });
  4692. })
  4693. ->pluck('user_id')->toArray();
  4694. $user_id = array_unique($user_id);
  4695. $chat_ids = $user_id;
  4696. $user_id = json_encode($user_id);
  4697. $data['re_user_ids'] = $user_id;
  4698. $result = Notice::insertGetId($data);
  4699. if ($result && $data['is_group'] == 1) {
  4700. //chat_group
  4701. $group_id = PublicData::uuid();
  4702. $groupData = [
  4703. 'id' => $group_id,
  4704. 'creator_id' => $data['user_id'],
  4705. 'group_name' => $data['group_name'] ?? '',
  4706. 'profile' => $data['profile'] ?? 0,
  4707. ];
  4708. var_dump($groupData, '-----------------groupData-------');
  4709. $groupResult = ChatGroups::insertGetId($groupData);
  4710. var_dump($groupResult, '-----------------groupid-------');
  4711. $groupMemberData = [
  4712. 'id' => PublicData::uuid(),
  4713. 'user_id' => $data['user_id'],
  4714. 'group_id' => $group_id,
  4715. 'leader' => 2,
  4716. ];
  4717. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4718. //$chat_ids 去除掉$data['user_id']
  4719. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  4720. //插入群成员表
  4721. $groupMemberDataUser = [];
  4722. $chatData = [];
  4723. foreach ($chat_ids as $key => $value) {
  4724. $groupMemberDataUser[] = [
  4725. 'id' => PublicData::uuid(),
  4726. 'user_id' => $value,
  4727. 'group_id' => $group_id,
  4728. 'leader' => 1,
  4729. ];
  4730. $chatData[] = [
  4731. 'user_id' => $value,
  4732. 'msg_type' => 1,
  4733. 'receiver_id' => $group_id,
  4734. 'content' => '通过通知创建群聊',
  4735. 'group_receiver_id' => $data['user_id'],
  4736. 'action' => 'recieved',
  4737. 'created_at' => date('Y-m-d H:i:s'),
  4738. ];
  4739. }
  4740. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4741. ChatGroupsMember::insert($groupMemberDataUser);
  4742. //插入一条管理员聊天记录
  4743. $chatData[] = [
  4744. 'user_id' => $data['user_id'],
  4745. 'msg_type' => 1,
  4746. 'receiver_id' => $group_id,
  4747. 'content' => '通过通知创建群聊',
  4748. 'group_receiver_id' => $data['user_id'],
  4749. 'action' => 'said',
  4750. 'created_at' => date('Y-m-d H:i:s'),
  4751. ];
  4752. var_dump($chatData, '-----------------chatData-------');
  4753. $chatResult = ChatRecords::insert($chatData);
  4754. //更新result的 group_id
  4755. $data['group_id'] = $group_id;
  4756. Notice::where(['id' => $result])->update($data);
  4757. }
  4758. if (empty($result)) {
  4759. return Result::error("添加失败", 0);
  4760. }
  4761. return Result::success($result);
  4762. }
  4763. public function updateNotice(array $data): array
  4764. {
  4765. date_default_timezone_set('Asia/Shanghai');
  4766. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4767. $user_id = UserInfo::
  4768. //city_id不是null
  4769. whereNotNull('city_id')
  4770. ->whereNotNull('department_id')
  4771. ->where(function ($query) use ($data) {
  4772. $query->where(function ($subQuery) use ($data) {
  4773. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4774. });
  4775. })
  4776. ->where(function ($query) use ($data) {
  4777. $query->where(function ($subQuery) use ($data) {
  4778. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4779. });
  4780. })
  4781. ->pluck('user_id')->toArray();
  4782. $user_id = array_unique($user_id);
  4783. $user_id = json_encode($user_id);
  4784. $data['re_user_ids'] = $user_id;
  4785. $data['updated_at'] = date('Y-m-d H:i:s');
  4786. $result = Notice::where('id', $data['id'])->update($data);
  4787. return Result::success($result);
  4788. }
  4789. public function getNoticeList(array $data): array
  4790. {
  4791. $where = [];
  4792. //title
  4793. if (isset($data['title']) && !empty($data['title'])) {
  4794. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4795. }
  4796. //level
  4797. if (isset($data['level']) && !empty($data['level'])) {
  4798. $where[] = ['notice.level', '=', $data['level']];
  4799. }
  4800. //status
  4801. if (isset($data['status']) && !empty($data['status'])) {
  4802. $where[] = ['notice.status', '=', $data['status']];
  4803. }
  4804. var_dump($data, '-----------------test---------');
  4805. if ($data['type_id'] == 10000) {
  4806. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4807. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4808. })
  4809. ->where($where)
  4810. ->orderBy('updated_at', 'desc')
  4811. ->limit($data['page_size'])
  4812. ->offset(($data['page'] - 1) * $data['page_size'])
  4813. ->get();
  4814. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4815. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4816. })
  4817. ->where($where)
  4818. ->orderBy('updated_at', 'desc')
  4819. ->count();
  4820. } else {
  4821. $result = Notice::where($where)
  4822. // ->where('user_id', $data['user_id'])
  4823. ->Where(function ($query) use ($data) {
  4824. $query->Where(function ($q) use ($data) {
  4825. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4826. ->orWhere('notice.user_id', $data['user_id']);
  4827. });
  4828. })
  4829. ->orderBy('updated_at', 'desc')
  4830. ->limit($data['page_size'])
  4831. ->offset(($data['page'] - 1) * $data['page_size'])
  4832. ->get();
  4833. $total = Notice::where($where)
  4834. // ->where('user_id', $data['user_id'])
  4835. ->Where(function ($query) use ($data) {
  4836. $query->Where(function ($q) use ($data) {
  4837. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4838. ->orWhere('notice.user_id', $data['user_id']);
  4839. });
  4840. })
  4841. ->count();
  4842. }
  4843. if (empty($result)) {
  4844. return Result::error("查询失败", 0);
  4845. }
  4846. $data = [
  4847. 'rows' => $result,
  4848. 'count' => $total,
  4849. ];
  4850. return Result::success($data);
  4851. }
  4852. public function getNoticeDetail(array $data): array
  4853. {
  4854. $result = Notice::where('id', $data['id'])->first();
  4855. if (empty($result)) {
  4856. return Result::error("查询失败", 0);
  4857. }
  4858. return Result::success($result);
  4859. }
  4860. public function deleteNotice(array $data): array
  4861. {
  4862. $notice = Notice::where('id', $data['id'])->first();
  4863. if (empty($notice)) {
  4864. return Result::error("删除失败", 0);
  4865. }
  4866. $chat_group_id = $notice->group_id;
  4867. if ($chat_group_id) {
  4868. //删除群聊
  4869. ChatGroups::where('id', $chat_group_id)->delete();
  4870. //删除群成员
  4871. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4872. //删除群聊记录
  4873. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4874. }
  4875. $result = Notice::where('id', $data['id'])->delete();
  4876. return Result::success($result);
  4877. }
  4878. public function getMSG(array $data): array
  4879. {
  4880. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  4881. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  4882. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  4883. $result = [];
  4884. if ($type_id == 1) {
  4885. //最近的5篇已审的文章
  4886. $apply_articale = Article::where('status', 1)
  4887. ->where('admin_user_id', $user_id)
  4888. ->orderBy('updated_at', 'desc')
  4889. ->limit(5)->get();
  4890. //获取5条单聊未读聊天消息
  4891. $chat = ChatRecords::where('is_read', 0)
  4892. ->where('user_id', $user_id)
  4893. ->where('talk_type', 1)
  4894. ->orderBy('created_at', 'desc')
  4895. ->limit(5)->get();
  4896. //获取5条未读群聊信息
  4897. $chat_group = ChatRecords::where('is_read', 0)
  4898. ->where('user_id', $user_id)
  4899. ->where('talk_type', 2)
  4900. ->orderBy('created_at', 'desc')
  4901. ->limit(5)->get();
  4902. //获取5条用户的已审核商品
  4903. $good = Good::where('status', 2)
  4904. ->where('user_id', $user_id)
  4905. ->orderBy('updated_at', 'desc')
  4906. ->limit(5)->get();
  4907. //获取5条用户待审核的公告
  4908. $notice = Notice::where('status', 2)
  4909. ->where('user_id', $user_id)
  4910. ->orderBy('updated_at', 'desc')
  4911. ->limit(5)->get();
  4912. //获取5条用户的待审核投诉
  4913. $complaint = Complaint::where('status', 2)
  4914. ->where('user_id', $user_id)
  4915. ->orderBy('updated_at', 'desc')
  4916. ->limit(5)->get();
  4917. //获取5条用户的book
  4918. $book = Book::where('status', 2)
  4919. ->where('user_id', $user_id)
  4920. ->orderBy('updated_at', 'desc')
  4921. ->limit(5)->get();
  4922. //获取5条用户的求职
  4923. //获取5条用户的求职 1
  4924. $job_hunting = JobHunting::where('job_hunting.status', 1)
  4925. ->where('job_hunting.user_id', $user_id)
  4926. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4927. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  4928. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4929. ->orderBy('updated_at', 'desc')
  4930. ->limit(5)->get();
  4931. //获取5条用户的求职 2
  4932. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  4933. ->where('job_recruiting.user_id', $user_id)
  4934. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4935. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4936. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4937. ->orderBy('updated_at', 'desc')
  4938. ->limit(5)->get();
  4939. //人才库 1
  4940. $job_apply = JobApply::where('job_apply.status', 1)
  4941. ->where('job_apply.receiver_id', $user_id)
  4942. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  4943. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  4944. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  4945. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  4946. ->select('job_recruiting', 'job_recruiting.', '', '')
  4947. ->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')
  4948. ->orderBy('updated_at', 'desc')
  4949. ->limit(5)->get();
  4950. // 职场机会 2
  4951. $job_resume = JobResume::where('job_resume.status', 1)
  4952. ->where('job_resume.receiver_id', $user_id)
  4953. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  4954. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  4955. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  4956. ->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')
  4957. ->orderBy('updated_at', 'desc')
  4958. ->limit(5)->get();
  4959. $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);
  4960. $result = [
  4961. 'apply_articale' => $apply_articale,
  4962. 'chat' => $chat,
  4963. 'chat_group' => $chat_group,
  4964. 'good' => $good,
  4965. 'notice' => $notice,
  4966. 'complaint' => $complaint,
  4967. 'book' => $book,
  4968. 'job_hunting' => $job_hunting,
  4969. 'job_recruiting' => $job_recruiting,
  4970. 'job_apply' => $job_apply,
  4971. 'job_resume' => $job_resume,
  4972. 'count' => $count,
  4973. ];
  4974. } elseif ($type_id == 2) {
  4975. //最近的5篇已审的文章
  4976. $apply_articale = Article::where('status', 1)
  4977. ->where('admin_user_id', $user_id)
  4978. ->limit(5)->get();
  4979. //获取5条单聊未读聊天消息
  4980. $chat = ChatRecords::where('is_read', 0)
  4981. ->where('user_id', $user_id)
  4982. ->where('talk_type', 1)
  4983. ->orderBy('created_at', 'desc')
  4984. ->limit(5)->get();
  4985. //获取5条未读群聊信息
  4986. $chat_group = ChatRecords::where('is_read', 0)
  4987. ->where('user_id', $user_id)
  4988. ->where('talk_type', 2)
  4989. ->orderBy('created_at', 'desc')
  4990. ->limit(5)->get();
  4991. //获取5条用户的已审核商品
  4992. $good = Good::where('status', 2)
  4993. ->where('user_id', $user_id)
  4994. ->orderBy('updated_at', 'desc')
  4995. ->limit(5)->get();
  4996. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  4997. $result = [
  4998. 'apply_articale' => $apply_articale,
  4999. 'chat' => $chat,
  5000. 'chat_group' => $chat_group,
  5001. 'good' => $good,
  5002. 'count' => $count,
  5003. ];
  5004. } elseif ($type_id == 3) {
  5005. //最近的5篇已审的文章
  5006. $apply_articale = Article::where('status', 1)
  5007. ->where('admin_user_id', $user_id)
  5008. ->limit(5)->get();
  5009. //获取5条单聊未读聊天消息
  5010. $chat = ChatRecords::where('is_read', 0)
  5011. ->where('user_id', $user_id)
  5012. ->where('talk_type', 1)
  5013. ->orderBy('created_at', 'desc')
  5014. ->limit(5)->get();
  5015. //获取5条未读群聊信息
  5016. $chat_group = ChatRecords::where('is_read', 0)
  5017. ->where('user_id', $user_id)
  5018. ->where('talk_type', 2)
  5019. ->orderBy('created_at', 'desc')
  5020. ->limit(5)->get();
  5021. //获取5条用户的已审核商品
  5022. $good = Good::where('status', 2)
  5023. ->where('user_id', $user_id)
  5024. ->orderBy('updated_at', 'desc')
  5025. ->limit(5)->get();
  5026. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  5027. $result = [
  5028. 'apply_articale' => $apply_articale,
  5029. 'chat' => $chat,
  5030. 'chat_group' => $chat_group,
  5031. 'good' => $good,
  5032. 'count' => $count,
  5033. ];
  5034. } elseif ($type_id == 4) {
  5035. //最近的5篇已审的文章
  5036. $apply_articale = Article::where('status', 1)
  5037. ->where('admin_user_id', $user_id)
  5038. ->limit(5)->get();
  5039. //获取5条用户的已审核商品
  5040. $good = Good::where('status', 2)
  5041. ->where('user_id', $user_id)
  5042. ->orderBy('updated_at', 'desc')
  5043. ->limit(5)->get();
  5044. $count = count($apply_articale) + count($good);
  5045. $result = [
  5046. 'apply_articale' => $apply_articale,
  5047. 'chat' => '',
  5048. 'chat_group' => '',
  5049. 'good' => $good,
  5050. 'count' => $count,
  5051. ];
  5052. } elseif ($type_id == 10000) {
  5053. //获取未审核的5篇文章
  5054. $apply_articale = Article::where('status', 0)
  5055. ->orderBy('updated_at', 'desc')
  5056. ->limit(5)->get();
  5057. //获取5条单聊未读聊天消息
  5058. $chat = ChatRecords::where('is_read', 0)
  5059. ->where('user_id', $user_id)
  5060. ->where('talk_type', 1)
  5061. ->orderBy('created_at', 'desc')
  5062. ->limit(5)->get();
  5063. //获取5条未读群聊信息
  5064. $chat_group = ChatRecords::where('is_read', 0)
  5065. ->where('user_id', $user_id)
  5066. ->where('talk_type', 2)
  5067. ->orderBy('created_at', 'desc')
  5068. ->limit(5)->get();
  5069. //获取5条用户的已审核商品
  5070. $good = Good::where('status', 1)
  5071. // ->where('user_id', $user_id)
  5072. ->orderBy('updated_at', 'desc')
  5073. ->limit(5)->get();
  5074. //获取5条用户待审核的公告
  5075. $notice = Notice::where('status', 1)
  5076. ->orderBy('updated_at', 'desc')
  5077. ->limit(5)->get();
  5078. //获取5条用户的待审核投诉
  5079. $complaint = Complaint::where('status', 1)
  5080. ->orderBy('updated_at', 'desc')
  5081. ->limit(5)->get();
  5082. //获取5条用户的book
  5083. $book = Book::where('status', 1)
  5084. ->orderBy('updated_at', 'desc')
  5085. ->limit(5)->get();
  5086. //获取5条用户的求职 1
  5087. $job_hunting = JobHunting::where('job_hunting.status', 1)
  5088. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  5089. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  5090. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  5091. ->orderBy('updated_at', 'desc')
  5092. ->limit(5)->get();
  5093. //获取5条用户的求职 2
  5094. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  5095. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5096. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5097. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  5098. ->orderBy('updated_at', 'desc')
  5099. ->limit(5)->get();
  5100. //人才库 1
  5101. $job_apply = JobApply::where('job_apply.status', 1)
  5102. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  5103. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  5104. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  5105. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  5106. ->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')
  5107. ->orderBy('updated_at', 'desc')
  5108. ->limit(5)->get();
  5109. // 职场机会 2
  5110. $job_resume = JobResume::where('job_resume.status', 1)
  5111. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  5112. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  5113. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  5114. ->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')
  5115. ->orderBy('updated_at', 'desc')
  5116. ->limit(5)->get();
  5117. $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);
  5118. $result = [
  5119. 'apply_articale' => $apply_articale,
  5120. 'chat' => $chat,
  5121. 'chat_group' => $chat_group,
  5122. 'good' => $good,
  5123. 'notice' => $notice,
  5124. 'complaint' => $complaint,
  5125. 'book' => $book,
  5126. 'job_hunting' => $job_hunting,
  5127. 'job_recruiting' => $job_recruiting,
  5128. 'job_apply' => $job_apply,
  5129. 'job_resume' => $job_resume,
  5130. 'count' => $count,
  5131. ];
  5132. } elseif ($type_id == 20000) {
  5133. }
  5134. var_dump($type_id, '-----------------test---------');
  5135. return Result::success($result);
  5136. }
  5137. public function getComplaintList(array $data): array
  5138. {
  5139. var_dump($data, '00000001000000000000');
  5140. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  5141. unset($data['type_id']);
  5142. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  5143. $where = [];
  5144. if ($type_id != 10000 && empty($data['deal_user'])) {
  5145. $where['complaint.user_id'] = $user_id;
  5146. }
  5147. if (!empty($data['title'])) {
  5148. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  5149. }
  5150. if (!empty($data['department_id'])) {
  5151. $where['complaint.department_id'] = $data['department_id'];
  5152. }
  5153. if (!empty($data['deal'])) {
  5154. $where['complaint.deal'] = $data['deal'];
  5155. }
  5156. if (!empty($data['status'])) {
  5157. $where['complaint.status'] = $data['status'];
  5158. }
  5159. var_dump(!empty($data['deal_user']), '----------1');
  5160. var_dump($where, '----------2');
  5161. $result = Complaint::where($where)
  5162. ->when(!empty($data['status1']), function ($query) use ($data) {
  5163. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5164. })
  5165. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5166. //json re_user_ids data[user_id]是不是在里面
  5167. $query->Where(function ($q) use ($data) {
  5168. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5169. ->where('complaint.status', 2);
  5170. });
  5171. })
  5172. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5173. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5174. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5175. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5176. ->orderBy('updated_at', 'desc')
  5177. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5178. //sql输出
  5179. if (empty($result)) {
  5180. return Result::error("暂无投诉信息", 0);
  5181. }
  5182. // 取出数据
  5183. $rows = $result->items();
  5184. $count = $result->total();
  5185. $responseData = [
  5186. 'rows' => $rows,
  5187. 'count' => $count,
  5188. ];
  5189. return Result::success($responseData);
  5190. }
  5191. public function getComplaintInfo(array $data): array
  5192. {
  5193. $result = Complaint::where('id', $data['id'])->first();
  5194. if (empty($result)) {
  5195. return Result::error("查询失败", 0);
  5196. }
  5197. return Result::success($result);
  5198. }
  5199. public function addComplaint(array $data): array
  5200. {
  5201. date_default_timezone_set('Asia/Shanghai');
  5202. $data['created_at'] = date('Y-m-d H:i:s');
  5203. $data['updated_at'] = date('Y-m-d H:i:s');
  5204. $result = Complaint::create($data);
  5205. return Result::success($result);
  5206. }
  5207. public function updateComplaint(array $data): array
  5208. {
  5209. date_default_timezone_set('Asia/Shanghai');
  5210. $data['updated_at'] = date('Y-m-d H:i:s');
  5211. $user_id = $data['user_id'] ?? 0;
  5212. $type_id = $data['type_id'] ?? 0;
  5213. unset($data['user_id']);
  5214. unset($data['type_id']);
  5215. $result = Complaint::where('id', $data['id'])->update($data);
  5216. return Result::success($result);
  5217. }
  5218. public function deleteComplaint(array $data): array
  5219. {
  5220. $result = Complaint::where('id', $data['id'])->delete();
  5221. return Result::success($result);
  5222. }
  5223. public function getComplainInfo(array $data): array
  5224. {
  5225. $result = Complaint::where('id', $data['id'])->first();
  5226. if (empty($result)) {
  5227. return Result::error("查询失败", 0);
  5228. }
  5229. return Result::success($result);
  5230. }
  5231. public function updateComplaintStatus(array $data): array
  5232. {
  5233. date_default_timezone_set('Asia/Shanghai');
  5234. $data['updated_at'] = date('Y-m-d H:i:s');
  5235. $user_id = $data['user_id'] ?? 0;
  5236. $type_id = $data['type_id'] ?? 0;
  5237. unset($data['user_id']);
  5238. unset($data['type_id']);
  5239. //处理, 写入处理人
  5240. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5241. $data['real_deal_user'] = $user_id;
  5242. }
  5243. //如果是deal 23,则判断是不是处理人
  5244. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5245. $complaintInof = Complaint::where('id', $data['id'])
  5246. ->where('real_deal_user', $user_id)
  5247. ->first();
  5248. if (empty($complaintInof)) {
  5249. return Result::error("处理人错误", 0);
  5250. }
  5251. }
  5252. $result = complaint::where('id', $data['id'])->update($data);
  5253. return Result::success($result);
  5254. }
  5255. public function updateGoodStatus(array $data): array
  5256. {
  5257. $user_id = $data['user_id'] ?? 0;
  5258. $type_id = $data['type_id'] ?? 0;
  5259. unset($data['user_id']);
  5260. unset($data['type_id']);
  5261. $result = Good::where('id', $data['id'])->update($data);
  5262. return Result::success($result);
  5263. }
  5264. public function updateJobHuntingStatus(array $data): array
  5265. {
  5266. $user_id = $data['user_id'] ?? 0;
  5267. $type_id = $data['type_id'] ?? 0;
  5268. unset($data['user_id']);
  5269. unset($data['type_id']);
  5270. $result = JobHunting::where('id', $data['id'])->update($data);
  5271. return Result::success($result);
  5272. }
  5273. public function updateNoticeStatus(array $data): array
  5274. {
  5275. $user_id = $data['user_id'] ?? 0;
  5276. $type_id = $data['type_id'] ?? 0;
  5277. unset($data['user_id']);
  5278. unset($data['type_id']);
  5279. $result = Notice::where('id', $data['id'])->update($data);
  5280. return Result::success($result);
  5281. }
  5282. public function getDUser(array $data): array
  5283. {
  5284. if (!empty($data['ids'])) {
  5285. $user = User::whereIn('id', $data['ids'])->getall();
  5286. if (empty($user)) {
  5287. return Result::error('无数据', 0);
  5288. }
  5289. return Result::success($user);
  5290. }
  5291. $where = [];
  5292. if (!empty($data['department_id'])) {
  5293. $where['department_id'] = $data['department_id'];
  5294. }
  5295. if (!empty($data['city_id'])) {
  5296. $where['city_id'] = $data['city_id'];
  5297. }
  5298. $result = User::where('type_id', 2)
  5299. ->where('status', 1)
  5300. ->where($where)
  5301. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5302. ->get();
  5303. if (empty($result)) {
  5304. return Result::error("查询失败", 0);
  5305. }
  5306. return Result::success($result);
  5307. }
  5308. //20250324 通知,公告,消息
  5309. // 20250306 -------招聘--------fr
  5310. /*
  5311. * 招聘列表
  5312. * */
  5313. public function getJobRecruitingList(array $data): array
  5314. {
  5315. $where = [];
  5316. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5317. if ($data['checkout'] == 0) {
  5318. $job_status = [0, 2];
  5319. } else {
  5320. $job_status = [1];
  5321. }
  5322. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5323. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5324. }
  5325. $user = User::where('id', $data['user_id'])->first();
  5326. if (empty($user)) {
  5327. return Result::error("用户不存在", 0);
  5328. }
  5329. // 3:企业会员
  5330. if ($user['type_id'] == 3) {
  5331. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5332. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5333. }
  5334. // 如果 $where 为空,则不添加 where 条件
  5335. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5336. return $query->where($where);
  5337. })
  5338. ->whereIn('job_recruiting.status', $job_status)
  5339. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5340. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5341. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5342. ->orderBy("updated_at", "desc")
  5343. ->offset(($data['page'] - 1) * $data['page_size'])
  5344. ->limit($data['page_size'])
  5345. ->get()
  5346. ->all();
  5347. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5348. return $query->where($where);
  5349. })
  5350. ->whereIn('job_recruiting.status', $job_status)
  5351. ->count();
  5352. if (empty($result)) {
  5353. return Result::error("暂无招聘信息", 0);
  5354. }
  5355. return Result::success($result);
  5356. }
  5357. /*
  5358. * 招聘信息添加
  5359. * */
  5360. public function addJobRecruiting(array $data): array
  5361. {
  5362. // return Result::success($data);
  5363. $user = User::where('user.id', $data['user_id'])
  5364. ->where('user.status', 1)
  5365. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5366. ->select(
  5367. 'user.type_id',
  5368. 'user.mobile',
  5369. 'user.email',
  5370. 'user_info.business_name',
  5371. 'user_info.company_hy_id',
  5372. 'user_info.company_nature',
  5373. 'user_info.company_size',
  5374. 'user_info.introduction',
  5375. 'user_info.real_name',
  5376. 'user_info.company_url',
  5377. 'user_info.address_arr_id',
  5378. 'user_info.address'
  5379. )
  5380. ->first();
  5381. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5382. return Result::error("用户不存在", 0);
  5383. }
  5384. $web = Website::where('id', $data['website_id'])->first();
  5385. if (empty($web)) {
  5386. return Result::error("网站不存在", 0);
  5387. }
  5388. // return Result::success($user);
  5389. $data['action_id'] = $data['user_id'];
  5390. $data['user_type'] = $user['type_id'];
  5391. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5392. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5393. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5394. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5395. // 公司地址 管理员必填
  5396. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5397. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5398. // 管理员-企业相关信息
  5399. $company = [
  5400. // 'user_id' => $data['user_id']?? null,
  5401. 'business_name' => $data['business_name'] ?? null,
  5402. 'company_hy_id' => $data['company_hy_id'] ?? null,
  5403. 'company_size' => $data['company_size'] ?? null,
  5404. 'company_nature' => $data['company_nature'] ?? null,
  5405. 'introduction' => $data['introduction'] ?? null,
  5406. 'real_name' => $data['real_name'] ?? null,
  5407. 'mobile' => $data['mobile'] ?? null,
  5408. 'company_url' => $data['company_url'] ?? null,
  5409. 'address_arr_id' => $data['address_arr_id'] ?? null,
  5410. 'address' => $data['address'] ?? null,
  5411. 'email' => $data['email'] ?? null,
  5412. ];
  5413. //去掉相关企业信息
  5414. $job = array_diff_key($data, array_flip(array_keys($company)));
  5415. Db::beginTransaction();
  5416. try {
  5417. // 先添加职位相关信息
  5418. if ($user['type_id'] == 10000) {
  5419. $job['status'] = 1;
  5420. }
  5421. if (empty($data['experience']) || $data['experience'] == '') {
  5422. $job['experience'] = null;
  5423. } else {
  5424. $job['experience'] = $data['experience'];
  5425. }
  5426. $jobId = JobRecruiting::insertGetId($job);
  5427. if (empty($jobId)) {
  5428. Db::rollBack();
  5429. return Result::error("添加失败");
  5430. }
  5431. // 添加公司信息
  5432. $company['user_id'] = $data['user_id'] ?? null;
  5433. $company['job_id'] = $jobId;
  5434. $company['user_type'] = $user['type_id'] ?? null;
  5435. $company['website_id'] = $data['website_id'] ?? null;
  5436. if ($user['type_id'] == 10000) {
  5437. // 管理员添加企业信息
  5438. // return Result::success($company);
  5439. $companyId = JobCompany::insertGetId($company);
  5440. if (empty($companyId)) {
  5441. Db::rollBack();
  5442. return Result::error("添加失败");
  5443. }
  5444. } else {
  5445. // 企业会员添加企业信息
  5446. $company = [
  5447. 'user_id' => $data['user_id'] ?? null,
  5448. 'business_name' => $user['business_name'] ?? null,
  5449. 'company_hy_id' => $user['company_hy_id'] ?? null,
  5450. 'company_size' => $user['company_size'] ?? null,
  5451. 'company_nature' => $user['company_nature'] ?? null,
  5452. 'introduction' => $user['introduction'] ?? null,
  5453. 'real_name' => $user['real_name'] ?? null,
  5454. 'mobile' => $user['mobile'] ?? null,
  5455. 'company_url' => $user['company_url'] ?? null,
  5456. 'address_arr_id' => $user['address_arr_id'] ?? null,
  5457. 'address' => $user['address'] ?? null,
  5458. 'email' => $user['email'] ?? null,
  5459. 'website_id' => $data['website_id'] ?? null,
  5460. 'user_type' => $user['type_id'] ?? null,
  5461. 'job_id' => $jobId,
  5462. ];
  5463. $companyId = JobCompany::insertGetId($company);
  5464. if (empty($companyId)) {
  5465. Db::rollBack();
  5466. return Result::error("添加失败");
  5467. }
  5468. // return Result::success($company);
  5469. }
  5470. Db::commit();
  5471. } catch (\Exception $e) {
  5472. Db::rollBack();
  5473. return Result::error($e->getMessage(), 0);
  5474. }
  5475. $result = [
  5476. 'job_id' => $jobId,
  5477. 'company_id' => $companyId,
  5478. ];
  5479. if (empty($result)) {
  5480. return Result::error("添加失败", 0);
  5481. }
  5482. return Result::success($result);
  5483. }
  5484. /*
  5485. * 获取招聘信息详情
  5486. * */
  5487. public function getJobRecruitingInfo(array $data): array
  5488. {
  5489. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5490. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5491. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5492. ->select(
  5493. 'job_recruiting.*',
  5494. 'website.website_name as website_name',
  5495. 'job_company.business_name',
  5496. 'job_company.company_hy_id',
  5497. 'job_company.company_size',
  5498. 'job_company.company_nature',
  5499. 'job_company.introduction',
  5500. 'job_company.real_name',
  5501. 'job_company.mobile',
  5502. 'job_company.company_url',
  5503. 'job_company.address_arr_id',
  5504. 'job_company.address',
  5505. 'job_company.email'
  5506. )
  5507. ->first();
  5508. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5509. if (!empty($cityId)) {
  5510. if (isset($cityId[1]) && $cityId[1] != null) {
  5511. $city = District::where('id', $cityId[1])->first(['name']);
  5512. } else {
  5513. $city = District::where('id', $cityId[0])->first(['name']);
  5514. }
  5515. $result['city'] = $city['name'] ?? '';
  5516. }
  5517. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5518. if (is_array($addressId) && !empty($addressId)) {
  5519. $address = District::whereIn('id', $addressId)
  5520. ->orderBy('level', 'asc')
  5521. ->get(['name'])
  5522. ->pluck('name')
  5523. ->implode('');
  5524. // $job->address_name = $address ?? '';
  5525. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5526. }
  5527. if (empty($result)) {
  5528. return Result::error("招聘信息不存在", 0);
  5529. }
  5530. // return Result::success($job);
  5531. return Result::success($result);
  5532. }
  5533. /*
  5534. * 修改招聘信息
  5535. * */
  5536. public function upJobRecruiting(array $data): array
  5537. {
  5538. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5539. // return Result::success($job);
  5540. if (empty($job)) {
  5541. return Result::error("招聘信息不存在", 0);
  5542. }
  5543. $user = User::where('id', $data['user_id'])->first();
  5544. // return Result::success($user);
  5545. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5546. return Result::error("用户不存在", 0);
  5547. }
  5548. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5549. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5550. }
  5551. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5552. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5553. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5554. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5555. // 公司地址 管理员必填
  5556. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5557. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5558. // 管理员-企业相关信息
  5559. $company = [
  5560. 'business_name' => $data['business_name'] ?? null,
  5561. 'company_hy_id' => $data['hy_id'] ?? null,
  5562. 'company_size' => $data['company_size'] ?? null,
  5563. 'company_nature' => $data['company_nature'] ?? null,
  5564. 'introduction' => $data['introduction'] ?? null,
  5565. 'real_name' => $data['real_name'] ?? null,
  5566. 'mobile' => $data['mobile'] ?? null,
  5567. 'company_url' => $data['company_url'] ?? null,
  5568. 'address_arr_id' => $data['address_arr_id'] ?? null,
  5569. 'address' => $data['address'] ?? null,
  5570. 'email' => $data['email'] ?? null,
  5571. ];
  5572. //去掉相关企业信息
  5573. $data = array_diff_key($data, array_flip(array_keys($company)));
  5574. $jobId = $data['id'];
  5575. $web = $data['website_id'];
  5576. $data['action_id'] = $data['user_id'];
  5577. unset($data['user_id']);
  5578. unset($data['user_type']);
  5579. unset($data['id']);
  5580. unset($data['website_id']);
  5581. // return Result::success($data);
  5582. Db::beginTransaction();
  5583. try {
  5584. // 管理员修改招聘信息
  5585. if ($user['type_id'] == 10000) {
  5586. $data['website_id'] = $web;
  5587. $company['website_id'] = $data['website_id'];
  5588. $data['status'] = 1;
  5589. } else {
  5590. $data['status'] = 0;
  5591. }
  5592. if (empty($data['experience']) || $data['experience'] == '') {
  5593. $job['experience'] = null;
  5594. } else {
  5595. $job['experience'] = $data['experience'];
  5596. }
  5597. // Db::rollBack();
  5598. // return Result::success($company);
  5599. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5600. if (empty($result['job'])) {
  5601. Db::rollBack();
  5602. return Result::error("修改招聘信息失败");
  5603. }
  5604. // 管理员修改企业相关信息
  5605. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5606. if (empty($result['company'])) {
  5607. Db::rollBack();
  5608. return Result::error("修改企业相关信息失败");
  5609. }
  5610. Db::commit();
  5611. // return Result::success($result);
  5612. } catch (\Exception $e) {
  5613. Db::rollBack();
  5614. return Result::error($e->getMessage(), 0);
  5615. }
  5616. return Result::success($result);
  5617. }
  5618. /*
  5619. * 招聘信息删除
  5620. * */
  5621. public function delJobRecruiting(array $data): array
  5622. {
  5623. $user = User::where('id', $data['user_id'])->first();
  5624. if (empty($user)) {
  5625. return Result::error("用户不存在", 0);
  5626. }
  5627. $job = JobRecruiting::where('id', $data['id'])->first();
  5628. if (empty($job)) {
  5629. return Result::error("招聘信息不存在", 0);
  5630. }
  5631. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5632. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5633. }
  5634. Db::beginTransaction();
  5635. try {
  5636. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5637. if (empty($result['job'])) {
  5638. Db::rollBack();
  5639. return Result::error("删除招聘信息失败");
  5640. }
  5641. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5642. if (empty($result['company'])) {
  5643. Db::rollBack();
  5644. return Result::error("删除企业相关信息失败");
  5645. }
  5646. Db::commit();
  5647. } catch (\Exception $e) {
  5648. Db::rollBack();
  5649. return Result::error($e->getMessage(), 0);
  5650. }
  5651. return Result::success($result);
  5652. }
  5653. /*
  5654. * 获取公司信息
  5655. * */
  5656. public function getJobCompany(array $data): array
  5657. {
  5658. $user = User::where('user.id', $data['user_id'])
  5659. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5660. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5661. ->first();
  5662. // return Result::success($user);
  5663. if (empty($user)) {
  5664. return Result::error("用户不存在", 0);
  5665. }
  5666. if ($user['type_id'] == 3) {
  5667. $result = [
  5668. // 'id' => 0,
  5669. 'user_id' => $data['user_id'],
  5670. 'website_id' => $data['website_id'],
  5671. 'business_name' => $user['business_name'], // 企业名称
  5672. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5673. 'company_nature' => $user['company_nature'], // 公司性质
  5674. 'company_size' => $user['company_size'], // 公司规模
  5675. 'introduction' => $user['introduction'], // 公司简介
  5676. 'real_name' => $user['real_name'], // 企业联系人
  5677. 'mobile' => $user['mobile'], // 企业联系电话
  5678. 'company_url' => $user['company_url'], // 企业网址
  5679. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5680. 'address' => $user['address'], // 企业地址
  5681. 'email' => $user['email'], // 企业邮箱
  5682. ];
  5683. } else {
  5684. return Result::error("用户类型错误", 0);
  5685. }
  5686. if (empty($result)) {
  5687. return Result::error("公司信息不存在", 0);
  5688. }
  5689. return Result::success($result);
  5690. }
  5691. /*
  5692. * 修改公司信息
  5693. * */
  5694. public function upJobCompany(array $data): array
  5695. {
  5696. // return Result::success($data);
  5697. $user = User::where('user.id', $data['user_id'])
  5698. ->where('user.status', 1)
  5699. ->select('user.user_name', 'user.type_id')
  5700. ->first();
  5701. if (empty($user)) {
  5702. return Result::error("用户不存在", 0);
  5703. }
  5704. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5705. $company = [
  5706. 'business_name' => $data['business_name'], // 企业名称
  5707. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5708. 'company_nature' => $data['company_nature'], // 公司性质
  5709. 'company_size' => $data['company_size'], // 公司规模
  5710. 'introduction' => $data['introduction'], // 公司简介
  5711. // 'real_name' => $data['real_name'], // 企业联系人
  5712. 'company_url' => $data['company_url'], // 企业网址
  5713. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5714. 'address' => $data['address'], // 企业详细地址
  5715. ];
  5716. if ($user['type_id'] == 3) {
  5717. Db::beginTransaction();
  5718. try {
  5719. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5720. 'business_name' => $data['business_name'], // 企业名称
  5721. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5722. 'company_nature' => $data['company_nature'], // 公司性质
  5723. 'company_size' => $data['company_size'], // 公司规模
  5724. 'introduction' => $data['introduction'], // 公司简介
  5725. // 'real_name' => $data['real_name'], // 企业联系人
  5726. 'company_url' => $data['company_url'], // 企业网址
  5727. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5728. 'address' => $data['address'], // 企业详细地址
  5729. ]);
  5730. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5731. Db::commit();
  5732. } catch (\Exception $e) {
  5733. Db::rollBack();
  5734. return Result::error($e->getMessage(), 0);
  5735. }
  5736. } else {
  5737. return Result::error("用户类型错误", 0);
  5738. }
  5739. if (empty($result)) {
  5740. return Result::error("修改失败", 0);
  5741. }
  5742. return Result::success($result);
  5743. }
  5744. /*
  5745. * 获取省-市
  5746. * */
  5747. public function getJobRecruitingArea(array $data): array
  5748. {
  5749. if (isset($data['pid']) && $data['pid'] != null) {
  5750. $result = District::where('pid', $data['pid'])->get()->all();
  5751. } else {
  5752. $result = District::where('level', 1)->get()->all();
  5753. }
  5754. if (empty($result)) {
  5755. return Result::error("暂无此省市", 0);
  5756. }
  5757. return Result::success($result);
  5758. }
  5759. /*
  5760. * 获取行业分类
  5761. * */
  5762. public function getIndustry(array $data): array
  5763. {
  5764. $result = JobIndustry::get()->all();
  5765. if (empty($result)) {
  5766. return Result::error("暂无行业分类", 0);
  5767. }
  5768. return Result::success($result);
  5769. }
  5770. /*
  5771. * 获取职位
  5772. * */
  5773. public function getPositionList(array $data): array
  5774. {
  5775. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5776. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5777. } else {
  5778. $result = JobPosition::where('zwpid', 0)->get()->all();
  5779. }
  5780. if (empty($result)) {
  5781. return Result::error("暂无此职位", 0);
  5782. }
  5783. return Result::success($result);
  5784. }
  5785. /*
  5786. * 获取工作性质-菜单
  5787. * */
  5788. public function getJobNature(array $data): array
  5789. {
  5790. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5791. if (empty($result)) {
  5792. return Result::error("暂无工作性质", 0);
  5793. }
  5794. return Result::success($result);
  5795. }
  5796. /*
  5797. * 获取工作经验-菜单
  5798. * */
  5799. public function getExperience(array $data): array
  5800. {
  5801. $result = JobEnum::where('egroup', 'years')->get()->all();
  5802. if (empty($result)) {
  5803. return Result::error("暂无工作经验", 0);
  5804. }
  5805. return Result::success($result);
  5806. }
  5807. /*
  5808. * 获取学历-菜单
  5809. * */
  5810. public function getEducation(array $data): array
  5811. {
  5812. $result = JobEnum::where('egroup', 'education')->get()->all();
  5813. if (empty($result)) {
  5814. return Result::error("暂无学历", 0);
  5815. }
  5816. return Result::success($result);
  5817. }
  5818. /*
  5819. * 获取薪资-菜单
  5820. * */
  5821. public function getSalary(array $data): array
  5822. {
  5823. $result = JobEnum::where('egroup', 'income')->get()->all();
  5824. if (empty($result)) {
  5825. return Result::error("暂无薪资", 0);
  5826. }
  5827. return Result::success($result);
  5828. }
  5829. /*
  5830. * 获取语言-菜单
  5831. * */
  5832. public function getLanguage(array $data): array
  5833. {
  5834. $result = JobEnum::where('egroup', 'language')->get()->all();
  5835. if (empty($result)) {
  5836. return Result::error("暂无语言", 0);
  5837. }
  5838. return Result::success($result);
  5839. }
  5840. /*
  5841. * 获取掌握程度-菜单
  5842. * */
  5843. public function getLevel(array $data): array
  5844. {
  5845. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5846. if (empty($result)) {
  5847. return Result::error("暂无工作性质", 0);
  5848. }
  5849. return Result::success($result);
  5850. }
  5851. // 公司信息
  5852. /*
  5853. * 获取公司性质-菜单
  5854. * */
  5855. public function getCompanyNature(array $data): array
  5856. {
  5857. $result = JobNature::get()->all();
  5858. if (empty($result)) {
  5859. return Result::error("暂无公司性质", 0);
  5860. }
  5861. return Result::success($result);
  5862. }
  5863. /*
  5864. * 获取公司规模-菜单
  5865. * */
  5866. public function getCompanySize(array $data): array
  5867. {
  5868. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5869. if (empty($result)) {
  5870. return Result::error("暂无公司规模", 0);
  5871. }
  5872. return Result::success($result);
  5873. }
  5874. /*
  5875. * 招聘信息审核
  5876. * */
  5877. public function checkJobRecruiting(array $data): array
  5878. {
  5879. $user = User::where('id', $data['user_id'])->first();
  5880. if (empty($user)) {
  5881. return Result::error("用户不存在", 0);
  5882. }
  5883. $job = JobRecruiting::where('id', $data['id'])->first();
  5884. if (empty($job)) {
  5885. return Result::error("招聘信息不存在", 0);
  5886. }
  5887. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5888. if ($user['type_id'] != 10000) {
  5889. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5890. }
  5891. // 驳回原因
  5892. if ($data['status'] == 2) {
  5893. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5894. }
  5895. $data['action_id'] = $data['user_id'];
  5896. unset($data['user_id']);
  5897. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5898. if (empty($result)) {
  5899. return Result::error("审核失败", 0);
  5900. }
  5901. return Result::success($result);
  5902. }
  5903. public function myApplyList(array $data): array
  5904. {
  5905. var_dump($data, '------参数');
  5906. $user = User::where('id', $data['user_id'])->first();
  5907. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5908. return Result::error("用户不存在", 0);
  5909. }
  5910. // 1:个人会员 职场机会
  5911. if ($user['type_id'] == 1) {
  5912. $where['user_id'] = $user['id'];
  5913. }
  5914. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5915. $query->where('user_id', $user['id']);
  5916. })
  5917. ->pluck('recruit_id');
  5918. $where = [];
  5919. if (isset($data['salary']) && $data['salary'] != null) {
  5920. $where['job_recruiting.salary'] = $data['salary'];
  5921. }
  5922. if (isset($data['experience']) && $data['experience'] != null) {
  5923. $where['job_recruiting.experience'] = $data['experience'];
  5924. }
  5925. if (isset($data['business_name']) && $data['business_name'] != null) {
  5926. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5927. }
  5928. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5929. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5930. ->where($where);
  5931. // ->count();
  5932. $count = $query->count();
  5933. $query = clone $query;
  5934. $job = $query
  5935. ->leftJoin('job_enum as income_enum', function ($join) {
  5936. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5937. ->where('income_enum.egroup', 'income');
  5938. })
  5939. ->leftJoin('job_enum as years_enum', function ($join) {
  5940. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5941. ->where('years_enum.egroup', 'years');
  5942. })
  5943. // ->where($where)
  5944. ->orderBy('job_recruiting.updated_at', 'desc')
  5945. ->select(
  5946. 'job_recruiting.id',
  5947. 'job_recruiting.title',
  5948. 'job_company.business_name',
  5949. 'income_enum.evalue as salary_evalue',
  5950. 'income_enum.ename as salary_ename',
  5951. 'years_enum.evalue as experience_evalue',
  5952. 'years_enum.ename as experience_ename',
  5953. 'job_recruiting.updated_at'
  5954. )
  5955. ->offset(($data['page'] - 1) * $data['pageSize'])
  5956. ->limit($data['pageSize'])
  5957. ->get()
  5958. ->all();
  5959. if (empty($job)) {
  5960. return Result::error("暂无招聘信息", 0);
  5961. }
  5962. $result = [
  5963. 'row' => $job,
  5964. 'count' => $count,
  5965. ];
  5966. return Result::success($result);
  5967. }
  5968. /*
  5969. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5970. * */
  5971. public function getRecruitingList(array $data): array
  5972. {
  5973. $user = User::where('id', $data['user_id'])->first();
  5974. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5975. return Result::error("用户不存在", 0);
  5976. }
  5977. // 1:个人会员 职场机会
  5978. if ($user['type_id'] == 1) {
  5979. $where['user_id'] = $user['id'];
  5980. }
  5981. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5982. $query->where('recruit_id', $user['id']);
  5983. })
  5984. ->pluck('recruit_id');
  5985. $where = [];
  5986. if (isset($data['salary']) && $data['salary'] != null) {
  5987. $where['job_recruiting.salary'] = $data['salary'];
  5988. }
  5989. if (isset($data['experience']) && $data['experience'] != null) {
  5990. $where['job_recruiting.experience'] = $data['experience'];
  5991. }
  5992. if (isset($data['business_name']) && $data['business_name'] != null) {
  5993. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5994. }
  5995. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5996. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5997. ->where($where);
  5998. // ->count();
  5999. $count = $query->count();
  6000. $query = clone $query;
  6001. $job = $query
  6002. ->leftJoin('job_enum as income_enum', function ($join) {
  6003. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6004. ->where('income_enum.egroup', 'income');
  6005. })
  6006. ->leftJoin('job_enum as years_enum', function ($join) {
  6007. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6008. ->where('years_enum.egroup', 'years');
  6009. })
  6010. // ->where($where)
  6011. ->orderBy('job_recruiting.updated_at', 'desc')
  6012. ->select(
  6013. 'job_recruiting.id',
  6014. 'job_recruiting.title',
  6015. 'job_company.business_name',
  6016. 'income_enum.evalue as salary_evalue',
  6017. 'income_enum.ename as salary_ename',
  6018. 'years_enum.evalue as experience_evalue',
  6019. 'years_enum.ename as experience_ename',
  6020. 'job_recruiting.updated_at'
  6021. )
  6022. ->offset(($data['page'] - 1) * $data['pageSize'])
  6023. ->limit($data['pageSize'])
  6024. ->get()
  6025. ->all();
  6026. if (empty($job)) {
  6027. return Result::error("暂无招聘信息", 0);
  6028. }
  6029. $result = [
  6030. 'row' => $job,
  6031. 'count' => $count,
  6032. ];
  6033. return Result::success($result);
  6034. }
  6035. /*
  6036. * 获取企业会员-招聘信息列表
  6037. * */
  6038. public function getRecruitingInfo(array $data): array
  6039. {
  6040. $user = User::where('id', $data['user_id'])->first();
  6041. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6042. return Result::error("用户不存在", 0);
  6043. }
  6044. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6045. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6046. ->select(
  6047. 'job_recruiting.*',
  6048. 'job_company.business_name',
  6049. 'job_company.company_hy_id',
  6050. 'job_company.company_size',
  6051. 'job_company.company_nature',
  6052. 'job_company.introduction',
  6053. 'job_company.real_name',
  6054. 'job_company.mobile',
  6055. 'job_company.company_url',
  6056. 'job_company.address_arr_id',
  6057. 'job_company.address',
  6058. 'job_company.email'
  6059. )
  6060. ->get();
  6061. if (empty($recruiting)) {
  6062. return Result::error("暂无招聘信息", 0);
  6063. }
  6064. return Result::success($recruiting);
  6065. }
  6066. /*
  6067. * 获取企业会员-我的沟通
  6068. * */
  6069. public function getJobResumeList(array $data): array
  6070. {
  6071. $user = User::where('id', $data['user_id'])->first();
  6072. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6073. return Result::error("用户不存在", 0);
  6074. }
  6075. $where = [];
  6076. if (isset($data['salary']) && $data['salary'] != null) {
  6077. $where['job_hunting.salary'] = $data['salary'];
  6078. }
  6079. if (isset($data['user_name']) && $data['user_name'] != null) {
  6080. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6081. }
  6082. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6083. $query->where('job_resume.user_id', $user['id']);
  6084. })
  6085. ->when(!empty($where), function ($query) use ($where) {
  6086. $query->where($where);
  6087. })
  6088. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6089. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6090. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6091. ->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');
  6092. $count = $job->count();
  6093. if ($count == 0) {
  6094. return Result::error("暂无沟通记录", 0);
  6095. }
  6096. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6097. ->offset(($data['page'] - 1) * $data['pageSize'])
  6098. ->limit($data['pageSize'])
  6099. ->get();
  6100. if (empty($jobs)) {
  6101. return Result::error("暂无沟通记录", 0);
  6102. }
  6103. $result['row'] = $this->processJob($jobs, '');
  6104. $result['count'] = $count;
  6105. return Result::success($result);
  6106. }
  6107. // 20250306 招聘
  6108. //20250422 书刊音像
  6109. public function addBook(array $data): array
  6110. {
  6111. // $user_id = $data['user_id'] ?? 0;
  6112. $type_id = $data['type_id'] ?? 0;
  6113. // $website_id = $data['website_id'] ?? 0;
  6114. // unset($data['user_id']);
  6115. unset($data['type_id']);
  6116. // unset($data['website_id']);
  6117. //处理数组
  6118. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6119. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6120. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6121. if ($data['img_url'] == '') {
  6122. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6123. preg_match_all($reg, $data['detail'], $matches);
  6124. if (isset($matches[1][0])) {
  6125. //截取varchar240
  6126. $data['img_url'] = substr($matches[1][0], 0, 240);
  6127. }
  6128. }
  6129. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6130. //提取标题+内容中的关键词
  6131. $data['keyword'] = $data['title'];
  6132. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6133. Jieba::init(); // 初始化 jieba-php
  6134. Finalseg::init();
  6135. $segList = Jieba::cut($data['keyword']);
  6136. $segList1 = array_slice($segList, 0, 8);
  6137. $data['keyword'] = implode(',', $segList1);
  6138. }
  6139. if ($data['description'] == '') {
  6140. //提取内容中的描述
  6141. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  6142. }
  6143. var_dump($data, '--');
  6144. $result = Book::insertGetId($data);
  6145. if (empty($result)) {
  6146. return Result::error("添加失败", 0);
  6147. }
  6148. return Result::success($result);
  6149. }
  6150. public function getBookList(array $data): array
  6151. {
  6152. $where = [];
  6153. if (!empty($data["title"])) {
  6154. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6155. }
  6156. if (!empty($data['website_name'])) {
  6157. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6158. }
  6159. if (!empty($data['status'])) {
  6160. $where[] = ['book.status', '=', $data['status']];
  6161. }
  6162. $user_id = $data['user_id'];
  6163. $type_id = $data['type_id'];
  6164. // $type_id = 4;
  6165. var_dump($type_id, '------1--------');
  6166. if ($type_id != 10000) {
  6167. $where[] = ['book.user_id', '=', $user_id];
  6168. }
  6169. var_dump(!empty($data['status1']), '=-===1');
  6170. $result = Book::where($where)
  6171. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6172. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6173. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6174. ->when(isset($data['status1']), function ($query) use ($data) {
  6175. $query->whereIn('book.status', [1, 3]);
  6176. })
  6177. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6178. ->orderBy("updated_at", "desc")
  6179. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6180. if (empty($result)) {
  6181. return Result::error("暂无数据", 0);
  6182. }
  6183. // 取出数据
  6184. $rows = $result->items();
  6185. $count = $result->total();
  6186. $responseData = [
  6187. 'rows' => $rows,
  6188. 'count' => $count,
  6189. ];
  6190. return Result::success($responseData);
  6191. }
  6192. public function deleteBook(array $data): array
  6193. {
  6194. $result = Book::where('id', $data['id'])->delete();
  6195. if (empty($result)) {
  6196. return Result::error("删除失败", 0);
  6197. }
  6198. return Result::success($result);
  6199. }
  6200. public function updateBook(array $data): array
  6201. {
  6202. // $user_id = $data['user_id'] ?? 0;
  6203. $type_id = $data['type_id'] ?? 0;
  6204. // $website_id = $data['website_id'] ?? 0;
  6205. unset($data['user_id']);
  6206. unset($data['type_id']);
  6207. // unset($data['website_id']);
  6208. //处理数组
  6209. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6210. if ($data['img_url'] == '') {
  6211. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6212. preg_match_all($reg, $data['detail'], $matches);
  6213. if (isset($matches[1][0])) {
  6214. //截取varchar240
  6215. $data['img_url'] = substr($matches[1][0], 0, 240);
  6216. }
  6217. }
  6218. if ($data['keyword'] == '') {
  6219. //提取标题+内容中的关键词
  6220. $data['keyword'] = $data['title'];
  6221. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6222. Jieba::init(); // 初始化 jieba-php
  6223. Finalseg::init();
  6224. $segList = Jieba::cut($data['keyword']);
  6225. $segList1 = array_slice($segList, 0, 8);
  6226. $data['keyword'] = implode(',', $segList1);
  6227. }
  6228. if ($data['description'] == '') {
  6229. //提取内容中的描述
  6230. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  6231. }
  6232. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6233. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6234. $result = Book::where("id", $data["id"])->update($data);
  6235. if (empty($result)) {
  6236. return Result::error("更新失败", 0);
  6237. }
  6238. return Result::success($result);
  6239. }
  6240. public function getBookInfo(array $data): array
  6241. {
  6242. $result = Book::where("id", $data["id"])->first();
  6243. if (empty($result)) {
  6244. return Result::error("获取失败", 0);
  6245. }
  6246. return Result::success($result);
  6247. }
  6248. public function updateBookStatus(array $data): array
  6249. {
  6250. //审核
  6251. unset($data['user_id']);
  6252. $result = Book::where("id", $data["id"])->update($data);
  6253. if (empty($result)) {
  6254. return Result::error("更新失败", 0);
  6255. }
  6256. return Result::success($result);
  6257. }
  6258. //20250422 书刊音像
  6259. /**
  6260. * 贴身宝贝
  6261. * @param array $data
  6262. * @return array
  6263. */
  6264. public function getWebsiteTsbb(array $data): array
  6265. {
  6266. $month = $data['month'] ?? date('m');
  6267. $day = $data['day'] ?? date('d');
  6268. // 使用缓存键
  6269. $cacheKey = "tsbb_data_{$month}_{$day}";
  6270. // 尝试从缓存获取数据
  6271. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6272. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6273. if ($cachedData = $cache->get($cacheKey)) {
  6274. return Result::success(unserialize($cachedData));
  6275. }
  6276. //查询老黄历
  6277. try {
  6278. $date = date('Y-m-d');
  6279. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6280. // 使用 curl 替代 file_get_contents
  6281. $ch = curl_init();
  6282. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6283. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6284. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6285. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6286. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6287. 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');
  6288. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6289. 'Accept: application/json',
  6290. 'Content-Type: application/json',
  6291. 'Referer: https://www.36jxs.com/'
  6292. ]);
  6293. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6294. curl_setopt($ch, CURLOPT_ENCODING, '');
  6295. $almanacResponse = curl_exec($ch);
  6296. var_dump("====:",$almanacResponse);
  6297. if (curl_errno($ch)) {
  6298. var_dump('Curl error:', curl_error($ch));
  6299. throw new \Exception('Curl error: ' . curl_error($ch));
  6300. }
  6301. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6302. curl_close($ch);
  6303. if ($almanacResponse === false) {
  6304. throw new \Exception('Failed to fetch almanac data');
  6305. }
  6306. $almanacData = json_decode($almanacResponse, true);
  6307. if (json_last_error() !== JSON_ERROR_NONE) {
  6308. throw new \Exception('Failed to parse almanac data');
  6309. }
  6310. $almanacInfo = $almanacData['data'] ?? [];
  6311. } catch (\Exception $e) {
  6312. var_dump('Exception:', $e->getMessage());
  6313. $almanacInfo = [];
  6314. }
  6315. // 获取历史上的今天数据
  6316. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6317. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6318. ->orderBy('year', 'asc')
  6319. ->select("title", "id", "year", DB::raw('1 as type'))
  6320. ->limit(16)
  6321. ->get();
  6322. // 获取节日数据 - 从今天开始获取未来4条
  6323. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6324. ->orderBy('showtime', 'asc')
  6325. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6326. ->limit(16)
  6327. ->get();
  6328. //说文解字
  6329. $chartacterList = Character::orderBy('updated_at', 'desc')
  6330. ->select("id", "title", "duyin", "bushou", "bihua",DB::raw('3 as type'))
  6331. ->limit(6)
  6332. ->get();
  6333. //谜语沙龙
  6334. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6335. ->select("id", "riddle_title", "riddle_bottom","prompt",DB::raw('4 as type'))
  6336. ->limit(4)
  6337. ->get();
  6338. //成语欣赏
  6339. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6340. ->select("id", "title", "duyin",DB::raw('5 as type'))
  6341. ->limit(32)
  6342. ->get();
  6343. //名联赏析
  6344. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6345. ->select("id", "first", "second",DB::raw('6 as type'))
  6346. ->limit(6)
  6347. ->get();
  6348. // 获取分类文章数据
  6349. $categoryIds = [627,628,629,630,631,632,633,634,635,636];
  6350. // 使用子查询优化
  6351. $articlesList = DB::table('article')
  6352. ->select([
  6353. 'article.id',
  6354. 'article.title',
  6355. 'article.imgurl',
  6356. 'article.created_at',
  6357. 'category.name as category_name',
  6358. 'category.id as category_id',
  6359. DB::raw('100 as type')
  6360. ])
  6361. ->join('category', 'article.catid', '=', 'category.id')
  6362. ->where('article.status', 1)
  6363. ->whereIn('category.id', $categoryIds)
  6364. // ->whereRaw('article.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)')
  6365. ->orderBy('article.created_at', 'desc')
  6366. ->get()
  6367. ->groupBy('category_id')
  6368. ->map(function ($group) {
  6369. // 确保第一条数据有图片
  6370. $firstWithImage = $group->first(function ($item) {
  6371. return !empty($item->imgurl);
  6372. });
  6373. if ($firstWithImage) {
  6374. // 如果有带图片的文章,将其放在第一位
  6375. $group = $group->filter(function ($item) use ($firstWithImage) {
  6376. return $item->id !== $firstWithImage->id;
  6377. })->prepend($firstWithImage);
  6378. }
  6379. return [
  6380. 'category_name' => $group->first()->category_name,
  6381. 'catid' => $group->first()->category_id,
  6382. 'type'=>100,
  6383. 'list' => $group->take(6)->map(function ($item) {
  6384. return [
  6385. 'id' => $item->id,
  6386. 'title' => $item->title,
  6387. 'imgurl' => $item->imgurl,
  6388. 'created_at' => $item->created_at
  6389. ];
  6390. })->values()
  6391. ];
  6392. })
  6393. ->values()
  6394. ->toArray();
  6395. $result = [
  6396. // 'almanac' => $almanacInfo,
  6397. 'historyTodayList' => [
  6398. 'category_name' => '历史上的今天',
  6399. 'list' => $historyTodayList,
  6400. 'type' => 1
  6401. ],
  6402. 'festivalList' => [
  6403. 'category_name' => '节日',
  6404. 'list' => $festivalList,
  6405. 'type' => 2
  6406. ],
  6407. 'chartacterList' => [
  6408. 'category_name' => '说文解字',
  6409. 'list' => $chartacterList,
  6410. 'type' => 3
  6411. ],
  6412. 'coupletList' => [
  6413. 'category_name' => '名联赏析',
  6414. 'list' => $coupletList,
  6415. 'type' => 6
  6416. ],
  6417. 'riddletList' => [
  6418. 'category_name' => '谜语沙龙',
  6419. 'list' => $riddletList,
  6420. 'type' => 4
  6421. ],
  6422. 'idiomList' => [
  6423. 'category_name' => '成语欣赏',
  6424. 'list' => $idiomList,
  6425. 'type' => 5
  6426. ],
  6427. 'articlesList' => $articlesList
  6428. ];
  6429. // 缓存结果,设置1小时过期
  6430. $cache->set($cacheKey, serialize($result), 3600);
  6431. return Result::success($result);
  6432. }
  6433. /**
  6434. * 获取资讯列表
  6435. */
  6436. public function getWebsiteTsbbList(array $data): array
  6437. {
  6438. $page = $data['page'] ?? 1;
  6439. $pageSize = $data['pageSize'] ?? 10;
  6440. // 如果没有传入月份和日期,则使用今天的日期
  6441. $month = $data['month'] ?? date('m');
  6442. $day = $data['day'] ?? date('d');
  6443. $total = 0;
  6444. $result = [];
  6445. $data['type'] = intval($data['type']);
  6446. var_dump("接收参数:",$data);
  6447. switch ($data['type']) {
  6448. case 1:
  6449. $query = HistoryToday::where(function($q) use ($month, $day) {
  6450. // 当前月份之后的数据
  6451. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6452. // 或者当前月份且日期大于等于当前日期的数据
  6453. ->orWhere(function($q) use ($month, $day) {
  6454. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6455. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6456. });
  6457. })
  6458. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6459. $total = $query->count();
  6460. $result = $query->select("title", "id", "year","updated_at", DB::raw('1 as type'))
  6461. ->offset(($page - 1) * $pageSize)
  6462. ->limit($pageSize)
  6463. ->get();
  6464. break;
  6465. case 2:
  6466. $query = Festival::where(function($q) use ($month, $day) {
  6467. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6468. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6469. ->orWhere(function($q) use ($month, $day) {
  6470. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6471. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6472. });
  6473. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6474. $total = $query->count();
  6475. $result = $query->select("title", "id","updated_at", "showtime", DB::raw('2 as type'))
  6476. ->offset(($page - 1) * $pageSize)
  6477. ->limit($pageSize)
  6478. ->get();
  6479. break;
  6480. case 3:
  6481. $query = Character::orderBy("updated_at", "desc");
  6482. $total = $query->count();
  6483. $result = $query->select("title", "id","updated_at", DB::raw('3 as type'))
  6484. ->offset(($page - 1) * $pageSize)
  6485. ->limit($pageSize)
  6486. ->get();
  6487. break;
  6488. case 4:
  6489. $query = Riddle::orderBy("updated_at", "desc");
  6490. $total = $query->count();
  6491. $result = $query->select("riddle_title as title","updated_at", "id", DB::raw('4 as type'))
  6492. ->offset(($page - 1) * $pageSize)
  6493. ->limit($pageSize)
  6494. ->get();
  6495. break;
  6496. case 5:
  6497. $query = Idiom::orderBy("updated_at", "desc");
  6498. $total = $query->count();
  6499. $result = $query->select("title", "id","updated_at", DB::raw('5 as type'))
  6500. ->offset(($page - 1) * $pageSize)
  6501. ->limit($pageSize)
  6502. ->get();
  6503. break;
  6504. case 6:
  6505. $query = Couplet::orderBy("updated_at", "desc");
  6506. $total = $query->count();
  6507. $result = $query->select("first as title","updated_at", "id", DB::raw('6 as type'))
  6508. ->offset(($page - 1) * $pageSize)
  6509. ->limit($pageSize)
  6510. ->get();
  6511. break;
  6512. default:
  6513. $query = Article::where(['catid'=>$data['catid']])->orderBy("updated_at", "desc");
  6514. $total = $query->count();
  6515. $result = $query->select("title", "id","updated_at", DB::raw('100 as type'))
  6516. ->offset(($page - 1) * $pageSize)
  6517. ->limit($pageSize)
  6518. ->get();
  6519. }
  6520. return Result::success([
  6521. 'list' => $result,
  6522. 'total' => $total,
  6523. 'page' => (int)$page,
  6524. 'pageSize' => (int)$pageSize,
  6525. 'month' => $month,
  6526. 'day' => $day
  6527. ]);
  6528. }
  6529. /**
  6530. * 1:历史上的今天
  6531. * 2:节日
  6532. * 3:文章
  6533. *
  6534. * 资讯详情信息
  6535. */
  6536. public function getWebsiteTsbbDetail(array $data): array
  6537. {
  6538. $data['type'] = intval($data['type']);
  6539. switch ($data['type']) {
  6540. case 1:
  6541. $result = HistoryToday::where("id", $data['id'])->first();
  6542. break;
  6543. case 2:
  6544. $result = Festival::where("id", $data['id'])->first();
  6545. break;
  6546. case 3:
  6547. $result = Character::where("id", $data['id'])->first();
  6548. break;
  6549. case 4:
  6550. $result = Riddle::where("id", $data['id'])->first();
  6551. break;
  6552. case 5:
  6553. $result = Idiom::where("id", $data['id'])->first();
  6554. break;
  6555. case 6:
  6556. $result = Couplet::where("id", $data['id'])->first();
  6557. break;
  6558. default:
  6559. $result = Article::where("id", $data['id'])->select("article.*","article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6560. break;
  6561. }
  6562. return Result::success($result);
  6563. }
  6564. }