NewsService.php 358 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. use App\Model\Message;
  70. use App\Model\ResearchTopic;
  71. use App\Model\RetopicUser;
  72. use App\Model\WebCateinfo;
  73. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  74. class NewsService implements NewsServiceInterface
  75. {
  76. #[Inject]
  77. protected Redis $redis;
  78. /**
  79. * 获取导航池列表
  80. * @param array $data
  81. * @return array
  82. */
  83. public function getCategoryList(array $data): array
  84. {
  85. $search = $data['name'] ?? '';
  86. $page = (int)($data['page'] ?? 1);
  87. $perPage = (int)($data['pageSize'] ?? 10);
  88. // 1. 查出所有匹配的分类id
  89. if ($search) {
  90. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  91. if (empty($matchedIds)) {
  92. return Result::success(['rows' => [], 'total' => 0]);
  93. }
  94. // 2. 递归查所有父级,直到一级分类
  95. $idsStr = implode(',', $matchedIds);
  96. $sql = "
  97. WITH RECURSIVE parents AS (
  98. SELECT * FROM category WHERE id IN ($idsStr)
  99. UNION ALL
  100. SELECT c.* FROM category c
  101. INNER JOIN parents p ON c.id = p.pid
  102. )
  103. SELECT * FROM parents
  104. ";
  105. $parents = Db::select($sql);
  106. $parentIds = [];
  107. foreach ($parents as $row) {
  108. if ($row->pid == 0) {
  109. $parentIds[] = $row->id;
  110. }
  111. }
  112. $parentIds = array_unique($parentIds);
  113. } else {
  114. // 没有搜索,一级分类就是根
  115. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  116. }
  117. // 3. 一级分类分页
  118. $total = count($parentIds);
  119. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  120. if (empty($parentIds)) {
  121. return Result::success(['rows' => [], 'total' => $total]);
  122. }
  123. // 4. 递归查所有子孙
  124. $idsStr = implode(',', $parentIds);
  125. $sql = "
  126. WITH RECURSIVE subcategories AS (
  127. SELECT * FROM category WHERE id IN ($idsStr)
  128. UNION ALL
  129. SELECT c.* FROM category c
  130. INNER JOIN subcategories s ON c.pid = s.id
  131. )
  132. SELECT * FROM subcategories ORDER BY updated_at DESC
  133. ";
  134. $allCategories = Db::select($sql);
  135. // 5. 组装树结构
  136. $categoryMap = [];
  137. foreach ($allCategories as $cat) {
  138. $cat = (array)$cat;
  139. $cat['children'] = [];
  140. $categoryMap[$cat['id']] = $cat;
  141. }
  142. foreach ($categoryMap as $id => &$cat) {
  143. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  144. $categoryMap[$cat['pid']]['children'][] = &$cat;
  145. }
  146. }
  147. unset($cat);
  148. $categoryTree = [];
  149. foreach ($parentIds as $id) {
  150. if (isset($categoryMap[$id])) {
  151. $categoryTree[] = $categoryMap[$id];
  152. }
  153. }
  154. return Result::success([
  155. 'rows' => $categoryTree,
  156. 'total' => $total,
  157. ]);
  158. }
  159. private function findMatchedCategories($search)
  160. {
  161. if ($search) {
  162. return Category::where('name', 'like', "%{$search}%")
  163. ->orderBy('updated_at', 'desc')
  164. ->get();
  165. }
  166. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  167. ->get();
  168. }
  169. private function findAllParents($categories)
  170. {
  171. $allCategories = [];
  172. foreach ($categories as $category) {
  173. $parentId = $category->pid;
  174. while ($parentId > 0) {
  175. $parent = Category::find($parentId);
  176. if ($parent) {
  177. $allCategories[$parent->id] = $parent;
  178. $parentId = $parent->pid;
  179. } else {
  180. break;
  181. }
  182. }
  183. $allCategories[$category->id] = $category;
  184. }
  185. return array_values($allCategories);
  186. }
  187. private function buildCategoryTree($category, $allRequiredCategories)
  188. {
  189. $categoryData = $category->toArray();
  190. $children = [];
  191. foreach ($allRequiredCategories as $c) {
  192. if ($c->pid === $category->id) {
  193. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  194. }
  195. }
  196. if (!empty($children)) {
  197. $categoryData['children'] = $children;
  198. }
  199. return $categoryData;
  200. }
  201. public function myCategoryList(array $data): array
  202. {
  203. $sszq = $data['sszq'] ?? '';
  204. unset($data['sszq']);
  205. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  206. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  207. $where[] = [
  208. 'pid',
  209. '=',
  210. $data['pid'],
  211. ];
  212. if (isset($data['name'])) {
  213. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  214. }
  215. var_dump($where);
  216. //根据分类id,从category表中取出分类信息
  217. $result = Category::where($where)
  218. ->whereIn('category.id', $catorytids)
  219. ->select('category.*', 'category.id as category_id')->get();
  220. if (empty($result)) {
  221. return Result::error("没有栏目数据");
  222. }
  223. return Result::success($result);
  224. }
  225. /**
  226. * @param array $data
  227. * @return array
  228. */
  229. public function categoryList(array $data): array
  230. {
  231. $where[] = [
  232. 'pid',
  233. '=',
  234. $data['pid']
  235. ];
  236. if (isset($data['name'])) {
  237. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  238. }
  239. var_dump($where);
  240. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  241. if (empty($result)) {
  242. return Result::error("没有栏目数据");
  243. }
  244. return Result::success($result);
  245. }
  246. /**
  247. * @param array $data
  248. * @return array
  249. */
  250. public function addCategory(array $data): array
  251. {
  252. if (isset($data['id'])) {
  253. unset($data['id']);
  254. }
  255. $id = Category::insertGetId($data);
  256. if (empty($id)) {
  257. return Result::error("添加失败");
  258. }
  259. return Result::success(['id' => $id]);
  260. }
  261. /**
  262. * @param array $data
  263. * @return array
  264. */
  265. public function delCategory(array $data): array
  266. {
  267. Db::beginTransaction();
  268. try {
  269. $categoryList = Category::where(['pid' => $data['id']])->get();
  270. if ($categoryList->toArray()) {
  271. Db::rollBack();
  272. return Result::error("分类下面有子分类不能删除");
  273. }
  274. $articleList = Article::where(['catid' => $data['id']])->get();
  275. if ($articleList->toArray()) {
  276. Db::rollBack();
  277. return Result::error("分类下面有资讯不能删除");
  278. }
  279. $result = Category::where($data)->delete();
  280. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  281. if (!$result) {
  282. Db::rollBack();
  283. return Result::error("删除失败");
  284. }
  285. Db::commit();
  286. return Result::success($result);
  287. } catch (\Exception $e) {
  288. Db::rollBack();
  289. return Result::error("删除失败" . $e->getMessage());
  290. }
  291. }
  292. /**
  293. * @param array $data
  294. * @return array
  295. */
  296. public function updateCategory(array $data): array
  297. {
  298. $where = [
  299. 'id' => $data['id'],
  300. ];
  301. $result = Category::where($where)->update($data);
  302. if ($result) {
  303. return Result::success($result);
  304. } else {
  305. return Result::error("更新失败");
  306. }
  307. }
  308. /**
  309. * 获取导航池信息
  310. * @param array $data
  311. * @return array
  312. */
  313. public function getCategoryInfo(array $data): array
  314. {
  315. $where = [
  316. 'id' => $data['id'],
  317. ];
  318. $result = Category::where($where)->first();
  319. if ($result) {
  320. return Result::success($result);
  321. } else {
  322. return Result::error("更新失败");
  323. }
  324. }
  325. public function getArticleCommend(array $data): array
  326. {
  327. $where = [
  328. 'website_id' => $data['website_id'],
  329. ];
  330. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  331. var_dump($ids);
  332. if (empty($ids)) {
  333. return Result::error("没有推荐数据");
  334. }
  335. //id
  336. $whereArticle = [];
  337. if (isset($data['id'])) {
  338. $whereArticle['id'] = $data['id'];
  339. }
  340. //title like
  341. if (isset($data['title'])) {
  342. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  343. }
  344. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  345. ->where($whereArticle)
  346. ->orderBy('id', 'desc')
  347. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  348. if ($article) {
  349. $data = [
  350. 'rows' => $article->items(),
  351. 'count' => $article->total(),
  352. ];
  353. return Result::success($data);
  354. } else {
  355. return Result::error("获取失败失败");
  356. }
  357. }
  358. /**
  359. * @param array $data
  360. * @return array
  361. */
  362. public function getArticleList(array $data): array
  363. {
  364. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  365. $type_id = $data['type_id'];
  366. unset($data['type_id']);
  367. $user_id = $data['user_id'];
  368. unset($data['user_id']);
  369. $where = [];
  370. $status1 = [];
  371. if (isset($data['id']) && $data['id']) {
  372. array_push($where, ['article.id', '=', $data['id']]);
  373. }
  374. if (isset($data['title']) && $data['title']) {
  375. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  376. }
  377. if (isset($data['category_name']) && $data['category_name']) {
  378. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  379. }
  380. if (isset($data['catid']) && $data['catid']) {
  381. array_push($where, ['article.catid', '=', $data['catid']]);
  382. }
  383. if (isset($data['author']) && $data['author']) {
  384. array_push($where, ['article.author', '=', $data['author']]);
  385. }
  386. if (isset($data['islink']) && $data['islink'] !== "") {
  387. array_push($where, ['article.islink', '=', $data['islink']]);
  388. }
  389. if (isset($data['status']) && $data['status'] !== "") {
  390. array_push($where, ['article.status', '=', $data['status']]);
  391. }
  392. if (isset($data['status1'])) {
  393. $status1 = json_decode(($data['status1']));
  394. }
  395. //不是管理员展示个人数据;
  396. if ($type_id != 10000) {
  397. $where[] = ['article.admin_user_id', '=', $user_id];
  398. }
  399. $startTime = microtime(true);
  400. $rep = Article::query()
  401. // 预加载相关关联
  402. ->with([
  403. 'category' => function ($query) {
  404. $query->select('id', 'name');
  405. },
  406. 'websiteCategory' => function ($query) {
  407. $query->select('website_id', 'category_id', 'alias');
  408. },'user' => function ($query) {
  409. $query->select('id', 'nickname');
  410. }
  411. ])
  412. // 构建where条件
  413. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  414. $query->where('article.id', '=', $data['id']);
  415. })
  416. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  417. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  418. })
  419. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  420. // 使用子查询替代左连接进行模糊搜索
  421. $query->whereHas('category', function ($subQuery) use ($data) {
  422. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  423. });
  424. })
  425. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  426. $query->where('article.catid', '=', $data['catid']);
  427. })
  428. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  429. $query->where('article.author', '=', $data['author']);
  430. })
  431. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  432. $query->where('article.islink', '=', $data['islink']);
  433. })
  434. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  435. $query->where('article.status', '=', $data['status']);
  436. })
  437. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  438. // 安全地处理JSON字符串
  439. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  440. if (!empty($status1)) {
  441. $query->whereIn('article.status', $status1);
  442. }
  443. })
  444. ->select('article.*')
  445. // 非管理员限制
  446. ->when($type_id != 10000, function ($query) use ($user_id) {
  447. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  448. $query->where('article.admin_user_id', $user_id)
  449. ->leftJoin('article_ignore', function ($join) {
  450. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  451. $join->on('article_ignore.article_id', '=', 'article.id')
  452. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  453. })
  454. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  455. })
  456. // 基础条件
  457. ->whereNotIn('article.status', [404])
  458. // 排序和分页
  459. ->orderBy('article.updated_at', 'desc')
  460. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  461. // 获取结果并格式化
  462. $data = [
  463. 'rows' => $rep->items(),
  464. 'count' => $rep->total(),
  465. ];
  466. // 执行查询
  467. $endTime = microtime(true);
  468. $executionTime = ($endTime - $startTime) * 1000;
  469. echo "查询执行时间: {$executionTime}ms\n";
  470. return Result::success($data);
  471. }
  472. /**
  473. * @param array $data
  474. * @return array
  475. */
  476. public function addArticle(array $data): array
  477. {
  478. var_dump($data, '----------12-----------1');
  479. // ------c_show_time********add***1****
  480. $is_collect = $data['is_collect'] ?? 0;
  481. $user_type = $data['user_type'];
  482. unset($data['is_collect']);
  483. unset($data['user_type']);
  484. // ------c_show_time********add***1****
  485. unset($data['nav_add_pool_id']);
  486. // unset($data['commend_id']);
  487. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  488. Db::beginTransaction();
  489. try {
  490. //处理投票
  491. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  492. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  493. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  494. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  495. unset($data['is_survey']);
  496. unset($data['survey_name']);
  497. unset($data['suvey_array']);
  498. // unset($data['website_id']);
  499. // unset($data['web_site_id']);
  500. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  501. if ($data['hits'] == '') {
  502. $data['hits'] = 0;
  503. }
  504. if ($data['is_original'] == '') {
  505. $data['is_original'] = 0;
  506. }
  507. if ($data['status'] == '') {
  508. $data['status'] = 0;
  509. }
  510. $articleData = $data;
  511. unset($articleData['content']);
  512. //自动处理缩略图、关键字、描述
  513. if ($articleData['imgurl'] == '') {
  514. //如果没有图,设置level=0
  515. $levelArr = json_decode($articleData['level'], true);
  516. var_dump($levelArr, '----------levelArr-----------1');
  517. //content中提取图片第一个图,正则提取
  518. // -------采集器相关优化-----
  519. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  520. if ($is_collect == 1) {
  521. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  522. } else {
  523. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  524. }
  525. // -------采集器相关优化-----
  526. preg_match_all($reg, $data['content'], $matches);
  527. if (isset($matches[1][0])) {
  528. //截取varchar240
  529. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  530. //如果有图,设置level=3
  531. if (!in_array(3, $levelArr)) {
  532. $levelArr[] = 3;
  533. }
  534. $articleData['level'] = json_encode($levelArr);
  535. } else {
  536. if (!in_array(0, $levelArr)) {
  537. $levelArr[] = 0;
  538. }
  539. $articleData['level'] = json_encode($levelArr);
  540. }
  541. }
  542. var_dump($articleData['level'], '----------$articleData[level]----------1');
  543. if ($articleData['keyword'] == '') {
  544. //提取标题+内容中的关键词
  545. $articleData['keyword'] = $data['title'];
  546. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  547. Jieba::init(); // 初始化 jieba-php
  548. Finalseg::init();
  549. $segList = Jieba::cut($articleData['keyword']);
  550. $segList1 = array_slice($segList, 0, 8);
  551. $articleData['keyword'] = implode(',', $segList1);
  552. }
  553. if ($articleData['introduce'] == '') {
  554. //提取内容中的描述
  555. $content = $data['content'];
  556. // 去除 <style> 和 <script> 标签及其内容
  557. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  558. // 去除所有 HTML 标签
  559. $content = strip_tags($content);
  560. // 去除 HTML 实体
  561. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  562. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  563. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  564. // 去除多余空白
  565. $content = preg_replace('/\s+/u', '', $content);
  566. // 截取 100 个字符
  567. $articleData['introduce'] = mb_substr($content, 0, 100);
  568. }
  569. if ($articleData['status'] == 0) {
  570. $this->sendMessage([
  571. 'talk_type' => 100,
  572. 'title' => $articleData['title'],
  573. 'content' => '提交了审核',
  574. 'messageType' => 2,
  575. ]);
  576. }
  577. if(!empty($data['fujian'])){
  578. $articleData['fujian'] = $data['fujian'];
  579. }
  580. $id = Article::insertGetId($articleData);
  581. if (!$id) {
  582. throw new \Exception('文章插入失败');
  583. }
  584. $articleDataContent = [
  585. 'article_id' => $id,
  586. 'content' => $data['content'],
  587. ];
  588. // 采集器中的文章内容,在添加时,去掉div标签
  589. if ($is_collect == 1) {
  590. // 采集来的文章,content中可能包含div标签,需要先移除
  591. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  592. $article_data = preg_replace($pattern, '', $data['content']);
  593. $$articleDataContent['content'] = $article_data;
  594. }
  595. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  596. if (!$contentInsertId) {
  597. throw new \Exception('文章内容插入失败');
  598. }
  599. // ------c_show_time********add***2****
  600. // 直接使用当前系统时间,不再强制添加8小时
  601. $now = date('Y-m-d H:i:s');
  602. if ($user_type == 10000 || $is_collect == 1) {
  603. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  604. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  605. if (!isset($data['catid'])) {
  606. throw new \Exception('缺少必要字段:catid');
  607. }
  608. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  609. $web = WebsiteCategory::where('category_id', $data['catid'])
  610. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  611. ->select(
  612. 'website_id',
  613. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  614. )
  615. ->get();
  616. // $id = 225; -----测试开启
  617. // 采集来的文章,错开时间在两小时之内发布
  618. if ($user_type == 10000 && $is_collect == 1) {
  619. $web_num = $web->where('is_core', '!=', 2)->count();
  620. $waiting_interval = 10;
  621. if ($web_num > 12) {
  622. // 若网站数量大于12个,则每个网站间隔时间取均值
  623. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  624. $waiting_interval = 120 / max(1, $web_num);
  625. }
  626. $time = 0;
  627. } else {
  628. // 非核心站与核心站----显示时间-----间隔
  629. $time = 20;
  630. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  631. $waiting_interval = 5;
  632. }
  633. // 将 Hyperf\Database\Model\Collection 转换为数组
  634. $webArray = $web->toArray();
  635. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  636. // 检查 $item 对象是否有 is_core 属性
  637. if (!isset($item['is_core'])) {
  638. throw new \Exception('$item 对象缺少 is_core 属性');
  639. }
  640. // 当 is_core 为 2 时,则表示此网站不存在
  641. if ($item['is_core'] == 2) {
  642. return null;
  643. }
  644. if ($is_collect == 1) {
  645. // 采集来的文章,错开时间在两小时之内发布
  646. // $time = 0;
  647. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  648. $time += $waiting_interval;
  649. } else if ($item['is_core'] == 1) {
  650. // 当 is_core 为 1 时,则表示此网站是核心站
  651. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  652. } else {
  653. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  654. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  655. if ($item['is_core'] == 0) {
  656. $time += $waiting_interval;
  657. }
  658. }
  659. return [
  660. 'article_id' => $id,
  661. 'website_id' => $item['website_id'],
  662. 'c_show_time' => $c_show_time,
  663. // 'is_core' => $item['is_core'],
  664. // 'time' => $time
  665. ];
  666. }, array_keys($webArray), $webArray)));
  667. // Db::commit();
  668. // return Result::success($article_ignore);
  669. if (!empty($article_ignore)) {
  670. $article_ignores = ArticleIgnore::insert($article_ignore);
  671. if (!$article_ignores) {
  672. throw new \Exception('c端展示时间插入失败');
  673. }
  674. }
  675. }
  676. // ------c_show_time********add***2****
  677. //处理投票
  678. if ($is_survey == 1) {
  679. //生成年月日时分秒+8位随机数
  680. $uuid = date('YmdHis') . rand(10000000, 99999999);
  681. var_dump($suvey_array, 'suvey_array________');
  682. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  683. var_dump($suveys_array, '---------------------1');
  684. var_dump($suvey_array, '---------------------2');
  685. $suvey_data = [];
  686. foreach ($suveys_array as $key => $value) {
  687. if ($value == '') {
  688. continue;
  689. }
  690. if (is_array($value)) {
  691. $suvey_data[] = [
  692. 'sur_id' => $uuid,
  693. 'art_id' => $id,
  694. 'website_id' => $website_id ?? 2,
  695. 'survey_name' => $survey_name,
  696. 'choice_name' => $value[1],
  697. 'is_other' => 1,
  698. 'other_id' => 0,
  699. 'results' => 0,
  700. ];
  701. } else {
  702. $suvey_data[] = [
  703. 'sur_id' => $uuid,
  704. 'art_id' => $id,
  705. 'website_id' => $website_id ?? 2,
  706. 'survey_name' => $survey_name,
  707. 'choice_name' => $value,
  708. 'is_other' => 0,
  709. 'other_id' => 0,
  710. 'results' => 0,
  711. ];
  712. }
  713. if (empty($suvey_data)) {
  714. throw new \Exception("投票数据为空");
  715. }
  716. }
  717. $result = ArticleSurvey::insert($suvey_data);
  718. if (!$result) {
  719. throw new \Exception("投票失败,ArticleSurvey插入失败");
  720. }
  721. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  722. if (!$result) {
  723. throw new \Exception("投票失败,更新主表失败");
  724. }
  725. }
  726. Db::commit();
  727. return Result::success(['id' => $id]);
  728. } catch (\Throwable $ex) {
  729. Db::rollBack();
  730. var_dump($ex->getMessage());
  731. return Result::error("创建失败", 0);
  732. }
  733. }
  734. /**
  735. * @param array $data
  736. * @return array
  737. */
  738. public function delArticle(array $data): array
  739. {
  740. // ------c_show_time********del*******
  741. Db::beginTransaction();
  742. try {
  743. $article = Article::where(['id' => $data['id']])->delete();
  744. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  745. if (!$article) {
  746. throw new \Exception("删除失败,文章删除失败");
  747. }
  748. //survey投票删除
  749. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  750. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  751. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  752. // 若文章详情删除失败,抛出异常
  753. if (!$article_data) {
  754. throw new \Exception("删除失败,文章详情删除失败");
  755. }
  756. Db::commit(); // 所有操作成功,提交事务
  757. } catch (\Throwable $ex) {
  758. Db::rollBack();
  759. var_dump($ex->getMessage());
  760. return Result::error("删除失败: " . $ex->getMessage(), 0);
  761. }
  762. // ------c_show_time********del*******
  763. if (!$article) {
  764. return Result::error("删除失败");
  765. }
  766. return Result::success($article);
  767. }
  768. /**
  769. * @param array $data
  770. * @return array
  771. */
  772. public function updateArticle(array $data): array
  773. {
  774. var_dump($data, '----------12-----------1');
  775. Db::beginTransaction();
  776. // ------c_show_time********up*******
  777. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  778. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  779. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  780. $web = WebsiteCategory::where('category_id', $data['catid'])
  781. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  782. ->select(
  783. 'website_id',
  784. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  785. )
  786. ->get();
  787. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  788. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  789. $websiteIds = $web->pluck('website_id')->toArray();
  790. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  791. if ($user_type == 0) {
  792. throw new \Exception("用户类型不能为空");
  793. }
  794. if ($user_type == 10000) {
  795. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  796. $web = WebsiteCategory::where('category_id', $data['catid'])
  797. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  798. ->select(
  799. 'website_id',
  800. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  801. )
  802. ->get();
  803. // 非核心站与核心站----显示时间-----间隔
  804. $time = 20;
  805. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  806. $waiting_interval = 5;
  807. $webArray = $web->toArray();
  808. if (empty($webArray)) {
  809. throw new \Exception('网站分类不存在');
  810. }
  811. // 直接使用当前系统时间,不再强制添加8小时
  812. $now = date('Y-m-d H:i:s');
  813. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  814. // 检查 $item 对象是否有 is_core 属性
  815. if (!isset($item['is_core'])) {
  816. throw new \Exception('$item 对象缺少 is_core 属性');
  817. }
  818. // 当 is_core 为 2 时,则表示此网站不存在
  819. if ($item['is_core'] == 2) {
  820. return null;
  821. } else if ($item['is_core'] == 1) {
  822. // 当 is_core 为 1 时,则表示此网站是核心站
  823. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  824. } else {
  825. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  826. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  827. if ($item['is_core'] == 0) {
  828. $time += $waiting_interval;
  829. }
  830. }
  831. return [
  832. 'article_id' => $data['id'],
  833. 'website_id' => $item['website_id'],
  834. 'c_show_time' => $c_show_time,
  835. ];
  836. }, array_keys($webArray), $webArray)));
  837. if (!empty($article_ignore)) {
  838. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  839. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  840. $article_ignores = ArticleIgnore::upsert(
  841. $article_ignore,
  842. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  843. ['c_show_time'] // 需要更新的字段
  844. );
  845. if (!$article_ignores) {
  846. throw new \Exception('c端展示时间插入失败');
  847. }
  848. }
  849. // Db::commit();
  850. // return Result::success($article_ignore);
  851. }
  852. // ------c_show_time********up*******
  853. unset($data['user_type']);
  854. // unset($data['web_site_id']);
  855. unset($data['nav_add_pool_id']);
  856. try {
  857. //处理投票
  858. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  859. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  860. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  861. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  862. unset($data['is_survey']);
  863. unset($data['survey_name']);
  864. unset($data['suvey_array']);
  865. unset($data['website_id']);
  866. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  867. if ($data['hits'] == '') {
  868. $data['hits'] = 0;
  869. }
  870. if ($data['is_original'] == '') {
  871. $data['is_original'] = 0;
  872. }
  873. if ($data['status'] == '') {
  874. $data['status'] = 0;
  875. }
  876. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  877. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  878. $articleData = $data;
  879. unset($articleData['content']);
  880. unset($articleData['status_name']);
  881. unset($articleData['name']);
  882. unset($articleData['content']);
  883. unset($articleData['pid_arr']);
  884. unset($articleData['pid']);
  885. //自动处理缩略图、关键字、描述
  886. if ($articleData['imgurl'] == '') {
  887. //如果没有图,设置level=0
  888. $levelArr = json_decode($articleData['level'], true);
  889. var_dump($levelArr, '----------levelArr-----------1');
  890. //content中提取图片第一个图,正则提取
  891. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  892. preg_match_all($reg, $data['content'], $matches);
  893. if (isset($matches[1][0])) {
  894. //截取varchar240
  895. // 截取到第一个<
  896. $articleData['imgurl'] = $matches[1][0];
  897. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  898. $pos = strpos($articleData['imgurl'], '"');
  899. if ($pos !== false) {
  900. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  901. }
  902. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  903. //如果有图,设置level=3
  904. if (!in_array(3, $levelArr)) {
  905. $levelArr[] = 3;
  906. }
  907. $articleData['level'] = json_encode($levelArr);
  908. } else {
  909. if (!in_array(0, $levelArr)) {
  910. $levelArr[] = 0;
  911. }
  912. $articleData['level'] = json_encode($levelArr);
  913. }
  914. }
  915. var_dump($articleData['level'], '----------$articleData[level]----------1');
  916. if ($articleData['keyword'] == '') {
  917. //提取标题+内容中的关键词
  918. $articleData['keyword'] = $data['title'];
  919. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  920. Jieba::init(); // 初始化 jieba-php
  921. Finalseg::init();
  922. $segList = Jieba::cut($articleData['keyword']);
  923. $segList1 = array_slice($segList, 0, 8);
  924. $articleData['keyword'] = implode(',', $segList1);
  925. }
  926. if ($articleData['introduce'] == '') {
  927. //提取内容中的描述
  928. $content = $data['content'];
  929. // 去除 <style> 和 <script> 标签及其内容
  930. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  931. // 去除所有 HTML 标签
  932. $content = strip_tags($content);
  933. // 去除 HTML 实体
  934. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  935. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  936. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  937. // 去除多余空白
  938. $content = preg_replace('/\s+/u', '', $content);
  939. // 截取 100 个字符
  940. $articleData['introduce'] = mb_substr($content, 0, 100);
  941. }
  942. if ($articleData['status'] == 0) {
  943. $this->sendMessage([
  944. 'talk_type' => 100,
  945. 'title' => $articleData['title'],
  946. 'content' => '提交了审核',
  947. 'messageType' => 2,
  948. ]);
  949. }
  950. if(!empty($data['fujian'])){
  951. $articleData['fujian'] = $data['fujian'];
  952. }
  953. $id = Article::where(['id' => $data['id']])->update($articleData);
  954. // $articleDataContent = [
  955. // 'content' => $data['content'],
  956. // ];
  957. // 采集来的文章,content中可能包含div标签,需要先移除
  958. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  959. $article_data = preg_replace($pattern, '', $data['content']);
  960. $articleDataContent['content'] = $article_data;
  961. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  962. //处理投票
  963. $id = $data['id'];
  964. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  965. var_dump($suvey_array, 'suvey_array________delete');
  966. //处理投票
  967. if ($is_survey == 1) {
  968. //生成年月日时分秒+8位随机数
  969. $uuid = date('YmdHis') . rand(10000000, 99999999);
  970. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  971. var_dump($suveys_array, '---------------------1');
  972. $suvey_data = [];
  973. if (is_array($suveys_array)) {
  974. foreach ($suveys_array as $key => $value) {
  975. if ($value == '') {
  976. continue;
  977. }
  978. if (is_array($value)) {
  979. $suvey_data[] = [
  980. 'sur_id' => $uuid,
  981. 'art_id' => $id,
  982. 'website_id' => $website_id ?? 2,
  983. 'survey_name' => $survey_name,
  984. 'choice_name' => $value[1],
  985. 'is_other' => 1,
  986. 'other_id' => 0,
  987. 'results' => 0,
  988. ];
  989. } else {
  990. $suvey_data[] = [
  991. 'sur_id' => $uuid,
  992. 'art_id' => $id,
  993. 'website_id' => $website_id ?? 2,
  994. 'survey_name' => $survey_name,
  995. 'choice_name' => $value,
  996. 'is_other' => 0,
  997. 'other_id' => 0,
  998. 'results' => 0,
  999. ];
  1000. }
  1001. if (empty($suvey_data)) {
  1002. throw new \Exception("投票数据为空");
  1003. }
  1004. }
  1005. }
  1006. $result = ArticleSurvey::insert($suvey_data);
  1007. if (!$result) {
  1008. throw new \Exception("投票失败");
  1009. }
  1010. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1011. if (!$result) {
  1012. throw new \Exception("投票失败");
  1013. }
  1014. } else {
  1015. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1016. }
  1017. Db::commit();
  1018. return Result::success([]);
  1019. } catch (\Throwable $ex) {
  1020. Db::rollBack();
  1021. var_dump($ex->getMessage());
  1022. return Result::error("更新失败" . $ex->getMessage(), 0);
  1023. }
  1024. }
  1025. /**
  1026. * 更新资讯状态
  1027. * @param array $data
  1028. * @return array
  1029. */
  1030. public function upArticleStatus(array $data): array
  1031. {
  1032. $articleData = Article::where(['id' => $data['id']])->first();
  1033. //发送10次
  1034. // for ($i = 0; $i < 10; $i++) {
  1035. // $this->sendMessage([
  1036. // 'talk_type' => 100,
  1037. // 'title' => $i . $articleData['title'],
  1038. // 'content' => '审核通过',
  1039. // 'messageType' => 2,
  1040. // 'user_id' => $articleData['admin_user_id'],
  1041. // ]);
  1042. // }
  1043. // var_dump($data['status'], 'status');
  1044. // return Result::success();
  1045. if ($data['status'] == 1) {
  1046. $this->sendMessage([
  1047. 'talk_type' => 101,
  1048. 'title' => $articleData['title'],
  1049. 'content' => '审核通过',
  1050. 'messageType' => 2,
  1051. 'user_id' => $articleData['admin_user_id'],
  1052. ]);
  1053. }
  1054. if ($data['status'] == 2) {
  1055. $this->sendMessage([
  1056. 'talk_type' => 101,
  1057. 'title' => $articleData['title'],
  1058. 'content' => '审核拒绝',
  1059. 'messageType' => 2,
  1060. 'user_id' => $articleData['admin_user_id'],
  1061. ]);
  1062. }
  1063. if ($data['status'] == 0) {
  1064. $this->sendMessage([
  1065. 'talk_type' => 100,
  1066. 'title' => $articleData['title'],
  1067. 'content' => '提交了审核',
  1068. 'messageType' => 2,
  1069. ]);
  1070. }
  1071. $result = Article::where(['id' => $data['id']])->update($data);
  1072. // ------c_show_time********up_status*******
  1073. // 若是审核通过 则更新c_show_time
  1074. if ($data['status'] == 1) {
  1075. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1076. $web = Article::where('article.id', $data['id'])
  1077. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1078. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1079. ->select(
  1080. 'website_id',
  1081. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  1082. )
  1083. ->get();
  1084. // 非核心站与核心站----显示时间-----间隔
  1085. $time = 20;
  1086. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1087. $waiting_interval = 5;
  1088. $webArray = $web->toArray();
  1089. if (empty($webArray)) {
  1090. throw new \Exception('网站分类不存在');
  1091. }
  1092. // 直接使用当前系统时间,不再强制添加8小时
  1093. $now = date('Y-m-d H:i:s');
  1094. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1095. if (isset($data['ignore_ids'])) {
  1096. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1097. if (in_array($item['website_id'], $ignore_website_ids)) {
  1098. $is_ignore = 1;
  1099. } else {
  1100. $is_ignore = 0;
  1101. }
  1102. return [
  1103. 'article_id' => $data['id'],
  1104. 'website_id' => $item['website_id'],
  1105. 'is_ignore' => $is_ignore,
  1106. ];
  1107. } else {
  1108. // 检查 $item 对象是否有 is_core 属性
  1109. if (!isset($item['is_core'])) {
  1110. throw new \Exception('$item 对象缺少 is_core 属性');
  1111. }
  1112. // 当 is_core 为 2 时,则表示此网站不存在
  1113. if ($item['is_core'] == 2) {
  1114. return null;
  1115. } else if ($item['is_core'] == 1) {
  1116. // 当 is_core 为 1 时,则表示此网站是核心站
  1117. $c_show_time = $now;
  1118. } else {
  1119. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1120. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1121. if ($item['is_core'] == 0) {
  1122. $time += $waiting_interval;
  1123. }
  1124. }
  1125. return [
  1126. 'article_id' => $data['id'],
  1127. 'website_id' => $item['website_id'],
  1128. 'c_show_time' => $c_show_time,
  1129. ];
  1130. }
  1131. }, array_keys($webArray), $webArray)));
  1132. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1133. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1134. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1135. $websiteIds = $web->pluck('website_id')->toArray();
  1136. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1137. $article_ignores = ArticleIgnore::upsert(
  1138. $article_ignore,
  1139. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1140. ['c_show_time'] // 需要更新的字段
  1141. );
  1142. if (!$article_ignores) {
  1143. throw new \Exception('c端展示时间插入失败');
  1144. }
  1145. }
  1146. if (!empty($data['ignore_ids'])) {
  1147. // return Result::success($article_ignore);
  1148. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1149. if (!empty($article_ignore)) {
  1150. $article_ignores = ArticleIgnore::upsert(
  1151. $article_ignore,
  1152. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1153. ['is_ignore'] // 需要更新的字段
  1154. );
  1155. // if(!$article_ignores){
  1156. // throw new \Exception('屏蔽网站更新失败');
  1157. // }
  1158. }
  1159. }
  1160. }
  1161. // ------c_show_time********up_status*******
  1162. if ($result) {
  1163. return Result::success();
  1164. } else {
  1165. return Result::error("更新状态失败", 0);
  1166. }
  1167. }
  1168. /**
  1169. * 获取新闻详情
  1170. * @param array $data
  1171. * @return array
  1172. */
  1173. public function getArticleInfo(array $data): array
  1174. {
  1175. $where = [
  1176. 'article.id' => $data['id'],
  1177. // 'article.status' => 1,
  1178. ];
  1179. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1180. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1181. $info = $result;
  1182. // var_dump($info, 'info');
  1183. $info['survey_array'] = $articleSurvey;
  1184. if ($result) {
  1185. return Result::success($info);
  1186. } else {
  1187. return Result::error("查询失败", 0);
  1188. }
  1189. }
  1190. /**
  1191. * 获取头条新闻
  1192. * @param array $data
  1193. * @return array
  1194. */
  1195. public function getWebsiteArticlett(array $data): array
  1196. {
  1197. $website_id = $data['website_id'];
  1198. $website = Website::where('id', $data['website_id'])->first();
  1199. if (empty($website)) {
  1200. return Result::error("网站不存在", 0);
  1201. }
  1202. $categorys = $this->processArticlePro($website_id);
  1203. $catiall = $categorys['catiall'];
  1204. $categoryIds = $categorys['categoryIds'];
  1205. $where = [
  1206. 'status' => 1
  1207. ];
  1208. // $website_column = $website['column'];
  1209. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1210. $website_column = json_decode($website['website_column_arr_id'], true);
  1211. }
  1212. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1213. // return Result::success($diff_pid_categoryIds);
  1214. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1215. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1216. }
  1217. // $website_id = $data['website_id'];
  1218. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1219. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1220. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1221. switch ($data['level']) {
  1222. case 1:
  1223. case 2:
  1224. case 3:
  1225. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1226. $query = Article::where($where)
  1227. ->where('level', 'like', '%' . $data['level'] . '%')
  1228. ->orderBy('updated_at', 'desc');
  1229. break;
  1230. case 4: //最新资讯
  1231. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1232. break;
  1233. case 5: //资讯推荐
  1234. $query = Article::where($where)
  1235. ->where('updated_at', '>', $month);
  1236. break;
  1237. case 7: //资讯分类
  1238. if (isset($data['id']) && !empty($data['id'])) {
  1239. $keyword = Article::where('id', $data['id'])->value('keyword');
  1240. $keywordArray = explode(',', $keyword);
  1241. $whereL7 = [];
  1242. foreach ($keywordArray as $k => $v) {
  1243. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1244. }
  1245. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1246. break;
  1247. } else {
  1248. return Result::error("请输入资讯ID", 0);
  1249. break;
  1250. }
  1251. default:
  1252. break;
  1253. }
  1254. // $whereL7 = [];
  1255. // if(isset($data['id']) && !empty($data['id'])){
  1256. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1257. // $keywordArray = explode(',', $keyword);
  1258. // foreach ($keywordArray as $k => $v) {
  1259. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1260. // }
  1261. // }
  1262. // $query = Article::where($where)
  1263. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1264. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1265. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1266. // }
  1267. // if($data['level'] == 7){
  1268. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1269. // }
  1270. // if($data['level'] == 4){
  1271. // $query = $query->inRandomOrder()
  1272. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1273. // }
  1274. // if($data['level'] == 5){
  1275. // $query = $query->orderBy('updated_at','desc');
  1276. // }
  1277. // });
  1278. if ($data['textnum'] > 0) {
  1279. $query = clone $query;
  1280. $result['text'] = $query
  1281. ->whereIn('catid', $categoryIds)
  1282. ->leftJoinSub(function ($query) use ($website_id) {
  1283. $query->from('article_ignore')
  1284. ->where('website_id', $website_id);
  1285. }, 'article_ignore', function ($join) {
  1286. $join->on('article_ignore.article_id', '=', 'article.id');
  1287. })
  1288. ->where(function ($query) {
  1289. $query->whereNull('article_ignore.article_id')
  1290. ->orWhere(function ($subQuery) {
  1291. $subQuery->whereNotNull('article_ignore.article_id')
  1292. ->where('article_ignore.is_ignore', 0)
  1293. ->where(function ($subSubQuery) {
  1294. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1295. ->orWhereNull('article_ignore.c_show_time');
  1296. });
  1297. });
  1298. })
  1299. // ->where(function ($query) use ($website_id) {
  1300. // $query->whereNull('article_ignore.article_id')
  1301. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1302. // })
  1303. ->select(
  1304. 'article.id',
  1305. 'article.title',
  1306. 'article.author',
  1307. 'article.updated_at',
  1308. 'article.introduce',
  1309. 'article.islink',
  1310. 'article.linkurl',
  1311. 'article.copyfrom',
  1312. 'article.cat_arr_id',
  1313. 'article.catid',
  1314. 'article.level',
  1315. // 'article_ignore.is_ignore',
  1316. // 'article_ignore.c_show_time',
  1317. )
  1318. ->offset($data['placeid'])
  1319. ->limit($data['textnum'])
  1320. ->get()->all();
  1321. foreach ($result['text'] as $k => $v) {
  1322. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1323. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1324. }
  1325. }
  1326. if ($data['imgnum'] > 0) {
  1327. $query = clone $query;
  1328. if ($data['textnum'] == 0) {
  1329. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1330. $query->from('article_ignore')
  1331. ->where('website_id', $website_id);
  1332. }, 'article_ignore', function ($join) {
  1333. $join->on('article_ignore.article_id', '=', 'article.id');
  1334. })
  1335. ->where(function ($query) {
  1336. $query->whereNull('article_ignore.article_id')
  1337. ->orWhere(function ($subQuery) {
  1338. $subQuery->whereNotNull('article_ignore.article_id')
  1339. ->where('article_ignore.is_ignore', 0)
  1340. ->where(function ($subSubQuery) {
  1341. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1342. ->orWhereNull('article_ignore.c_show_time');
  1343. });
  1344. });
  1345. });
  1346. }
  1347. $result['img'] = $query
  1348. ->whereIn('catid', $categoryIds)
  1349. ->where('article.imgurl', '!=', '')
  1350. ->select(
  1351. 'article.id',
  1352. 'article.title',
  1353. 'article.imgurl',
  1354. 'article.author',
  1355. 'article.updated_at',
  1356. 'article.introduce',
  1357. 'article.islink',
  1358. 'article.linkurl',
  1359. 'article.copyfrom',
  1360. 'article.cat_arr_id',
  1361. 'article.catid',
  1362. 'article.level',
  1363. // 'article_ignore.is_ignore',
  1364. // 'article_ignore.c_show_time',
  1365. )
  1366. ->offset($data['placeid'])
  1367. ->limit($data['imgnum'])
  1368. ->get()->all();
  1369. foreach ($result['img'] as $k => $v) {
  1370. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1371. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1372. }
  1373. }
  1374. if (empty($result)) {
  1375. return Result::error("暂无相关资讯", 0);
  1376. }
  1377. return Result::success($result);
  1378. }
  1379. /**
  1380. * 获取模块新闻
  1381. * @param array $data
  1382. * @return array
  1383. */
  1384. public function getWebsiteModelArticles(array $data): array
  1385. {
  1386. $catid = $data['catid'];
  1387. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1388. $category = $category->toArray();
  1389. if (!empty($category)) {
  1390. $where = [
  1391. 'status' => 1,
  1392. 'catid' => $catid,
  1393. ];
  1394. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1395. // 1:文字新闻;2:轮播图;3:图文;
  1396. // 级别:0:未分类
  1397. // 3:推荐图片
  1398. if ($data['level'] == 1) {
  1399. $data['level'] = 0;
  1400. }
  1401. $result = Article::where($where)
  1402. ->where(function ($query) use ($data) {
  1403. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1404. ->orWhereNull("level")
  1405. ->orWhereRaw("level = '[]'");
  1406. })
  1407. ->leftJoinSub(function ($query) use ($data) {
  1408. $query->from('article_ignore')
  1409. ->where('website_id', $data['website_id']);
  1410. }, 'article_ignore', function ($join) {
  1411. $join->on('article_ignore.article_id', '=', 'article.id');
  1412. })
  1413. ->where(function ($query) {
  1414. $query->whereNull('article_ignore.article_id')
  1415. ->orWhere(function ($subQuery) {
  1416. $subQuery->whereNotNull('article_ignore.article_id')
  1417. ->where('article_ignore.is_ignore', 0)
  1418. ->where(function ($subSubQuery) {
  1419. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1420. ->orWhereNull('article_ignore.c_show_time');
  1421. });
  1422. });
  1423. })
  1424. // ->where(function ($query) use ($data) {
  1425. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1426. // ->orWhereNull("ignore_ids");
  1427. // })
  1428. ->orderBy("updated_at", "desc")
  1429. ->offset($placeid)
  1430. ->limit($data['pagesize'])
  1431. ->get();
  1432. if (empty($result)) {
  1433. return Result::error("此栏目暂无相关新闻", 0);
  1434. }
  1435. } else {
  1436. return Result::error("此网站暂无此栏目", 0);
  1437. }
  1438. return Result::success($result);
  1439. }
  1440. /**
  1441. *获取新闻列表
  1442. * @param array $data
  1443. * @return array
  1444. */
  1445. public function getWebsiteArticleList(array $data): array
  1446. {
  1447. // return Result::success($data);
  1448. $where[] = ['status', '=', 1];
  1449. $website_id = $data['website_id'];
  1450. $website = Website::where('id', $data['website_id'])->first();
  1451. if (empty($website)) {
  1452. return Result::error("网站不存在", 0);
  1453. }
  1454. // $website_column = $website['column'];
  1455. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1456. $website_column = json_decode($website['website_column_arr_id'], true);
  1457. }
  1458. $categorys = $this->processArticlePro($website_id);
  1459. $cat_1st_arr = $categorys['cat_1st_arr'];
  1460. $catiall = $categorys['catiall'];
  1461. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1462. // return Result::success($diff_pid_categoryIds);
  1463. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1464. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1465. }
  1466. if (isset($data['catid']) && !empty($data['catid'])) {
  1467. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1468. if (empty($category)) {
  1469. return Result::error("此网站暂无此栏目", 0);
  1470. }
  1471. array_push($where, ['catid', '=', $data['catid']]);
  1472. }
  1473. // return Result::success($where);
  1474. $query = Article::where($where)
  1475. ->leftJoinSub(function ($query) use ($website_id) {
  1476. $query->from('article_ignore')
  1477. ->where('website_id', $website_id);
  1478. }, 'article_ignore', function ($join) {
  1479. $join->on('article_ignore.article_id', '=', 'article.id');
  1480. })
  1481. ->where(function ($query) {
  1482. $query->whereNull('article_ignore.article_id')
  1483. ->orWhere(function ($subQuery) {
  1484. $subQuery->whereNotNull('article_ignore.article_id')
  1485. ->where('article_ignore.is_ignore', 0)
  1486. ->where(function ($subSubQuery) {
  1487. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1488. ->orWhereNull('article_ignore.c_show_time');
  1489. });
  1490. });
  1491. })
  1492. ->select(
  1493. 'article.id',
  1494. 'article.title',
  1495. 'article.imgurl',
  1496. 'article.author',
  1497. 'article.updated_at',
  1498. 'article.introduce',
  1499. 'article.islink',
  1500. 'article.linkurl',
  1501. 'article.copyfrom',
  1502. 'article.cat_arr_id',
  1503. 'article.catid'
  1504. );
  1505. $count = $query->count();
  1506. $rep = $query->orderBy("updated_at", "desc")
  1507. ->offset(($data['page'] - 1) * $data['pageSize'])
  1508. ->limit($data['pageSize'])
  1509. ->get()->all();
  1510. $categorys = $this->processArticlePro($website_id);
  1511. $cat_1st_arr = $categorys['cat_1st_arr'];
  1512. $catiall = $categorys['catiall'];
  1513. // $web['website_id'] = $data['website_id'];
  1514. foreach ($rep as $k => $v) {
  1515. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1516. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1517. }
  1518. // $rep = $this->processArticles($rep,$web);
  1519. $data = [
  1520. 'rows' => $rep,
  1521. 'count' => $count,
  1522. ];
  1523. if (empty($rep)) {
  1524. return Result::error("没有信息数据");
  1525. }
  1526. return Result::success($data);
  1527. }
  1528. /**
  1529. * 前端-获取新闻详情
  1530. * @param array $data
  1531. * @return array
  1532. */
  1533. public function selectWebsiteArticleInfo(array $data): array
  1534. {
  1535. $where = [
  1536. 'article.id' => $data['id'],
  1537. 'article.status' => 1,
  1538. ];
  1539. $result = Article::where($where)
  1540. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1541. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1542. // ->where(function ($query) use ($data) {
  1543. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1544. // ->orWhereNull("ignore_ids");
  1545. // })
  1546. ->leftJoinSub(function ($query) use ($data) {
  1547. $query->from('article_ignore')
  1548. ->where('website_id', $data['website_id']);
  1549. }, 'article_ignore', function ($join) {
  1550. $join->on('article_ignore.article_id', '=', 'article.id');
  1551. })
  1552. ->where(function ($query) {
  1553. $query->whereNull('article_ignore.article_id')
  1554. ->orWhere(function ($subQuery) {
  1555. $subQuery->whereNotNull('article_ignore.article_id')
  1556. ->where('article_ignore.is_ignore', 0)
  1557. ->where(function ($subSubQuery) {
  1558. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1559. ->orWhereNull('article_ignore.c_show_time');
  1560. });
  1561. });
  1562. })
  1563. ->select(
  1564. 'article.*',
  1565. 'article_data.content',
  1566. 'article_data.article_id',
  1567. 'article_extend.website_url',
  1568. 'article_extend.email',
  1569. 'article_extend.contacts',
  1570. 'article_extend.contacts_mobile',
  1571. 'article_extend.contacts_address',
  1572. 'article_extend.zip_code',
  1573. 'article_extend.enterprise_name'
  1574. )
  1575. ->first();
  1576. if (empty($result)) {
  1577. return Result::error("暂无此新闻!", 0);
  1578. }
  1579. if (!empty($result['publiced_at'])) {
  1580. $result['updated_at'] = $result['publiced_at'];
  1581. }
  1582. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1583. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1584. ->where('website_category.website_id', $data['website_id'])
  1585. ->where(['website_category.category_id' => $result['catid']])
  1586. ->first();
  1587. if (empty($category)) {
  1588. return Result::error("查询失败", 0);
  1589. }
  1590. //手动推荐文章
  1591. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1592. if (empty($commend_ids)) {
  1593. $commendArticle = [];
  1594. } else {
  1595. //去除不存在的文章ID
  1596. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1597. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1598. ->leftJoinSub(function ($query) use ($data) {
  1599. $query->from('article_ignore')
  1600. ->where('website_id', $data['website_id']);
  1601. }, 'article_ignore', function ($join) {
  1602. $join->on('article_ignore.article_id', '=', 'article.id');
  1603. })
  1604. ->where(function ($query) {
  1605. $query->whereNull('article_ignore.article_id')
  1606. ->orWhere(function ($subQuery) {
  1607. $subQuery->whereNotNull('article_ignore.article_id')
  1608. ->where('article_ignore.is_ignore', 0)
  1609. ->where(function ($subSubQuery) {
  1610. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1611. ->orWhereNull('article_ignore.c_show_time');
  1612. });
  1613. });
  1614. })
  1615. ->where('article.status', 1)
  1616. ->where('website_category.website_id', $data['website_id'])
  1617. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1618. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1619. // ->orderBy('article.updated_at', 'desc')
  1620. ->limit(5)
  1621. ->get();
  1622. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1623. foreach ($commendArticle as $k => $v) {
  1624. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1625. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1626. $cat_arr_id = array_unique($cat_arr_id);
  1627. // 从website_category取出alias_pinyin
  1628. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1629. ->whereIn('category_id', $cat_arr_id)
  1630. ->pluck('alias_pinyin', 'category_id')
  1631. ->toArray();
  1632. // 将cat_arr_id的json转成路径/隔开
  1633. $path_parts = [];
  1634. foreach ($cat_arr_id as $cat_id) {
  1635. if (isset($cat_arr[$cat_id])) {
  1636. $path_parts[] = $cat_arr[$cat_id];
  1637. }
  1638. }
  1639. $v->alias_pinyin = implode('/', $path_parts);
  1640. } else {
  1641. $v->alias_pinyin = '';
  1642. }
  1643. }
  1644. }
  1645. $result['category_id'] = $category['category_id'];
  1646. $result['cat_name'] = $category['alias'];
  1647. $result['website_name'] = $category['website_name'] ?? "";
  1648. $result['suffix'] = $category['suffix'] ?? "";
  1649. $result['commendArticle'] = $commendArticle;
  1650. $result['commend_ids'] = $commend_ids;
  1651. return Result::success($result);
  1652. }
  1653. /**
  1654. * 前端-获取网站调查问卷
  1655. * @param array $data
  1656. * @return array
  1657. */
  1658. public function getWebsiteSurvey(array $data): array
  1659. {
  1660. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1661. $website = Website::where('id', $data['website_id'])->first();
  1662. if (empty($website)) {
  1663. return Result::error("暂无此网站", 0);
  1664. }
  1665. }
  1666. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1667. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1668. if (empty($article)) {
  1669. return Result::error("暂无此文章", 0);
  1670. }
  1671. // return Result::error($data,0);
  1672. $where['art_id'] = $data['art_id'];
  1673. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1674. } else {
  1675. $survey = Article::where(function ($query) {
  1676. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1677. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1678. })
  1679. ->where('status', 1)
  1680. ->where('is_survey', 1)
  1681. ->select('survey_id')
  1682. ->orderBy('updated_at', 'desc')
  1683. ->first();
  1684. if (empty($survey)) {
  1685. return Result::error("暂无调查问卷", 0);
  1686. }
  1687. $where['sur_id'] = $survey['survey_id'];
  1688. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1689. }
  1690. // return Result::success($where);
  1691. $result = ArticleSurvey::where($where)
  1692. ->where(function ($query) {
  1693. $query->where('is_other', 0)
  1694. ->orWhere(function ($subQuery) {
  1695. $subQuery->where('is_other', 1)
  1696. ->where('other_id', 0);
  1697. });
  1698. })
  1699. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1700. ->select('article_survey.*', 'article.survey_type')
  1701. ->get()->all();
  1702. if (empty($result)) {
  1703. return Result::error("此文章暂无调查问卷", 0);
  1704. }
  1705. return Result::success($result);
  1706. }
  1707. /**
  1708. * 前端-添加网站调查问卷选项
  1709. * @param array $data
  1710. * @return array
  1711. */
  1712. public function addWebsiteSurveyOption(array $data): array
  1713. {
  1714. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1715. $website = Website::where('id', $data['website_id'])->first();
  1716. if (empty($website)) {
  1717. return Result::error("暂无此网站", 0);
  1718. }
  1719. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1720. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1721. if (empty($survey)) {
  1722. return Result::error("此调查问卷不可添加选项", 0);
  1723. }
  1724. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1725. $choice = [
  1726. 'art_id' => $survey['art_id'],
  1727. 'website_id' => $data['website_id'],
  1728. 'survey_name' => $survey['survey_name'],
  1729. 'choice_name' => $data['choice_name'],
  1730. 'sur_id' => $survey['sur_id'],
  1731. 'is_other' => 1,
  1732. 'other_id' => $survey['id'],
  1733. ];
  1734. $result = ArticleSurvey::insertGetId($choice);
  1735. if (empty($result)) {
  1736. return Result::error("添加失败", 0);
  1737. }
  1738. return Result::success($result);
  1739. }
  1740. }
  1741. return Result::error("添加失败", 0);
  1742. }
  1743. return Result::error("添加失败", 0);
  1744. }
  1745. /**
  1746. * 前端-调查问卷投票
  1747. * @param array $data
  1748. * @return array
  1749. */
  1750. public function addWebsiteSurveyVote(array $data): array
  1751. {
  1752. // return Result::success($data);
  1753. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1754. $website = Website::where('id', $data['website_id'])->first();
  1755. if (empty($website)) {
  1756. return Result::error("暂无此网站", 0);
  1757. }
  1758. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1759. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1760. // return Result::success($survey);
  1761. if (empty($is_survey)) {
  1762. return Result::error("此调查问卷不存在", 0);
  1763. }
  1764. // return Result::success($survey);
  1765. // 调查问卷类型
  1766. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1767. //多选 若是json型则转化成数组类型
  1768. if (strpos($data['choice_id'], '[') === 0) {
  1769. $data['choice_id'] = json_decode($data['choice_id'], true);
  1770. } else {
  1771. // 单选 也转换成数组
  1772. $data['choice_id'] = [$data['choice_id']];
  1773. }
  1774. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1775. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1776. // ->where('website_id',$data['website_id'])
  1777. ->where('is_other', 1)
  1778. ->where('other_id', 0)
  1779. ->first();
  1780. if (!empty($other)) {
  1781. return Result::error("请选择已有的选项!", 0);
  1782. }
  1783. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1784. // ->where('website_id',$data['website_id'])
  1785. ->where('is_other', 1)
  1786. ->where('other_id', '!=', 0)
  1787. ->first();
  1788. // return Result::success($choice['other']);
  1789. $choice_id = $data['choice_id'];
  1790. if (!empty($choice['other'])) {
  1791. // array_push($data['choice_id'],$choice['other']['other_id']);
  1792. if (!empty($choice_id)) {
  1793. $key = array_search($choice['other']['id'], $choice_id);
  1794. if ($key !== false) {
  1795. unset($choice_id[$key]);
  1796. $choice_id = array_values($choice_id);
  1797. }
  1798. array_push($choice_id, $choice['other']['other_id']);
  1799. } else {
  1800. $choice_id[0] = $choice['other']['other_id'];
  1801. }
  1802. array_push($data['choice_id'], $choice['other']['other_id']);
  1803. }
  1804. // return Result::success($data);
  1805. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1806. // ->where('website_id',$data['website_id'])
  1807. ->increment('results', 1);
  1808. if (empty($choice)) {
  1809. return Result::error("请选择已有的选项!", 0);
  1810. }
  1811. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1812. // ->where('website_id',$data['website_id'])
  1813. ->where('other_id', 0)
  1814. ->get();
  1815. $survey['choice'] = $choice_id;
  1816. return Result::success($survey);
  1817. }
  1818. return Result::error("参数必填!");
  1819. }
  1820. return Result::error("此调查问卷不存在", 0);
  1821. }
  1822. return Result::error("参数必填!");
  1823. }
  1824. /**
  1825. * 后端-获取网站调查问卷列表
  1826. * @param array $data
  1827. * @return array
  1828. */
  1829. public function getSurveyList(array $data): array
  1830. {
  1831. $where = [];
  1832. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1833. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1834. }
  1835. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1836. if (!empty($where)) {
  1837. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1838. $query = ArticleSurvey::select(
  1839. 'art_id as id',
  1840. Db::raw('MAX(id) as surid'),
  1841. Db::raw('MAX(survey_name) as survey_name'),
  1842. Db::raw('MAX(sur_id) as survey_id')
  1843. )
  1844. ->groupBy('art_id')
  1845. ->where($where)
  1846. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1847. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1848. $sub->select('id')
  1849. ->from('article')
  1850. ->where('survey_type', $survey_type);
  1851. });
  1852. })
  1853. ->with(['article' => function ($query) {
  1854. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1855. }]);
  1856. ;
  1857. }else{
  1858. $query = ArticleSurvey::select(
  1859. 'art_id as id',
  1860. Db::raw('MAX(id) as surid'),
  1861. Db::raw('MAX(survey_name) as survey_name'),
  1862. Db::raw('MAX(sur_id) as survey_id'),
  1863. )
  1864. ->groupBy('art_id')
  1865. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1866. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1867. $sub->select('id')
  1868. ->from('article')
  1869. ->where('survey_type', $survey_type);
  1870. });
  1871. })
  1872. ->with(['article' => function ($query) {
  1873. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1874. }]);
  1875. }
  1876. $count = $query->get()->count();
  1877. // 简单写法:直接统计分组后的 art_id 数量
  1878. $survey = $query->orderBy('id', 'desc')
  1879. ->limit($data['pageSize'])
  1880. ->offset(($data['page'] - 1) * $data['pageSize'])
  1881. ->get();
  1882. if (empty($survey->toArray())) {
  1883. return Result::error("暂无调查问卷!", 0);
  1884. }
  1885. $survey = array_map(function ($item) {
  1886. if (isset($item['article'])) {
  1887. $item['survey_type'] = $item['article']['survey_type'];
  1888. $item['created_at'] = $item['article']['created_at'];
  1889. $item['updated_at'] = $item['article']['updated_at'];
  1890. } else {
  1891. // 处理article为null的情况,设置默认值
  1892. $item['survey_type'] = null;
  1893. $item['created_at'] = null;
  1894. $item['updated_at'] = null;
  1895. }
  1896. unset($item['article']);
  1897. return $item;
  1898. }, $survey->toArray());
  1899. $result = [
  1900. 'rows' => $survey,
  1901. 'count' => $count,
  1902. ];
  1903. return Result::success($result);
  1904. }
  1905. /**
  1906. * 后端-获取网站调查问卷详情
  1907. * @param array $data
  1908. * @return array
  1909. */
  1910. public function getSurveyInfo(array $data): array
  1911. {
  1912. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1913. $where = ['sur_id' => $data['sur_id']];
  1914. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1915. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1916. ->select('article_survey.*', 'article.survey_type')
  1917. ->get()->all();
  1918. if (empty($choose)) {
  1919. return Result::error("此调查问卷不存在", 0);
  1920. }
  1921. $resultsArray = array_column($choose, 'results');
  1922. $total = array_sum($resultsArray);
  1923. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1924. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1925. // $total = 0;
  1926. if (!empty($other)) {
  1927. $total = $total + $other['results'];
  1928. $other['choice_name'] = '(其他)';
  1929. if (!empty($others)) {
  1930. $other['hasChildren'] = true;
  1931. // array_push($other,['hasChildren','=',true]);
  1932. $other['children'] = $others;
  1933. $other_choices = [$other->toArray()];
  1934. $mer_choice = array_merge($choose, $other_choices);
  1935. $value_choice = array_values($mer_choice);
  1936. } else {
  1937. // return Result::error('1111');
  1938. $other_choices = [$other->toArray()];
  1939. $other_choices = array_merge($choose, $other_choices);
  1940. $value_choice = array_values($other_choices);
  1941. // return Result::success($result);
  1942. }
  1943. } else {
  1944. $value_choice = $choose;
  1945. }
  1946. $result = [
  1947. 'choose' => $value_choice,
  1948. 'total' => $total,
  1949. ];
  1950. }
  1951. return Result::success($result);
  1952. }
  1953. /**
  1954. * 前端-搜索新闻列表
  1955. * @param array $data
  1956. * @return array
  1957. */
  1958. public function selectWebsiteArticle(array $data): array
  1959. {
  1960. $website = Website::where('id', $data['website_id'])->first();
  1961. if (empty($website)) {
  1962. return Result::error("网站不存在", 0);
  1963. }
  1964. // $website_column = $website['column'];
  1965. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1966. $website_column = json_decode($website['website_column_arr_id'], true);
  1967. }
  1968. $website_id = $data['website_id'];
  1969. $categorys = $this->processArticlePro($website_id);
  1970. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1971. // return Result::success($diff_pid_categoryIds);
  1972. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1973. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1974. }
  1975. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1976. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1977. $catiall = $categorys['catiall'];
  1978. $categoryIds = $categorys['categoryIds'];
  1979. // return Result::success($categoryIds);
  1980. $query = Article::where('status', 1)
  1981. ->whereIn('catid', $categoryIds)
  1982. ->leftJoinSub(function ($query) use ($website_id) {
  1983. $query->from('article_ignore')
  1984. ->where('website_id', $website_id);
  1985. }, 'article_ignore', function ($join) {
  1986. $join->on('article_ignore.article_id', '=', 'article.id');
  1987. })
  1988. ->where(function ($query) {
  1989. $query->whereNull('article_ignore.article_id')
  1990. ->orWhere(function ($subQuery) {
  1991. $subQuery->whereNotNull('article_ignore.article_id')
  1992. ->where('article_ignore.is_ignore', 0)
  1993. ->where(function ($subSubQuery) {
  1994. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1995. ->orWhereNull('article_ignore.c_show_time');
  1996. });
  1997. });
  1998. });
  1999. // ->get()->all();
  2000. // return Result::success($query);
  2001. if (isset($data['cityid']) && !empty($data['cityid'])) {
  2002. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  2003. }
  2004. if (isset($data['department_id']) && !empty($data['department_id'])) {
  2005. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  2006. }
  2007. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2008. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  2009. }
  2010. // 计算总数
  2011. $count = $query->count();
  2012. // return Result::success($count);
  2013. // 分页查询
  2014. $articles = $query
  2015. ->select(
  2016. 'article.id',
  2017. 'article.title',
  2018. 'article.imgurl',
  2019. 'article.author',
  2020. 'article.updated_at',
  2021. 'article.introduce',
  2022. 'article.islink',
  2023. 'article.linkurl',
  2024. 'article.copyfrom',
  2025. 'article.cat_arr_id',
  2026. 'article.catid',
  2027. 'article.department_arr_id',
  2028. 'article.city_arr_id',
  2029. // 'article_ignore.c_show_time',
  2030. // 'article_ignore.is_ignore'
  2031. )
  2032. ->orderBy("updated_at", "desc")
  2033. ->offset(($data['page'] - 1) * $data['pageSize'])
  2034. ->limit($data['pageSize'])
  2035. ->get();
  2036. // return Result::success($articles);
  2037. foreach ($articles as $k => $v) {
  2038. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2039. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2040. }
  2041. if (empty($articles)) {
  2042. return Result::error("没有符合条件的资讯数据");
  2043. }
  2044. $result = [
  2045. 'rows' => $articles,
  2046. 'count' => $count,
  2047. ];
  2048. return Result::success($result);
  2049. }
  2050. /**
  2051. * 模块新闻加强版
  2052. * @param array $data
  2053. * @return array
  2054. */
  2055. public function getWebsiteCatidArticle(array $data): array
  2056. {
  2057. $where = [
  2058. 'website_category.category_id' => $data['catid'],
  2059. 'website_category.website_id' => $data['website_id'],
  2060. ];
  2061. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2062. $child_catnum = $data['child_catnum'] ?? 1;
  2063. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2064. $childCategoryIds = array_column($category['child'], 'category_id');
  2065. if (empty($childCategoryIds)) {
  2066. return Result::error("暂无子栏目", 0);
  2067. }
  2068. $imgArticles = [];
  2069. $textArticles = [];
  2070. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2071. // 初始化子分类图片新闻和文字新闻数组
  2072. // 查询所有子级栏目的图文新闻
  2073. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2074. ->where(function ($query) use ($data) {
  2075. $query->where(function ($subQuery) use ($data) {
  2076. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2077. })->orWhereNull("ignore_ids");
  2078. })
  2079. ->where('status', 1)
  2080. ->where('imgurl', '!=', '')
  2081. ->select('*')
  2082. ->orderBy('updated_at', 'desc')
  2083. ->limit($data['child_imgnum'])
  2084. ->get();
  2085. }
  2086. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2087. // 查询所有子级栏目的文字新闻
  2088. $textArticles = Article::where('catid', $childCategoryIds[0])
  2089. ->where('status', 1)
  2090. ->where(function ($query) use ($data) {
  2091. $query->where(function ($subQuery) use ($data) {
  2092. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2093. })->orWhereNull("ignore_ids");
  2094. })
  2095. ->select('*')
  2096. ->orderBy('updated_at', 'desc')
  2097. ->limit($data['child_textnum'])
  2098. ->get();
  2099. }
  2100. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2101. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2102. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2103. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2104. return $child;
  2105. }, $category['child']);
  2106. }
  2107. // }
  2108. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2109. $category['img'] = WebsiteCategory::where($where)
  2110. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2111. ->where('article.status', 1)
  2112. ->where('article.imgurl', '!=', '')
  2113. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2114. ->orderBy('article.updated_at', 'desc')
  2115. ->limit($data['img_num'])
  2116. ->get();
  2117. }
  2118. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2119. $category['text'] = WebsiteCategory::where($where)
  2120. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2121. ->where('article.status', 1)
  2122. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2123. ->orderBy('article.updated_at', 'desc')
  2124. ->limit($data['text_num'])
  2125. ->get();
  2126. }
  2127. // $category = $category->get();
  2128. if (empty($category)) {
  2129. return Result::error("查询失败", 0);
  2130. }
  2131. return Result::success($category);
  2132. }
  2133. /**
  2134. * 模块新闻加强plus版
  2135. * @param array $data
  2136. * @return array
  2137. */
  2138. public function getWebsiteAllArticle(array $data): array
  2139. {
  2140. // return Result::success($data);
  2141. $time1 = microtime(true);
  2142. $wetbsite_id = $data['website_id'] ?? 2;
  2143. $data = json_decode($data['id'], true);
  2144. $website = Website::where('id', $wetbsite_id)->first();
  2145. if (empty($website)) {
  2146. return Result::error("网站不存在", 0);
  2147. }
  2148. // return Result::success($website);
  2149. $website_column = $website['website_column_arr_id'] ?? '[]';
  2150. $website_column = json_decode($website_column, true);
  2151. $categorys = $this->processArticlePro($wetbsite_id);
  2152. $cat_1st_arr = $categorys['cat_1st_arr'];
  2153. $catiall = $categorys['catiall'];
  2154. // return Result::success($catiall);
  2155. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2156. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2157. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2158. }
  2159. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2160. // return Result::success($categorys);
  2161. $parent_category = array_column($data, 'parent');
  2162. $parent_cat = [];
  2163. $child_category = array_column($data, 'child');
  2164. if (!empty($parent_category)) {
  2165. foreach ($parent_category as $key => $value) {
  2166. $arr = array_map('intval', explode(',', $value));
  2167. $parent_cat[$key] = $arr[0] ?? 0;
  2168. $parent_category = $arr[0] ?? 0;
  2169. $article_imgnum = $arr[1] ?? 0;
  2170. $article_textnum = $arr[2] ?? 0;
  2171. if ($parent_category != 0) {
  2172. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2173. // return Result::success($category_arr);
  2174. if ($article_imgnum != 0) {
  2175. $img_article = Article::whereIn('catid', $category_arr)
  2176. ->where('status', 1)
  2177. ->where('imgurl', '!=', '')
  2178. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2179. $query->from('article_ignore')
  2180. ->where('website_id', $wetbsite_id);
  2181. }, 'article_ignore', function ($join) {
  2182. $join->on('article_ignore.article_id', '=', 'article.id');
  2183. })
  2184. ->where(function ($query) {
  2185. $query->whereNull('article_ignore.article_id')
  2186. ->orWhere(function ($subQuery) {
  2187. $subQuery->whereNotNull('article_ignore.article_id')
  2188. ->where('article_ignore.is_ignore', 0)
  2189. ->where(function ($subSubQuery) {
  2190. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2191. ->orWhereNull('article_ignore.c_show_time');
  2192. });
  2193. });
  2194. })
  2195. ->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')
  2196. ->orderBy('updated_at', 'desc')
  2197. ->limit($article_imgnum)
  2198. ->get()->all();
  2199. foreach ($img_article as $k => $v) {
  2200. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2201. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2202. }
  2203. } else {
  2204. $img_article = [];
  2205. }
  2206. if ($article_textnum != 0) {
  2207. $text_article = Article::whereIn('catid', $category_arr)
  2208. ->where('status', 1)
  2209. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2210. $query->from('article_ignore')
  2211. ->where('website_id', $wetbsite_id);
  2212. }, 'article_ignore', function ($join) {
  2213. $join->on('article_ignore.article_id', '=', 'article.id');
  2214. })
  2215. ->where(function ($query) {
  2216. $query->whereNull('article_ignore.article_id')
  2217. ->orWhere(function ($subQuery) {
  2218. $subQuery->whereNotNull('article_ignore.article_id')
  2219. ->where('article_ignore.is_ignore', 0)
  2220. ->where(function ($subSubQuery) {
  2221. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2222. ->orWhereNull('article_ignore.c_show_time');
  2223. });
  2224. });
  2225. })
  2226. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2227. ->orderBy('updated_at', 'desc')
  2228. ->limit($article_textnum)
  2229. ->get()->all();
  2230. foreach ($text_article as $k => $v) {
  2231. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2232. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2233. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2234. }
  2235. } else {
  2236. $text_article = [];
  2237. }
  2238. $catiall[$parent_category]['imgnum'] = $img_article;
  2239. $catiall[$parent_category]['textnum'] = $text_article;
  2240. $parent[$key] = $catiall[$parent_category];
  2241. } else {
  2242. $parent[$key] = '';
  2243. }
  2244. }
  2245. }
  2246. if (!empty($child_category)) {
  2247. foreach ($child_category as $key => $value) {
  2248. $arr = array_map('intval', explode(',', $value));
  2249. $parent_category = $parent_cat[$key];
  2250. $child_category = $arr[0] ?? 0;
  2251. $article_imgnum = $arr[1] ?? 0;
  2252. $article_textnum = $arr[2] ?? 0;
  2253. if ($child_category != 0) {
  2254. $all_childcat = $cat_1st_arr[$parent_category];
  2255. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2256. // 从 $websiteInfoIndexed 中获取对应的数据
  2257. $info = $websiteInfoIndexed[$v];
  2258. // 返回一个包含所需信息的数组
  2259. return [
  2260. 'alias' => $info->alias,
  2261. 'category_id' => $info->category_id,
  2262. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2263. 'pid' => $info->pid,
  2264. 'type' => $info->type,
  2265. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2266. 'pinyin' => $info->pinyin,
  2267. ];
  2268. }, $all_childcat);
  2269. if ($article_imgnum != 0) {
  2270. $img_article = Article::where('catid', $child_category)
  2271. ->where('status', 1)
  2272. ->where('imgurl', '!=', '')
  2273. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2274. $query->from('article_ignore')
  2275. ->where('website_id', $wetbsite_id);
  2276. }, 'article_ignore', function ($join) {
  2277. $join->on('article_ignore.article_id', '=', 'article.id');
  2278. })
  2279. ->where(function ($query) {
  2280. $query->whereNull('article_ignore.article_id')
  2281. ->orWhere(function ($subQuery) {
  2282. $subQuery->whereNotNull('article_ignore.article_id')
  2283. ->where('article_ignore.is_ignore', 0)
  2284. ->where(function ($subSubQuery) {
  2285. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2286. ->orWhereNull('article_ignore.c_show_time');
  2287. });
  2288. });
  2289. })
  2290. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2291. ->orderBy('updated_at', 'desc')
  2292. ->limit($article_imgnum)
  2293. ->get()->all();
  2294. foreach ($img_article as $k => $v) {
  2295. // var_dump($v);
  2296. // var_dump($k);
  2297. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2298. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2299. }
  2300. } else {
  2301. $img_article = [];
  2302. }
  2303. if ($article_textnum != 0) {
  2304. $text_article = Article::where('catid', $child_category)
  2305. ->where('status', 1)
  2306. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2307. $query->from('article_ignore')
  2308. ->where('website_id', $wetbsite_id);
  2309. }, 'article_ignore', function ($join) {
  2310. $join->on('article_ignore.article_id', '=', 'article.id');
  2311. })
  2312. ->where(function ($query) {
  2313. $query->whereNull('article_ignore.article_id')
  2314. ->orWhere(function ($subQuery) {
  2315. $subQuery->whereNotNull('article_ignore.article_id')
  2316. ->where('article_ignore.is_ignore', 0)
  2317. ->where(function ($subSubQuery) {
  2318. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2319. ->orWhereNull('article_ignore.c_show_time');
  2320. });
  2321. });
  2322. })
  2323. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2324. ->orderBy('updated_at', 'desc')
  2325. ->limit($article_textnum)
  2326. ->get()->all();
  2327. foreach ($text_article as $k => $v) {
  2328. // var_dump($v);
  2329. // var_dump($k);
  2330. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2331. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2332. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2333. }
  2334. } else {
  2335. $text_article = [];
  2336. }
  2337. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2338. $catiall[$child_category]['imgnum'] = $img_article;
  2339. $catiall[$child_category]['textnum'] = $text_article;
  2340. $child[$key] = $catiall[$child_category];
  2341. // var_dump($pids);
  2342. } else {
  2343. $child[$key] = '';
  2344. }
  2345. }
  2346. }
  2347. foreach ($parent as $key => $value) {
  2348. $result[$key] = $value;
  2349. if (!empty($child[$key])) {
  2350. // var_dump($child[$key]);
  2351. $result[$key]['child'] = $child[$key];
  2352. // $value[$key]['child'] = $child[$key];
  2353. } else {
  2354. $result[$key]['child'] = [
  2355. "alias" => null,
  2356. "category_id" => null,
  2357. "type" => null,
  2358. "pinyin" => null,
  2359. "all_childcat" => [],
  2360. "imgnum" => [],
  2361. "textnum" => []
  2362. ];
  2363. }
  2364. }
  2365. return Result::success($result);
  2366. }
  2367. /**
  2368. * 辅助方法:获取文章列表
  2369. */
  2370. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2371. {
  2372. sleep(1);
  2373. $query = Article::where('article.status', 1)
  2374. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2375. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2376. ->where(function ($query) use ($website) {
  2377. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2378. })
  2379. ->leftJoin('website_category', function ($join) use ($website) {
  2380. $join->on('article.catid', '=', 'website_category.category_id')
  2381. ->where('website_category.website_id', '=', $website['website_id']);
  2382. })
  2383. ->select(
  2384. 'article.id',
  2385. 'article.title',
  2386. 'article.imgurl',
  2387. 'article.author',
  2388. 'article.updated_at',
  2389. 'article.introduce',
  2390. 'article.islink',
  2391. 'article.linkurl',
  2392. 'article.copyfrom',
  2393. 'article.cat_arr_id',
  2394. 'article.catid',
  2395. 'website_category.alias as category_name'
  2396. )
  2397. ->orderBy('updated_at', 'desc')
  2398. ->limit($limit);
  2399. // 如果是图片文章,添加图片URL条件
  2400. if ($isImageArticle) {
  2401. $query->where('imgurl', '!=', '');
  2402. } else {
  2403. // 文字文章不需要imgurl字段
  2404. $query->addSelect('article.introduce');
  2405. }
  2406. $articles = $query->get();
  2407. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2408. }
  2409. /**
  2410. * 乡村网-获取特殊新闻模块
  2411. * @param array $data
  2412. * @return array
  2413. */
  2414. public function getWebsiteArticles(array $data): array
  2415. {
  2416. $website_id = $data['website_id'];
  2417. $website = Website::where('id', $website_id)->first();
  2418. if (empty($website)) {
  2419. return Result::error("网站不存在", 0);
  2420. }
  2421. // return Result::success($website);
  2422. $website_column = $website['website_column_arr_id'] ?? '[]';
  2423. $website_column = json_decode($website_column, true);
  2424. $catids = json_decode($data['id'], true);
  2425. $parent_category = array_column($catids, 'parent');
  2426. if (!empty($parent_category) && is_array($parent_category)) {
  2427. $categorys = $this->processArticlePro($website_id);
  2428. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2429. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2430. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2431. }
  2432. $catiall = $categorys['catiall'];
  2433. $cat_1st_arr = $categorys['cat_1st_arr'];
  2434. // return Result::success($categorys);
  2435. foreach ($parent_category as $key => $value) {
  2436. $arr = array_map('intval', explode(',', $value));
  2437. $parent_category = $arr[0] ?? 0;
  2438. $article_imgnum = $arr[1] ?? 0;
  2439. $article_textnum = $arr[2] ?? 0;
  2440. if ($parent_category != 0) {
  2441. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2442. // return Result::success($category_arr);
  2443. if ($article_imgnum != 0) {
  2444. $img_article = Article::whereIn('article.catid', $category_arr)
  2445. ->where('article.status', 1)
  2446. ->where('article.imgurl', '!=', '')
  2447. ->leftJoinSub(function ($query) use ($website_id) {
  2448. $query->from('article_ignore')
  2449. ->where('website_id', $website_id);
  2450. }, 'article_ignore', function ($join) {
  2451. $join->on('article_ignore.article_id', '=', 'article.id');
  2452. })
  2453. ->where(function ($query) {
  2454. $query->whereNull('article_ignore.article_id')
  2455. ->orWhere(function ($subQuery) {
  2456. $subQuery->whereNotNull('article_ignore.article_id')
  2457. ->where('article_ignore.is_ignore', 0)
  2458. ->where(function ($subSubQuery) {
  2459. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2460. ->orWhereNull('article_ignore.c_show_time');
  2461. });
  2462. });
  2463. })
  2464. ->select(
  2465. 'article.id',
  2466. 'article.title',
  2467. 'article.imgurl',
  2468. 'article.author',
  2469. 'article.updated_at',
  2470. 'article.introduce',
  2471. 'article.islink',
  2472. 'article.linkurl',
  2473. 'article.copyfrom',
  2474. 'article.cat_arr_id',
  2475. 'article.catid as category_id'
  2476. )
  2477. ->orderBy('updated_at', 'desc')
  2478. ->limit($article_imgnum)
  2479. ->get()->all();
  2480. foreach ($img_article as $k => $v) {
  2481. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2482. // return Result::success($v);
  2483. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2484. }
  2485. } else {
  2486. $img_article = [];
  2487. }
  2488. if ($article_textnum != 0) {
  2489. $text_article = Article::whereIn('article.catid', $category_arr)
  2490. ->where('article.status', 1)
  2491. ->leftJoinSub(function ($query) use ($website_id) {
  2492. $query->from('article_ignore')
  2493. ->where('website_id', $website_id);
  2494. }, 'article_ignore', function ($join) {
  2495. $join->on('article_ignore.article_id', '=', 'article.id');
  2496. })
  2497. ->where(function ($query) {
  2498. $query->whereNull('article_ignore.article_id')
  2499. ->orWhere(function ($subQuery) {
  2500. $subQuery->whereNotNull('article_ignore.article_id')
  2501. ->where('article_ignore.is_ignore', 0)
  2502. ->where(function ($subSubQuery) {
  2503. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2504. ->orWhereNull('article_ignore.c_show_time');
  2505. });
  2506. });
  2507. })
  2508. ->select(
  2509. 'article.id',
  2510. 'article.title',
  2511. 'article.author',
  2512. 'article.updated_at',
  2513. 'article.introduce',
  2514. 'article.islink',
  2515. 'article.linkurl',
  2516. 'article.copyfrom',
  2517. 'article.cat_arr_id',
  2518. 'article.catid as category_id'
  2519. )
  2520. ->orderBy('updated_at', 'desc')
  2521. ->limit($article_textnum)
  2522. ->get()->all();
  2523. foreach ($text_article as $k => $v) {
  2524. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2525. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2526. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2527. }
  2528. } else {
  2529. $text_article = [];
  2530. }
  2531. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2532. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2533. $parent[$key] = $catiall[$parent_category];
  2534. } else {
  2535. $parent[$key] = [];
  2536. }
  2537. }
  2538. }
  2539. return Result::success($parent);
  2540. }
  2541. // 封装处理商品的路由问题
  2542. function processGoods($goods, $data)
  2543. {
  2544. return $goods->map(function ($good) use ($data) {
  2545. $catid = $good->catid ?? 0;
  2546. // $pinyin = '';
  2547. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2548. if (!empty($category->pid) && $category->pid != 0) {
  2549. $level = json_decode($category->category_arr_id, true);
  2550. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2551. ->whereIn('category_id', $level)
  2552. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2553. ->get(['aLIas_pinyin'])
  2554. ->pluck('aLIas_pinyin')
  2555. ->implode('/');
  2556. } else {
  2557. $pinyin = $category->aLIas_pinyin ?? '';
  2558. }
  2559. if (isset($good->city_id) && !empty($good->city_id)) {
  2560. $city = District::where('id', $good->city_id)->first(['name']);
  2561. $good->city_name = $city->name ?? '';
  2562. }
  2563. // 解析imgurl JSON并取第一条数据
  2564. $imgUrls = json_decode($good->imgurl, true);
  2565. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2566. $good->pinyin = $pinyin;
  2567. return $good;
  2568. });
  2569. }
  2570. /**
  2571. * 获取商城首页-根据栏目id
  2572. * @param array $data
  2573. * @return array
  2574. * */
  2575. function getWebsiteCatidshop(array $data): array
  2576. {
  2577. $input['catid'] = $data['catid'];
  2578. $input['website_id'] = $data['website_id'];
  2579. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2580. $result = array_map(function ($item) use ($input) {
  2581. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2582. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2583. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2584. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2585. if (empty($category) || $category->type != 2) {
  2586. return Result::error("暂无此栏目", 0);
  2587. } else {
  2588. $website['website_id'] = $input['website_id'];
  2589. $goods = Good::where('good.status', 2)
  2590. ->where('good.website_id', $website['website_id'])
  2591. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2592. ->select(
  2593. 'good.id',
  2594. 'good.name',
  2595. 'good.imgurl',
  2596. 'good.description',
  2597. 'good.updated_at',
  2598. 'good.catid',
  2599. 'good.type_id',
  2600. 'good.price',
  2601. 'good.com',
  2602. 'good.level',
  2603. 'good.unit'
  2604. )
  2605. ->orderBy('updated_at', 'desc')
  2606. ->offset($goodStart)
  2607. ->limit($goodNum);
  2608. $all_goods = $goods->get();
  2609. $all_goods = $this->processGoods($all_goods, $website);
  2610. }
  2611. return $all_goods ?? [];
  2612. }
  2613. }, $data);
  2614. return Result::success($result);
  2615. }
  2616. /**
  2617. * 获取商品模块
  2618. * @param array $data
  2619. * @return array
  2620. * */
  2621. public function getWebsiteshop(array $data): array
  2622. {
  2623. $input['id'] = $data['id'];
  2624. $input['website_id'] = $data['website_id'];
  2625. $catid = $data['catid'];
  2626. $data = json_decode($input['id'] ?? '', true) ?? [];
  2627. $result['goods'] = array_map(function ($item) use ($input) {
  2628. // 检查parent元素是否存在且不是undefined
  2629. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2630. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2631. $website = $input['website_id'];
  2632. $query = Good::where('good.status', 2)
  2633. ->where('good.website_id', $website);
  2634. switch ($Levelid) {
  2635. case 1:
  2636. case 2:
  2637. case 3:
  2638. $goods = $query->where(function ($q) use ($Levelid) {
  2639. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2640. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2641. });
  2642. break;
  2643. case 4:
  2644. $goods = $query;
  2645. break;
  2646. case 5:
  2647. $goods = $query->where('type_id', 1);
  2648. break;
  2649. case 6:
  2650. $goods = $query->where('type_id', 2);
  2651. break;
  2652. default:
  2653. return [];
  2654. }
  2655. $all_goods = $goods
  2656. ->select(
  2657. 'good.id',
  2658. 'good.name',
  2659. 'good.imgurl',
  2660. 'good.description',
  2661. 'good.updated_at',
  2662. 'good.catid',
  2663. 'good.type_id',
  2664. 'good.price',
  2665. 'good.level',
  2666. 'good.website_id'
  2667. )
  2668. ->orderBy('updated_at', 'desc')
  2669. ->offset($goodStart)
  2670. ->limit($goodNum)
  2671. ->get();
  2672. $web['website_id'] = $website;
  2673. $all_goods = $this->processGoods($all_goods, $web);
  2674. }
  2675. return $all_goods;
  2676. }, $data);
  2677. $website = $input['website_id'];
  2678. $result['article'] = Article::where(function ($query) use ($website) {
  2679. $query->where(function ($subQuery) use ($website) {
  2680. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2681. })->orWhereNull("ignore_ids");
  2682. })
  2683. ->where('catid', $catid)
  2684. ->where('article.status', 1)
  2685. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2686. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2687. ->orderBy('article.updated_at', 'desc')
  2688. ->first();
  2689. return Result::success($result);
  2690. }
  2691. /**
  2692. * 获取商品分类
  2693. * @param array $data
  2694. * @return array
  2695. * */
  2696. public function getWebsiteshopCat(array $data): array
  2697. {
  2698. $website = $data['website_id'];
  2699. $category = WebsiteCategory::where('website_id', $website)
  2700. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2701. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2702. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2703. ->orderBy('sort')
  2704. ->get();
  2705. $cat = $category->map(function ($item) use ($website) {
  2706. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2707. $pid = $item->pid ?? 0;
  2708. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2709. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2710. ->where('website_id', $website)
  2711. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2712. ->get(['aLIas_pinyin'])
  2713. ->pluck('aLIas_pinyin')
  2714. ->implode('/');
  2715. } else {
  2716. $pinyin = $item->aLIas_pinyin ?? '';
  2717. }
  2718. $item->pinyin = $pinyin;
  2719. });
  2720. if (empty($category)) {
  2721. return Result::error("栏目查询失败", 0);
  2722. }
  2723. $cat_tree = Result::buildMenuTree($category);
  2724. $web['website_id'] = $website;
  2725. $goods = Good::where('website_id', $website)
  2726. ->where('status', 2)
  2727. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2728. ->latest('updated_at')
  2729. ->offset(($data['page'] - 1) * $data['pageSize'])
  2730. ->limit($data['pageSize'])
  2731. ->get();
  2732. if (!empty($goods)) {
  2733. if ($goods->count() > 1 && !empty($goods)) {
  2734. $goods = $this->processGoods($goods, $web);
  2735. }
  2736. } else {
  2737. $goods = [];
  2738. }
  2739. $result = [
  2740. 'category' => $cat_tree,
  2741. 'goods' => $goods,
  2742. ];
  2743. // $resul['goods'] = $goods;
  2744. if (empty($result)) {
  2745. return Result::error("查询失败", 0);
  2746. }
  2747. return Result::success($result);
  2748. }
  2749. /*
  2750. * 获取商品列表
  2751. * @param array $data
  2752. * @return array
  2753. * */
  2754. public function getWebsiteshopList(array $data): array
  2755. {
  2756. // return Result::success($data);
  2757. $where = [
  2758. 'status' => 2,
  2759. 'website_id' => $data['website_id'],
  2760. ];
  2761. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2762. // return Result::error("查询失败", 0);
  2763. // }
  2764. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2765. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2766. $data['catid'] = $category->category_id ?? 0;
  2767. }
  2768. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2769. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2770. }
  2771. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2772. array_push($where, ['type_id', $data['type_id']]);
  2773. }
  2774. $query = Good::where($where)
  2775. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2776. $query->where(function ($q) use ($data) {
  2777. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2778. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2779. });
  2780. })
  2781. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2782. $query->where(function ($q) use ($data) {
  2783. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2784. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2785. });
  2786. })
  2787. ->select(
  2788. 'good.id',
  2789. 'good.name',
  2790. 'good.imgurl',
  2791. 'good.description',
  2792. 'good.updated_at',
  2793. 'good.com',
  2794. 'good.catid',
  2795. 'good.type_id',
  2796. 'good.website_id',
  2797. 'good.cat_arr_id',
  2798. 'good.created_at',
  2799. 'good.city_id'
  2800. )
  2801. ->latest('updated_at');
  2802. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2803. $result['count'] = $query->clone()->count();
  2804. $result['goods'] = $this->processGoods(
  2805. $query->clone()
  2806. ->offset(($data['page'] - 1) * $data['pageSize'])
  2807. ->limit($data['pageSize'])
  2808. ->get(),
  2809. $data
  2810. );
  2811. } else {
  2812. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2813. // 获取 type_id 为 1 的数据
  2814. $result['type1'] = $this->processGoods(
  2815. $query->clone()
  2816. ->where('type_id', 1)
  2817. ->offset(($data['page'] - 1) * $data['pageSize'])
  2818. ->limit($data['pageSize'])
  2819. ->get(),
  2820. $data
  2821. );
  2822. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2823. // 获取 type_id 为 2 的数据
  2824. $result['type2'] = $this->processGoods(
  2825. $query->clone()
  2826. ->where('type_id', 2)
  2827. ->offset(($data['page'] - 1) * $data['pageSize'])
  2828. ->limit($data['pageSize'])
  2829. ->get(),
  2830. $data
  2831. );
  2832. }
  2833. if (empty($result)) {
  2834. return Result::error("查询失败", 0);
  2835. }
  2836. return Result::success($result);
  2837. }
  2838. /**
  2839. * 获取商品详情
  2840. * @param array $data
  2841. * @return array
  2842. * */
  2843. public function getWebsiteshopInfo(array $data): array
  2844. {
  2845. $where = [
  2846. 'good.status' => 2,
  2847. 'good.website_id' => $data['website_id'],
  2848. 'good.id' => $data['id'],
  2849. ];
  2850. $goods = Good::where($where)
  2851. ->where('good.id', $data['id'])
  2852. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2853. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2854. ->first();
  2855. if (empty($goods)) {
  2856. return Result::error("查询失败", 0);
  2857. }
  2858. $goods->imgurl = json_decode($goods->imgurl, true);
  2859. return Result::success($goods);
  2860. }
  2861. /**
  2862. * plus pro 处理文章路由问题
  2863. */
  2864. function processArticlePro($website_id)
  2865. {
  2866. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2867. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2868. // // 取出category_id 对应的aLIas_pinyin
  2869. // $categoryIds = array_column($categorys, 'category_id');
  2870. // $categoryPIds = array_column($categorys, 'pid');
  2871. // $aliasPinyins = array_column($categorys, 'path');
  2872. // $alias = array_column($categorys, 'alias');
  2873. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2874. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2875. // // return Result::success($cat_arr);
  2876. // // $catiall = [];
  2877. // //一级所有子级的记录
  2878. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2879. // return [
  2880. // 'cat_1st_arr' => $cat_alias_arr,
  2881. // 'catiall' => $cat_arr,
  2882. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2883. // 'categoryIds' => $categoryIds,
  2884. // ];
  2885. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2886. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2887. // 取出category_id 对应的aLIas_pinyin
  2888. $categoryIds = array_column($categorys, 'category_id');
  2889. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2890. return $pid != 0;
  2891. })));
  2892. $category_path = array_column($categorys, 'path');
  2893. $cat_arr = array_combine($categoryIds, $category_path);
  2894. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2895. $catiall = [];
  2896. //一级所有子级的记录
  2897. $cat_1st_arr = [];
  2898. foreach ($categorys as $key => $value) {
  2899. // $category_arr_id = json_decode($value->category_arr_id);
  2900. // $pinyin_str = '';
  2901. // // 算出一级 并且算出子级
  2902. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2903. $cat_1st_arr[$value->pid][] = $value->category_id;
  2904. }
  2905. // foreach ($category_arr_id as $k => $v) {
  2906. // $pinyin_str .= $cat_arr[$v] . '/';
  2907. // }
  2908. // $pinyin_str = rtrim($pinyin_str, '/');
  2909. $catiall[$value->category_id]['alias'] = $value->alias;
  2910. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2911. $catiall[$value->category_id]['type'] = $value->type;
  2912. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2913. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2914. }
  2915. return [
  2916. 'cat_1st_arr' => $cat_1st_arr,
  2917. 'catiall' => $catiall,
  2918. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2919. 'categoryIds' => $categoryIds,
  2920. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2921. 'categoryPIds' => $categoryPIds,
  2922. ];
  2923. }
  2924. /**
  2925. * 封装处理文章的路由问题
  2926. * */
  2927. function processArticles($articles, $data)
  2928. {
  2929. // 检查 $articles 是否为数组或可迭代对象
  2930. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2931. return $articles->map(function ($article) use ($data) {
  2932. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2933. $catid = $article->cat_arr_id ?? '';
  2934. }
  2935. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2936. $catid = $article->category_arr_id ?? '';
  2937. }
  2938. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2939. $level = json_decode($catid, true);
  2940. if (!is_array($level)) {
  2941. return $article;
  2942. } else {
  2943. $level = array_map('intval', $level);
  2944. }
  2945. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2946. ->where($data)
  2947. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2948. ->pluck('aLIas_pinyin')
  2949. ->implode('/');
  2950. $article->pinyin = $pinyin ?? '';
  2951. return $article;
  2952. });
  2953. } else {
  2954. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2955. $catid = $articles->cat_arr_id ?? '';
  2956. $level = json_decode($catid, true);
  2957. if (!is_array($level)) {
  2958. return $articles;
  2959. } else {
  2960. $level = array_map('intval', $level);
  2961. }
  2962. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2963. ->where($data)
  2964. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2965. ->pluck('aLIas_pinyin')
  2966. ->implode('/');
  2967. $articles->pinyin = $pinyin ?? '';
  2968. return $articles;
  2969. }
  2970. }
  2971. // 封装处理由问题
  2972. function processJob($job, $data)
  2973. {
  2974. return $job->map(function ($job) use ($data) {
  2975. $category = $job->cat_arr_id ?? '';
  2976. $cityid = $job->city_arr_id ?? '';
  2977. $city = json_decode($cityid, true);
  2978. $pinyin = '';
  2979. $level = json_decode($category, true);
  2980. // 路由
  2981. if (!empty($level) && is_array($level)) {
  2982. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2983. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2984. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2985. ->get(['aLIas_pinyin'])
  2986. ->pluck('aLIas_pinyin')
  2987. ->implode('/');
  2988. if (empty($pinyin)) {
  2989. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2990. }
  2991. $job->pinyin = $pinyin;
  2992. }
  2993. // 取职位-城市 市??省
  2994. if (!empty($city) && is_array($city)) {
  2995. if (isset($city[1]) && !empty($city[1])) {
  2996. $city = District::where('id', $city[1])->first(['name']);
  2997. $job->city_name = $city->name ?? '';
  2998. } else if (isset($city[0]) && !empty($city[0])) {
  2999. $city = District::where('id', $city[0])->first(['name']);
  3000. $job->city_name = $city->name ?? '';
  3001. } else {
  3002. $job->city_name = '全国';
  3003. }
  3004. }
  3005. // 获取简历最后一级地区
  3006. if (isset($job->city_id) && !empty($job->city_id)) {
  3007. $city = District::where('id', $job->city_id)->first(['name']);
  3008. $job->hunt_cityname = $city->name ?? '';
  3009. }
  3010. // 组合详细地址
  3011. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3012. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3013. if (is_array($address_id) && !empty($address_id)) {
  3014. $address = District::whereIn('id', $address_id)
  3015. ->orderBy('level', 'asc')
  3016. ->get(['name'])
  3017. ->pluck('name')
  3018. ->implode('');
  3019. // $job->address_name = $address ?? '';
  3020. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3021. }
  3022. }
  3023. // 取行业
  3024. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3025. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3026. if (!empty($job->industry)) {
  3027. $query->where('hyid', $job->industry);
  3028. } else if (!empty($job->hy_id)) {
  3029. $query->where('hyid', $job->hy_id);
  3030. } else if (!empty($job->company_hy_id)) {
  3031. $query->where('hyid', $job->company_hy_id);
  3032. } else {
  3033. $query->where('hyid', $job->job_industry);
  3034. }
  3035. })->first(['hyname']);
  3036. $job->hy_name = $hy_name->hyname ?? '';
  3037. }
  3038. // 取职位类别
  3039. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3040. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3041. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3042. $job->zw_name = $zw_name->zwname ?? '';
  3043. }
  3044. // 取具体职位
  3045. 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))) {
  3046. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3047. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3048. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3049. }
  3050. // 取工作经验
  3051. if (isset($job->experience) && !empty($job->experience)) {
  3052. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3053. $job->experience_name = $experience->ename ?? '';
  3054. }
  3055. // 取学历
  3056. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3057. $education = $job->educational ?? $job->school_education;
  3058. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3059. $job->education_name = $education->ename ?? '';
  3060. }
  3061. // 语言
  3062. if (isset($job->language) && !empty($job->language)) {
  3063. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3064. $job->language_name = $language->ename ?? '';
  3065. }
  3066. // 薪资
  3067. if (isset($job->salary) && !empty($job->salary)) {
  3068. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3069. $job->salary_name = $salary->ename ?? '';
  3070. }
  3071. // 职位性质
  3072. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3073. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3074. $job->job_nature_name = $job_nature->ename ?? '';
  3075. }
  3076. // 公司规模
  3077. if (isset($job->company_size) && !empty($job->company_size)) {
  3078. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3079. $job->company_size_name = $company_size->ename ?? '';
  3080. }
  3081. // 公司性质
  3082. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3083. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3084. $job->company_nature_name = $company_nature->nature_name ?? '';
  3085. }
  3086. // $job->pinyin = $pinyin;
  3087. return $job;
  3088. });
  3089. }
  3090. /**
  3091. * 获取书籍模块
  3092. * @param array $data
  3093. * @return array
  3094. * */
  3095. public function getWebsiteBook(array $data): array
  3096. {
  3097. $input['id'] = $data['id'];
  3098. $input['website_id'] = $data['website_id'];
  3099. // 将 JSON 字符串转换为 PHP 数组
  3100. $data = json_decode($input['id'], true);
  3101. // 使用 array_map 处理每个元素
  3102. $result = array_map(function ($item) use ($input) {
  3103. // 检查parent元素是否存在且不是undefined
  3104. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3105. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3106. $website = [
  3107. 'website_id' => $input['website_id'],
  3108. ];
  3109. // 查询栏目名称
  3110. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3111. if (empty($category)) {
  3112. $parent_alias = '';
  3113. $parent_pinyin = null;
  3114. $imgBooks = [];
  3115. $textBooks = [];
  3116. } else {
  3117. $parent_alias = $category->alias ?? '';
  3118. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3119. // 查找子分类ID数组
  3120. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3121. array_push($childCategoryIds, $parentCatId);
  3122. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3123. if ($parentImgNum != 0) {
  3124. // 查询图片新闻
  3125. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3126. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3127. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3128. })
  3129. ->where('book.status', 2)
  3130. ->where('book.img_url', '!=', '')
  3131. ->where('book.website_id', $website['website_id'])
  3132. ->leftJoin('website_category', function ($join) use ($website) {
  3133. $join->on('book.cat_id', '=', 'website_category.category_id')
  3134. ->where('website_category.website_id', '=', $website['website_id']);
  3135. })
  3136. ->select(
  3137. 'book.id',
  3138. 'book.title',
  3139. 'book.img_url',
  3140. 'book.price',
  3141. 'book.market_price',
  3142. 'book.description',
  3143. 'book.cat_id',
  3144. 'book.description',
  3145. 'book.updated_at',
  3146. 'website_category.alias as category_name',
  3147. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3148. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3149. )
  3150. ->orderBy('updated_at', 'desc')
  3151. ->limit($parentImgNum)
  3152. ->get()->all();
  3153. // 查询文字新闻
  3154. }
  3155. if ($parentTextNum != 0) {
  3156. $textBooks = [];
  3157. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3158. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3159. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3160. })
  3161. ->where('book.status', 2)
  3162. ->where('book.website_id', $website['website_id'])
  3163. ->leftJoin('website_category', function ($join) use ($website) {
  3164. $join->on('book.cat_id', '=', 'website_category.category_id')
  3165. ->where('website_category.website_id', '=', $website['website_id']);
  3166. })
  3167. ->select(
  3168. 'book.id',
  3169. 'book.title',
  3170. 'book.img_url',
  3171. 'book.price',
  3172. 'book.market_price',
  3173. 'book.description',
  3174. 'book.cat_id',
  3175. 'book.description',
  3176. 'book.updated_at',
  3177. 'website_category.alias as category_name',
  3178. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3179. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3180. )
  3181. ->orderBy('updated_at', 'desc')
  3182. ->limit($parentTextNum)
  3183. ->get()->all();
  3184. }
  3185. }
  3186. }
  3187. $resultItem = [
  3188. 'alias' => $parent_alias ?? '',
  3189. 'category_id' => $parentCatId ?? 0,
  3190. 'pinyin' => $parent_pinyin ?? null,
  3191. 'imgnum' => $imgBooks ?? [],
  3192. 'textnum' => $textBooks ?? [],
  3193. ];
  3194. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3195. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3196. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3197. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3198. ->get()->all();
  3199. if (!empty($childCategory)) {
  3200. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3201. // 查询子栏目名称
  3202. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3203. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3204. ->first();
  3205. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3206. $childImgArticles = [];
  3207. $childTextArticles = [];
  3208. $resultItem['child'] = [];
  3209. } else {
  3210. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3211. // 查询子栏目图片新闻
  3212. $childImgArticles = Book::where('cat_id', $childCatId)
  3213. ->where('status', 2)
  3214. ->where('img_url', '!=', '')
  3215. ->where('book.website_id', $website['website_id'])
  3216. ->leftJoin('website_category', function ($join) use ($website) {
  3217. $join->on('book.cat_id', '=', 'website_category.category_id')
  3218. ->where('website_category.website_id', '=', $website['website_id']);
  3219. })
  3220. ->select(
  3221. 'book.id',
  3222. 'book.title',
  3223. 'book.img_url',
  3224. 'book.price',
  3225. 'book.market_price',
  3226. 'book.description',
  3227. 'book.cat_id',
  3228. 'book.description',
  3229. 'book.updated_at',
  3230. DB::raw("'$child_pinyin' as pinyin")
  3231. )
  3232. ->orderBy('updated_at', 'desc')
  3233. ->limit($childImgNum)
  3234. ->get()->all();
  3235. // 查询子栏目文字新闻
  3236. $childTextArticles = Book::where('cat_id', $childCatId)
  3237. ->where('status', 2)
  3238. ->where('book.website_id', $website['website_id'])
  3239. ->leftJoin('website_category', function ($join) use ($website) {
  3240. $join->on('book.cat_id', '=', 'website_category.category_id')
  3241. ->where('website_category.website_id', '=', $website['website_id']);
  3242. })
  3243. ->select(
  3244. 'book.id',
  3245. 'book.title',
  3246. 'book.img_url',
  3247. 'book.price',
  3248. 'book.market_price',
  3249. 'book.description',
  3250. 'book.cat_id',
  3251. 'book.description',
  3252. 'book.updated_at',
  3253. DB::raw("'$child_pinyin' as pinyin")
  3254. )
  3255. ->orderBy('updated_at', 'desc')
  3256. ->limit($childTextNum)
  3257. ->get()->all();
  3258. $resultItem['child'] = [
  3259. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3260. 'category_id' => $childCatId,
  3261. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3262. 'all_childcat' => $childCategory,
  3263. 'imgnum' => $childImgArticles,
  3264. 'textnum' => $childTextArticles,
  3265. ];
  3266. }
  3267. }
  3268. } else {
  3269. $resultItem['child'] = [];
  3270. }
  3271. return $resultItem;
  3272. }, $data);
  3273. return Result::success($result);
  3274. }
  3275. /**
  3276. * 获取书刊列表
  3277. * @param array $data
  3278. * @return array
  3279. * */
  3280. public function getWebsiteBookList(array $data): array
  3281. {
  3282. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3283. if (empty($web)) {
  3284. return Result::error("查询失败", 0);
  3285. }
  3286. $catid = $data['id'];
  3287. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3288. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3289. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3290. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3291. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3292. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3293. ->where('pid', $category['pid'])
  3294. ->select(
  3295. 'category_id',
  3296. 'alias',
  3297. 'aLIas_pinyin',
  3298. 'pid',
  3299. 'sort',
  3300. 'is_url',
  3301. 'web_url',
  3302. 'seo_title',
  3303. 'seo_keywords',
  3304. 'seo_description',
  3305. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3306. )
  3307. ->orderBy('sort')
  3308. ->get()->all();
  3309. if (empty($category)) {
  3310. return Result::error("查询失败", 0);
  3311. }
  3312. $query = Book::where('book.status', 2)
  3313. ->where('book.website_id', $data['website_id'])
  3314. ->where('book.cat_id', $catid)
  3315. ->select(
  3316. 'book.id',
  3317. 'book.title',
  3318. 'book.img_url',
  3319. 'book.description',
  3320. 'book.updated_at',
  3321. 'book.cat_id',
  3322. DB::raw("'$pinyin' as pinyin")
  3323. )
  3324. ->orderBy('book.updated_at', 'desc');
  3325. $count = $query->count();
  3326. $query = clone $query;
  3327. $Book = $query
  3328. ->limit($data['pageSize'])
  3329. ->offset(($data['page'] - 1) * $data['pageSize'])
  3330. ->get()->all();
  3331. $result = [
  3332. 'category' => $categorys,
  3333. 'books' => $Book,
  3334. 'count' => $count,
  3335. ];
  3336. // if(empty($result)){
  3337. // return Result::error("查询失败", 0);
  3338. // }
  3339. return Result::success($result);
  3340. }
  3341. /**
  3342. * 获取书刊详情
  3343. * @param array $data
  3344. * @return array
  3345. * */
  3346. public function getWebsiteBookInfo(array $data): array
  3347. {
  3348. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3349. if (empty($web)) {
  3350. return Result::error("查询失败", 0);
  3351. }
  3352. $book = Book::where('status', 2)
  3353. ->where('website_id', $data['website_id'])
  3354. ->where('id', $data['id'])
  3355. ->select(
  3356. 'book.*',
  3357. )
  3358. ->orderBy('updated_at', 'desc')
  3359. ->first();
  3360. if (empty($book)) {
  3361. return Result::error("查询失败", 0);
  3362. }
  3363. // 先查询当前分类的 pid
  3364. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3365. ->where('category_id', $book['cat_id'])
  3366. ->first(['pid', 'category_id']);
  3367. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3368. if (!empty($carpid)) {
  3369. if ($carpid->pid != 0) {
  3370. $pid = $carpid['pid'];
  3371. // $parent_pinyin = '';
  3372. } else {
  3373. $pid = $carpid['category_id'];
  3374. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3375. }
  3376. }
  3377. $categorys = $query->where('pid', $pid)
  3378. ->select(
  3379. 'category_id',
  3380. 'alias',
  3381. 'aLIas_pinyin',
  3382. 'pid',
  3383. 'sort',
  3384. 'is_url',
  3385. 'web_url',
  3386. 'category_arr_id as cat_arr_id',
  3387. )
  3388. ->orderBy('sort')
  3389. ->get();
  3390. $category = $this->processArticle($categorys, $data);
  3391. $result = [
  3392. 'category' => $category,
  3393. 'books' => $book,
  3394. ];
  3395. return Result::success($result);
  3396. }
  3397. /**
  3398. * 尝试
  3399. * @param array $data
  3400. * @return array
  3401. * */
  3402. public function test(array $data): array
  3403. {
  3404. $input['id'] = $data['id'];
  3405. $input['website_id'] = $data['website_id'];
  3406. // 将 JSON 字符串转换为 PHP 数组
  3407. $data = json_decode($input['id'], true);
  3408. $result = [];
  3409. $article = $data;
  3410. $result = array_map(function ($item) use ($input) {
  3411. $website = [
  3412. 'website_id' => $input['website_id'],
  3413. ];
  3414. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3415. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3416. $parent = [
  3417. 0 => $category['category_id'] ?? [],
  3418. 1 => $parentImgNum ?? [],
  3419. 2 => $parentTextNum ?? [],
  3420. ];
  3421. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3422. $child = [];
  3423. $resultItem = [
  3424. // 'alias' => $parent_alias ?? '',
  3425. 'category_id' => $parentCatId ?? 0,
  3426. 'pinyin' => $parentImgNum ?? null,
  3427. 'imgnum' => $parentTextNum ?? [],
  3428. // 'textnum' => $textArticles ?? [],
  3429. ];
  3430. return $parent;
  3431. }, $data);
  3432. return Result::success($result);
  3433. // });
  3434. }
  3435. /**
  3436. * 封装处理文章的路由问题
  3437. * */
  3438. function processArticle($article, $data)
  3439. {
  3440. return $article->map(function ($article) use ($data) {
  3441. $catid = $article->cat_arr_id ?? '';
  3442. $level = json_decode($catid, true);
  3443. $pinyin = '';
  3444. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3445. if (!empty($level) && is_array($level)) {
  3446. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3447. ->where('website_id', $data['website_id'])
  3448. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3449. ->get(['aLIas_pinyin'])
  3450. ->pluck('aLIas_pinyin')
  3451. ->implode('/');
  3452. } else {
  3453. $pinyin = '';
  3454. }
  3455. $article->pinyin = $pinyin;
  3456. return $article;
  3457. });
  3458. }
  3459. /**
  3460. * c端-获取招工招聘下拉选框
  3461. * @param array $data
  3462. * @return array
  3463. * */
  3464. public function getWebsiteJobSelect(array $data): array
  3465. {
  3466. $web = Website::where('id', $data['website_id'])->first();
  3467. if (empty($web)) {
  3468. return Result::error("该网站不存在", 0);
  3469. }
  3470. $hy = JobIndustry::get()->all();
  3471. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3472. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3473. $result = [
  3474. 'hy' => $hy,
  3475. 'zw' => $zw,
  3476. 'jtzw' => $jtzw,
  3477. ];
  3478. if (empty($result)) {
  3479. return Result::error("查询失败", 0);
  3480. }
  3481. return Result::success($result);
  3482. }
  3483. /**
  3484. * c端-获取招工招聘
  3485. * @param array $data
  3486. * @return array
  3487. * */
  3488. public function getWebsiteJob(array $data): array
  3489. {
  3490. $web = Website::where('id', $data['website_id'])->first();
  3491. if (empty($web)) {
  3492. return Result::error("该网站不存在", 0);
  3493. }
  3494. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3495. ->where('job_hunting.website_id', $data['website_id'])
  3496. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3497. $query->where(function ($q) use ($data) {
  3498. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3499. });
  3500. })
  3501. ->select(
  3502. 'job_hunting.id',
  3503. 'job_hunting.catid',
  3504. 'job_hunting.cat_arr_id',
  3505. 'job_hunting.job_name_get',
  3506. 'job_hunting.industry',
  3507. 'job_hunting.name',
  3508. 'job_hunting.sexy',
  3509. 'job_hunting.origin',
  3510. 'job_hunting.city_arr_id',
  3511. 'job_hunting.experience',
  3512. 'job_hunting.updated_at',
  3513. 'job_hunting.salary',
  3514. 'job_hunting.skillList',
  3515. 'job_hunting.slelf_evaluation',
  3516. )
  3517. ->orderBy('updated_at', 'desc')
  3518. ->limit($data['job1_num'])
  3519. ->get();
  3520. $web['website_id'] = $data['website_id'];
  3521. if (empty($job_hunting)) {
  3522. $job_huntings = "未查询到相关简历信息";
  3523. } else {
  3524. $job_huntings = $this->processJob($job_hunting, $web);
  3525. }
  3526. // 0:待审核 1:已通过 2:已拒绝
  3527. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3528. ->where('job_recruiting.website_id', $data['website_id'])
  3529. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3530. $query->where(function ($q) use ($data) {
  3531. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3532. });
  3533. })
  3534. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3535. ->select(
  3536. 'job_recruiting.id',
  3537. 'job_recruiting.catid',
  3538. 'job_recruiting.cat_arr_id',
  3539. 'job_recruiting.title',
  3540. 'job_recruiting.jtzw_id',
  3541. 'job_recruiting.hy_id',
  3542. 'job_recruiting.city_arr_id',
  3543. 'job_recruiting.due_data',
  3544. 'job_recruiting.updated_at',
  3545. 'job_recruiting.experience',
  3546. 'job_recruiting.educational',
  3547. 'job_recruiting.salary',
  3548. 'job_recruiting.zw_id',
  3549. 'job_company.business_name',
  3550. 'job_recruiting.keyword',
  3551. 'job_recruiting.description',
  3552. )
  3553. ->orderBy('updated_at', 'desc')
  3554. ->limit($data['job2_num'])
  3555. ->get();
  3556. if (empty($job_recruiting->toArray())) {
  3557. $job_recruitings = "未查询到相关职位信息";
  3558. } else {
  3559. $job_recruitings = $this->processJob($job_recruiting, $web);
  3560. }
  3561. $result = [
  3562. 'job_hunting' => $job_huntings,
  3563. 'job_recuiting' => $job_recruitings,
  3564. ];
  3565. return Result::success($result);
  3566. }
  3567. /**
  3568. * c端-获取招工招聘列表
  3569. * @param array $data
  3570. * @return array
  3571. * */
  3572. public function getWebsiteJobList(array $data): array
  3573. {
  3574. $recruit_where = [];
  3575. $hunt_where = [];
  3576. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3577. if (empty($web)) {
  3578. return Result::error("此网站不存在", 0);
  3579. }
  3580. $website_id['website_id'] = $data['website_id'];
  3581. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3582. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3583. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3584. }
  3585. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3586. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3587. }
  3588. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3589. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3590. }
  3591. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3592. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3593. }
  3594. $query = JobRecruiting::where('job_recruiting.status', 1)
  3595. ->where('job_recruiting.website_id', $data['website_id'])
  3596. ->where($recruit_where)
  3597. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3598. $query->where(function ($q) use ($data) {
  3599. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3600. });
  3601. })
  3602. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3603. $query->where(function ($q) use ($data) {
  3604. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3605. });
  3606. })
  3607. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3608. ->select(
  3609. 'job_recruiting.id',
  3610. 'job_recruiting.catid',
  3611. 'job_recruiting.hy_id',
  3612. 'job_recruiting.title',
  3613. 'job_recruiting.zw_id',
  3614. 'job_recruiting.educational',
  3615. 'job_recruiting.jtzw_id',
  3616. 'job_recruiting.city_arr_id',
  3617. 'job_recruiting.due_data',
  3618. 'job_recruiting.experience',
  3619. 'job_recruiting.cat_arr_id',
  3620. 'job_recruiting.updated_at',
  3621. 'job_company.business_name',
  3622. 'job_recruiting.keyword',
  3623. 'job_recruiting.description',
  3624. )
  3625. ->orderBy('job_recruiting.updated_at', 'desc');
  3626. $recruit_count = $query->count();
  3627. $query = clone $query;
  3628. $JobRecruiting = $query
  3629. ->offset(($data['page'] - 1) * $data['pageSize'])
  3630. ->limit($data['pageSize'])
  3631. ->get();
  3632. if (empty($JobRecruiting)) {
  3633. $JobRecruiting = "暂无相关职位信息";
  3634. } else {
  3635. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3636. }
  3637. }
  3638. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3639. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3640. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3641. }
  3642. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3643. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3644. }
  3645. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3646. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3647. }
  3648. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3649. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3650. }
  3651. $query = JobHunting::where('job_hunting.status', 2)
  3652. ->where('job_hunting.website_id', $data['website_id'])
  3653. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3654. ->where($hunt_where)
  3655. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3656. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3657. // })
  3658. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3659. $query->where(function ($q) use ($data) {
  3660. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3661. });
  3662. })
  3663. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3664. $query->where(function ($q) use ($data) {
  3665. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3666. });
  3667. })
  3668. ->select(
  3669. 'job_hunting.id',
  3670. 'job_hunting.catid',
  3671. 'job_hunting.sexy',
  3672. 'job_hunting.experience',
  3673. 'job_hunting.origin',
  3674. 'job_hunting.industry',
  3675. 'job_hunting.name',
  3676. 'job_hunting.job',
  3677. 'job_hunting.job_name_get',
  3678. 'job_hunting.city_arr_id',
  3679. 'job_hunting.cat_arr_id',
  3680. 'job_hunting.created_at',
  3681. 'job_hunting.updated_at',
  3682. 'job_position.zwname as job_name',
  3683. 'job_hunting.skillList',
  3684. 'job_hunting.slelf_evaluation',
  3685. )
  3686. ->orderBy('job_hunting.updated_at', 'desc');
  3687. $hunt_count = $query->count();
  3688. $query = clone $query;
  3689. $JobHunting = $query
  3690. ->offset(($data['page'] - 1) * $data['pageSize'])
  3691. ->limit($data['pageSize'])
  3692. ->get();
  3693. if (empty($JobHunting)) {
  3694. $JobRecruiting = "暂无相关简历信息";
  3695. } else {
  3696. $JobHunting = $this->processJob($JobHunting, $website_id);
  3697. }
  3698. }
  3699. $result = [
  3700. 'JobRecruiting' => $JobRecruiting ?? [],
  3701. 'recruit_count' => $recruit_count ?? 0,
  3702. 'JobHunting' => $JobHunting ?? [],
  3703. 'hunt_count' => $hunt_count ?? 0,
  3704. ];
  3705. return Result::success($result);
  3706. }
  3707. /**
  3708. * c端-获取招工招聘详情
  3709. * @param array $data
  3710. * @return array
  3711. * */
  3712. public function getWebsiteJobInfo(array $data): array
  3713. {
  3714. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3715. if (empty($web)) {
  3716. return Result::error("该网站不存在", 0);
  3717. }
  3718. $webid = [
  3719. 'website_id' => $data['website_id'],
  3720. ];
  3721. // 职位相关信息
  3722. if ($data['type'] == 1) {
  3723. $query = JobRecruiting::where('status', 1)
  3724. ->where('website_id', $data['website_id'])
  3725. ->select('*');
  3726. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3727. $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();
  3728. if (!empty($company)) {
  3729. $result['company'] = $this->processJob($company, $webid);
  3730. }
  3731. $other_job = JobRecruiting::where('status', 1)
  3732. ->where('website_id', $data['website_id'])
  3733. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3734. ->where('id', '!=', $data['id'])
  3735. ->where('user_id', '=', $job[0]['user_id'])
  3736. ->limit($data['pageSize'])
  3737. ->get();
  3738. if (!empty($other_job)) {
  3739. $result['other_job'] = $this->processJob($other_job, $webid);
  3740. }
  3741. } else {
  3742. // 简历相关信息
  3743. $job = JobHunting::where('job_hunting.status', 2)
  3744. ->where('job_hunting.website_id', $data['website_id'])
  3745. ->where('job_hunting.id', $data['id'])
  3746. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3747. ->select('job_hunting.*', 'user_name')
  3748. ->get();
  3749. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3750. if (!empty($resume->toArray())) {
  3751. $result['resume'] = 1;
  3752. } else {
  3753. $result['resume'] = 0;
  3754. }
  3755. }
  3756. if (empty($job->toArray())) {
  3757. return Result::error("id参数错误", 0);
  3758. }
  3759. if (!empty($job[0]['job_experience'])) {
  3760. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3761. if (!empty($job_experience)) {
  3762. // $hy = [];
  3763. foreach ($job_experience as $key => $value) {
  3764. // $id = $value['id'];
  3765. $hy[$key] = $value['job_industry'];
  3766. $zw_id[$key] = $value['job_typename'];
  3767. $jtzw_id[$key] = $value['job_name'];
  3768. }
  3769. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3770. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3771. // 先将关联表转换为索引数组,提高查找效率
  3772. $hyLookup = [];
  3773. foreach ($hy_table as $item) {
  3774. $hyLookup[$item['hyid']] = $item['hyname'];
  3775. }
  3776. $zwLookup = [];
  3777. foreach ($zw_table as $item) {
  3778. $zwLookup[$item['zwid']] = $item['zwname'];
  3779. }
  3780. foreach ($job_experience as $key => &$value) {
  3781. // 处理行业名称
  3782. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3783. $value['hy_name'] = $hyLookup[$hy[$key]];
  3784. }
  3785. // 处理职位名称
  3786. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3787. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3788. }
  3789. // 处理具体职位名称
  3790. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3791. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3792. }
  3793. }
  3794. // 释放引用,防止意外修改后续代码
  3795. unset($value);
  3796. }
  3797. $result['job_experience'] = $job_experience ?? [];
  3798. }
  3799. if (!empty($job[0]['education_experience'])) {
  3800. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3801. if (!empty($education_experience)) {
  3802. foreach ($education_experience as $key => $value) {
  3803. // $id = $value['id'];
  3804. $education[$key] = $value['school_education'];
  3805. }
  3806. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3807. // // 先将关联表转换为索引数组,提高查找效率
  3808. $educationLookup = [];
  3809. foreach ($education_table as $item) {
  3810. $educationLookup[$item['evalue']] = $item['ename'];
  3811. }
  3812. foreach ($education_experience as $key => &$value) {
  3813. // 处理学历名称
  3814. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3815. $value['education_name'] = $educationLookup[$education[$key]];
  3816. }
  3817. }
  3818. }
  3819. $result['education_experience'] = $job_experience ?? [];
  3820. }
  3821. $result['job'] = $this->processJob($job, $webid);
  3822. // // 返现对应的栏目
  3823. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3824. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3825. ->whereIn('category_id', $catid)
  3826. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3827. ->orderBy('pid')->get()->all();
  3828. if (!empty($category)) {
  3829. $result['category'] = $category;
  3830. }
  3831. $result['job'] = $job;
  3832. $result['job_experience'] = $job_experience ?? [];
  3833. $result['education_experience'] = $education_experience ?? [];
  3834. if (empty($result)) {
  3835. return Result::error("参数错误", 0);
  3836. }
  3837. return Result::success($result);
  3838. }
  3839. /**
  3840. * c端-申请职位
  3841. * @param array $data
  3842. * @return array
  3843. * */
  3844. public function getWebsiteJobApply(array $data): array
  3845. {
  3846. // 首先验证网站是否存在
  3847. // return Result::success($data);
  3848. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3849. if (empty($web)) {
  3850. return Result::error("该网站不存在", 0);
  3851. }
  3852. // 验证用户是否存在且为个人会员/管理员
  3853. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3854. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3855. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3856. return Result::error("用户不存在", 0);
  3857. }
  3858. // 去除重复元素和空元素,并保持原始顺序
  3859. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3860. return !empty($value);
  3861. }));
  3862. // 验证职位是否存在 1:审核通过
  3863. $recruiting = JobRecruiting::where('status', 1)
  3864. ->where('website_id', $data['website_id'])
  3865. ->whereIn('id', $data['recruit_id'])
  3866. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3867. if (empty($recruiting)) {
  3868. return Result::error("该职位不存在", 0);
  3869. }
  3870. // 简历是否存在
  3871. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3872. if (empty($hunt_id)) {
  3873. return Result::error("该简历不存在", 0);
  3874. }
  3875. $data['hunt_id'] = $hunt_id['hunt_id'];
  3876. // // 验证是否已投递过该职位
  3877. $apply = JobApply::where('user_id', $data['user_id'])
  3878. ->where('hunt_id', $data['hunt_id'])
  3879. ->where('website_id', $data['website_id'])
  3880. ->whereIn('recruit_id', $data['recruit_id'])
  3881. ->get(['recruit_id']);
  3882. if (!empty($apply->toArray())) {
  3883. return Result::error("您已投递过该职位!");
  3884. }
  3885. $insertData = array_map(function ($recruiting) use ($data) {
  3886. return [
  3887. 'user_id' => $data['user_id'],
  3888. 'hunt_id' => $data['hunt_id'],
  3889. 'website_id' => $data['website_id'],
  3890. 'recruit_id' => $recruiting['recruit_id'],
  3891. 'receiver_id' => $recruiting['receiver_id'],
  3892. 'status' => 1,
  3893. ];
  3894. }, $recruiting);
  3895. // 批量插入数据
  3896. $result = JobApply::insert($insertData);
  3897. if (empty($result)) {
  3898. return Result::error("投递失败", 0);
  3899. }
  3900. return Result::success($result);
  3901. }
  3902. /**
  3903. * 招工招聘-沟通简历
  3904. * @param array $data
  3905. * @return array
  3906. * */
  3907. public function getWebsiteJobResume(array $data): array
  3908. {
  3909. // 首先验证网站是否存在
  3910. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3911. if (empty($web)) {
  3912. return Result::error("该网站不存在", 0);
  3913. }
  3914. // return Result::success($data);
  3915. // 验证用户是否存在且为企业会员/管理员
  3916. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3917. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3918. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3919. return Result::error("用户不存在", 0);
  3920. }
  3921. // 去除重复元素和空元素,并保持原始顺序
  3922. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3923. return !empty($value);
  3924. }));
  3925. // 验证简历是否存在
  3926. $hunting = JobHunting::where('status', 2)
  3927. ->where('website_id', $data['website_id'])
  3928. ->whereIn('id', $data['hunt_id'])
  3929. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3930. if (empty($hunting)) {
  3931. return Result::error("该简历不存在", 0);
  3932. }
  3933. // 验证是否已沟通过该简历
  3934. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3935. ->where('recruit_id', $data['recruit_id'])
  3936. ->where('website_id', $data['website_id'])
  3937. ->whereIn('hunt_id', $data['hunt_id'])
  3938. ->get(['hunt_id']);
  3939. if (!empty($remuse->toArray())) {
  3940. return Result::error("您已沟通过该简历!");
  3941. }
  3942. // 准备要插入的数据数组
  3943. $insertData = array_map(function ($hunting) use ($data) {
  3944. return [
  3945. 'user_id' => $data['user_id'],
  3946. 'recruit_id' => $data['recruit_id'],
  3947. 'website_id' => $data['website_id'],
  3948. 'hunt_id' => $hunting['hunt_id'],
  3949. 'receiver_id' => $hunting['receiver_id'],
  3950. 'status' => 1,
  3951. ];
  3952. }, $hunting);
  3953. // 批量插入数据
  3954. $result = JobRemuse::insert($insertData);
  3955. if (empty($result)) {
  3956. return Result::error("沟通失败", 0);
  3957. }
  3958. return Result::success($result);
  3959. }
  3960. /**
  3961. * 招工招聘 -我的职位(企业会员)
  3962. * @param array $data
  3963. * @return array
  3964. */
  3965. public function getWebsiteJobRecruiting(array $data): array
  3966. {
  3967. $web = Website::where('id', $data['website_id'])->first('id');
  3968. if (empty($web)) {
  3969. return Result::error("该网站不存在", 0);
  3970. }
  3971. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3972. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3973. return Result::error("用户暂无权限!", 0);
  3974. }
  3975. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3976. $result = JobRecruiting::where('website_id', $data['website_id'])
  3977. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3978. $query->where('user_id', $user['id']);
  3979. })
  3980. ->where('status', 1)
  3981. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3982. ->orderBy('updated_at', 'desc')
  3983. ->limit($data['pageSize'])
  3984. ->get();
  3985. if (empty($result)) {
  3986. return Result::error("暂无相关职位信息", 0);
  3987. }
  3988. return Result::success($result);
  3989. }
  3990. /**
  3991. * c端 - 验证路由
  3992. * @param array $data
  3993. * @return array
  3994. */
  3995. /**
  3996. * c端 - 验证路由
  3997. * @param array $data
  3998. * @return array
  3999. */
  4000. public function checkWebsiteRoute(array $data): array
  4001. {
  4002. // 测试001111111222
  4003. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  4004. if (empty($web)) {
  4005. return Result::error("该网站不存在", 0);
  4006. } elseif ($web['status'] != 1) {
  4007. return Result::error("网站已经关闭", 0);
  4008. }
  4009. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4010. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4011. // 验证路由是否存在
  4012. if (empty($whiteRouterInfo)) {
  4013. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4014. }
  4015. if (!empty($whiteRouterInfo)) {
  4016. return Result::success($whiteRouterInfo->toArray());
  4017. }
  4018. }
  4019. // 验证栏目路由
  4020. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4021. ->where('path', $data['all_route'])
  4022. ->get()->all();
  4023. if (count($last_category) == 0) {
  4024. return Result::error("该栏目不存在", 0);
  4025. }
  4026. if (count($last_category) > 1) {
  4027. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4028. }
  4029. if (count($last_category) == 1) {
  4030. $last_category = $last_category[0];
  4031. }
  4032. // return Result::success($last_category);
  4033. if (isset($data['id']) && !empty($data['id'])) {
  4034. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4035. switch ($last_category['type']) {
  4036. case 1:
  4037. // 文章
  4038. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4039. $article = Article::where('status', 1)
  4040. ->where('id', $data['id'])
  4041. ->where(function ($query) use ($data) {
  4042. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4043. ->orWhereNull("ignore_ids");
  4044. })
  4045. ->first(['catid']);
  4046. if (empty($article)) {
  4047. return Result::error("该文章不存在", 0);
  4048. }
  4049. // return Result::success($article);
  4050. break;
  4051. case 2:
  4052. // 商品
  4053. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4054. $article = Good::where('website_id', $data['website_id'])
  4055. ->where('status', 2)
  4056. ->where('id', $data['id'])
  4057. ->first(['cat_arr_id']);
  4058. if (empty($article)) {
  4059. return Result::error("该商品不存在", 0);
  4060. }
  4061. break;
  4062. case 3:
  4063. // 书刊信息
  4064. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4065. $article = Book::where('website_id', $data['website_id'])
  4066. ->where('status', 2)
  4067. ->where('id', $data['id'])
  4068. ->first(['id', 'cat_arr_id']);
  4069. if (empty($article)) {
  4070. return Result::error("该书刊不存在", 0);
  4071. }
  4072. break;
  4073. case 4:
  4074. // 招聘
  4075. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4076. $article = JobRecruiting::where('website_id', $data['website_id'])
  4077. ->where('status', 1)
  4078. ->where('id', $data['id'])
  4079. ->first(['cat_arr_id']);
  4080. if (empty($article)) {
  4081. return Result::error("该招聘不存在", 0);
  4082. }
  4083. break;
  4084. case 5:
  4085. // 求职
  4086. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4087. $article = JobHunting::where('website_id', $data['website_id'])
  4088. ->where('status', 2)
  4089. ->where('id', $data['id'])
  4090. ->first(['cat_arr_id']);
  4091. if (empty($article)) {
  4092. return Result::error("该求职不存在", 0);
  4093. }
  4094. break;
  4095. case 6:
  4096. // 企业
  4097. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4098. $article = Company::
  4099. // where('website_id', $data['website_id'])
  4100. // ->
  4101. where('status', 1)
  4102. ->where('id', $data['id'])
  4103. ->first(['cat_arr_id']);
  4104. if (empty($article)) {
  4105. return Result::error("该企业不存在", 0);
  4106. }
  4107. break;
  4108. case 7:
  4109. // 项目
  4110. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4111. $article = Project::where('website_id', $data['website_id'])
  4112. ->where('status', 1)
  4113. ->where('id', $data['id'])
  4114. ->first(['cat_arr_id']);
  4115. if (empty($article)) {
  4116. return Result::error("该项目不存在", 0);
  4117. }
  4118. break;
  4119. default:
  4120. return Result::error("该数据不存在", 0);
  4121. break;
  4122. }
  4123. // return Result::success($article);
  4124. // $catid =0 ;
  4125. if (!isset($article['cat_arr_id'])) {
  4126. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4127. } else {
  4128. $catidArray = json_decode($article['cat_arr_id'], true);
  4129. $catid = !empty($catidArray) ? end($catidArray) : null;
  4130. }
  4131. // return Result::success($catid);
  4132. // // return Result::success($article['cat_arr_id']);
  4133. if (empty($catid)) {
  4134. return Result::error("该栏目路径不存在", 0);
  4135. }
  4136. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4137. ->where('category_id', $catid)
  4138. ->first('path');
  4139. }
  4140. // else{
  4141. // // if ($last_category['pid'] != 0) {
  4142. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4143. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4144. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4145. // ->where('category_id',$catid)
  4146. // ->where('path',$data['all_route'])
  4147. // ->first('path');
  4148. // // } else {
  4149. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4150. // // }
  4151. // }
  4152. // return Result::success($path);
  4153. if (!empty($path) && $path['path'] != $data['all_route']) {
  4154. return Result::error('非法路径!');
  4155. } else {
  4156. return Result::success($last_category['path']);
  4157. }
  4158. }
  4159. /**
  4160. * 招工招聘 - 获取推荐职位
  4161. * @param array $data
  4162. * @return array
  4163. */
  4164. public function getWebsiteLevelJob(array $data): array
  4165. {
  4166. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4167. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4168. ->where('job_recruiting.status', 1)
  4169. ->where('job_level', $data['job_level'])
  4170. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4171. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4172. ->orderBy('job_recruiting.updated_at', 'desc')
  4173. ->limit($data['pageSize'])
  4174. ->get();
  4175. $web = ['website_id' => $data['website_id']];
  4176. if (!empty($job)) {
  4177. $result = $this->processJob($job, $web);
  4178. }
  4179. if (empty($result)) {
  4180. return Result::error("暂无相关职位信息", 0);
  4181. }
  4182. return Result::success($result);
  4183. }
  4184. /**
  4185. * 验证导航名称是否重复
  4186. * @return void
  4187. */
  4188. //20250226 产品列表
  4189. public function getGoodList(array $data): array
  4190. {
  4191. var_dump($data, '---------1-2--');
  4192. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4193. unset($data['user_type_id']);
  4194. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4195. $where = [];
  4196. if ($type_id != '10000') {
  4197. $where = [
  4198. 'good.user_id' => $user_id,
  4199. ];
  4200. }
  4201. //类型
  4202. if (isset($data['type_id']) && $data['type_id']) {
  4203. $where['good.type_id'] = $data['type_id'];
  4204. }
  4205. //名称
  4206. if (isset($data['name']) && $data['name']) {
  4207. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4208. }
  4209. //status
  4210. if (isset($data['status']) && $data['status'] != '') {
  4211. $where['good.status'] = $data['status'];
  4212. }
  4213. //status1
  4214. // if (isset($data['status1']) && $data['status1'] == 1) {
  4215. // $status1 = 1;
  4216. // }
  4217. $where1 = [];
  4218. //website_id
  4219. // if (isset($data['website_id']) && $data['website_id']) {
  4220. // $where1 = [
  4221. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4222. // ];
  4223. // }
  4224. // website_name
  4225. if (isset($data['website_name']) && $data['website_name']) {
  4226. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4227. }
  4228. // catid
  4229. if (isset($data['category_name']) && $data['category_name']) {
  4230. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4231. }
  4232. // $result = Good::where($where)
  4233. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4234. var_dump($where, '---------1---');
  4235. $result = Good::where($where)
  4236. ->when(!empty($where1), function ($query) use ($where1) {
  4237. return $query->where($where1);
  4238. })
  4239. //status 1待审核2已审核3已拒绝
  4240. ->when(isset($data['status1']), function ($query) {
  4241. return $query->whereIn('good.status', [1, 3]);
  4242. })
  4243. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4244. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4245. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4246. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4247. ->orderBy("updated_at", "desc")
  4248. ->limit($data['page_size'])
  4249. ->offset(($data['page'] - 1) * $data['page_size'])
  4250. ->get();
  4251. $count = Good::where($where)
  4252. ->when(!empty($where1), function ($query) use ($where1) {
  4253. return $query->where($where1);
  4254. })
  4255. //status 1待审核2已审核3已拒绝
  4256. ->when(isset($data['status1']), function ($query) {
  4257. return $query->whereIn('good.status', [1, 3]);
  4258. })
  4259. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4260. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4261. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4262. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4263. ->orderBy("updated_at", "desc")->count();
  4264. $data = [
  4265. 'rows' => $result->toArray(),
  4266. 'count' => $count,
  4267. ];
  4268. if (empty($result)) {
  4269. return Result::error("此栏目暂无相关产品", 0);
  4270. }
  4271. return Result::success($data);
  4272. }
  4273. public function getGoodInfo(array $data): array
  4274. {
  4275. $result = Good::where('id', $data['id'])->first();
  4276. if (empty($result)) {
  4277. return Result::error("此产品不存在", 0);
  4278. }
  4279. return Result::success($result);
  4280. }
  4281. public function addGood(array $data): array
  4282. {
  4283. // unset($data['city_arr_id']);
  4284. // unset($data['cat_arr_id']);
  4285. $data['city_id'] = end($data['city_arr_id']);
  4286. $data['catid'] = end($data['cat_arr_id']);
  4287. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4288. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4289. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4290. unset($data['imgUrl']); //大小写
  4291. if (isset($data['price']) && $data['price'] == '') {
  4292. $data['price'] = 0;
  4293. }
  4294. if ($data['imgurl'] == '') {
  4295. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4296. preg_match_all($reg, $data['detail'], $matches);
  4297. if (isset($matches[1][0])) {
  4298. //截取varchar240
  4299. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4300. }
  4301. }
  4302. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4303. //提取标题+内容中的关键词
  4304. $data['keyword'] = $data['name'];
  4305. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4306. Jieba::init(); // 初始化 jieba-php
  4307. Finalseg::init();
  4308. $segList = Jieba::cut($data['keyword']);
  4309. $segList1 = array_slice($segList, 0, 8);
  4310. $data['keyword'] = implode(',', $segList1);
  4311. }
  4312. if ($data['description'] == '') {
  4313. //提取内容中的描述
  4314. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4315. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4316. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4317. }
  4318. if ($data['status'] == 1) {
  4319. $this->sendMessage([
  4320. 'talk_type' => 200,
  4321. 'title' => $data['name'],
  4322. 'content' => '提交了审核',
  4323. 'messageType' => 3,
  4324. ]);
  4325. }
  4326. $result = Good::insert($data);
  4327. if (empty($result)) {
  4328. return Result::error("添加失败", 0);
  4329. }
  4330. return Result::success($result);
  4331. }
  4332. public function updateGood(array $data): array
  4333. {
  4334. $data['city_id'] = end($data['city_arr_id']);
  4335. $data['catid'] = end($data['cat_arr_id']);
  4336. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4337. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4338. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4339. //设置东八区
  4340. date_default_timezone_set('Asia/Shanghai');
  4341. $data['updated_at'] = date('Y-m-d H:i:s');
  4342. if (isset($data['price']) && $data['price'] == '') {
  4343. $data['price'] = 0;
  4344. }
  4345. if ($data['imgurl'] == '') {
  4346. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4347. preg_match_all($reg, $data['detail'], $matches);
  4348. if (isset($matches[1][0])) {
  4349. //截取varchar240
  4350. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4351. }
  4352. }
  4353. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4354. //提取标题+内容中的关键词
  4355. $data['keyword'] = $data['name'];
  4356. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4357. Jieba::init(); // 初始化 jieba-php
  4358. Finalseg::init();
  4359. $segList = Jieba::cut($data['keyword']);
  4360. $segList1 = array_slice($segList, 0, 8);
  4361. $data['keyword'] = implode(',', $segList1);
  4362. }
  4363. if ($data['description'] == '') {
  4364. //提取内容中的描述
  4365. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4366. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4367. }
  4368. if ($data['status'] == 1) {
  4369. $this->sendMessage([
  4370. 'talk_type' => 200,
  4371. 'title' => $data['name'],
  4372. 'content' => '提交了审核',
  4373. 'messageType' => 3,
  4374. ]);
  4375. }
  4376. $result = Good::where('id', $data['id'])->update($data);
  4377. if (empty($result)) {
  4378. return Result::error("更新失败", 0);
  4379. }
  4380. return Result::success($result);
  4381. }
  4382. public function delGood(array $data): array
  4383. {
  4384. $result = Good::where('id', $data['id'])->delete();
  4385. if (empty($result)) {
  4386. return Result::error("删除失败", 0);
  4387. }
  4388. return Result::success($result);
  4389. }
  4390. //20250226 产品列表
  4391. //20250306 求职信息
  4392. public function getJobHuntingList(array $data): array
  4393. {
  4394. $where = [];
  4395. if (isset($data['username']) && !empty($data['username'])) {
  4396. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4397. }
  4398. //status 1待审核2已审核3已拒绝
  4399. if (isset($data['status']) && $data['status'] != '') {
  4400. $where = [
  4401. 'job_hunting.status' => $data['status'],
  4402. ];
  4403. }
  4404. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4405. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4406. unset($data['type_id']);
  4407. if ($type_id != '10000') {
  4408. $where[] = ['job_hunting.user_id', '=', $user_id];
  4409. }
  4410. $result = JobHunting::where($where)
  4411. ->when(!empty($data['status1']), function ($query) use ($data) {
  4412. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4413. })
  4414. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4415. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4416. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4417. ->orderBy("updated_at", "desc")
  4418. ->limit($data['page_size'])
  4419. ->offset(($data['page'] - 1) * $data['page_size'])
  4420. ->get();
  4421. if (empty($result)) {
  4422. return Result::error("查询失败", 0);
  4423. }
  4424. $count = JobHunting::where($where)
  4425. ->when(!empty($data['status1']), function ($query) use ($data) {
  4426. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4427. })
  4428. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4429. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4430. ->count();
  4431. $data = [
  4432. 'rows' => $result->toArray(),
  4433. 'count' => $count,
  4434. ];
  4435. return Result::success($data);
  4436. }
  4437. public function getJobHuntingApply(array $data): array
  4438. {
  4439. var_dump($data, '-----------------test--------1-');
  4440. $where = [];
  4441. if (isset($data['username']) && !empty($data['username'])) {
  4442. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4443. }
  4444. if (isset($data['salary']) && !empty($data['salary'])) {
  4445. $where[] = [
  4446. 'job_hunting.salary',
  4447. '=',
  4448. $data['salary'],
  4449. ];
  4450. }
  4451. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4452. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4453. unset($data['type_id']);
  4454. if ($type_id != '10000') {
  4455. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4456. }
  4457. var_dump($where, '-----------------test---------');
  4458. $result = jobApply::where($where)
  4459. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4460. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4461. // })
  4462. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4463. ->where('job_enum.egroup', '=', 'income')
  4464. ->where('job_hunting.status', 2) //已审核
  4465. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4466. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4467. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4468. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4469. //职位----是申请职位
  4470. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4471. ->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')
  4472. ->orderBy("job_hunting.updated_at", "desc")
  4473. ->limit($data['page_size'])
  4474. ->offset(($data['page'] - 1) * $data['page_size'])
  4475. ->get();
  4476. if (empty($result)) {
  4477. return Result::error("查询失败", 0);
  4478. }
  4479. $count = jobApply::where($where)
  4480. ->where('job_enum.egroup', '=', 'income')
  4481. ->where('job_hunting.status', 2) //已审核
  4482. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4483. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4484. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4485. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4486. //职位----是申请职位
  4487. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4488. ->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')
  4489. ->count();
  4490. $data = [
  4491. 'rows' => $result->toArray(),
  4492. 'count' => $count,
  4493. ];
  4494. return Result::success($data);
  4495. }
  4496. public function addJobHunting(array $data): array
  4497. {
  4498. date_default_timezone_set('Asia/Shanghai');
  4499. unset($data['company_name']);
  4500. unset($data['job_industry']);
  4501. unset($data['job_name']);
  4502. unset($data['department']);
  4503. unset($data['job_timeList']);
  4504. unset($data['job_content']);
  4505. unset($data['job_typename']); //不知道这是啥,
  4506. $data['created_at'] = date('Y-m-d H:i:s');
  4507. $data['updated_at'] = date('Y-m-d H:i:s');
  4508. //根据用户 user_id 只能添加一次
  4509. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4510. if (!empty($result)) {
  4511. return Result::error("您已添加过求职信息", 0);
  4512. }
  4513. var_dump($result, '-----------------test---------');
  4514. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4515. if (is_string($data['city_arr_id'])) {
  4516. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4517. $cityArr = json_decode($data['city_arr_id'], true);
  4518. // 确保 $cityArr 是数组
  4519. if (is_array($cityArr)) {
  4520. $data['city_id'] = end($cityArr);
  4521. }
  4522. } else {
  4523. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4524. if (is_array($data['city_arr_id'])) {
  4525. $data['city_id'] = end($data['city_arr_id']);
  4526. }
  4527. }
  4528. }
  4529. // 处理求职所绑定栏目
  4530. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4531. if (is_string($data['cat_arr_id'])) {
  4532. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4533. // 先清理可能存在的无效 JSON 字符
  4534. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4535. $catArr = json_decode($cleanedCatArrStr, true);
  4536. // 检查 JSON 解码是否成功且结果是数组
  4537. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4538. $data['catid'] = end($catArr);
  4539. }
  4540. } else {
  4541. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4542. if (is_array($data['cat_arr_id'])) {
  4543. $data['catid'] = end($data['cat_arr_id']);
  4544. }
  4545. }
  4546. }
  4547. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4548. $this->sendMessage([
  4549. 'talk_type' => 600,
  4550. 'title' => $data['name'],
  4551. 'content' => '提交了审核',
  4552. 'messageType' => 11,
  4553. ]);
  4554. }
  4555. $result = JobHunting::create($data);
  4556. if (empty($result)) {
  4557. return Result::error("添加失败", 0);
  4558. }
  4559. return Result::success($result);
  4560. }
  4561. public function delJobHunting(array $data): array
  4562. {
  4563. $result = JobHunting::where('id', $data['id'])->delete();
  4564. if (empty($result)) {
  4565. return Result::error("删除失败", 0);
  4566. }
  4567. return Result::success($result);
  4568. }
  4569. public function updateJobHunting(array $data): array
  4570. {
  4571. //设置东八区
  4572. date_default_timezone_set('Asia/Shanghai');
  4573. unset($data['company_name']);
  4574. unset($data['job_industry']);
  4575. unset($data['job_name']);
  4576. unset($data['department']);
  4577. unset($data['job_timeList']);
  4578. unset($data['job_content']);
  4579. unset($data['job_typename']); //不知道这是啥,
  4580. $data['created_at'] = date('Y-m-d H:i:s');
  4581. $data['updated_at'] = date('Y-m-d H:i:s');
  4582. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4583. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4584. $cityArr = json_decode($data['city_arr_id'], true);
  4585. $data['city_id'] = end($cityArr);
  4586. } else {
  4587. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4588. $data['city_id'] = end($data['city_arr_id']);
  4589. }
  4590. // 处理求职所绑定栏目
  4591. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4592. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4593. $catArr = json_decode($data['cat_arr_id'], true);
  4594. $data['catid'] = end($catArr);
  4595. } else {
  4596. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4597. $data['catid'] = end($data['cat_arr_id']);
  4598. }
  4599. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4600. $this->sendMessage([
  4601. 'talk_type' => 600,
  4602. 'title' => $data['name'],
  4603. 'content' => '提交了审核',
  4604. 'messageType' => 11,
  4605. ]);
  4606. }
  4607. $result = JobHunting::where('id', $data['id'])->update($data);
  4608. if (empty($result)) {
  4609. return Result::error("更新失败", 0);
  4610. }
  4611. return Result::success($result);
  4612. }
  4613. public function getJobHuntingInfo(array $data): array
  4614. {
  4615. $result = JobHunting::where('id', $data['id'])->first();
  4616. if (empty($result)) {
  4617. return Result::error("查询失败", 0);
  4618. }
  4619. return Result::success($result);
  4620. }
  4621. public function getJobHuntingData(array $data): array
  4622. {
  4623. $jobEnum = JobEnum::get();
  4624. $jobIndustry = JobIndustry::get();
  4625. $jobNature = JobNature::get();
  4626. $jobPosition = JobPosition::get();
  4627. $data = [
  4628. 'jobEnum' => $jobEnum,
  4629. 'jobIndustry' => $jobIndustry,
  4630. 'jobNature' => $jobNature,
  4631. 'jobPosition' => $jobPosition,
  4632. ];
  4633. return Result::success($data);
  4634. }
  4635. public function delJobHuntingInfo(array $data): array
  4636. {
  4637. $result = JobHunting::where('id', $data['id'])->delete();
  4638. return Result::success();
  4639. }
  4640. //20250324 通知,公告,消息
  4641. public function delNotice(array $data): array
  4642. {
  4643. $result = Notice::where('id', $data['id'])->delete();
  4644. if ($result) {
  4645. return Result::success();
  4646. } else {
  4647. return Result::error("删除失败", 0);
  4648. }
  4649. }
  4650. public function getNoticeInfo(array $data): array
  4651. {
  4652. $result = Notice::where('id', $data['id'])->first();
  4653. // var_dump($result['re_user_ids'], '--------------------');
  4654. if (empty($result)) {
  4655. return Result::error("查询失败", 0);
  4656. }
  4657. return Result::success($result);
  4658. }
  4659. public function readNotice(array $data): array
  4660. {
  4661. $result = Notice::where('id', $data['id'])->first();
  4662. // var_dump($result['re_user_ids'], '--------------------');
  4663. if (empty($result)) {
  4664. return Result::error("查询失败", 0);
  4665. }
  4666. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4667. $re_user_ids = json_decode($result['re_user_ids'], true);
  4668. var_dump($re_user_ids, '--------------1---test---------');
  4669. var_dump($data, '--------------1---test---------');
  4670. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4671. //如果已经存在,就不再添加
  4672. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4673. $read_id = json_decode($result['read_id'], true);
  4674. if (!is_array($read_id)) {
  4675. $read_id = [];
  4676. }
  4677. if (!in_array($data['user_id'], $read_id)) {
  4678. $read_id[] = $data['user_id'];
  4679. $result['read_id'] = json_encode($read_id);
  4680. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4681. }
  4682. } else {
  4683. //如果不存在,就添加
  4684. $result['read_id'] = json_encode([$data['user_id']]);
  4685. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4686. }
  4687. }
  4688. return Result::success($result);
  4689. }
  4690. public function addNotice(array $data): array
  4691. {
  4692. date_default_timezone_set('Asia/Shanghai');
  4693. $data['created_at'] = date('Y-m-d H:i:s');
  4694. $data['updated_at'] = date('Y-m-d H:i:s');
  4695. // $data['level'] = "1,2,3,4,5";
  4696. $level = json_decode($data['level'], true);
  4697. $user_id = UserInfo::
  4698. //city_id不是null
  4699. whereNotNull('city_id')
  4700. ->whereNotNull('department_id')
  4701. ->where(function ($query) use ($data) {
  4702. $query->where(function ($subQuery) use ($data) {
  4703. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4704. });
  4705. })
  4706. ->where(function ($query) use ($data) {
  4707. $query->where(function ($subQuery) use ($data) {
  4708. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4709. });
  4710. })
  4711. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4712. $query->whereIn('level', $level);
  4713. })
  4714. ->pluck('user_id')->toArray();
  4715. $user_id = array_unique($user_id);
  4716. $chat_ids = $user_id;
  4717. $user_id = json_encode($user_id);
  4718. $data['re_user_ids'] = $user_id;
  4719. $this->sendMessage([
  4720. 'talk_type' => 700,
  4721. 'title' => $data['title'],
  4722. 'content' => '提交了审核',
  4723. 'messageType' => 5,
  4724. ]);
  4725. $result = Notice::insertGetId($data);
  4726. if (empty($result)) {
  4727. return Result::error("添加失败", 0);
  4728. }
  4729. return Result::success($result);
  4730. }
  4731. public function updateNotice(array $data): array
  4732. {
  4733. date_default_timezone_set('Asia/Shanghai');
  4734. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4735. $user_id = UserInfo::
  4736. //city_id不是null
  4737. whereNotNull('city_id')
  4738. ->whereNotNull('department_id')
  4739. ->where(function ($query) use ($data) {
  4740. $query->where(function ($subQuery) use ($data) {
  4741. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4742. });
  4743. })
  4744. ->where(function ($query) use ($data) {
  4745. $query->where(function ($subQuery) use ($data) {
  4746. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4747. });
  4748. })
  4749. ->pluck('user_id')->toArray();
  4750. $user_id = array_unique($user_id);
  4751. $user_id = json_encode($user_id);
  4752. $data['re_user_ids'] = $user_id;
  4753. $data['updated_at'] = date('Y-m-d H:i:s');
  4754. $this->sendMessage([
  4755. 'talk_type' => 700,
  4756. 'title' => $data['title'],
  4757. 'content' => '提交了审核',
  4758. 'messageType' => 5,
  4759. ]);
  4760. $result = Notice::where('id', $data['id'])->update($data);
  4761. return Result::success($result);
  4762. }
  4763. public function getNoticeList(array $data): array
  4764. {
  4765. $where = [];
  4766. //title
  4767. if (isset($data['title']) && !empty($data['title'])) {
  4768. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4769. }
  4770. //level
  4771. if (isset($data['level']) && !empty($data['level'])) {
  4772. $where[] = ['notice.level', '=', $data['level']];
  4773. }
  4774. //status
  4775. if (isset($data['status']) && !empty($data['status'])) {
  4776. $where[] = ['notice.status', '=', $data['status']];
  4777. }
  4778. //type
  4779. if (isset($data['type']) && !empty($data['type'])) {
  4780. $where[] = ['notice.type', '=', $data['type']];
  4781. }
  4782. var_dump($data, '------------11111-2----test---------');
  4783. if ($data['type_id'] == 10000) {
  4784. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4785. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4786. })
  4787. ->where($where)
  4788. ->orderBy('updated_at', 'desc')
  4789. ->limit($data['page_size'])
  4790. ->offset(($data['page'] - 1) * $data['page_size'])
  4791. ->get();
  4792. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4793. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4794. })
  4795. ->where($where)
  4796. ->orderBy('updated_at', 'desc')
  4797. ->count();
  4798. } else {
  4799. $result = Notice::where($where)
  4800. // ->where('user_id', $data['user_id'])
  4801. ->Where(function ($query) use ($data) {
  4802. $query->Where(function ($q) use ($data) {
  4803. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4804. ->orWhere('notice.user_id', $data['user_id']);
  4805. });
  4806. })
  4807. ->when(!empty($data['status1']), function ($query) use ($data) {
  4808. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4809. })
  4810. ->orderBy('updated_at', 'desc')
  4811. ->limit($data['page_size'])
  4812. ->offset(($data['page'] - 1) * $data['page_size'])
  4813. ->get();
  4814. $total = Notice::where($where)
  4815. ->when(!empty($data['status1']), function ($query) use ($data) {
  4816. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4817. })
  4818. // ->where('user_id', $data['user_id'])
  4819. ->Where(function ($query) use ($data) {
  4820. $query->Where(function ($q) use ($data) {
  4821. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4822. ->orWhere('notice.user_id', $data['user_id']);
  4823. });
  4824. })
  4825. ->count();
  4826. }
  4827. if (empty($result)) {
  4828. return Result::error("查询失败", 0);
  4829. }
  4830. $data = [
  4831. 'rows' => $result,
  4832. 'count' => $total,
  4833. ];
  4834. return Result::success($data);
  4835. }
  4836. public function noticeList(array $data): array
  4837. {
  4838. $where = [];
  4839. //title
  4840. if (isset($data['title']) && !empty($data['title'])) {
  4841. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4842. }
  4843. //level
  4844. if (isset($data['level']) && !empty($data['level'])) {
  4845. $where[] = ['notice.level', '=', $data['level']];
  4846. }
  4847. //status
  4848. if (isset($data['status']) && !empty($data['status'])) {
  4849. $where[] = ['notice.status', '=', $data['status']];
  4850. }
  4851. //type
  4852. if (isset($data['type']) && !empty($data['type'])) {
  4853. $where[] = ['notice.type', '=', $data['type']];
  4854. }
  4855. var_dump($data, '------------11111-2----test---------');
  4856. if ($data['type_id'] == 10000) {
  4857. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4858. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4859. })
  4860. ->where($where)
  4861. ->orderBy('updated_at', 'desc')
  4862. ->limit($data['page_size'])
  4863. ->offset(($data['page'] - 1) * $data['page_size'])
  4864. ->get();
  4865. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4866. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4867. })
  4868. ->where($where)
  4869. ->orderBy('updated_at', 'desc')
  4870. ->count();
  4871. } else {
  4872. $result = Notice::where($where)
  4873. // ->where('user_id', $data['user_id'])
  4874. ->Where(function ($query) use ($data) {
  4875. $query->Where(function ($q) use ($data) {
  4876. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4877. ->orWhere('notice.user_id', $data['user_id']);
  4878. });
  4879. })
  4880. ->when(!empty($data['status1']), function ($query) use ($data) {
  4881. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4882. })
  4883. ->orderBy('updated_at', 'desc')
  4884. ->limit($data['page_size'])
  4885. ->offset(($data['page'] - 1) * $data['page_size'])
  4886. ->get();
  4887. $total = Notice::where($where)
  4888. ->when(!empty($data['status1']), function ($query) use ($data) {
  4889. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4890. })
  4891. // ->where('user_id', $data['user_id'])
  4892. ->Where(function ($query) use ($data) {
  4893. $query->Where(function ($q) use ($data) {
  4894. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4895. ->orWhere('notice.user_id', $data['user_id']);
  4896. });
  4897. })
  4898. ->count();
  4899. }
  4900. if (empty($result)) {
  4901. return Result::error("查询失败", 0);
  4902. }
  4903. $data = [
  4904. 'rows' => $result,
  4905. 'count' => $total,
  4906. ];
  4907. return Result::success($data);
  4908. }
  4909. public function getNoticeDetail(array $data): array
  4910. {
  4911. $result = Notice::where('id', $data['id'])->first();
  4912. if (empty($result)) {
  4913. return Result::error("查询失败", 0);
  4914. }
  4915. return Result::success($result);
  4916. }
  4917. public function deleteNotice(array $data): array
  4918. {
  4919. $notice = Notice::where('id', $data['id'])->first();
  4920. if (empty($notice)) {
  4921. return Result::error("删除失败", 0);
  4922. }
  4923. $chat_group_id = $notice->group_id;
  4924. if ($chat_group_id) {
  4925. //删除群聊
  4926. ChatGroups::where('id', $chat_group_id)->delete();
  4927. //删除群成员
  4928. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4929. //删除群聊记录
  4930. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4931. }
  4932. $result = Notice::where('id', $data['id'])->delete();
  4933. return Result::success($result);
  4934. }
  4935. public function complaintList(array $data): array
  4936. {
  4937. var_dump($data, '---------1---------');
  4938. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4939. unset($data['type_id']);
  4940. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4941. $where = [];
  4942. if ($type_id != 10000 && empty($data['deal_user'])) {
  4943. // $where['complaint.user_id'] = $user_id;
  4944. }
  4945. if (!empty($data['title'])) {
  4946. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4947. }
  4948. if (!empty($data['department_id'])) {
  4949. $where['complaint.department_id'] = $data['department_id'];
  4950. }
  4951. if (!empty($data['deal'])) {
  4952. $where['complaint.deal'] = $data['deal'];
  4953. }
  4954. if (!empty($data['status'])) {
  4955. $where['complaint.status'] = $data['status'];
  4956. }
  4957. var_dump(!empty($data['deal_user']), '----------1');
  4958. var_dump($where, '----------2');
  4959. $result = Complaint::where($where)
  4960. ->when(!empty($data['status1']), function ($query) use ($data) {
  4961. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4962. })
  4963. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4964. //json re_user_ids data[user_id]是不是在里面
  4965. $query->Where(function ($q) use ($data) {
  4966. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4967. ->where('complaint.status', 2);
  4968. });
  4969. })
  4970. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4971. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4972. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4973. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4974. ->orderBy('updated_at', 'desc')
  4975. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4976. //sql输出
  4977. if (empty($result)) {
  4978. return Result::error("暂无投诉信息", 0);
  4979. }
  4980. // 取出数据
  4981. $rows = $result->items();
  4982. $count = $result->total();
  4983. $responseData = [
  4984. 'rows' => $rows,
  4985. 'count' => $count,
  4986. ];
  4987. return Result::success($responseData);
  4988. }
  4989. public function getComplaintList(array $data): array
  4990. {
  4991. var_dump($data, '00000001000000000000');
  4992. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4993. unset($data['type_id']);
  4994. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4995. $where = [];
  4996. if ($type_id != 10000 && empty($data['deal_user'])) {
  4997. $where['complaint.user_id'] = $user_id;
  4998. }
  4999. if (!empty($data['title'])) {
  5000. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  5001. }
  5002. if (!empty($data['department_id'])) {
  5003. $where['complaint.department_id'] = $data['department_id'];
  5004. }
  5005. if (!empty($data['deal'])) {
  5006. $where['complaint.deal'] = $data['deal'];
  5007. }
  5008. if (!empty($data['status'])) {
  5009. $where['complaint.status'] = $data['status'];
  5010. }
  5011. var_dump(!empty($data['deal_user']), '----------1');
  5012. var_dump($where, '----------2');
  5013. $result = Complaint::where($where)
  5014. ->when(!empty($data['status1']), function ($query) use ($data) {
  5015. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5016. })
  5017. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5018. // //json re_user_ids data[user_id]是不是在里面
  5019. // $query->Where(function ($q) use ($data) {
  5020. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5021. // ->where('complaint.status', 2);
  5022. // });
  5023. // })
  5024. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5025. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5026. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5027. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5028. ->orderBy('updated_at', 'desc')
  5029. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5030. //sql输出
  5031. if (empty($result)) {
  5032. return Result::error("暂无投诉信息", 0);
  5033. }
  5034. // 取出数据
  5035. $rows = $result->items();
  5036. $count = $result->total();
  5037. $responseData = [
  5038. 'rows' => $rows,
  5039. 'count' => $count,
  5040. ];
  5041. return Result::success($responseData);
  5042. }
  5043. public function getComplaintInfo(array $data): array
  5044. {
  5045. $result = Complaint::where('id', $data['id'])->first();
  5046. if (empty($result)) {
  5047. return Result::error("查询失败", 0);
  5048. }
  5049. return Result::success($result);
  5050. }
  5051. public function readComplaint(array $data): array
  5052. {
  5053. $result = Complaint::where('id', $data['id'])->first();
  5054. if (empty($result)) {
  5055. return Result::error("查询失败", 0);
  5056. }
  5057. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5058. $re_user_ids = json_decode($result['re_user_ids'], true);
  5059. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5060. //如果已经存在,就不再添加
  5061. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5062. $read_id = json_decode($result['read_id'], true);
  5063. if (!is_array($read_id)) {
  5064. $read_id = [];
  5065. }
  5066. if (!in_array($data['user_id'], $read_id)) {
  5067. $read_id[] = $data['user_id'];
  5068. $result['read_id'] = json_encode($read_id);
  5069. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5070. }
  5071. } else {
  5072. //如果不存在,就添加
  5073. $result['read_id'] = json_encode([$data['user_id']]);
  5074. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5075. }
  5076. }
  5077. return Result::success($result);
  5078. }
  5079. public function addComplaint(array $data): array
  5080. {
  5081. date_default_timezone_set('Asia/Shanghai');
  5082. $data['created_at'] = date('Y-m-d H:i:s');
  5083. $data['updated_at'] = date('Y-m-d H:i:s');
  5084. $this->sendMessage([
  5085. 'talk_type' => 800,
  5086. 'title' => $data['title'],
  5087. 'content' => '提交了审核',
  5088. 'messageType' => 6,
  5089. ]);
  5090. $result = Complaint::create($data);
  5091. return Result::success($result);
  5092. }
  5093. public function updateComplaint(array $data): array
  5094. {
  5095. date_default_timezone_set('Asia/Shanghai');
  5096. $data['updated_at'] = date('Y-m-d H:i:s');
  5097. $user_id = $data['user_id'] ?? 0;
  5098. $type_id = $data['type_id'] ?? 0;
  5099. unset($data['user_id']);
  5100. unset($data['type_id']);
  5101. $this->sendMessage([
  5102. 'talk_type' => 800,
  5103. 'title' => $data['title'],
  5104. 'content' => '提交了审核',
  5105. 'messageType' => 6,
  5106. ]);
  5107. $result = Complaint::where('id', $data['id'])->update($data);
  5108. return Result::success($result);
  5109. }
  5110. public function deleteComplaint(array $data): array
  5111. {
  5112. $result = Complaint::where('id', $data['id'])->delete();
  5113. return Result::success($result);
  5114. }
  5115. public function getComplainInfo(array $data): array
  5116. {
  5117. $result = Complaint::where('id', $data['id'])->first();
  5118. if (empty($result)) {
  5119. return Result::error("查询失败", 0);
  5120. }
  5121. return Result::success($result);
  5122. }
  5123. public function updateComplaintStatus(array $data): array
  5124. {
  5125. date_default_timezone_set('Asia/Shanghai');
  5126. $data['updated_at'] = date('Y-m-d H:i:s');
  5127. $user_id = $data['user_id'] ?? 0;
  5128. $type_id = $data['type_id'] ?? 0;
  5129. unset($data['user_id']);
  5130. unset($data['type_id']);
  5131. //处理, 写入处理人
  5132. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5133. $data['real_deal_user'] = $user_id;
  5134. }
  5135. //如果是deal 23,则判断是不是处理人
  5136. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5137. $complaintInof = Complaint::where('id', $data['id'])
  5138. ->where('real_deal_user', $user_id)
  5139. ->first();
  5140. if (empty($complaintInof)) {
  5141. return Result::error("处理人错误", 0);
  5142. }
  5143. }
  5144. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5145. if ($data['status'] == 1) {
  5146. $this->sendMessage([
  5147. 'talk_type' => 800,
  5148. 'title' => $complaintInfo['title'],
  5149. 'content' => '提交了审核',
  5150. 'messageType' => 6,
  5151. ]);
  5152. }
  5153. if ($data['status'] == 2 && !isset($data['deal'])) {
  5154. $this->sendMessage([
  5155. 'talk_type' => 801,
  5156. 'title' => $complaintInfo['title'],
  5157. 'content' => '审核通过',
  5158. 'messageType' => 6,
  5159. 'user_id' => $complaintInfo['user_id'],
  5160. ]);
  5161. $this->sendMessage([
  5162. 'talk_type' => 802,
  5163. 'title' => $complaintInfo['title'],
  5164. 'content' => '待处理',
  5165. 'messageType' => 6,
  5166. 'user_id' => $complaintInfo['re_user_ids'],
  5167. ]);
  5168. }
  5169. if ($data['status'] == 3 && !isset($data['deal'])) {
  5170. $this->sendMessage([
  5171. 'talk_type' => 801,
  5172. 'title' => $complaintInfo['title'],
  5173. 'content' => '审核拒绝',
  5174. 'messageType' => 6,
  5175. 'user_id' => $complaintInfo['user_id'],
  5176. ]);
  5177. }
  5178. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5179. $this->sendMessage([
  5180. 'talk_type' => 802,
  5181. 'title' => $complaintInfo['title'],
  5182. 'content' => '处理中',
  5183. 'messageType' => 6,
  5184. 'user_id' => $complaintInfo['re_user_ids'],
  5185. ]);
  5186. }
  5187. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5188. $this->sendMessage([
  5189. 'talk_type' => 802,
  5190. 'title' => $complaintInfo['title'],
  5191. 'content' => '不予处理',
  5192. 'messageType' => 6,
  5193. 'user_id' => $complaintInfo['re_user_ids'],
  5194. ]);
  5195. }
  5196. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5197. $this->sendMessage([
  5198. 'talk_type' => 802,
  5199. 'title' => $complaintInfo['title'],
  5200. 'content' => '已完结',
  5201. 'messageType' => 6,
  5202. 'user_id' => $complaintInfo['re_user_ids'],
  5203. ]);
  5204. }
  5205. $result = complaint::where('id', $data['id'])->update($data);
  5206. return Result::success($result);
  5207. }
  5208. public function updateGoodStatus(array $data): array
  5209. {
  5210. $user_id = $data['user_id'] ?? 0;
  5211. $type_id = $data['type_id'] ?? 0;
  5212. unset($data['user_id']);
  5213. unset($data['type_id']);
  5214. $goodInfo = Good::where('id', $data['id'])->first();
  5215. if ($data['status'] == 2) {
  5216. $this->sendMessage([
  5217. 'talk_type' => 201,
  5218. 'title' => $goodInfo['name'],
  5219. 'content' => '审核通过',
  5220. 'messageType' => 3,
  5221. 'user_id' => $goodInfo['user_id'],
  5222. ]);
  5223. }
  5224. if ($data['status'] == 3) {
  5225. $this->sendMessage([
  5226. 'talk_type' => 201,
  5227. 'title' => $goodInfo['name'],
  5228. 'content' => '审核拒绝',
  5229. 'messageType' => 3,
  5230. 'user_id' => $goodInfo['user_id'],
  5231. ]);
  5232. }
  5233. if ($data['status'] == 1) {
  5234. $this->sendMessage([
  5235. 'talk_type' => 200,
  5236. 'title' => $goodInfo['name'],
  5237. 'content' => '提交了审核',
  5238. 'messageType' => 3,
  5239. ]);
  5240. }
  5241. $result = Good::where('id', $data['id'])->update($data);
  5242. return Result::success($result);
  5243. }
  5244. public function updateJobHuntingStatus(array $data): array
  5245. {
  5246. $user_id = $data['user_id'] ?? 0;
  5247. $type_id = $data['type_id'] ?? 0;
  5248. unset($data['user_id']);
  5249. unset($data['type_id']);
  5250. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5251. if ($data['status'] == 2) {
  5252. $this->sendMessage([
  5253. 'talk_type' => 601,
  5254. 'title' => $jogHuntingInfo['name'],
  5255. 'content' => '审核通过',
  5256. 'messageType' => 11,
  5257. 'user_id' => $jogHuntingInfo['user_id'],
  5258. ]);
  5259. }
  5260. if ($data['status'] == 3) {
  5261. $this->sendMessage([
  5262. 'talk_type' => 601,
  5263. 'title' => $jogHuntingInfo['name'],
  5264. 'content' => '审核拒绝',
  5265. 'messageType' => 11,
  5266. 'user_id' => $jogHuntingInfo['user_id'],
  5267. ]);
  5268. }
  5269. if ($data['status'] == 1) {
  5270. $this->sendMessage([
  5271. 'talk_type' => 600,
  5272. 'title' => $jogHuntingInfo['name'],
  5273. 'content' => '提交了审核',
  5274. 'messageType' => 11,
  5275. ]);
  5276. }
  5277. $result = JobHunting::where('id', $data['id'])->update($data);
  5278. return Result::success($result);
  5279. }
  5280. public function updateNoticeStatus(array $data): array
  5281. {
  5282. $user_id = $data['user_id'] ?? 0;
  5283. $type_id = $data['type_id'] ?? 0;
  5284. unset($data['user_id']);
  5285. unset($data['type_id']);
  5286. //查询公告
  5287. $notice = Notice::where('id', $data['id'])->first();
  5288. if (empty($notice)) {
  5289. return Result::error("公告不存在", 0);
  5290. }
  5291. //$chat_ids 去除掉$data['user_id']
  5292. $chat_ids = json_decode($notice['re_user_ids'], true);
  5293. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5294. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5295. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5296. //chat_group
  5297. $group_id = PublicData::uuid();
  5298. $groupData = [
  5299. 'id' => $group_id,
  5300. 'creator_id' => $notice['user_id'],
  5301. 'group_name' => $notice['group_name'] ?? '',
  5302. 'profile' => $notice['profile'] ?? 0,
  5303. ];
  5304. var_dump($groupData, '-----------------groupData-------');
  5305. $groupResult = ChatGroups::insertGetId($groupData);
  5306. var_dump($groupResult, '-----------------groupid-------');
  5307. $groupMemberData = [
  5308. 'id' => PublicData::uuid(),
  5309. 'user_id' => $notice['user_id'],
  5310. 'group_id' => $group_id,
  5311. 'leader' => 2,
  5312. ];
  5313. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5314. //插入群成员表
  5315. $groupMemberDataUser = [];
  5316. $chatData = [];
  5317. foreach ($chat_ids as $key => $value) {
  5318. $groupMemberDataUser[] = [
  5319. 'id' => PublicData::uuid(),
  5320. 'user_id' => $value,
  5321. 'group_id' => $group_id,
  5322. 'leader' => 1,
  5323. ];
  5324. $chatData[] = [
  5325. 'user_id' => $value,
  5326. 'msg_type' => 1,
  5327. 'receiver_id' => $group_id,
  5328. 'content' => '通过通知创建群聊',
  5329. 'group_receiver_id' => $notice['user_id'],
  5330. 'action' => 'recieved',
  5331. 'created_at' => date('Y-m-d H:i:s'),
  5332. ];
  5333. }
  5334. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5335. ChatGroupsMember::insert($groupMemberDataUser);
  5336. //插入一条管理员聊天记录
  5337. $chatData[] = [
  5338. 'user_id' => $notice['user_id'],
  5339. 'msg_type' => 1,
  5340. 'receiver_id' => $group_id,
  5341. 'content' => '通过通知创建群聊',
  5342. 'group_receiver_id' => $notice['user_id'],
  5343. 'action' => 'said',
  5344. 'created_at' => date('Y-m-d H:i:s'),
  5345. ];
  5346. var_dump($chatData, '-----------------chatData-------');
  5347. $chatResult = ChatRecords::insert($chatData);
  5348. //处理imp
  5349. $group = [
  5350. 'type' => 1,
  5351. 'name' => $notice['group_name'] ?? '',
  5352. 'profile' => '',
  5353. 'avatar' => '',
  5354. 'creator_id' => $notice['user_id'],
  5355. ];
  5356. $groupResult = GroupImp::insertGetId($group);
  5357. var_dump($groupResult, '获取imp group_id');
  5358. $groupMember = [
  5359. 'user_id' => $notice['user_id'],
  5360. 'group_id' => $groupResult,
  5361. 'leader' => 1,
  5362. 'join_time' => Date('Y-m-d H:i:s')
  5363. ];
  5364. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5365. $talk_session = [
  5366. 'user_id' => $notice['user_id'],
  5367. 'to_from_id' => $groupResult,
  5368. 'talk_mode' => 2,
  5369. 'created_at' => Date('Y-m-d H:i:s'),
  5370. 'updated_at' => Date('Y-m-d H:i:s'),
  5371. ];
  5372. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5373. //被通知人员处理
  5374. foreach ($chat_ids as $key => $value) {
  5375. $groupMemberdata[] = [
  5376. 'user_id' => $value,
  5377. 'group_id' => $groupResult,
  5378. 'leader' => 3,
  5379. 'join_time' => Date('Y-m-d H:i:s')
  5380. ];
  5381. $talk_sessionData[] = [
  5382. 'user_id' => $value,
  5383. 'to_from_id' => $groupResult,
  5384. 'talk_mode' => 2,
  5385. 'created_at' => Date('Y-m-d H:i:s'),
  5386. 'updated_at' => Date('Y-m-d H:i:s'),
  5387. ];
  5388. }
  5389. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5390. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5391. $group_id = $groupResult;
  5392. //更新result的 group_id
  5393. $data['group_id'] = $group_id;
  5394. Notice::where(['id' => $data['id']])->update($data);
  5395. }
  5396. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5397. //删除掉信息
  5398. GroupImp::where('id', $notice['group_id'])->delete();
  5399. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5400. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5401. foreach ($chat_ids as $key => $value) {
  5402. }
  5403. //聊天记录删除
  5404. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5405. $data['group_id'] = null;
  5406. Notice::where(['id' => $data['id']])->update($data);
  5407. }
  5408. $result = Notice::where('id', $data['id'])->update($data);
  5409. $noticeInfo = Notice::where('id', $data['id'])->first();
  5410. if ($data['status'] == 2) {
  5411. $this->sendMessage([
  5412. 'talk_type' => 701,
  5413. 'title' => $noticeInfo['title'],
  5414. 'content' => '审核通过',
  5415. 'messageType' => 3,
  5416. 'user_id' => $noticeInfo['user_id'],
  5417. ]);
  5418. }
  5419. if ($data['status'] == 3) {
  5420. $this->sendMessage([
  5421. 'talk_type' => 701,
  5422. 'title' => $noticeInfo['title'],
  5423. 'content' => '审核拒绝',
  5424. 'messageType' => 3,
  5425. 'user_id' => $noticeInfo['user_id'],
  5426. ]);
  5427. }
  5428. if ($data['status'] == 1) {
  5429. $this->sendMessage([
  5430. 'talk_type' => 700,
  5431. 'title' => $noticeInfo['title'],
  5432. 'content' => '提交了审核',
  5433. 'messageType' => 3,
  5434. ]);
  5435. }
  5436. return Result::success($result);
  5437. }
  5438. public function getDUser(array $data): array
  5439. {
  5440. if (!empty($data['ids'])) {
  5441. $user = User::whereIn('id', $data['ids'])->getall();
  5442. if (empty($user)) {
  5443. return Result::error('无数据', 0);
  5444. }
  5445. return Result::success($user);
  5446. }
  5447. $where = [];
  5448. if (!empty($data['department_id'])) {
  5449. $where['department_id'] = $data['department_id'];
  5450. }
  5451. if (!empty($data['city_id'])) {
  5452. $where['city_id'] = $data['city_id'];
  5453. }
  5454. $result = User::where('type_id', 2)
  5455. ->where('status', 1)
  5456. ->where($where)
  5457. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5458. ->get();
  5459. if (empty($result)) {
  5460. return Result::error("查询失败", 0);
  5461. }
  5462. return Result::success($result);
  5463. }
  5464. /**
  5465. * 验证导航名称是否重复
  5466. * @return void
  5467. */
  5468. public function checkCategoryName(array $data): array
  5469. {
  5470. $result = Category::when($data, function ($query) use ($data) {
  5471. if (isset($data['name']) && $data['name']) {
  5472. $query->where("name", $data['name']);
  5473. }
  5474. if (isset($data['id']) && $data['id']) {
  5475. $query->where("id", "!=", $data['id']);
  5476. }
  5477. })->first();
  5478. if ($result) {
  5479. return Result::error("已存在");
  5480. } else {
  5481. return Result::success();
  5482. }
  5483. }
  5484. //20250226 产品列表
  5485. // 20250306 -------招聘--------fr
  5486. /*
  5487. * 招聘列表
  5488. * */
  5489. public function getJobRecruitingList(array $data): array
  5490. {
  5491. $where = [];
  5492. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5493. if ($data['checkout'] == 0) {
  5494. $job_status = [0, 2];
  5495. } else {
  5496. $job_status = [1];
  5497. }
  5498. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5499. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5500. }
  5501. $user = User::where('id', $data['user_id'])->first();
  5502. if (empty($user)) {
  5503. return Result::error("用户不存在", 0);
  5504. }
  5505. // 3:企业会员
  5506. if ($user['type_id'] == 3) {
  5507. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5508. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5509. }
  5510. // 如果 $where 为空,则不添加 where 条件
  5511. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5512. return $query->where($where);
  5513. })
  5514. ->whereIn('job_recruiting.status', $job_status)
  5515. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5516. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5517. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5518. ->orderBy("updated_at", "desc")
  5519. ->offset(($data['page'] - 1) * $data['page_size'])
  5520. ->limit($data['page_size'])
  5521. ->get()
  5522. ->all();
  5523. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5524. return $query->where($where);
  5525. })
  5526. ->whereIn('job_recruiting.status', $job_status)
  5527. ->count();
  5528. if (empty($result)) {
  5529. return Result::error("暂无招聘信息", 0);
  5530. }
  5531. return Result::success($result);
  5532. }
  5533. /*
  5534. * 招聘信息添加
  5535. * */
  5536. public function addJobRecruiting(array $data): array
  5537. {
  5538. // var_dump('添加招聘进入news------data',$data);
  5539. // return Result::success($data);
  5540. $user = User::where('user.id', $data['user_id'])
  5541. ->where('user.status', 1)
  5542. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5543. ->select(
  5544. 'user.type_id',
  5545. 'user.mobile',
  5546. 'user.email',
  5547. 'user_info.business_name',
  5548. 'user_info.company_hy_id',
  5549. 'user_info.company_nature',
  5550. 'user_info.company_size',
  5551. 'user_info.introduction',
  5552. 'user_info.real_name',
  5553. 'user_info.company_url',
  5554. 'user_info.address_arr_id',
  5555. 'user_info.address'
  5556. )
  5557. ->first();
  5558. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5559. return Result::error("用户不存在", 0);
  5560. }
  5561. $web = Website::where('id', $data['website_id'])->first();
  5562. if (empty($web)) {
  5563. return Result::error("网站不存在", 0);
  5564. }
  5565. // var_dump('添加招聘进入news---user---user',$user);
  5566. // 处理招聘关键词
  5567. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5568. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5569. } else {
  5570. Jieba::init(); // 初始化 jieba-php
  5571. Finalseg::init();
  5572. $segList = Jieba::cut($data['title']);
  5573. $segList1 = array_slice($segList, 0, 8);
  5574. $data['keyword'] = implode(',', $segList1);
  5575. }
  5576. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5577. $content = $data['description'];
  5578. // 去除 <style> 和 <script> 标签及其内容
  5579. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5580. // 去除所有 HTML 标签
  5581. $content = strip_tags($content);
  5582. // 去除 HTML 实体
  5583. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5584. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5585. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5586. // 去除多余空白
  5587. $content = preg_replace('/\s+/u', '', $content);
  5588. // 截取 100 个字符
  5589. $data['seo_description'] = mb_substr($content, 0, 100);
  5590. }
  5591. // return Result::success($user);
  5592. $data['action_id'] = $data['user_id'] ?? null;
  5593. $data['user_type'] = $user['type_id'] ?? null;
  5594. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5595. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5596. $data['catid'] = end($data['cat_arr_id']);
  5597. } else {
  5598. $data['catid'] = 0;
  5599. }
  5600. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5601. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5602. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5603. // 公司地址 管理员必填
  5604. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5605. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5606. // 管理员-企业相关信息
  5607. $company = [
  5608. // 'user_id' => $data['user_id']?? null,
  5609. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5610. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5611. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5612. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5613. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5614. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5615. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5616. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5617. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5618. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5619. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5620. ];
  5621. //去掉相关企业信息
  5622. $job = array_diff_key($data, array_flip(array_keys($company)));
  5623. // var_dump('添加招聘进入news---job---user',$job);
  5624. Db::beginTransaction();
  5625. try {
  5626. // // 先添加职位相关信息
  5627. if ($user['type_id'] == 10000) {
  5628. $job['status'] = 1;
  5629. }
  5630. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5631. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5632. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5633. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5634. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5635. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5636. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5637. // return Result::success($job);
  5638. $jobId = JobRecruiting::insertGetId($job);
  5639. if (empty($jobId)) {
  5640. Db::rollBack();
  5641. return Result::error("添加失败");
  5642. }
  5643. // 添加公司信息
  5644. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5645. $company['job_id'] = $jobId;
  5646. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5647. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5648. if ($user['type_id'] == 10000) {
  5649. // 管理员添加企业信息
  5650. $companyId = JobCompany::insertGetId($company);
  5651. if (empty($companyId)) {
  5652. Db::rollBack();
  5653. return Result::error("添加失败");
  5654. }
  5655. } else {
  5656. // 企业会员添加企业信息
  5657. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5658. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5659. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5660. $company['job_id'] = $jobId;
  5661. $companyId = JobCompany::insertGetId($company);
  5662. if (empty($companyId)) {
  5663. Db::rollBack();
  5664. return Result::error("添加失败");
  5665. }
  5666. }
  5667. Db::commit();
  5668. $result = [
  5669. 'job_id' => $jobId,
  5670. 'company_id' => $companyId,
  5671. ];
  5672. return Result::success($result);
  5673. } catch (\Exception $e) {
  5674. Db::rollBack();
  5675. return Result::error($e->getMessage(), 0);
  5676. }
  5677. // return Result::success($result);
  5678. }
  5679. /*
  5680. * 获取招聘信息详情
  5681. * */
  5682. public function getJobRecruitingInfo(array $data): array
  5683. {
  5684. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5685. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5686. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5687. ->select(
  5688. 'job_recruiting.*',
  5689. 'website.website_name as website_name',
  5690. 'job_company.business_name',
  5691. 'job_company.company_hy_id',
  5692. 'job_company.company_size',
  5693. 'job_company.company_nature',
  5694. 'job_company.introduction',
  5695. 'job_company.real_name',
  5696. 'job_company.mobile',
  5697. 'job_company.company_url',
  5698. 'job_company.address_arr_id',
  5699. 'job_company.address',
  5700. 'job_company.email'
  5701. )
  5702. ->first();
  5703. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5704. if (!empty($cityId)) {
  5705. if (isset($cityId[1]) && $cityId[1] != null) {
  5706. $city = District::where('id', $cityId[1])->first(['name']);
  5707. } else {
  5708. $city = District::where('id', $cityId[0])->first(['name']);
  5709. }
  5710. $result['city'] = $city['name'] ?? '';
  5711. }
  5712. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5713. if (is_array($addressId) && !empty($addressId)) {
  5714. $address = District::whereIn('id', $addressId)
  5715. ->orderBy('level', 'asc')
  5716. ->get(['name'])
  5717. ->pluck('name')
  5718. ->implode('');
  5719. // $job->address_name = $address ?? '';
  5720. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5721. }
  5722. if (empty($result)) {
  5723. return Result::error("招聘信息不存在", 0);
  5724. }
  5725. // return Result::success($job);
  5726. return Result::success($result);
  5727. }
  5728. /*
  5729. * 修改招聘信息
  5730. * */
  5731. public function upJobRecruiting(array $data): array
  5732. {
  5733. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5734. // return Result::success($job);
  5735. if (empty($job)) {
  5736. return Result::error("招聘信息不存在", 0);
  5737. }
  5738. $user = User::where('id', $data['user_id'])->first();
  5739. // return Result::success($user);
  5740. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5741. return Result::error("用户不存在", 0);
  5742. }
  5743. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5744. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5745. }
  5746. // 处理招聘关键词
  5747. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5748. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5749. } else {
  5750. Jieba::init(); // 初始化 jieba-php
  5751. Finalseg::init();
  5752. $segList = Jieba::cut($data['title']);
  5753. $segList1 = array_slice($segList, 0, 8);
  5754. $data['keyword'] = implode(',', $segList1);
  5755. }
  5756. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5757. $content = $data['description'];
  5758. // 去除 <style> 和 <script> 标签及其内容
  5759. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5760. // 去除所有 HTML 标签
  5761. $content = strip_tags($content);
  5762. // 去除 HTML 实体
  5763. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5764. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5765. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5766. // 去除多余空白
  5767. $content = preg_replace('/\s+/u', '', $content);
  5768. // 截取 100 个字符
  5769. $data['seo_description'] = mb_substr($content, 0, 100);
  5770. }
  5771. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5772. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5773. $data['catid'] = end($data['cat_arr_id']);
  5774. } else {
  5775. }
  5776. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5777. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5778. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5779. // 公司地址 管理员必填
  5780. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5781. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5782. // 管理员-企业相关信息
  5783. $company = [
  5784. // 'user_id' => $data['user_id']?? null,
  5785. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5786. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5787. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5788. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5789. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5790. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5791. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5792. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5793. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5794. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5795. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5796. ];
  5797. //去掉相关企业信息
  5798. $data = array_diff_key($data, array_flip(array_keys($company)));
  5799. $jobId = $data['id'];
  5800. $web = $data['website_id'];
  5801. $data['action_id'] = $data['user_id'];
  5802. unset($data['user_id']);
  5803. unset($data['user_type']);
  5804. unset($data['id']);
  5805. unset($data['website_id']);
  5806. // return Result::success($data);
  5807. Db::beginTransaction();
  5808. try {
  5809. // 管理员修改招聘信息
  5810. if ($user['type_id'] == 10000) {
  5811. $data['website_id'] = $web;
  5812. $company['website_id'] = $data['website_id'];
  5813. $data['status'] = 1;
  5814. } else {
  5815. $data['status'] = 0;
  5816. }
  5817. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5818. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5819. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5820. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5821. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5822. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5823. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5824. // return Result::success($job);
  5825. // Db::rollBack();
  5826. // return Result::success($company);
  5827. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5828. $this->sendMessage([
  5829. 'talk_type' => 500,
  5830. 'title' => $data['title'],
  5831. 'content' => '提交了审核',
  5832. 'messageType' => 10,
  5833. ]);
  5834. }
  5835. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5836. if (empty($result['job'])) {
  5837. Db::rollBack();
  5838. return Result::error("修改招聘信息失败");
  5839. }
  5840. // 管理员修改企业相关信息
  5841. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5842. if (empty($result['company'])) {
  5843. Db::rollBack();
  5844. return Result::error("修改企业相关信息失败");
  5845. }
  5846. Db::commit();
  5847. // return Result::success($result);
  5848. } catch (\Exception $e) {
  5849. Db::rollBack();
  5850. return Result::error($e->getMessage(), 0);
  5851. }
  5852. return Result::success($result);
  5853. }
  5854. /*
  5855. * 招聘信息删除
  5856. * */
  5857. public function delJobRecruiting(array $data): array
  5858. {
  5859. $user = User::where('id', $data['user_id'])->first();
  5860. if (empty($user)) {
  5861. return Result::error("用户不存在", 0);
  5862. }
  5863. $job = JobRecruiting::where('id', $data['id'])->first();
  5864. if (empty($job)) {
  5865. return Result::error("招聘信息不存在", 0);
  5866. }
  5867. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5868. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5869. }
  5870. Db::beginTransaction();
  5871. try {
  5872. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5873. if (empty($result['job'])) {
  5874. Db::rollBack();
  5875. return Result::error("删除招聘信息失败");
  5876. }
  5877. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5878. if (empty($result['company'])) {
  5879. Db::rollBack();
  5880. return Result::error("删除企业相关信息失败");
  5881. }
  5882. Db::commit();
  5883. } catch (\Exception $e) {
  5884. Db::rollBack();
  5885. return Result::error($e->getMessage(), 0);
  5886. }
  5887. return Result::success($result);
  5888. }
  5889. /*
  5890. * 获取公司信息
  5891. * */
  5892. public function getJobCompany(array $data): array
  5893. {
  5894. $user = User::where('user.id', $data['user_id'])
  5895. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5896. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5897. ->first();
  5898. // return Result::success($user);
  5899. if (empty($user)) {
  5900. return Result::error("用户不存在", 0);
  5901. }
  5902. if ($user['type_id'] == 3) {
  5903. $result = [
  5904. // 'id' => 0,
  5905. 'user_id' => $data['user_id'],
  5906. 'website_id' => $data['website_id'],
  5907. 'business_name' => $user['business_name'], // 企业名称
  5908. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5909. 'company_nature' => $user['company_nature'], // 公司性质
  5910. 'company_size' => $user['company_size'], // 公司规模
  5911. 'introduction' => $user['introduction'], // 公司简介
  5912. 'real_name' => $user['real_name'], // 企业联系人
  5913. 'mobile' => $user['mobile'], // 企业联系电话
  5914. 'company_url' => $user['company_url'], // 企业网址
  5915. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5916. 'address' => $user['address'], // 企业地址
  5917. 'email' => $user['email'], // 企业邮箱
  5918. ];
  5919. } else {
  5920. return Result::error("用户类型错误", 0);
  5921. }
  5922. if (empty($result)) {
  5923. return Result::error("公司信息不存在", 0);
  5924. }
  5925. return Result::success($result);
  5926. }
  5927. /*
  5928. * 修改公司信息
  5929. * */
  5930. public function upJobCompany(array $data): array
  5931. {
  5932. // return Result::success($data);
  5933. $user = User::where('user.id', $data['user_id'])
  5934. ->where('user.status', 1)
  5935. ->select('user.user_name', 'user.type_id')
  5936. ->first();
  5937. if (empty($user)) {
  5938. return Result::error("用户不存在", 0);
  5939. }
  5940. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5941. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5942. $company = [
  5943. 'business_name' => $data['business_name'], // 企业名称
  5944. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5945. 'company_nature' => $data['company_nature'], // 公司性质
  5946. 'company_size' => $data['company_size'], // 公司规模
  5947. 'introduction' => $data['introduction'], // 公司简介
  5948. // 'real_name' => $data['real_name'], // 企业联系人
  5949. 'company_url' => $data['company_url'], // 企业网址
  5950. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5951. 'address' => $data['address'], // 企业详细地址
  5952. // 'email' => $data['email'], // 企业邮箱
  5953. ];
  5954. if ($user['type_id'] == 3) {
  5955. Db::beginTransaction();
  5956. try {
  5957. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5958. 'business_name' => $data['business_name'], // 企业名称
  5959. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5960. 'company_nature' => $data['company_nature'], // 公司性质
  5961. 'company_size' => $data['company_size'], // 公司规模
  5962. 'introduction' => $data['introduction'], // 公司简介
  5963. // 'real_name' => $data['real_name'], // 企业联系人
  5964. 'company_url' => $data['company_url'], // 企业网址
  5965. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5966. 'address' => $data['address'], // 企业详细地址
  5967. ]);
  5968. if (empty($result['userinfo'])) {
  5969. Db::rollBack();
  5970. return Result::error('修改企业会员信息失败!');
  5971. }
  5972. $result['user'] = User::where('id', $data['user_id'])->update([
  5973. 'email' => $data['email'], // 企业邮箱
  5974. ]);
  5975. if (empty($result['user'])) {
  5976. Db::rollBack();
  5977. return Result::error('修改个人中心信息失败!');
  5978. }
  5979. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5980. if (!empty($job_company)) {
  5981. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5982. if (empty($result['job_company'])) {
  5983. Db::rollBack();
  5984. return Result::error('修改企业会员信息失败!');
  5985. }
  5986. }
  5987. Db::commit();
  5988. return Result::success($result);
  5989. } catch (\Exception $e) {
  5990. Db::rollBack();
  5991. return Result::error($e->getMessage(), 0);
  5992. }
  5993. } else {
  5994. return Result::error("用户类型错误", 0);
  5995. }
  5996. }
  5997. /*
  5998. * 获取省-市
  5999. * */
  6000. public function getJobRecruitingArea(array $data): array
  6001. {
  6002. if (isset($data['pid']) && $data['pid'] != null) {
  6003. $result = District::where('pid', $data['pid'])->get()->all();
  6004. } else {
  6005. $result = District::where('level', 1)->get()->all();
  6006. }
  6007. if (empty($result)) {
  6008. return Result::error("暂无此省市", 0);
  6009. }
  6010. return Result::success($result);
  6011. }
  6012. /*
  6013. * 获取行业分类
  6014. * */
  6015. public function getIndustry(array $data): array
  6016. {
  6017. $result = JobIndustry::get()->all();
  6018. if (empty($result)) {
  6019. return Result::error("暂无行业分类", 0);
  6020. }
  6021. return Result::success($result);
  6022. }
  6023. /*
  6024. * 获取职位
  6025. * */
  6026. public function getPositionList(array $data): array
  6027. {
  6028. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6029. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6030. } else {
  6031. $result = JobPosition::where('zwpid', 0)->get()->all();
  6032. }
  6033. if (empty($result)) {
  6034. return Result::error("暂无此职位", 0);
  6035. }
  6036. return Result::success($result);
  6037. }
  6038. /*
  6039. * 获取工作性质-菜单
  6040. * */
  6041. public function getJobNature(array $data): array
  6042. {
  6043. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6044. if (empty($result)) {
  6045. return Result::error("暂无工作性质", 0);
  6046. }
  6047. return Result::success($result);
  6048. }
  6049. /*
  6050. * 获取工作经验-菜单
  6051. * */
  6052. public function getExperience(array $data): array
  6053. {
  6054. $result = JobEnum::where('egroup', 'years')->get()->all();
  6055. if (empty($result)) {
  6056. return Result::error("暂无工作经验", 0);
  6057. }
  6058. return Result::success($result);
  6059. }
  6060. /*
  6061. * 获取学历-菜单
  6062. * */
  6063. public function getEducation(array $data): array
  6064. {
  6065. $result = JobEnum::where('egroup', 'education')->get()->all();
  6066. if (empty($result)) {
  6067. return Result::error("暂无学历", 0);
  6068. }
  6069. return Result::success($result);
  6070. }
  6071. /*
  6072. * 获取薪资-菜单
  6073. * */
  6074. public function getSalary(array $data): array
  6075. {
  6076. $result = JobEnum::where('egroup', 'income')->get()->all();
  6077. if (empty($result)) {
  6078. return Result::error("暂无薪资", 0);
  6079. }
  6080. return Result::success($result);
  6081. }
  6082. /*
  6083. * 获取语言-菜单
  6084. * */
  6085. public function getLanguage(array $data): array
  6086. {
  6087. $result = JobEnum::where('egroup', 'language')->get()->all();
  6088. if (empty($result)) {
  6089. return Result::error("暂无语言", 0);
  6090. }
  6091. return Result::success($result);
  6092. }
  6093. /*
  6094. * 获取掌握程度-菜单
  6095. * */
  6096. public function getLevel(array $data): array
  6097. {
  6098. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6099. if (empty($result)) {
  6100. return Result::error("暂无工作性质", 0);
  6101. }
  6102. return Result::success($result);
  6103. }
  6104. // 公司信息
  6105. /*
  6106. * 获取公司性质-菜单
  6107. * */
  6108. public function getCompanyNature(array $data): array
  6109. {
  6110. $result = JobNature::get()->all();
  6111. if (empty($result)) {
  6112. return Result::error("暂无公司性质", 0);
  6113. }
  6114. return Result::success($result);
  6115. }
  6116. /*
  6117. * 获取公司规模-菜单
  6118. * */
  6119. public function getCompanySize(array $data): array
  6120. {
  6121. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6122. if (empty($result)) {
  6123. return Result::error("暂无公司规模", 0);
  6124. }
  6125. return Result::success($result);
  6126. }
  6127. /*
  6128. * 招聘信息审核
  6129. * */
  6130. public function checkJobRecruiting(array $data): array
  6131. {
  6132. $user = User::where('id', $data['user_id'])->first();
  6133. if (empty($user)) {
  6134. return Result::error("用户不存在", 0);
  6135. }
  6136. $job = JobRecruiting::where('id', $data['id'])->first();
  6137. if (empty($job)) {
  6138. return Result::error("招聘信息不存在", 0);
  6139. }
  6140. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6141. if ($user['type_id'] != 10000) {
  6142. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6143. }
  6144. // 驳回原因
  6145. if ($data['status'] == 2) {
  6146. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6147. }
  6148. $data['action_id'] = $data['user_id'];
  6149. unset($data['user_id']);
  6150. if ($data['status'] == 1) {
  6151. $this->sendMessage([
  6152. 'talk_type' => 501,
  6153. 'title' => $job['title'],
  6154. 'content' => '审核通过',
  6155. 'messageType' => 10,
  6156. 'user_id' => $job['user_id'],
  6157. ]);
  6158. }
  6159. if ($data['status'] == 2) {
  6160. $this->sendMessage([
  6161. 'talk_type' => 501,
  6162. 'title' => $job['title'],
  6163. 'content' => '审核拒绝',
  6164. 'messageType' => 10,
  6165. 'user_id' => $job['user_id'],
  6166. ]);
  6167. }
  6168. if ($data['status'] == 0) {
  6169. $this->sendMessage([
  6170. 'talk_type' => 500,
  6171. 'title' => $job['title'],
  6172. 'content' => '提交了审核',
  6173. 'messageType' => 10,
  6174. ]);
  6175. }
  6176. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6177. if (empty($result)) {
  6178. return Result::error("审核失败", 0);
  6179. }
  6180. return Result::success($result);
  6181. }
  6182. public function myApplyList(array $data): array
  6183. {
  6184. var_dump($data, '------参数');
  6185. $user = User::where('id', $data['user_id'])->first();
  6186. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6187. return Result::error("用户不存在", 0);
  6188. }
  6189. // 1:个人会员 职场机会
  6190. if ($user['type_id'] == 1) {
  6191. $where['user_id'] = $user['id'];
  6192. }
  6193. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6194. $query->where('user_id', $user['id']);
  6195. })
  6196. ->pluck('recruit_id');
  6197. $where = [];
  6198. if (isset($data['salary']) && $data['salary'] != null) {
  6199. $where['job_recruiting.salary'] = $data['salary'];
  6200. }
  6201. if (isset($data['experience']) && $data['experience'] != null) {
  6202. $where['job_recruiting.experience'] = $data['experience'];
  6203. }
  6204. if (isset($data['business_name']) && $data['business_name'] != null) {
  6205. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6206. }
  6207. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6208. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6209. ->where($where);
  6210. // ->count();
  6211. $count = $query->count();
  6212. $query = clone $query;
  6213. $job = $query
  6214. ->leftJoin('job_enum as income_enum', function ($join) {
  6215. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6216. ->where('income_enum.egroup', 'income');
  6217. })
  6218. ->leftJoin('job_enum as years_enum', function ($join) {
  6219. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6220. ->where('years_enum.egroup', 'years');
  6221. })
  6222. // ->where($where)
  6223. ->orderBy('job_recruiting.updated_at', 'desc')
  6224. ->select(
  6225. 'job_recruiting.id',
  6226. 'job_recruiting.title',
  6227. 'job_company.business_name',
  6228. 'income_enum.evalue as salary_evalue',
  6229. 'income_enum.ename as salary_ename',
  6230. 'years_enum.evalue as experience_evalue',
  6231. 'years_enum.ename as experience_ename',
  6232. 'job_recruiting.updated_at'
  6233. )
  6234. ->offset(($data['page'] - 1) * $data['pageSize'])
  6235. ->limit($data['pageSize'])
  6236. ->get()
  6237. ->all();
  6238. if (empty($job)) {
  6239. return Result::error("暂无招聘信息", 0);
  6240. }
  6241. $result = [
  6242. 'row' => $job,
  6243. 'count' => $count,
  6244. ];
  6245. return Result::success($result);
  6246. }
  6247. public function readJobApply(array $data): array
  6248. {
  6249. $result = JobApply::where('id', $data['id'])->first();
  6250. if (empty($result)) {
  6251. return Result::error("查询失败", 0);
  6252. }
  6253. $result = JobApply::where('id', $data['id'])->update([
  6254. 'status' => 2,
  6255. ]);
  6256. return Result::success($result);
  6257. }
  6258. /*
  6259. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6260. * */
  6261. public function getRecruitingList(array $data): array
  6262. {
  6263. $user = User::where('id', $data['user_id'])->first();
  6264. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6265. return Result::error("用户不存在", 0);
  6266. }
  6267. // 1:个人会员 职场机会
  6268. if ($user['type_id'] == 1) {
  6269. $where['user_id'] = $user['id'];
  6270. }
  6271. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6272. $query->where('receiver_id', $user['id']);
  6273. })
  6274. ->pluck('recruit_id');
  6275. // return Result::success($recruitingId);
  6276. $where = [];
  6277. if (isset($data['salary']) && $data['salary'] != null) {
  6278. $where['job_recruiting.salary'] = $data['salary'];
  6279. }
  6280. if (isset($data['experience']) && $data['experience'] != null) {
  6281. $where['job_recruiting.experience'] = $data['experience'];
  6282. }
  6283. if (isset($data['business_name']) && $data['business_name'] != null) {
  6284. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6285. }
  6286. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6287. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6288. ->where($where);
  6289. // ->count();
  6290. $count = $query->count();
  6291. $query = clone $query;
  6292. $job = $query
  6293. ->leftJoin('job_enum as income_enum', function ($join) {
  6294. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6295. ->where('income_enum.egroup', 'income');
  6296. })
  6297. ->leftJoin('job_enum as years_enum', function ($join) {
  6298. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6299. ->where('years_enum.egroup', 'years');
  6300. })
  6301. // ->where($where)
  6302. ->orderBy('job_recruiting.updated_at', 'desc')
  6303. ->select(
  6304. 'job_recruiting.id',
  6305. 'job_recruiting.title',
  6306. 'job_company.business_name',
  6307. 'income_enum.evalue as salary_evalue',
  6308. 'income_enum.ename as salary_ename',
  6309. 'years_enum.evalue as experience_evalue',
  6310. 'years_enum.ename as experience_ename',
  6311. 'job_recruiting.updated_at'
  6312. )
  6313. ->offset(($data['page'] - 1) * $data['pageSize'])
  6314. ->limit($data['pageSize'])
  6315. ->get()
  6316. ->all();
  6317. if (empty($job)) {
  6318. return Result::error("暂无招聘信息", 0);
  6319. }
  6320. $result = [
  6321. 'row' => $job,
  6322. 'count' => $count,
  6323. ];
  6324. return Result::success($result);
  6325. }
  6326. /*
  6327. * 获取企业会员-招聘信息列表
  6328. * */
  6329. public function getRecruitingInfo(array $data): array
  6330. {
  6331. $user = User::where('id', $data['user_id'])->first();
  6332. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6333. return Result::error("用户不存在", 0);
  6334. }
  6335. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6336. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6337. ->select(
  6338. 'job_recruiting.*',
  6339. 'job_company.business_name',
  6340. 'job_company.company_hy_id',
  6341. 'job_company.company_size',
  6342. 'job_company.company_nature',
  6343. 'job_company.introduction',
  6344. 'job_company.real_name',
  6345. 'job_company.mobile',
  6346. 'job_company.company_url',
  6347. 'job_company.address_arr_id',
  6348. 'job_company.address',
  6349. 'job_company.email'
  6350. )
  6351. ->get();
  6352. if (empty($recruiting)) {
  6353. return Result::error("暂无招聘信息", 0);
  6354. }
  6355. return Result::success($recruiting);
  6356. }
  6357. /*
  6358. * 获取企业会员-我的沟通
  6359. * */
  6360. public function getJobResumeList(array $data): array
  6361. {
  6362. $user = User::where('id', $data['user_id'])->first();
  6363. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6364. return Result::error("用户不存在", 0);
  6365. }
  6366. $where = [];
  6367. if (isset($data['salary']) && $data['salary'] != null) {
  6368. $where['job_hunting.salary'] = $data['salary'];
  6369. }
  6370. if (isset($data['user_name']) && $data['user_name'] != null) {
  6371. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6372. }
  6373. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6374. $query->where('job_resume.user_id', $user['id']);
  6375. })
  6376. ->when(!empty($where), function ($query) use ($where) {
  6377. $query->where($where);
  6378. })
  6379. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6380. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6381. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6382. ->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');
  6383. $count = $job->count();
  6384. if ($count == 0) {
  6385. return Result::error("暂无沟通记录", 0);
  6386. }
  6387. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6388. ->offset(($data['page'] - 1) * $data['pageSize'])
  6389. ->limit($data['pageSize'])
  6390. ->get();
  6391. if (empty($jobs)) {
  6392. return Result::error("暂无沟通记录", 0);
  6393. }
  6394. $result['row'] = $this->processJob($jobs, '');
  6395. $result['count'] = $count;
  6396. return Result::success($result);
  6397. }
  6398. public function readJobResume(array $data): array
  6399. {
  6400. $result = JobResume::where('id', $data['id'])->first();
  6401. if (empty($result)) {
  6402. return Result::error("查询失败", 0);
  6403. }
  6404. $result = JobResume::where('id', $data['id'])->update([
  6405. 'status' => 2,
  6406. ]);
  6407. return Result::success($result);
  6408. }
  6409. // 20250306 招聘
  6410. //20250422 书刊音像
  6411. public function addBook(array $data): array
  6412. {
  6413. $user_id = $data['user_id'] ?? 0;
  6414. $type_id = $data['type_id'] ?? 0;
  6415. // $website_id = $data['website_id'] ?? 0;
  6416. // unset($data['user_id']);
  6417. unset($data['type_id']);
  6418. // unset($data['website_id']);
  6419. //处理数组
  6420. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6421. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6422. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6423. if ($data['img_url'] == '') {
  6424. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6425. preg_match_all($reg, $data['detail'], $matches);
  6426. if (isset($matches[1][0])) {
  6427. //截取varchar240
  6428. $data['img_url'] = substr($matches[1][0], 0, 240);
  6429. }
  6430. }
  6431. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6432. //提取标题+内容中的关键词
  6433. $data['keyword'] = $data['title'];
  6434. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6435. Jieba::init(); // 初始化 jieba-php
  6436. Finalseg::init();
  6437. $segList = Jieba::cut($data['keyword']);
  6438. $segList1 = array_slice($segList, 0, 8);
  6439. $data['keyword'] = implode(',', $segList1);
  6440. }
  6441. if ($data['description'] == '') {
  6442. //提取内容中的描述
  6443. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6444. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6445. }
  6446. var_dump($data, '--');
  6447. if ($data['status'] == 1) {
  6448. $this->sendMessage([
  6449. 'talk_type' => 400,
  6450. 'title' => $data['title'],
  6451. 'content' => '提交了审核',
  6452. 'messageType' => 7,
  6453. ]);
  6454. }
  6455. $result = Book::insertGetId($data);
  6456. if (empty($result)) {
  6457. return Result::error("添加失败", 0);
  6458. }
  6459. return Result::success($result);
  6460. }
  6461. public function getBookList(array $data): array
  6462. {
  6463. $where = [];
  6464. if (!empty($data["title"])) {
  6465. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6466. }
  6467. if (!empty($data['website_name'])) {
  6468. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6469. }
  6470. if (!empty($data['status'])) {
  6471. $where[] = ['book.status', '=', $data['status']];
  6472. }
  6473. $user_id = $data['user_id'];
  6474. $type_id = $data['type_id'];
  6475. // $type_id = 4;
  6476. var_dump($type_id, '------1--------');
  6477. if ($type_id != 10000) {
  6478. $where[] = ['book.user_id', '=', $user_id];
  6479. }
  6480. var_dump(!empty($data['status1']), '=-===1');
  6481. $result = Book::where($where)
  6482. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6483. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6484. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6485. ->when(isset($data['status1']), function ($query) use ($data) {
  6486. $query->whereIn('book.status', [1, 3]);
  6487. })
  6488. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6489. ->orderBy("updated_at", "desc")
  6490. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6491. if (empty($result)) {
  6492. return Result::error("暂无数据", 0);
  6493. }
  6494. // 取出数据
  6495. $rows = $result->items();
  6496. $count = $result->total();
  6497. $responseData = [
  6498. 'rows' => $rows,
  6499. 'count' => $count,
  6500. ];
  6501. return Result::success($responseData);
  6502. }
  6503. public function deleteBook(array $data): array
  6504. {
  6505. $result = Book::where('id', $data['id'])->delete();
  6506. if (empty($result)) {
  6507. return Result::error("删除失败", 0);
  6508. }
  6509. return Result::success($result);
  6510. }
  6511. public function updateBook(array $data): array
  6512. {
  6513. // $user_id = $data['user_id'] ?? 0;
  6514. $type_id = $data['type_id'] ?? 0;
  6515. // $website_id = $data['website_id'] ?? 0;
  6516. unset($data['user_id']);
  6517. unset($data['type_id']);
  6518. // unset($data['website_id']);
  6519. //处理数组
  6520. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6521. if ($data['img_url'] == '') {
  6522. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6523. preg_match_all($reg, $data['detail'], $matches);
  6524. if (isset($matches[1][0])) {
  6525. //截取varchar240
  6526. $data['img_url'] = substr($matches[1][0], 0, 240);
  6527. }
  6528. }
  6529. if ($data['keyword'] == '') {
  6530. //提取标题+内容中的关键词
  6531. $data['keyword'] = $data['title'];
  6532. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6533. Jieba::init(); // 初始化 jieba-php
  6534. Finalseg::init();
  6535. $segList = Jieba::cut($data['keyword']);
  6536. $segList1 = array_slice($segList, 0, 8);
  6537. $data['keyword'] = implode(',', $segList1);
  6538. }
  6539. if ($data['description'] == '') {
  6540. //提取内容中的描述
  6541. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6542. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6543. }
  6544. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6545. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6546. if ($data['status'] == 1) {
  6547. $this->sendMessage([
  6548. 'talk_type' => 400,
  6549. 'title' => $data['title'],
  6550. 'content' => '提交了审核',
  6551. 'messageType' => 7,
  6552. ]);
  6553. }
  6554. $result = Book::where("id", $data["id"])->update($data);
  6555. if (empty($result)) {
  6556. return Result::error("更新失败", 0);
  6557. }
  6558. return Result::success($result);
  6559. }
  6560. public function getBookInfo(array $data): array
  6561. {
  6562. $result = Book::where("id", $data["id"])->first();
  6563. if (empty($result)) {
  6564. return Result::error("获取失败", 0);
  6565. }
  6566. return Result::success($result);
  6567. }
  6568. public function updateBookStatus(array $data): array
  6569. {
  6570. //审核
  6571. unset($data['user_id']);
  6572. $bookInfo = Book::where("id", $data["id"])->first();
  6573. var_dump($bookInfo, '----');
  6574. if ($data['status'] == 2) {
  6575. $this->sendMessage([
  6576. 'talk_type' => 401,
  6577. 'title' => $bookInfo['title'],
  6578. 'content' => '审核通过',
  6579. 'messageType' => 7,
  6580. 'user_id' => $bookInfo['user_id'],
  6581. ]);
  6582. }
  6583. if ($data['status'] == 3) {
  6584. $this->sendMessage([
  6585. 'talk_type' => 401,
  6586. 'title' => $bookInfo['title'],
  6587. 'content' => '审核拒绝',
  6588. 'messageType' => 7,
  6589. 'user_id' => $bookInfo['user_id'],
  6590. ]);
  6591. }
  6592. if ($data['status'] == 1) {
  6593. $this->sendMessage([
  6594. 'talk_type' => 400,
  6595. 'title' => $bookInfo['title'],
  6596. 'content' => '提交了审核',
  6597. 'messageType' => 7,
  6598. // 'user_id'=>$bookInfo['user_id'],
  6599. ]);
  6600. }
  6601. $result = Book::where("id", $data["id"])->update($data);
  6602. if (empty($result)) {
  6603. return Result::error("更新失败", 0);
  6604. }
  6605. return Result::success($result);
  6606. }
  6607. //20250422 书刊音像
  6608. /**
  6609. * 贴身宝贝
  6610. * @param array $data
  6611. * @return array
  6612. */
  6613. public function getWebsiteTsbb(array $data): array
  6614. {
  6615. $month = $data['month'] ?? date('m');
  6616. $day = $data['day'] ?? date('d');
  6617. // 使用缓存键
  6618. $cacheKey = "tsbb_data_{$month}_{$day}";
  6619. // 尝试从缓存获取数据
  6620. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6621. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6622. if ($cachedData = $cache->get($cacheKey)) {
  6623. return Result::success(unserialize($cachedData));
  6624. }
  6625. //查询老黄历
  6626. try {
  6627. $date = date('Y-m-d');
  6628. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6629. // 使用 curl 替代 file_get_contents
  6630. $ch = curl_init();
  6631. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6632. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6633. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6634. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6635. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6636. 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');
  6637. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6638. 'Accept: application/json',
  6639. 'Content-Type: application/json',
  6640. 'Referer: https://www.36jxs.com/'
  6641. ]);
  6642. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6643. curl_setopt($ch, CURLOPT_ENCODING, '');
  6644. $almanacResponse = curl_exec($ch);
  6645. var_dump("====:", $almanacResponse);
  6646. if (curl_errno($ch)) {
  6647. var_dump('Curl error:', curl_error($ch));
  6648. throw new \Exception('Curl error: ' . curl_error($ch));
  6649. }
  6650. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6651. curl_close($ch);
  6652. if ($almanacResponse === false) {
  6653. throw new \Exception('Failed to fetch almanac data');
  6654. }
  6655. $almanacData = json_decode($almanacResponse, true);
  6656. if (json_last_error() !== JSON_ERROR_NONE) {
  6657. throw new \Exception('Failed to parse almanac data');
  6658. }
  6659. $almanacInfo = $almanacData['data'] ?? [];
  6660. } catch (\Exception $e) {
  6661. var_dump('Exception:', $e->getMessage());
  6662. $almanacInfo = [];
  6663. }
  6664. // 获取历史上的今天数据
  6665. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6666. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6667. ->orderBy('year', 'asc')
  6668. ->select("title", "id", "year", DB::raw('1 as type'))
  6669. ->limit(16)
  6670. ->get();
  6671. // 获取节日数据 - 从今天开始获取未来4条
  6672. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6673. ->orderBy('showtime', 'asc')
  6674. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6675. ->limit(16)
  6676. ->get();
  6677. //说文解字
  6678. $chartacterList = Character::orderBy('updated_at', 'desc')
  6679. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6680. ->limit(6)
  6681. ->get();
  6682. //谜语沙龙
  6683. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6684. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6685. ->limit(4)
  6686. ->get();
  6687. //成语欣赏
  6688. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6689. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6690. ->limit(32)
  6691. ->get();
  6692. //名联赏析
  6693. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6694. ->select("id", "first", "second", DB::raw('6 as type'))
  6695. ->limit(6)
  6696. ->get();
  6697. // 获取分类文章数据
  6698. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6699. ->pluck('category_id')
  6700. ->toArray();
  6701. $articlesList = [];
  6702. foreach ($categoryIds as $catid) {
  6703. // 先查有图片的
  6704. $withImg = DB::table('article')
  6705. ->where('status', 1)
  6706. ->where('catid', $catid)
  6707. ->whereNotNull('imgurl')
  6708. ->where('imgurl', '!=', '')
  6709. ->orderBy('updated_at', 'desc')
  6710. ->limit(6)
  6711. ->get();
  6712. $count = $withImg->count();
  6713. if ($count < 6) {
  6714. // 不足6条再查无图片的补足
  6715. $withoutImg = DB::table('article')
  6716. ->where('status', 1)
  6717. ->where('catid', $catid)
  6718. ->where(function ($q) {
  6719. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6720. })
  6721. ->orderBy('updated_at', 'desc')
  6722. ->limit(6 - $count)
  6723. ->get();
  6724. $articles = $withImg->concat($withoutImg);
  6725. } else {
  6726. $articles = $withImg;
  6727. }
  6728. // 组装
  6729. $category = \App\Model\Category::find($catid);
  6730. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6731. $articlesList[] = [
  6732. 'category_name' => $category ? $category->name : '',
  6733. 'catid' => $catid,
  6734. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6735. 'type' => 100,
  6736. 'list' => $articles->map(function ($item) {
  6737. return [
  6738. 'id' => $item->id,
  6739. 'title' => $item->title,
  6740. 'imgurl' => $item->imgurl,
  6741. 'created_at' => $item->created_at
  6742. ];
  6743. })->values()
  6744. ];
  6745. }
  6746. $result = [
  6747. 'almanac' => $almanacInfo,
  6748. 'historyTodayList' => [
  6749. 'category_name' => '历史上的今天',
  6750. 'list' => $historyTodayList,
  6751. 'type' => 1
  6752. ],
  6753. 'festivalList' => [
  6754. 'category_name' => '节日预告',
  6755. 'list' => $festivalList,
  6756. 'type' => 2
  6757. ],
  6758. 'chartacterList' => [
  6759. 'category_name' => '说文解字',
  6760. 'list' => $chartacterList,
  6761. 'type' => 3
  6762. ],
  6763. 'coupletList' => [
  6764. 'category_name' => '名联赏析',
  6765. 'list' => $coupletList,
  6766. 'type' => 6
  6767. ],
  6768. 'riddletList' => [
  6769. 'category_name' => '谜语沙龙',
  6770. 'list' => $riddletList,
  6771. 'type' => 4
  6772. ],
  6773. 'idiomList' => [
  6774. 'category_name' => '成语欣赏',
  6775. 'list' => $idiomList,
  6776. 'type' => 5
  6777. ],
  6778. 'articlesList' => $articlesList
  6779. ];
  6780. // 缓存结果,设置1小时过期
  6781. $cache->set($cacheKey, serialize($result), 3600);
  6782. return Result::success($result);
  6783. }
  6784. /**
  6785. * 获取资讯列表
  6786. */
  6787. public function getWebsiteTsbbList(array $data): array
  6788. {
  6789. $page = $data['page'] ?? 1;
  6790. $pageSize = $data['pageSize'] ?? 10;
  6791. // 如果没有传入月份和日期,则使用今天的日期
  6792. $month = $data['month'] ?? date('m');
  6793. $day = $data['day'] ?? date('d');
  6794. $total = 0;
  6795. $result = [];
  6796. $data['type'] = intval($data['type']);
  6797. var_dump("接收参数:", $data);
  6798. switch ($data['type']) {
  6799. case 1:
  6800. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6801. // 当前月份之后的数据
  6802. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6803. // 或者当前月份且日期大于等于当前日期的数据
  6804. ->orWhere(function ($q) use ($month, $day) {
  6805. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6806. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6807. });
  6808. })
  6809. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6810. $total = $query->count();
  6811. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6812. ->offset(($page - 1) * $pageSize)
  6813. ->limit($pageSize)
  6814. ->get();
  6815. break;
  6816. case 2:
  6817. $query = Festival::where(function ($q) use ($month, $day) {
  6818. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6819. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6820. ->orWhere(function ($q) use ($month, $day) {
  6821. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6822. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6823. });
  6824. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6825. $total = $query->count();
  6826. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6827. ->offset(($page - 1) * $pageSize)
  6828. ->limit($pageSize)
  6829. ->get();
  6830. break;
  6831. case 3:
  6832. $query = Character::orderBy("updated_at", "desc");
  6833. $total = $query->count();
  6834. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6835. ->offset(($page - 1) * $pageSize)
  6836. ->limit($pageSize)
  6837. ->get();
  6838. break;
  6839. case 4:
  6840. $query = Riddle::orderBy("updated_at", "desc");
  6841. $total = $query->count();
  6842. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6843. ->offset(($page - 1) * $pageSize)
  6844. ->limit($pageSize)
  6845. ->get();
  6846. break;
  6847. case 5:
  6848. $query = Idiom::orderBy("updated_at", "desc");
  6849. $total = $query->count();
  6850. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6851. ->offset(($page - 1) * $pageSize)
  6852. ->limit($pageSize)
  6853. ->get();
  6854. break;
  6855. case 6:
  6856. $query = Couplet::orderBy("updated_at", "desc");
  6857. $total = $query->count();
  6858. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6859. ->offset(($page - 1) * $pageSize)
  6860. ->limit($pageSize)
  6861. ->get();
  6862. break;
  6863. default:
  6864. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6865. $total = $query->count();
  6866. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6867. ->offset(($page - 1) * $pageSize)
  6868. ->limit($pageSize)
  6869. ->get();
  6870. }
  6871. return Result::success([
  6872. 'list' => $result,
  6873. 'total' => $total,
  6874. 'page' => (int)$page,
  6875. 'pageSize' => (int)$pageSize,
  6876. 'month' => $month,
  6877. 'day' => $day
  6878. ]);
  6879. }
  6880. /**
  6881. * 1:历史上的今天
  6882. * 2:节日
  6883. * 3:文章
  6884. *
  6885. * 资讯详情信息
  6886. */
  6887. public function getWebsiteTsbbDetail(array $data): array
  6888. {
  6889. $data['type'] = intval($data['type']);
  6890. switch ($data['type']) {
  6891. case 1:
  6892. $result = HistoryToday::where("id", $data['id'])->first();
  6893. break;
  6894. case 2:
  6895. $result = Festival::where("id", $data['id'])->first();
  6896. break;
  6897. case 3:
  6898. $result = Character::where("id", $data['id'])->first();
  6899. break;
  6900. case 4:
  6901. $result = Riddle::where("id", $data['id'])->first();
  6902. break;
  6903. case 5:
  6904. $result = Idiom::where("id", $data['id'])->first();
  6905. break;
  6906. case 6:
  6907. $result = Couplet::where("id", $data['id'])->first();
  6908. break;
  6909. default:
  6910. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6911. break;
  6912. }
  6913. return Result::success($result);
  6914. }
  6915. /**
  6916. * 农网导航首页数据
  6917. */
  6918. public function getWebsiteNwHomeList(array $data): array
  6919. {
  6920. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6921. ->pluck('category_id')
  6922. ->toArray();
  6923. // 使用子查询优化
  6924. $articlesList = DB::table('article')
  6925. ->select([
  6926. 'article.id',
  6927. 'article.title',
  6928. 'article.imgurl',
  6929. 'article.created_at',
  6930. 'category.name as category_name',
  6931. 'category.id as category_id',
  6932. 'website_category.aLIas_pinyin as pinyin',
  6933. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6934. DB::raw('100 as type')
  6935. ])
  6936. ->join('category', 'article.catid', '=', 'category.id')
  6937. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6938. ->leftJoin('website_category as parent_wc', function ($join) {
  6939. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6940. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6941. })
  6942. ->where('website_category.website_id', $data['website_id'])
  6943. ->where('article.status', 1)
  6944. ->whereIn('category.id', $categoryIds)
  6945. ->orderBy('article.created_at', 'desc')
  6946. ->get()
  6947. ->groupBy('category_id')
  6948. ->map(function ($group) {
  6949. // 确保第一条数据有图片
  6950. $firstWithImage = $group->first(function ($item) {
  6951. return !empty($item->imgurl);
  6952. });
  6953. if ($firstWithImage) {
  6954. // 如果有带图片的文章,将其放在第一位
  6955. $group = $group->filter(function ($item) use ($firstWithImage) {
  6956. return $item->id !== $firstWithImage->id;
  6957. })->prepend($firstWithImage);
  6958. }
  6959. return [
  6960. 'category_name' => $group->first()->category_name,
  6961. 'catid' => $group->first()->category_id,
  6962. 'pinyin' => $group->first()->pinyin,
  6963. 'parent_pinyin' => $group->first()->parent_pinyin,
  6964. 'list' => $group->take(4)->map(function ($item) {
  6965. return [
  6966. 'id' => $item->id,
  6967. 'title' => $item->title,
  6968. ];
  6969. })->values()
  6970. ];
  6971. })
  6972. ->values()
  6973. ->toArray();
  6974. return Result::success($articlesList);
  6975. }
  6976. /**
  6977. * 企业管理
  6978. * @param array $data
  6979. * @return array
  6980. */
  6981. public function getCompanyList(array $data): array
  6982. {
  6983. // return Result::success($data);
  6984. $where = [];
  6985. $user = User::where('id', $data['user_id'])->first();
  6986. if (empty($user)) {
  6987. return Result::error('用户不存在!');
  6988. }
  6989. if ($user['type_id'] != 10000) {
  6990. $where['user_id'] = $data['user_id'];
  6991. }
  6992. if (isset($data['title']) && !empty($data['title'])) {
  6993. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6994. }
  6995. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6996. array_push($where, ['website.id', $data['website_id']]);
  6997. }
  6998. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6999. if ($data['ischeck'] == 1) {
  7000. if (isset($data['status']) && $data['status'] != '') {
  7001. array_push($where, ['company.status', $data['status']]);
  7002. $query = Company::where($where);
  7003. } else {
  7004. $query = Company::whereIn('company.status', [0, 2]);
  7005. }
  7006. } else {
  7007. $query = Company::where('company.status', 1);
  7008. }
  7009. }
  7010. $result = $query->where($where)
  7011. ->leftJoin('website_category', function ($query) {
  7012. $query->on('website_category.category_id', '=', 'company.category_id')
  7013. ->on('website_category.website_id', '=', 'company.website_id');
  7014. })
  7015. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7016. ->select(
  7017. 'company.id',
  7018. 'company.title',
  7019. 'company.website_id',
  7020. 'company.category_id',
  7021. 'website.website_name',
  7022. 'website_category.alias as category_name',
  7023. 'company.status',
  7024. 'company.updated_at',
  7025. 'company.user_id'
  7026. )
  7027. ->orderBy('company.updated_at', 'desc')
  7028. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7029. if ($result->isEmpty()) {
  7030. return Result::error("暂无企业", 0);
  7031. }
  7032. return Result::success($result);
  7033. }
  7034. /**
  7035. * 添加企业
  7036. * @param array $data
  7037. * @return array
  7038. */
  7039. public function addCompany(array $data): array
  7040. {
  7041. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7042. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7043. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7044. $data['cat_arr_id'] = json_encode($car_arr_id);
  7045. } else {
  7046. $data['cat_arr_id'] = '';
  7047. }
  7048. if ($data['imgurl'] == '') {
  7049. //content中提取图片第一个图,正则提取
  7050. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7051. preg_match_all($reg, $data['content'], $matches);
  7052. if (isset($matches[1][0])) {
  7053. //截取varchar240
  7054. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7055. }
  7056. }
  7057. if ($data['keyword'] == '') {
  7058. //提取标题+内容中的关键词
  7059. $data['keyword'] = $data['title'];
  7060. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7061. Jieba::init(); // 初始化 jieba-php
  7062. Finalseg::init();
  7063. $segList = Jieba::cut($data['keyword']);
  7064. $segList1 = array_slice($segList, 0, 8);
  7065. $data['keyword'] = implode(',', $segList1);
  7066. }
  7067. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7068. //提取内容中的描述
  7069. $content = $data['content'];
  7070. // 去除 <style> 和 <script> 标签及其内容
  7071. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7072. // 去除所有 HTML 标签
  7073. $content = strip_tags($content);
  7074. // 去除 HTML 实体
  7075. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7076. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7077. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7078. // 去除多余空白
  7079. $content = preg_replace('/\s+/u', '', $content);
  7080. // 截取 100 个字符
  7081. $data['introduce'] = mb_substr($content, 0, 100);
  7082. }
  7083. $user = User::where('id', $data['user_id'])->first();
  7084. if (empty($user)) {
  7085. return Result::error('用户不存在!');
  7086. }
  7087. if ($user['type_id'] == 10000) {
  7088. $data['status'] = 1;
  7089. }
  7090. if (isset($data['level']) && $data['level'] != null) {
  7091. $data['level'] = intval($data['level']);
  7092. } else {
  7093. $data['level'] = null;
  7094. }
  7095. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7096. $this->sendMessage([
  7097. 'talk_type' => 900,
  7098. 'title' => $data['title'],
  7099. 'content' => '提交了审核',
  7100. 'messageType' => 8,
  7101. ]);
  7102. }
  7103. $result = Company::insertGetId($data);
  7104. if ($result) {
  7105. return Result::success($result);
  7106. } else {
  7107. return Result::error('添加失败');
  7108. }
  7109. }
  7110. /**
  7111. * 更新企业
  7112. * @param array $data
  7113. * @return array
  7114. */
  7115. public function upCompany(array $data): array
  7116. {
  7117. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7118. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7119. $data['cat_arr_id'] = json_encode($car_arr_id);
  7120. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7121. } else {
  7122. $data['cat_arr_id'] = '';
  7123. }
  7124. if ($data['imgurl'] == '') {
  7125. //content中提取图片第一个图,正则提取
  7126. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7127. preg_match_all($reg, $data['content'], $matches);
  7128. if (isset($matches[1][0])) {
  7129. //截取varchar
  7130. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7131. }
  7132. }
  7133. if ($data['keyword'] == '') {
  7134. //提取标题+内容中的关键词
  7135. $data['keyword'] = $data['title'];
  7136. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7137. Jieba::init(); // 初始化 jieba-php
  7138. Finalseg::init();
  7139. $segList = Jieba::cut($data['keyword']);
  7140. $segList1 = array_slice($segList, 0, 8);
  7141. $data['keyword'] = implode(',', $segList1);
  7142. }
  7143. if ($data['introduce'] == '') {
  7144. //提取内容中的描述
  7145. $content = $data['content'];
  7146. // 去除 <style> 和 <script> 标签及其内容
  7147. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7148. // 去除所有 HTML 标签
  7149. $content = strip_tags($content);
  7150. // 去除 HTML 实体
  7151. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7152. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7153. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7154. // 去除多余空白
  7155. $content = preg_replace('/\s+/u', '', $content);
  7156. // 截取 100 个字符
  7157. $data['introduce'] = mb_substr($content, 0, 100);
  7158. }
  7159. if (isset($data['level']) && $data['level'] != null) {
  7160. $data['level'] = intval($data['level']);
  7161. } else {
  7162. $data['level'] = null;
  7163. }
  7164. $user = User::where('id', $data['user_id'])->first();
  7165. if (empty($user)) {
  7166. return Result::error('用户不存在!');
  7167. }
  7168. if ($user['type_id'] == 10000) {
  7169. $data['status'] = 1;
  7170. } else {
  7171. $data['status'] = 0;
  7172. }
  7173. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7174. $this->sendMessage([
  7175. 'talk_type' => 900,
  7176. 'title' => $data['title'],
  7177. 'content' => '提交了审核',
  7178. 'messageType' => 8,
  7179. ]);
  7180. }
  7181. $result = Company::where('id', $data['id'])->update($data);
  7182. if ($result) {
  7183. return Result::success($result);
  7184. } else {
  7185. return Result::error('修改失败');
  7186. }
  7187. }
  7188. /**
  7189. * 删除企业
  7190. * @param array $data
  7191. * @return array
  7192. */
  7193. public function delCompany(array $data): array
  7194. {
  7195. $result = Company::where('id', $data['id'])->delete();
  7196. if ($result) {
  7197. return Result::success($result);
  7198. } else {
  7199. return Result::error('删除失败');
  7200. }
  7201. }
  7202. /**
  7203. * 审核企业
  7204. * @param array $data
  7205. * @return array
  7206. */
  7207. public function checkCompany(array $data): array
  7208. {
  7209. $user = User::where('id', $data['user_id'])->first();
  7210. if (empty($user)) {
  7211. return Result::error('用户不存在!');
  7212. }
  7213. $company = Company::where('id', $data['id'])->first();
  7214. if (empty($company)) {
  7215. return Result::error('企业不存在!');
  7216. }
  7217. // 状态:0:未审核 1:已审核 2:已拒绝
  7218. if ($data['status'] == 2 || $data['status'] == '2') {
  7219. $this->sendMessage([
  7220. 'talk_type' => 901,
  7221. 'title' => $company['title'],
  7222. 'content' => '审核拒绝',
  7223. 'messageType' => 8,
  7224. 'user_id' => $company['user_id'],
  7225. ]);
  7226. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7227. } else {
  7228. if ($data['status'] == 1) {
  7229. $this->sendMessage([
  7230. 'talk_type' => 901,
  7231. 'title' => $company['title'],
  7232. 'content' => '审核通过',
  7233. 'messageType' => 8,
  7234. 'user_id' => $company['user_id'],
  7235. ]);
  7236. } else if ($data['status'] == 0) {
  7237. $this->sendMessage([
  7238. 'talk_type' => 900,
  7239. 'title' => $company['title'],
  7240. 'content' => '提交了审核',
  7241. 'messageType' => 8,
  7242. ]);
  7243. }
  7244. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7245. }
  7246. if (empty($result)) {
  7247. return Result::error('审核失败!');
  7248. } else {
  7249. return Result::success($result);
  7250. }
  7251. }
  7252. /**
  7253. * 获取企业信息
  7254. * @param array $data
  7255. * @return array
  7256. */
  7257. public function getCompanyInfo(array $data): array
  7258. {
  7259. $result = Company::where('id', $data['id'])->first();
  7260. $city_arr = json_decode($result['city_arr_id']);
  7261. $result['city_name'] = District::whereIn('id', $city_arr)
  7262. ->pluck('name')
  7263. ->implode('-');
  7264. if (empty($result)) {
  7265. return Result::error('企业不存在!');
  7266. } else {
  7267. return Result::success($result);
  7268. }
  7269. }
  7270. /**
  7271. * @param array $data
  7272. * @return array
  7273. */
  7274. public function getWebsiteCompany(array $data): array
  7275. {
  7276. $categorys = json_decode($data['id'], true);
  7277. $category_arr = $this->processArticlePro($data['website_id']);
  7278. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7279. $catiall = $category_arr['catiall'];
  7280. $categoryIds = $category_arr['categoryIds'];
  7281. // return Result::success($category_arr);
  7282. foreach ($categorys as $key => $value) {
  7283. if (array_key_exists('level', $value)) {
  7284. $parts = explode(',', $value['level']);
  7285. $level = $parts[0] ?? null;
  7286. $imgnum = $parts[1] ?? null;
  7287. $textnum = $parts[2] ?? null;
  7288. if (!empty($textnum) && $textnum > 0) {
  7289. $text_num = Company::where('level', $level)
  7290. ->whereIn('category_id', $categoryIds)
  7291. ->where('status', 1)
  7292. ->select(
  7293. 'company.id',
  7294. 'company.title',
  7295. 'company.description',
  7296. 'company.updated_at',
  7297. 'company.category_id',
  7298. 'company.cat_arr_id'
  7299. )
  7300. ->orderBy('updated_at', 'desc')
  7301. ->limit($textnum)
  7302. ->get()->all();
  7303. }
  7304. if (!empty($imgnum) && $imgnum > 0) {
  7305. $img_num = Company::where('level', $level)
  7306. ->whereIn('category_id', $categoryIds)
  7307. ->where('status', 1)
  7308. ->where('imgurl', '!=', '')
  7309. ->whereNotNull('imgurl')
  7310. ->select(
  7311. 'company.id',
  7312. 'company.title',
  7313. 'company.description',
  7314. 'company.updated_at',
  7315. 'company.imgurl as imgs',
  7316. 'company.category_id',
  7317. 'company.cat_arr_id'
  7318. )
  7319. ->orderBy('updated_at', 'desc')
  7320. ->limit($imgnum)
  7321. ->get()->all();
  7322. }
  7323. }
  7324. if (array_key_exists('id', $value)) {
  7325. $parts = explode(',', $value['id']);
  7326. $category_id = $parts[0] ?? null;
  7327. $imgnum = $parts[1] ?? null;
  7328. $textnum = $parts[2] ?? null;
  7329. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7330. if (!empty($textnum) && $textnum > 0) {
  7331. $text_num = Company::whereIn('category_id', $category_arr)
  7332. // ->where('website_id', $data['website_id'])
  7333. ->where('status', 1)
  7334. ->select(
  7335. 'company.id',
  7336. 'company.title',
  7337. 'company.description',
  7338. 'company.updated_at',
  7339. 'company.category_id',
  7340. 'company.cat_arr_id'
  7341. )
  7342. ->orderBy('updated_at', 'desc')
  7343. ->limit($textnum)
  7344. ->get()->all();
  7345. }
  7346. if (!empty($imgnum) && $imgnum > 0) {
  7347. $img_num = Company::whereIn('category_id', $category_arr)
  7348. // ->where('website_id', $data['website_id'])
  7349. ->where('status', 1)
  7350. ->where('imgurl', '!=', '')
  7351. ->whereNotNull('imgurl')
  7352. ->select(
  7353. 'company.id',
  7354. 'company.title',
  7355. 'company.description',
  7356. 'company.updated_at',
  7357. 'company.imgurl as imgs',
  7358. 'company.category_id',
  7359. 'company.cat_arr_id'
  7360. )
  7361. ->orderBy('updated_at', 'desc')
  7362. ->limit($imgnum)
  7363. ->get()->all();
  7364. }
  7365. }
  7366. if (!empty($text_num)) {
  7367. foreach ($text_num as $k => $v) {
  7368. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7369. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7370. }
  7371. }
  7372. if (!empty($img_num)) {
  7373. foreach ($img_num as $k => $v) {
  7374. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7375. $imgurl = json_decode($v['imgs'], true);
  7376. if (!empty($imgurl)) {
  7377. $img_num[$k]->imgurl = $imgurl[0];
  7378. }
  7379. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7380. }
  7381. }
  7382. $company[$key]['img_num'] = $img_num ?? [];
  7383. $company[$key]['text_num'] = $text_num ?? [];
  7384. }
  7385. if (empty($company)) {
  7386. return Result::error("暂无相关企业信息", 0);
  7387. }
  7388. return Result::success($company);
  7389. }
  7390. /**
  7391. * @param array $data
  7392. * @return array
  7393. */
  7394. public function getWebsiteCompanyList(array $data): array
  7395. {
  7396. $where['website_id'] = $data['website_id'];
  7397. $where['status'] = 1;
  7398. $categoryIds = [];
  7399. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7400. $category_id = $data['category_id'];
  7401. }
  7402. $category_arr = $this->processArticlePro($data['website_id']);
  7403. $categoryIds = $category_arr['categoryIds'];
  7404. // return Result::success($cat_1st_arr);
  7405. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7406. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7407. })
  7408. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7409. $query->whereIn('category_id', $categoryIds);
  7410. })
  7411. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7412. $query->where('category_id', $category_id);
  7413. })
  7414. ->where('status',1)
  7415. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7416. ->orderBy('updated_at', 'desc')
  7417. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7418. if (empty($company)) {
  7419. return Result::error("暂无相关公司信息", 0);
  7420. }
  7421. $result = [
  7422. 'count' => $company->total(),
  7423. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7424. ];
  7425. return Result::success($result);
  7426. }
  7427. /**
  7428. * 获取项目列表
  7429. * @param array $data
  7430. * @return array
  7431. */
  7432. public function getProjectList(array $data): array
  7433. {
  7434. $where = [];
  7435. $user = User::where('id', $data['user_id'])->first();
  7436. if (empty($user)) {
  7437. return Result::error('用户不存在!');
  7438. }
  7439. if ($user->type_id != 10000) {
  7440. array_push($where, ['project.user_id', $data['user_id']]);
  7441. }
  7442. $query = Project::query();
  7443. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7444. array_push($where, ['project.website_id', $data['website_id']]);
  7445. }
  7446. if (isset($data['title']) && !empty($data['title'])) {
  7447. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7448. }
  7449. if ($data['status'] != 3) {
  7450. array_push($where, ['project.status', $data['status']]);
  7451. }
  7452. $query = Project::where($where)
  7453. ->when($data['status'] == 3, function ($query) {
  7454. $query->whereIn('project.status', [0, 2]);
  7455. });
  7456. $count = $query->clone()
  7457. ->count();
  7458. $rows = $query->clone()
  7459. ->leftJoin('website', 'project.website_id', 'website.id')
  7460. ->leftJoin('website_category', function ($join) {
  7461. $join->on('project.website_id', '=', 'website_category.website_id')
  7462. ->on('project.category_id', '=', 'website_category.category_id');
  7463. })
  7464. ->select(
  7465. 'project.id',
  7466. 'project.title',
  7467. 'project.updated_at',
  7468. 'project.status',
  7469. 'website.website_name',
  7470. 'website_category.alias as category_name',
  7471. 'project.website_id',
  7472. 'project.user_id'
  7473. )
  7474. ->orderBy('project.updated_at', 'desc')
  7475. ->offset(($data['page'] - 1) * $data['pageSize'])
  7476. ->limit($data['pageSize'])
  7477. ->get();
  7478. if ($rows->isEmpty()) {
  7479. return Result::error("暂无相关项目信息", 0);
  7480. }
  7481. $result = [
  7482. 'count' => $count,
  7483. 'rows' => $rows,
  7484. ];
  7485. return Result::success($result);
  7486. }
  7487. /**
  7488. * 添加项目
  7489. * @param array $data
  7490. * @return array
  7491. */
  7492. public function addProject(array $data): array
  7493. {
  7494. $user = User::where('id', $data['user_id'])->first();
  7495. if (empty($user)) {
  7496. return Result::error("暂无相关用户信息", 0);
  7497. }
  7498. if ($user->type_id == 10000) {
  7499. $data['status'] = 1;
  7500. } else {
  7501. $data['status'] = 0;
  7502. }
  7503. if ($data['keyword'] == '') {
  7504. //提取标题+内容中的关键词
  7505. $data['keyword'] = $data['title'];
  7506. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7507. Jieba::init(); // 初始化 jieba-php
  7508. Finalseg::init();
  7509. $segList = Jieba::cut($data['keyword']);
  7510. $segList1 = array_slice($segList, 0, 8);
  7511. $data['keyword'] = implode(',', $segList1);
  7512. }
  7513. if ($data['description'] == '') {
  7514. //提取内容中的描述
  7515. // var_dump(11111);
  7516. //提取内容中的描述
  7517. $content = $data['introduce'];
  7518. // 去除 <style> 和 <script> 标签及其内容
  7519. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7520. // 去除所有 HTML 标签
  7521. $content = strip_tags($content);
  7522. // 去除 HTML 实体
  7523. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7524. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7525. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7526. // 去除多余空白
  7527. $content = preg_replace('/\s+/u', '', $content);
  7528. // 截取 100 个字符
  7529. $data['description'] = mb_substr($content, 0, 100);
  7530. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7531. }
  7532. if ($data['status'] == 0) {
  7533. $this->sendMessage([
  7534. 'talk_type' => 1000,
  7535. 'title' => $data['title'],
  7536. 'content' => '提交了审核',
  7537. 'messageType' => 9,
  7538. ]);
  7539. }
  7540. $project = Project::insertGetId($data);
  7541. if (empty($project)) {
  7542. return Result::error("暂无相关项目信息", 0);
  7543. }
  7544. return Result::success($project);
  7545. }
  7546. /**
  7547. * 更新项目
  7548. * @param array $data
  7549. * @return array
  7550. */
  7551. public function upProject(array $data): array
  7552. {
  7553. $project = Project::where('id', $data['id'])->first();
  7554. if (empty($project)) {
  7555. return Result::error("暂无相关项目信息", 0);
  7556. }
  7557. $id = $data['id'];
  7558. unset($data['id']);
  7559. $user = User::where('id', $data['user_id'])->first();
  7560. if (empty($user)) {
  7561. return Result::error("暂无相关用户信息", 0);
  7562. }
  7563. if ($user->type_id == 10000) {
  7564. $data['status'] = 1;
  7565. } else {
  7566. $data['status'] = 0;
  7567. }
  7568. unset($data['user_id']);
  7569. if ($data['keyword'] == '') {
  7570. //提取标题+内容中的关键词
  7571. $data['keyword'] = $data['title'];
  7572. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7573. Jieba::init(); // 初始化 jieba-php
  7574. Finalseg::init();
  7575. $segList = Jieba::cut($data['keyword']);
  7576. $segList1 = array_slice($segList, 0, 8);
  7577. $data['keyword'] = implode(',', $segList1);
  7578. }
  7579. if ($data['description'] == '') {
  7580. //提取内容中的描述
  7581. // var_dump(11111);
  7582. //提取内容中的描述
  7583. $content = $data['introduce'];
  7584. // 去除 <style> 和 <script> 标签及其内容
  7585. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7586. // 去除所有 HTML 标签
  7587. $content = strip_tags($content);
  7588. // 去除 HTML 实体
  7589. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7590. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7591. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7592. // 去除多余空白
  7593. $content = preg_replace('/\s+/u', '', $content);
  7594. // 截取 100 个字符
  7595. $data['description'] = mb_substr($content, 0, 100);
  7596. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7597. }
  7598. if ($data['status'] == 0) {
  7599. $this->sendMessage([
  7600. 'talk_type' => 1000,
  7601. 'title' => $data['title'],
  7602. 'content' => '提交了审核',
  7603. 'messageType' => 9,
  7604. ]);
  7605. }
  7606. $result = Project::where('id', $id)->update($data);
  7607. if (empty($result)) {
  7608. return Result::error("更新失败", 0);
  7609. }
  7610. return Result::success($result);
  7611. }
  7612. /**
  7613. * 删除项目
  7614. * @param array $data
  7615. * @return array
  7616. */
  7617. public function delProject(array $data): array
  7618. {
  7619. $user = User::where('id', $data['user_id'])->first();
  7620. if (empty($user)) {
  7621. return Result::error("暂无相关用户信息", 0);
  7622. }
  7623. $project = Project::where('id', $data['id'])->first();
  7624. if (empty($project)) {
  7625. return Result::error("暂无相关项目信息", 0);
  7626. }
  7627. $result = Project::where('id', $data['id'])->delete();
  7628. if (empty($result)) {
  7629. return Result::error("删除失败", 0);
  7630. }
  7631. return Result::success($result);
  7632. }
  7633. /**
  7634. * 审核项目
  7635. * @param array $data
  7636. * @return array
  7637. */
  7638. public function checkProject(array $data): array
  7639. {
  7640. $user = User::where('id', $data['user_id'])->first();
  7641. if (empty($user)) {
  7642. return Result::error("暂无相关用户信息", 0);
  7643. }
  7644. // 0:未审核; 1:已审核; 2:已拒绝;
  7645. if ($user->type_id != 10000) {
  7646. if ($data['status'] == 1 || $data['status'] == 2) {
  7647. return Result::error("此用户权限不足", 0);
  7648. }
  7649. }
  7650. $project = Project::where('id', $data['id'])->first();
  7651. if (empty($project)) {
  7652. return Result::error("暂无相关项目信息", 0);
  7653. }
  7654. if ($data['status'] == 2) {
  7655. $this->sendMessage([
  7656. 'talk_type' => 1001,
  7657. 'title' => $project['title'],
  7658. 'content' => '审核拒绝',
  7659. 'messageType' => 9,
  7660. 'user_id' => $project['user_id'],
  7661. ]);
  7662. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7663. } else {
  7664. if ($data['status'] == 1) {
  7665. $this->sendMessage([
  7666. 'talk_type' => 1001,
  7667. 'title' => $project['title'],
  7668. 'content' => '审核通过',
  7669. 'messageType' => 9,
  7670. 'user_id' => $project['user_id'],
  7671. ]);
  7672. } else if ($data['status'] == 0) {
  7673. $this->sendMessage([
  7674. 'talk_type' => 1000,
  7675. 'title' => $project['title'],
  7676. 'content' => '提交了审核',
  7677. 'messageType' => 9,
  7678. ]);
  7679. }
  7680. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7681. }
  7682. if (empty($result)) {
  7683. return Result::error("审核失败", 0);
  7684. }
  7685. return Result::success($result);
  7686. }
  7687. /**
  7688. * 获取项目详情
  7689. * @param array $data
  7690. * @return array
  7691. */
  7692. public function getProjectInfo(array $data): array
  7693. {
  7694. $project = Project::where('id', $data['id'])->first();
  7695. if (empty($project)) {
  7696. return Result::error("暂无相关项目信息", 0);
  7697. }
  7698. return Result::success($project);
  7699. }
  7700. public function getWebsiteCompanyInfo(array $data): array
  7701. {
  7702. $company = Company::where('id', $data['id'])
  7703. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7704. ->where('status', 1)
  7705. // ->where('website_id', $data['website_id'])
  7706. ->select('company.*', 'job_industry.hyname as hy_name')
  7707. ->first();
  7708. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7709. $jobnature_id = $company['jobnature_id'] ?? null;
  7710. if ($jobnature_id !== null) {
  7711. switch ($jobnature_id) {
  7712. case 0:
  7713. $company->jobnature_name = '市场监督';
  7714. break;
  7715. case 1:
  7716. $company->jobnature_name = '信访纪检';
  7717. break;
  7718. case 2:
  7719. $company->jobnature_name = '公检法司';
  7720. break;
  7721. case 3:
  7722. $company->jobnature_name = '高关注机构';
  7723. break;
  7724. default:
  7725. $company->jobnature_name = '';
  7726. break;
  7727. }
  7728. } else {
  7729. $company->jobnature_name = '';
  7730. }
  7731. $city_arr = $company->city_arr_id;
  7732. if (!empty($city_arr)) {
  7733. $city_arr = json_decode($city_arr, true);
  7734. $cityNames = District::whereIn('id', $city_arr)
  7735. ->pluck('name')
  7736. ->implode('-');
  7737. $company->city_name = $cityNames;
  7738. } else {
  7739. $company->city_name = '';
  7740. }
  7741. if (empty($company)) {
  7742. return Result::error("暂无相关公司信息", 0);
  7743. }
  7744. return Result::success($company);
  7745. }
  7746. public function getMSG(array $data): array
  7747. {
  7748. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7749. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7750. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7751. $result = [];
  7752. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7753. //最近的5篇已审的文章
  7754. $apply_articale = Article::where('status', 1)
  7755. ->where('admin_user_id', $user_id)
  7756. ->orderBy('updated_at', 'desc')
  7757. // ->limit(5)
  7758. ->get();
  7759. //获取5条用户的已审核商品
  7760. $good = Good::where('status', 2)
  7761. ->where('user_id', $user_id)
  7762. ->orderBy('updated_at', 'desc')
  7763. // ->limit(5)
  7764. ->get();
  7765. //获取5条用户待审核的公告
  7766. $notice = Notice::where('status', 2)
  7767. ->where('user_id', $user_id)
  7768. ->orderBy('updated_at', 'desc')
  7769. ->limit(5)->get();
  7770. //获取5条用户的待审核投诉
  7771. $complaint = Complaint::where('status', 2)
  7772. ->where('user_id', $user_id)
  7773. ->orderBy('updated_at', 'desc')
  7774. // ->limit(5)
  7775. ->get();
  7776. //获取5条用户的book
  7777. $book = Book::where('status', 2)
  7778. ->where('user_id', $user_id)
  7779. ->orderBy('updated_at', 'desc')
  7780. // ->limit(5)
  7781. ->get();
  7782. //获取5条用户的求职
  7783. //获取5条用户的求职 1
  7784. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7785. ->where('job_hunting.user_id', $user_id)
  7786. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7787. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7788. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7789. ->orderBy('updated_at', 'desc')
  7790. // ->limit(5)
  7791. ->get();
  7792. //获取5条用户的求职 2
  7793. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7794. ->where('job_recruiting.user_id', $user_id)
  7795. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7796. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7797. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7798. ->orderBy('updated_at', 'desc')
  7799. // ->limit(5)
  7800. ->get();
  7801. //人才库 1
  7802. $job_apply = JobApply::where('job_apply.status', 1)
  7803. ->where('job_apply.receiver_id', $user_id)
  7804. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7805. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7806. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7807. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7808. ->select('job_recruiting', 'job_recruiting.', '', '')
  7809. ->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')
  7810. ->orderBy('updated_at', 'desc')
  7811. // ->limit(5)
  7812. ->get();
  7813. // 职场机会 2
  7814. $job_resume = JobResume::where('job_resume.status', 1)
  7815. ->where('job_resume.receiver_id', $user_id)
  7816. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7817. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7818. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7819. ->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')
  7820. ->orderBy('updated_at', 'desc')
  7821. // ->limit(5)
  7822. ->get();
  7823. //获取5条用户待处理的投诉
  7824. $complaint_deal = Complaint::where('status', 2)
  7825. ->where('deal', 1)
  7826. ->whereJsonContains('re_user_ids', $user_id)
  7827. ->orderBy('updated_at', 'desc')
  7828. // ->limit(5)
  7829. ->get();
  7830. //获取 被通知者未读信息
  7831. $notice_unread = Notice::where('status', 2)
  7832. ->whereJsonContains('re_user_ids', $user_id)
  7833. //未读消息
  7834. ->where(function ($query) use ($user_id) {
  7835. $query->whereJsonDoesntContain('read_id', $user_id)
  7836. ->orWhereNull('read_id');
  7837. })
  7838. ->orderBy('updated_at', 'desc')
  7839. ->get();
  7840. $complaint_unread = Complaint::where('status', 2)
  7841. ->whereJsonContains('re_user_ids', $user_id)
  7842. //未读消息
  7843. ->where(function ($query) use ($user_id) {
  7844. $query->whereJsonDoesntContain('read_id', $user_id)
  7845. ->orWhereNull('read_id');
  7846. })
  7847. ->orderBy('updated_at', 'desc')
  7848. ->get();
  7849. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7850. $complany = Company::where('status', 1)
  7851. ->where('user_id', $user_id)
  7852. ->orderBy('updated_at', 'desc')
  7853. // ->limit(5)
  7854. ->get();
  7855. //获取5条单聊未读聊天消息
  7856. // $chat = ChatRecords::where('is_read', 0)
  7857. // ->where('user_id', $user_id)
  7858. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7859. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7860. // ->where('action', 'recieved')
  7861. // ->where('talk_type', 1)
  7862. // ->orderBy('created_at', 'desc')
  7863. // // ->limit(5)
  7864. // ->get();
  7865. //获取5条未读群聊信息
  7866. // $chat_group = ChatRecords::where('is_read', 0)
  7867. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7868. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7869. // ->where('user_id', $user_id)
  7870. // ->where('talk_type', 2)
  7871. // ->orderBy('created_at', 'desc')
  7872. // // ->limit(5)
  7873. // ->get();
  7874. //获取5条用户的待审核项目
  7875. $project = Project::where('status', 1)
  7876. ->where('user_id', $user_id)
  7877. ->orderBy('updated_at', 'desc')
  7878. // ->limit(5)
  7879. ->get();
  7880. // count($chat) + count($chat_group) +
  7881. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume) + count($complaint_deal)
  7882. + count($complany)
  7883. + count($project)
  7884. + count($notice_unread)
  7885. + count($complaint_unread)
  7886. // + count($chat) + count($chat_group)
  7887. ;
  7888. $result = [
  7889. 'apply_articale' => $apply_articale,
  7890. // 'chat' => $chat,
  7891. // 'chat_group' => $chat_group,
  7892. 'good' => $good,
  7893. 'notice' => $notice,
  7894. 'complaint' => $complaint,
  7895. 'book' => $book,
  7896. 'job_hunting' => $job_hunting,
  7897. 'job_recruiting' => $job_recruiting,
  7898. 'job_apply' => $job_apply,
  7899. 'job_resume' => $job_resume,
  7900. 'complaint_deal' => $complaint_deal,
  7901. 'complany' => $complany,
  7902. 'project' => $project,
  7903. 'notice_unread' => $notice_unread,
  7904. 'complaint_unread' => $complaint_unread,
  7905. 'count' => $count,
  7906. ];
  7907. } elseif ($type_id == 12) {
  7908. //最近的5篇已审的文章
  7909. $apply_articale = Article::where('status', 1)
  7910. ->where('admin_user_id', $user_id)
  7911. ->limit(5)->get();
  7912. //获取5条单聊未读聊天消息
  7913. $chat = ChatRecords::where('is_read', 0)
  7914. ->where('user_id', $user_id)
  7915. ->where('talk_type', 1)
  7916. ->orderBy('created_at', 'desc')
  7917. ->limit(5)->get();
  7918. //获取5条未读群聊信息
  7919. $chat_group = ChatRecords::where('is_read', 0)
  7920. ->where('user_id', $user_id)
  7921. ->where('talk_type', 2)
  7922. ->orderBy('created_at', 'desc')
  7923. ->limit(5)->get();
  7924. //获取5条用户的已审核商品
  7925. $good = Good::where('status', 2)
  7926. ->where('user_id', $user_id)
  7927. ->orderBy('updated_at', 'desc')
  7928. ->limit(5)->get();
  7929. //获取5条用户的book
  7930. $book = Book::where('status', 2)
  7931. ->where('user_id', $user_id)
  7932. ->orderBy('updated_at', 'desc')
  7933. ->limit(5)->get();
  7934. //获取5条用户的求职
  7935. //获取5条用户的求职 1
  7936. //count($chat) + count($chat_group)
  7937. $count = count($apply_articale) + count($good);
  7938. $result = [
  7939. 'apply_articale' => $apply_articale,
  7940. 'chat' => $chat,
  7941. 'chat_group' => $chat_group,
  7942. 'good' => $good,
  7943. 'book' => $book,
  7944. 'count' => $count,
  7945. ];
  7946. } elseif ($type_id == 13) {
  7947. //最近的5篇已审的文章
  7948. $apply_articale = Article::where('status', 1)
  7949. ->where('admin_user_id', $user_id)
  7950. ->limit(5)->get();
  7951. //获取5条单聊未读聊天消息
  7952. $chat = ChatRecords::where('is_read', 0)
  7953. ->where('user_id', $user_id)
  7954. ->where('talk_type', 1)
  7955. ->orderBy('created_at', 'desc')
  7956. ->limit(5)->get();
  7957. //获取5条未读群聊信息
  7958. $chat_group = ChatRecords::where('is_read', 0)
  7959. ->where('user_id', $user_id)
  7960. ->where('talk_type', 2)
  7961. ->orderBy('created_at', 'desc')
  7962. ->limit(5)->get();
  7963. //获取5条用户的已审核商品
  7964. $good = Good::where('status', 2)
  7965. ->where('user_id', $user_id)
  7966. ->orderBy('updated_at', 'desc')
  7967. ->limit(5)->get();
  7968. //count($chat) + count($chat_group) +
  7969. $count = count($apply_articale) + count($good);
  7970. $result = [
  7971. 'apply_articale' => $apply_articale,
  7972. 'chat' => $chat,
  7973. 'chat_group' => $chat_group,
  7974. 'good' => $good,
  7975. 'count' => $count,
  7976. ];
  7977. } elseif ($type_id == 14) {
  7978. //最近的5篇已审的文章
  7979. $apply_articale = Article::where('status', 1)
  7980. ->where('admin_user_id', $user_id)
  7981. // ->limit(5)
  7982. ->get();
  7983. //获取5条用户的已审核商品
  7984. $good = Good::where('status', 2)
  7985. ->where('user_id', $user_id)
  7986. ->orderBy('updated_at', 'desc')
  7987. // ->limit(5)
  7988. ->get();
  7989. $count = count($apply_articale) + count($good);
  7990. $result = [
  7991. 'apply_articale' => $apply_articale,
  7992. 'chat' => '',
  7993. 'chat_group' => '',
  7994. 'good' => $good,
  7995. 'count' => $count,
  7996. ];
  7997. } elseif ($type_id == 10000) {
  7998. //获取未审核的5篇文章
  7999. $apply_articale = Article::where('status', 0)
  8000. ->orderBy('updated_at', 'desc')
  8001. // ->limit(5)
  8002. ->get();
  8003. //获取5条单聊未读聊天消息
  8004. //获取5条单聊未读聊天消息
  8005. // $chat = ChatRecords::where('is_read', 0)
  8006. // ->where('user_id', $user_id)
  8007. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  8008. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  8009. // ->where('action', 'recieved')
  8010. // ->where('talk_type', 1)
  8011. // ->orderBy('created_at', 'desc')
  8012. // // ->limit(5)
  8013. // ->get();
  8014. // //获取5条未读群聊信息
  8015. // $chat_group = ChatRecords::where('is_read', 0)
  8016. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8017. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8018. // ->where('user_id', $user_id)
  8019. // ->where('talk_type', 2)
  8020. // ->orderBy('created_at', 'desc')
  8021. // // ->limit(5)
  8022. // ->get();
  8023. //获取5条用户的已审核商品
  8024. $good = Good::where('status', 1)
  8025. // ->where('user_id', $user_id)
  8026. ->orderBy('updated_at', 'desc')
  8027. // ->limit(5)
  8028. ->get();
  8029. //获取5条用户待审核的公告
  8030. $notice = Notice::where('status', 1)
  8031. ->orderBy('updated_at', 'desc')
  8032. // ->limit(5)
  8033. ->get();
  8034. //获取5条用户的待审核投诉
  8035. $complaint = Complaint::where('status', 1)
  8036. ->orderBy('updated_at', 'desc')
  8037. // ->limit(5)
  8038. ->get();
  8039. //获取5条用户的book
  8040. $book = Book::where('status', 1)
  8041. ->orderBy('updated_at', 'desc')
  8042. // ->limit(5)
  8043. ->get();
  8044. //获取5条用户的求职 1
  8045. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8046. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8047. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8048. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8049. ->orderBy('updated_at', 'desc')
  8050. // ->limit(5)
  8051. ->get();
  8052. //获取5条用户的求职 2
  8053. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8054. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8055. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8056. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8057. ->orderBy('updated_at', 'desc')
  8058. // ->limit(5)
  8059. ->get();
  8060. //人才库 1
  8061. $job_apply = JobApply::where('job_apply.status', 1)
  8062. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8063. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8064. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8065. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8066. ->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')
  8067. ->orderBy('updated_at', 'desc')
  8068. // ->limit(5)
  8069. ->get();
  8070. // 职场机会 2
  8071. $job_resume = JobResume::where('job_resume.status', 1)
  8072. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8073. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8074. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8075. ->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')
  8076. ->orderBy('updated_at', 'desc')
  8077. // ->limit(5)
  8078. ->get();
  8079. //待审核数据com pro
  8080. $complany = Company::where('status', 0)
  8081. ->orderBy('updated_at', 'desc')
  8082. // ->limit(5)
  8083. ->get();
  8084. $project = Project::where('status', 0)
  8085. ->orderBy('updated_at', 'desc')
  8086. // ->limit(5)
  8087. ->get();
  8088. $count =
  8089. // count($chat) +
  8090. // count($chat_group) +
  8091. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8092. // + count($job_apply)
  8093. // + count($job_resume)
  8094. + count($complany)
  8095. + count($project);
  8096. $result = [
  8097. 'apply_articale' => $apply_articale,
  8098. // 'chat' => $chat,
  8099. // 'chat_group' => $chat_group,
  8100. 'good' => $good,
  8101. 'notice' => $notice,
  8102. 'complaint' => $complaint,
  8103. 'book' => $book,
  8104. 'job_hunting' => $job_hunting,
  8105. 'job_recruiting' => $job_recruiting,
  8106. // 'job_apply' => $job_apply,
  8107. // 'job_resume' => $job_resume,
  8108. 'complany' => $complany,
  8109. 'project' => $project,
  8110. 'count' => $count,
  8111. ];
  8112. } elseif ($type_id == 20000) {
  8113. }
  8114. var_dump($type_id, '-----------------test---------');
  8115. return Result::success($result);
  8116. }
  8117. /**
  8118. * @param array $data
  8119. * @return array
  8120. */
  8121. public function getWebsiteProject(array $data): array
  8122. {
  8123. $categorys = json_decode($data['id'], true);
  8124. if (!empty($categorys)) {
  8125. $category_arr = $this->processArticlePro($data['website_id']);
  8126. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8127. $catiall = $category_arr['catiall'];
  8128. // return Result::success($catiall);
  8129. foreach ($categorys as $key => $val) {
  8130. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8131. $level = explode(',', $val['level'])[0];
  8132. $imgnum = explode(',', $val['level'])[1] ?? null;
  8133. $textnum = explode(',', $val['level'])[2] ?? null;
  8134. if ($level == 1) {
  8135. if (!empty($textnum) && $textnum > 0) {
  8136. $text_num = Project::where('level', $level)
  8137. ->where('website_id', $data['website_id'])
  8138. ->where('status', 1)
  8139. ->select(
  8140. 'project.id',
  8141. 'project.title',
  8142. 'project.description',
  8143. 'project.updated_at',
  8144. 'project.category_id',
  8145. 'project.cat_arr_id'
  8146. )
  8147. ->orderBy('updated_at', 'desc')
  8148. ->limit($textnum)
  8149. ->get()->all();
  8150. }
  8151. if (!empty($imgnum) && $imgnum > 0) {
  8152. $img_num = Project::where('level', $level)
  8153. ->where('website_id', $data['website_id'])
  8154. ->where('status', 1)
  8155. ->where('imgurl', '!=', '')
  8156. ->whereNotNull('imgurl')
  8157. ->select(
  8158. 'project.id',
  8159. 'project.title',
  8160. 'project.description',
  8161. 'project.updated_at',
  8162. 'project.imgurl as imgs',
  8163. 'project.category_id',
  8164. 'project.cat_arr_id'
  8165. )
  8166. ->orderBy('updated_at', 'desc')
  8167. ->limit($imgnum)
  8168. ->get()->all();
  8169. }
  8170. } else {
  8171. if (!empty($textnum) && $textnum > 0) {
  8172. $text_num = Project::where('website_id', $data['website_id'])
  8173. ->where('status', 1)
  8174. ->select(
  8175. 'project.id',
  8176. 'project.title',
  8177. 'project.description',
  8178. 'project.updated_at',
  8179. 'project.category_id',
  8180. 'project.cat_arr_id',
  8181. 'project.website_id',
  8182. 'project.updated_at',
  8183. 'project.created_at'
  8184. )
  8185. ->orderBy('updated_at', 'desc')
  8186. ->limit($textnum)
  8187. ->get()->all();
  8188. }
  8189. if (!empty($imgnum) && $imgnum > 0) {
  8190. $img_num = Project::where('website_id', $data['website_id'])
  8191. ->where('status', 1)
  8192. ->where('imgurl', '!=', '')
  8193. ->whereNotNull('imgurl')
  8194. ->select(
  8195. 'project.id',
  8196. 'project.title',
  8197. 'project.description',
  8198. 'project.updated_at',
  8199. 'project.imgurl as imgs',
  8200. 'project.category_id',
  8201. 'project.cat_arr_id'
  8202. )
  8203. ->orderBy('updated_at', 'desc')
  8204. ->limit($imgnum)
  8205. ->get()->all();
  8206. }
  8207. }
  8208. }
  8209. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8210. $category_ids = explode(',', $val['id'])[0];
  8211. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8212. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8213. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8214. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8215. $text_num = Project::whereIn('category_id', $category_arr)
  8216. ->where('website_id', $data['website_id'])
  8217. ->where('status', 1)
  8218. ->select(
  8219. 'project.id',
  8220. 'project.title',
  8221. 'project.description',
  8222. 'project.updated_at',
  8223. 'project.category_id',
  8224. 'project.cat_arr_id'
  8225. )
  8226. ->orderBy('updated_at', 'desc')
  8227. ->limit($cat_textnum)
  8228. ->get()->all();
  8229. }
  8230. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8231. $img_num = Project::whereIn('category_id', $category_arr)
  8232. ->where('website_id', $data['website_id'])
  8233. ->where('status', 1)
  8234. ->where('imgurl', '!=', '')
  8235. ->whereNotNull('imgurl')
  8236. ->select(
  8237. 'project.id',
  8238. 'project.title',
  8239. 'project.description',
  8240. 'project.updated_at',
  8241. 'project.imgurl as imgs',
  8242. 'project.category_id',
  8243. 'project.cat_arr_id'
  8244. )
  8245. ->orderBy('updated_at', 'desc')
  8246. ->limit($cat_imgnum)
  8247. ->get()->all();
  8248. }
  8249. }
  8250. if (!empty($img_num)) {
  8251. foreach ($img_num as $k => $v) {
  8252. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8253. $imgurl = json_decode($v['imgs'], true);
  8254. if (!empty($imgurl)) {
  8255. $img_num[$k]->imgurl = $imgurl[0];
  8256. }
  8257. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8258. }
  8259. }
  8260. if (!empty($text_num)) {
  8261. foreach ($text_num as $k => $v) {
  8262. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8263. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8264. }
  8265. }
  8266. $project[$key]['img_num'] = $img_num ?? [];
  8267. $project[$key]['text_num'] = $text_num ?? [];
  8268. }
  8269. }
  8270. if (empty($project)) {
  8271. return Result::error("暂无相关项目信息", 0);
  8272. }
  8273. return Result::success($project);
  8274. }
  8275. /**
  8276. * @param array $data
  8277. * @return array
  8278. */
  8279. public function getWebsiteProjectInfo(array $data): array
  8280. {
  8281. $project = Project::where('id', $data['id'])
  8282. ->where('status', 1)
  8283. ->where('website_id', $data['website_id'])
  8284. ->select('project.*')
  8285. ->first();
  8286. if (empty($project)) {
  8287. return Result::error("暂无相关项目信息", 0);
  8288. }
  8289. return Result::success($project);
  8290. }
  8291. /**
  8292. * @param array $data
  8293. * @return array
  8294. */
  8295. public function getWebsiteProjectList(array $data): array
  8296. {
  8297. $where = [];
  8298. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8299. $where['category_id'] = $data['category_id'];
  8300. }
  8301. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8302. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8303. }
  8304. $query = Project::where($where)
  8305. ->where('status', 1)
  8306. ->where('website_id', $data['website_id'])
  8307. ->select(
  8308. 'project.id',
  8309. 'project.title',
  8310. 'project.description',
  8311. 'project.imgurl as imgs',
  8312. 'project.category_id',
  8313. 'project.cat_arr_id'
  8314. )
  8315. ->orderBy('updated_at', 'desc');
  8316. $count = $query->count();
  8317. $project = $query->clone()
  8318. ->offset(($data['page'] - 1) * $data['pageSize'])
  8319. ->limit($data['pageSize'])
  8320. ->get()->all();
  8321. if (empty($project)) {
  8322. return Result::error("暂无相关项目信息", 0);
  8323. }
  8324. $categorys = $this->processArticlePro($data['website_id']);
  8325. $catiall = $categorys['catiall'];
  8326. foreach ($project as $key => $val) {
  8327. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8328. if (!empty($val['imgs'])) {
  8329. $imgurl = json_decode($val['imgs'], true);
  8330. if (!empty($imgurl)) {
  8331. $project[$key]->imgurl = $imgurl[0];
  8332. }
  8333. } else {
  8334. $project[$key]->imgurl = '';
  8335. }
  8336. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8337. }
  8338. $result = [
  8339. 'rows' => $project,
  8340. 'count' => $count,
  8341. ];
  8342. return Result::success($result);
  8343. }
  8344. /**
  8345. * @param array $data
  8346. * @return array
  8347. */
  8348. public function getWebsiteCategoryJob(array $data): array
  8349. {
  8350. $categorys = json_decode($data['id'], true);
  8351. if (!empty($categorys)) {
  8352. $category_arr = $this->processArticlePro($data['website_id']);
  8353. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8354. $catiall = $category_arr['catiall'];
  8355. foreach ($categorys as $key => $val) {
  8356. if (isset($val['id']) && !empty($val['id'])) {
  8357. $catid = explode(',', $val['id'])[0] ?? null;
  8358. $type = explode(',', $val['id'])[1] ?? null;
  8359. $textnum = explode(',', $val['id'])[2] ?? null;
  8360. }
  8361. // 4:招聘;5:求职;
  8362. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8363. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8364. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8365. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8366. ->where('job_recruiting.status', 1)
  8367. ->where('job_recruiting.website_id', $data['website_id'])
  8368. ->select(
  8369. 'job_recruiting.id',
  8370. 'job_recruiting.title',
  8371. 'job_company.business_name',
  8372. 'job_recruiting.updated_at',
  8373. 'job_recruiting.cat_arr_id',
  8374. 'job_recruiting.keyword',
  8375. 'job_recruiting.description'
  8376. )
  8377. ->orderBy('job_recruiting.updated_at', 'desc')
  8378. ->limit($textnum)
  8379. ->get()->all();
  8380. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8381. // 状态 审核状态,1待审核2已审核3已拒绝
  8382. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8383. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8384. ->where('job_hunting.status', 2)
  8385. ->where('job_hunting.website_id', $data['website_id'])
  8386. ->select(
  8387. 'job_hunting.id',
  8388. 'job_hunting.name',
  8389. 'job_hunting.cat_arr_id',
  8390. 'job_position.zwname as job_name',
  8391. 'job_hunting.updated_at',
  8392. // 'job_hunting.keyword',
  8393. 'job_hunting.slelf_evaluation'
  8394. )
  8395. ->orderBy('updated_at', 'desc')
  8396. ->limit($textnum)
  8397. ->get()->all();
  8398. } else {
  8399. $job = [];
  8400. }
  8401. // var_dump($catid.'222uuuuuuu'.$key);
  8402. if (!empty($job)) {
  8403. foreach ($job as $k => $value) {
  8404. if (isset($value->cat_arr_id)) {
  8405. $catArr = json_decode($value->cat_arr_id, true);
  8406. $catId = end($catArr);
  8407. } else {
  8408. continue;
  8409. }
  8410. if (isset($catiall[$catId])) {
  8411. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8412. }
  8413. }
  8414. }
  8415. // var_dump($catid.'xxxxx'.$key);
  8416. $result[$key] = $job ?? [];
  8417. }
  8418. }
  8419. if (empty($result)) {
  8420. return Result::error("暂无相关分类信息", 0);
  8421. }
  8422. return Result::success($result);
  8423. }
  8424. /**
  8425. * 发送消息
  8426. * @param array $messageData
  8427. * @return void
  8428. */
  8429. public function sendMessage($messageData)
  8430. {
  8431. $msg = [
  8432. 'talk_type' => $messageData['talk_type'],
  8433. 'title' => $messageData['title'],
  8434. 'content' => $messageData['content'],
  8435. 'messageType' => $messageData['messageType'],
  8436. 'user_id' => $messageData['user_id'] ?? '',
  8437. 'time' => microtime(),
  8438. ];
  8439. $message = new MqProducer($msg);
  8440. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8441. $producer->produce($message);
  8442. }
  8443. /**
  8444. * 行业分类管理 ------1121
  8445. * @param array $data
  8446. * @return array
  8447. */
  8448. public function getJobIndustryList(array $data): array
  8449. {
  8450. $page = $data['page'] ?? 1;
  8451. $page_size = $data['page_size'] ?? 10;
  8452. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8453. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8454. } else {
  8455. $where = [];
  8456. }
  8457. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8458. $query->where([$where]); // 修复:将条件包装成二维数组
  8459. })
  8460. ->orderBy('updated_at', 'desc');
  8461. $count = $rs_query->count();
  8462. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8463. $result = [
  8464. 'count' => $count,
  8465. 'list' => $hy,
  8466. ];
  8467. if (empty($hy)) {
  8468. return Result::success('暂无数据');
  8469. }
  8470. return Result::success($result);
  8471. }
  8472. /**
  8473. * 添加行业分类
  8474. * @param array $data
  8475. * @return array
  8476. */
  8477. public function addJobIndustry(array $data): array
  8478. {
  8479. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8480. if (!empty($hy_name)) {
  8481. return Result::error('行业分类已存在');
  8482. }
  8483. $hy = JobIndustry::insertGetId($data);
  8484. if (empty($hy)) {
  8485. return Result::error('添加失败');
  8486. }
  8487. return Result::success($hy);
  8488. }
  8489. /**
  8490. * 更新行业分类
  8491. * @param array $data
  8492. * @return array
  8493. */
  8494. public function upJobIndustry(array $data): array
  8495. {
  8496. $hy_query = JobIndustry::get();
  8497. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8498. $hy_names = $hy_query->pluck('hyname')->toArray();
  8499. if (!in_array($data['hyid'], $hy_ids)) {
  8500. return Result::error('行业分类不存在');
  8501. }
  8502. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8503. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8504. // return Result::success($other_key_hy);
  8505. unset($hy_names[$other_key_hy]);
  8506. if (in_array($data['hyname'], $hy_names)) {
  8507. return Result::error('行业分类名称已存在');
  8508. }
  8509. }
  8510. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8511. if (empty($hy)) {
  8512. return Result::error('更新失败');
  8513. }
  8514. return Result::success($hy);
  8515. }
  8516. /**
  8517. * 删除行业分类
  8518. * @param array $data
  8519. * @return array
  8520. */
  8521. public function delJobIndustry(array $data): array
  8522. {
  8523. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8524. if (empty($hy_id)) {
  8525. return Result::error('行业分类不存在');
  8526. }
  8527. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8528. if (empty($hy)) {
  8529. return Result::error('删除失败');
  8530. }
  8531. return Result::success($hy);
  8532. }
  8533. /**
  8534. * 职位分类-列表
  8535. * @param array $data
  8536. * @return array
  8537. */
  8538. public function getJobPositionList(array $data): array
  8539. {
  8540. $page = $data['page'] ?? 1;
  8541. $page_size = $data['page_size'] ?? 10;
  8542. $where = [];
  8543. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8544. $zwids = JobPosition::where('zwpid', 0)
  8545. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8546. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8547. })
  8548. ->orderBy('updated_at', 'desc')
  8549. ->pluck('zwid')
  8550. // ->get()
  8551. ->toArray();
  8552. }
  8553. if (isset($data['childname']) && !empty($data['childname'])) {
  8554. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8555. ->when(!empty($data['childname']), function ($query) use ($data) {
  8556. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8557. })
  8558. ->orderBy('updated_at', 'desc')
  8559. ->pluck('zwpid')
  8560. // ->get()
  8561. ->toArray();
  8562. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8563. $child_zwids = array_intersect($zwids, $child_zwids);
  8564. }
  8565. $zwids = array_values(array_unique($child_zwids));
  8566. }
  8567. $zwids = $zwids ?? null;
  8568. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8569. $query->whereIn('zwid', $zwids);
  8570. })
  8571. ->where('zwpid', 0)
  8572. ->count();
  8573. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8574. $query->whereIn('zwid', $zwids);
  8575. })
  8576. ->where('zwpid', 0)
  8577. ->orderBy('updated_at', 'desc')
  8578. ->offset(($page - 1) * $page_size)
  8579. ->limit($page_size)->get()
  8580. ->map(function ($item) use ($data) {
  8581. $item->children = $item->where('zwpid', $item->zwid)
  8582. ->when(!empty($data['childname']), function ($query) use ($data) {
  8583. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8584. })
  8585. ->orderBy('updated_at', 'desc')
  8586. ->get();
  8587. return $item;
  8588. })
  8589. ->all();
  8590. $result = [
  8591. 'count' => $count,
  8592. 'list' => $position,
  8593. ];
  8594. if (empty($result)) {
  8595. return Result::success('暂无数据');
  8596. }
  8597. return Result::success($result);
  8598. }
  8599. /**
  8600. * 职位分类-添加
  8601. * @param array $data
  8602. * @return array
  8603. */
  8604. public function addJobPosition(array $data): array
  8605. {
  8606. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8607. ->where('zwname', $data['zwname'])->first(['zwid']);
  8608. if (!empty($zw_name)) {
  8609. return Result::error('职位分类已存在');
  8610. }
  8611. $zw = JobPosition::insertGetId($data);
  8612. if(empty($zw)){
  8613. return Result::error('添加失败');
  8614. }
  8615. return Result::success($zw);
  8616. }
  8617. /**
  8618. * 更新职位分类
  8619. * @param array $data
  8620. * @return array
  8621. */
  8622. public function upJobPosition(array $data): array
  8623. {
  8624. $zw_position = JobPosition::get();
  8625. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8626. return Result::error('职位分类不存在');
  8627. }
  8628. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8629. ->where('zwpid', $data['zwpid'])
  8630. ->where('zwname', $data['zwname'])->first();
  8631. if (!empty($zw_name)) {
  8632. return Result::error('职位分类已存在');
  8633. }
  8634. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8635. if (empty($result)) {
  8636. return Result::error('更新失败');
  8637. }
  8638. return Result::success($result);
  8639. }
  8640. /**
  8641. * 删除职位分类
  8642. * @param array $data
  8643. * @return array
  8644. */
  8645. public function delJobPosition(array $data): array
  8646. {
  8647. $zw_jobposition = JobPosition::get();
  8648. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8649. if (empty($zw_id)) {
  8650. return Result::error('职位分类不存在');
  8651. }
  8652. if($zw_id->zwpid == 0){
  8653. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8654. if(!empty($zw_job)){
  8655. return Result::error('请先删除子分类');
  8656. }
  8657. }
  8658. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8659. if (empty($result)) {
  8660. return Result::error('删除失败');
  8661. }
  8662. return Result::success($result);
  8663. }
  8664. /**
  8665. * 网民留言-添加
  8666. * @param array $data
  8667. * @return array
  8668. */
  8669. public function addMessage(array $data): array
  8670. {
  8671. $user = User::where('id', $data['user_id'])->first();
  8672. if (empty($user)) {
  8673. return Result::error('用户不存在');
  8674. }
  8675. if($user['type_id'] == 10000){
  8676. $data['status'] = 1;
  8677. }else{
  8678. $data['status'] = 0;
  8679. }
  8680. if ($data['keyword'] == '') {
  8681. //提取标题+内容中的关键词
  8682. $data['keyword'] = $data['title'];
  8683. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8684. Jieba::init(); // 初始化 jieba-php
  8685. Finalseg::init();
  8686. $segList = Jieba::cut($data['keyword']);
  8687. $segList1 = array_slice($segList, 0, 8);
  8688. $data['keyword'] = implode(',', $segList1);
  8689. }
  8690. if ($data['description'] == '') {
  8691. //提取内容中的描述
  8692. $content = $data['content'];
  8693. // 去除 <style> 和 <script> 标签及其内容
  8694. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8695. // 去除所有 HTML 标签
  8696. $content = strip_tags($content);
  8697. // 去除 HTML 实体
  8698. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8699. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8700. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8701. // 去除多余空白
  8702. $content = preg_replace('/\s+/u', '', $content);
  8703. // 截取 100 个字符
  8704. $data['description'] = mb_substr($content, 0, 100);
  8705. }
  8706. if(!empty($data['reply'])){
  8707. $data['reply_userid'] = $data['user_id'];
  8708. }
  8709. $result = Message::insertGetId($data);
  8710. if(empty($result)){
  8711. return Result::error('添加失败');
  8712. }
  8713. return Result::success($result);
  8714. }
  8715. /**
  8716. * 网民留言-更新
  8717. * @param array $data
  8718. * @return array
  8719. */
  8720. public function upMessage(array $data): array
  8721. {
  8722. $user = User::where('id', $data['user_id'])->first();
  8723. if (empty($user)) {
  8724. return Result::error('用户不存在');
  8725. }
  8726. if($user['type_id'] == 10000){
  8727. $data['status'] = 1;
  8728. }else{
  8729. $data['status'] = 0;
  8730. }
  8731. $message = Message::where('id', $data['id'])->first();
  8732. if (empty($message)) {
  8733. return Result::error('留言不存在');
  8734. }
  8735. if($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000){
  8736. return Result::error('非留言人不能更新');
  8737. }
  8738. if ($data['keyword'] == '') {
  8739. //提取标题+内容中的关键词
  8740. $data['keyword'] = $data['title'];
  8741. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8742. Jieba::init(); // 初始化 jieba-php
  8743. Finalseg::init();
  8744. $segList = Jieba::cut($data['keyword']);
  8745. $segList1 = array_slice($segList, 0, 8);
  8746. $data['keyword'] = implode(',', $segList1);
  8747. }
  8748. if ($data['description'] == '') {
  8749. //提取内容中的描述
  8750. $content = $data['content'];
  8751. // 去除 <style> 和 <script> 标签及其内容
  8752. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8753. // 去除所有 HTML 标签
  8754. $content = strip_tags($content);
  8755. // 去除 HTML 实体
  8756. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8757. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8758. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8759. // 去除多余空白
  8760. $content = preg_replace('/\s+/u', '', $content);
  8761. // 截取 100 个字符
  8762. $data['description'] = mb_substr($content, 0, 100);
  8763. }
  8764. unset($data['id']);
  8765. if(!empty($data['reply'])){
  8766. $data['reply_userid'] = $data['user_id'];
  8767. unset($data['user_id']);
  8768. }
  8769. $result = Message::where('id', $message['id'])->update($data);
  8770. if (empty($result)) {
  8771. return Result::error('更新失败');
  8772. }
  8773. return Result::success($result);
  8774. }
  8775. /**
  8776. * 网民留言-删除
  8777. * @param array $data
  8778. * @return array
  8779. */
  8780. public function delMessage(array $data): array
  8781. {
  8782. $result = Message::where('id', $data['id'])->delete();
  8783. if (empty($result)) {
  8784. return Result::error('删除失败');
  8785. }
  8786. return Result::success($result);
  8787. }
  8788. /**
  8789. * 网民留言-更新状态
  8790. * @param array $data
  8791. * @return array
  8792. */
  8793. public function upMessageStatus(array $data): array
  8794. {
  8795. $message = Message::where('id', $data['id'])->first();
  8796. if (empty($message)) {
  8797. return Result::error('留言不存在!');
  8798. }
  8799. unset($data['id']);
  8800. unset($data['user_id']);
  8801. if($data['status'] != 2){
  8802. $data['reason'] = null;
  8803. }
  8804. $result = Message::where('id', $message['id'])->update($data);
  8805. if (empty($result)) {
  8806. return Result::error('留言更新失败!');
  8807. }
  8808. return Result::success($result);
  8809. }
  8810. /**
  8811. * 网民留言-获取详情
  8812. * @param array $data
  8813. * @return array
  8814. */
  8815. public function getMessageInfo(array $data): array
  8816. {
  8817. $result = Message::where('message.id', $data['id'])
  8818. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8819. ->select('message.*', 'website_column.column_arr_id')
  8820. ->first();
  8821. if (empty($result)) {
  8822. return Result::error('留言不存在!');
  8823. }
  8824. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8825. return Result::success($result);
  8826. }
  8827. /**
  8828. * 网民留言-获取列表
  8829. * @param array $data
  8830. * @return array
  8831. */
  8832. public function getMessageList(array $data): array
  8833. {
  8834. $where = [];
  8835. if($data['is_master'] == 1){
  8836. $where['message.status'] = 1;
  8837. }else if($data['is_master'] == 2){
  8838. $where['message.status'] = 2;
  8839. }else if($data['is_master'] == 3){
  8840. $where['message.status'] = 0;
  8841. }
  8842. $user = User::where('id', $data['user_id'])->first();
  8843. if (empty($user)) {
  8844. return Result::error('用户不存在');
  8845. }
  8846. $column_arr_id = [];
  8847. if($user['type_id'] != 10000 && !empty($data['website_id'])){
  8848. $where['message.user_id'] = $data['user_id'];
  8849. $web = Website::where('id',$data['website_id'])->first('website_column_arr_id');
  8850. if(empty($web)){
  8851. return Result::error('此网站未关联任何网站属性!');
  8852. }
  8853. $column_arr_id = json_decode($web['website_column_arr_id'],true);
  8854. }
  8855. if(!empty($data['title'])){
  8856. array_push($where, ['message.title', 'like', '%'.$data['title'].'%']);
  8857. }
  8858. $result = Message::when($data['is_master'] == 0, function ($query) {
  8859. $query->whereIn('message.status', [0, 2]);
  8860. })
  8861. ->when(!empty($where), function ($query) use ($where) {
  8862. $query->where($where);
  8863. })
  8864. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  8865. ->select('message.*', 'user.nickname')
  8866. ->orderBy('message.updated_at', 'desc')
  8867. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8868. if(empty($result->items())) {
  8869. return Result::error('留言不存在!');
  8870. }
  8871. $result = [
  8872. 'data' => $result->items(),
  8873. 'count' => $result->total(),
  8874. ];
  8875. if(!empty($column_arr_id) && $user['type_id'] != 10000){
  8876. foreach($result['data'] as $key => $value){
  8877. if(in_array($value['column_id'], $column_arr_id)){
  8878. $result['data'][$key]['is_update'] = 1;
  8879. }else{
  8880. $result['data'][$key]['is_update'] = 0;
  8881. }
  8882. }
  8883. }
  8884. return Result::success($result);
  8885. }
  8886. /**
  8887. * 网民留言-检查是否可编辑
  8888. * @param array $data
  8889. * @return array
  8890. */
  8891. public function checkMessageEdit(array $data): array
  8892. {
  8893. $message = Message::where('id', $data['id'])->first();
  8894. if (empty($message)) {
  8895. return Result::error('留言不存在!');
  8896. }
  8897. $web = Website::where('id', $data['website_id'])->first();
  8898. if (empty($web)) {
  8899. return Result::error('网站不存在!');
  8900. }
  8901. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8902. if(empty($column_arr)){
  8903. return Result::error('该网站未关联任何属性!');
  8904. }
  8905. if(!in_array($message['column_id'], $column_arr)){
  8906. return Result::error('不可编辑');
  8907. }
  8908. return Result::success('可编辑');
  8909. }
  8910. /**
  8911. * 调研选题-获取所有Researchers
  8912. * @param array $data
  8913. * @return array
  8914. */
  8915. public function getAllResearcher(array $data): array
  8916. {
  8917. $where['role_user.role_id'] = 21;
  8918. if(!empty($data['id'])){
  8919. $where['user.id'] = $data['id'];
  8920. }
  8921. if(!empty($data['real_name'])){
  8922. array_push($where, ['user_info.real_name', 'like', '%'.$data['real_name'].'%']);
  8923. }
  8924. $users = User::leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  8925. ->leftJoin('role_user', 'user.id', '=', 'role_user.user_id')
  8926. ->where($where)
  8927. ->select('user.id', 'user_info.real_name','user_info.number')
  8928. ->get()->toArray();
  8929. if (empty($users)) {
  8930. return Result::error('此调研员不存在!');
  8931. }
  8932. $user_number = array_search($data['user_id'], array_column($users, 'id'));
  8933. if($user_number == false){
  8934. $result['number'] = null;
  8935. }else{
  8936. $result['number'] = $users[$user_number]['number'];
  8937. }
  8938. $result['users'] = $users;
  8939. $result['user_id'] = $data['user_id'];
  8940. return Result::success($result);
  8941. }
  8942. /**
  8943. * 调研选题-添加
  8944. * @param array $data
  8945. * @return array
  8946. */
  8947. public function addResearchTopic(array $data): array
  8948. {
  8949. $user = User::where('id', $data['user_id'])->first();
  8950. if (empty($user)) {
  8951. return Result::error('用户不存在');
  8952. }
  8953. if($user['type_id'] == 10000){
  8954. $data['status'] = 1;
  8955. }else{
  8956. $data['status'] = 0;
  8957. }
  8958. if ($data['keyword'] == '') {
  8959. //提取标题+内容中的关键词
  8960. $data['keyword'] = $data['title'];
  8961. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8962. Jieba::init(); // 初始化 jieba-php
  8963. Finalseg::init();
  8964. $segList = Jieba::cut($data['keyword']);
  8965. $segList1 = array_slice($segList, 0, 8);
  8966. $data['keyword'] = implode(',', $segList1);
  8967. }
  8968. if ($data['description'] == '') {
  8969. //提取内容中的描述
  8970. $content = $data['content'];
  8971. // 去除 <style> 和 <script> 标签及其内容
  8972. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8973. // 去除所有 HTML 标签
  8974. $content = strip_tags($content);
  8975. // 去除 HTML 实体
  8976. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8977. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8978. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8979. // 去除多余空白
  8980. $content = preg_replace('/\s+/u', '', $content);
  8981. // 截取 100 个字符
  8982. $data['description'] = mb_substr($content, 0, 100);
  8983. }
  8984. $data['level'] = empty($data['level']) ? null : $data['level'];
  8985. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  8986. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  8987. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  8988. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  8989. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  8990. unset($data['users_id']);
  8991. // return Result::success($data);
  8992. Db::beginTransaction();
  8993. try{
  8994. $result = ResearchTopic::insertGetId($data);
  8995. if (empty($result)) {
  8996. Db::rollBack();
  8997. return Result::error('添加失败');
  8998. }
  8999. if(!empty($users_id) && is_string($users_id)){
  9000. $users = json_decode($users_id ?? '[]',true);
  9001. }
  9002. $users_type4 = User::where('type_id', 4)->pluck('id');
  9003. $type4_num = array_intersect($users, $users_type4->toArray());
  9004. if(count($users) != count($type4_num)){
  9005. Db::rollBack();
  9006. return Result::error('请选择调研员!');
  9007. }
  9008. // return Result::success($users);
  9009. if(!empty($users) && is_array($users)){
  9010. // 去重:确保同一 retopic_id + user_id 组合唯一
  9011. $users = array_values(array_unique($users));
  9012. // 组装关联数据
  9013. $users_topic = [];
  9014. foreach ($users as $key => $value) {
  9015. $users_topic[$key] = [
  9016. 'user_id' => $value,
  9017. 'retopic_id' => $result,
  9018. ];
  9019. }
  9020. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9021. $retopic_user = RetopicUser::insert($users_topic);
  9022. if(empty($retopic_user)){
  9023. Db::rollBack();
  9024. return Result::error('添加失败');
  9025. }
  9026. }
  9027. Db::commit();
  9028. return Result::success($result);
  9029. }catch(\Exception $e){
  9030. Db::rollBack();
  9031. return Result::error($e->getMessage());
  9032. }
  9033. }
  9034. /**
  9035. * 调研选题-编辑
  9036. * @param array $data
  9037. * @return array
  9038. */
  9039. public function upResearchTopic(array $data): array
  9040. {
  9041. $user = User::where('id', $data['user_id'])->first();
  9042. if (empty($user)) {
  9043. return Result::error('用户不存在');
  9044. }
  9045. if($user['type_id'] == 10000){
  9046. $data['status'] = 1;
  9047. }else{
  9048. $data['status'] = 0;
  9049. }
  9050. $topic = ResearchTopic::where('id', $data['id'])->first();
  9051. if (empty($topic)) {
  9052. return Result::error('此调研选题不存在');
  9053. }
  9054. if ($data['keyword'] == '') {
  9055. //提取标题+内容中的关键词
  9056. $data['keyword'] = $data['title'];
  9057. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9058. Jieba::init(); // 初始化 jieba-php
  9059. Finalseg::init();
  9060. $segList = Jieba::cut($data['keyword']);
  9061. $segList1 = array_slice($segList, 0, 8);
  9062. $data['keyword'] = implode(',', $segList1);
  9063. }
  9064. if ($data['description'] == '') {
  9065. //提取内容中的描述
  9066. $content = $data['content'];
  9067. // 去除 <style> 和 <script> 标签及其内容
  9068. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9069. // 去除所有 HTML 标签
  9070. $content = strip_tags($content);
  9071. // 去除 HTML 实体
  9072. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9073. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9074. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9075. // 去除多余空白
  9076. $content = preg_replace('/\s+/u', '', $content);
  9077. // 截取 100 个字符
  9078. $data['description'] = mb_substr($content, 0, 100);
  9079. }
  9080. $data['level'] = empty($data['level']) ? null : $data['level'];
  9081. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9082. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9083. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9084. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9085. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9086. $id = $data['id'];
  9087. unset($data['users_id']);
  9088. unset($data['id']);
  9089. // return Result::success($data);
  9090. Db::beginTransaction();
  9091. try{
  9092. $result = ResearchTopic::where('id', $id)->update($data);
  9093. if (empty($result)) {
  9094. Db::rollBack();
  9095. return Result::error('编辑调研选题失败!');
  9096. }
  9097. if(!empty($users_id) && is_string($users_id)){
  9098. $users = json_decode($users_id ?? '[]',true);
  9099. }
  9100. // return Result::success($users);
  9101. $retopic_users = RetopicUser::where('retopic_id', $id)->pluck('user_id')->toArray();
  9102. if(!empty($retopic_users)){
  9103. $del_users = RetopicUser::where('retopic_id', $id)->delete();
  9104. if(empty($del_users)){
  9105. Db::rollBack();
  9106. return Result::error('编辑同行人员失败!');
  9107. }
  9108. }
  9109. if(!empty($users) && is_array($users)){
  9110. // 去重:确保同一 retopic_id + user_id 组合唯一
  9111. $users = array_values(array_unique($users));
  9112. // 组装关联数据
  9113. $users_topic = [];
  9114. foreach ($users as $key => $value) {
  9115. $users_topic[$key] = [
  9116. 'user_id' => $value,
  9117. 'retopic_id' => $id,
  9118. ];
  9119. }
  9120. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9121. $retopic_user = RetopicUser::insert($users_topic);
  9122. if(empty($retopic_user)){
  9123. Db::rollBack();
  9124. return Result::error('编辑失败');
  9125. }
  9126. }
  9127. Db::commit();
  9128. return Result::success($result);
  9129. }catch(\Exception $e){
  9130. Db::rollBack();
  9131. return Result::error($e->getMessage());
  9132. }
  9133. }
  9134. /**
  9135. * 调研选题-删除
  9136. * @param array $data
  9137. * @return array
  9138. */
  9139. public function delResearchTopic(array $data): array
  9140. {
  9141. $user = User::where('id', $data['user_id'])->first();
  9142. if (empty($user)) {
  9143. return Result::error('用户不存在');
  9144. }
  9145. $topic = ResearchTopic::where('id', $data['id'])->first();
  9146. if (empty($topic)) {
  9147. return Result::error('此调研选题不存在');
  9148. }
  9149. Db::beginTransaction();
  9150. try{
  9151. $result = ResearchTopic::where('id', $data['id'])->delete();
  9152. if (empty($result)) {
  9153. Db::rollBack();
  9154. return Result::error('删除调研选题失败!');
  9155. }
  9156. $topic_users = RetopicUser::where('retopic_id', $data['id'])->pluck('user_id')->toArray();
  9157. if(!empty($topic_users)){
  9158. $del_topic_users = RetopicUser::where('retopic_id', $data['id'])->delete();
  9159. if(empty($del_topic_users)){
  9160. Db::rollBack();
  9161. return Result::error('删除同行人员失败!');
  9162. }
  9163. }
  9164. Db::commit();
  9165. return Result::success($result);
  9166. }catch(\Exception $e){
  9167. Db::rollBack();
  9168. return Result::error($e->getMessage());
  9169. }
  9170. }
  9171. /**
  9172. * 调研选题-列表
  9173. * @param array $data
  9174. * @return array
  9175. */
  9176. public function getResearchTopicList(array $data): array
  9177. {
  9178. $user = User::where('id', $data['user_id'])->first();
  9179. if (empty($user)) {
  9180. return Result::error('用户不存在!');
  9181. }
  9182. $where = [];
  9183. if($user->type_id != 10000){
  9184. $where['research_topic.user_id'] = $data['user_id'];
  9185. $website = Website::where('id', $data['website_id'])->first();
  9186. if (empty($website)) {
  9187. return Result::error('网站不存在!');
  9188. }
  9189. $web_column = json_decode($website->website_column_arr_id ?? '[]',true);
  9190. if(empty($web_column)){
  9191. return Result::error('网站未配置栏目!');
  9192. }
  9193. }
  9194. if($data['is_master'] != 0){
  9195. if($data['is_master'] == 3){
  9196. $where['research_topic.status'] = 0;
  9197. }else{
  9198. $where['research_topic.status'] = $data['is_master'];
  9199. }
  9200. }
  9201. if(!empty($data['title'])){
  9202. array_push($where, ['research_topic.title', 'like', '%'.$data['title'].'%']);
  9203. }
  9204. $page = $data['page'] ?? 1;
  9205. $page_size = $data['page_size'] ?? 10;
  9206. $research_topic = ResearchTopic::when($data['is_master'] == 0, function($query) use($data){
  9207. $query->whereIn('research_topic.status', [0,2]);
  9208. })
  9209. ->when(!empty($where), function($query) use($where){
  9210. $query->where($where);
  9211. })
  9212. ->with(['retopicUsers' => function ($query) {
  9213. $query->select('id', 'user_id', 'retopic_id');
  9214. }
  9215. ])
  9216. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9217. ->select('research_topic.id','research_topic.title','research_topic.updated_at','research_topic.status',
  9218. 'research_topic.due_time','user.nickname','research_topic.column_id','research_topic.user_id')
  9219. ->orderBy('research_topic.updated_at', 'desc')
  9220. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9221. if(empty($research_topic->items())){
  9222. return Result::error('暂无调研选题!');
  9223. }
  9224. $result = [
  9225. 'rows' => $research_topic->items(),
  9226. 'count' => $research_topic->total()
  9227. ];
  9228. foreach($result['rows'] as $key => $value){
  9229. if($user->type_id != 10000){
  9230. if(in_array($value['column_id'], $web_column)){
  9231. $result['rows'][$key]['is_update'] = 1;
  9232. }else{
  9233. $result['rows'][$key]['is_update'] = 0;
  9234. }
  9235. }else{
  9236. if($value['user_id'] == $data['user_id']){
  9237. $result['rows'][$key]['is_update'] = 1;
  9238. }else{
  9239. $result['rows'][$key]['is_update'] = 0;
  9240. }
  9241. }
  9242. if(!empty($value['retopicUsers'])){
  9243. $retopic_users = $value['retopicUsers'];
  9244. $retopic_user = $retopic_users->pluck('user_id')->toArray();
  9245. $result['rows'][$key]['txry_users'] = implode(',', $retopic_user);
  9246. unset($result['rows'][$key]['retopicUsers']);
  9247. }
  9248. }
  9249. return Result::success($result);
  9250. }
  9251. /**
  9252. * 调研选题-修改状态
  9253. * @param array $data
  9254. * @return array
  9255. */
  9256. public function checkResearchTopic(array $data): array
  9257. {
  9258. $user = User::where('id', $data['user_id'])->first();
  9259. if (empty($user)) {
  9260. return Result::error('用户不存在!');
  9261. }
  9262. if($user->type_id != 10000 && ($data['status'] == 1 || $data['status'] == 2)){
  9263. return Result::error('此用户暂无权限!');
  9264. }
  9265. $topic = ResearchTopic::where('id', $data['id'])->first();
  9266. if (empty($topic)) {
  9267. return Result::error('此调研选题不存在');
  9268. }
  9269. $id = $data['id'];
  9270. unset($data['id']);
  9271. unset($data['user_id']);
  9272. $result = ResearchTopic::where('id', $id)->update($data);
  9273. if (empty($result)) {
  9274. return Result::error('修改调研选题状态失败!');
  9275. }
  9276. return Result::success($result);
  9277. }
  9278. /**
  9279. * 调研选题-详情
  9280. * @param array $data
  9281. * @return array
  9282. */
  9283. public function getResearchTopicInfo(array $data): array
  9284. {
  9285. $user = User::where('id', $data['user_id'])->first();
  9286. if (empty($user)) {
  9287. return Result::error('用户不存在!');
  9288. }
  9289. $research_topic = ResearchTopic::where('research_topic.id', $data['id'])
  9290. ->with(['retopicUsers' => function ($query) {
  9291. $query->select('user_id','retopic_id');
  9292. }
  9293. ])
  9294. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9295. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9296. ->select('research_topic.*','user_info.number')
  9297. ->first();
  9298. if(empty($research_topic)){
  9299. return Result::error('获取调研选题详情失败!');
  9300. }
  9301. $retopic_user = $research_topic['retopicUsers'];
  9302. if(!empty($retopic_user)){
  9303. $retopic_user = $retopic_user->pluck('user_id')->toArray();
  9304. foreach($retopic_user as $key => $value){
  9305. $real_name = UserInfo::where('user_id', $value)->value('real_name');
  9306. $research_topic['retopicUsers'][$key]['real_name'] = $real_name;
  9307. $research_topic['retopicUsers'][$key]['user_id'] = $value;
  9308. unset($research_topic['retopicUsers'][$key]['retopic_id']);
  9309. }
  9310. }
  9311. return Result::success($research_topic);
  9312. }
  9313. /**
  9314. * 添加网站导航
  9315. * @param array $data
  9316. */
  9317. public function addWebCateinfo(array $data): array
  9318. {
  9319. $user = User::where('id', $data['user_id'])->first();
  9320. if (empty($user)) {
  9321. return Result::error('用户不存在');
  9322. }
  9323. if($user['type_id'] == 10000){
  9324. $data['status'] = 1;
  9325. }else{
  9326. $data['status'] = 0;
  9327. }
  9328. if ($data['keyword'] == '') {
  9329. //提取标题+内容中的关键词
  9330. $data['keyword'] = $data['title'];
  9331. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9332. Jieba::init(); // 初始化 jieba-php
  9333. Finalseg::init();
  9334. $segList = Jieba::cut($data['keyword']);
  9335. $segList1 = array_slice($segList, 0, 8);
  9336. $data['keyword'] = implode(',', $segList1);
  9337. }
  9338. if ($data['description'] == '') {
  9339. //提取内容中的描述
  9340. $content = $data['content'];
  9341. // 去除 <style> 和 <script> 标签及其内容
  9342. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9343. // 去除所有 HTML 标签
  9344. $content = strip_tags($content);
  9345. // 去除 HTML 实体
  9346. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9347. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9348. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9349. // 去除多余空白
  9350. $content = preg_replace('/\s+/u', '', $content);
  9351. // 截取 100 个字符
  9352. $data['description'] = mb_substr($content, 0, 100);
  9353. }
  9354. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9355. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9356. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9357. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9358. unset($data['users_id']);
  9359. $result = WebCateinfo::insertGetId($data);
  9360. if (empty($result)) {
  9361. return Result::error('添加失败');
  9362. }
  9363. return Result::success($result);
  9364. }
  9365. /**
  9366. * 更新网站导航
  9367. * @param array $data
  9368. */
  9369. public function upWebCateinfo(array $data): array
  9370. {
  9371. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9372. if (empty($webCateinfo)) {
  9373. return Result::error('导航不存在');
  9374. }
  9375. $user = User::where('id', $data['user_id'])->first();
  9376. if (empty($user)) {
  9377. return Result::error('用户不存在');
  9378. }
  9379. if($user['type_id'] == 10000){
  9380. $data['status'] = 1;
  9381. }else{
  9382. $data['status'] = 0;
  9383. }
  9384. if ($data['keyword'] == '') {
  9385. //提取标题+内容中的关键词
  9386. $data['keyword'] = $data['title'];
  9387. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9388. Jieba::init(); // 初始化 jieba-php
  9389. Finalseg::init();
  9390. $segList = Jieba::cut($data['keyword']);
  9391. $segList1 = array_slice($segList, 0, 8);
  9392. $data['keyword'] = implode(',', $segList1);
  9393. }
  9394. if ($data['description'] == '') {
  9395. //提取内容中的描述
  9396. $content = $data['content'];
  9397. // 去除 <style> 和 <script> 标签及其内容
  9398. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9399. // 去除所有 HTML 标签
  9400. $content = strip_tags($content);
  9401. // 去除 HTML 实体
  9402. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9403. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9404. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9405. // 去除多余空白
  9406. $content = preg_replace('/\s+/u', '', $content);
  9407. // 截取 100 个字符
  9408. $data['description'] = mb_substr($content, 0, 100);
  9409. }
  9410. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9411. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9412. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9413. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9414. unset($data['users_id']);
  9415. $result = WebCateinfo::where('id', $data['id'])->update($data);
  9416. if (empty($result)) {
  9417. return Result::error('更新失败');
  9418. }
  9419. return Result::success($result);
  9420. }
  9421. /**
  9422. * 获取网站导航列表
  9423. * @param array $data
  9424. * @return array
  9425. */
  9426. public function getWebCateinfoList(array $data): array
  9427. {
  9428. $user = User::where('id', $data['user_id'])->first();
  9429. if (empty($user)) {
  9430. return Result::error('用户不存在');
  9431. }
  9432. $where = [];
  9433. if($user['type_id'] != 10000){
  9434. $where['web_cateinfo.user_id'] = $data['user_id'];
  9435. }
  9436. if(!empty($data['title'])){
  9437. array_push($where, ['web_cateinfo.title', 'like', '%'.$data['title'].'%']);
  9438. }
  9439. if($data['is_master'] != 0){
  9440. if($data['is_master'] == 3){
  9441. $where['web_cateinfo.status'] = 0;
  9442. }else{
  9443. $where['web_cateinfo.status'] = $data['is_master'];
  9444. }
  9445. }
  9446. $web_cateinfo = WebCateinfo::when(!empty($data['is_master'] == 0), function ($query) use ($where) {
  9447. $query->whereIn('web_cateinfo.status', [0, 2]);
  9448. })
  9449. ->when(!empty($where), function ($query) use ($where) {
  9450. $query->where($where);
  9451. })
  9452. ->leftJoin('user', 'web_cateinfo.user_id', '=', 'user.id')
  9453. ->select(['web_cateinfo.id', 'web_cateinfo.user_id', 'user.nickname', 'web_cateinfo.title', 'web_cateinfo.cate_name', 'web_cateinfo.status','web_cateinfo.updated_at'])
  9454. ->orderBy('updated_at', 'desc')
  9455. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9456. if(empty($web_cateinfo->items())){
  9457. return Result::error('官网导航不存在');
  9458. }
  9459. $result = [
  9460. 'rows' => $web_cateinfo->items(),
  9461. 'total' => $web_cateinfo->total(),
  9462. ];
  9463. foreach($result['rows'] as $key => $value){
  9464. if($value['user_id'] == $data['user_id']){
  9465. $result['rows'][$key]['is_update'] = 1;
  9466. }else{
  9467. $result['rows'][$key]['is_update'] = 0;
  9468. }
  9469. }
  9470. return Result::success($result);
  9471. }
  9472. /**
  9473. * 删除网站导航
  9474. * @param array $data
  9475. */
  9476. public function delWebCateinfo(array $data): array
  9477. {
  9478. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9479. if (empty($webCateinfo)) {
  9480. return Result::error('导航不存在');
  9481. }
  9482. $result = WebCateinfo::where('id', $data['id'])->delete();
  9483. if (empty($result)) {
  9484. return Result::error('删除失败');
  9485. }
  9486. return Result::success($result);
  9487. }
  9488. /**
  9489. * 审核网站导航
  9490. * @param array $data
  9491. */
  9492. public function checkWebCateinfo(array $data): array
  9493. {
  9494. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9495. if (empty($webCateinfo)) {
  9496. return Result::error('导航不存在');
  9497. }
  9498. $user = User::where('id', $data['user_id'])->first();
  9499. if (empty($user)) {
  9500. return Result::error('用户不存在');
  9501. }
  9502. if($user['type_id'] != 10000 && $data['status'] == 1){
  9503. return Result::error('非管理员不能审核');
  9504. }
  9505. $update_data['status'] = $data['status'];
  9506. if($data['status'] == 2){
  9507. $update_data['reason'] = $data['reason'];
  9508. }
  9509. $result = WebCateinfo::where('id', $data['id'])->update($update_data);
  9510. if (empty($result)) {
  9511. return Result::error('审核失败');
  9512. }
  9513. return Result::success($result);
  9514. }
  9515. /**
  9516. * 获取网站导航详情
  9517. * @param array $data
  9518. */
  9519. public function getWebCateinfoDetail(array $data): array
  9520. {
  9521. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9522. if (empty($webCateinfo)) {
  9523. return Result::error('导航不存在');
  9524. }
  9525. $result = $webCateinfo->toArray();
  9526. return Result::success($result);
  9527. }
  9528. }