NewsService.php 338 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  73. class NewsService implements NewsServiceInterface
  74. {
  75. #[Inject]
  76. protected Redis $redis;
  77. /**
  78. * 获取导航池列表
  79. * @param array $data
  80. * @return array
  81. */
  82. public function getCategoryList(array $data): array
  83. {
  84. $search = $data['name'] ?? '';
  85. $page = (int)($data['page'] ?? 1);
  86. $perPage = (int)($data['pageSize'] ?? 10);
  87. // 1. 查出所有匹配的分类id
  88. if ($search) {
  89. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  90. if (empty($matchedIds)) {
  91. return Result::success(['rows' => [], 'total' => 0]);
  92. }
  93. // 2. 递归查所有父级,直到一级分类
  94. $idsStr = implode(',', $matchedIds);
  95. $sql = "
  96. WITH RECURSIVE parents AS (
  97. SELECT * FROM category WHERE id IN ($idsStr)
  98. UNION ALL
  99. SELECT c.* FROM category c
  100. INNER JOIN parents p ON c.id = p.pid
  101. )
  102. SELECT * FROM parents
  103. ";
  104. $parents = Db::select($sql);
  105. $parentIds = [];
  106. foreach ($parents as $row) {
  107. if ($row->pid == 0) {
  108. $parentIds[] = $row->id;
  109. }
  110. }
  111. $parentIds = array_unique($parentIds);
  112. } else {
  113. // 没有搜索,一级分类就是根
  114. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  115. }
  116. // 3. 一级分类分页
  117. $total = count($parentIds);
  118. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  119. if (empty($parentIds)) {
  120. return Result::success(['rows' => [], 'total' => $total]);
  121. }
  122. // 4. 递归查所有子孙
  123. $idsStr = implode(',', $parentIds);
  124. $sql = "
  125. WITH RECURSIVE subcategories AS (
  126. SELECT * FROM category WHERE id IN ($idsStr)
  127. UNION ALL
  128. SELECT c.* FROM category c
  129. INNER JOIN subcategories s ON c.pid = s.id
  130. )
  131. SELECT * FROM subcategories ORDER BY updated_at DESC
  132. ";
  133. $allCategories = Db::select($sql);
  134. // 5. 组装树结构
  135. $categoryMap = [];
  136. foreach ($allCategories as $cat) {
  137. $cat = (array)$cat;
  138. $cat['children'] = [];
  139. $categoryMap[$cat['id']] = $cat;
  140. }
  141. foreach ($categoryMap as $id => &$cat) {
  142. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  143. $categoryMap[$cat['pid']]['children'][] = &$cat;
  144. }
  145. }
  146. unset($cat);
  147. $categoryTree = [];
  148. foreach ($parentIds as $id) {
  149. if (isset($categoryMap[$id])) {
  150. $categoryTree[] = $categoryMap[$id];
  151. }
  152. }
  153. return Result::success([
  154. 'rows' => $categoryTree,
  155. 'total' => $total,
  156. ]);
  157. }
  158. private function findMatchedCategories($search)
  159. {
  160. if ($search) {
  161. return Category::where('name', 'like', "%{$search}%")
  162. ->orderBy('updated_at', 'desc')
  163. ->get();
  164. }
  165. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  166. ->get();
  167. }
  168. private function findAllParents($categories)
  169. {
  170. $allCategories = [];
  171. foreach ($categories as $category) {
  172. $parentId = $category->pid;
  173. while ($parentId > 0) {
  174. $parent = Category::find($parentId);
  175. if ($parent) {
  176. $allCategories[$parent->id] = $parent;
  177. $parentId = $parent->pid;
  178. } else {
  179. break;
  180. }
  181. }
  182. $allCategories[$category->id] = $category;
  183. }
  184. return array_values($allCategories);
  185. }
  186. private function buildCategoryTree($category, $allRequiredCategories)
  187. {
  188. $categoryData = $category->toArray();
  189. $children = [];
  190. foreach ($allRequiredCategories as $c) {
  191. if ($c->pid === $category->id) {
  192. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  193. }
  194. }
  195. if (!empty($children)) {
  196. $categoryData['children'] = $children;
  197. }
  198. return $categoryData;
  199. }
  200. public function myCategoryList(array $data): array
  201. {
  202. $sszq = $data['sszq'] ?? '';
  203. unset($data['sszq']);
  204. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  205. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  206. $where[] = [
  207. 'pid',
  208. '=',
  209. $data['pid'],
  210. ];
  211. if (isset($data['name'])) {
  212. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  213. }
  214. var_dump($where);
  215. //根据分类id,从category表中取出分类信息
  216. $result = Category::where($where)
  217. ->whereIn('category.id', $catorytids)
  218. ->select('category.*', 'category.id as category_id')->get();
  219. if (empty($result)) {
  220. return Result::error("没有栏目数据");
  221. }
  222. return Result::success($result);
  223. }
  224. /**
  225. * @param array $data
  226. * @return array
  227. */
  228. public function categoryList(array $data): array
  229. {
  230. $where[] = [
  231. 'pid',
  232. '=',
  233. $data['pid']
  234. ];
  235. if (isset($data['name'])) {
  236. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  237. }
  238. var_dump($where);
  239. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  240. if (empty($result)) {
  241. return Result::error("没有栏目数据");
  242. }
  243. return Result::success($result);
  244. }
  245. /**
  246. * @param array $data
  247. * @return array
  248. */
  249. public function addCategory(array $data): array
  250. {
  251. if (isset($data['id'])) {
  252. unset($data['id']);
  253. }
  254. $id = Category::insertGetId($data);
  255. if (empty($id)) {
  256. return Result::error("添加失败");
  257. }
  258. return Result::success(['id' => $id]);
  259. }
  260. /**
  261. * @param array $data
  262. * @return array
  263. */
  264. public function delCategory(array $data): array
  265. {
  266. Db::beginTransaction();
  267. try {
  268. $categoryList = Category::where(['pid' => $data['id']])->get();
  269. if ($categoryList->toArray()) {
  270. Db::rollBack();
  271. return Result::error("分类下面有子分类不能删除");
  272. }
  273. $articleList = Article::where(['catid' => $data['id']])->get();
  274. if ($articleList->toArray()) {
  275. Db::rollBack();
  276. return Result::error("分类下面有资讯不能删除");
  277. }
  278. $result = Category::where($data)->delete();
  279. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  280. if (!$result) {
  281. Db::rollBack();
  282. return Result::error("删除失败");
  283. }
  284. Db::commit();
  285. return Result::success($result);
  286. } catch (\Exception $e) {
  287. Db::rollBack();
  288. return Result::error("删除失败" . $e->getMessage());
  289. }
  290. }
  291. /**
  292. * @param array $data
  293. * @return array
  294. */
  295. public function updateCategory(array $data): array
  296. {
  297. $where = [
  298. 'id' => $data['id'],
  299. ];
  300. $result = Category::where($where)->update($data);
  301. if ($result) {
  302. return Result::success($result);
  303. } else {
  304. return Result::error("更新失败");
  305. }
  306. }
  307. /**
  308. * 获取导航池信息
  309. * @param array $data
  310. * @return array
  311. */
  312. public function getCategoryInfo(array $data): array
  313. {
  314. $where = [
  315. 'id' => $data['id'],
  316. ];
  317. $result = Category::where($where)->first();
  318. if ($result) {
  319. return Result::success($result);
  320. } else {
  321. return Result::error("更新失败");
  322. }
  323. }
  324. public function getArticleCommend(array $data): array
  325. {
  326. $where = [
  327. 'website_id' => $data['website_id'],
  328. ];
  329. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  330. var_dump($ids);
  331. if (empty($ids)) {
  332. return Result::error("没有推荐数据");
  333. }
  334. //id
  335. $whereArticle = [];
  336. if (isset($data['id'])) {
  337. $whereArticle['id'] = $data['id'];
  338. }
  339. //title like
  340. if (isset($data['title'])) {
  341. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  342. }
  343. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  344. ->where($whereArticle)
  345. ->orderBy('id', 'desc')
  346. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  347. if ($article) {
  348. $data = [
  349. 'rows' => $article->items(),
  350. 'count' => $article->total(),
  351. ];
  352. return Result::success($data);
  353. } else {
  354. return Result::error("获取失败失败");
  355. }
  356. }
  357. /**
  358. * @param array $data
  359. * @return array
  360. */
  361. public function getArticleList(array $data): array
  362. {
  363. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  364. $type_id = $data['type_id'];
  365. unset($data['type_id']);
  366. $user_id = $data['user_id'];
  367. unset($data['user_id']);
  368. $where = [];
  369. $status1 = [];
  370. if (isset($data['id']) && $data['id']) {
  371. array_push($where, ['article.id', '=', $data['id']]);
  372. }
  373. if (isset($data['title']) && $data['title']) {
  374. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  375. }
  376. if (isset($data['category_name']) && $data['category_name']) {
  377. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  378. }
  379. if (isset($data['catid']) && $data['catid']) {
  380. array_push($where, ['article.catid', '=', $data['catid']]);
  381. }
  382. if (isset($data['author']) && $data['author']) {
  383. array_push($where, ['article.author', '=', $data['author']]);
  384. }
  385. if (isset($data['islink']) && $data['islink'] !== "") {
  386. array_push($where, ['article.islink', '=', $data['islink']]);
  387. }
  388. if (isset($data['status']) && $data['status'] !== "") {
  389. array_push($where, ['article.status', '=', $data['status']]);
  390. }
  391. if (isset($data['status1'])) {
  392. $status1 = json_decode(($data['status1']));
  393. }
  394. //不是管理员展示个人数据;
  395. if ($type_id != 10000) {
  396. $where[] = ['article.admin_user_id', '=', $user_id];
  397. }
  398. $startTime = microtime(true);
  399. $rep = Article::query()
  400. // 预加载相关关联
  401. ->with([
  402. 'category' => function ($query) {
  403. $query->select('id', 'name');
  404. },
  405. 'websiteCategory' => function ($query) {
  406. $query->select('website_id', 'category_id', 'alias');
  407. },'user' => function ($query) {
  408. $query->select('id', 'nickname');
  409. }
  410. ])
  411. // 构建where条件
  412. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  413. $query->where('article.id', '=', $data['id']);
  414. })
  415. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  416. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  417. })
  418. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  419. // 使用子查询替代左连接进行模糊搜索
  420. $query->whereHas('category', function ($subQuery) use ($data) {
  421. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  422. });
  423. })
  424. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  425. $query->where('article.catid', '=', $data['catid']);
  426. })
  427. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  428. $query->where('article.author', '=', $data['author']);
  429. })
  430. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  431. $query->where('article.islink', '=', $data['islink']);
  432. })
  433. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  434. $query->where('article.status', '=', $data['status']);
  435. })
  436. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  437. // 安全地处理JSON字符串
  438. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  439. if (!empty($status1)) {
  440. $query->whereIn('article.status', $status1);
  441. }
  442. })
  443. ->select('article.*')
  444. // 非管理员限制
  445. ->when($type_id != 10000, function ($query) use ($user_id) {
  446. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  447. $query->where('article.admin_user_id', $user_id)
  448. ->leftJoin('article_ignore', function ($join) {
  449. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  450. $join->on('article_ignore.article_id', '=', 'article.id')
  451. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  452. })
  453. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  454. })
  455. // 基础条件
  456. ->whereNotIn('article.status', [404])
  457. // 排序和分页
  458. ->orderBy('article.updated_at', 'desc')
  459. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  460. // 获取结果并格式化
  461. $data = [
  462. 'rows' => $rep->items(),
  463. 'count' => $rep->total(),
  464. ];
  465. // 执行查询
  466. $endTime = microtime(true);
  467. $executionTime = ($endTime - $startTime) * 1000;
  468. echo "查询执行时间: {$executionTime}ms\n";
  469. return Result::success($data);
  470. }
  471. /**
  472. * @param array $data
  473. * @return array
  474. */
  475. public function addArticle(array $data): array
  476. {
  477. var_dump($data, '----------12-----------1');
  478. // ------c_show_time********add***1****
  479. $is_collect = $data['is_collect'] ?? 0;
  480. $user_type = $data['user_type'];
  481. unset($data['is_collect']);
  482. unset($data['user_type']);
  483. // ------c_show_time********add***1****
  484. unset($data['nav_add_pool_id']);
  485. // unset($data['commend_id']);
  486. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  487. Db::beginTransaction();
  488. try {
  489. //处理投票
  490. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  491. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  492. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  493. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  494. unset($data['is_survey']);
  495. unset($data['survey_name']);
  496. unset($data['suvey_array']);
  497. // unset($data['website_id']);
  498. // unset($data['web_site_id']);
  499. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  500. if ($data['hits'] == '') {
  501. $data['hits'] = 0;
  502. }
  503. if ($data['is_original'] == '') {
  504. $data['is_original'] = 0;
  505. }
  506. if ($data['status'] == '') {
  507. $data['status'] = 0;
  508. }
  509. $articleData = $data;
  510. unset($articleData['content']);
  511. //自动处理缩略图、关键字、描述
  512. if ($articleData['imgurl'] == '') {
  513. //如果没有图,设置level=0
  514. $levelArr = json_decode($articleData['level'], true);
  515. var_dump($levelArr, '----------levelArr-----------1');
  516. //content中提取图片第一个图,正则提取
  517. // -------采集器相关优化-----
  518. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  519. if ($is_collect == 1) {
  520. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  521. } else {
  522. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  523. }
  524. // -------采集器相关优化-----
  525. preg_match_all($reg, $data['content'], $matches);
  526. if (isset($matches[1][0])) {
  527. //截取varchar240
  528. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  529. //如果有图,设置level=3
  530. if (!in_array(3, $levelArr)) {
  531. $levelArr[] = 3;
  532. }
  533. $articleData['level'] = json_encode($levelArr);
  534. } else {
  535. if (!in_array(0, $levelArr)) {
  536. $levelArr[] = 0;
  537. }
  538. $articleData['level'] = json_encode($levelArr);
  539. }
  540. }
  541. var_dump($articleData['level'], '----------$articleData[level]----------1');
  542. if ($articleData['keyword'] == '') {
  543. //提取标题+内容中的关键词
  544. $articleData['keyword'] = $data['title'];
  545. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  546. Jieba::init(); // 初始化 jieba-php
  547. Finalseg::init();
  548. $segList = Jieba::cut($articleData['keyword']);
  549. $segList1 = array_slice($segList, 0, 8);
  550. $articleData['keyword'] = implode(',', $segList1);
  551. }
  552. if ($articleData['introduce'] == '') {
  553. //提取内容中的描述
  554. $content = $data['content'];
  555. // 去除 <style> 和 <script> 标签及其内容
  556. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  557. // 去除所有 HTML 标签
  558. $content = strip_tags($content);
  559. // 去除 HTML 实体
  560. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  561. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  562. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  563. // 去除多余空白
  564. $content = preg_replace('/\s+/u', '', $content);
  565. // 截取 100 个字符
  566. $articleData['introduce'] = mb_substr($content, 0, 100);
  567. }
  568. if ($articleData['status'] == 0) {
  569. $this->sendMessage([
  570. 'talk_type' => 100,
  571. 'title' => $articleData['title'],
  572. 'content' => '提交了审核',
  573. 'messageType' => 2,
  574. ]);
  575. }
  576. if(!empty($data['fujian'])){
  577. $articleData['fujian'] = $data['fujian'];
  578. }
  579. $id = Article::insertGetId($articleData);
  580. if (!$id) {
  581. throw new \Exception('文章插入失败');
  582. }
  583. $articleDataContent = [
  584. 'article_id' => $id,
  585. 'content' => $data['content'],
  586. ];
  587. // 采集器中的文章内容,在添加时,去掉div标签
  588. if ($is_collect == 1) {
  589. // 采集来的文章,content中可能包含div标签,需要先移除
  590. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  591. $article_data = preg_replace($pattern, '', $data['content']);
  592. $$articleDataContent['content'] = $article_data;
  593. }
  594. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  595. if (!$contentInsertId) {
  596. throw new \Exception('文章内容插入失败');
  597. }
  598. // ------c_show_time********add***2****
  599. // 直接使用当前系统时间,不再强制添加8小时
  600. $now = date('Y-m-d H:i:s');
  601. if ($user_type == 10000 || $is_collect == 1) {
  602. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  603. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  604. if (!isset($data['catid'])) {
  605. throw new \Exception('缺少必要字段:catid');
  606. }
  607. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  608. $web = WebsiteCategory::where('category_id', $data['catid'])
  609. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  610. ->select(
  611. 'website_id',
  612. 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')
  613. )
  614. ->get();
  615. // $id = 225; -----测试开启
  616. // 采集来的文章,错开时间在两小时之内发布
  617. if ($user_type == 10000 && $is_collect == 1) {
  618. $web_num = $web->where('is_core', '!=', 2)->count();
  619. $waiting_interval = 10;
  620. if ($web_num > 12) {
  621. // 若网站数量大于12个,则每个网站间隔时间取均值
  622. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  623. $waiting_interval = 120 / max(1, $web_num);
  624. }
  625. $time = 0;
  626. } else {
  627. // 非核心站与核心站----显示时间-----间隔
  628. $time = 20;
  629. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  630. $waiting_interval = 5;
  631. }
  632. // 将 Hyperf\Database\Model\Collection 转换为数组
  633. $webArray = $web->toArray();
  634. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  635. // 检查 $item 对象是否有 is_core 属性
  636. if (!isset($item['is_core'])) {
  637. throw new \Exception('$item 对象缺少 is_core 属性');
  638. }
  639. // 当 is_core 为 2 时,则表示此网站不存在
  640. if ($item['is_core'] == 2) {
  641. return null;
  642. }
  643. if ($is_collect == 1) {
  644. // 采集来的文章,错开时间在两小时之内发布
  645. // $time = 0;
  646. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  647. $time += $waiting_interval;
  648. } else if ($item['is_core'] == 1) {
  649. // 当 is_core 为 1 时,则表示此网站是核心站
  650. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  651. } else {
  652. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  653. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  654. if ($item['is_core'] == 0) {
  655. $time += $waiting_interval;
  656. }
  657. }
  658. return [
  659. 'article_id' => $id,
  660. 'website_id' => $item['website_id'],
  661. 'c_show_time' => $c_show_time,
  662. // 'is_core' => $item['is_core'],
  663. // 'time' => $time
  664. ];
  665. }, array_keys($webArray), $webArray)));
  666. // Db::commit();
  667. // return Result::success($article_ignore);
  668. if (!empty($article_ignore)) {
  669. $article_ignores = ArticleIgnore::insert($article_ignore);
  670. if (!$article_ignores) {
  671. throw new \Exception('c端展示时间插入失败');
  672. }
  673. }
  674. }
  675. // ------c_show_time********add***2****
  676. //处理投票
  677. if ($is_survey == 1) {
  678. //生成年月日时分秒+8位随机数
  679. $uuid = date('YmdHis') . rand(10000000, 99999999);
  680. var_dump($suvey_array, 'suvey_array________');
  681. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  682. var_dump($suveys_array, '---------------------1');
  683. var_dump($suvey_array, '---------------------2');
  684. $suvey_data = [];
  685. foreach ($suveys_array as $key => $value) {
  686. if ($value == '') {
  687. continue;
  688. }
  689. if (is_array($value)) {
  690. $suvey_data[] = [
  691. 'sur_id' => $uuid,
  692. 'art_id' => $id,
  693. 'website_id' => $website_id ?? 2,
  694. 'survey_name' => $survey_name,
  695. 'choice_name' => $value[1],
  696. 'is_other' => 1,
  697. 'other_id' => 0,
  698. 'results' => 0,
  699. ];
  700. } else {
  701. $suvey_data[] = [
  702. 'sur_id' => $uuid,
  703. 'art_id' => $id,
  704. 'website_id' => $website_id ?? 2,
  705. 'survey_name' => $survey_name,
  706. 'choice_name' => $value,
  707. 'is_other' => 0,
  708. 'other_id' => 0,
  709. 'results' => 0,
  710. ];
  711. }
  712. if (empty($suvey_data)) {
  713. throw new \Exception("投票数据为空");
  714. }
  715. }
  716. $result = ArticleSurvey::insert($suvey_data);
  717. if (!$result) {
  718. throw new \Exception("投票失败,ArticleSurvey插入失败");
  719. }
  720. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  721. if (!$result) {
  722. throw new \Exception("投票失败,更新主表失败");
  723. }
  724. }
  725. Db::commit();
  726. return Result::success(['id' => $id]);
  727. } catch (\Throwable $ex) {
  728. Db::rollBack();
  729. var_dump($ex->getMessage());
  730. return Result::error("创建失败", 0);
  731. }
  732. }
  733. /**
  734. * @param array $data
  735. * @return array
  736. */
  737. public function delArticle(array $data): array
  738. {
  739. // ------c_show_time********del*******
  740. Db::beginTransaction();
  741. try {
  742. $article = Article::where(['id' => $data['id']])->delete();
  743. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  744. if (!$article) {
  745. throw new \Exception("删除失败,文章删除失败");
  746. }
  747. //survey投票删除
  748. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  749. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  750. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  751. // 若文章详情删除失败,抛出异常
  752. if (!$article_data) {
  753. throw new \Exception("删除失败,文章详情删除失败");
  754. }
  755. Db::commit(); // 所有操作成功,提交事务
  756. } catch (\Throwable $ex) {
  757. Db::rollBack();
  758. var_dump($ex->getMessage());
  759. return Result::error("删除失败: " . $ex->getMessage(), 0);
  760. }
  761. // ------c_show_time********del*******
  762. if (!$article) {
  763. return Result::error("删除失败");
  764. }
  765. return Result::success($article);
  766. }
  767. /**
  768. * @param array $data
  769. * @return array
  770. */
  771. public function updateArticle(array $data): array
  772. {
  773. var_dump($data, '----------12-----------1');
  774. Db::beginTransaction();
  775. // ------c_show_time********up*******
  776. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  777. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  778. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  779. $web = WebsiteCategory::where('category_id', $data['catid'])
  780. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  781. ->select(
  782. 'website_id',
  783. 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')
  784. )
  785. ->get();
  786. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  787. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  788. $websiteIds = $web->pluck('website_id')->toArray();
  789. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  790. if ($user_type == 0) {
  791. throw new \Exception("用户类型不能为空");
  792. }
  793. if ($user_type == 10000) {
  794. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  795. $web = WebsiteCategory::where('category_id', $data['catid'])
  796. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  797. ->select(
  798. 'website_id',
  799. 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')
  800. )
  801. ->get();
  802. // 非核心站与核心站----显示时间-----间隔
  803. $time = 20;
  804. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  805. $waiting_interval = 5;
  806. $webArray = $web->toArray();
  807. if (empty($webArray)) {
  808. throw new \Exception('网站分类不存在');
  809. }
  810. // 直接使用当前系统时间,不再强制添加8小时
  811. $now = date('Y-m-d H:i:s');
  812. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  813. // 检查 $item 对象是否有 is_core 属性
  814. if (!isset($item['is_core'])) {
  815. throw new \Exception('$item 对象缺少 is_core 属性');
  816. }
  817. // 当 is_core 为 2 时,则表示此网站不存在
  818. if ($item['is_core'] == 2) {
  819. return null;
  820. } else if ($item['is_core'] == 1) {
  821. // 当 is_core 为 1 时,则表示此网站是核心站
  822. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  823. } else {
  824. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  825. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  826. if ($item['is_core'] == 0) {
  827. $time += $waiting_interval;
  828. }
  829. }
  830. return [
  831. 'article_id' => $data['id'],
  832. 'website_id' => $item['website_id'],
  833. 'c_show_time' => $c_show_time,
  834. ];
  835. }, array_keys($webArray), $webArray)));
  836. if (!empty($article_ignore)) {
  837. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  838. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  839. $article_ignores = ArticleIgnore::upsert(
  840. $article_ignore,
  841. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  842. ['c_show_time'] // 需要更新的字段
  843. );
  844. if (!$article_ignores) {
  845. throw new \Exception('c端展示时间插入失败');
  846. }
  847. }
  848. // Db::commit();
  849. // return Result::success($article_ignore);
  850. }
  851. // ------c_show_time********up*******
  852. unset($data['user_type']);
  853. // unset($data['web_site_id']);
  854. unset($data['nav_add_pool_id']);
  855. try {
  856. //处理投票
  857. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  858. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  859. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  860. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  861. unset($data['is_survey']);
  862. unset($data['survey_name']);
  863. unset($data['suvey_array']);
  864. unset($data['website_id']);
  865. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  866. if ($data['hits'] == '') {
  867. $data['hits'] = 0;
  868. }
  869. if ($data['is_original'] == '') {
  870. $data['is_original'] = 0;
  871. }
  872. if ($data['status'] == '') {
  873. $data['status'] = 0;
  874. }
  875. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  876. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  877. $articleData = $data;
  878. unset($articleData['content']);
  879. unset($articleData['status_name']);
  880. unset($articleData['name']);
  881. unset($articleData['content']);
  882. unset($articleData['pid_arr']);
  883. unset($articleData['pid']);
  884. //自动处理缩略图、关键字、描述
  885. if ($articleData['imgurl'] == '') {
  886. //如果没有图,设置level=0
  887. $levelArr = json_decode($articleData['level'], true);
  888. var_dump($levelArr, '----------levelArr-----------1');
  889. //content中提取图片第一个图,正则提取
  890. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  891. preg_match_all($reg, $data['content'], $matches);
  892. if (isset($matches[1][0])) {
  893. //截取varchar240
  894. // 截取到第一个<
  895. $articleData['imgurl'] = $matches[1][0];
  896. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  897. $pos = strpos($articleData['imgurl'], '"');
  898. if ($pos !== false) {
  899. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  900. }
  901. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  902. //如果有图,设置level=3
  903. if (!in_array(3, $levelArr)) {
  904. $levelArr[] = 3;
  905. }
  906. $articleData['level'] = json_encode($levelArr);
  907. } else {
  908. if (!in_array(0, $levelArr)) {
  909. $levelArr[] = 0;
  910. }
  911. $articleData['level'] = json_encode($levelArr);
  912. }
  913. }
  914. var_dump($articleData['level'], '----------$articleData[level]----------1');
  915. if ($articleData['keyword'] == '') {
  916. //提取标题+内容中的关键词
  917. $articleData['keyword'] = $data['title'];
  918. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  919. Jieba::init(); // 初始化 jieba-php
  920. Finalseg::init();
  921. $segList = Jieba::cut($articleData['keyword']);
  922. $segList1 = array_slice($segList, 0, 8);
  923. $articleData['keyword'] = implode(',', $segList1);
  924. }
  925. if ($articleData['introduce'] == '') {
  926. //提取内容中的描述
  927. $content = $data['content'];
  928. // 去除 <style> 和 <script> 标签及其内容
  929. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  930. // 去除所有 HTML 标签
  931. $content = strip_tags($content);
  932. // 去除 HTML 实体
  933. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  934. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  935. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  936. // 去除多余空白
  937. $content = preg_replace('/\s+/u', '', $content);
  938. // 截取 100 个字符
  939. $articleData['introduce'] = mb_substr($content, 0, 100);
  940. }
  941. if ($articleData['status'] == 0) {
  942. $this->sendMessage([
  943. 'talk_type' => 100,
  944. 'title' => $articleData['title'],
  945. 'content' => '提交了审核',
  946. 'messageType' => 2,
  947. ]);
  948. }
  949. if(!empty($data['fujian'])){
  950. $articleData['fujian'] = $data['fujian'];
  951. }
  952. $id = Article::where(['id' => $data['id']])->update($articleData);
  953. // $articleDataContent = [
  954. // 'content' => $data['content'],
  955. // ];
  956. // 采集来的文章,content中可能包含div标签,需要先移除
  957. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  958. $article_data = preg_replace($pattern, '', $data['content']);
  959. $articleDataContent['content'] = $article_data;
  960. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  961. //处理投票
  962. $id = $data['id'];
  963. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  964. var_dump($suvey_array, 'suvey_array________delete');
  965. //处理投票
  966. if ($is_survey == 1) {
  967. //生成年月日时分秒+8位随机数
  968. $uuid = date('YmdHis') . rand(10000000, 99999999);
  969. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  970. var_dump($suveys_array, '---------------------1');
  971. $suvey_data = [];
  972. if (is_array($suveys_array)) {
  973. foreach ($suveys_array as $key => $value) {
  974. if ($value == '') {
  975. continue;
  976. }
  977. if (is_array($value)) {
  978. $suvey_data[] = [
  979. 'sur_id' => $uuid,
  980. 'art_id' => $id,
  981. 'website_id' => $website_id ?? 2,
  982. 'survey_name' => $survey_name,
  983. 'choice_name' => $value[1],
  984. 'is_other' => 1,
  985. 'other_id' => 0,
  986. 'results' => 0,
  987. ];
  988. } else {
  989. $suvey_data[] = [
  990. 'sur_id' => $uuid,
  991. 'art_id' => $id,
  992. 'website_id' => $website_id ?? 2,
  993. 'survey_name' => $survey_name,
  994. 'choice_name' => $value,
  995. 'is_other' => 0,
  996. 'other_id' => 0,
  997. 'results' => 0,
  998. ];
  999. }
  1000. if (empty($suvey_data)) {
  1001. throw new \Exception("投票数据为空");
  1002. }
  1003. }
  1004. }
  1005. $result = ArticleSurvey::insert($suvey_data);
  1006. if (!$result) {
  1007. throw new \Exception("投票失败");
  1008. }
  1009. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1010. if (!$result) {
  1011. throw new \Exception("投票失败");
  1012. }
  1013. } else {
  1014. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1015. }
  1016. Db::commit();
  1017. return Result::success([]);
  1018. } catch (\Throwable $ex) {
  1019. Db::rollBack();
  1020. var_dump($ex->getMessage());
  1021. return Result::error("更新失败" . $ex->getMessage(), 0);
  1022. }
  1023. }
  1024. /**
  1025. * 更新资讯状态
  1026. * @param array $data
  1027. * @return array
  1028. */
  1029. public function upArticleStatus(array $data): array
  1030. {
  1031. $articleData = Article::where(['id' => $data['id']])->first();
  1032. //发送10次
  1033. // for ($i = 0; $i < 10; $i++) {
  1034. // $this->sendMessage([
  1035. // 'talk_type' => 100,
  1036. // 'title' => $i . $articleData['title'],
  1037. // 'content' => '审核通过',
  1038. // 'messageType' => 2,
  1039. // 'user_id' => $articleData['admin_user_id'],
  1040. // ]);
  1041. // }
  1042. // var_dump($data['status'], 'status');
  1043. // return Result::success();
  1044. if ($data['status'] == 1) {
  1045. $this->sendMessage([
  1046. 'talk_type' => 101,
  1047. 'title' => $articleData['title'],
  1048. 'content' => '审核通过',
  1049. 'messageType' => 2,
  1050. 'user_id' => $articleData['admin_user_id'],
  1051. ]);
  1052. }
  1053. if ($data['status'] == 2) {
  1054. $this->sendMessage([
  1055. 'talk_type' => 101,
  1056. 'title' => $articleData['title'],
  1057. 'content' => '审核拒绝',
  1058. 'messageType' => 2,
  1059. 'user_id' => $articleData['admin_user_id'],
  1060. ]);
  1061. }
  1062. if ($data['status'] == 0) {
  1063. $this->sendMessage([
  1064. 'talk_type' => 100,
  1065. 'title' => $articleData['title'],
  1066. 'content' => '提交了审核',
  1067. 'messageType' => 2,
  1068. ]);
  1069. }
  1070. $result = Article::where(['id' => $data['id']])->update($data);
  1071. // ------c_show_time********up_status*******
  1072. // 若是审核通过 则更新c_show_time
  1073. if ($data['status'] == 1) {
  1074. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1075. $web = Article::where('article.id', $data['id'])
  1076. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1077. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1078. ->select(
  1079. 'website_id',
  1080. 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')
  1081. )
  1082. ->get();
  1083. // 非核心站与核心站----显示时间-----间隔
  1084. $time = 20;
  1085. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1086. $waiting_interval = 5;
  1087. $webArray = $web->toArray();
  1088. if (empty($webArray)) {
  1089. throw new \Exception('网站分类不存在');
  1090. }
  1091. // 直接使用当前系统时间,不再强制添加8小时
  1092. $now = date('Y-m-d H:i:s');
  1093. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1094. if (isset($data['ignore_ids'])) {
  1095. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1096. if (in_array($item['website_id'], $ignore_website_ids)) {
  1097. $is_ignore = 1;
  1098. } else {
  1099. $is_ignore = 0;
  1100. }
  1101. return [
  1102. 'article_id' => $data['id'],
  1103. 'website_id' => $item['website_id'],
  1104. 'is_ignore' => $is_ignore,
  1105. ];
  1106. } else {
  1107. // 检查 $item 对象是否有 is_core 属性
  1108. if (!isset($item['is_core'])) {
  1109. throw new \Exception('$item 对象缺少 is_core 属性');
  1110. }
  1111. // 当 is_core 为 2 时,则表示此网站不存在
  1112. if ($item['is_core'] == 2) {
  1113. return null;
  1114. } else if ($item['is_core'] == 1) {
  1115. // 当 is_core 为 1 时,则表示此网站是核心站
  1116. $c_show_time = $now;
  1117. } else {
  1118. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1119. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1120. if ($item['is_core'] == 0) {
  1121. $time += $waiting_interval;
  1122. }
  1123. }
  1124. return [
  1125. 'article_id' => $data['id'],
  1126. 'website_id' => $item['website_id'],
  1127. 'c_show_time' => $c_show_time,
  1128. ];
  1129. }
  1130. }, array_keys($webArray), $webArray)));
  1131. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1132. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1133. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1134. $websiteIds = $web->pluck('website_id')->toArray();
  1135. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1136. $article_ignores = ArticleIgnore::upsert(
  1137. $article_ignore,
  1138. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1139. ['c_show_time'] // 需要更新的字段
  1140. );
  1141. if (!$article_ignores) {
  1142. throw new \Exception('c端展示时间插入失败');
  1143. }
  1144. }
  1145. if (!empty($data['ignore_ids'])) {
  1146. // return Result::success($article_ignore);
  1147. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1148. if (!empty($article_ignore)) {
  1149. $article_ignores = ArticleIgnore::upsert(
  1150. $article_ignore,
  1151. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1152. ['is_ignore'] // 需要更新的字段
  1153. );
  1154. // if(!$article_ignores){
  1155. // throw new \Exception('屏蔽网站更新失败');
  1156. // }
  1157. }
  1158. }
  1159. }
  1160. // ------c_show_time********up_status*******
  1161. if ($result) {
  1162. return Result::success();
  1163. } else {
  1164. return Result::error("更新状态失败", 0);
  1165. }
  1166. }
  1167. /**
  1168. * 获取新闻详情
  1169. * @param array $data
  1170. * @return array
  1171. */
  1172. public function getArticleInfo(array $data): array
  1173. {
  1174. $where = [
  1175. 'article.id' => $data['id'],
  1176. // 'article.status' => 1,
  1177. ];
  1178. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1179. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1180. $info = $result;
  1181. // var_dump($info, 'info');
  1182. $info['survey_array'] = $articleSurvey;
  1183. if ($result) {
  1184. return Result::success($info);
  1185. } else {
  1186. return Result::error("查询失败", 0);
  1187. }
  1188. }
  1189. /**
  1190. * 获取头条新闻
  1191. * @param array $data
  1192. * @return array
  1193. */
  1194. public function getWebsiteArticlett(array $data): array
  1195. {
  1196. $website_id = $data['website_id'];
  1197. $website = Website::where('id', $data['website_id'])->first();
  1198. if (empty($website)) {
  1199. return Result::error("网站不存在", 0);
  1200. }
  1201. $categorys = $this->processArticlePro($website_id);
  1202. $catiall = $categorys['catiall'];
  1203. $categoryIds = $categorys['categoryIds'];
  1204. $where = [
  1205. 'status' => 1
  1206. ];
  1207. // $website_column = $website['column'];
  1208. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1209. $website_column = json_decode($website['website_column_arr_id'], true);
  1210. }
  1211. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1212. // return Result::success($diff_pid_categoryIds);
  1213. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1214. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1215. }
  1216. // $website_id = $data['website_id'];
  1217. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1218. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1219. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1220. switch ($data['level']) {
  1221. case 1:
  1222. case 2:
  1223. case 3:
  1224. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1225. $query = Article::where($where)
  1226. ->where('level', 'like', '%' . $data['level'] . '%')
  1227. ->orderBy('updated_at', 'desc');
  1228. break;
  1229. case 4: //最新资讯
  1230. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1231. break;
  1232. case 5: //资讯推荐
  1233. $query = Article::where($where)
  1234. ->where('updated_at', '>', $month);
  1235. break;
  1236. case 7: //资讯分类
  1237. if (isset($data['id']) && !empty($data['id'])) {
  1238. $keyword = Article::where('id', $data['id'])->value('keyword');
  1239. $keywordArray = explode(',', $keyword);
  1240. $whereL7 = [];
  1241. foreach ($keywordArray as $k => $v) {
  1242. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1243. }
  1244. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1245. break;
  1246. } else {
  1247. return Result::error("请输入资讯ID", 0);
  1248. break;
  1249. }
  1250. default:
  1251. break;
  1252. }
  1253. // $whereL7 = [];
  1254. // if(isset($data['id']) && !empty($data['id'])){
  1255. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1256. // $keywordArray = explode(',', $keyword);
  1257. // foreach ($keywordArray as $k => $v) {
  1258. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1259. // }
  1260. // }
  1261. // $query = Article::where($where)
  1262. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1263. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1264. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1265. // }
  1266. // if($data['level'] == 7){
  1267. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1268. // }
  1269. // if($data['level'] == 4){
  1270. // $query = $query->inRandomOrder()
  1271. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1272. // }
  1273. // if($data['level'] == 5){
  1274. // $query = $query->orderBy('updated_at','desc');
  1275. // }
  1276. // });
  1277. if ($data['textnum'] > 0) {
  1278. $query = clone $query;
  1279. $result['text'] = $query
  1280. ->whereIn('catid', $categoryIds)
  1281. ->leftJoinSub(function ($query) use ($website_id) {
  1282. $query->from('article_ignore')
  1283. ->where('website_id', $website_id);
  1284. }, 'article_ignore', function ($join) {
  1285. $join->on('article_ignore.article_id', '=', 'article.id');
  1286. })
  1287. ->where(function ($query) {
  1288. $query->whereNull('article_ignore.article_id')
  1289. ->orWhere(function ($subQuery) {
  1290. $subQuery->whereNotNull('article_ignore.article_id')
  1291. ->where('article_ignore.is_ignore', 0)
  1292. ->where(function ($subSubQuery) {
  1293. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1294. ->orWhereNull('article_ignore.c_show_time');
  1295. });
  1296. });
  1297. })
  1298. // ->where(function ($query) use ($website_id) {
  1299. // $query->whereNull('article_ignore.article_id')
  1300. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1301. // })
  1302. ->select(
  1303. 'article.id',
  1304. 'article.title',
  1305. 'article.author',
  1306. 'article.updated_at',
  1307. 'article.introduce',
  1308. 'article.islink',
  1309. 'article.linkurl',
  1310. 'article.copyfrom',
  1311. 'article.cat_arr_id',
  1312. 'article.catid',
  1313. 'article.level',
  1314. // 'article_ignore.is_ignore',
  1315. // 'article_ignore.c_show_time',
  1316. )
  1317. ->offset($data['placeid'])
  1318. ->limit($data['textnum'])
  1319. ->get()->all();
  1320. foreach ($result['text'] as $k => $v) {
  1321. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1322. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1323. }
  1324. }
  1325. if ($data['imgnum'] > 0) {
  1326. $query = clone $query;
  1327. if ($data['textnum'] == 0) {
  1328. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1329. $query->from('article_ignore')
  1330. ->where('website_id', $website_id);
  1331. }, 'article_ignore', function ($join) {
  1332. $join->on('article_ignore.article_id', '=', 'article.id');
  1333. })
  1334. ->where(function ($query) {
  1335. $query->whereNull('article_ignore.article_id')
  1336. ->orWhere(function ($subQuery) {
  1337. $subQuery->whereNotNull('article_ignore.article_id')
  1338. ->where('article_ignore.is_ignore', 0)
  1339. ->where(function ($subSubQuery) {
  1340. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1341. ->orWhereNull('article_ignore.c_show_time');
  1342. });
  1343. });
  1344. });
  1345. }
  1346. $result['img'] = $query
  1347. ->whereIn('catid', $categoryIds)
  1348. ->where('article.imgurl', '!=', '')
  1349. ->select(
  1350. 'article.id',
  1351. 'article.title',
  1352. 'article.imgurl',
  1353. 'article.author',
  1354. 'article.updated_at',
  1355. 'article.introduce',
  1356. 'article.islink',
  1357. 'article.linkurl',
  1358. 'article.copyfrom',
  1359. 'article.cat_arr_id',
  1360. 'article.catid',
  1361. 'article.level',
  1362. // 'article_ignore.is_ignore',
  1363. // 'article_ignore.c_show_time',
  1364. )
  1365. ->offset($data['placeid'])
  1366. ->limit($data['imgnum'])
  1367. ->get()->all();
  1368. foreach ($result['img'] as $k => $v) {
  1369. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1370. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1371. }
  1372. }
  1373. if (empty($result)) {
  1374. return Result::error("暂无相关资讯", 0);
  1375. }
  1376. return Result::success($result);
  1377. }
  1378. /**
  1379. * 获取模块新闻
  1380. * @param array $data
  1381. * @return array
  1382. */
  1383. public function getWebsiteModelArticles(array $data): array
  1384. {
  1385. $catid = $data['catid'];
  1386. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1387. $category = $category->toArray();
  1388. if (!empty($category)) {
  1389. $where = [
  1390. 'status' => 1,
  1391. 'catid' => $catid,
  1392. ];
  1393. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1394. // 1:文字新闻;2:轮播图;3:图文;
  1395. // 级别:0:未分类
  1396. // 3:推荐图片
  1397. if ($data['level'] == 1) {
  1398. $data['level'] = 0;
  1399. }
  1400. $result = Article::where($where)
  1401. ->where(function ($query) use ($data) {
  1402. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1403. ->orWhereNull("level")
  1404. ->orWhereRaw("level = '[]'");
  1405. })
  1406. ->leftJoinSub(function ($query) use ($data) {
  1407. $query->from('article_ignore')
  1408. ->where('website_id', $data['website_id']);
  1409. }, 'article_ignore', function ($join) {
  1410. $join->on('article_ignore.article_id', '=', 'article.id');
  1411. })
  1412. ->where(function ($query) {
  1413. $query->whereNull('article_ignore.article_id')
  1414. ->orWhere(function ($subQuery) {
  1415. $subQuery->whereNotNull('article_ignore.article_id')
  1416. ->where('article_ignore.is_ignore', 0)
  1417. ->where(function ($subSubQuery) {
  1418. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1419. ->orWhereNull('article_ignore.c_show_time');
  1420. });
  1421. });
  1422. })
  1423. // ->where(function ($query) use ($data) {
  1424. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1425. // ->orWhereNull("ignore_ids");
  1426. // })
  1427. ->orderBy("updated_at", "desc")
  1428. ->offset($placeid)
  1429. ->limit($data['pagesize'])
  1430. ->get();
  1431. if (empty($result)) {
  1432. return Result::error("此栏目暂无相关新闻", 0);
  1433. }
  1434. } else {
  1435. return Result::error("此网站暂无此栏目", 0);
  1436. }
  1437. return Result::success($result);
  1438. }
  1439. /**
  1440. *获取新闻列表
  1441. * @param array $data
  1442. * @return array
  1443. */
  1444. public function getWebsiteArticleList(array $data): array
  1445. {
  1446. // return Result::success($data);
  1447. $where[] = ['status', '=', 1];
  1448. $website_id = $data['website_id'];
  1449. $website = Website::where('id', $data['website_id'])->first();
  1450. if (empty($website)) {
  1451. return Result::error("网站不存在", 0);
  1452. }
  1453. // $website_column = $website['column'];
  1454. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1455. $website_column = json_decode($website['website_column_arr_id'], true);
  1456. }
  1457. $categorys = $this->processArticlePro($website_id);
  1458. $cat_1st_arr = $categorys['cat_1st_arr'];
  1459. $catiall = $categorys['catiall'];
  1460. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1461. // return Result::success($diff_pid_categoryIds);
  1462. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1463. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1464. }
  1465. if (isset($data['catid']) && !empty($data['catid'])) {
  1466. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1467. if (empty($category)) {
  1468. return Result::error("此网站暂无此栏目", 0);
  1469. }
  1470. array_push($where, ['catid', '=', $data['catid']]);
  1471. }
  1472. // return Result::success($where);
  1473. $query = Article::where($where)
  1474. ->leftJoinSub(function ($query) use ($website_id) {
  1475. $query->from('article_ignore')
  1476. ->where('website_id', $website_id);
  1477. }, 'article_ignore', function ($join) {
  1478. $join->on('article_ignore.article_id', '=', 'article.id');
  1479. })
  1480. ->where(function ($query) {
  1481. $query->whereNull('article_ignore.article_id')
  1482. ->orWhere(function ($subQuery) {
  1483. $subQuery->whereNotNull('article_ignore.article_id')
  1484. ->where('article_ignore.is_ignore', 0)
  1485. ->where(function ($subSubQuery) {
  1486. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1487. ->orWhereNull('article_ignore.c_show_time');
  1488. });
  1489. });
  1490. })
  1491. ->select(
  1492. 'article.id',
  1493. 'article.title',
  1494. 'article.imgurl',
  1495. 'article.author',
  1496. 'article.updated_at',
  1497. 'article.introduce',
  1498. 'article.islink',
  1499. 'article.linkurl',
  1500. 'article.copyfrom',
  1501. 'article.cat_arr_id',
  1502. 'article.catid'
  1503. );
  1504. $count = $query->count();
  1505. $rep = $query->orderBy("updated_at", "desc")
  1506. ->offset(($data['page'] - 1) * $data['pageSize'])
  1507. ->limit($data['pageSize'])
  1508. ->get()->all();
  1509. $categorys = $this->processArticlePro($website_id);
  1510. $cat_1st_arr = $categorys['cat_1st_arr'];
  1511. $catiall = $categorys['catiall'];
  1512. // $web['website_id'] = $data['website_id'];
  1513. foreach ($rep as $k => $v) {
  1514. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1515. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1516. }
  1517. // $rep = $this->processArticles($rep,$web);
  1518. $data = [
  1519. 'rows' => $rep,
  1520. 'count' => $count,
  1521. ];
  1522. if (empty($rep)) {
  1523. return Result::error("没有信息数据");
  1524. }
  1525. return Result::success($data);
  1526. }
  1527. /**
  1528. * 前端-获取新闻详情
  1529. * @param array $data
  1530. * @return array
  1531. */
  1532. public function selectWebsiteArticleInfo(array $data): array
  1533. {
  1534. $where = [
  1535. 'article.id' => $data['id'],
  1536. 'article.status' => 1,
  1537. ];
  1538. $result = Article::where($where)
  1539. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1540. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1541. // ->where(function ($query) use ($data) {
  1542. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1543. // ->orWhereNull("ignore_ids");
  1544. // })
  1545. ->leftJoinSub(function ($query) use ($data) {
  1546. $query->from('article_ignore')
  1547. ->where('website_id', $data['website_id']);
  1548. }, 'article_ignore', function ($join) {
  1549. $join->on('article_ignore.article_id', '=', 'article.id');
  1550. })
  1551. ->where(function ($query) {
  1552. $query->whereNull('article_ignore.article_id')
  1553. ->orWhere(function ($subQuery) {
  1554. $subQuery->whereNotNull('article_ignore.article_id')
  1555. ->where('article_ignore.is_ignore', 0)
  1556. ->where(function ($subSubQuery) {
  1557. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1558. ->orWhereNull('article_ignore.c_show_time');
  1559. });
  1560. });
  1561. })
  1562. ->select(
  1563. 'article.*',
  1564. 'article_data.content',
  1565. 'article_data.article_id',
  1566. 'article_extend.website_url',
  1567. 'article_extend.email',
  1568. 'article_extend.contacts',
  1569. 'article_extend.contacts_mobile',
  1570. 'article_extend.contacts_address',
  1571. 'article_extend.zip_code',
  1572. 'article_extend.enterprise_name'
  1573. )
  1574. ->first();
  1575. if (empty($result)) {
  1576. return Result::error("暂无此新闻!", 0);
  1577. }
  1578. if (!empty($result['publiced_at'])) {
  1579. $result['updated_at'] = $result['publiced_at'];
  1580. }
  1581. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1582. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1583. ->where('website_category.website_id', $data['website_id'])
  1584. ->where(['website_category.category_id' => $result['catid']])
  1585. ->first();
  1586. if (empty($category)) {
  1587. return Result::error("查询失败", 0);
  1588. }
  1589. //手动推荐文章
  1590. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1591. if (empty($commend_ids)) {
  1592. $commendArticle = [];
  1593. } else {
  1594. //去除不存在的文章ID
  1595. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1596. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1597. ->leftJoinSub(function ($query) use ($data) {
  1598. $query->from('article_ignore')
  1599. ->where('website_id', $data['website_id']);
  1600. }, 'article_ignore', function ($join) {
  1601. $join->on('article_ignore.article_id', '=', 'article.id');
  1602. })
  1603. ->where(function ($query) {
  1604. $query->whereNull('article_ignore.article_id')
  1605. ->orWhere(function ($subQuery) {
  1606. $subQuery->whereNotNull('article_ignore.article_id')
  1607. ->where('article_ignore.is_ignore', 0)
  1608. ->where(function ($subSubQuery) {
  1609. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1610. ->orWhereNull('article_ignore.c_show_time');
  1611. });
  1612. });
  1613. })
  1614. ->where('article.status', 1)
  1615. ->where('website_category.website_id', $data['website_id'])
  1616. ->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')
  1617. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1618. // ->orderBy('article.updated_at', 'desc')
  1619. ->limit(5)
  1620. ->get();
  1621. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1622. foreach ($commendArticle as $k => $v) {
  1623. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1624. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1625. $cat_arr_id = array_unique($cat_arr_id);
  1626. // 从website_category取出alias_pinyin
  1627. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1628. ->whereIn('category_id', $cat_arr_id)
  1629. ->pluck('alias_pinyin', 'category_id')
  1630. ->toArray();
  1631. // 将cat_arr_id的json转成路径/隔开
  1632. $path_parts = [];
  1633. foreach ($cat_arr_id as $cat_id) {
  1634. if (isset($cat_arr[$cat_id])) {
  1635. $path_parts[] = $cat_arr[$cat_id];
  1636. }
  1637. }
  1638. $v->alias_pinyin = implode('/', $path_parts);
  1639. } else {
  1640. $v->alias_pinyin = '';
  1641. }
  1642. }
  1643. }
  1644. $result['category_id'] = $category['category_id'];
  1645. $result['cat_name'] = $category['alias'];
  1646. $result['website_name'] = $category['website_name'] ?? "";
  1647. $result['suffix'] = $category['suffix'] ?? "";
  1648. $result['commendArticle'] = $commendArticle;
  1649. $result['commend_ids'] = $commend_ids;
  1650. return Result::success($result);
  1651. }
  1652. /**
  1653. * 前端-获取网站调查问卷
  1654. * @param array $data
  1655. * @return array
  1656. */
  1657. public function getWebsiteSurvey(array $data): array
  1658. {
  1659. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1660. $website = Website::where('id', $data['website_id'])->first();
  1661. if (empty($website)) {
  1662. return Result::error("暂无此网站", 0);
  1663. }
  1664. }
  1665. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1666. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1667. if (empty($article)) {
  1668. return Result::error("暂无此文章", 0);
  1669. }
  1670. // return Result::error($data,0);
  1671. $where['art_id'] = $data['art_id'];
  1672. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1673. } else {
  1674. $survey = Article::where(function ($query) {
  1675. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1676. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1677. })
  1678. ->where('status', 1)
  1679. ->where('is_survey', 1)
  1680. ->select('survey_id')
  1681. ->orderBy('updated_at', 'desc')
  1682. ->first();
  1683. if (empty($survey)) {
  1684. return Result::error("暂无调查问卷", 0);
  1685. }
  1686. $where['sur_id'] = $survey['survey_id'];
  1687. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1688. }
  1689. // return Result::success($where);
  1690. $result = ArticleSurvey::where($where)
  1691. ->where(function ($query) {
  1692. $query->where('is_other', 0)
  1693. ->orWhere(function ($subQuery) {
  1694. $subQuery->where('is_other', 1)
  1695. ->where('other_id', 0);
  1696. });
  1697. })
  1698. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1699. ->select('article_survey.*', 'article.survey_type')
  1700. ->get()->all();
  1701. if (empty($result)) {
  1702. return Result::error("此文章暂无调查问卷", 0);
  1703. }
  1704. return Result::success($result);
  1705. }
  1706. /**
  1707. * 前端-添加网站调查问卷选项
  1708. * @param array $data
  1709. * @return array
  1710. */
  1711. public function addWebsiteSurveyOption(array $data): array
  1712. {
  1713. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1714. $website = Website::where('id', $data['website_id'])->first();
  1715. if (empty($website)) {
  1716. return Result::error("暂无此网站", 0);
  1717. }
  1718. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1719. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1720. if (empty($survey)) {
  1721. return Result::error("此调查问卷不可添加选项", 0);
  1722. }
  1723. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1724. $choice = [
  1725. 'art_id' => $survey['art_id'],
  1726. 'website_id' => $data['website_id'],
  1727. 'survey_name' => $survey['survey_name'],
  1728. 'choice_name' => $data['choice_name'],
  1729. 'sur_id' => $survey['sur_id'],
  1730. 'is_other' => 1,
  1731. 'other_id' => $survey['id'],
  1732. ];
  1733. $result = ArticleSurvey::insertGetId($choice);
  1734. if (empty($result)) {
  1735. return Result::error("添加失败", 0);
  1736. }
  1737. return Result::success($result);
  1738. }
  1739. }
  1740. return Result::error("添加失败", 0);
  1741. }
  1742. return Result::error("添加失败", 0);
  1743. }
  1744. /**
  1745. * 前端-调查问卷投票
  1746. * @param array $data
  1747. * @return array
  1748. */
  1749. public function addWebsiteSurveyVote(array $data): array
  1750. {
  1751. // return Result::success($data);
  1752. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1753. $website = Website::where('id', $data['website_id'])->first();
  1754. if (empty($website)) {
  1755. return Result::error("暂无此网站", 0);
  1756. }
  1757. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1758. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1759. // return Result::success($survey);
  1760. if (empty($is_survey)) {
  1761. return Result::error("此调查问卷不存在", 0);
  1762. }
  1763. // return Result::success($survey);
  1764. // 调查问卷类型
  1765. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1766. //多选 若是json型则转化成数组类型
  1767. if (strpos($data['choice_id'], '[') === 0) {
  1768. $data['choice_id'] = json_decode($data['choice_id'], true);
  1769. } else {
  1770. // 单选 也转换成数组
  1771. $data['choice_id'] = [$data['choice_id']];
  1772. }
  1773. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1774. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1775. // ->where('website_id',$data['website_id'])
  1776. ->where('is_other', 1)
  1777. ->where('other_id', 0)
  1778. ->first();
  1779. if (!empty($other)) {
  1780. return Result::error("请选择已有的选项!", 0);
  1781. }
  1782. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1783. // ->where('website_id',$data['website_id'])
  1784. ->where('is_other', 1)
  1785. ->where('other_id', '!=', 0)
  1786. ->first();
  1787. // return Result::success($choice['other']);
  1788. $choice_id = $data['choice_id'];
  1789. if (!empty($choice['other'])) {
  1790. // array_push($data['choice_id'],$choice['other']['other_id']);
  1791. if (!empty($choice_id)) {
  1792. $key = array_search($choice['other']['id'], $choice_id);
  1793. if ($key !== false) {
  1794. unset($choice_id[$key]);
  1795. $choice_id = array_values($choice_id);
  1796. }
  1797. array_push($choice_id, $choice['other']['other_id']);
  1798. } else {
  1799. $choice_id[0] = $choice['other']['other_id'];
  1800. }
  1801. array_push($data['choice_id'], $choice['other']['other_id']);
  1802. }
  1803. // return Result::success($data);
  1804. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1805. // ->where('website_id',$data['website_id'])
  1806. ->increment('results', 1);
  1807. if (empty($choice)) {
  1808. return Result::error("请选择已有的选项!", 0);
  1809. }
  1810. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1811. // ->where('website_id',$data['website_id'])
  1812. ->where('other_id', 0)
  1813. ->get();
  1814. $survey['choice'] = $choice_id;
  1815. return Result::success($survey);
  1816. }
  1817. return Result::error("参数必填!");
  1818. }
  1819. return Result::error("此调查问卷不存在", 0);
  1820. }
  1821. return Result::error("参数必填!");
  1822. }
  1823. /**
  1824. * 后端-获取网站调查问卷列表
  1825. * @param array $data
  1826. * @return array
  1827. */
  1828. public function getSurveyList(array $data): array
  1829. {
  1830. $where = [];
  1831. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1832. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1833. }
  1834. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1835. if (!empty($where)) {
  1836. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1837. $query = ArticleSurvey::select(
  1838. 'art_id as id',
  1839. Db::raw('MAX(id) as surid'),
  1840. Db::raw('MAX(survey_name) as survey_name'),
  1841. Db::raw('MAX(sur_id) as survey_id')
  1842. )
  1843. ->groupBy('art_id')
  1844. ->where($where)
  1845. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1846. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1847. $sub->select('id')
  1848. ->from('article')
  1849. ->where('survey_type', $survey_type);
  1850. });
  1851. })
  1852. ->with(['article' => function ($query) {
  1853. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1854. }]);
  1855. ;
  1856. }else{
  1857. $query = ArticleSurvey::select(
  1858. 'art_id as id',
  1859. Db::raw('MAX(id) as surid'),
  1860. Db::raw('MAX(survey_name) as survey_name'),
  1861. Db::raw('MAX(sur_id) as survey_id'),
  1862. )
  1863. ->groupBy('art_id')
  1864. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1865. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1866. $sub->select('id')
  1867. ->from('article')
  1868. ->where('survey_type', $survey_type);
  1869. });
  1870. })
  1871. ->with(['article' => function ($query) {
  1872. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1873. }]);
  1874. }
  1875. $count = $query->get()->count();
  1876. // 简单写法:直接统计分组后的 art_id 数量
  1877. $survey = $query->orderBy('id', 'desc')
  1878. ->limit($data['pageSize'])
  1879. ->offset(($data['page'] - 1) * $data['pageSize'])
  1880. ->get();
  1881. if (empty($survey->toArray())) {
  1882. return Result::error("暂无调查问卷!", 0);
  1883. }
  1884. $survey = array_map(function ($item) {
  1885. $item['survey_type'] = $item['article']['survey_type'];
  1886. $item['created_at'] = $item['article']['created_at'];
  1887. $item['updated_at'] = $item['article']['updated_at'];
  1888. unset($item['article']);
  1889. return $item;
  1890. }, $survey->toArray());
  1891. $result = [
  1892. 'rows' => $survey,
  1893. 'count' => $count,
  1894. ];
  1895. return Result::success($result);
  1896. }
  1897. /**
  1898. * 后端-获取网站调查问卷详情
  1899. * @param array $data
  1900. * @return array
  1901. */
  1902. public function getSurveyInfo(array $data): array
  1903. {
  1904. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1905. $where = ['sur_id' => $data['sur_id']];
  1906. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1907. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1908. ->select('article_survey.*', 'article.survey_type')
  1909. ->get()->all();
  1910. if (empty($choose)) {
  1911. return Result::error("此调查问卷不存在", 0);
  1912. }
  1913. $resultsArray = array_column($choose, 'results');
  1914. $total = array_sum($resultsArray);
  1915. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1916. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1917. // $total = 0;
  1918. if (!empty($other)) {
  1919. $total = $total + $other['results'];
  1920. $other['choice_name'] = '(其他)';
  1921. if (!empty($others)) {
  1922. $other['hasChildren'] = true;
  1923. // array_push($other,['hasChildren','=',true]);
  1924. $other['children'] = $others;
  1925. $other_choices = [$other->toArray()];
  1926. $mer_choice = array_merge($choose, $other_choices);
  1927. $value_choice = array_values($mer_choice);
  1928. } else {
  1929. // return Result::error('1111');
  1930. $other_choices = [$other->toArray()];
  1931. $other_choices = array_merge($choose, $other_choices);
  1932. $value_choice = array_values($other_choices);
  1933. // return Result::success($result);
  1934. }
  1935. } else {
  1936. $value_choice = $choose;
  1937. }
  1938. $result = [
  1939. 'choose' => $value_choice,
  1940. 'total' => $total,
  1941. ];
  1942. }
  1943. return Result::success($result);
  1944. }
  1945. /**
  1946. * 前端-搜索新闻列表
  1947. * @param array $data
  1948. * @return array
  1949. */
  1950. public function selectWebsiteArticle(array $data): array
  1951. {
  1952. $website = Website::where('id', $data['website_id'])->first();
  1953. if (empty($website)) {
  1954. return Result::error("网站不存在", 0);
  1955. }
  1956. // $website_column = $website['column'];
  1957. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1958. $website_column = json_decode($website['website_column_arr_id'], true);
  1959. }
  1960. $website_id = $data['website_id'];
  1961. $categorys = $this->processArticlePro($website_id);
  1962. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1963. // return Result::success($diff_pid_categoryIds);
  1964. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1965. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1966. }
  1967. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1968. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1969. $catiall = $categorys['catiall'];
  1970. $categoryIds = $categorys['categoryIds'];
  1971. // return Result::success($categoryIds);
  1972. $query = Article::where('status', 1)
  1973. ->whereIn('catid', $categoryIds)
  1974. ->leftJoinSub(function ($query) use ($website_id) {
  1975. $query->from('article_ignore')
  1976. ->where('website_id', $website_id);
  1977. }, 'article_ignore', function ($join) {
  1978. $join->on('article_ignore.article_id', '=', 'article.id');
  1979. })
  1980. ->where(function ($query) {
  1981. $query->whereNull('article_ignore.article_id')
  1982. ->orWhere(function ($subQuery) {
  1983. $subQuery->whereNotNull('article_ignore.article_id')
  1984. ->where('article_ignore.is_ignore', 0)
  1985. ->where(function ($subSubQuery) {
  1986. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1987. ->orWhereNull('article_ignore.c_show_time');
  1988. });
  1989. });
  1990. });
  1991. // ->get()->all();
  1992. // return Result::success($query);
  1993. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1994. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1995. }
  1996. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1997. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1998. }
  1999. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2000. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  2001. }
  2002. // 计算总数
  2003. $count = $query->count();
  2004. // return Result::success($count);
  2005. // 分页查询
  2006. $articles = $query
  2007. ->select(
  2008. 'article.id',
  2009. 'article.title',
  2010. 'article.imgurl',
  2011. 'article.author',
  2012. 'article.updated_at',
  2013. 'article.introduce',
  2014. 'article.islink',
  2015. 'article.linkurl',
  2016. 'article.copyfrom',
  2017. 'article.cat_arr_id',
  2018. 'article.catid',
  2019. 'article.department_arr_id',
  2020. 'article.city_arr_id',
  2021. // 'article_ignore.c_show_time',
  2022. // 'article_ignore.is_ignore'
  2023. )
  2024. ->orderBy("updated_at", "desc")
  2025. ->offset(($data['page'] - 1) * $data['pageSize'])
  2026. ->limit($data['pageSize'])
  2027. ->get();
  2028. // return Result::success($articles);
  2029. foreach ($articles as $k => $v) {
  2030. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2031. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2032. }
  2033. if (empty($articles)) {
  2034. return Result::error("没有符合条件的资讯数据");
  2035. }
  2036. $result = [
  2037. 'rows' => $articles,
  2038. 'count' => $count,
  2039. ];
  2040. return Result::success($result);
  2041. }
  2042. /**
  2043. * 模块新闻加强版
  2044. * @param array $data
  2045. * @return array
  2046. */
  2047. public function getWebsiteCatidArticle(array $data): array
  2048. {
  2049. $where = [
  2050. 'website_category.category_id' => $data['catid'],
  2051. 'website_category.website_id' => $data['website_id'],
  2052. ];
  2053. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2054. $child_catnum = $data['child_catnum'] ?? 1;
  2055. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2056. $childCategoryIds = array_column($category['child'], 'category_id');
  2057. if (empty($childCategoryIds)) {
  2058. return Result::error("暂无子栏目", 0);
  2059. }
  2060. $imgArticles = [];
  2061. $textArticles = [];
  2062. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2063. // 初始化子分类图片新闻和文字新闻数组
  2064. // 查询所有子级栏目的图文新闻
  2065. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2066. ->where(function ($query) use ($data) {
  2067. $query->where(function ($subQuery) use ($data) {
  2068. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2069. })->orWhereNull("ignore_ids");
  2070. })
  2071. ->where('status', 1)
  2072. ->where('imgurl', '!=', '')
  2073. ->select('*')
  2074. ->orderBy('updated_at', 'desc')
  2075. ->limit($data['child_imgnum'])
  2076. ->get();
  2077. }
  2078. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2079. // 查询所有子级栏目的文字新闻
  2080. $textArticles = Article::where('catid', $childCategoryIds[0])
  2081. ->where('status', 1)
  2082. ->where(function ($query) use ($data) {
  2083. $query->where(function ($subQuery) use ($data) {
  2084. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2085. })->orWhereNull("ignore_ids");
  2086. })
  2087. ->select('*')
  2088. ->orderBy('updated_at', 'desc')
  2089. ->limit($data['child_textnum'])
  2090. ->get();
  2091. }
  2092. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2093. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2094. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2095. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2096. return $child;
  2097. }, $category['child']);
  2098. }
  2099. // }
  2100. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2101. $category['img'] = WebsiteCategory::where($where)
  2102. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2103. ->where('article.status', 1)
  2104. ->where('article.imgurl', '!=', '')
  2105. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2106. ->orderBy('article.updated_at', 'desc')
  2107. ->limit($data['img_num'])
  2108. ->get();
  2109. }
  2110. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2111. $category['text'] = WebsiteCategory::where($where)
  2112. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2113. ->where('article.status', 1)
  2114. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2115. ->orderBy('article.updated_at', 'desc')
  2116. ->limit($data['text_num'])
  2117. ->get();
  2118. }
  2119. // $category = $category->get();
  2120. if (empty($category)) {
  2121. return Result::error("查询失败", 0);
  2122. }
  2123. return Result::success($category);
  2124. }
  2125. /**
  2126. * 模块新闻加强plus版
  2127. * @param array $data
  2128. * @return array
  2129. */
  2130. public function getWebsiteAllArticle(array $data): array
  2131. {
  2132. // return Result::success($data);
  2133. $time1 = microtime(true);
  2134. $wetbsite_id = $data['website_id'] ?? 2;
  2135. $data = json_decode($data['id'], true);
  2136. $website = Website::where('id', $wetbsite_id)->first();
  2137. if (empty($website)) {
  2138. return Result::error("网站不存在", 0);
  2139. }
  2140. // return Result::success($website);
  2141. $website_column = $website['website_column_arr_id'] ?? '[]';
  2142. $website_column = json_decode($website_column, true);
  2143. $categorys = $this->processArticlePro($wetbsite_id);
  2144. $cat_1st_arr = $categorys['cat_1st_arr'];
  2145. $catiall = $categorys['catiall'];
  2146. // return Result::success($catiall);
  2147. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2148. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2149. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2150. }
  2151. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2152. // return Result::success($categorys);
  2153. $parent_category = array_column($data, 'parent');
  2154. $parent_cat = [];
  2155. $child_category = array_column($data, 'child');
  2156. if (!empty($parent_category)) {
  2157. foreach ($parent_category as $key => $value) {
  2158. $arr = array_map('intval', explode(',', $value));
  2159. $parent_cat[$key] = $arr[0] ?? 0;
  2160. $parent_category = $arr[0] ?? 0;
  2161. $article_imgnum = $arr[1] ?? 0;
  2162. $article_textnum = $arr[2] ?? 0;
  2163. if ($parent_category != 0) {
  2164. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2165. // return Result::success($category_arr);
  2166. if ($article_imgnum != 0) {
  2167. $img_article = Article::whereIn('catid', $category_arr)
  2168. ->where('status', 1)
  2169. ->where('imgurl', '!=', '')
  2170. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2171. $query->from('article_ignore')
  2172. ->where('website_id', $wetbsite_id);
  2173. }, 'article_ignore', function ($join) {
  2174. $join->on('article_ignore.article_id', '=', 'article.id');
  2175. })
  2176. ->where(function ($query) {
  2177. $query->whereNull('article_ignore.article_id')
  2178. ->orWhere(function ($subQuery) {
  2179. $subQuery->whereNotNull('article_ignore.article_id')
  2180. ->where('article_ignore.is_ignore', 0)
  2181. ->where(function ($subSubQuery) {
  2182. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2183. ->orWhereNull('article_ignore.c_show_time');
  2184. });
  2185. });
  2186. })
  2187. ->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')
  2188. ->orderBy('updated_at', 'desc')
  2189. ->limit($article_imgnum)
  2190. ->get()->all();
  2191. foreach ($img_article as $k => $v) {
  2192. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2193. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2194. }
  2195. } else {
  2196. $img_article = [];
  2197. }
  2198. if ($article_textnum != 0) {
  2199. $text_article = Article::whereIn('catid', $category_arr)
  2200. ->where('status', 1)
  2201. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2202. $query->from('article_ignore')
  2203. ->where('website_id', $wetbsite_id);
  2204. }, 'article_ignore', function ($join) {
  2205. $join->on('article_ignore.article_id', '=', 'article.id');
  2206. })
  2207. ->where(function ($query) {
  2208. $query->whereNull('article_ignore.article_id')
  2209. ->orWhere(function ($subQuery) {
  2210. $subQuery->whereNotNull('article_ignore.article_id')
  2211. ->where('article_ignore.is_ignore', 0)
  2212. ->where(function ($subSubQuery) {
  2213. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2214. ->orWhereNull('article_ignore.c_show_time');
  2215. });
  2216. });
  2217. })
  2218. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2219. ->orderBy('updated_at', 'desc')
  2220. ->limit($article_textnum)
  2221. ->get()->all();
  2222. foreach ($text_article as $k => $v) {
  2223. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2224. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2225. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2226. }
  2227. } else {
  2228. $text_article = [];
  2229. }
  2230. $catiall[$parent_category]['imgnum'] = $img_article;
  2231. $catiall[$parent_category]['textnum'] = $text_article;
  2232. $parent[$key] = $catiall[$parent_category];
  2233. } else {
  2234. $parent[$key] = '';
  2235. }
  2236. }
  2237. }
  2238. if (!empty($child_category)) {
  2239. foreach ($child_category as $key => $value) {
  2240. $arr = array_map('intval', explode(',', $value));
  2241. $parent_category = $parent_cat[$key];
  2242. $child_category = $arr[0] ?? 0;
  2243. $article_imgnum = $arr[1] ?? 0;
  2244. $article_textnum = $arr[2] ?? 0;
  2245. if ($child_category != 0) {
  2246. $all_childcat = $cat_1st_arr[$parent_category];
  2247. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2248. // 从 $websiteInfoIndexed 中获取对应的数据
  2249. $info = $websiteInfoIndexed[$v];
  2250. // 返回一个包含所需信息的数组
  2251. return [
  2252. 'alias' => $info->alias,
  2253. 'category_id' => $info->category_id,
  2254. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2255. 'pid' => $info->pid,
  2256. 'type' => $info->type,
  2257. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2258. 'pinyin' => $info->pinyin,
  2259. ];
  2260. }, $all_childcat);
  2261. if ($article_imgnum != 0) {
  2262. $img_article = Article::where('catid', $child_category)
  2263. ->where('status', 1)
  2264. ->where('imgurl', '!=', '')
  2265. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2266. $query->from('article_ignore')
  2267. ->where('website_id', $wetbsite_id);
  2268. }, 'article_ignore', function ($join) {
  2269. $join->on('article_ignore.article_id', '=', 'article.id');
  2270. })
  2271. ->where(function ($query) {
  2272. $query->whereNull('article_ignore.article_id')
  2273. ->orWhere(function ($subQuery) {
  2274. $subQuery->whereNotNull('article_ignore.article_id')
  2275. ->where('article_ignore.is_ignore', 0)
  2276. ->where(function ($subSubQuery) {
  2277. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2278. ->orWhereNull('article_ignore.c_show_time');
  2279. });
  2280. });
  2281. })
  2282. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2283. ->orderBy('updated_at', 'desc')
  2284. ->limit($article_imgnum)
  2285. ->get()->all();
  2286. foreach ($img_article as $k => $v) {
  2287. // var_dump($v);
  2288. // var_dump($k);
  2289. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2290. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2291. }
  2292. } else {
  2293. $img_article = [];
  2294. }
  2295. if ($article_textnum != 0) {
  2296. $text_article = Article::where('catid', $child_category)
  2297. ->where('status', 1)
  2298. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2299. $query->from('article_ignore')
  2300. ->where('website_id', $wetbsite_id);
  2301. }, 'article_ignore', function ($join) {
  2302. $join->on('article_ignore.article_id', '=', 'article.id');
  2303. })
  2304. ->where(function ($query) {
  2305. $query->whereNull('article_ignore.article_id')
  2306. ->orWhere(function ($subQuery) {
  2307. $subQuery->whereNotNull('article_ignore.article_id')
  2308. ->where('article_ignore.is_ignore', 0)
  2309. ->where(function ($subSubQuery) {
  2310. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2311. ->orWhereNull('article_ignore.c_show_time');
  2312. });
  2313. });
  2314. })
  2315. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2316. ->orderBy('updated_at', 'desc')
  2317. ->limit($article_textnum)
  2318. ->get()->all();
  2319. foreach ($text_article as $k => $v) {
  2320. // var_dump($v);
  2321. // var_dump($k);
  2322. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2323. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2324. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2325. }
  2326. } else {
  2327. $text_article = [];
  2328. }
  2329. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2330. $catiall[$child_category]['imgnum'] = $img_article;
  2331. $catiall[$child_category]['textnum'] = $text_article;
  2332. $child[$key] = $catiall[$child_category];
  2333. // var_dump($pids);
  2334. } else {
  2335. $child[$key] = '';
  2336. }
  2337. }
  2338. }
  2339. foreach ($parent as $key => $value) {
  2340. $result[$key] = $value;
  2341. if (!empty($child[$key])) {
  2342. // var_dump($child[$key]);
  2343. $result[$key]['child'] = $child[$key];
  2344. // $value[$key]['child'] = $child[$key];
  2345. } else {
  2346. $result[$key]['child'] = [
  2347. "alias" => null,
  2348. "category_id" => null,
  2349. "type" => null,
  2350. "pinyin" => null,
  2351. "all_childcat" => [],
  2352. "imgnum" => [],
  2353. "textnum" => []
  2354. ];
  2355. }
  2356. }
  2357. return Result::success($result);
  2358. }
  2359. /**
  2360. * 辅助方法:获取文章列表
  2361. */
  2362. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2363. {
  2364. sleep(1);
  2365. $query = Article::where('article.status', 1)
  2366. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2367. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2368. ->where(function ($query) use ($website) {
  2369. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2370. })
  2371. ->leftJoin('website_category', function ($join) use ($website) {
  2372. $join->on('article.catid', '=', 'website_category.category_id')
  2373. ->where('website_category.website_id', '=', $website['website_id']);
  2374. })
  2375. ->select(
  2376. 'article.id',
  2377. 'article.title',
  2378. 'article.imgurl',
  2379. 'article.author',
  2380. 'article.updated_at',
  2381. 'article.introduce',
  2382. 'article.islink',
  2383. 'article.linkurl',
  2384. 'article.copyfrom',
  2385. 'article.cat_arr_id',
  2386. 'article.catid',
  2387. 'website_category.alias as category_name'
  2388. )
  2389. ->orderBy('updated_at', 'desc')
  2390. ->limit($limit);
  2391. // 如果是图片文章,添加图片URL条件
  2392. if ($isImageArticle) {
  2393. $query->where('imgurl', '!=', '');
  2394. } else {
  2395. // 文字文章不需要imgurl字段
  2396. $query->addSelect('article.introduce');
  2397. }
  2398. $articles = $query->get();
  2399. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2400. }
  2401. /**
  2402. * 乡村网-获取特殊新闻模块
  2403. * @param array $data
  2404. * @return array
  2405. */
  2406. public function getWebsiteArticles(array $data): array
  2407. {
  2408. $website_id = $data['website_id'];
  2409. $website = Website::where('id', $website_id)->first();
  2410. if (empty($website)) {
  2411. return Result::error("网站不存在", 0);
  2412. }
  2413. // return Result::success($website);
  2414. $website_column = $website['website_column_arr_id'] ?? '[]';
  2415. $website_column = json_decode($website_column, true);
  2416. $catids = json_decode($data['id'], true);
  2417. $parent_category = array_column($catids, 'parent');
  2418. if (!empty($parent_category) && is_array($parent_category)) {
  2419. $categorys = $this->processArticlePro($website_id);
  2420. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2421. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2422. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2423. }
  2424. $catiall = $categorys['catiall'];
  2425. $cat_1st_arr = $categorys['cat_1st_arr'];
  2426. // return Result::success($categorys);
  2427. foreach ($parent_category as $key => $value) {
  2428. $arr = array_map('intval', explode(',', $value));
  2429. $parent_category = $arr[0] ?? 0;
  2430. $article_imgnum = $arr[1] ?? 0;
  2431. $article_textnum = $arr[2] ?? 0;
  2432. if ($parent_category != 0) {
  2433. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2434. // return Result::success($category_arr);
  2435. if ($article_imgnum != 0) {
  2436. $img_article = Article::whereIn('article.catid', $category_arr)
  2437. ->where('article.status', 1)
  2438. ->where('article.imgurl', '!=', '')
  2439. ->leftJoinSub(function ($query) use ($website_id) {
  2440. $query->from('article_ignore')
  2441. ->where('website_id', $website_id);
  2442. }, 'article_ignore', function ($join) {
  2443. $join->on('article_ignore.article_id', '=', 'article.id');
  2444. })
  2445. ->where(function ($query) {
  2446. $query->whereNull('article_ignore.article_id')
  2447. ->orWhere(function ($subQuery) {
  2448. $subQuery->whereNotNull('article_ignore.article_id')
  2449. ->where('article_ignore.is_ignore', 0)
  2450. ->where(function ($subSubQuery) {
  2451. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2452. ->orWhereNull('article_ignore.c_show_time');
  2453. });
  2454. });
  2455. })
  2456. ->select(
  2457. 'article.id',
  2458. 'article.title',
  2459. 'article.imgurl',
  2460. 'article.author',
  2461. 'article.updated_at',
  2462. 'article.introduce',
  2463. 'article.islink',
  2464. 'article.linkurl',
  2465. 'article.copyfrom',
  2466. 'article.cat_arr_id',
  2467. 'article.catid as category_id'
  2468. )
  2469. ->orderBy('updated_at', 'desc')
  2470. ->limit($article_imgnum)
  2471. ->get()->all();
  2472. foreach ($img_article as $k => $v) {
  2473. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2474. // return Result::success($v);
  2475. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2476. }
  2477. } else {
  2478. $img_article = [];
  2479. }
  2480. if ($article_textnum != 0) {
  2481. $text_article = Article::whereIn('article.catid', $category_arr)
  2482. ->where('article.status', 1)
  2483. ->leftJoinSub(function ($query) use ($website_id) {
  2484. $query->from('article_ignore')
  2485. ->where('website_id', $website_id);
  2486. }, 'article_ignore', function ($join) {
  2487. $join->on('article_ignore.article_id', '=', 'article.id');
  2488. })
  2489. ->where(function ($query) {
  2490. $query->whereNull('article_ignore.article_id')
  2491. ->orWhere(function ($subQuery) {
  2492. $subQuery->whereNotNull('article_ignore.article_id')
  2493. ->where('article_ignore.is_ignore', 0)
  2494. ->where(function ($subSubQuery) {
  2495. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2496. ->orWhereNull('article_ignore.c_show_time');
  2497. });
  2498. });
  2499. })
  2500. ->select(
  2501. 'article.id',
  2502. 'article.title',
  2503. 'article.author',
  2504. 'article.updated_at',
  2505. 'article.introduce',
  2506. 'article.islink',
  2507. 'article.linkurl',
  2508. 'article.copyfrom',
  2509. 'article.cat_arr_id',
  2510. 'article.catid as category_id'
  2511. )
  2512. ->orderBy('updated_at', 'desc')
  2513. ->limit($article_textnum)
  2514. ->get()->all();
  2515. foreach ($text_article as $k => $v) {
  2516. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2517. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2518. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2519. }
  2520. } else {
  2521. $text_article = [];
  2522. }
  2523. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2524. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2525. $parent[$key] = $catiall[$parent_category];
  2526. } else {
  2527. $parent[$key] = [];
  2528. }
  2529. }
  2530. }
  2531. return Result::success($parent);
  2532. }
  2533. // 封装处理商品的路由问题
  2534. function processGoods($goods, $data)
  2535. {
  2536. return $goods->map(function ($good) use ($data) {
  2537. $catid = $good->catid ?? 0;
  2538. // $pinyin = '';
  2539. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2540. if (!empty($category->pid) && $category->pid != 0) {
  2541. $level = json_decode($category->category_arr_id, true);
  2542. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2543. ->whereIn('category_id', $level)
  2544. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2545. ->get(['aLIas_pinyin'])
  2546. ->pluck('aLIas_pinyin')
  2547. ->implode('/');
  2548. } else {
  2549. $pinyin = $category->aLIas_pinyin ?? '';
  2550. }
  2551. if (isset($good->city_id) && !empty($good->city_id)) {
  2552. $city = District::where('id', $good->city_id)->first(['name']);
  2553. $good->city_name = $city->name ?? '';
  2554. }
  2555. // 解析imgurl JSON并取第一条数据
  2556. $imgUrls = json_decode($good->imgurl, true);
  2557. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2558. $good->pinyin = $pinyin;
  2559. return $good;
  2560. });
  2561. }
  2562. /**
  2563. * 获取商城首页-根据栏目id
  2564. * @param array $data
  2565. * @return array
  2566. * */
  2567. function getWebsiteCatidshop(array $data): array
  2568. {
  2569. $input['catid'] = $data['catid'];
  2570. $input['website_id'] = $data['website_id'];
  2571. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2572. $result = array_map(function ($item) use ($input) {
  2573. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2574. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2575. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2576. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2577. if (empty($category) || $category->type != 2) {
  2578. return Result::error("暂无此栏目", 0);
  2579. } else {
  2580. $website['website_id'] = $input['website_id'];
  2581. $goods = Good::where('good.status', 2)
  2582. ->where('good.website_id', $website['website_id'])
  2583. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2584. ->select(
  2585. 'good.id',
  2586. 'good.name',
  2587. 'good.imgurl',
  2588. 'good.description',
  2589. 'good.updated_at',
  2590. 'good.catid',
  2591. 'good.type_id',
  2592. 'good.price',
  2593. 'good.com',
  2594. 'good.level',
  2595. 'good.unit'
  2596. )
  2597. ->orderBy('updated_at', 'desc')
  2598. ->offset($goodStart)
  2599. ->limit($goodNum);
  2600. $all_goods = $goods->get();
  2601. $all_goods = $this->processGoods($all_goods, $website);
  2602. }
  2603. return $all_goods ?? [];
  2604. }
  2605. }, $data);
  2606. return Result::success($result);
  2607. }
  2608. /**
  2609. * 获取商品模块
  2610. * @param array $data
  2611. * @return array
  2612. * */
  2613. public function getWebsiteshop(array $data): array
  2614. {
  2615. $input['id'] = $data['id'];
  2616. $input['website_id'] = $data['website_id'];
  2617. $catid = $data['catid'];
  2618. $data = json_decode($input['id'] ?? '', true) ?? [];
  2619. $result['goods'] = array_map(function ($item) use ($input) {
  2620. // 检查parent元素是否存在且不是undefined
  2621. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2622. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2623. $website = $input['website_id'];
  2624. $query = Good::where('good.status', 2)
  2625. ->where('good.website_id', $website);
  2626. switch ($Levelid) {
  2627. case 1:
  2628. case 2:
  2629. case 3:
  2630. $goods = $query->where(function ($q) use ($Levelid) {
  2631. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2632. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2633. });
  2634. break;
  2635. case 4:
  2636. $goods = $query;
  2637. break;
  2638. case 5:
  2639. $goods = $query->where('type_id', 1);
  2640. break;
  2641. case 6:
  2642. $goods = $query->where('type_id', 2);
  2643. break;
  2644. default:
  2645. return [];
  2646. }
  2647. $all_goods = $goods
  2648. ->select(
  2649. 'good.id',
  2650. 'good.name',
  2651. 'good.imgurl',
  2652. 'good.description',
  2653. 'good.updated_at',
  2654. 'good.catid',
  2655. 'good.type_id',
  2656. 'good.price',
  2657. 'good.level',
  2658. 'good.website_id'
  2659. )
  2660. ->orderBy('updated_at', 'desc')
  2661. ->offset($goodStart)
  2662. ->limit($goodNum)
  2663. ->get();
  2664. $web['website_id'] = $website;
  2665. $all_goods = $this->processGoods($all_goods, $web);
  2666. }
  2667. return $all_goods;
  2668. }, $data);
  2669. $website = $input['website_id'];
  2670. $result['article'] = Article::where(function ($query) use ($website) {
  2671. $query->where(function ($subQuery) use ($website) {
  2672. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2673. })->orWhereNull("ignore_ids");
  2674. })
  2675. ->where('catid', $catid)
  2676. ->where('article.status', 1)
  2677. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2678. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2679. ->orderBy('article.updated_at', 'desc')
  2680. ->first();
  2681. return Result::success($result);
  2682. }
  2683. /**
  2684. * 获取商品分类
  2685. * @param array $data
  2686. * @return array
  2687. * */
  2688. public function getWebsiteshopCat(array $data): array
  2689. {
  2690. $website = $data['website_id'];
  2691. $category = WebsiteCategory::where('website_id', $website)
  2692. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2693. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2694. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2695. ->orderBy('sort')
  2696. ->get();
  2697. $cat = $category->map(function ($item) use ($website) {
  2698. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2699. $pid = $item->pid ?? 0;
  2700. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2701. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2702. ->where('website_id', $website)
  2703. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2704. ->get(['aLIas_pinyin'])
  2705. ->pluck('aLIas_pinyin')
  2706. ->implode('/');
  2707. } else {
  2708. $pinyin = $item->aLIas_pinyin ?? '';
  2709. }
  2710. $item->pinyin = $pinyin;
  2711. });
  2712. if (empty($category)) {
  2713. return Result::error("栏目查询失败", 0);
  2714. }
  2715. $cat_tree = Result::buildMenuTree($category);
  2716. $web['website_id'] = $website;
  2717. $goods = Good::where('website_id', $website)
  2718. ->where('status', 2)
  2719. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2720. ->latest('updated_at')
  2721. ->offset(($data['page'] - 1) * $data['pageSize'])
  2722. ->limit($data['pageSize'])
  2723. ->get();
  2724. if (!empty($goods)) {
  2725. if ($goods->count() > 1 && !empty($goods)) {
  2726. $goods = $this->processGoods($goods, $web);
  2727. }
  2728. } else {
  2729. $goods = [];
  2730. }
  2731. $result = [
  2732. 'category' => $cat_tree,
  2733. 'goods' => $goods,
  2734. ];
  2735. // $resul['goods'] = $goods;
  2736. if (empty($result)) {
  2737. return Result::error("查询失败", 0);
  2738. }
  2739. return Result::success($result);
  2740. }
  2741. /*
  2742. * 获取商品列表
  2743. * @param array $data
  2744. * @return array
  2745. * */
  2746. public function getWebsiteshopList(array $data): array
  2747. {
  2748. // return Result::success($data);
  2749. $where = [
  2750. 'status' => 2,
  2751. 'website_id' => $data['website_id'],
  2752. ];
  2753. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2754. // return Result::error("查询失败", 0);
  2755. // }
  2756. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2757. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2758. $data['catid'] = $category->category_id ?? 0;
  2759. }
  2760. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2761. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2762. }
  2763. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2764. array_push($where, ['type_id', $data['type_id']]);
  2765. }
  2766. $query = Good::where($where)
  2767. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2768. $query->where(function ($q) use ($data) {
  2769. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2770. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2771. });
  2772. })
  2773. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2774. $query->where(function ($q) use ($data) {
  2775. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2776. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2777. });
  2778. })
  2779. ->select(
  2780. 'good.id',
  2781. 'good.name',
  2782. 'good.imgurl',
  2783. 'good.description',
  2784. 'good.updated_at',
  2785. 'good.com',
  2786. 'good.catid',
  2787. 'good.type_id',
  2788. 'good.website_id',
  2789. 'good.cat_arr_id',
  2790. 'good.created_at',
  2791. 'good.city_id'
  2792. )
  2793. ->latest('updated_at');
  2794. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2795. $result['count'] = $query->clone()->count();
  2796. $result['goods'] = $this->processGoods(
  2797. $query->clone()
  2798. ->offset(($data['page'] - 1) * $data['pageSize'])
  2799. ->limit($data['pageSize'])
  2800. ->get(),
  2801. $data
  2802. );
  2803. } else {
  2804. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2805. // 获取 type_id 为 1 的数据
  2806. $result['type1'] = $this->processGoods(
  2807. $query->clone()
  2808. ->where('type_id', 1)
  2809. ->offset(($data['page'] - 1) * $data['pageSize'])
  2810. ->limit($data['pageSize'])
  2811. ->get(),
  2812. $data
  2813. );
  2814. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2815. // 获取 type_id 为 2 的数据
  2816. $result['type2'] = $this->processGoods(
  2817. $query->clone()
  2818. ->where('type_id', 2)
  2819. ->offset(($data['page'] - 1) * $data['pageSize'])
  2820. ->limit($data['pageSize'])
  2821. ->get(),
  2822. $data
  2823. );
  2824. }
  2825. if (empty($result)) {
  2826. return Result::error("查询失败", 0);
  2827. }
  2828. return Result::success($result);
  2829. }
  2830. /**
  2831. * 获取商品详情
  2832. * @param array $data
  2833. * @return array
  2834. * */
  2835. public function getWebsiteshopInfo(array $data): array
  2836. {
  2837. $where = [
  2838. 'good.status' => 2,
  2839. 'good.website_id' => $data['website_id'],
  2840. 'good.id' => $data['id'],
  2841. ];
  2842. $goods = Good::where($where)
  2843. ->where('good.id', $data['id'])
  2844. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2845. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2846. ->first();
  2847. if (empty($goods)) {
  2848. return Result::error("查询失败", 0);
  2849. }
  2850. $goods->imgurl = json_decode($goods->imgurl, true);
  2851. return Result::success($goods);
  2852. }
  2853. /**
  2854. * plus pro 处理文章路由问题
  2855. */
  2856. function processArticlePro($website_id)
  2857. {
  2858. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2859. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2860. // // 取出category_id 对应的aLIas_pinyin
  2861. // $categoryIds = array_column($categorys, 'category_id');
  2862. // $categoryPIds = array_column($categorys, 'pid');
  2863. // $aliasPinyins = array_column($categorys, 'path');
  2864. // $alias = array_column($categorys, 'alias');
  2865. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2866. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2867. // // return Result::success($cat_arr);
  2868. // // $catiall = [];
  2869. // //一级所有子级的记录
  2870. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2871. // return [
  2872. // 'cat_1st_arr' => $cat_alias_arr,
  2873. // 'catiall' => $cat_arr,
  2874. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2875. // 'categoryIds' => $categoryIds,
  2876. // ];
  2877. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2878. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2879. // 取出category_id 对应的aLIas_pinyin
  2880. $categoryIds = array_column($categorys, 'category_id');
  2881. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2882. return $pid != 0;
  2883. })));
  2884. $category_path = array_column($categorys, 'path');
  2885. $cat_arr = array_combine($categoryIds, $category_path);
  2886. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2887. $catiall = [];
  2888. //一级所有子级的记录
  2889. $cat_1st_arr = [];
  2890. foreach ($categorys as $key => $value) {
  2891. // $category_arr_id = json_decode($value->category_arr_id);
  2892. // $pinyin_str = '';
  2893. // // 算出一级 并且算出子级
  2894. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2895. $cat_1st_arr[$value->pid][] = $value->category_id;
  2896. }
  2897. // foreach ($category_arr_id as $k => $v) {
  2898. // $pinyin_str .= $cat_arr[$v] . '/';
  2899. // }
  2900. // $pinyin_str = rtrim($pinyin_str, '/');
  2901. $catiall[$value->category_id]['alias'] = $value->alias;
  2902. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2903. $catiall[$value->category_id]['type'] = $value->type;
  2904. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2905. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2906. }
  2907. return [
  2908. 'cat_1st_arr' => $cat_1st_arr,
  2909. 'catiall' => $catiall,
  2910. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2911. 'categoryIds' => $categoryIds,
  2912. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2913. 'categoryPIds' => $categoryPIds,
  2914. ];
  2915. }
  2916. /**
  2917. * 封装处理文章的路由问题
  2918. * */
  2919. function processArticles($articles, $data)
  2920. {
  2921. // 检查 $articles 是否为数组或可迭代对象
  2922. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2923. return $articles->map(function ($article) use ($data) {
  2924. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2925. $catid = $article->cat_arr_id ?? '';
  2926. }
  2927. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2928. $catid = $article->category_arr_id ?? '';
  2929. }
  2930. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2931. $level = json_decode($catid, true);
  2932. if (!is_array($level)) {
  2933. return $article;
  2934. } else {
  2935. $level = array_map('intval', $level);
  2936. }
  2937. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2938. ->where($data)
  2939. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2940. ->pluck('aLIas_pinyin')
  2941. ->implode('/');
  2942. $article->pinyin = $pinyin ?? '';
  2943. return $article;
  2944. });
  2945. } else {
  2946. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2947. $catid = $articles->cat_arr_id ?? '';
  2948. $level = json_decode($catid, true);
  2949. if (!is_array($level)) {
  2950. return $articles;
  2951. } else {
  2952. $level = array_map('intval', $level);
  2953. }
  2954. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2955. ->where($data)
  2956. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2957. ->pluck('aLIas_pinyin')
  2958. ->implode('/');
  2959. $articles->pinyin = $pinyin ?? '';
  2960. return $articles;
  2961. }
  2962. }
  2963. // 封装处理由问题
  2964. function processJob($job, $data)
  2965. {
  2966. return $job->map(function ($job) use ($data) {
  2967. $category = $job->cat_arr_id ?? '';
  2968. $cityid = $job->city_arr_id ?? '';
  2969. $city = json_decode($cityid, true);
  2970. $pinyin = '';
  2971. $level = json_decode($category, true);
  2972. // 路由
  2973. if (!empty($level) && is_array($level)) {
  2974. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2975. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2976. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2977. ->get(['aLIas_pinyin'])
  2978. ->pluck('aLIas_pinyin')
  2979. ->implode('/');
  2980. if (empty($pinyin)) {
  2981. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2982. }
  2983. $job->pinyin = $pinyin;
  2984. }
  2985. // 取职位-城市 市??省
  2986. if (!empty($city) && is_array($city)) {
  2987. if (isset($city[1]) && !empty($city[1])) {
  2988. $city = District::where('id', $city[1])->first(['name']);
  2989. $job->city_name = $city->name ?? '';
  2990. } else if (isset($city[0]) && !empty($city[0])) {
  2991. $city = District::where('id', $city[0])->first(['name']);
  2992. $job->city_name = $city->name ?? '';
  2993. } else {
  2994. $job->city_name = '全国';
  2995. }
  2996. }
  2997. // 获取简历最后一级地区
  2998. if (isset($job->city_id) && !empty($job->city_id)) {
  2999. $city = District::where('id', $job->city_id)->first(['name']);
  3000. $job->hunt_cityname = $city->name ?? '';
  3001. }
  3002. // 组合详细地址
  3003. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3004. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3005. if (is_array($address_id) && !empty($address_id)) {
  3006. $address = District::whereIn('id', $address_id)
  3007. ->orderBy('level', 'asc')
  3008. ->get(['name'])
  3009. ->pluck('name')
  3010. ->implode('');
  3011. // $job->address_name = $address ?? '';
  3012. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3013. }
  3014. }
  3015. // 取行业
  3016. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3017. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3018. if (!empty($job->industry)) {
  3019. $query->where('hyid', $job->industry);
  3020. } else if (!empty($job->hy_id)) {
  3021. $query->where('hyid', $job->hy_id);
  3022. } else if (!empty($job->company_hy_id)) {
  3023. $query->where('hyid', $job->company_hy_id);
  3024. } else {
  3025. $query->where('hyid', $job->job_industry);
  3026. }
  3027. })->first(['hyname']);
  3028. $job->hy_name = $hy_name->hyname ?? '';
  3029. }
  3030. // 取职位类别
  3031. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3032. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3033. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3034. $job->zw_name = $zw_name->zwname ?? '';
  3035. }
  3036. // 取具体职位
  3037. 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))) {
  3038. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3039. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3040. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3041. }
  3042. // 取工作经验
  3043. if (isset($job->experience) && !empty($job->experience)) {
  3044. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3045. $job->experience_name = $experience->ename ?? '';
  3046. }
  3047. // 取学历
  3048. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3049. $education = $job->educational ?? $job->school_education;
  3050. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3051. $job->education_name = $education->ename ?? '';
  3052. }
  3053. // 语言
  3054. if (isset($job->language) && !empty($job->language)) {
  3055. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3056. $job->language_name = $language->ename ?? '';
  3057. }
  3058. // 薪资
  3059. if (isset($job->salary) && !empty($job->salary)) {
  3060. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3061. $job->salary_name = $salary->ename ?? '';
  3062. }
  3063. // 职位性质
  3064. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3065. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3066. $job->job_nature_name = $job_nature->ename ?? '';
  3067. }
  3068. // 公司规模
  3069. if (isset($job->company_size) && !empty($job->company_size)) {
  3070. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3071. $job->company_size_name = $company_size->ename ?? '';
  3072. }
  3073. // 公司性质
  3074. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3075. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3076. $job->company_nature_name = $company_nature->nature_name ?? '';
  3077. }
  3078. // $job->pinyin = $pinyin;
  3079. return $job;
  3080. });
  3081. }
  3082. /**
  3083. * 获取书籍模块
  3084. * @param array $data
  3085. * @return array
  3086. * */
  3087. public function getWebsiteBook(array $data): array
  3088. {
  3089. $input['id'] = $data['id'];
  3090. $input['website_id'] = $data['website_id'];
  3091. // 将 JSON 字符串转换为 PHP 数组
  3092. $data = json_decode($input['id'], true);
  3093. // 使用 array_map 处理每个元素
  3094. $result = array_map(function ($item) use ($input) {
  3095. // 检查parent元素是否存在且不是undefined
  3096. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3097. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3098. $website = [
  3099. 'website_id' => $input['website_id'],
  3100. ];
  3101. // 查询栏目名称
  3102. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3103. if (empty($category)) {
  3104. $parent_alias = '';
  3105. $parent_pinyin = null;
  3106. $imgBooks = [];
  3107. $textBooks = [];
  3108. } else {
  3109. $parent_alias = $category->alias ?? '';
  3110. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3111. // 查找子分类ID数组
  3112. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3113. array_push($childCategoryIds, $parentCatId);
  3114. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3115. if ($parentImgNum != 0) {
  3116. // 查询图片新闻
  3117. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3118. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3119. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3120. })
  3121. ->where('book.status', 2)
  3122. ->where('book.img_url', '!=', '')
  3123. ->where('book.website_id', $website['website_id'])
  3124. ->leftJoin('website_category', function ($join) use ($website) {
  3125. $join->on('book.cat_id', '=', 'website_category.category_id')
  3126. ->where('website_category.website_id', '=', $website['website_id']);
  3127. })
  3128. ->select(
  3129. 'book.id',
  3130. 'book.title',
  3131. 'book.img_url',
  3132. 'book.price',
  3133. 'book.market_price',
  3134. 'book.description',
  3135. 'book.cat_id',
  3136. 'book.description',
  3137. 'book.updated_at',
  3138. 'website_category.alias as category_name',
  3139. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3140. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3141. )
  3142. ->orderBy('updated_at', 'desc')
  3143. ->limit($parentImgNum)
  3144. ->get()->all();
  3145. // 查询文字新闻
  3146. }
  3147. if ($parentTextNum != 0) {
  3148. $textBooks = [];
  3149. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3150. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3151. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3152. })
  3153. ->where('book.status', 2)
  3154. ->where('book.website_id', $website['website_id'])
  3155. ->leftJoin('website_category', function ($join) use ($website) {
  3156. $join->on('book.cat_id', '=', 'website_category.category_id')
  3157. ->where('website_category.website_id', '=', $website['website_id']);
  3158. })
  3159. ->select(
  3160. 'book.id',
  3161. 'book.title',
  3162. 'book.img_url',
  3163. 'book.price',
  3164. 'book.market_price',
  3165. 'book.description',
  3166. 'book.cat_id',
  3167. 'book.description',
  3168. 'book.updated_at',
  3169. 'website_category.alias as category_name',
  3170. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3171. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3172. )
  3173. ->orderBy('updated_at', 'desc')
  3174. ->limit($parentTextNum)
  3175. ->get()->all();
  3176. }
  3177. }
  3178. }
  3179. $resultItem = [
  3180. 'alias' => $parent_alias ?? '',
  3181. 'category_id' => $parentCatId ?? 0,
  3182. 'pinyin' => $parent_pinyin ?? null,
  3183. 'imgnum' => $imgBooks ?? [],
  3184. 'textnum' => $textBooks ?? [],
  3185. ];
  3186. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3187. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3188. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3189. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3190. ->get()->all();
  3191. if (!empty($childCategory)) {
  3192. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3193. // 查询子栏目名称
  3194. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3195. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3196. ->first();
  3197. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3198. $childImgArticles = [];
  3199. $childTextArticles = [];
  3200. $resultItem['child'] = [];
  3201. } else {
  3202. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3203. // 查询子栏目图片新闻
  3204. $childImgArticles = Book::where('cat_id', $childCatId)
  3205. ->where('status', 2)
  3206. ->where('img_url', '!=', '')
  3207. ->where('book.website_id', $website['website_id'])
  3208. ->leftJoin('website_category', function ($join) use ($website) {
  3209. $join->on('book.cat_id', '=', 'website_category.category_id')
  3210. ->where('website_category.website_id', '=', $website['website_id']);
  3211. })
  3212. ->select(
  3213. 'book.id',
  3214. 'book.title',
  3215. 'book.img_url',
  3216. 'book.price',
  3217. 'book.market_price',
  3218. 'book.description',
  3219. 'book.cat_id',
  3220. 'book.description',
  3221. 'book.updated_at',
  3222. DB::raw("'$child_pinyin' as pinyin")
  3223. )
  3224. ->orderBy('updated_at', 'desc')
  3225. ->limit($childImgNum)
  3226. ->get()->all();
  3227. // 查询子栏目文字新闻
  3228. $childTextArticles = Book::where('cat_id', $childCatId)
  3229. ->where('status', 2)
  3230. ->where('book.website_id', $website['website_id'])
  3231. ->leftJoin('website_category', function ($join) use ($website) {
  3232. $join->on('book.cat_id', '=', 'website_category.category_id')
  3233. ->where('website_category.website_id', '=', $website['website_id']);
  3234. })
  3235. ->select(
  3236. 'book.id',
  3237. 'book.title',
  3238. 'book.img_url',
  3239. 'book.price',
  3240. 'book.market_price',
  3241. 'book.description',
  3242. 'book.cat_id',
  3243. 'book.description',
  3244. 'book.updated_at',
  3245. DB::raw("'$child_pinyin' as pinyin")
  3246. )
  3247. ->orderBy('updated_at', 'desc')
  3248. ->limit($childTextNum)
  3249. ->get()->all();
  3250. $resultItem['child'] = [
  3251. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3252. 'category_id' => $childCatId,
  3253. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3254. 'all_childcat' => $childCategory,
  3255. 'imgnum' => $childImgArticles,
  3256. 'textnum' => $childTextArticles,
  3257. ];
  3258. }
  3259. }
  3260. } else {
  3261. $resultItem['child'] = [];
  3262. }
  3263. return $resultItem;
  3264. }, $data);
  3265. return Result::success($result);
  3266. }
  3267. /**
  3268. * 获取书刊列表
  3269. * @param array $data
  3270. * @return array
  3271. * */
  3272. public function getWebsiteBookList(array $data): array
  3273. {
  3274. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3275. if (empty($web)) {
  3276. return Result::error("查询失败", 0);
  3277. }
  3278. $catid = $data['id'];
  3279. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3280. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3281. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3282. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3283. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3284. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3285. ->where('pid', $category['pid'])
  3286. ->select(
  3287. 'category_id',
  3288. 'alias',
  3289. 'aLIas_pinyin',
  3290. 'pid',
  3291. 'sort',
  3292. 'is_url',
  3293. 'web_url',
  3294. 'seo_title',
  3295. 'seo_keywords',
  3296. 'seo_description',
  3297. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3298. )
  3299. ->orderBy('sort')
  3300. ->get()->all();
  3301. if (empty($category)) {
  3302. return Result::error("查询失败", 0);
  3303. }
  3304. $query = Book::where('book.status', 2)
  3305. ->where('book.website_id', $data['website_id'])
  3306. ->where('book.cat_id', $catid)
  3307. ->select(
  3308. 'book.id',
  3309. 'book.title',
  3310. 'book.img_url',
  3311. 'book.description',
  3312. 'book.updated_at',
  3313. 'book.cat_id',
  3314. DB::raw("'$pinyin' as pinyin")
  3315. )
  3316. ->orderBy('book.updated_at', 'desc');
  3317. $count = $query->count();
  3318. $query = clone $query;
  3319. $Book = $query
  3320. ->limit($data['pageSize'])
  3321. ->offset(($data['page'] - 1) * $data['pageSize'])
  3322. ->get()->all();
  3323. $result = [
  3324. 'category' => $categorys,
  3325. 'books' => $Book,
  3326. 'count' => $count,
  3327. ];
  3328. // if(empty($result)){
  3329. // return Result::error("查询失败", 0);
  3330. // }
  3331. return Result::success($result);
  3332. }
  3333. /**
  3334. * 获取书刊详情
  3335. * @param array $data
  3336. * @return array
  3337. * */
  3338. public function getWebsiteBookInfo(array $data): array
  3339. {
  3340. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3341. if (empty($web)) {
  3342. return Result::error("查询失败", 0);
  3343. }
  3344. $book = Book::where('status', 2)
  3345. ->where('website_id', $data['website_id'])
  3346. ->where('id', $data['id'])
  3347. ->select(
  3348. 'book.*',
  3349. )
  3350. ->orderBy('updated_at', 'desc')
  3351. ->first();
  3352. if (empty($book)) {
  3353. return Result::error("查询失败", 0);
  3354. }
  3355. // 先查询当前分类的 pid
  3356. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3357. ->where('category_id', $book['cat_id'])
  3358. ->first(['pid', 'category_id']);
  3359. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3360. if (!empty($carpid)) {
  3361. if ($carpid->pid != 0) {
  3362. $pid = $carpid['pid'];
  3363. // $parent_pinyin = '';
  3364. } else {
  3365. $pid = $carpid['category_id'];
  3366. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3367. }
  3368. }
  3369. $categorys = $query->where('pid', $pid)
  3370. ->select(
  3371. 'category_id',
  3372. 'alias',
  3373. 'aLIas_pinyin',
  3374. 'pid',
  3375. 'sort',
  3376. 'is_url',
  3377. 'web_url',
  3378. 'category_arr_id as cat_arr_id',
  3379. )
  3380. ->orderBy('sort')
  3381. ->get();
  3382. $category = $this->processArticle($categorys, $data);
  3383. $result = [
  3384. 'category' => $category,
  3385. 'books' => $book,
  3386. ];
  3387. return Result::success($result);
  3388. }
  3389. /**
  3390. * 尝试
  3391. * @param array $data
  3392. * @return array
  3393. * */
  3394. public function test(array $data): array
  3395. {
  3396. $input['id'] = $data['id'];
  3397. $input['website_id'] = $data['website_id'];
  3398. // 将 JSON 字符串转换为 PHP 数组
  3399. $data = json_decode($input['id'], true);
  3400. $result = [];
  3401. $article = $data;
  3402. $result = array_map(function ($item) use ($input) {
  3403. $website = [
  3404. 'website_id' => $input['website_id'],
  3405. ];
  3406. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3407. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3408. $parent = [
  3409. 0 => $category['category_id'] ?? [],
  3410. 1 => $parentImgNum ?? [],
  3411. 2 => $parentTextNum ?? [],
  3412. ];
  3413. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3414. $child = [];
  3415. $resultItem = [
  3416. // 'alias' => $parent_alias ?? '',
  3417. 'category_id' => $parentCatId ?? 0,
  3418. 'pinyin' => $parentImgNum ?? null,
  3419. 'imgnum' => $parentTextNum ?? [],
  3420. // 'textnum' => $textArticles ?? [],
  3421. ];
  3422. return $parent;
  3423. }, $data);
  3424. return Result::success($result);
  3425. // });
  3426. }
  3427. /**
  3428. * 封装处理文章的路由问题
  3429. * */
  3430. function processArticle($article, $data)
  3431. {
  3432. return $article->map(function ($article) use ($data) {
  3433. $catid = $article->cat_arr_id ?? '';
  3434. $level = json_decode($catid, true);
  3435. $pinyin = '';
  3436. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3437. if (!empty($level) && is_array($level)) {
  3438. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3439. ->where('website_id', $data['website_id'])
  3440. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3441. ->get(['aLIas_pinyin'])
  3442. ->pluck('aLIas_pinyin')
  3443. ->implode('/');
  3444. } else {
  3445. $pinyin = '';
  3446. }
  3447. $article->pinyin = $pinyin;
  3448. return $article;
  3449. });
  3450. }
  3451. /**
  3452. * c端-获取招工招聘下拉选框
  3453. * @param array $data
  3454. * @return array
  3455. * */
  3456. public function getWebsiteJobSelect(array $data): array
  3457. {
  3458. $web = Website::where('id', $data['website_id'])->first();
  3459. if (empty($web)) {
  3460. return Result::error("该网站不存在", 0);
  3461. }
  3462. $hy = JobIndustry::get()->all();
  3463. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3464. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3465. $result = [
  3466. 'hy' => $hy,
  3467. 'zw' => $zw,
  3468. 'jtzw' => $jtzw,
  3469. ];
  3470. if (empty($result)) {
  3471. return Result::error("查询失败", 0);
  3472. }
  3473. return Result::success($result);
  3474. }
  3475. /**
  3476. * c端-获取招工招聘
  3477. * @param array $data
  3478. * @return array
  3479. * */
  3480. public function getWebsiteJob(array $data): array
  3481. {
  3482. $web = Website::where('id', $data['website_id'])->first();
  3483. if (empty($web)) {
  3484. return Result::error("该网站不存在", 0);
  3485. }
  3486. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3487. ->where('job_hunting.website_id', $data['website_id'])
  3488. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3489. $query->where(function ($q) use ($data) {
  3490. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3491. });
  3492. })
  3493. ->select(
  3494. 'job_hunting.id',
  3495. 'job_hunting.catid',
  3496. 'job_hunting.cat_arr_id',
  3497. 'job_hunting.job_name_get',
  3498. 'job_hunting.industry',
  3499. 'job_hunting.name',
  3500. 'job_hunting.sexy',
  3501. 'job_hunting.origin',
  3502. 'job_hunting.city_arr_id',
  3503. 'job_hunting.experience',
  3504. 'job_hunting.updated_at',
  3505. 'job_hunting.salary',
  3506. 'job_hunting.skillList',
  3507. 'job_hunting.slelf_evaluation',
  3508. )
  3509. ->orderBy('updated_at', 'desc')
  3510. ->limit($data['job1_num'])
  3511. ->get();
  3512. $web['website_id'] = $data['website_id'];
  3513. if (empty($job_hunting)) {
  3514. $job_huntings = "未查询到相关简历信息";
  3515. } else {
  3516. $job_huntings = $this->processJob($job_hunting, $web);
  3517. }
  3518. // 0:待审核 1:已通过 2:已拒绝
  3519. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3520. ->where('job_recruiting.website_id', $data['website_id'])
  3521. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3522. $query->where(function ($q) use ($data) {
  3523. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3524. });
  3525. })
  3526. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3527. ->select(
  3528. 'job_recruiting.id',
  3529. 'job_recruiting.catid',
  3530. 'job_recruiting.cat_arr_id',
  3531. 'job_recruiting.title',
  3532. 'job_recruiting.jtzw_id',
  3533. 'job_recruiting.hy_id',
  3534. 'job_recruiting.city_arr_id',
  3535. 'job_recruiting.due_data',
  3536. 'job_recruiting.updated_at',
  3537. 'job_recruiting.experience',
  3538. 'job_recruiting.educational',
  3539. 'job_recruiting.salary',
  3540. 'job_recruiting.zw_id',
  3541. 'job_company.business_name',
  3542. 'job_recruiting.keyword',
  3543. 'job_recruiting.description',
  3544. )
  3545. ->orderBy('updated_at', 'desc')
  3546. ->limit($data['job2_num'])
  3547. ->get();
  3548. if (empty($job_recruiting->toArray())) {
  3549. $job_recruitings = "未查询到相关职位信息";
  3550. } else {
  3551. $job_recruitings = $this->processJob($job_recruiting, $web);
  3552. }
  3553. $result = [
  3554. 'job_hunting' => $job_huntings,
  3555. 'job_recuiting' => $job_recruitings,
  3556. ];
  3557. return Result::success($result);
  3558. }
  3559. /**
  3560. * c端-获取招工招聘列表
  3561. * @param array $data
  3562. * @return array
  3563. * */
  3564. public function getWebsiteJobList(array $data): array
  3565. {
  3566. $recruit_where = [];
  3567. $hunt_where = [];
  3568. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3569. if (empty($web)) {
  3570. return Result::error("此网站不存在", 0);
  3571. }
  3572. $website_id['website_id'] = $data['website_id'];
  3573. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3574. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3575. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3576. }
  3577. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3578. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3579. }
  3580. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3581. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3582. }
  3583. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3584. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3585. }
  3586. $query = JobRecruiting::where('job_recruiting.status', 1)
  3587. ->where('job_recruiting.website_id', $data['website_id'])
  3588. ->where($recruit_where)
  3589. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3590. $query->where(function ($q) use ($data) {
  3591. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3592. });
  3593. })
  3594. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3595. $query->where(function ($q) use ($data) {
  3596. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3597. });
  3598. })
  3599. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3600. ->select(
  3601. 'job_recruiting.id',
  3602. 'job_recruiting.catid',
  3603. 'job_recruiting.hy_id',
  3604. 'job_recruiting.title',
  3605. 'job_recruiting.zw_id',
  3606. 'job_recruiting.educational',
  3607. 'job_recruiting.jtzw_id',
  3608. 'job_recruiting.city_arr_id',
  3609. 'job_recruiting.due_data',
  3610. 'job_recruiting.experience',
  3611. 'job_recruiting.cat_arr_id',
  3612. 'job_recruiting.updated_at',
  3613. 'job_company.business_name',
  3614. 'job_recruiting.keyword',
  3615. 'job_recruiting.description',
  3616. )
  3617. ->orderBy('job_recruiting.updated_at', 'desc');
  3618. $recruit_count = $query->count();
  3619. $query = clone $query;
  3620. $JobRecruiting = $query
  3621. ->offset(($data['page'] - 1) * $data['pageSize'])
  3622. ->limit($data['pageSize'])
  3623. ->get();
  3624. if (empty($JobRecruiting)) {
  3625. $JobRecruiting = "暂无相关职位信息";
  3626. } else {
  3627. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3628. }
  3629. }
  3630. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3631. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3632. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3633. }
  3634. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3635. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3636. }
  3637. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3638. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3639. }
  3640. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3641. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3642. }
  3643. $query = JobHunting::where('job_hunting.status', 2)
  3644. ->where('job_hunting.website_id', $data['website_id'])
  3645. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3646. ->where($hunt_where)
  3647. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3648. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3649. // })
  3650. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3651. $query->where(function ($q) use ($data) {
  3652. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3653. });
  3654. })
  3655. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3656. $query->where(function ($q) use ($data) {
  3657. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3658. });
  3659. })
  3660. ->select(
  3661. 'job_hunting.id',
  3662. 'job_hunting.catid',
  3663. 'job_hunting.sexy',
  3664. 'job_hunting.experience',
  3665. 'job_hunting.origin',
  3666. 'job_hunting.industry',
  3667. 'job_hunting.name',
  3668. 'job_hunting.job',
  3669. 'job_hunting.job_name_get',
  3670. 'job_hunting.city_arr_id',
  3671. 'job_hunting.cat_arr_id',
  3672. 'job_hunting.created_at',
  3673. 'job_hunting.updated_at',
  3674. 'job_position.zwname as job_name',
  3675. 'job_hunting.skillList',
  3676. 'job_hunting.slelf_evaluation',
  3677. )
  3678. ->orderBy('job_hunting.updated_at', 'desc');
  3679. $hunt_count = $query->count();
  3680. $query = clone $query;
  3681. $JobHunting = $query
  3682. ->offset(($data['page'] - 1) * $data['pageSize'])
  3683. ->limit($data['pageSize'])
  3684. ->get();
  3685. if (empty($JobHunting)) {
  3686. $JobRecruiting = "暂无相关简历信息";
  3687. } else {
  3688. $JobHunting = $this->processJob($JobHunting, $website_id);
  3689. }
  3690. }
  3691. $result = [
  3692. 'JobRecruiting' => $JobRecruiting ?? [],
  3693. 'recruit_count' => $recruit_count ?? 0,
  3694. 'JobHunting' => $JobHunting ?? [],
  3695. 'hunt_count' => $hunt_count ?? 0,
  3696. ];
  3697. return Result::success($result);
  3698. }
  3699. /**
  3700. * c端-获取招工招聘详情
  3701. * @param array $data
  3702. * @return array
  3703. * */
  3704. public function getWebsiteJobInfo(array $data): array
  3705. {
  3706. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3707. if (empty($web)) {
  3708. return Result::error("该网站不存在", 0);
  3709. }
  3710. $webid = [
  3711. 'website_id' => $data['website_id'],
  3712. ];
  3713. // 职位相关信息
  3714. if ($data['type'] == 1) {
  3715. $query = JobRecruiting::where('status', 1)
  3716. ->where('website_id', $data['website_id'])
  3717. ->select('*');
  3718. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3719. $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();
  3720. if (!empty($company)) {
  3721. $result['company'] = $this->processJob($company, $webid);
  3722. }
  3723. $other_job = JobRecruiting::where('status', 1)
  3724. ->where('website_id', $data['website_id'])
  3725. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3726. ->where('id', '!=', $data['id'])
  3727. ->where('user_id', '=', $job[0]['user_id'])
  3728. ->limit($data['pageSize'])
  3729. ->get();
  3730. if (!empty($other_job)) {
  3731. $result['other_job'] = $this->processJob($other_job, $webid);
  3732. }
  3733. } else {
  3734. // 简历相关信息
  3735. $job = JobHunting::where('job_hunting.status', 2)
  3736. ->where('job_hunting.website_id', $data['website_id'])
  3737. ->where('job_hunting.id', $data['id'])
  3738. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3739. ->select('job_hunting.*', 'user_name')
  3740. ->get();
  3741. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3742. if (!empty($resume->toArray())) {
  3743. $result['resume'] = 1;
  3744. } else {
  3745. $result['resume'] = 0;
  3746. }
  3747. }
  3748. if (empty($job->toArray())) {
  3749. return Result::error("id参数错误", 0);
  3750. }
  3751. if (!empty($job[0]['job_experience'])) {
  3752. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3753. if (!empty($job_experience)) {
  3754. // $hy = [];
  3755. foreach ($job_experience as $key => $value) {
  3756. // $id = $value['id'];
  3757. $hy[$key] = $value['job_industry'];
  3758. $zw_id[$key] = $value['job_typename'];
  3759. $jtzw_id[$key] = $value['job_name'];
  3760. }
  3761. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3762. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3763. // 先将关联表转换为索引数组,提高查找效率
  3764. $hyLookup = [];
  3765. foreach ($hy_table as $item) {
  3766. $hyLookup[$item['hyid']] = $item['hyname'];
  3767. }
  3768. $zwLookup = [];
  3769. foreach ($zw_table as $item) {
  3770. $zwLookup[$item['zwid']] = $item['zwname'];
  3771. }
  3772. foreach ($job_experience as $key => &$value) {
  3773. // 处理行业名称
  3774. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3775. $value['hy_name'] = $hyLookup[$hy[$key]];
  3776. }
  3777. // 处理职位名称
  3778. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3779. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3780. }
  3781. // 处理具体职位名称
  3782. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3783. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3784. }
  3785. }
  3786. // 释放引用,防止意外修改后续代码
  3787. unset($value);
  3788. }
  3789. $result['job_experience'] = $job_experience ?? [];
  3790. }
  3791. if (!empty($job[0]['education_experience'])) {
  3792. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3793. if (!empty($education_experience)) {
  3794. foreach ($education_experience as $key => $value) {
  3795. // $id = $value['id'];
  3796. $education[$key] = $value['school_education'];
  3797. }
  3798. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3799. // // 先将关联表转换为索引数组,提高查找效率
  3800. $educationLookup = [];
  3801. foreach ($education_table as $item) {
  3802. $educationLookup[$item['evalue']] = $item['ename'];
  3803. }
  3804. foreach ($education_experience as $key => &$value) {
  3805. // 处理学历名称
  3806. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3807. $value['education_name'] = $educationLookup[$education[$key]];
  3808. }
  3809. }
  3810. }
  3811. $result['education_experience'] = $job_experience ?? [];
  3812. }
  3813. $result['job'] = $this->processJob($job, $webid);
  3814. // // 返现对应的栏目
  3815. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3816. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3817. ->whereIn('category_id', $catid)
  3818. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3819. ->orderBy('pid')->get()->all();
  3820. if (!empty($category)) {
  3821. $result['category'] = $category;
  3822. }
  3823. $result['job'] = $job;
  3824. $result['job_experience'] = $job_experience ?? [];
  3825. $result['education_experience'] = $education_experience ?? [];
  3826. if (empty($result)) {
  3827. return Result::error("参数错误", 0);
  3828. }
  3829. return Result::success($result);
  3830. }
  3831. /**
  3832. * c端-申请职位
  3833. * @param array $data
  3834. * @return array
  3835. * */
  3836. public function getWebsiteJobApply(array $data): array
  3837. {
  3838. // 首先验证网站是否存在
  3839. // return Result::success($data);
  3840. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3841. if (empty($web)) {
  3842. return Result::error("该网站不存在", 0);
  3843. }
  3844. // 验证用户是否存在且为个人会员/管理员
  3845. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3846. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3847. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3848. return Result::error("用户不存在", 0);
  3849. }
  3850. // 去除重复元素和空元素,并保持原始顺序
  3851. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3852. return !empty($value);
  3853. }));
  3854. // 验证职位是否存在 1:审核通过
  3855. $recruiting = JobRecruiting::where('status', 1)
  3856. ->where('website_id', $data['website_id'])
  3857. ->whereIn('id', $data['recruit_id'])
  3858. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3859. if (empty($recruiting)) {
  3860. return Result::error("该职位不存在", 0);
  3861. }
  3862. // 简历是否存在
  3863. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3864. if (empty($hunt_id)) {
  3865. return Result::error("该简历不存在", 0);
  3866. }
  3867. $data['hunt_id'] = $hunt_id['hunt_id'];
  3868. // // 验证是否已投递过该职位
  3869. $apply = JobApply::where('user_id', $data['user_id'])
  3870. ->where('hunt_id', $data['hunt_id'])
  3871. ->where('website_id', $data['website_id'])
  3872. ->whereIn('recruit_id', $data['recruit_id'])
  3873. ->get(['recruit_id']);
  3874. if (!empty($apply->toArray())) {
  3875. return Result::error("您已投递过该职位!");
  3876. }
  3877. $insertData = array_map(function ($recruiting) use ($data) {
  3878. return [
  3879. 'user_id' => $data['user_id'],
  3880. 'hunt_id' => $data['hunt_id'],
  3881. 'website_id' => $data['website_id'],
  3882. 'recruit_id' => $recruiting['recruit_id'],
  3883. 'receiver_id' => $recruiting['receiver_id'],
  3884. 'status' => 1,
  3885. ];
  3886. }, $recruiting);
  3887. // 批量插入数据
  3888. $result = JobApply::insert($insertData);
  3889. if (empty($result)) {
  3890. return Result::error("投递失败", 0);
  3891. }
  3892. return Result::success($result);
  3893. }
  3894. /**
  3895. * 招工招聘-沟通简历
  3896. * @param array $data
  3897. * @return array
  3898. * */
  3899. public function getWebsiteJobResume(array $data): array
  3900. {
  3901. // 首先验证网站是否存在
  3902. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3903. if (empty($web)) {
  3904. return Result::error("该网站不存在", 0);
  3905. }
  3906. // return Result::success($data);
  3907. // 验证用户是否存在且为企业会员/管理员
  3908. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3909. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3910. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3911. return Result::error("用户不存在", 0);
  3912. }
  3913. // 去除重复元素和空元素,并保持原始顺序
  3914. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3915. return !empty($value);
  3916. }));
  3917. // 验证简历是否存在
  3918. $hunting = JobHunting::where('status', 2)
  3919. ->where('website_id', $data['website_id'])
  3920. ->whereIn('id', $data['hunt_id'])
  3921. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3922. if (empty($hunting)) {
  3923. return Result::error("该简历不存在", 0);
  3924. }
  3925. // 验证是否已沟通过该简历
  3926. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3927. ->where('recruit_id', $data['recruit_id'])
  3928. ->where('website_id', $data['website_id'])
  3929. ->whereIn('hunt_id', $data['hunt_id'])
  3930. ->get(['hunt_id']);
  3931. if (!empty($remuse->toArray())) {
  3932. return Result::error("您已沟通过该简历!");
  3933. }
  3934. // 准备要插入的数据数组
  3935. $insertData = array_map(function ($hunting) use ($data) {
  3936. return [
  3937. 'user_id' => $data['user_id'],
  3938. 'recruit_id' => $data['recruit_id'],
  3939. 'website_id' => $data['website_id'],
  3940. 'hunt_id' => $hunting['hunt_id'],
  3941. 'receiver_id' => $hunting['receiver_id'],
  3942. 'status' => 1,
  3943. ];
  3944. }, $hunting);
  3945. // 批量插入数据
  3946. $result = JobRemuse::insert($insertData);
  3947. if (empty($result)) {
  3948. return Result::error("沟通失败", 0);
  3949. }
  3950. return Result::success($result);
  3951. }
  3952. /**
  3953. * 招工招聘 -我的职位(企业会员)
  3954. * @param array $data
  3955. * @return array
  3956. */
  3957. public function getWebsiteJobRecruiting(array $data): array
  3958. {
  3959. $web = Website::where('id', $data['website_id'])->first('id');
  3960. if (empty($web)) {
  3961. return Result::error("该网站不存在", 0);
  3962. }
  3963. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3964. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3965. return Result::error("用户暂无权限!", 0);
  3966. }
  3967. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3968. $result = JobRecruiting::where('website_id', $data['website_id'])
  3969. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3970. $query->where('user_id', $user['id']);
  3971. })
  3972. ->where('status', 1)
  3973. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3974. ->orderBy('updated_at', 'desc')
  3975. ->limit($data['pageSize'])
  3976. ->get();
  3977. if (empty($result)) {
  3978. return Result::error("暂无相关职位信息", 0);
  3979. }
  3980. return Result::success($result);
  3981. }
  3982. /**
  3983. * c端 - 验证路由
  3984. * @param array $data
  3985. * @return array
  3986. */
  3987. /**
  3988. * c端 - 验证路由
  3989. * @param array $data
  3990. * @return array
  3991. */
  3992. public function checkWebsiteRoute(array $data): array
  3993. {
  3994. // 测试001111111222
  3995. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3996. if (empty($web)) {
  3997. return Result::error("该网站不存在", 0);
  3998. } elseif ($web['status'] != 1) {
  3999. return Result::error("网站已经关闭", 0);
  4000. }
  4001. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4002. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4003. // 验证路由是否存在
  4004. if (empty($whiteRouterInfo)) {
  4005. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4006. }
  4007. if (!empty($whiteRouterInfo)) {
  4008. return Result::success($whiteRouterInfo->toArray());
  4009. }
  4010. }
  4011. // 验证栏目路由
  4012. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4013. ->where('path', $data['all_route'])
  4014. ->get()->all();
  4015. if (count($last_category) == 0) {
  4016. return Result::error("该栏目不存在", 0);
  4017. }
  4018. if (count($last_category) > 1) {
  4019. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4020. }
  4021. if (count($last_category) == 1) {
  4022. $last_category = $last_category[0];
  4023. }
  4024. // return Result::success($last_category);
  4025. if (isset($data['id']) && !empty($data['id'])) {
  4026. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4027. switch ($last_category['type']) {
  4028. case 1:
  4029. // 文章
  4030. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4031. $article = Article::where('status', 1)
  4032. ->where('id', $data['id'])
  4033. ->where(function ($query) use ($data) {
  4034. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4035. ->orWhereNull("ignore_ids");
  4036. })
  4037. ->first(['catid']);
  4038. if (empty($article)) {
  4039. return Result::error("该文章不存在", 0);
  4040. }
  4041. // return Result::success($article);
  4042. break;
  4043. case 2:
  4044. // 商品
  4045. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4046. $article = Good::where('website_id', $data['website_id'])
  4047. ->where('status', 2)
  4048. ->where('id', $data['id'])
  4049. ->first(['cat_arr_id']);
  4050. if (empty($article)) {
  4051. return Result::error("该商品不存在", 0);
  4052. }
  4053. break;
  4054. case 3:
  4055. // 书刊信息
  4056. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4057. $article = Book::where('website_id', $data['website_id'])
  4058. ->where('status', 2)
  4059. ->where('id', $data['id'])
  4060. ->first(['id', 'cat_arr_id']);
  4061. if (empty($article)) {
  4062. return Result::error("该书刊不存在", 0);
  4063. }
  4064. break;
  4065. case 4:
  4066. // 招聘
  4067. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4068. $article = JobRecruiting::where('website_id', $data['website_id'])
  4069. ->where('status', 1)
  4070. ->where('id', $data['id'])
  4071. ->first(['cat_arr_id']);
  4072. if (empty($article)) {
  4073. return Result::error("该招聘不存在", 0);
  4074. }
  4075. break;
  4076. case 5:
  4077. // 求职
  4078. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4079. $article = JobHunting::where('website_id', $data['website_id'])
  4080. ->where('status', 2)
  4081. ->where('id', $data['id'])
  4082. ->first(['cat_arr_id']);
  4083. if (empty($article)) {
  4084. return Result::error("该求职不存在", 0);
  4085. }
  4086. break;
  4087. case 6:
  4088. // 企业
  4089. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4090. $article = Company::
  4091. // where('website_id', $data['website_id'])
  4092. // ->
  4093. where('status', 1)
  4094. ->where('id', $data['id'])
  4095. ->first(['cat_arr_id']);
  4096. if (empty($article)) {
  4097. return Result::error("该企业不存在", 0);
  4098. }
  4099. break;
  4100. case 7:
  4101. // 项目
  4102. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4103. $article = Project::where('website_id', $data['website_id'])
  4104. ->where('status', 1)
  4105. ->where('id', $data['id'])
  4106. ->first(['cat_arr_id']);
  4107. if (empty($article)) {
  4108. return Result::error("该项目不存在", 0);
  4109. }
  4110. break;
  4111. default:
  4112. return Result::error("该数据不存在", 0);
  4113. break;
  4114. }
  4115. // return Result::success($article);
  4116. // $catid =0 ;
  4117. if (!isset($article['cat_arr_id'])) {
  4118. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4119. } else {
  4120. $catidArray = json_decode($article['cat_arr_id'], true);
  4121. $catid = !empty($catidArray) ? end($catidArray) : null;
  4122. }
  4123. // return Result::success($catid);
  4124. // // return Result::success($article['cat_arr_id']);
  4125. if (empty($catid)) {
  4126. return Result::error("该栏目路径不存在", 0);
  4127. }
  4128. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4129. ->where('category_id', $catid)
  4130. ->first('path');
  4131. }
  4132. // else{
  4133. // // if ($last_category['pid'] != 0) {
  4134. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4135. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4136. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4137. // ->where('category_id',$catid)
  4138. // ->where('path',$data['all_route'])
  4139. // ->first('path');
  4140. // // } else {
  4141. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4142. // // }
  4143. // }
  4144. // return Result::success($path);
  4145. if (!empty($path) && $path['path'] != $data['all_route']) {
  4146. return Result::error('非法路径!');
  4147. } else {
  4148. return Result::success($last_category['path']);
  4149. }
  4150. }
  4151. /**
  4152. * 招工招聘 - 获取推荐职位
  4153. * @param array $data
  4154. * @return array
  4155. */
  4156. public function getWebsiteLevelJob(array $data): array
  4157. {
  4158. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4159. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4160. ->where('job_recruiting.status', 1)
  4161. ->where('job_level', $data['job_level'])
  4162. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4163. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4164. ->orderBy('job_recruiting.updated_at', 'desc')
  4165. ->limit($data['pageSize'])
  4166. ->get();
  4167. $web = ['website_id' => $data['website_id']];
  4168. if (!empty($job)) {
  4169. $result = $this->processJob($job, $web);
  4170. }
  4171. if (empty($result)) {
  4172. return Result::error("暂无相关职位信息", 0);
  4173. }
  4174. return Result::success($result);
  4175. }
  4176. /**
  4177. * 验证导航名称是否重复
  4178. * @return void
  4179. */
  4180. //20250226 产品列表
  4181. public function getGoodList(array $data): array
  4182. {
  4183. var_dump($data, '---------1-2--');
  4184. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4185. unset($data['user_type_id']);
  4186. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4187. $where = [];
  4188. if ($type_id != '10000') {
  4189. $where = [
  4190. 'good.user_id' => $user_id,
  4191. ];
  4192. }
  4193. //类型
  4194. if (isset($data['type_id']) && $data['type_id']) {
  4195. $where['good.type_id'] = $data['type_id'];
  4196. }
  4197. //名称
  4198. if (isset($data['name']) && $data['name']) {
  4199. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4200. }
  4201. //status
  4202. if (isset($data['status']) && $data['status'] != '') {
  4203. $where['good.status'] = $data['status'];
  4204. }
  4205. //status1
  4206. // if (isset($data['status1']) && $data['status1'] == 1) {
  4207. // $status1 = 1;
  4208. // }
  4209. $where1 = [];
  4210. //website_id
  4211. // if (isset($data['website_id']) && $data['website_id']) {
  4212. // $where1 = [
  4213. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4214. // ];
  4215. // }
  4216. // website_name
  4217. if (isset($data['website_name']) && $data['website_name']) {
  4218. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4219. }
  4220. // catid
  4221. if (isset($data['category_name']) && $data['category_name']) {
  4222. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4223. }
  4224. // $result = Good::where($where)
  4225. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4226. var_dump($where, '---------1---');
  4227. $result = Good::where($where)
  4228. ->when(!empty($where1), function ($query) use ($where1) {
  4229. return $query->where($where1);
  4230. })
  4231. //status 1待审核2已审核3已拒绝
  4232. ->when(isset($data['status1']), function ($query) {
  4233. return $query->whereIn('good.status', [1, 3]);
  4234. })
  4235. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4236. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4237. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4238. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4239. ->orderBy("updated_at", "desc")
  4240. ->limit($data['page_size'])
  4241. ->offset(($data['page'] - 1) * $data['page_size'])
  4242. ->get();
  4243. $count = Good::where($where)
  4244. ->when(!empty($where1), function ($query) use ($where1) {
  4245. return $query->where($where1);
  4246. })
  4247. //status 1待审核2已审核3已拒绝
  4248. ->when(isset($data['status1']), function ($query) {
  4249. return $query->whereIn('good.status', [1, 3]);
  4250. })
  4251. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4252. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4253. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4254. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4255. ->orderBy("updated_at", "desc")->count();
  4256. $data = [
  4257. 'rows' => $result->toArray(),
  4258. 'count' => $count,
  4259. ];
  4260. if (empty($result)) {
  4261. return Result::error("此栏目暂无相关产品", 0);
  4262. }
  4263. return Result::success($data);
  4264. }
  4265. public function getGoodInfo(array $data): array
  4266. {
  4267. $result = Good::where('id', $data['id'])->first();
  4268. if (empty($result)) {
  4269. return Result::error("此产品不存在", 0);
  4270. }
  4271. return Result::success($result);
  4272. }
  4273. public function addGood(array $data): array
  4274. {
  4275. // unset($data['city_arr_id']);
  4276. // unset($data['cat_arr_id']);
  4277. $data['city_id'] = end($data['city_arr_id']);
  4278. $data['catid'] = end($data['cat_arr_id']);
  4279. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4280. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4281. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4282. unset($data['imgUrl']); //大小写
  4283. if (isset($data['price']) && $data['price'] == '') {
  4284. $data['price'] = 0;
  4285. }
  4286. if ($data['imgurl'] == '') {
  4287. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4288. preg_match_all($reg, $data['detail'], $matches);
  4289. if (isset($matches[1][0])) {
  4290. //截取varchar240
  4291. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4292. }
  4293. }
  4294. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4295. //提取标题+内容中的关键词
  4296. $data['keyword'] = $data['name'];
  4297. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4298. Jieba::init(); // 初始化 jieba-php
  4299. Finalseg::init();
  4300. $segList = Jieba::cut($data['keyword']);
  4301. $segList1 = array_slice($segList, 0, 8);
  4302. $data['keyword'] = implode(',', $segList1);
  4303. }
  4304. if ($data['description'] == '') {
  4305. //提取内容中的描述
  4306. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4307. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4308. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4309. }
  4310. if ($data['status'] == 1) {
  4311. $this->sendMessage([
  4312. 'talk_type' => 200,
  4313. 'title' => $data['name'],
  4314. 'content' => '提交了审核',
  4315. 'messageType' => 3,
  4316. ]);
  4317. }
  4318. $result = Good::insert($data);
  4319. if (empty($result)) {
  4320. return Result::error("添加失败", 0);
  4321. }
  4322. return Result::success($result);
  4323. }
  4324. public function updateGood(array $data): array
  4325. {
  4326. $data['city_id'] = end($data['city_arr_id']);
  4327. $data['catid'] = end($data['cat_arr_id']);
  4328. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4329. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4330. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4331. //设置东八区
  4332. date_default_timezone_set('Asia/Shanghai');
  4333. $data['updated_at'] = date('Y-m-d H:i:s');
  4334. if (isset($data['price']) && $data['price'] == '') {
  4335. $data['price'] = 0;
  4336. }
  4337. if ($data['imgurl'] == '') {
  4338. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4339. preg_match_all($reg, $data['detail'], $matches);
  4340. if (isset($matches[1][0])) {
  4341. //截取varchar240
  4342. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4343. }
  4344. }
  4345. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4346. //提取标题+内容中的关键词
  4347. $data['keyword'] = $data['name'];
  4348. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4349. Jieba::init(); // 初始化 jieba-php
  4350. Finalseg::init();
  4351. $segList = Jieba::cut($data['keyword']);
  4352. $segList1 = array_slice($segList, 0, 8);
  4353. $data['keyword'] = implode(',', $segList1);
  4354. }
  4355. if ($data['description'] == '') {
  4356. //提取内容中的描述
  4357. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4358. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4359. }
  4360. if ($data['status'] == 1) {
  4361. $this->sendMessage([
  4362. 'talk_type' => 200,
  4363. 'title' => $data['name'],
  4364. 'content' => '提交了审核',
  4365. 'messageType' => 3,
  4366. ]);
  4367. }
  4368. $result = Good::where('id', $data['id'])->update($data);
  4369. if (empty($result)) {
  4370. return Result::error("更新失败", 0);
  4371. }
  4372. return Result::success($result);
  4373. }
  4374. public function delGood(array $data): array
  4375. {
  4376. $result = Good::where('id', $data['id'])->delete();
  4377. if (empty($result)) {
  4378. return Result::error("删除失败", 0);
  4379. }
  4380. return Result::success($result);
  4381. }
  4382. //20250226 产品列表
  4383. //20250306 求职信息
  4384. public function getJobHuntingList(array $data): array
  4385. {
  4386. $where = [];
  4387. if (isset($data['username']) && !empty($data['username'])) {
  4388. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4389. }
  4390. //status 1待审核2已审核3已拒绝
  4391. if (isset($data['status']) && $data['status'] != '') {
  4392. $where = [
  4393. 'job_hunting.status' => $data['status'],
  4394. ];
  4395. }
  4396. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4397. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4398. unset($data['type_id']);
  4399. if ($type_id != '10000') {
  4400. $where[] = ['job_hunting.user_id', '=', $user_id];
  4401. }
  4402. $result = JobHunting::where($where)
  4403. ->when(!empty($data['status1']), function ($query) use ($data) {
  4404. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4405. })
  4406. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4407. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4408. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4409. ->orderBy("updated_at", "desc")
  4410. ->limit($data['page_size'])
  4411. ->offset(($data['page'] - 1) * $data['page_size'])
  4412. ->get();
  4413. if (empty($result)) {
  4414. return Result::error("查询失败", 0);
  4415. }
  4416. $count = JobHunting::where($where)
  4417. ->when(!empty($data['status1']), function ($query) use ($data) {
  4418. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4419. })
  4420. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4421. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4422. ->count();
  4423. $data = [
  4424. 'rows' => $result->toArray(),
  4425. 'count' => $count,
  4426. ];
  4427. return Result::success($data);
  4428. }
  4429. public function getJobHuntingApply(array $data): array
  4430. {
  4431. var_dump($data, '-----------------test--------1-');
  4432. $where = [];
  4433. if (isset($data['username']) && !empty($data['username'])) {
  4434. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4435. }
  4436. if (isset($data['salary']) && !empty($data['salary'])) {
  4437. $where[] = [
  4438. 'job_hunting.salary',
  4439. '=',
  4440. $data['salary'],
  4441. ];
  4442. }
  4443. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4444. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4445. unset($data['type_id']);
  4446. if ($type_id != '10000') {
  4447. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4448. }
  4449. var_dump($where, '-----------------test---------');
  4450. $result = jobApply::where($where)
  4451. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4452. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4453. // })
  4454. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4455. ->where('job_enum.egroup', '=', 'income')
  4456. ->where('job_hunting.status', 2) //已审核
  4457. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4458. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4459. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4460. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4461. //职位----是申请职位
  4462. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4463. ->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')
  4464. ->orderBy("job_hunting.updated_at", "desc")
  4465. ->limit($data['page_size'])
  4466. ->offset(($data['page'] - 1) * $data['page_size'])
  4467. ->get();
  4468. if (empty($result)) {
  4469. return Result::error("查询失败", 0);
  4470. }
  4471. $count = jobApply::where($where)
  4472. ->where('job_enum.egroup', '=', 'income')
  4473. ->where('job_hunting.status', 2) //已审核
  4474. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4475. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4476. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4477. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4478. //职位----是申请职位
  4479. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4480. ->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')
  4481. ->count();
  4482. $data = [
  4483. 'rows' => $result->toArray(),
  4484. 'count' => $count,
  4485. ];
  4486. return Result::success($data);
  4487. }
  4488. public function addJobHunting(array $data): array
  4489. {
  4490. date_default_timezone_set('Asia/Shanghai');
  4491. unset($data['company_name']);
  4492. unset($data['job_industry']);
  4493. unset($data['job_name']);
  4494. unset($data['department']);
  4495. unset($data['job_timeList']);
  4496. unset($data['job_content']);
  4497. unset($data['job_typename']); //不知道这是啥,
  4498. $data['created_at'] = date('Y-m-d H:i:s');
  4499. $data['updated_at'] = date('Y-m-d H:i:s');
  4500. //根据用户 user_id 只能添加一次
  4501. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4502. if (!empty($result)) {
  4503. return Result::error("您已添加过求职信息", 0);
  4504. }
  4505. var_dump($result, '-----------------test---------');
  4506. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4507. if (is_string($data['city_arr_id'])) {
  4508. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4509. $cityArr = json_decode($data['city_arr_id'], true);
  4510. // 确保 $cityArr 是数组
  4511. if (is_array($cityArr)) {
  4512. $data['city_id'] = end($cityArr);
  4513. }
  4514. } else {
  4515. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4516. if (is_array($data['city_arr_id'])) {
  4517. $data['city_id'] = end($data['city_arr_id']);
  4518. }
  4519. }
  4520. }
  4521. // 处理求职所绑定栏目
  4522. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4523. if (is_string($data['cat_arr_id'])) {
  4524. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4525. // 先清理可能存在的无效 JSON 字符
  4526. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4527. $catArr = json_decode($cleanedCatArrStr, true);
  4528. // 检查 JSON 解码是否成功且结果是数组
  4529. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4530. $data['catid'] = end($catArr);
  4531. }
  4532. } else {
  4533. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4534. if (is_array($data['cat_arr_id'])) {
  4535. $data['catid'] = end($data['cat_arr_id']);
  4536. }
  4537. }
  4538. }
  4539. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4540. $this->sendMessage([
  4541. 'talk_type' => 600,
  4542. 'title' => $data['name'],
  4543. 'content' => '提交了审核',
  4544. 'messageType' => 11,
  4545. ]);
  4546. }
  4547. $result = JobHunting::create($data);
  4548. if (empty($result)) {
  4549. return Result::error("添加失败", 0);
  4550. }
  4551. return Result::success($result);
  4552. }
  4553. public function delJobHunting(array $data): array
  4554. {
  4555. $result = JobHunting::where('id', $data['id'])->delete();
  4556. if (empty($result)) {
  4557. return Result::error("删除失败", 0);
  4558. }
  4559. return Result::success($result);
  4560. }
  4561. public function updateJobHunting(array $data): array
  4562. {
  4563. //设置东八区
  4564. date_default_timezone_set('Asia/Shanghai');
  4565. unset($data['company_name']);
  4566. unset($data['job_industry']);
  4567. unset($data['job_name']);
  4568. unset($data['department']);
  4569. unset($data['job_timeList']);
  4570. unset($data['job_content']);
  4571. unset($data['job_typename']); //不知道这是啥,
  4572. $data['created_at'] = date('Y-m-d H:i:s');
  4573. $data['updated_at'] = date('Y-m-d H:i:s');
  4574. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4575. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4576. $cityArr = json_decode($data['city_arr_id'], true);
  4577. $data['city_id'] = end($cityArr);
  4578. } else {
  4579. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4580. $data['city_id'] = end($data['city_arr_id']);
  4581. }
  4582. // 处理求职所绑定栏目
  4583. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4584. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4585. $catArr = json_decode($data['cat_arr_id'], true);
  4586. $data['catid'] = end($catArr);
  4587. } else {
  4588. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4589. $data['catid'] = end($data['cat_arr_id']);
  4590. }
  4591. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4592. $this->sendMessage([
  4593. 'talk_type' => 600,
  4594. 'title' => $data['name'],
  4595. 'content' => '提交了审核',
  4596. 'messageType' => 11,
  4597. ]);
  4598. }
  4599. $result = JobHunting::where('id', $data['id'])->update($data);
  4600. if (empty($result)) {
  4601. return Result::error("更新失败", 0);
  4602. }
  4603. return Result::success($result);
  4604. }
  4605. public function getJobHuntingInfo(array $data): array
  4606. {
  4607. $result = JobHunting::where('id', $data['id'])->first();
  4608. if (empty($result)) {
  4609. return Result::error("查询失败", 0);
  4610. }
  4611. return Result::success($result);
  4612. }
  4613. public function getJobHuntingData(array $data): array
  4614. {
  4615. $jobEnum = JobEnum::get();
  4616. $jobIndustry = JobIndustry::get();
  4617. $jobNature = JobNature::get();
  4618. $jobPosition = JobPosition::get();
  4619. $data = [
  4620. 'jobEnum' => $jobEnum,
  4621. 'jobIndustry' => $jobIndustry,
  4622. 'jobNature' => $jobNature,
  4623. 'jobPosition' => $jobPosition,
  4624. ];
  4625. return Result::success($data);
  4626. }
  4627. public function delJobHuntingInfo(array $data): array
  4628. {
  4629. $result = JobHunting::where('id', $data['id'])->delete();
  4630. return Result::success();
  4631. }
  4632. //20250324 通知,公告,消息
  4633. public function delNotice(array $data): array
  4634. {
  4635. $result = Notice::where('id', $data['id'])->delete();
  4636. if ($result) {
  4637. return Result::success();
  4638. } else {
  4639. return Result::error("删除失败", 0);
  4640. }
  4641. }
  4642. public function getNoticeInfo(array $data): array
  4643. {
  4644. $result = Notice::where('id', $data['id'])->first();
  4645. // var_dump($result['re_user_ids'], '--------------------');
  4646. if (empty($result)) {
  4647. return Result::error("查询失败", 0);
  4648. }
  4649. return Result::success($result);
  4650. }
  4651. public function readNotice(array $data): array
  4652. {
  4653. $result = Notice::where('id', $data['id'])->first();
  4654. // var_dump($result['re_user_ids'], '--------------------');
  4655. if (empty($result)) {
  4656. return Result::error("查询失败", 0);
  4657. }
  4658. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4659. $re_user_ids = json_decode($result['re_user_ids'], true);
  4660. var_dump($re_user_ids, '--------------1---test---------');
  4661. var_dump($data, '--------------1---test---------');
  4662. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4663. //如果已经存在,就不再添加
  4664. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4665. $read_id = json_decode($result['read_id'], true);
  4666. if (!is_array($read_id)) {
  4667. $read_id = [];
  4668. }
  4669. if (!in_array($data['user_id'], $read_id)) {
  4670. $read_id[] = $data['user_id'];
  4671. $result['read_id'] = json_encode($read_id);
  4672. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4673. }
  4674. } else {
  4675. //如果不存在,就添加
  4676. $result['read_id'] = json_encode([$data['user_id']]);
  4677. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4678. }
  4679. }
  4680. return Result::success($result);
  4681. }
  4682. public function addNotice(array $data): array
  4683. {
  4684. date_default_timezone_set('Asia/Shanghai');
  4685. $data['created_at'] = date('Y-m-d H:i:s');
  4686. $data['updated_at'] = date('Y-m-d H:i:s');
  4687. // $data['level'] = "1,2,3,4,5";
  4688. $level = json_decode($data['level'], true);
  4689. $user_id = UserInfo::
  4690. //city_id不是null
  4691. whereNotNull('city_id')
  4692. ->whereNotNull('department_id')
  4693. ->where(function ($query) use ($data) {
  4694. $query->where(function ($subQuery) use ($data) {
  4695. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4696. });
  4697. })
  4698. ->where(function ($query) use ($data) {
  4699. $query->where(function ($subQuery) use ($data) {
  4700. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4701. });
  4702. })
  4703. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4704. $query->whereIn('level', $level);
  4705. })
  4706. ->pluck('user_id')->toArray();
  4707. $user_id = array_unique($user_id);
  4708. $chat_ids = $user_id;
  4709. $user_id = json_encode($user_id);
  4710. $data['re_user_ids'] = $user_id;
  4711. $this->sendMessage([
  4712. 'talk_type' => 700,
  4713. 'title' => $data['title'],
  4714. 'content' => '提交了审核',
  4715. 'messageType' => 5,
  4716. ]);
  4717. $result = Notice::insertGetId($data);
  4718. if (empty($result)) {
  4719. return Result::error("添加失败", 0);
  4720. }
  4721. return Result::success($result);
  4722. }
  4723. public function updateNotice(array $data): array
  4724. {
  4725. date_default_timezone_set('Asia/Shanghai');
  4726. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4727. $user_id = UserInfo::
  4728. //city_id不是null
  4729. whereNotNull('city_id')
  4730. ->whereNotNull('department_id')
  4731. ->where(function ($query) use ($data) {
  4732. $query->where(function ($subQuery) use ($data) {
  4733. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4734. });
  4735. })
  4736. ->where(function ($query) use ($data) {
  4737. $query->where(function ($subQuery) use ($data) {
  4738. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4739. });
  4740. })
  4741. ->pluck('user_id')->toArray();
  4742. $user_id = array_unique($user_id);
  4743. $user_id = json_encode($user_id);
  4744. $data['re_user_ids'] = $user_id;
  4745. $data['updated_at'] = date('Y-m-d H:i:s');
  4746. $this->sendMessage([
  4747. 'talk_type' => 700,
  4748. 'title' => $data['title'],
  4749. 'content' => '提交了审核',
  4750. 'messageType' => 5,
  4751. ]);
  4752. $result = Notice::where('id', $data['id'])->update($data);
  4753. return Result::success($result);
  4754. }
  4755. public function getNoticeList(array $data): array
  4756. {
  4757. $where = [];
  4758. //title
  4759. if (isset($data['title']) && !empty($data['title'])) {
  4760. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4761. }
  4762. //level
  4763. if (isset($data['level']) && !empty($data['level'])) {
  4764. $where[] = ['notice.level', '=', $data['level']];
  4765. }
  4766. //status
  4767. if (isset($data['status']) && !empty($data['status'])) {
  4768. $where[] = ['notice.status', '=', $data['status']];
  4769. }
  4770. //type
  4771. if (isset($data['type']) && !empty($data['type'])) {
  4772. $where[] = ['notice.type', '=', $data['type']];
  4773. }
  4774. var_dump($data, '------------11111-2----test---------');
  4775. if ($data['type_id'] == 10000) {
  4776. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4777. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4778. })
  4779. ->where($where)
  4780. ->orderBy('updated_at', 'desc')
  4781. ->limit($data['page_size'])
  4782. ->offset(($data['page'] - 1) * $data['page_size'])
  4783. ->get();
  4784. $total = 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. ->count();
  4790. } else {
  4791. $result = Notice::where($where)
  4792. // ->where('user_id', $data['user_id'])
  4793. ->Where(function ($query) use ($data) {
  4794. $query->Where(function ($q) use ($data) {
  4795. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4796. ->orWhere('notice.user_id', $data['user_id']);
  4797. });
  4798. })
  4799. ->when(!empty($data['status1']), function ($query) use ($data) {
  4800. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4801. })
  4802. ->orderBy('updated_at', 'desc')
  4803. ->limit($data['page_size'])
  4804. ->offset(($data['page'] - 1) * $data['page_size'])
  4805. ->get();
  4806. $total = Notice::where($where)
  4807. ->when(!empty($data['status1']), function ($query) use ($data) {
  4808. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4809. })
  4810. // ->where('user_id', $data['user_id'])
  4811. ->Where(function ($query) use ($data) {
  4812. $query->Where(function ($q) use ($data) {
  4813. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4814. ->orWhere('notice.user_id', $data['user_id']);
  4815. });
  4816. })
  4817. ->count();
  4818. }
  4819. if (empty($result)) {
  4820. return Result::error("查询失败", 0);
  4821. }
  4822. $data = [
  4823. 'rows' => $result,
  4824. 'count' => $total,
  4825. ];
  4826. return Result::success($data);
  4827. }
  4828. public function noticeList(array $data): array
  4829. {
  4830. $where = [];
  4831. //title
  4832. if (isset($data['title']) && !empty($data['title'])) {
  4833. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4834. }
  4835. //level
  4836. if (isset($data['level']) && !empty($data['level'])) {
  4837. $where[] = ['notice.level', '=', $data['level']];
  4838. }
  4839. //status
  4840. if (isset($data['status']) && !empty($data['status'])) {
  4841. $where[] = ['notice.status', '=', $data['status']];
  4842. }
  4843. //type
  4844. if (isset($data['type']) && !empty($data['type'])) {
  4845. $where[] = ['notice.type', '=', $data['type']];
  4846. }
  4847. var_dump($data, '------------11111-2----test---------');
  4848. if ($data['type_id'] == 10000) {
  4849. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4850. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4851. })
  4852. ->where($where)
  4853. ->orderBy('updated_at', 'desc')
  4854. ->limit($data['page_size'])
  4855. ->offset(($data['page'] - 1) * $data['page_size'])
  4856. ->get();
  4857. $total = 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. ->count();
  4863. } else {
  4864. $result = Notice::where($where)
  4865. // ->where('user_id', $data['user_id'])
  4866. ->Where(function ($query) use ($data) {
  4867. $query->Where(function ($q) use ($data) {
  4868. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4869. ->orWhere('notice.user_id', $data['user_id']);
  4870. });
  4871. })
  4872. ->when(!empty($data['status1']), function ($query) use ($data) {
  4873. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4874. })
  4875. ->orderBy('updated_at', 'desc')
  4876. ->limit($data['page_size'])
  4877. ->offset(($data['page'] - 1) * $data['page_size'])
  4878. ->get();
  4879. $total = Notice::where($where)
  4880. ->when(!empty($data['status1']), function ($query) use ($data) {
  4881. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4882. })
  4883. // ->where('user_id', $data['user_id'])
  4884. ->Where(function ($query) use ($data) {
  4885. $query->Where(function ($q) use ($data) {
  4886. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4887. ->orWhere('notice.user_id', $data['user_id']);
  4888. });
  4889. })
  4890. ->count();
  4891. }
  4892. if (empty($result)) {
  4893. return Result::error("查询失败", 0);
  4894. }
  4895. $data = [
  4896. 'rows' => $result,
  4897. 'count' => $total,
  4898. ];
  4899. return Result::success($data);
  4900. }
  4901. public function getNoticeDetail(array $data): array
  4902. {
  4903. $result = Notice::where('id', $data['id'])->first();
  4904. if (empty($result)) {
  4905. return Result::error("查询失败", 0);
  4906. }
  4907. return Result::success($result);
  4908. }
  4909. public function deleteNotice(array $data): array
  4910. {
  4911. $notice = Notice::where('id', $data['id'])->first();
  4912. if (empty($notice)) {
  4913. return Result::error("删除失败", 0);
  4914. }
  4915. $chat_group_id = $notice->group_id;
  4916. if ($chat_group_id) {
  4917. //删除群聊
  4918. ChatGroups::where('id', $chat_group_id)->delete();
  4919. //删除群成员
  4920. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4921. //删除群聊记录
  4922. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4923. }
  4924. $result = Notice::where('id', $data['id'])->delete();
  4925. return Result::success($result);
  4926. }
  4927. public function complaintList(array $data): array
  4928. {
  4929. var_dump($data, '---------1---------');
  4930. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4931. unset($data['type_id']);
  4932. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4933. $where = [];
  4934. if ($type_id != 10000 && empty($data['deal_user'])) {
  4935. // $where['complaint.user_id'] = $user_id;
  4936. }
  4937. if (!empty($data['title'])) {
  4938. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4939. }
  4940. if (!empty($data['department_id'])) {
  4941. $where['complaint.department_id'] = $data['department_id'];
  4942. }
  4943. if (!empty($data['deal'])) {
  4944. $where['complaint.deal'] = $data['deal'];
  4945. }
  4946. if (!empty($data['status'])) {
  4947. $where['complaint.status'] = $data['status'];
  4948. }
  4949. var_dump(!empty($data['deal_user']), '----------1');
  4950. var_dump($where, '----------2');
  4951. $result = Complaint::where($where)
  4952. ->when(!empty($data['status1']), function ($query) use ($data) {
  4953. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4954. })
  4955. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4956. //json re_user_ids data[user_id]是不是在里面
  4957. $query->Where(function ($q) use ($data) {
  4958. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4959. ->where('complaint.status', 2);
  4960. });
  4961. })
  4962. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4963. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4964. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4965. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4966. ->orderBy('updated_at', 'desc')
  4967. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4968. //sql输出
  4969. if (empty($result)) {
  4970. return Result::error("暂无投诉信息", 0);
  4971. }
  4972. // 取出数据
  4973. $rows = $result->items();
  4974. $count = $result->total();
  4975. $responseData = [
  4976. 'rows' => $rows,
  4977. 'count' => $count,
  4978. ];
  4979. return Result::success($responseData);
  4980. }
  4981. public function getComplaintList(array $data): array
  4982. {
  4983. var_dump($data, '00000001000000000000');
  4984. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4985. unset($data['type_id']);
  4986. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4987. $where = [];
  4988. if ($type_id != 10000 && empty($data['deal_user'])) {
  4989. $where['complaint.user_id'] = $user_id;
  4990. }
  4991. if (!empty($data['title'])) {
  4992. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4993. }
  4994. if (!empty($data['department_id'])) {
  4995. $where['complaint.department_id'] = $data['department_id'];
  4996. }
  4997. if (!empty($data['deal'])) {
  4998. $where['complaint.deal'] = $data['deal'];
  4999. }
  5000. if (!empty($data['status'])) {
  5001. $where['complaint.status'] = $data['status'];
  5002. }
  5003. var_dump(!empty($data['deal_user']), '----------1');
  5004. var_dump($where, '----------2');
  5005. $result = Complaint::where($where)
  5006. ->when(!empty($data['status1']), function ($query) use ($data) {
  5007. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5008. })
  5009. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5010. // //json re_user_ids data[user_id]是不是在里面
  5011. // $query->Where(function ($q) use ($data) {
  5012. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5013. // ->where('complaint.status', 2);
  5014. // });
  5015. // })
  5016. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5017. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5018. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5019. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5020. ->orderBy('updated_at', 'desc')
  5021. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5022. //sql输出
  5023. if (empty($result)) {
  5024. return Result::error("暂无投诉信息", 0);
  5025. }
  5026. // 取出数据
  5027. $rows = $result->items();
  5028. $count = $result->total();
  5029. $responseData = [
  5030. 'rows' => $rows,
  5031. 'count' => $count,
  5032. ];
  5033. return Result::success($responseData);
  5034. }
  5035. public function getComplaintInfo(array $data): array
  5036. {
  5037. $result = Complaint::where('id', $data['id'])->first();
  5038. if (empty($result)) {
  5039. return Result::error("查询失败", 0);
  5040. }
  5041. return Result::success($result);
  5042. }
  5043. public function readComplaint(array $data): array
  5044. {
  5045. $result = Complaint::where('id', $data['id'])->first();
  5046. if (empty($result)) {
  5047. return Result::error("查询失败", 0);
  5048. }
  5049. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5050. $re_user_ids = json_decode($result['re_user_ids'], true);
  5051. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5052. //如果已经存在,就不再添加
  5053. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5054. $read_id = json_decode($result['read_id'], true);
  5055. if (!is_array($read_id)) {
  5056. $read_id = [];
  5057. }
  5058. if (!in_array($data['user_id'], $read_id)) {
  5059. $read_id[] = $data['user_id'];
  5060. $result['read_id'] = json_encode($read_id);
  5061. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5062. }
  5063. } else {
  5064. //如果不存在,就添加
  5065. $result['read_id'] = json_encode([$data['user_id']]);
  5066. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5067. }
  5068. }
  5069. return Result::success($result);
  5070. }
  5071. public function addComplaint(array $data): array
  5072. {
  5073. date_default_timezone_set('Asia/Shanghai');
  5074. $data['created_at'] = date('Y-m-d H:i:s');
  5075. $data['updated_at'] = date('Y-m-d H:i:s');
  5076. $this->sendMessage([
  5077. 'talk_type' => 800,
  5078. 'title' => $data['title'],
  5079. 'content' => '提交了审核',
  5080. 'messageType' => 6,
  5081. ]);
  5082. $result = Complaint::create($data);
  5083. return Result::success($result);
  5084. }
  5085. public function updateComplaint(array $data): array
  5086. {
  5087. date_default_timezone_set('Asia/Shanghai');
  5088. $data['updated_at'] = date('Y-m-d H:i:s');
  5089. $user_id = $data['user_id'] ?? 0;
  5090. $type_id = $data['type_id'] ?? 0;
  5091. unset($data['user_id']);
  5092. unset($data['type_id']);
  5093. $this->sendMessage([
  5094. 'talk_type' => 800,
  5095. 'title' => $data['title'],
  5096. 'content' => '提交了审核',
  5097. 'messageType' => 6,
  5098. ]);
  5099. $result = Complaint::where('id', $data['id'])->update($data);
  5100. return Result::success($result);
  5101. }
  5102. public function deleteComplaint(array $data): array
  5103. {
  5104. $result = Complaint::where('id', $data['id'])->delete();
  5105. return Result::success($result);
  5106. }
  5107. public function getComplainInfo(array $data): array
  5108. {
  5109. $result = Complaint::where('id', $data['id'])->first();
  5110. if (empty($result)) {
  5111. return Result::error("查询失败", 0);
  5112. }
  5113. return Result::success($result);
  5114. }
  5115. public function updateComplaintStatus(array $data): array
  5116. {
  5117. date_default_timezone_set('Asia/Shanghai');
  5118. $data['updated_at'] = date('Y-m-d H:i:s');
  5119. $user_id = $data['user_id'] ?? 0;
  5120. $type_id = $data['type_id'] ?? 0;
  5121. unset($data['user_id']);
  5122. unset($data['type_id']);
  5123. //处理, 写入处理人
  5124. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5125. $data['real_deal_user'] = $user_id;
  5126. }
  5127. //如果是deal 23,则判断是不是处理人
  5128. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5129. $complaintInof = Complaint::where('id', $data['id'])
  5130. ->where('real_deal_user', $user_id)
  5131. ->first();
  5132. if (empty($complaintInof)) {
  5133. return Result::error("处理人错误", 0);
  5134. }
  5135. }
  5136. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5137. if ($data['status'] == 1) {
  5138. $this->sendMessage([
  5139. 'talk_type' => 800,
  5140. 'title' => $complaintInfo['title'],
  5141. 'content' => '提交了审核',
  5142. 'messageType' => 6,
  5143. ]);
  5144. }
  5145. if ($data['status'] == 2 && !isset($data['deal'])) {
  5146. $this->sendMessage([
  5147. 'talk_type' => 801,
  5148. 'title' => $complaintInfo['title'],
  5149. 'content' => '审核通过',
  5150. 'messageType' => 6,
  5151. 'user_id' => $complaintInfo['user_id'],
  5152. ]);
  5153. $this->sendMessage([
  5154. 'talk_type' => 802,
  5155. 'title' => $complaintInfo['title'],
  5156. 'content' => '待处理',
  5157. 'messageType' => 6,
  5158. 'user_id' => $complaintInfo['re_user_ids'],
  5159. ]);
  5160. }
  5161. if ($data['status'] == 3 && !isset($data['deal'])) {
  5162. $this->sendMessage([
  5163. 'talk_type' => 801,
  5164. 'title' => $complaintInfo['title'],
  5165. 'content' => '审核拒绝',
  5166. 'messageType' => 6,
  5167. 'user_id' => $complaintInfo['user_id'],
  5168. ]);
  5169. }
  5170. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5171. $this->sendMessage([
  5172. 'talk_type' => 802,
  5173. 'title' => $complaintInfo['title'],
  5174. 'content' => '处理中',
  5175. 'messageType' => 6,
  5176. 'user_id' => $complaintInfo['re_user_ids'],
  5177. ]);
  5178. }
  5179. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5180. $this->sendMessage([
  5181. 'talk_type' => 802,
  5182. 'title' => $complaintInfo['title'],
  5183. 'content' => '不予处理',
  5184. 'messageType' => 6,
  5185. 'user_id' => $complaintInfo['re_user_ids'],
  5186. ]);
  5187. }
  5188. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5189. $this->sendMessage([
  5190. 'talk_type' => 802,
  5191. 'title' => $complaintInfo['title'],
  5192. 'content' => '已完结',
  5193. 'messageType' => 6,
  5194. 'user_id' => $complaintInfo['re_user_ids'],
  5195. ]);
  5196. }
  5197. $result = complaint::where('id', $data['id'])->update($data);
  5198. return Result::success($result);
  5199. }
  5200. public function updateGoodStatus(array $data): array
  5201. {
  5202. $user_id = $data['user_id'] ?? 0;
  5203. $type_id = $data['type_id'] ?? 0;
  5204. unset($data['user_id']);
  5205. unset($data['type_id']);
  5206. $goodInfo = Good::where('id', $data['id'])->first();
  5207. if ($data['status'] == 2) {
  5208. $this->sendMessage([
  5209. 'talk_type' => 201,
  5210. 'title' => $goodInfo['name'],
  5211. 'content' => '审核通过',
  5212. 'messageType' => 3,
  5213. 'user_id' => $goodInfo['user_id'],
  5214. ]);
  5215. }
  5216. if ($data['status'] == 3) {
  5217. $this->sendMessage([
  5218. 'talk_type' => 201,
  5219. 'title' => $goodInfo['name'],
  5220. 'content' => '审核拒绝',
  5221. 'messageType' => 3,
  5222. 'user_id' => $goodInfo['user_id'],
  5223. ]);
  5224. }
  5225. if ($data['status'] == 1) {
  5226. $this->sendMessage([
  5227. 'talk_type' => 200,
  5228. 'title' => $goodInfo['name'],
  5229. 'content' => '提交了审核',
  5230. 'messageType' => 3,
  5231. ]);
  5232. }
  5233. $result = Good::where('id', $data['id'])->update($data);
  5234. return Result::success($result);
  5235. }
  5236. public function updateJobHuntingStatus(array $data): array
  5237. {
  5238. $user_id = $data['user_id'] ?? 0;
  5239. $type_id = $data['type_id'] ?? 0;
  5240. unset($data['user_id']);
  5241. unset($data['type_id']);
  5242. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5243. if ($data['status'] == 2) {
  5244. $this->sendMessage([
  5245. 'talk_type' => 601,
  5246. 'title' => $jogHuntingInfo['name'],
  5247. 'content' => '审核通过',
  5248. 'messageType' => 11,
  5249. 'user_id' => $jogHuntingInfo['user_id'],
  5250. ]);
  5251. }
  5252. if ($data['status'] == 3) {
  5253. $this->sendMessage([
  5254. 'talk_type' => 601,
  5255. 'title' => $jogHuntingInfo['name'],
  5256. 'content' => '审核拒绝',
  5257. 'messageType' => 11,
  5258. 'user_id' => $jogHuntingInfo['user_id'],
  5259. ]);
  5260. }
  5261. if ($data['status'] == 1) {
  5262. $this->sendMessage([
  5263. 'talk_type' => 600,
  5264. 'title' => $jogHuntingInfo['name'],
  5265. 'content' => '提交了审核',
  5266. 'messageType' => 11,
  5267. ]);
  5268. }
  5269. $result = JobHunting::where('id', $data['id'])->update($data);
  5270. return Result::success($result);
  5271. }
  5272. public function updateNoticeStatus(array $data): array
  5273. {
  5274. $user_id = $data['user_id'] ?? 0;
  5275. $type_id = $data['type_id'] ?? 0;
  5276. unset($data['user_id']);
  5277. unset($data['type_id']);
  5278. //查询公告
  5279. $notice = Notice::where('id', $data['id'])->first();
  5280. if (empty($notice)) {
  5281. return Result::error("公告不存在", 0);
  5282. }
  5283. //$chat_ids 去除掉$data['user_id']
  5284. $chat_ids = json_decode($notice['re_user_ids'], true);
  5285. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5286. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5287. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5288. //chat_group
  5289. $group_id = PublicData::uuid();
  5290. $groupData = [
  5291. 'id' => $group_id,
  5292. 'creator_id' => $notice['user_id'],
  5293. 'group_name' => $notice['group_name'] ?? '',
  5294. 'profile' => $notice['profile'] ?? 0,
  5295. ];
  5296. var_dump($groupData, '-----------------groupData-------');
  5297. $groupResult = ChatGroups::insertGetId($groupData);
  5298. var_dump($groupResult, '-----------------groupid-------');
  5299. $groupMemberData = [
  5300. 'id' => PublicData::uuid(),
  5301. 'user_id' => $notice['user_id'],
  5302. 'group_id' => $group_id,
  5303. 'leader' => 2,
  5304. ];
  5305. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5306. //插入群成员表
  5307. $groupMemberDataUser = [];
  5308. $chatData = [];
  5309. foreach ($chat_ids as $key => $value) {
  5310. $groupMemberDataUser[] = [
  5311. 'id' => PublicData::uuid(),
  5312. 'user_id' => $value,
  5313. 'group_id' => $group_id,
  5314. 'leader' => 1,
  5315. ];
  5316. $chatData[] = [
  5317. 'user_id' => $value,
  5318. 'msg_type' => 1,
  5319. 'receiver_id' => $group_id,
  5320. 'content' => '通过通知创建群聊',
  5321. 'group_receiver_id' => $notice['user_id'],
  5322. 'action' => 'recieved',
  5323. 'created_at' => date('Y-m-d H:i:s'),
  5324. ];
  5325. }
  5326. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5327. ChatGroupsMember::insert($groupMemberDataUser);
  5328. //插入一条管理员聊天记录
  5329. $chatData[] = [
  5330. 'user_id' => $notice['user_id'],
  5331. 'msg_type' => 1,
  5332. 'receiver_id' => $group_id,
  5333. 'content' => '通过通知创建群聊',
  5334. 'group_receiver_id' => $notice['user_id'],
  5335. 'action' => 'said',
  5336. 'created_at' => date('Y-m-d H:i:s'),
  5337. ];
  5338. var_dump($chatData, '-----------------chatData-------');
  5339. $chatResult = ChatRecords::insert($chatData);
  5340. //处理imp
  5341. $group = [
  5342. 'type' => 1,
  5343. 'name' => $notice['group_name'] ?? '',
  5344. 'profile' => '',
  5345. 'avatar' => '',
  5346. 'creator_id' => $notice['user_id'],
  5347. ];
  5348. $groupResult = GroupImp::insertGetId($group);
  5349. var_dump($groupResult, '获取imp group_id');
  5350. $groupMember = [
  5351. 'user_id' => $notice['user_id'],
  5352. 'group_id' => $groupResult,
  5353. 'leader' => 1,
  5354. 'join_time' => Date('Y-m-d H:i:s')
  5355. ];
  5356. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5357. $talk_session = [
  5358. 'user_id' => $notice['user_id'],
  5359. 'to_from_id' => $groupResult,
  5360. 'talk_mode' => 2,
  5361. 'created_at' => Date('Y-m-d H:i:s'),
  5362. 'updated_at' => Date('Y-m-d H:i:s'),
  5363. ];
  5364. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5365. //被通知人员处理
  5366. foreach ($chat_ids as $key => $value) {
  5367. $groupMemberdata[] = [
  5368. 'user_id' => $value,
  5369. 'group_id' => $groupResult,
  5370. 'leader' => 3,
  5371. 'join_time' => Date('Y-m-d H:i:s')
  5372. ];
  5373. $talk_sessionData[] = [
  5374. 'user_id' => $value,
  5375. 'to_from_id' => $groupResult,
  5376. 'talk_mode' => 2,
  5377. 'created_at' => Date('Y-m-d H:i:s'),
  5378. 'updated_at' => Date('Y-m-d H:i:s'),
  5379. ];
  5380. }
  5381. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5382. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5383. $group_id = $groupResult;
  5384. //更新result的 group_id
  5385. $data['group_id'] = $group_id;
  5386. Notice::where(['id' => $data['id']])->update($data);
  5387. }
  5388. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5389. //删除掉信息
  5390. GroupImp::where('id', $notice['group_id'])->delete();
  5391. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5392. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5393. foreach ($chat_ids as $key => $value) {
  5394. }
  5395. //聊天记录删除
  5396. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5397. $data['group_id'] = null;
  5398. Notice::where(['id' => $data['id']])->update($data);
  5399. }
  5400. $result = Notice::where('id', $data['id'])->update($data);
  5401. $noticeInfo = Notice::where('id', $data['id'])->first();
  5402. if ($data['status'] == 2) {
  5403. $this->sendMessage([
  5404. 'talk_type' => 701,
  5405. 'title' => $noticeInfo['title'],
  5406. 'content' => '审核通过',
  5407. 'messageType' => 3,
  5408. 'user_id' => $noticeInfo['user_id'],
  5409. ]);
  5410. }
  5411. if ($data['status'] == 3) {
  5412. $this->sendMessage([
  5413. 'talk_type' => 701,
  5414. 'title' => $noticeInfo['title'],
  5415. 'content' => '审核拒绝',
  5416. 'messageType' => 3,
  5417. 'user_id' => $noticeInfo['user_id'],
  5418. ]);
  5419. }
  5420. if ($data['status'] == 1) {
  5421. $this->sendMessage([
  5422. 'talk_type' => 700,
  5423. 'title' => $noticeInfo['title'],
  5424. 'content' => '提交了审核',
  5425. 'messageType' => 3,
  5426. ]);
  5427. }
  5428. return Result::success($result);
  5429. }
  5430. public function getDUser(array $data): array
  5431. {
  5432. if (!empty($data['ids'])) {
  5433. $user = User::whereIn('id', $data['ids'])->getall();
  5434. if (empty($user)) {
  5435. return Result::error('无数据', 0);
  5436. }
  5437. return Result::success($user);
  5438. }
  5439. $where = [];
  5440. if (!empty($data['department_id'])) {
  5441. $where['department_id'] = $data['department_id'];
  5442. }
  5443. if (!empty($data['city_id'])) {
  5444. $where['city_id'] = $data['city_id'];
  5445. }
  5446. $result = User::where('type_id', 2)
  5447. ->where('status', 1)
  5448. ->where($where)
  5449. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5450. ->get();
  5451. if (empty($result)) {
  5452. return Result::error("查询失败", 0);
  5453. }
  5454. return Result::success($result);
  5455. }
  5456. /**
  5457. * 验证导航名称是否重复
  5458. * @return void
  5459. */
  5460. public function checkCategoryName(array $data): array
  5461. {
  5462. $result = Category::when($data, function ($query) use ($data) {
  5463. if (isset($data['name']) && $data['name']) {
  5464. $query->where("name", $data['name']);
  5465. }
  5466. if (isset($data['id']) && $data['id']) {
  5467. $query->where("id", "!=", $data['id']);
  5468. }
  5469. })->first();
  5470. if ($result) {
  5471. return Result::error("已存在");
  5472. } else {
  5473. return Result::success();
  5474. }
  5475. }
  5476. //20250226 产品列表
  5477. // 20250306 -------招聘--------fr
  5478. /*
  5479. * 招聘列表
  5480. * */
  5481. public function getJobRecruitingList(array $data): array
  5482. {
  5483. $where = [];
  5484. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5485. if ($data['checkout'] == 0) {
  5486. $job_status = [0, 2];
  5487. } else {
  5488. $job_status = [1];
  5489. }
  5490. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5491. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5492. }
  5493. $user = User::where('id', $data['user_id'])->first();
  5494. if (empty($user)) {
  5495. return Result::error("用户不存在", 0);
  5496. }
  5497. // 3:企业会员
  5498. if ($user['type_id'] == 3) {
  5499. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5500. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5501. }
  5502. // 如果 $where 为空,则不添加 where 条件
  5503. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5504. return $query->where($where);
  5505. })
  5506. ->whereIn('job_recruiting.status', $job_status)
  5507. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5508. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5509. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5510. ->orderBy("updated_at", "desc")
  5511. ->offset(($data['page'] - 1) * $data['page_size'])
  5512. ->limit($data['page_size'])
  5513. ->get()
  5514. ->all();
  5515. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5516. return $query->where($where);
  5517. })
  5518. ->whereIn('job_recruiting.status', $job_status)
  5519. ->count();
  5520. if (empty($result)) {
  5521. return Result::error("暂无招聘信息", 0);
  5522. }
  5523. return Result::success($result);
  5524. }
  5525. /*
  5526. * 招聘信息添加
  5527. * */
  5528. public function addJobRecruiting(array $data): array
  5529. {
  5530. // var_dump('添加招聘进入news------data',$data);
  5531. // return Result::success($data);
  5532. $user = User::where('user.id', $data['user_id'])
  5533. ->where('user.status', 1)
  5534. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5535. ->select(
  5536. 'user.type_id',
  5537. 'user.mobile',
  5538. 'user.email',
  5539. 'user_info.business_name',
  5540. 'user_info.company_hy_id',
  5541. 'user_info.company_nature',
  5542. 'user_info.company_size',
  5543. 'user_info.introduction',
  5544. 'user_info.real_name',
  5545. 'user_info.company_url',
  5546. 'user_info.address_arr_id',
  5547. 'user_info.address'
  5548. )
  5549. ->first();
  5550. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5551. return Result::error("用户不存在", 0);
  5552. }
  5553. $web = Website::where('id', $data['website_id'])->first();
  5554. if (empty($web)) {
  5555. return Result::error("网站不存在", 0);
  5556. }
  5557. // var_dump('添加招聘进入news---user---user',$user);
  5558. // 处理招聘关键词
  5559. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5560. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5561. } else {
  5562. Jieba::init(); // 初始化 jieba-php
  5563. Finalseg::init();
  5564. $segList = Jieba::cut($data['title']);
  5565. $segList1 = array_slice($segList, 0, 8);
  5566. $data['keyword'] = implode(',', $segList1);
  5567. }
  5568. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5569. $content = $data['description'];
  5570. // 去除 <style> 和 <script> 标签及其内容
  5571. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5572. // 去除所有 HTML 标签
  5573. $content = strip_tags($content);
  5574. // 去除 HTML 实体
  5575. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5576. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5577. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5578. // 去除多余空白
  5579. $content = preg_replace('/\s+/u', '', $content);
  5580. // 截取 100 个字符
  5581. $data['seo_description'] = mb_substr($content, 0, 100);
  5582. }
  5583. // return Result::success($user);
  5584. $data['action_id'] = $data['user_id'] ?? null;
  5585. $data['user_type'] = $user['type_id'] ?? null;
  5586. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5587. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5588. $data['catid'] = end($data['cat_arr_id']);
  5589. } else {
  5590. $data['catid'] = 0;
  5591. }
  5592. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5593. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5594. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5595. // 公司地址 管理员必填
  5596. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5597. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5598. // 管理员-企业相关信息
  5599. $company = [
  5600. // 'user_id' => $data['user_id']?? null,
  5601. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5602. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5603. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5604. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5605. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5606. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5607. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5608. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5609. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5610. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5611. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5612. ];
  5613. //去掉相关企业信息
  5614. $job = array_diff_key($data, array_flip(array_keys($company)));
  5615. // var_dump('添加招聘进入news---job---user',$job);
  5616. Db::beginTransaction();
  5617. try {
  5618. // // 先添加职位相关信息
  5619. if ($user['type_id'] == 10000) {
  5620. $job['status'] = 1;
  5621. }
  5622. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5623. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5624. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5625. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5626. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5627. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5628. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5629. // return Result::success($job);
  5630. $jobId = JobRecruiting::insertGetId($job);
  5631. if (empty($jobId)) {
  5632. Db::rollBack();
  5633. return Result::error("添加失败");
  5634. }
  5635. // 添加公司信息
  5636. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5637. $company['job_id'] = $jobId;
  5638. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5639. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5640. if ($user['type_id'] == 10000) {
  5641. // 管理员添加企业信息
  5642. $companyId = JobCompany::insertGetId($company);
  5643. if (empty($companyId)) {
  5644. Db::rollBack();
  5645. return Result::error("添加失败");
  5646. }
  5647. } else {
  5648. // 企业会员添加企业信息
  5649. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5650. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5651. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5652. $company['job_id'] = $jobId;
  5653. $companyId = JobCompany::insertGetId($company);
  5654. if (empty($companyId)) {
  5655. Db::rollBack();
  5656. return Result::error("添加失败");
  5657. }
  5658. }
  5659. Db::commit();
  5660. $result = [
  5661. 'job_id' => $jobId,
  5662. 'company_id' => $companyId,
  5663. ];
  5664. return Result::success($result);
  5665. } catch (\Exception $e) {
  5666. Db::rollBack();
  5667. return Result::error($e->getMessage(), 0);
  5668. }
  5669. // return Result::success($result);
  5670. }
  5671. /*
  5672. * 获取招聘信息详情
  5673. * */
  5674. public function getJobRecruitingInfo(array $data): array
  5675. {
  5676. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5677. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5678. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5679. ->select(
  5680. 'job_recruiting.*',
  5681. 'website.website_name as website_name',
  5682. 'job_company.business_name',
  5683. 'job_company.company_hy_id',
  5684. 'job_company.company_size',
  5685. 'job_company.company_nature',
  5686. 'job_company.introduction',
  5687. 'job_company.real_name',
  5688. 'job_company.mobile',
  5689. 'job_company.company_url',
  5690. 'job_company.address_arr_id',
  5691. 'job_company.address',
  5692. 'job_company.email'
  5693. )
  5694. ->first();
  5695. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5696. if (!empty($cityId)) {
  5697. if (isset($cityId[1]) && $cityId[1] != null) {
  5698. $city = District::where('id', $cityId[1])->first(['name']);
  5699. } else {
  5700. $city = District::where('id', $cityId[0])->first(['name']);
  5701. }
  5702. $result['city'] = $city['name'] ?? '';
  5703. }
  5704. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5705. if (is_array($addressId) && !empty($addressId)) {
  5706. $address = District::whereIn('id', $addressId)
  5707. ->orderBy('level', 'asc')
  5708. ->get(['name'])
  5709. ->pluck('name')
  5710. ->implode('');
  5711. // $job->address_name = $address ?? '';
  5712. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5713. }
  5714. if (empty($result)) {
  5715. return Result::error("招聘信息不存在", 0);
  5716. }
  5717. // return Result::success($job);
  5718. return Result::success($result);
  5719. }
  5720. /*
  5721. * 修改招聘信息
  5722. * */
  5723. public function upJobRecruiting(array $data): array
  5724. {
  5725. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5726. // return Result::success($job);
  5727. if (empty($job)) {
  5728. return Result::error("招聘信息不存在", 0);
  5729. }
  5730. $user = User::where('id', $data['user_id'])->first();
  5731. // return Result::success($user);
  5732. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5733. return Result::error("用户不存在", 0);
  5734. }
  5735. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5736. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5737. }
  5738. // 处理招聘关键词
  5739. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5740. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5741. } else {
  5742. Jieba::init(); // 初始化 jieba-php
  5743. Finalseg::init();
  5744. $segList = Jieba::cut($data['title']);
  5745. $segList1 = array_slice($segList, 0, 8);
  5746. $data['keyword'] = implode(',', $segList1);
  5747. }
  5748. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5749. $content = $data['description'];
  5750. // 去除 <style> 和 <script> 标签及其内容
  5751. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5752. // 去除所有 HTML 标签
  5753. $content = strip_tags($content);
  5754. // 去除 HTML 实体
  5755. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5756. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5757. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5758. // 去除多余空白
  5759. $content = preg_replace('/\s+/u', '', $content);
  5760. // 截取 100 个字符
  5761. $data['seo_description'] = mb_substr($content, 0, 100);
  5762. }
  5763. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5764. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5765. $data['catid'] = end($data['cat_arr_id']);
  5766. } else {
  5767. }
  5768. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5769. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5770. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5771. // 公司地址 管理员必填
  5772. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5773. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5774. // 管理员-企业相关信息
  5775. $company = [
  5776. // 'user_id' => $data['user_id']?? null,
  5777. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5778. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5779. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5780. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5781. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5782. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5783. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5784. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5785. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5786. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5787. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5788. ];
  5789. //去掉相关企业信息
  5790. $data = array_diff_key($data, array_flip(array_keys($company)));
  5791. $jobId = $data['id'];
  5792. $web = $data['website_id'];
  5793. $data['action_id'] = $data['user_id'];
  5794. unset($data['user_id']);
  5795. unset($data['user_type']);
  5796. unset($data['id']);
  5797. unset($data['website_id']);
  5798. // return Result::success($data);
  5799. Db::beginTransaction();
  5800. try {
  5801. // 管理员修改招聘信息
  5802. if ($user['type_id'] == 10000) {
  5803. $data['website_id'] = $web;
  5804. $company['website_id'] = $data['website_id'];
  5805. $data['status'] = 1;
  5806. } else {
  5807. $data['status'] = 0;
  5808. }
  5809. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5810. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5811. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5812. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5813. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5814. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5815. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5816. // return Result::success($job);
  5817. // Db::rollBack();
  5818. // return Result::success($company);
  5819. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5820. $this->sendMessage([
  5821. 'talk_type' => 500,
  5822. 'title' => $data['title'],
  5823. 'content' => '提交了审核',
  5824. 'messageType' => 10,
  5825. ]);
  5826. }
  5827. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5828. if (empty($result['job'])) {
  5829. Db::rollBack();
  5830. return Result::error("修改招聘信息失败");
  5831. }
  5832. // 管理员修改企业相关信息
  5833. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5834. if (empty($result['company'])) {
  5835. Db::rollBack();
  5836. return Result::error("修改企业相关信息失败");
  5837. }
  5838. Db::commit();
  5839. // return Result::success($result);
  5840. } catch (\Exception $e) {
  5841. Db::rollBack();
  5842. return Result::error($e->getMessage(), 0);
  5843. }
  5844. return Result::success($result);
  5845. }
  5846. /*
  5847. * 招聘信息删除
  5848. * */
  5849. public function delJobRecruiting(array $data): array
  5850. {
  5851. $user = User::where('id', $data['user_id'])->first();
  5852. if (empty($user)) {
  5853. return Result::error("用户不存在", 0);
  5854. }
  5855. $job = JobRecruiting::where('id', $data['id'])->first();
  5856. if (empty($job)) {
  5857. return Result::error("招聘信息不存在", 0);
  5858. }
  5859. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5860. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5861. }
  5862. Db::beginTransaction();
  5863. try {
  5864. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5865. if (empty($result['job'])) {
  5866. Db::rollBack();
  5867. return Result::error("删除招聘信息失败");
  5868. }
  5869. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5870. if (empty($result['company'])) {
  5871. Db::rollBack();
  5872. return Result::error("删除企业相关信息失败");
  5873. }
  5874. Db::commit();
  5875. } catch (\Exception $e) {
  5876. Db::rollBack();
  5877. return Result::error($e->getMessage(), 0);
  5878. }
  5879. return Result::success($result);
  5880. }
  5881. /*
  5882. * 获取公司信息
  5883. * */
  5884. public function getJobCompany(array $data): array
  5885. {
  5886. $user = User::where('user.id', $data['user_id'])
  5887. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5888. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5889. ->first();
  5890. // return Result::success($user);
  5891. if (empty($user)) {
  5892. return Result::error("用户不存在", 0);
  5893. }
  5894. if ($user['type_id'] == 3) {
  5895. $result = [
  5896. // 'id' => 0,
  5897. 'user_id' => $data['user_id'],
  5898. 'website_id' => $data['website_id'],
  5899. 'business_name' => $user['business_name'], // 企业名称
  5900. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5901. 'company_nature' => $user['company_nature'], // 公司性质
  5902. 'company_size' => $user['company_size'], // 公司规模
  5903. 'introduction' => $user['introduction'], // 公司简介
  5904. 'real_name' => $user['real_name'], // 企业联系人
  5905. 'mobile' => $user['mobile'], // 企业联系电话
  5906. 'company_url' => $user['company_url'], // 企业网址
  5907. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5908. 'address' => $user['address'], // 企业地址
  5909. 'email' => $user['email'], // 企业邮箱
  5910. ];
  5911. } else {
  5912. return Result::error("用户类型错误", 0);
  5913. }
  5914. if (empty($result)) {
  5915. return Result::error("公司信息不存在", 0);
  5916. }
  5917. return Result::success($result);
  5918. }
  5919. /*
  5920. * 修改公司信息
  5921. * */
  5922. public function upJobCompany(array $data): array
  5923. {
  5924. // return Result::success($data);
  5925. $user = User::where('user.id', $data['user_id'])
  5926. ->where('user.status', 1)
  5927. ->select('user.user_name', 'user.type_id')
  5928. ->first();
  5929. if (empty($user)) {
  5930. return Result::error("用户不存在", 0);
  5931. }
  5932. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5933. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5934. $company = [
  5935. 'business_name' => $data['business_name'], // 企业名称
  5936. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5937. 'company_nature' => $data['company_nature'], // 公司性质
  5938. 'company_size' => $data['company_size'], // 公司规模
  5939. 'introduction' => $data['introduction'], // 公司简介
  5940. // 'real_name' => $data['real_name'], // 企业联系人
  5941. 'company_url' => $data['company_url'], // 企业网址
  5942. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5943. 'address' => $data['address'], // 企业详细地址
  5944. // 'email' => $data['email'], // 企业邮箱
  5945. ];
  5946. if ($user['type_id'] == 3) {
  5947. Db::beginTransaction();
  5948. try {
  5949. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5950. 'business_name' => $data['business_name'], // 企业名称
  5951. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5952. 'company_nature' => $data['company_nature'], // 公司性质
  5953. 'company_size' => $data['company_size'], // 公司规模
  5954. 'introduction' => $data['introduction'], // 公司简介
  5955. // 'real_name' => $data['real_name'], // 企业联系人
  5956. 'company_url' => $data['company_url'], // 企业网址
  5957. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5958. 'address' => $data['address'], // 企业详细地址
  5959. ]);
  5960. if (empty($result['userinfo'])) {
  5961. Db::rollBack();
  5962. return Result::error('修改企业会员信息失败!');
  5963. }
  5964. $result['user'] = User::where('id', $data['user_id'])->update([
  5965. 'email' => $data['email'], // 企业邮箱
  5966. ]);
  5967. if (empty($result['user'])) {
  5968. Db::rollBack();
  5969. return Result::error('修改个人中心信息失败!');
  5970. }
  5971. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5972. if (!empty($job_company)) {
  5973. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5974. if (empty($result['job_company'])) {
  5975. Db::rollBack();
  5976. return Result::error('修改企业会员信息失败!');
  5977. }
  5978. }
  5979. Db::commit();
  5980. return Result::success($result);
  5981. } catch (\Exception $e) {
  5982. Db::rollBack();
  5983. return Result::error($e->getMessage(), 0);
  5984. }
  5985. } else {
  5986. return Result::error("用户类型错误", 0);
  5987. }
  5988. }
  5989. /*
  5990. * 获取省-市
  5991. * */
  5992. public function getJobRecruitingArea(array $data): array
  5993. {
  5994. if (isset($data['pid']) && $data['pid'] != null) {
  5995. $result = District::where('pid', $data['pid'])->get()->all();
  5996. } else {
  5997. $result = District::where('level', 1)->get()->all();
  5998. }
  5999. if (empty($result)) {
  6000. return Result::error("暂无此省市", 0);
  6001. }
  6002. return Result::success($result);
  6003. }
  6004. /*
  6005. * 获取行业分类
  6006. * */
  6007. public function getIndustry(array $data): array
  6008. {
  6009. $result = JobIndustry::get()->all();
  6010. if (empty($result)) {
  6011. return Result::error("暂无行业分类", 0);
  6012. }
  6013. return Result::success($result);
  6014. }
  6015. /*
  6016. * 获取职位
  6017. * */
  6018. public function getPositionList(array $data): array
  6019. {
  6020. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6021. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6022. } else {
  6023. $result = JobPosition::where('zwpid', 0)->get()->all();
  6024. }
  6025. if (empty($result)) {
  6026. return Result::error("暂无此职位", 0);
  6027. }
  6028. return Result::success($result);
  6029. }
  6030. /*
  6031. * 获取工作性质-菜单
  6032. * */
  6033. public function getJobNature(array $data): array
  6034. {
  6035. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6036. if (empty($result)) {
  6037. return Result::error("暂无工作性质", 0);
  6038. }
  6039. return Result::success($result);
  6040. }
  6041. /*
  6042. * 获取工作经验-菜单
  6043. * */
  6044. public function getExperience(array $data): array
  6045. {
  6046. $result = JobEnum::where('egroup', 'years')->get()->all();
  6047. if (empty($result)) {
  6048. return Result::error("暂无工作经验", 0);
  6049. }
  6050. return Result::success($result);
  6051. }
  6052. /*
  6053. * 获取学历-菜单
  6054. * */
  6055. public function getEducation(array $data): array
  6056. {
  6057. $result = JobEnum::where('egroup', 'education')->get()->all();
  6058. if (empty($result)) {
  6059. return Result::error("暂无学历", 0);
  6060. }
  6061. return Result::success($result);
  6062. }
  6063. /*
  6064. * 获取薪资-菜单
  6065. * */
  6066. public function getSalary(array $data): array
  6067. {
  6068. $result = JobEnum::where('egroup', 'income')->get()->all();
  6069. if (empty($result)) {
  6070. return Result::error("暂无薪资", 0);
  6071. }
  6072. return Result::success($result);
  6073. }
  6074. /*
  6075. * 获取语言-菜单
  6076. * */
  6077. public function getLanguage(array $data): array
  6078. {
  6079. $result = JobEnum::where('egroup', 'language')->get()->all();
  6080. if (empty($result)) {
  6081. return Result::error("暂无语言", 0);
  6082. }
  6083. return Result::success($result);
  6084. }
  6085. /*
  6086. * 获取掌握程度-菜单
  6087. * */
  6088. public function getLevel(array $data): array
  6089. {
  6090. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6091. if (empty($result)) {
  6092. return Result::error("暂无工作性质", 0);
  6093. }
  6094. return Result::success($result);
  6095. }
  6096. // 公司信息
  6097. /*
  6098. * 获取公司性质-菜单
  6099. * */
  6100. public function getCompanyNature(array $data): array
  6101. {
  6102. $result = JobNature::get()->all();
  6103. if (empty($result)) {
  6104. return Result::error("暂无公司性质", 0);
  6105. }
  6106. return Result::success($result);
  6107. }
  6108. /*
  6109. * 获取公司规模-菜单
  6110. * */
  6111. public function getCompanySize(array $data): array
  6112. {
  6113. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6114. if (empty($result)) {
  6115. return Result::error("暂无公司规模", 0);
  6116. }
  6117. return Result::success($result);
  6118. }
  6119. /*
  6120. * 招聘信息审核
  6121. * */
  6122. public function checkJobRecruiting(array $data): array
  6123. {
  6124. $user = User::where('id', $data['user_id'])->first();
  6125. if (empty($user)) {
  6126. return Result::error("用户不存在", 0);
  6127. }
  6128. $job = JobRecruiting::where('id', $data['id'])->first();
  6129. if (empty($job)) {
  6130. return Result::error("招聘信息不存在", 0);
  6131. }
  6132. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6133. if ($user['type_id'] != 10000) {
  6134. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6135. }
  6136. // 驳回原因
  6137. if ($data['status'] == 2) {
  6138. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6139. }
  6140. $data['action_id'] = $data['user_id'];
  6141. unset($data['user_id']);
  6142. if ($data['status'] == 1) {
  6143. $this->sendMessage([
  6144. 'talk_type' => 501,
  6145. 'title' => $job['title'],
  6146. 'content' => '审核通过',
  6147. 'messageType' => 10,
  6148. 'user_id' => $job['user_id'],
  6149. ]);
  6150. }
  6151. if ($data['status'] == 2) {
  6152. $this->sendMessage([
  6153. 'talk_type' => 501,
  6154. 'title' => $job['title'],
  6155. 'content' => '审核拒绝',
  6156. 'messageType' => 10,
  6157. 'user_id' => $job['user_id'],
  6158. ]);
  6159. }
  6160. if ($data['status'] == 0) {
  6161. $this->sendMessage([
  6162. 'talk_type' => 500,
  6163. 'title' => $job['title'],
  6164. 'content' => '提交了审核',
  6165. 'messageType' => 10,
  6166. ]);
  6167. }
  6168. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6169. if (empty($result)) {
  6170. return Result::error("审核失败", 0);
  6171. }
  6172. return Result::success($result);
  6173. }
  6174. public function myApplyList(array $data): array
  6175. {
  6176. var_dump($data, '------参数');
  6177. $user = User::where('id', $data['user_id'])->first();
  6178. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6179. return Result::error("用户不存在", 0);
  6180. }
  6181. // 1:个人会员 职场机会
  6182. if ($user['type_id'] == 1) {
  6183. $where['user_id'] = $user['id'];
  6184. }
  6185. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6186. $query->where('user_id', $user['id']);
  6187. })
  6188. ->pluck('recruit_id');
  6189. $where = [];
  6190. if (isset($data['salary']) && $data['salary'] != null) {
  6191. $where['job_recruiting.salary'] = $data['salary'];
  6192. }
  6193. if (isset($data['experience']) && $data['experience'] != null) {
  6194. $where['job_recruiting.experience'] = $data['experience'];
  6195. }
  6196. if (isset($data['business_name']) && $data['business_name'] != null) {
  6197. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6198. }
  6199. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6200. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6201. ->where($where);
  6202. // ->count();
  6203. $count = $query->count();
  6204. $query = clone $query;
  6205. $job = $query
  6206. ->leftJoin('job_enum as income_enum', function ($join) {
  6207. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6208. ->where('income_enum.egroup', 'income');
  6209. })
  6210. ->leftJoin('job_enum as years_enum', function ($join) {
  6211. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6212. ->where('years_enum.egroup', 'years');
  6213. })
  6214. // ->where($where)
  6215. ->orderBy('job_recruiting.updated_at', 'desc')
  6216. ->select(
  6217. 'job_recruiting.id',
  6218. 'job_recruiting.title',
  6219. 'job_company.business_name',
  6220. 'income_enum.evalue as salary_evalue',
  6221. 'income_enum.ename as salary_ename',
  6222. 'years_enum.evalue as experience_evalue',
  6223. 'years_enum.ename as experience_ename',
  6224. 'job_recruiting.updated_at'
  6225. )
  6226. ->offset(($data['page'] - 1) * $data['pageSize'])
  6227. ->limit($data['pageSize'])
  6228. ->get()
  6229. ->all();
  6230. if (empty($job)) {
  6231. return Result::error("暂无招聘信息", 0);
  6232. }
  6233. $result = [
  6234. 'row' => $job,
  6235. 'count' => $count,
  6236. ];
  6237. return Result::success($result);
  6238. }
  6239. public function readJobApply(array $data): array
  6240. {
  6241. $result = JobApply::where('id', $data['id'])->first();
  6242. if (empty($result)) {
  6243. return Result::error("查询失败", 0);
  6244. }
  6245. $result = JobApply::where('id', $data['id'])->update([
  6246. 'status' => 2,
  6247. ]);
  6248. return Result::success($result);
  6249. }
  6250. /*
  6251. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6252. * */
  6253. public function getRecruitingList(array $data): array
  6254. {
  6255. $user = User::where('id', $data['user_id'])->first();
  6256. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6257. return Result::error("用户不存在", 0);
  6258. }
  6259. // 1:个人会员 职场机会
  6260. if ($user['type_id'] == 1) {
  6261. $where['user_id'] = $user['id'];
  6262. }
  6263. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6264. $query->where('receiver_id', $user['id']);
  6265. })
  6266. ->pluck('recruit_id');
  6267. // return Result::success($recruitingId);
  6268. $where = [];
  6269. if (isset($data['salary']) && $data['salary'] != null) {
  6270. $where['job_recruiting.salary'] = $data['salary'];
  6271. }
  6272. if (isset($data['experience']) && $data['experience'] != null) {
  6273. $where['job_recruiting.experience'] = $data['experience'];
  6274. }
  6275. if (isset($data['business_name']) && $data['business_name'] != null) {
  6276. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6277. }
  6278. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6279. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6280. ->where($where);
  6281. // ->count();
  6282. $count = $query->count();
  6283. $query = clone $query;
  6284. $job = $query
  6285. ->leftJoin('job_enum as income_enum', function ($join) {
  6286. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6287. ->where('income_enum.egroup', 'income');
  6288. })
  6289. ->leftJoin('job_enum as years_enum', function ($join) {
  6290. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6291. ->where('years_enum.egroup', 'years');
  6292. })
  6293. // ->where($where)
  6294. ->orderBy('job_recruiting.updated_at', 'desc')
  6295. ->select(
  6296. 'job_recruiting.id',
  6297. 'job_recruiting.title',
  6298. 'job_company.business_name',
  6299. 'income_enum.evalue as salary_evalue',
  6300. 'income_enum.ename as salary_ename',
  6301. 'years_enum.evalue as experience_evalue',
  6302. 'years_enum.ename as experience_ename',
  6303. 'job_recruiting.updated_at'
  6304. )
  6305. ->offset(($data['page'] - 1) * $data['pageSize'])
  6306. ->limit($data['pageSize'])
  6307. ->get()
  6308. ->all();
  6309. if (empty($job)) {
  6310. return Result::error("暂无招聘信息", 0);
  6311. }
  6312. $result = [
  6313. 'row' => $job,
  6314. 'count' => $count,
  6315. ];
  6316. return Result::success($result);
  6317. }
  6318. /*
  6319. * 获取企业会员-招聘信息列表
  6320. * */
  6321. public function getRecruitingInfo(array $data): array
  6322. {
  6323. $user = User::where('id', $data['user_id'])->first();
  6324. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6325. return Result::error("用户不存在", 0);
  6326. }
  6327. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6328. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6329. ->select(
  6330. 'job_recruiting.*',
  6331. 'job_company.business_name',
  6332. 'job_company.company_hy_id',
  6333. 'job_company.company_size',
  6334. 'job_company.company_nature',
  6335. 'job_company.introduction',
  6336. 'job_company.real_name',
  6337. 'job_company.mobile',
  6338. 'job_company.company_url',
  6339. 'job_company.address_arr_id',
  6340. 'job_company.address',
  6341. 'job_company.email'
  6342. )
  6343. ->get();
  6344. if (empty($recruiting)) {
  6345. return Result::error("暂无招聘信息", 0);
  6346. }
  6347. return Result::success($recruiting);
  6348. }
  6349. /*
  6350. * 获取企业会员-我的沟通
  6351. * */
  6352. public function getJobResumeList(array $data): array
  6353. {
  6354. $user = User::where('id', $data['user_id'])->first();
  6355. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6356. return Result::error("用户不存在", 0);
  6357. }
  6358. $where = [];
  6359. if (isset($data['salary']) && $data['salary'] != null) {
  6360. $where['job_hunting.salary'] = $data['salary'];
  6361. }
  6362. if (isset($data['user_name']) && $data['user_name'] != null) {
  6363. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6364. }
  6365. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6366. $query->where('job_resume.user_id', $user['id']);
  6367. })
  6368. ->when(!empty($where), function ($query) use ($where) {
  6369. $query->where($where);
  6370. })
  6371. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6372. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6373. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6374. ->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');
  6375. $count = $job->count();
  6376. if ($count == 0) {
  6377. return Result::error("暂无沟通记录", 0);
  6378. }
  6379. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6380. ->offset(($data['page'] - 1) * $data['pageSize'])
  6381. ->limit($data['pageSize'])
  6382. ->get();
  6383. if (empty($jobs)) {
  6384. return Result::error("暂无沟通记录", 0);
  6385. }
  6386. $result['row'] = $this->processJob($jobs, '');
  6387. $result['count'] = $count;
  6388. return Result::success($result);
  6389. }
  6390. public function readJobResume(array $data): array
  6391. {
  6392. $result = JobResume::where('id', $data['id'])->first();
  6393. if (empty($result)) {
  6394. return Result::error("查询失败", 0);
  6395. }
  6396. $result = JobResume::where('id', $data['id'])->update([
  6397. 'status' => 2,
  6398. ]);
  6399. return Result::success($result);
  6400. }
  6401. // 20250306 招聘
  6402. //20250422 书刊音像
  6403. public function addBook(array $data): array
  6404. {
  6405. $user_id = $data['user_id'] ?? 0;
  6406. $type_id = $data['type_id'] ?? 0;
  6407. // $website_id = $data['website_id'] ?? 0;
  6408. // unset($data['user_id']);
  6409. unset($data['type_id']);
  6410. // unset($data['website_id']);
  6411. //处理数组
  6412. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6413. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6414. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6415. if ($data['img_url'] == '') {
  6416. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6417. preg_match_all($reg, $data['detail'], $matches);
  6418. if (isset($matches[1][0])) {
  6419. //截取varchar240
  6420. $data['img_url'] = substr($matches[1][0], 0, 240);
  6421. }
  6422. }
  6423. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6424. //提取标题+内容中的关键词
  6425. $data['keyword'] = $data['title'];
  6426. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6427. Jieba::init(); // 初始化 jieba-php
  6428. Finalseg::init();
  6429. $segList = Jieba::cut($data['keyword']);
  6430. $segList1 = array_slice($segList, 0, 8);
  6431. $data['keyword'] = implode(',', $segList1);
  6432. }
  6433. if ($data['description'] == '') {
  6434. //提取内容中的描述
  6435. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6436. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6437. }
  6438. var_dump($data, '--');
  6439. if ($data['status'] == 1) {
  6440. $this->sendMessage([
  6441. 'talk_type' => 400,
  6442. 'title' => $data['title'],
  6443. 'content' => '提交了审核',
  6444. 'messageType' => 7,
  6445. ]);
  6446. }
  6447. $result = Book::insertGetId($data);
  6448. if (empty($result)) {
  6449. return Result::error("添加失败", 0);
  6450. }
  6451. return Result::success($result);
  6452. }
  6453. public function getBookList(array $data): array
  6454. {
  6455. $where = [];
  6456. if (!empty($data["title"])) {
  6457. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6458. }
  6459. if (!empty($data['website_name'])) {
  6460. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6461. }
  6462. if (!empty($data['status'])) {
  6463. $where[] = ['book.status', '=', $data['status']];
  6464. }
  6465. $user_id = $data['user_id'];
  6466. $type_id = $data['type_id'];
  6467. // $type_id = 4;
  6468. var_dump($type_id, '------1--------');
  6469. if ($type_id != 10000) {
  6470. $where[] = ['book.user_id', '=', $user_id];
  6471. }
  6472. var_dump(!empty($data['status1']), '=-===1');
  6473. $result = Book::where($where)
  6474. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6475. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6476. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6477. ->when(isset($data['status1']), function ($query) use ($data) {
  6478. $query->whereIn('book.status', [1, 3]);
  6479. })
  6480. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6481. ->orderBy("updated_at", "desc")
  6482. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6483. if (empty($result)) {
  6484. return Result::error("暂无数据", 0);
  6485. }
  6486. // 取出数据
  6487. $rows = $result->items();
  6488. $count = $result->total();
  6489. $responseData = [
  6490. 'rows' => $rows,
  6491. 'count' => $count,
  6492. ];
  6493. return Result::success($responseData);
  6494. }
  6495. public function deleteBook(array $data): array
  6496. {
  6497. $result = Book::where('id', $data['id'])->delete();
  6498. if (empty($result)) {
  6499. return Result::error("删除失败", 0);
  6500. }
  6501. return Result::success($result);
  6502. }
  6503. public function updateBook(array $data): array
  6504. {
  6505. // $user_id = $data['user_id'] ?? 0;
  6506. $type_id = $data['type_id'] ?? 0;
  6507. // $website_id = $data['website_id'] ?? 0;
  6508. unset($data['user_id']);
  6509. unset($data['type_id']);
  6510. // unset($data['website_id']);
  6511. //处理数组
  6512. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6513. if ($data['img_url'] == '') {
  6514. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6515. preg_match_all($reg, $data['detail'], $matches);
  6516. if (isset($matches[1][0])) {
  6517. //截取varchar240
  6518. $data['img_url'] = substr($matches[1][0], 0, 240);
  6519. }
  6520. }
  6521. if ($data['keyword'] == '') {
  6522. //提取标题+内容中的关键词
  6523. $data['keyword'] = $data['title'];
  6524. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6525. Jieba::init(); // 初始化 jieba-php
  6526. Finalseg::init();
  6527. $segList = Jieba::cut($data['keyword']);
  6528. $segList1 = array_slice($segList, 0, 8);
  6529. $data['keyword'] = implode(',', $segList1);
  6530. }
  6531. if ($data['description'] == '') {
  6532. //提取内容中的描述
  6533. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6534. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6535. }
  6536. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6537. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6538. if ($data['status'] == 1) {
  6539. $this->sendMessage([
  6540. 'talk_type' => 400,
  6541. 'title' => $data['title'],
  6542. 'content' => '提交了审核',
  6543. 'messageType' => 7,
  6544. ]);
  6545. }
  6546. $result = Book::where("id", $data["id"])->update($data);
  6547. if (empty($result)) {
  6548. return Result::error("更新失败", 0);
  6549. }
  6550. return Result::success($result);
  6551. }
  6552. public function getBookInfo(array $data): array
  6553. {
  6554. $result = Book::where("id", $data["id"])->first();
  6555. if (empty($result)) {
  6556. return Result::error("获取失败", 0);
  6557. }
  6558. return Result::success($result);
  6559. }
  6560. public function updateBookStatus(array $data): array
  6561. {
  6562. //审核
  6563. unset($data['user_id']);
  6564. $bookInfo = Book::where("id", $data["id"])->first();
  6565. var_dump($bookInfo, '----');
  6566. if ($data['status'] == 2) {
  6567. $this->sendMessage([
  6568. 'talk_type' => 401,
  6569. 'title' => $bookInfo['title'],
  6570. 'content' => '审核通过',
  6571. 'messageType' => 7,
  6572. 'user_id' => $bookInfo['user_id'],
  6573. ]);
  6574. }
  6575. if ($data['status'] == 3) {
  6576. $this->sendMessage([
  6577. 'talk_type' => 401,
  6578. 'title' => $bookInfo['title'],
  6579. 'content' => '审核拒绝',
  6580. 'messageType' => 7,
  6581. 'user_id' => $bookInfo['user_id'],
  6582. ]);
  6583. }
  6584. if ($data['status'] == 1) {
  6585. $this->sendMessage([
  6586. 'talk_type' => 400,
  6587. 'title' => $bookInfo['title'],
  6588. 'content' => '提交了审核',
  6589. 'messageType' => 7,
  6590. // 'user_id'=>$bookInfo['user_id'],
  6591. ]);
  6592. }
  6593. $result = Book::where("id", $data["id"])->update($data);
  6594. if (empty($result)) {
  6595. return Result::error("更新失败", 0);
  6596. }
  6597. return Result::success($result);
  6598. }
  6599. //20250422 书刊音像
  6600. /**
  6601. * 贴身宝贝
  6602. * @param array $data
  6603. * @return array
  6604. */
  6605. public function getWebsiteTsbb(array $data): array
  6606. {
  6607. $month = $data['month'] ?? date('m');
  6608. $day = $data['day'] ?? date('d');
  6609. // 使用缓存键
  6610. $cacheKey = "tsbb_data_{$month}_{$day}";
  6611. // 尝试从缓存获取数据
  6612. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6613. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6614. if ($cachedData = $cache->get($cacheKey)) {
  6615. return Result::success(unserialize($cachedData));
  6616. }
  6617. //查询老黄历
  6618. try {
  6619. $date = date('Y-m-d');
  6620. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6621. // 使用 curl 替代 file_get_contents
  6622. $ch = curl_init();
  6623. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6624. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6625. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6626. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6627. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6628. 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');
  6629. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6630. 'Accept: application/json',
  6631. 'Content-Type: application/json',
  6632. 'Referer: https://www.36jxs.com/'
  6633. ]);
  6634. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6635. curl_setopt($ch, CURLOPT_ENCODING, '');
  6636. $almanacResponse = curl_exec($ch);
  6637. var_dump("====:", $almanacResponse);
  6638. if (curl_errno($ch)) {
  6639. var_dump('Curl error:', curl_error($ch));
  6640. throw new \Exception('Curl error: ' . curl_error($ch));
  6641. }
  6642. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6643. curl_close($ch);
  6644. if ($almanacResponse === false) {
  6645. throw new \Exception('Failed to fetch almanac data');
  6646. }
  6647. $almanacData = json_decode($almanacResponse, true);
  6648. if (json_last_error() !== JSON_ERROR_NONE) {
  6649. throw new \Exception('Failed to parse almanac data');
  6650. }
  6651. $almanacInfo = $almanacData['data'] ?? [];
  6652. } catch (\Exception $e) {
  6653. var_dump('Exception:', $e->getMessage());
  6654. $almanacInfo = [];
  6655. }
  6656. // 获取历史上的今天数据
  6657. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6658. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6659. ->orderBy('year', 'asc')
  6660. ->select("title", "id", "year", DB::raw('1 as type'))
  6661. ->limit(16)
  6662. ->get();
  6663. // 获取节日数据 - 从今天开始获取未来4条
  6664. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6665. ->orderBy('showtime', 'asc')
  6666. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6667. ->limit(16)
  6668. ->get();
  6669. //说文解字
  6670. $chartacterList = Character::orderBy('updated_at', 'desc')
  6671. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6672. ->limit(6)
  6673. ->get();
  6674. //谜语沙龙
  6675. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6676. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6677. ->limit(4)
  6678. ->get();
  6679. //成语欣赏
  6680. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6681. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6682. ->limit(32)
  6683. ->get();
  6684. //名联赏析
  6685. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6686. ->select("id", "first", "second", DB::raw('6 as type'))
  6687. ->limit(6)
  6688. ->get();
  6689. // 获取分类文章数据
  6690. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6691. ->pluck('category_id')
  6692. ->toArray();
  6693. $articlesList = [];
  6694. foreach ($categoryIds as $catid) {
  6695. // 先查有图片的
  6696. $withImg = DB::table('article')
  6697. ->where('status', 1)
  6698. ->where('catid', $catid)
  6699. ->whereNotNull('imgurl')
  6700. ->where('imgurl', '!=', '')
  6701. ->orderBy('updated_at', 'desc')
  6702. ->limit(6)
  6703. ->get();
  6704. $count = $withImg->count();
  6705. if ($count < 6) {
  6706. // 不足6条再查无图片的补足
  6707. $withoutImg = DB::table('article')
  6708. ->where('status', 1)
  6709. ->where('catid', $catid)
  6710. ->where(function ($q) {
  6711. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6712. })
  6713. ->orderBy('updated_at', 'desc')
  6714. ->limit(6 - $count)
  6715. ->get();
  6716. $articles = $withImg->concat($withoutImg);
  6717. } else {
  6718. $articles = $withImg;
  6719. }
  6720. // 组装
  6721. $category = \App\Model\Category::find($catid);
  6722. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6723. $articlesList[] = [
  6724. 'category_name' => $category ? $category->name : '',
  6725. 'catid' => $catid,
  6726. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6727. 'type' => 100,
  6728. 'list' => $articles->map(function ($item) {
  6729. return [
  6730. 'id' => $item->id,
  6731. 'title' => $item->title,
  6732. 'imgurl' => $item->imgurl,
  6733. 'created_at' => $item->created_at
  6734. ];
  6735. })->values()
  6736. ];
  6737. }
  6738. $result = [
  6739. 'almanac' => $almanacInfo,
  6740. 'historyTodayList' => [
  6741. 'category_name' => '历史上的今天',
  6742. 'list' => $historyTodayList,
  6743. 'type' => 1
  6744. ],
  6745. 'festivalList' => [
  6746. 'category_name' => '节日预告',
  6747. 'list' => $festivalList,
  6748. 'type' => 2
  6749. ],
  6750. 'chartacterList' => [
  6751. 'category_name' => '说文解字',
  6752. 'list' => $chartacterList,
  6753. 'type' => 3
  6754. ],
  6755. 'coupletList' => [
  6756. 'category_name' => '名联赏析',
  6757. 'list' => $coupletList,
  6758. 'type' => 6
  6759. ],
  6760. 'riddletList' => [
  6761. 'category_name' => '谜语沙龙',
  6762. 'list' => $riddletList,
  6763. 'type' => 4
  6764. ],
  6765. 'idiomList' => [
  6766. 'category_name' => '成语欣赏',
  6767. 'list' => $idiomList,
  6768. 'type' => 5
  6769. ],
  6770. 'articlesList' => $articlesList
  6771. ];
  6772. // 缓存结果,设置1小时过期
  6773. $cache->set($cacheKey, serialize($result), 3600);
  6774. return Result::success($result);
  6775. }
  6776. /**
  6777. * 获取资讯列表
  6778. */
  6779. public function getWebsiteTsbbList(array $data): array
  6780. {
  6781. $page = $data['page'] ?? 1;
  6782. $pageSize = $data['pageSize'] ?? 10;
  6783. // 如果没有传入月份和日期,则使用今天的日期
  6784. $month = $data['month'] ?? date('m');
  6785. $day = $data['day'] ?? date('d');
  6786. $total = 0;
  6787. $result = [];
  6788. $data['type'] = intval($data['type']);
  6789. var_dump("接收参数:", $data);
  6790. switch ($data['type']) {
  6791. case 1:
  6792. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6793. // 当前月份之后的数据
  6794. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6795. // 或者当前月份且日期大于等于当前日期的数据
  6796. ->orWhere(function ($q) use ($month, $day) {
  6797. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6798. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6799. });
  6800. })
  6801. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6802. $total = $query->count();
  6803. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6804. ->offset(($page - 1) * $pageSize)
  6805. ->limit($pageSize)
  6806. ->get();
  6807. break;
  6808. case 2:
  6809. $query = Festival::where(function ($q) use ($month, $day) {
  6810. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6811. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6812. ->orWhere(function ($q) use ($month, $day) {
  6813. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6814. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6815. });
  6816. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6817. $total = $query->count();
  6818. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6819. ->offset(($page - 1) * $pageSize)
  6820. ->limit($pageSize)
  6821. ->get();
  6822. break;
  6823. case 3:
  6824. $query = Character::orderBy("updated_at", "desc");
  6825. $total = $query->count();
  6826. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6827. ->offset(($page - 1) * $pageSize)
  6828. ->limit($pageSize)
  6829. ->get();
  6830. break;
  6831. case 4:
  6832. $query = Riddle::orderBy("updated_at", "desc");
  6833. $total = $query->count();
  6834. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6835. ->offset(($page - 1) * $pageSize)
  6836. ->limit($pageSize)
  6837. ->get();
  6838. break;
  6839. case 5:
  6840. $query = Idiom::orderBy("updated_at", "desc");
  6841. $total = $query->count();
  6842. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6843. ->offset(($page - 1) * $pageSize)
  6844. ->limit($pageSize)
  6845. ->get();
  6846. break;
  6847. case 6:
  6848. $query = Couplet::orderBy("updated_at", "desc");
  6849. $total = $query->count();
  6850. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6851. ->offset(($page - 1) * $pageSize)
  6852. ->limit($pageSize)
  6853. ->get();
  6854. break;
  6855. default:
  6856. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6857. $total = $query->count();
  6858. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6859. ->offset(($page - 1) * $pageSize)
  6860. ->limit($pageSize)
  6861. ->get();
  6862. }
  6863. return Result::success([
  6864. 'list' => $result,
  6865. 'total' => $total,
  6866. 'page' => (int)$page,
  6867. 'pageSize' => (int)$pageSize,
  6868. 'month' => $month,
  6869. 'day' => $day
  6870. ]);
  6871. }
  6872. /**
  6873. * 1:历史上的今天
  6874. * 2:节日
  6875. * 3:文章
  6876. *
  6877. * 资讯详情信息
  6878. */
  6879. public function getWebsiteTsbbDetail(array $data): array
  6880. {
  6881. $data['type'] = intval($data['type']);
  6882. switch ($data['type']) {
  6883. case 1:
  6884. $result = HistoryToday::where("id", $data['id'])->first();
  6885. break;
  6886. case 2:
  6887. $result = Festival::where("id", $data['id'])->first();
  6888. break;
  6889. case 3:
  6890. $result = Character::where("id", $data['id'])->first();
  6891. break;
  6892. case 4:
  6893. $result = Riddle::where("id", $data['id'])->first();
  6894. break;
  6895. case 5:
  6896. $result = Idiom::where("id", $data['id'])->first();
  6897. break;
  6898. case 6:
  6899. $result = Couplet::where("id", $data['id'])->first();
  6900. break;
  6901. default:
  6902. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6903. break;
  6904. }
  6905. return Result::success($result);
  6906. }
  6907. /**
  6908. * 农网导航首页数据
  6909. */
  6910. public function getWebsiteNwHomeList(array $data): array
  6911. {
  6912. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6913. ->pluck('category_id')
  6914. ->toArray();
  6915. // 使用子查询优化
  6916. $articlesList = DB::table('article')
  6917. ->select([
  6918. 'article.id',
  6919. 'article.title',
  6920. 'article.imgurl',
  6921. 'article.created_at',
  6922. 'category.name as category_name',
  6923. 'category.id as category_id',
  6924. 'website_category.aLIas_pinyin as pinyin',
  6925. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6926. DB::raw('100 as type')
  6927. ])
  6928. ->join('category', 'article.catid', '=', 'category.id')
  6929. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6930. ->leftJoin('website_category as parent_wc', function ($join) {
  6931. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6932. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6933. })
  6934. ->where('website_category.website_id', $data['website_id'])
  6935. ->where('article.status', 1)
  6936. ->whereIn('category.id', $categoryIds)
  6937. ->orderBy('article.created_at', 'desc')
  6938. ->get()
  6939. ->groupBy('category_id')
  6940. ->map(function ($group) {
  6941. // 确保第一条数据有图片
  6942. $firstWithImage = $group->first(function ($item) {
  6943. return !empty($item->imgurl);
  6944. });
  6945. if ($firstWithImage) {
  6946. // 如果有带图片的文章,将其放在第一位
  6947. $group = $group->filter(function ($item) use ($firstWithImage) {
  6948. return $item->id !== $firstWithImage->id;
  6949. })->prepend($firstWithImage);
  6950. }
  6951. return [
  6952. 'category_name' => $group->first()->category_name,
  6953. 'catid' => $group->first()->category_id,
  6954. 'pinyin' => $group->first()->pinyin,
  6955. 'parent_pinyin' => $group->first()->parent_pinyin,
  6956. 'list' => $group->take(4)->map(function ($item) {
  6957. return [
  6958. 'id' => $item->id,
  6959. 'title' => $item->title,
  6960. ];
  6961. })->values()
  6962. ];
  6963. })
  6964. ->values()
  6965. ->toArray();
  6966. return Result::success($articlesList);
  6967. }
  6968. /**
  6969. * 企业管理
  6970. * @param array $data
  6971. * @return array
  6972. */
  6973. public function getCompanyList(array $data): array
  6974. {
  6975. // return Result::success($data);
  6976. $where = [];
  6977. $user = User::where('id', $data['user_id'])->first();
  6978. if (empty($user)) {
  6979. return Result::error('用户不存在!');
  6980. }
  6981. if ($user['type_id'] != 10000) {
  6982. $where['user_id'] = $data['user_id'];
  6983. }
  6984. if (isset($data['title']) && !empty($data['title'])) {
  6985. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6986. }
  6987. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6988. array_push($where, ['website.id', $data['website_id']]);
  6989. }
  6990. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6991. if ($data['ischeck'] == 1) {
  6992. if (isset($data['status']) && $data['status'] != '') {
  6993. array_push($where, ['company.status', $data['status']]);
  6994. $query = Company::where($where);
  6995. } else {
  6996. $query = Company::whereIn('company.status', [0, 2]);
  6997. }
  6998. } else {
  6999. $query = Company::where('company.status', 1);
  7000. }
  7001. }
  7002. $result = $query->where($where)
  7003. ->leftJoin('website_category', function ($query) {
  7004. $query->on('website_category.category_id', '=', 'company.category_id')
  7005. ->on('website_category.website_id', '=', 'company.website_id');
  7006. })
  7007. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7008. ->select(
  7009. 'company.id',
  7010. 'company.title',
  7011. 'company.website_id',
  7012. 'company.category_id',
  7013. 'website.website_name',
  7014. 'website_category.alias as category_name',
  7015. 'company.status',
  7016. 'company.updated_at',
  7017. 'company.user_id'
  7018. )
  7019. ->orderBy('company.updated_at', 'desc')
  7020. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7021. if ($result->isEmpty()) {
  7022. return Result::error("暂无企业", 0);
  7023. }
  7024. return Result::success($result);
  7025. }
  7026. /**
  7027. * 添加企业
  7028. * @param array $data
  7029. * @return array
  7030. */
  7031. public function addCompany(array $data): array
  7032. {
  7033. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7034. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7035. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7036. $data['cat_arr_id'] = json_encode($car_arr_id);
  7037. } else {
  7038. $data['cat_arr_id'] = '';
  7039. }
  7040. if ($data['imgurl'] == '') {
  7041. //content中提取图片第一个图,正则提取
  7042. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7043. preg_match_all($reg, $data['content'], $matches);
  7044. if (isset($matches[1][0])) {
  7045. //截取varchar240
  7046. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7047. }
  7048. }
  7049. if ($data['keyword'] == '') {
  7050. //提取标题+内容中的关键词
  7051. $data['keyword'] = $data['title'];
  7052. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7053. Jieba::init(); // 初始化 jieba-php
  7054. Finalseg::init();
  7055. $segList = Jieba::cut($data['keyword']);
  7056. $segList1 = array_slice($segList, 0, 8);
  7057. $data['keyword'] = implode(',', $segList1);
  7058. }
  7059. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7060. //提取内容中的描述
  7061. $content = $data['content'];
  7062. // 去除 <style> 和 <script> 标签及其内容
  7063. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7064. // 去除所有 HTML 标签
  7065. $content = strip_tags($content);
  7066. // 去除 HTML 实体
  7067. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7068. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7069. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7070. // 去除多余空白
  7071. $content = preg_replace('/\s+/u', '', $content);
  7072. // 截取 100 个字符
  7073. $data['introduce'] = mb_substr($content, 0, 100);
  7074. }
  7075. $user = User::where('id', $data['user_id'])->first();
  7076. if (empty($user)) {
  7077. return Result::error('用户不存在!');
  7078. }
  7079. if ($user['type_id'] == 10000) {
  7080. $data['status'] = 1;
  7081. }
  7082. if (isset($data['level']) && $data['level'] != null) {
  7083. $data['level'] = intval($data['level']);
  7084. } else {
  7085. $data['level'] = null;
  7086. }
  7087. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7088. $this->sendMessage([
  7089. 'talk_type' => 900,
  7090. 'title' => $data['title'],
  7091. 'content' => '提交了审核',
  7092. 'messageType' => 8,
  7093. ]);
  7094. }
  7095. $result = Company::insertGetId($data);
  7096. if ($result) {
  7097. return Result::success($result);
  7098. } else {
  7099. return Result::error('添加失败');
  7100. }
  7101. }
  7102. /**
  7103. * 更新企业
  7104. * @param array $data
  7105. * @return array
  7106. */
  7107. public function upCompany(array $data): array
  7108. {
  7109. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7110. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7111. $data['cat_arr_id'] = json_encode($car_arr_id);
  7112. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7113. } else {
  7114. $data['cat_arr_id'] = '';
  7115. }
  7116. if ($data['imgurl'] == '') {
  7117. //content中提取图片第一个图,正则提取
  7118. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7119. preg_match_all($reg, $data['content'], $matches);
  7120. if (isset($matches[1][0])) {
  7121. //截取varchar
  7122. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7123. }
  7124. }
  7125. if ($data['keyword'] == '') {
  7126. //提取标题+内容中的关键词
  7127. $data['keyword'] = $data['title'];
  7128. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7129. Jieba::init(); // 初始化 jieba-php
  7130. Finalseg::init();
  7131. $segList = Jieba::cut($data['keyword']);
  7132. $segList1 = array_slice($segList, 0, 8);
  7133. $data['keyword'] = implode(',', $segList1);
  7134. }
  7135. if ($data['introduce'] == '') {
  7136. //提取内容中的描述
  7137. $content = $data['content'];
  7138. // 去除 <style> 和 <script> 标签及其内容
  7139. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7140. // 去除所有 HTML 标签
  7141. $content = strip_tags($content);
  7142. // 去除 HTML 实体
  7143. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7144. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7145. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7146. // 去除多余空白
  7147. $content = preg_replace('/\s+/u', '', $content);
  7148. // 截取 100 个字符
  7149. $data['introduce'] = mb_substr($content, 0, 100);
  7150. }
  7151. if (isset($data['level']) && $data['level'] != null) {
  7152. $data['level'] = intval($data['level']);
  7153. } else {
  7154. $data['level'] = null;
  7155. }
  7156. $user = User::where('id', $data['user_id'])->first();
  7157. if (empty($user)) {
  7158. return Result::error('用户不存在!');
  7159. }
  7160. if ($user['type_id'] == 10000) {
  7161. $data['status'] = 1;
  7162. } else {
  7163. $data['status'] = 0;
  7164. }
  7165. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7166. $this->sendMessage([
  7167. 'talk_type' => 900,
  7168. 'title' => $data['title'],
  7169. 'content' => '提交了审核',
  7170. 'messageType' => 8,
  7171. ]);
  7172. }
  7173. $result = Company::where('id', $data['id'])->update($data);
  7174. if ($result) {
  7175. return Result::success($result);
  7176. } else {
  7177. return Result::error('修改失败');
  7178. }
  7179. }
  7180. /**
  7181. * 删除企业
  7182. * @param array $data
  7183. * @return array
  7184. */
  7185. public function delCompany(array $data): array
  7186. {
  7187. $result = Company::where('id', $data['id'])->delete();
  7188. if ($result) {
  7189. return Result::success($result);
  7190. } else {
  7191. return Result::error('删除失败');
  7192. }
  7193. }
  7194. /**
  7195. * 审核企业
  7196. * @param array $data
  7197. * @return array
  7198. */
  7199. public function checkCompany(array $data): array
  7200. {
  7201. $user = User::where('id', $data['user_id'])->first();
  7202. if (empty($user)) {
  7203. return Result::error('用户不存在!');
  7204. }
  7205. $company = Company::where('id', $data['id'])->first();
  7206. if (empty($company)) {
  7207. return Result::error('企业不存在!');
  7208. }
  7209. // 状态:0:未审核 1:已审核 2:已拒绝
  7210. if ($data['status'] == 2 || $data['status'] == '2') {
  7211. $this->sendMessage([
  7212. 'talk_type' => 901,
  7213. 'title' => $company['title'],
  7214. 'content' => '审核拒绝',
  7215. 'messageType' => 8,
  7216. 'user_id' => $company['user_id'],
  7217. ]);
  7218. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7219. } else {
  7220. if ($data['status'] == 1) {
  7221. $this->sendMessage([
  7222. 'talk_type' => 901,
  7223. 'title' => $company['title'],
  7224. 'content' => '审核通过',
  7225. 'messageType' => 8,
  7226. 'user_id' => $company['user_id'],
  7227. ]);
  7228. } else if ($data['status'] == 0) {
  7229. $this->sendMessage([
  7230. 'talk_type' => 900,
  7231. 'title' => $company['title'],
  7232. 'content' => '提交了审核',
  7233. 'messageType' => 8,
  7234. ]);
  7235. }
  7236. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7237. }
  7238. if (empty($result)) {
  7239. return Result::error('审核失败!');
  7240. } else {
  7241. return Result::success($result);
  7242. }
  7243. }
  7244. /**
  7245. * 获取企业信息
  7246. * @param array $data
  7247. * @return array
  7248. */
  7249. public function getCompanyInfo(array $data): array
  7250. {
  7251. $result = Company::where('id', $data['id'])->first();
  7252. $city_arr = json_decode($result['city_arr_id']);
  7253. $result['city_name'] = District::whereIn('id', $city_arr)
  7254. ->pluck('name')
  7255. ->implode('-');
  7256. if (empty($result)) {
  7257. return Result::error('企业不存在!');
  7258. } else {
  7259. return Result::success($result);
  7260. }
  7261. }
  7262. /**
  7263. * @param array $data
  7264. * @return array
  7265. */
  7266. public function getWebsiteCompany(array $data): array
  7267. {
  7268. $categorys = json_decode($data['id'], true);
  7269. $category_arr = $this->processArticlePro($data['website_id']);
  7270. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7271. $catiall = $category_arr['catiall'];
  7272. $categoryIds = $category_arr['categoryIds'];
  7273. // return Result::success($category_arr);
  7274. foreach ($categorys as $key => $value) {
  7275. if (array_key_exists('level', $value)) {
  7276. $parts = explode(',', $value['level']);
  7277. $level = $parts[0] ?? null;
  7278. $imgnum = $parts[1] ?? null;
  7279. $textnum = $parts[2] ?? null;
  7280. if (!empty($textnum) && $textnum > 0) {
  7281. $text_num = Company::where('level', $level)
  7282. ->whereIn('category_id', $categoryIds)
  7283. ->where('status', 1)
  7284. ->select(
  7285. 'company.id',
  7286. 'company.title',
  7287. 'company.description',
  7288. 'company.updated_at',
  7289. 'company.category_id',
  7290. 'company.cat_arr_id'
  7291. )
  7292. ->orderBy('updated_at', 'desc')
  7293. ->limit($textnum)
  7294. ->get()->all();
  7295. }
  7296. if (!empty($imgnum) && $imgnum > 0) {
  7297. $img_num = Company::where('level', $level)
  7298. ->whereIn('category_id', $categoryIds)
  7299. ->where('status', 1)
  7300. ->where('imgurl', '!=', '')
  7301. ->whereNotNull('imgurl')
  7302. ->select(
  7303. 'company.id',
  7304. 'company.title',
  7305. 'company.description',
  7306. 'company.updated_at',
  7307. 'company.imgurl as imgs',
  7308. 'company.category_id',
  7309. 'company.cat_arr_id'
  7310. )
  7311. ->orderBy('updated_at', 'desc')
  7312. ->limit($imgnum)
  7313. ->get()->all();
  7314. }
  7315. }
  7316. if (array_key_exists('id', $value)) {
  7317. $parts = explode(',', $value['id']);
  7318. $category_id = $parts[0] ?? null;
  7319. $imgnum = $parts[1] ?? null;
  7320. $textnum = $parts[2] ?? null;
  7321. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7322. if (!empty($textnum) && $textnum > 0) {
  7323. $text_num = Company::whereIn('category_id', $category_arr)
  7324. // ->where('website_id', $data['website_id'])
  7325. ->where('status', 1)
  7326. ->select(
  7327. 'company.id',
  7328. 'company.title',
  7329. 'company.description',
  7330. 'company.updated_at',
  7331. 'company.category_id',
  7332. 'company.cat_arr_id'
  7333. )
  7334. ->orderBy('updated_at', 'desc')
  7335. ->limit($textnum)
  7336. ->get()->all();
  7337. }
  7338. if (!empty($imgnum) && $imgnum > 0) {
  7339. $img_num = Company::whereIn('category_id', $category_arr)
  7340. // ->where('website_id', $data['website_id'])
  7341. ->where('status', 1)
  7342. ->where('imgurl', '!=', '')
  7343. ->whereNotNull('imgurl')
  7344. ->select(
  7345. 'company.id',
  7346. 'company.title',
  7347. 'company.description',
  7348. 'company.updated_at',
  7349. 'company.imgurl as imgs',
  7350. 'company.category_id',
  7351. 'company.cat_arr_id'
  7352. )
  7353. ->orderBy('updated_at', 'desc')
  7354. ->limit($imgnum)
  7355. ->get()->all();
  7356. }
  7357. }
  7358. if (!empty($text_num)) {
  7359. foreach ($text_num as $k => $v) {
  7360. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7361. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7362. }
  7363. }
  7364. if (!empty($img_num)) {
  7365. foreach ($img_num as $k => $v) {
  7366. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7367. $imgurl = json_decode($v['imgs'], true);
  7368. if (!empty($imgurl)) {
  7369. $img_num[$k]->imgurl = $imgurl[0];
  7370. }
  7371. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7372. }
  7373. }
  7374. $company[$key]['img_num'] = $img_num ?? [];
  7375. $company[$key]['text_num'] = $text_num ?? [];
  7376. }
  7377. if (empty($company)) {
  7378. return Result::error("暂无相关企业信息", 0);
  7379. }
  7380. return Result::success($company);
  7381. }
  7382. /**
  7383. * @param array $data
  7384. * @return array
  7385. */
  7386. public function getWebsiteCompanyList(array $data): array
  7387. {
  7388. $where['website_id'] = $data['website_id'];
  7389. $where['status'] = 1;
  7390. $categoryIds = [];
  7391. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7392. $category_id = $data['category_id'];
  7393. }
  7394. $category_arr = $this->processArticlePro($data['website_id']);
  7395. $categoryIds = $category_arr['categoryIds'];
  7396. // return Result::success($cat_1st_arr);
  7397. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7398. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7399. })
  7400. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7401. $query->whereIn('category_id', $categoryIds);
  7402. })
  7403. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7404. $query->where('category_id', $category_id);
  7405. })
  7406. ->where('status',1)
  7407. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7408. ->orderBy('updated_at', 'desc')
  7409. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7410. if (empty($company)) {
  7411. return Result::error("暂无相关公司信息", 0);
  7412. }
  7413. $result = [
  7414. 'count' => $company->total(),
  7415. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7416. ];
  7417. return Result::success($result);
  7418. }
  7419. /**
  7420. * 获取项目列表
  7421. * @param array $data
  7422. * @return array
  7423. */
  7424. public function getProjectList(array $data): array
  7425. {
  7426. $where = [];
  7427. $user = User::where('id', $data['user_id'])->first();
  7428. if (empty($user)) {
  7429. return Result::error('用户不存在!');
  7430. }
  7431. if ($user->type_id != 10000) {
  7432. array_push($where, ['project.user_id', $data['user_id']]);
  7433. }
  7434. $query = Project::query();
  7435. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7436. array_push($where, ['project.website_id', $data['website_id']]);
  7437. }
  7438. if (isset($data['title']) && !empty($data['title'])) {
  7439. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7440. }
  7441. if ($data['status'] != 3) {
  7442. array_push($where, ['project.status', $data['status']]);
  7443. }
  7444. $query = Project::where($where)
  7445. ->when($data['status'] == 3, function ($query) {
  7446. $query->whereIn('project.status', [0, 2]);
  7447. });
  7448. $count = $query->clone()
  7449. ->count();
  7450. $rows = $query->clone()
  7451. ->leftJoin('website', 'project.website_id', 'website.id')
  7452. ->leftJoin('website_category', function ($join) {
  7453. $join->on('project.website_id', '=', 'website_category.website_id')
  7454. ->on('project.category_id', '=', 'website_category.category_id');
  7455. })
  7456. ->select(
  7457. 'project.id',
  7458. 'project.title',
  7459. 'project.updated_at',
  7460. 'project.status',
  7461. 'website.website_name',
  7462. 'website_category.alias as category_name',
  7463. 'project.website_id',
  7464. 'project.user_id'
  7465. )
  7466. ->orderBy('project.updated_at', 'desc')
  7467. ->offset(($data['page'] - 1) * $data['pageSize'])
  7468. ->limit($data['pageSize'])
  7469. ->get();
  7470. if ($rows->isEmpty()) {
  7471. return Result::error("暂无相关项目信息", 0);
  7472. }
  7473. $result = [
  7474. 'count' => $count,
  7475. 'rows' => $rows,
  7476. ];
  7477. return Result::success($result);
  7478. }
  7479. /**
  7480. * 添加项目
  7481. * @param array $data
  7482. * @return array
  7483. */
  7484. public function addProject(array $data): array
  7485. {
  7486. $user = User::where('id', $data['user_id'])->first();
  7487. if (empty($user)) {
  7488. return Result::error("暂无相关用户信息", 0);
  7489. }
  7490. if ($user->type_id == 10000) {
  7491. $data['status'] = 1;
  7492. } else {
  7493. $data['status'] = 0;
  7494. }
  7495. if ($data['keyword'] == '') {
  7496. //提取标题+内容中的关键词
  7497. $data['keyword'] = $data['title'];
  7498. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7499. Jieba::init(); // 初始化 jieba-php
  7500. Finalseg::init();
  7501. $segList = Jieba::cut($data['keyword']);
  7502. $segList1 = array_slice($segList, 0, 8);
  7503. $data['keyword'] = implode(',', $segList1);
  7504. }
  7505. if ($data['description'] == '') {
  7506. //提取内容中的描述
  7507. // var_dump(11111);
  7508. //提取内容中的描述
  7509. $content = $data['introduce'];
  7510. // 去除 <style> 和 <script> 标签及其内容
  7511. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7512. // 去除所有 HTML 标签
  7513. $content = strip_tags($content);
  7514. // 去除 HTML 实体
  7515. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7516. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7517. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7518. // 去除多余空白
  7519. $content = preg_replace('/\s+/u', '', $content);
  7520. // 截取 100 个字符
  7521. $data['description'] = mb_substr($content, 0, 100);
  7522. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7523. }
  7524. if ($data['status'] == 0) {
  7525. $this->sendMessage([
  7526. 'talk_type' => 1000,
  7527. 'title' => $data['title'],
  7528. 'content' => '提交了审核',
  7529. 'messageType' => 9,
  7530. ]);
  7531. }
  7532. $project = Project::insertGetId($data);
  7533. if (empty($project)) {
  7534. return Result::error("暂无相关项目信息", 0);
  7535. }
  7536. return Result::success($project);
  7537. }
  7538. /**
  7539. * 更新项目
  7540. * @param array $data
  7541. * @return array
  7542. */
  7543. public function upProject(array $data): array
  7544. {
  7545. $project = Project::where('id', $data['id'])->first();
  7546. if (empty($project)) {
  7547. return Result::error("暂无相关项目信息", 0);
  7548. }
  7549. $id = $data['id'];
  7550. unset($data['id']);
  7551. $user = User::where('id', $data['user_id'])->first();
  7552. if (empty($user)) {
  7553. return Result::error("暂无相关用户信息", 0);
  7554. }
  7555. if ($user->type_id == 10000) {
  7556. $data['status'] = 1;
  7557. } else {
  7558. $data['status'] = 0;
  7559. }
  7560. unset($data['user_id']);
  7561. if ($data['keyword'] == '') {
  7562. //提取标题+内容中的关键词
  7563. $data['keyword'] = $data['title'];
  7564. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7565. Jieba::init(); // 初始化 jieba-php
  7566. Finalseg::init();
  7567. $segList = Jieba::cut($data['keyword']);
  7568. $segList1 = array_slice($segList, 0, 8);
  7569. $data['keyword'] = implode(',', $segList1);
  7570. }
  7571. if ($data['description'] == '') {
  7572. //提取内容中的描述
  7573. // var_dump(11111);
  7574. //提取内容中的描述
  7575. $content = $data['introduce'];
  7576. // 去除 <style> 和 <script> 标签及其内容
  7577. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7578. // 去除所有 HTML 标签
  7579. $content = strip_tags($content);
  7580. // 去除 HTML 实体
  7581. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7582. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7583. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7584. // 去除多余空白
  7585. $content = preg_replace('/\s+/u', '', $content);
  7586. // 截取 100 个字符
  7587. $data['description'] = mb_substr($content, 0, 100);
  7588. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7589. }
  7590. if ($data['status'] == 0) {
  7591. $this->sendMessage([
  7592. 'talk_type' => 1000,
  7593. 'title' => $data['title'],
  7594. 'content' => '提交了审核',
  7595. 'messageType' => 9,
  7596. ]);
  7597. }
  7598. $result = Project::where('id', $id)->update($data);
  7599. if (empty($result)) {
  7600. return Result::error("更新失败", 0);
  7601. }
  7602. return Result::success($result);
  7603. }
  7604. /**
  7605. * 删除项目
  7606. * @param array $data
  7607. * @return array
  7608. */
  7609. public function delProject(array $data): array
  7610. {
  7611. $user = User::where('id', $data['user_id'])->first();
  7612. if (empty($user)) {
  7613. return Result::error("暂无相关用户信息", 0);
  7614. }
  7615. $project = Project::where('id', $data['id'])->first();
  7616. if (empty($project)) {
  7617. return Result::error("暂无相关项目信息", 0);
  7618. }
  7619. $result = Project::where('id', $data['id'])->delete();
  7620. if (empty($result)) {
  7621. return Result::error("删除失败", 0);
  7622. }
  7623. return Result::success($result);
  7624. }
  7625. /**
  7626. * 审核项目
  7627. * @param array $data
  7628. * @return array
  7629. */
  7630. public function checkProject(array $data): array
  7631. {
  7632. $user = User::where('id', $data['user_id'])->first();
  7633. if (empty($user)) {
  7634. return Result::error("暂无相关用户信息", 0);
  7635. }
  7636. // 0:未审核; 1:已审核; 2:已拒绝;
  7637. if ($user->type_id != 10000) {
  7638. if ($data['status'] == 1 || $data['status'] == 2) {
  7639. return Result::error("此用户权限不足", 0);
  7640. }
  7641. }
  7642. $project = Project::where('id', $data['id'])->first();
  7643. if (empty($project)) {
  7644. return Result::error("暂无相关项目信息", 0);
  7645. }
  7646. if ($data['status'] == 2) {
  7647. $this->sendMessage([
  7648. 'talk_type' => 1001,
  7649. 'title' => $project['title'],
  7650. 'content' => '审核拒绝',
  7651. 'messageType' => 9,
  7652. 'user_id' => $project['user_id'],
  7653. ]);
  7654. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7655. } else {
  7656. if ($data['status'] == 1) {
  7657. $this->sendMessage([
  7658. 'talk_type' => 1001,
  7659. 'title' => $project['title'],
  7660. 'content' => '审核通过',
  7661. 'messageType' => 9,
  7662. 'user_id' => $project['user_id'],
  7663. ]);
  7664. } else if ($data['status'] == 0) {
  7665. $this->sendMessage([
  7666. 'talk_type' => 1000,
  7667. 'title' => $project['title'],
  7668. 'content' => '提交了审核',
  7669. 'messageType' => 9,
  7670. ]);
  7671. }
  7672. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7673. }
  7674. if (empty($result)) {
  7675. return Result::error("审核失败", 0);
  7676. }
  7677. return Result::success($result);
  7678. }
  7679. /**
  7680. * 获取项目详情
  7681. * @param array $data
  7682. * @return array
  7683. */
  7684. public function getProjectInfo(array $data): array
  7685. {
  7686. $project = Project::where('id', $data['id'])->first();
  7687. if (empty($project)) {
  7688. return Result::error("暂无相关项目信息", 0);
  7689. }
  7690. return Result::success($project);
  7691. }
  7692. public function getWebsiteCompanyInfo(array $data): array
  7693. {
  7694. $company = Company::where('id', $data['id'])
  7695. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7696. ->where('status', 1)
  7697. // ->where('website_id', $data['website_id'])
  7698. ->select('company.*', 'job_industry.hyname as hy_name')
  7699. ->first();
  7700. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7701. $jobnature_id = $company['jobnature_id'] ?? null;
  7702. if ($jobnature_id !== null) {
  7703. switch ($jobnature_id) {
  7704. case 0:
  7705. $company->jobnature_name = '市场监督';
  7706. break;
  7707. case 1:
  7708. $company->jobnature_name = '信访纪检';
  7709. break;
  7710. case 2:
  7711. $company->jobnature_name = '公检法司';
  7712. break;
  7713. case 3:
  7714. $company->jobnature_name = '高关注机构';
  7715. break;
  7716. default:
  7717. $company->jobnature_name = '';
  7718. break;
  7719. }
  7720. } else {
  7721. $company->jobnature_name = '';
  7722. }
  7723. $city_arr = $company->city_arr_id;
  7724. if (!empty($city_arr)) {
  7725. $city_arr = json_decode($city_arr, true);
  7726. $cityNames = District::whereIn('id', $city_arr)
  7727. ->pluck('name')
  7728. ->implode('-');
  7729. $company->city_name = $cityNames;
  7730. } else {
  7731. $company->city_name = '';
  7732. }
  7733. if (empty($company)) {
  7734. return Result::error("暂无相关公司信息", 0);
  7735. }
  7736. return Result::success($company);
  7737. }
  7738. public function getMSG(array $data): array
  7739. {
  7740. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7741. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7742. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7743. $result = [];
  7744. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7745. //最近的5篇已审的文章
  7746. $apply_articale = Article::where('status', 1)
  7747. ->where('admin_user_id', $user_id)
  7748. ->orderBy('updated_at', 'desc')
  7749. // ->limit(5)
  7750. ->get();
  7751. //获取5条用户的已审核商品
  7752. $good = Good::where('status', 2)
  7753. ->where('user_id', $user_id)
  7754. ->orderBy('updated_at', 'desc')
  7755. // ->limit(5)
  7756. ->get();
  7757. //获取5条用户待审核的公告
  7758. $notice = Notice::where('status', 2)
  7759. ->where('user_id', $user_id)
  7760. ->orderBy('updated_at', 'desc')
  7761. ->limit(5)->get();
  7762. //获取5条用户的待审核投诉
  7763. $complaint = Complaint::where('status', 2)
  7764. ->where('user_id', $user_id)
  7765. ->orderBy('updated_at', 'desc')
  7766. // ->limit(5)
  7767. ->get();
  7768. //获取5条用户的book
  7769. $book = Book::where('status', 2)
  7770. ->where('user_id', $user_id)
  7771. ->orderBy('updated_at', 'desc')
  7772. // ->limit(5)
  7773. ->get();
  7774. //获取5条用户的求职
  7775. //获取5条用户的求职 1
  7776. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7777. ->where('job_hunting.user_id', $user_id)
  7778. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7779. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7780. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7781. ->orderBy('updated_at', 'desc')
  7782. // ->limit(5)
  7783. ->get();
  7784. //获取5条用户的求职 2
  7785. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7786. ->where('job_recruiting.user_id', $user_id)
  7787. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7788. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7789. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7790. ->orderBy('updated_at', 'desc')
  7791. // ->limit(5)
  7792. ->get();
  7793. //人才库 1
  7794. $job_apply = JobApply::where('job_apply.status', 1)
  7795. ->where('job_apply.receiver_id', $user_id)
  7796. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7797. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7798. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7799. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7800. ->select('job_recruiting', 'job_recruiting.', '', '')
  7801. ->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')
  7802. ->orderBy('updated_at', 'desc')
  7803. // ->limit(5)
  7804. ->get();
  7805. // 职场机会 2
  7806. $job_resume = JobResume::where('job_resume.status', 1)
  7807. ->where('job_resume.receiver_id', $user_id)
  7808. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7809. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7810. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7811. ->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')
  7812. ->orderBy('updated_at', 'desc')
  7813. // ->limit(5)
  7814. ->get();
  7815. //获取5条用户待处理的投诉
  7816. $complaint_deal = Complaint::where('status', 2)
  7817. ->where('deal', 1)
  7818. ->whereJsonContains('re_user_ids', $user_id)
  7819. ->orderBy('updated_at', 'desc')
  7820. // ->limit(5)
  7821. ->get();
  7822. //获取 被通知者未读信息
  7823. $notice_unread = Notice::where('status', 2)
  7824. ->whereJsonContains('re_user_ids', $user_id)
  7825. //未读消息
  7826. ->where(function ($query) use ($user_id) {
  7827. $query->whereJsonDoesntContain('read_id', $user_id)
  7828. ->orWhereNull('read_id');
  7829. })
  7830. ->orderBy('updated_at', 'desc')
  7831. ->get();
  7832. $complaint_unread = Complaint::where('status', 2)
  7833. ->whereJsonContains('re_user_ids', $user_id)
  7834. //未读消息
  7835. ->where(function ($query) use ($user_id) {
  7836. $query->whereJsonDoesntContain('read_id', $user_id)
  7837. ->orWhereNull('read_id');
  7838. })
  7839. ->orderBy('updated_at', 'desc')
  7840. ->get();
  7841. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7842. $complany = Company::where('status', 1)
  7843. ->where('user_id', $user_id)
  7844. ->orderBy('updated_at', 'desc')
  7845. // ->limit(5)
  7846. ->get();
  7847. //获取5条单聊未读聊天消息
  7848. // $chat = ChatRecords::where('is_read', 0)
  7849. // ->where('user_id', $user_id)
  7850. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7851. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7852. // ->where('action', 'recieved')
  7853. // ->where('talk_type', 1)
  7854. // ->orderBy('created_at', 'desc')
  7855. // // ->limit(5)
  7856. // ->get();
  7857. //获取5条未读群聊信息
  7858. // $chat_group = ChatRecords::where('is_read', 0)
  7859. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7860. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7861. // ->where('user_id', $user_id)
  7862. // ->where('talk_type', 2)
  7863. // ->orderBy('created_at', 'desc')
  7864. // // ->limit(5)
  7865. // ->get();
  7866. //获取5条用户的待审核项目
  7867. $project = Project::where('status', 1)
  7868. ->where('user_id', $user_id)
  7869. ->orderBy('updated_at', 'desc')
  7870. // ->limit(5)
  7871. ->get();
  7872. // count($chat) + count($chat_group) +
  7873. $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)
  7874. + count($complany)
  7875. + count($project)
  7876. + count($notice_unread)
  7877. + count($complaint_unread)
  7878. // + count($chat) + count($chat_group)
  7879. ;
  7880. $result = [
  7881. 'apply_articale' => $apply_articale,
  7882. // 'chat' => $chat,
  7883. // 'chat_group' => $chat_group,
  7884. 'good' => $good,
  7885. 'notice' => $notice,
  7886. 'complaint' => $complaint,
  7887. 'book' => $book,
  7888. 'job_hunting' => $job_hunting,
  7889. 'job_recruiting' => $job_recruiting,
  7890. 'job_apply' => $job_apply,
  7891. 'job_resume' => $job_resume,
  7892. 'complaint_deal' => $complaint_deal,
  7893. 'complany' => $complany,
  7894. 'project' => $project,
  7895. 'notice_unread' => $notice_unread,
  7896. 'complaint_unread' => $complaint_unread,
  7897. 'count' => $count,
  7898. ];
  7899. } elseif ($type_id == 12) {
  7900. //最近的5篇已审的文章
  7901. $apply_articale = Article::where('status', 1)
  7902. ->where('admin_user_id', $user_id)
  7903. ->limit(5)->get();
  7904. //获取5条单聊未读聊天消息
  7905. $chat = ChatRecords::where('is_read', 0)
  7906. ->where('user_id', $user_id)
  7907. ->where('talk_type', 1)
  7908. ->orderBy('created_at', 'desc')
  7909. ->limit(5)->get();
  7910. //获取5条未读群聊信息
  7911. $chat_group = ChatRecords::where('is_read', 0)
  7912. ->where('user_id', $user_id)
  7913. ->where('talk_type', 2)
  7914. ->orderBy('created_at', 'desc')
  7915. ->limit(5)->get();
  7916. //获取5条用户的已审核商品
  7917. $good = Good::where('status', 2)
  7918. ->where('user_id', $user_id)
  7919. ->orderBy('updated_at', 'desc')
  7920. ->limit(5)->get();
  7921. //获取5条用户的book
  7922. $book = Book::where('status', 2)
  7923. ->where('user_id', $user_id)
  7924. ->orderBy('updated_at', 'desc')
  7925. ->limit(5)->get();
  7926. //获取5条用户的求职
  7927. //获取5条用户的求职 1
  7928. //count($chat) + count($chat_group)
  7929. $count = count($apply_articale) + count($good);
  7930. $result = [
  7931. 'apply_articale' => $apply_articale,
  7932. 'chat' => $chat,
  7933. 'chat_group' => $chat_group,
  7934. 'good' => $good,
  7935. 'book' => $book,
  7936. 'count' => $count,
  7937. ];
  7938. } elseif ($type_id == 13) {
  7939. //最近的5篇已审的文章
  7940. $apply_articale = Article::where('status', 1)
  7941. ->where('admin_user_id', $user_id)
  7942. ->limit(5)->get();
  7943. //获取5条单聊未读聊天消息
  7944. $chat = ChatRecords::where('is_read', 0)
  7945. ->where('user_id', $user_id)
  7946. ->where('talk_type', 1)
  7947. ->orderBy('created_at', 'desc')
  7948. ->limit(5)->get();
  7949. //获取5条未读群聊信息
  7950. $chat_group = ChatRecords::where('is_read', 0)
  7951. ->where('user_id', $user_id)
  7952. ->where('talk_type', 2)
  7953. ->orderBy('created_at', 'desc')
  7954. ->limit(5)->get();
  7955. //获取5条用户的已审核商品
  7956. $good = Good::where('status', 2)
  7957. ->where('user_id', $user_id)
  7958. ->orderBy('updated_at', 'desc')
  7959. ->limit(5)->get();
  7960. //count($chat) + count($chat_group) +
  7961. $count = count($apply_articale) + count($good);
  7962. $result = [
  7963. 'apply_articale' => $apply_articale,
  7964. 'chat' => $chat,
  7965. 'chat_group' => $chat_group,
  7966. 'good' => $good,
  7967. 'count' => $count,
  7968. ];
  7969. } elseif ($type_id == 14) {
  7970. //最近的5篇已审的文章
  7971. $apply_articale = Article::where('status', 1)
  7972. ->where('admin_user_id', $user_id)
  7973. // ->limit(5)
  7974. ->get();
  7975. //获取5条用户的已审核商品
  7976. $good = Good::where('status', 2)
  7977. ->where('user_id', $user_id)
  7978. ->orderBy('updated_at', 'desc')
  7979. // ->limit(5)
  7980. ->get();
  7981. $count = count($apply_articale) + count($good);
  7982. $result = [
  7983. 'apply_articale' => $apply_articale,
  7984. 'chat' => '',
  7985. 'chat_group' => '',
  7986. 'good' => $good,
  7987. 'count' => $count,
  7988. ];
  7989. } elseif ($type_id == 10000) {
  7990. //获取未审核的5篇文章
  7991. $apply_articale = Article::where('status', 0)
  7992. ->orderBy('updated_at', 'desc')
  7993. // ->limit(5)
  7994. ->get();
  7995. //获取5条单聊未读聊天消息
  7996. //获取5条单聊未读聊天消息
  7997. // $chat = ChatRecords::where('is_read', 0)
  7998. // ->where('user_id', $user_id)
  7999. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  8000. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  8001. // ->where('action', 'recieved')
  8002. // ->where('talk_type', 1)
  8003. // ->orderBy('created_at', 'desc')
  8004. // // ->limit(5)
  8005. // ->get();
  8006. // //获取5条未读群聊信息
  8007. // $chat_group = ChatRecords::where('is_read', 0)
  8008. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8009. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8010. // ->where('user_id', $user_id)
  8011. // ->where('talk_type', 2)
  8012. // ->orderBy('created_at', 'desc')
  8013. // // ->limit(5)
  8014. // ->get();
  8015. //获取5条用户的已审核商品
  8016. $good = Good::where('status', 1)
  8017. // ->where('user_id', $user_id)
  8018. ->orderBy('updated_at', 'desc')
  8019. // ->limit(5)
  8020. ->get();
  8021. //获取5条用户待审核的公告
  8022. $notice = Notice::where('status', 1)
  8023. ->orderBy('updated_at', 'desc')
  8024. // ->limit(5)
  8025. ->get();
  8026. //获取5条用户的待审核投诉
  8027. $complaint = Complaint::where('status', 1)
  8028. ->orderBy('updated_at', 'desc')
  8029. // ->limit(5)
  8030. ->get();
  8031. //获取5条用户的book
  8032. $book = Book::where('status', 1)
  8033. ->orderBy('updated_at', 'desc')
  8034. // ->limit(5)
  8035. ->get();
  8036. //获取5条用户的求职 1
  8037. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8038. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8039. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8040. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8041. ->orderBy('updated_at', 'desc')
  8042. // ->limit(5)
  8043. ->get();
  8044. //获取5条用户的求职 2
  8045. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8046. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8047. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8048. ->select('job_recruiting.*', '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. //人才库 1
  8053. $job_apply = JobApply::where('job_apply.status', 1)
  8054. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8055. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8056. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8057. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8058. ->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')
  8059. ->orderBy('updated_at', 'desc')
  8060. // ->limit(5)
  8061. ->get();
  8062. // 职场机会 2
  8063. $job_resume = JobResume::where('job_resume.status', 1)
  8064. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8065. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8066. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8067. ->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')
  8068. ->orderBy('updated_at', 'desc')
  8069. // ->limit(5)
  8070. ->get();
  8071. //待审核数据com pro
  8072. $complany = Company::where('status', 0)
  8073. ->orderBy('updated_at', 'desc')
  8074. // ->limit(5)
  8075. ->get();
  8076. $project = Project::where('status', 0)
  8077. ->orderBy('updated_at', 'desc')
  8078. // ->limit(5)
  8079. ->get();
  8080. $count =
  8081. // count($chat) +
  8082. // count($chat_group) +
  8083. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8084. // + count($job_apply)
  8085. // + count($job_resume)
  8086. + count($complany)
  8087. + count($project);
  8088. $result = [
  8089. 'apply_articale' => $apply_articale,
  8090. // 'chat' => $chat,
  8091. // 'chat_group' => $chat_group,
  8092. 'good' => $good,
  8093. 'notice' => $notice,
  8094. 'complaint' => $complaint,
  8095. 'book' => $book,
  8096. 'job_hunting' => $job_hunting,
  8097. 'job_recruiting' => $job_recruiting,
  8098. // 'job_apply' => $job_apply,
  8099. // 'job_resume' => $job_resume,
  8100. 'complany' => $complany,
  8101. 'project' => $project,
  8102. 'count' => $count,
  8103. ];
  8104. } elseif ($type_id == 20000) {
  8105. }
  8106. var_dump($type_id, '-----------------test---------');
  8107. return Result::success($result);
  8108. }
  8109. /**
  8110. * @param array $data
  8111. * @return array
  8112. */
  8113. public function getWebsiteProject(array $data): array
  8114. {
  8115. $categorys = json_decode($data['id'], true);
  8116. if (!empty($categorys)) {
  8117. $category_arr = $this->processArticlePro($data['website_id']);
  8118. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8119. $catiall = $category_arr['catiall'];
  8120. // return Result::success($catiall);
  8121. foreach ($categorys as $key => $val) {
  8122. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8123. $level = explode(',', $val['level'])[0];
  8124. $imgnum = explode(',', $val['level'])[1] ?? null;
  8125. $textnum = explode(',', $val['level'])[2] ?? null;
  8126. if ($level == 1) {
  8127. if (!empty($textnum) && $textnum > 0) {
  8128. $text_num = Project::where('level', $level)
  8129. ->where('website_id', $data['website_id'])
  8130. ->where('status', 1)
  8131. ->select(
  8132. 'project.id',
  8133. 'project.title',
  8134. 'project.description',
  8135. 'project.updated_at',
  8136. 'project.category_id',
  8137. 'project.cat_arr_id'
  8138. )
  8139. ->orderBy('updated_at', 'desc')
  8140. ->limit($textnum)
  8141. ->get()->all();
  8142. }
  8143. if (!empty($imgnum) && $imgnum > 0) {
  8144. $img_num = Project::where('level', $level)
  8145. ->where('website_id', $data['website_id'])
  8146. ->where('status', 1)
  8147. ->where('imgurl', '!=', '')
  8148. ->whereNotNull('imgurl')
  8149. ->select(
  8150. 'project.id',
  8151. 'project.title',
  8152. 'project.description',
  8153. 'project.updated_at',
  8154. 'project.imgurl as imgs',
  8155. 'project.category_id',
  8156. 'project.cat_arr_id'
  8157. )
  8158. ->orderBy('updated_at', 'desc')
  8159. ->limit($imgnum)
  8160. ->get()->all();
  8161. }
  8162. } else {
  8163. if (!empty($textnum) && $textnum > 0) {
  8164. $text_num = Project::where('website_id', $data['website_id'])
  8165. ->where('status', 1)
  8166. ->select(
  8167. 'project.id',
  8168. 'project.title',
  8169. 'project.description',
  8170. 'project.updated_at',
  8171. 'project.category_id',
  8172. 'project.cat_arr_id',
  8173. 'project.website_id',
  8174. 'project.updated_at',
  8175. 'project.created_at'
  8176. )
  8177. ->orderBy('updated_at', 'desc')
  8178. ->limit($textnum)
  8179. ->get()->all();
  8180. }
  8181. if (!empty($imgnum) && $imgnum > 0) {
  8182. $img_num = Project::where('website_id', $data['website_id'])
  8183. ->where('status', 1)
  8184. ->where('imgurl', '!=', '')
  8185. ->whereNotNull('imgurl')
  8186. ->select(
  8187. 'project.id',
  8188. 'project.title',
  8189. 'project.description',
  8190. 'project.updated_at',
  8191. 'project.imgurl as imgs',
  8192. 'project.category_id',
  8193. 'project.cat_arr_id'
  8194. )
  8195. ->orderBy('updated_at', 'desc')
  8196. ->limit($imgnum)
  8197. ->get()->all();
  8198. }
  8199. }
  8200. }
  8201. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8202. $category_ids = explode(',', $val['id'])[0];
  8203. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8204. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8205. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8206. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8207. $text_num = Project::whereIn('category_id', $category_arr)
  8208. ->where('website_id', $data['website_id'])
  8209. ->where('status', 1)
  8210. ->select(
  8211. 'project.id',
  8212. 'project.title',
  8213. 'project.description',
  8214. 'project.updated_at',
  8215. 'project.category_id',
  8216. 'project.cat_arr_id'
  8217. )
  8218. ->orderBy('updated_at', 'desc')
  8219. ->limit($cat_textnum)
  8220. ->get()->all();
  8221. }
  8222. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8223. $img_num = Project::whereIn('category_id', $category_arr)
  8224. ->where('website_id', $data['website_id'])
  8225. ->where('status', 1)
  8226. ->where('imgurl', '!=', '')
  8227. ->whereNotNull('imgurl')
  8228. ->select(
  8229. 'project.id',
  8230. 'project.title',
  8231. 'project.description',
  8232. 'project.updated_at',
  8233. 'project.imgurl as imgs',
  8234. 'project.category_id',
  8235. 'project.cat_arr_id'
  8236. )
  8237. ->orderBy('updated_at', 'desc')
  8238. ->limit($cat_imgnum)
  8239. ->get()->all();
  8240. }
  8241. }
  8242. if (!empty($img_num)) {
  8243. foreach ($img_num as $k => $v) {
  8244. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8245. $imgurl = json_decode($v['imgs'], true);
  8246. if (!empty($imgurl)) {
  8247. $img_num[$k]->imgurl = $imgurl[0];
  8248. }
  8249. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8250. }
  8251. }
  8252. if (!empty($text_num)) {
  8253. foreach ($text_num as $k => $v) {
  8254. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8255. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8256. }
  8257. }
  8258. $project[$key]['img_num'] = $img_num ?? [];
  8259. $project[$key]['text_num'] = $text_num ?? [];
  8260. }
  8261. }
  8262. if (empty($project)) {
  8263. return Result::error("暂无相关项目信息", 0);
  8264. }
  8265. return Result::success($project);
  8266. }
  8267. /**
  8268. * @param array $data
  8269. * @return array
  8270. */
  8271. public function getWebsiteProjectInfo(array $data): array
  8272. {
  8273. $project = Project::where('id', $data['id'])
  8274. ->where('status', 1)
  8275. ->where('website_id', $data['website_id'])
  8276. ->select('project.*')
  8277. ->first();
  8278. if (empty($project)) {
  8279. return Result::error("暂无相关项目信息", 0);
  8280. }
  8281. return Result::success($project);
  8282. }
  8283. /**
  8284. * @param array $data
  8285. * @return array
  8286. */
  8287. public function getWebsiteProjectList(array $data): array
  8288. {
  8289. $where = [];
  8290. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8291. $where['category_id'] = $data['category_id'];
  8292. }
  8293. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8294. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8295. }
  8296. $query = Project::where($where)
  8297. ->where('status', 1)
  8298. ->where('website_id', $data['website_id'])
  8299. ->select(
  8300. 'project.id',
  8301. 'project.title',
  8302. 'project.description',
  8303. 'project.imgurl as imgs',
  8304. 'project.category_id',
  8305. 'project.cat_arr_id'
  8306. )
  8307. ->orderBy('updated_at', 'desc');
  8308. $count = $query->count();
  8309. $project = $query->clone()
  8310. ->offset(($data['page'] - 1) * $data['pageSize'])
  8311. ->limit($data['pageSize'])
  8312. ->get()->all();
  8313. if (empty($project)) {
  8314. return Result::error("暂无相关项目信息", 0);
  8315. }
  8316. $categorys = $this->processArticlePro($data['website_id']);
  8317. $catiall = $categorys['catiall'];
  8318. foreach ($project as $key => $val) {
  8319. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8320. if (!empty($val['imgs'])) {
  8321. $imgurl = json_decode($val['imgs'], true);
  8322. if (!empty($imgurl)) {
  8323. $project[$key]->imgurl = $imgurl[0];
  8324. }
  8325. } else {
  8326. $project[$key]->imgurl = '';
  8327. }
  8328. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8329. }
  8330. $result = [
  8331. 'rows' => $project,
  8332. 'count' => $count,
  8333. ];
  8334. return Result::success($result);
  8335. }
  8336. /**
  8337. * @param array $data
  8338. * @return array
  8339. */
  8340. public function getWebsiteCategoryJob(array $data): array
  8341. {
  8342. $categorys = json_decode($data['id'], true);
  8343. if (!empty($categorys)) {
  8344. $category_arr = $this->processArticlePro($data['website_id']);
  8345. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8346. $catiall = $category_arr['catiall'];
  8347. foreach ($categorys as $key => $val) {
  8348. if (isset($val['id']) && !empty($val['id'])) {
  8349. $catid = explode(',', $val['id'])[0] ?? null;
  8350. $type = explode(',', $val['id'])[1] ?? null;
  8351. $textnum = explode(',', $val['id'])[2] ?? null;
  8352. }
  8353. // 4:招聘;5:求职;
  8354. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8355. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8356. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8357. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8358. ->where('job_recruiting.status', 1)
  8359. ->where('job_recruiting.website_id', $data['website_id'])
  8360. ->select(
  8361. 'job_recruiting.id',
  8362. 'job_recruiting.title',
  8363. 'job_company.business_name',
  8364. 'job_recruiting.updated_at',
  8365. 'job_recruiting.cat_arr_id',
  8366. 'job_recruiting.keyword',
  8367. 'job_recruiting.description'
  8368. )
  8369. ->orderBy('job_recruiting.updated_at', 'desc')
  8370. ->limit($textnum)
  8371. ->get()->all();
  8372. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8373. // 状态 审核状态,1待审核2已审核3已拒绝
  8374. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8375. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8376. ->where('job_hunting.status', 2)
  8377. ->where('job_hunting.website_id', $data['website_id'])
  8378. ->select(
  8379. 'job_hunting.id',
  8380. 'job_hunting.name',
  8381. 'job_hunting.cat_arr_id',
  8382. 'job_position.zwname as job_name',
  8383. 'job_hunting.updated_at',
  8384. // 'job_hunting.keyword',
  8385. 'job_hunting.slelf_evaluation'
  8386. )
  8387. ->orderBy('updated_at', 'desc')
  8388. ->limit($textnum)
  8389. ->get()->all();
  8390. } else {
  8391. $job = [];
  8392. }
  8393. // var_dump($catid.'222uuuuuuu'.$key);
  8394. if (!empty($job)) {
  8395. foreach ($job as $k => $value) {
  8396. if (isset($value->cat_arr_id)) {
  8397. $catArr = json_decode($value->cat_arr_id, true);
  8398. $catId = end($catArr);
  8399. } else {
  8400. continue;
  8401. }
  8402. if (isset($catiall[$catId])) {
  8403. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8404. }
  8405. }
  8406. }
  8407. // var_dump($catid.'xxxxx'.$key);
  8408. $result[$key] = $job ?? [];
  8409. }
  8410. }
  8411. if (empty($result)) {
  8412. return Result::error("暂无相关分类信息", 0);
  8413. }
  8414. return Result::success($result);
  8415. }
  8416. /**
  8417. * 发送消息
  8418. * @param array $messageData
  8419. * @return void
  8420. */
  8421. public function sendMessage($messageData)
  8422. {
  8423. $msg = [
  8424. 'talk_type' => $messageData['talk_type'],
  8425. 'title' => $messageData['title'],
  8426. 'content' => $messageData['content'],
  8427. 'messageType' => $messageData['messageType'],
  8428. 'user_id' => $messageData['user_id'] ?? '',
  8429. 'time' => microtime(),
  8430. ];
  8431. $message = new MqProducer($msg);
  8432. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8433. $producer->produce($message);
  8434. }
  8435. /**
  8436. * 行业分类管理 ------1121
  8437. * @param array $data
  8438. * @return array
  8439. */
  8440. public function getJobIndustryList(array $data): array
  8441. {
  8442. $page = $data['page'] ?? 1;
  8443. $page_size = $data['page_size'] ?? 10;
  8444. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8445. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8446. } else {
  8447. $where = [];
  8448. }
  8449. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8450. $query->where([$where]); // 修复:将条件包装成二维数组
  8451. })
  8452. ->orderBy('updated_at', 'desc');
  8453. $count = $rs_query->count();
  8454. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8455. $result = [
  8456. 'count' => $count,
  8457. 'list' => $hy,
  8458. ];
  8459. if (empty($hy)) {
  8460. return Result::success('暂无数据');
  8461. }
  8462. return Result::success($result);
  8463. }
  8464. /**
  8465. * 添加行业分类
  8466. * @param array $data
  8467. * @return array
  8468. */
  8469. public function addJobIndustry(array $data): array
  8470. {
  8471. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8472. if (!empty($hy_name)) {
  8473. return Result::error('行业分类已存在');
  8474. }
  8475. $hy = JobIndustry::insertGetId($data);
  8476. if (empty($hy)) {
  8477. return Result::error('添加失败');
  8478. }
  8479. return Result::success($hy);
  8480. }
  8481. /**
  8482. * 更新行业分类
  8483. * @param array $data
  8484. * @return array
  8485. */
  8486. public function upJobIndustry(array $data): array
  8487. {
  8488. $hy_query = JobIndustry::get();
  8489. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8490. $hy_names = $hy_query->pluck('hyname')->toArray();
  8491. if (!in_array($data['hyid'], $hy_ids)) {
  8492. return Result::error('行业分类不存在');
  8493. }
  8494. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8495. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8496. // return Result::success($other_key_hy);
  8497. unset($hy_names[$other_key_hy]);
  8498. if (in_array($data['hyname'], $hy_names)) {
  8499. return Result::error('行业分类名称已存在');
  8500. }
  8501. }
  8502. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8503. if (empty($hy)) {
  8504. return Result::error('更新失败');
  8505. }
  8506. return Result::success($hy);
  8507. }
  8508. /**
  8509. * 删除行业分类
  8510. * @param array $data
  8511. * @return array
  8512. */
  8513. public function delJobIndustry(array $data): array
  8514. {
  8515. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8516. if (empty($hy_id)) {
  8517. return Result::error('行业分类不存在');
  8518. }
  8519. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8520. if (empty($hy)) {
  8521. return Result::error('删除失败');
  8522. }
  8523. return Result::success($hy);
  8524. }
  8525. /**
  8526. * 职位分类-列表
  8527. * @param array $data
  8528. * @return array
  8529. */
  8530. public function getJobPositionList(array $data): array
  8531. {
  8532. $page = $data['page'] ?? 1;
  8533. $page_size = $data['page_size'] ?? 10;
  8534. $where = [];
  8535. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8536. $zwids = JobPosition::where('zwpid', 0)
  8537. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8538. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8539. })
  8540. ->orderBy('updated_at', 'desc')
  8541. ->pluck('zwid')
  8542. // ->get()
  8543. ->toArray();
  8544. }
  8545. if (isset($data['childname']) && !empty($data['childname'])) {
  8546. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8547. ->when(!empty($data['childname']), function ($query) use ($data) {
  8548. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8549. })
  8550. ->orderBy('updated_at', 'desc')
  8551. ->pluck('zwpid')
  8552. // ->get()
  8553. ->toArray();
  8554. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8555. $child_zwids = array_intersect($zwids, $child_zwids);
  8556. }
  8557. $zwids = array_values(array_unique($child_zwids));
  8558. }
  8559. $zwids = $zwids ?? null;
  8560. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8561. $query->whereIn('zwid', $zwids);
  8562. })
  8563. ->where('zwpid', 0)
  8564. ->count();
  8565. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8566. $query->whereIn('zwid', $zwids);
  8567. })
  8568. ->where('zwpid', 0)
  8569. ->orderBy('updated_at', 'desc')
  8570. ->offset(($page - 1) * $page_size)
  8571. ->limit($page_size)->get()
  8572. ->map(function ($item) use ($data) {
  8573. $item->children = $item->where('zwpid', $item->zwid)
  8574. ->when(!empty($data['childname']), function ($query) use ($data) {
  8575. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8576. })
  8577. ->orderBy('updated_at', 'desc')
  8578. ->get();
  8579. return $item;
  8580. })
  8581. ->all();
  8582. $result = [
  8583. 'count' => $count,
  8584. 'list' => $position,
  8585. ];
  8586. if (empty($result)) {
  8587. return Result::success('暂无数据');
  8588. }
  8589. return Result::success($result);
  8590. }
  8591. /**
  8592. * 职位分类-添加
  8593. * @param array $data
  8594. * @return array
  8595. */
  8596. public function addJobPosition(array $data): array
  8597. {
  8598. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8599. ->where('zwname', $data['zwname'])->first(['zwid']);
  8600. if (!empty($zw_name)) {
  8601. return Result::error('职位分类已存在');
  8602. }
  8603. $zw = JobPosition::insertGetId($data);
  8604. if(empty($zw)){
  8605. return Result::error('添加失败');
  8606. }
  8607. return Result::success($zw);
  8608. }
  8609. /**
  8610. * 更新职位分类
  8611. * @param array $data
  8612. * @return array
  8613. */
  8614. public function upJobPosition(array $data): array
  8615. {
  8616. $zw_position = JobPosition::get();
  8617. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8618. return Result::error('职位分类不存在');
  8619. }
  8620. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8621. ->where('zwpid', $data['zwpid'])
  8622. ->where('zwname', $data['zwname'])->first();
  8623. if (!empty($zw_name)) {
  8624. return Result::error('职位分类已存在');
  8625. }
  8626. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8627. if (empty($result)) {
  8628. return Result::error('更新失败');
  8629. }
  8630. return Result::success($result);
  8631. }
  8632. /**
  8633. * 删除职位分类
  8634. * @param array $data
  8635. * @return array
  8636. */
  8637. public function delJobPosition(array $data): array
  8638. {
  8639. $zw_jobposition = JobPosition::get();
  8640. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8641. if (empty($zw_id)) {
  8642. return Result::error('职位分类不存在');
  8643. }
  8644. if($zw_id->zwpid == 0){
  8645. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8646. if(!empty($zw_job)){
  8647. return Result::error('请先删除子分类');
  8648. }
  8649. }
  8650. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8651. if (empty($result)) {
  8652. return Result::error('删除失败');
  8653. }
  8654. return Result::success($result);
  8655. }
  8656. /**
  8657. * 网民留言-添加
  8658. * @param array $data
  8659. * @return array
  8660. */
  8661. public function addMessage(array $data): array
  8662. {
  8663. $user = User::where('id', $data['user_id'])->first();
  8664. if (empty($user)) {
  8665. return Result::error('用户不存在');
  8666. }
  8667. if($user['type_id'] == 10000){
  8668. $data['status'] = 1;
  8669. }else{
  8670. $data['status'] = 0;
  8671. }
  8672. if ($data['keyword'] == '') {
  8673. //提取标题+内容中的关键词
  8674. $data['keyword'] = $data['title'];
  8675. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8676. Jieba::init(); // 初始化 jieba-php
  8677. Finalseg::init();
  8678. $segList = Jieba::cut($data['keyword']);
  8679. $segList1 = array_slice($segList, 0, 8);
  8680. $data['keyword'] = implode(',', $segList1);
  8681. }
  8682. if ($data['description'] == '') {
  8683. //提取内容中的描述
  8684. $content = $data['content'];
  8685. // 去除 <style> 和 <script> 标签及其内容
  8686. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8687. // 去除所有 HTML 标签
  8688. $content = strip_tags($content);
  8689. // 去除 HTML 实体
  8690. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8691. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8692. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8693. // 去除多余空白
  8694. $content = preg_replace('/\s+/u', '', $content);
  8695. // 截取 100 个字符
  8696. $data['description'] = mb_substr($content, 0, 100);
  8697. }
  8698. if(!empty($data['reply'])){
  8699. $data['reply_userid'] = $data['user_id'];
  8700. }
  8701. $result = Message::insertGetId($data);
  8702. if(empty($result)){
  8703. return Result::error('添加失败');
  8704. }
  8705. return Result::success($result);
  8706. }
  8707. /**
  8708. * 网民留言-更新
  8709. * @param array $data
  8710. * @return array
  8711. */
  8712. public function upMessage(array $data): array
  8713. {
  8714. $user = User::where('id', $data['user_id'])->first();
  8715. if (empty($user)) {
  8716. return Result::error('用户不存在');
  8717. }
  8718. if($user['type_id'] == 10000){
  8719. $data['status'] = 1;
  8720. }else{
  8721. $data['status'] = 0;
  8722. }
  8723. $message = Message::where('id', $data['id'])->first();
  8724. if (empty($message)) {
  8725. return Result::error('留言不存在');
  8726. }
  8727. if($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000){
  8728. return Result::error('非留言人不能更新');
  8729. }
  8730. if ($data['keyword'] == '') {
  8731. //提取标题+内容中的关键词
  8732. $data['keyword'] = $data['title'];
  8733. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8734. Jieba::init(); // 初始化 jieba-php
  8735. Finalseg::init();
  8736. $segList = Jieba::cut($data['keyword']);
  8737. $segList1 = array_slice($segList, 0, 8);
  8738. $data['keyword'] = implode(',', $segList1);
  8739. }
  8740. if ($data['description'] == '') {
  8741. //提取内容中的描述
  8742. $content = $data['content'];
  8743. // 去除 <style> 和 <script> 标签及其内容
  8744. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8745. // 去除所有 HTML 标签
  8746. $content = strip_tags($content);
  8747. // 去除 HTML 实体
  8748. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8749. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8750. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8751. // 去除多余空白
  8752. $content = preg_replace('/\s+/u', '', $content);
  8753. // 截取 100 个字符
  8754. $data['description'] = mb_substr($content, 0, 100);
  8755. }
  8756. unset($data['id']);
  8757. if(!empty($data['reply'])){
  8758. $data['reply_userid'] = $data['user_id'];
  8759. unset($data['user_id']);
  8760. }
  8761. $result = Message::where('id', $message['id'])->update($data);
  8762. if (empty($result)) {
  8763. return Result::error('更新失败');
  8764. }
  8765. return Result::success($result);
  8766. }
  8767. /**
  8768. * 网民留言-删除
  8769. * @param array $data
  8770. * @return array
  8771. */
  8772. public function delMessage(array $data): array
  8773. {
  8774. $result = Message::where('id', $data['id'])->delete();
  8775. if (empty($result)) {
  8776. return Result::error('删除失败');
  8777. }
  8778. return Result::success($result);
  8779. }
  8780. /**
  8781. * 网民留言-更新状态
  8782. * @param array $data
  8783. * @return array
  8784. */
  8785. public function upMessageStatus(array $data): array
  8786. {
  8787. $message = Message::where('id', $data['id'])->first();
  8788. if (empty($message)) {
  8789. return Result::error('留言不存在!');
  8790. }
  8791. unset($data['id']);
  8792. unset($data['user_id']);
  8793. if($data['status'] != 2){
  8794. $data['reason'] = null;
  8795. }
  8796. $result = Message::where('id', $message['id'])->update($data);
  8797. if (empty($result)) {
  8798. return Result::error('留言更新失败!');
  8799. }
  8800. return Result::success($result);
  8801. }
  8802. /**
  8803. * 网民留言-获取详情
  8804. * @param array $data
  8805. * @return array
  8806. */
  8807. public function getMessageInfo(array $data): array
  8808. {
  8809. $result = Message::where('message.id', $data['id'])
  8810. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8811. ->select('message.*', 'website_column.column_arr_id')
  8812. ->first();
  8813. if (empty($result)) {
  8814. return Result::error('留言不存在!');
  8815. }
  8816. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8817. return Result::success($result);
  8818. }
  8819. /**
  8820. * 网民留言-获取列表
  8821. * @param array $data
  8822. * @return array
  8823. */
  8824. public function getMessageList(array $data): array
  8825. {
  8826. $where = [];
  8827. if($data['is_master'] == 1){
  8828. $where['message.status'] = 1;
  8829. }else if($data['is_master'] == 2){
  8830. $where['message.status'] = 2;
  8831. }else if($data['is_master'] == 3){
  8832. $where['message.status'] = 0;
  8833. }
  8834. $user = User::where('id', $data['user_id'])->first();
  8835. if (empty($user)) {
  8836. return Result::error('用户不存在');
  8837. }
  8838. $column_arr_id = [];
  8839. if($user['type_id'] != 10000 && !empty($data['website_id'])){
  8840. $where['message.user_id'] = $data['user_id'];
  8841. $web = Website::where('id',$data['website_id'])->first('website_column_arr_id');
  8842. if(empty($web)){
  8843. return Result::error('此网站未关联任何网站属性!');
  8844. }
  8845. $column_arr_id = json_decode($web['website_column_arr_id'],true);
  8846. }
  8847. if(!empty($data['title'])){
  8848. array_push($where, ['message.title', 'like', '%'.$data['title'].'%']);
  8849. }
  8850. $result = Message::when($data['is_master'] == 0, function ($query) {
  8851. $query->whereIn('message.status', [0, 2]);
  8852. })
  8853. ->when(!empty($where), function ($query) use ($where) {
  8854. $query->where($where);
  8855. })
  8856. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  8857. ->select('message.*', 'user.nickname')
  8858. ->orderBy('message.updated_at', 'desc')
  8859. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8860. if(empty($result->items())) {
  8861. return Result::error('留言不存在!');
  8862. }
  8863. $result = [
  8864. 'data' => $result->items(),
  8865. 'count' => $result->total(),
  8866. ];
  8867. if(!empty($column_arr_id) && $user['type_id'] != 10000){
  8868. foreach($result['data'] as $key => $value){
  8869. if(in_array($value['column_id'], $column_arr_id)){
  8870. $result['data'][$key]['is_update'] = 1;
  8871. }else{
  8872. $result['data'][$key]['is_update'] = 0;
  8873. }
  8874. }
  8875. }
  8876. return Result::success($result);
  8877. }
  8878. /**
  8879. * 网民留言-检查是否可编辑
  8880. * @param array $data
  8881. * @return array
  8882. */
  8883. public function checkMessageEdit(array $data): array
  8884. {
  8885. $message = Message::where('id', $data['id'])->first();
  8886. if (empty($message)) {
  8887. return Result::error('留言不存在!');
  8888. }
  8889. $web = Website::where('id', $data['website_id'])->first();
  8890. if (empty($web)) {
  8891. return Result::error('网站不存在!');
  8892. }
  8893. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8894. if(empty($column_arr)){
  8895. return Result::error('该网站未关联任何属性!');
  8896. }
  8897. if(!in_array($message['column_id'], $column_arr)){
  8898. return Result::error('不可编辑');
  8899. }
  8900. return Result::success('可编辑');
  8901. }
  8902. /**
  8903. * 调研选题-获取所有Researchers
  8904. * @param array $data
  8905. * @return array
  8906. */
  8907. public function getAllResearcher(array $data): array
  8908. {
  8909. $users = User::where('type_id', 4)
  8910. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  8911. ->select('user.id', 'user_info.real_name','user_info.number')
  8912. ->get()->toArray();
  8913. if (empty($users)) {
  8914. return Result::error('Researchers不存在!');
  8915. }
  8916. $num_key = array_search($data['user_id'], array_column($users, 'id'));
  8917. if(!empty($num_key)){
  8918. $result['number'] = $users[$num_key]['number'] ?? '';
  8919. }
  8920. $result['users'] = $users;
  8921. $result['user_id'] = $data['user_id'];
  8922. return Result::success($result);
  8923. }
  8924. /**
  8925. * 调研选题-添加
  8926. * @param array $data
  8927. * @return array
  8928. */
  8929. public function addResearchTopic(array $data): array
  8930. {
  8931. $user = User::where('id', $data['user_id'])->first();
  8932. if (empty($user)) {
  8933. return Result::error('用户不存在');
  8934. }
  8935. if($user['type_id'] == 10000){
  8936. $data['status'] = 1;
  8937. }else{
  8938. $data['status'] = 0;
  8939. }
  8940. if ($data['keyword'] == '') {
  8941. //提取标题+内容中的关键词
  8942. $data['keyword'] = $data['title'];
  8943. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8944. Jieba::init(); // 初始化 jieba-php
  8945. Finalseg::init();
  8946. $segList = Jieba::cut($data['keyword']);
  8947. $segList1 = array_slice($segList, 0, 8);
  8948. $data['keyword'] = implode(',', $segList1);
  8949. }
  8950. if ($data['description'] == '') {
  8951. //提取内容中的描述
  8952. $content = $data['content'];
  8953. // 去除 <style> 和 <script> 标签及其内容
  8954. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8955. // 去除所有 HTML 标签
  8956. $content = strip_tags($content);
  8957. // 去除 HTML 实体
  8958. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8959. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8960. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8961. // 去除多余空白
  8962. $content = preg_replace('/\s+/u', '', $content);
  8963. // 截取 100 个字符
  8964. $data['description'] = mb_substr($content, 0, 100);
  8965. }
  8966. $data['level'] = empty($data['level']) ? null : $data['level'];
  8967. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  8968. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  8969. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  8970. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  8971. unset($data['users_id']);
  8972. // return Result::success($data);
  8973. $result = ResearchTopic::insertGetId($data);
  8974. if (empty($result)) {
  8975. return Result::error('添加失败');
  8976. }
  8977. $users = json_decode($data['users_id'] ?? '[]',true);
  8978. if(!empty($users)){
  8979. foreach($users as $key => $value){
  8980. $users[$key]['user_id'] = $value;
  8981. $users[$key]['retopic_id'] = $result;
  8982. }
  8983. $retopic_user = RetopicUser::insert($users);
  8984. }
  8985. return Result::success($result);
  8986. }
  8987. }