NewsService.php 252 KB

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