NewsService.php 256 KB

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