NewsService.php 240 KB

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