NewsService.php 314 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. // $rep = Article::where($where)
  396. // ->whereNotIn('article.status', [404])
  397. // ->when($status1, function ($query) use ($status1) {
  398. // if (isset($status1) && $status1) {
  399. // $query->whereIn('article.status', $status1);
  400. // }
  401. // })
  402. // ->leftJoin('category', 'article.catid', 'category.id')
  403. // ->leftJoin('website_category', function ($join) {
  404. // $join->on('article.web_site_id', '=', 'website_category.website_id')
  405. // ->on('article.catid', '=', 'website_category.category_id');
  406. // })
  407. // ->when($type_id != 10000 && !empty($data['website_id']), function ($query) use ($data) {
  408. // $query->leftJoin('article_ignore', function ($join) use ($data) {
  409. // $join->on('article.id', '=', 'article_ignore.article_id')
  410. // ->where('article_ignore.website_id', $data['website_id']);
  411. // });
  412. // })
  413. // ->select("article.*", "category.name as category_name", "website_category.alias",
  414. // Db::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time'))
  415. // ->orderBy("article.updated_at", "desc")
  416. // ->limit($data['pageSize'])
  417. // ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  418. //
  419. $query = Article::where($where)
  420. ->whereNotIn('article.status', [404])
  421. ->when($status1, function ($query) use ($status1) {
  422. if (isset($status1) && $status1) {
  423. $query->whereIn('article.status', $status1);
  424. }
  425. })
  426. ->leftJoin('category', 'article.catid', 'category.id')
  427. ->leftJoin('website_category', function ($join) {
  428. $join->on('article.web_site_id', '=', 'website_category.website_id')
  429. ->on('article.catid', '=', 'website_category.category_id');
  430. });
  431. if ($type_id != 10000 && !empty($data['website_id'])) {
  432. $query = $query
  433. ->leftJoin('article_ignore', function ($join) use ($data) {
  434. $join->on('article.id', '=', 'article_ignore.article_id')
  435. ->where('article_ignore.website_id', $data['website_id']);
  436. })
  437. ->select("article.*", "category.name as category_name", "website_category.alias",'article_ignore.c_show_time');
  438. } else {
  439. $query = $query
  440. ->select("article.*", "category.name as category_name", "website_category.alias");
  441. }
  442. $count = $query->count();
  443. $rep = $query
  444. ->orderBy("article.updated_at", "desc")
  445. ->limit($data['pageSize'])
  446. ->offset(($data['page'] - 1) * $data['pageSize'])
  447. ->get();
  448. $data = [
  449. 'rows' => $rep->toArray(),
  450. 'count' => $count,
  451. ];
  452. if (empty($rep)) {
  453. return Result::error("没有信息数据");
  454. }
  455. return Result::success($data);
  456. }
  457. /**
  458. * @param array $data
  459. * @return array
  460. */
  461. public function addArticle(array $data): array
  462. {
  463. var_dump($data, '----------12-----------1');
  464. // ------c_show_time********add***1****
  465. $is_collect = $data['is_collect'] ?? 0;
  466. $user_type = $data['user_type'];
  467. unset($data['is_collect']);
  468. unset($data['user_type']);
  469. // ------c_show_time********add***1****
  470. unset($data['nav_add_pool_id']);
  471. // unset($data['commend_id']);
  472. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  473. Db::beginTransaction();
  474. try {
  475. //处理投票
  476. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  477. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  478. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  479. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  480. unset($data['is_survey']);
  481. unset($data['survey_name']);
  482. unset($data['suvey_array']);
  483. unset($data['website_id']);
  484. unset($data['web_site_id']);
  485. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  486. if ($data['hits'] == '') {
  487. $data['hits'] = 0;
  488. }
  489. if ($data['is_original'] == '') {
  490. $data['is_original'] = 0;
  491. }
  492. if ($data['status'] == '') {
  493. $data['status'] = 0;
  494. }
  495. $articleData = $data;
  496. unset($articleData['content']);
  497. //自动处理缩略图、关键字、描述
  498. if ($articleData['imgurl'] == '') {
  499. //如果没有图,设置level=0
  500. $levelArr = json_decode($articleData['level'], true);
  501. var_dump($levelArr, '----------levelArr-----------1');
  502. //content中提取图片第一个图,正则提取
  503. // -------采集器相关优化-----
  504. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  505. if($is_collect == 1){
  506. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  507. }else{
  508. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  509. }
  510. // -------采集器相关优化-----
  511. preg_match_all($reg, $data['content'], $matches);
  512. if (isset($matches[1][0])) {
  513. //截取varchar240
  514. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  515. //如果有图,设置level=3
  516. if (!in_array(3, $levelArr)) {
  517. $levelArr[] = 3;
  518. }
  519. $articleData['level'] = json_encode($levelArr);
  520. } else {
  521. if (!in_array(0, $levelArr)) {
  522. $levelArr[] = 0;
  523. }
  524. $articleData['level'] = json_encode($levelArr);
  525. }
  526. }
  527. var_dump($articleData['level'], '----------$articleData[level]----------1');
  528. if ($articleData['keyword'] == '') {
  529. //提取标题+内容中的关键词
  530. $articleData['keyword'] = $data['title'];
  531. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  532. Jieba::init(); // 初始化 jieba-php
  533. Finalseg::init();
  534. $segList = Jieba::cut($articleData['keyword']);
  535. $segList1 = array_slice($segList, 0, 8);
  536. $articleData['keyword'] = implode(',', $segList1);
  537. }
  538. if ($articleData['introduce'] == '') {
  539. //提取内容中的描述
  540. $content = $data['content'];
  541. // 去除 <style> 和 <script> 标签及其内容
  542. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  543. // 去除所有 HTML 标签
  544. $content = strip_tags($content);
  545. // 去除 HTML 实体
  546. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  547. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  548. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  549. // 去除多余空白
  550. $content = preg_replace('/\s+/u', '', $content);
  551. // 截取 100 个字符
  552. $articleData['introduce'] = mb_substr($content, 0, 100);
  553. }
  554. if ($articleData['status'] == 0) {
  555. $this->sendMessage([
  556. 'talk_type' => 100,
  557. 'title' => $articleData['title'],
  558. 'content' => '提交了审核',
  559. 'messageType' => 2,
  560. ]);
  561. }
  562. $id = Article::insertGetId($articleData);
  563. if (!$id) {
  564. throw new \Exception('文章插入失败');
  565. }
  566. $articleDataContent = [
  567. 'article_id' => $id,
  568. 'content' => $data['content'],
  569. ];
  570. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  571. if (!$contentInsertId) {
  572. throw new \Exception('文章内容插入失败');
  573. }
  574. // ------c_show_time********add***2****
  575. // 直接使用当前系统时间,不再强制添加8小时
  576. $now = date('Y-m-d H:i:s');
  577. if($user_type == 10000 || $is_collect == 1){
  578. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  579. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  580. if (!isset($data['catid'])) {
  581. throw new \Exception('缺少必要字段:catid');
  582. }
  583. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  584. $web = WebsiteCategory::where('category_id', $data['catid'])
  585. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  586. ->select('website_id',
  587. 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'))
  588. ->get();
  589. // $id = 225; -----测试开启
  590. // 采集来的文章,错开时间在两小时之内发布
  591. if($user_type == 10000 && $is_collect == 1){
  592. $web_num = $web->where('is_core', '!=', 2)->count();
  593. $waiting_interval = 10;
  594. if($web_num > 12){
  595. // 若网站数量大于12个,则每个网站间隔时间取均值
  596. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  597. $waiting_interval = 120 / max(1, $web_num);
  598. }
  599. $time = 0;
  600. }else{
  601. // 非核心站与核心站----显示时间-----间隔
  602. $time = 20;
  603. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  604. $waiting_interval = 5;
  605. }
  606. // 将 Hyperf\Database\Model\Collection 转换为数组
  607. $webArray = $web->toArray();
  608. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  609. // 检查 $item 对象是否有 is_core 属性
  610. if (!isset($item['is_core'])) {
  611. throw new \Exception('$item 对象缺少 is_core 属性');
  612. }
  613. // 当 is_core 为 2 时,则表示此网站不存在
  614. if ($item['is_core'] == 2) {
  615. return null;
  616. }
  617. if($is_collect == 1){
  618. // 采集来的文章,错开时间在两小时之内发布
  619. // $time = 0;
  620. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  621. $time += $waiting_interval;
  622. }else if($item['is_core'] == 1){
  623. // 当 is_core 为 1 时,则表示此网站是核心站
  624. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  625. }else{
  626. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  627. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  628. if ($item['is_core'] == 0) {
  629. $time += $waiting_interval;
  630. }
  631. }
  632. return [
  633. 'article_id' => $id,
  634. 'website_id' => $item['website_id'],
  635. 'c_show_time' => $c_show_time,
  636. // 'is_core' => $item['is_core'],
  637. // 'time' => $time
  638. ];
  639. }, array_keys($webArray), $webArray)));
  640. // Db::commit();
  641. // return Result::success($article_ignore);
  642. if(!empty($article_ignore)){
  643. $article_ignores = ArticleIgnore::insert($article_ignore);
  644. if(!$article_ignores){
  645. throw new \Exception('c端展示时间插入失败');
  646. }
  647. }
  648. }
  649. // ------c_show_time********add***2****
  650. //处理投票
  651. if ($is_survey == 1) {
  652. //生成年月日时分秒+8位随机数
  653. $uuid = date('YmdHis') . rand(10000000, 99999999);
  654. var_dump($suvey_array, 'suvey_array________');
  655. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  656. var_dump($suveys_array, '---------------------1');
  657. var_dump($suvey_array, '---------------------2');
  658. $suvey_data = [];
  659. foreach ($suveys_array as $key => $value) {
  660. if ($value == '') {
  661. continue;
  662. }
  663. if (is_array($value)) {
  664. $suvey_data[] = [
  665. 'sur_id' => $uuid,
  666. 'art_id' => $id,
  667. 'website_id' => $website_id ?? 2,
  668. 'survey_name' => $survey_name,
  669. 'choice_name' => $value[1],
  670. 'is_other' => 1,
  671. 'other_id' => 0,
  672. 'results' => 0,
  673. ];
  674. } else {
  675. $suvey_data[] = [
  676. 'sur_id' => $uuid,
  677. 'art_id' => $id,
  678. 'website_id' => $website_id ?? 2,
  679. 'survey_name' => $survey_name,
  680. 'choice_name' => $value,
  681. 'is_other' => 0,
  682. 'other_id' => 0,
  683. 'results' => 0,
  684. ];
  685. }
  686. if (empty($suvey_data)) {
  687. throw new \Exception("投票数据为空");
  688. }
  689. }
  690. $result = ArticleSurvey::insert($suvey_data);
  691. if (!$result) {
  692. throw new \Exception("投票失败,ArticleSurvey插入失败");
  693. }
  694. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  695. if (!$result) {
  696. throw new \Exception("投票失败,更新主表失败");
  697. }
  698. }
  699. Db::commit();
  700. return Result::success(['id' => $id]);
  701. } catch (\Throwable $ex) {
  702. Db::rollBack();
  703. var_dump($ex->getMessage());
  704. return Result::error("创建失败", 0);
  705. }
  706. }
  707. /**
  708. * @param array $data
  709. * @return array
  710. */
  711. public function delArticle(array $data): array
  712. {
  713. // ------c_show_time********del*******
  714. Db::beginTransaction();
  715. try{
  716. $article = Article::where(['id' => $data['id']])->delete();
  717. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  718. if (!$article) {
  719. throw new \Exception("删除失败,文章删除失败");
  720. }
  721. //survey投票删除
  722. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  723. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  724. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  725. // 若文章详情删除失败,抛出异常
  726. if (!$article_data) {
  727. throw new \Exception("删除失败,文章详情删除失败");
  728. }
  729. Db::commit(); // 所有操作成功,提交事务
  730. }catch (\Throwable $ex) {
  731. Db::rollBack();
  732. var_dump($ex->getMessage());
  733. return Result::error("删除失败: " . $ex->getMessage(), 0);
  734. }
  735. // ------c_show_time********del*******
  736. if (!$article) {
  737. return Result::error("删除失败");
  738. }
  739. return Result::success($article);
  740. }
  741. /**
  742. * @param array $data
  743. * @return array
  744. */
  745. public function updateArticle(array $data): array
  746. {
  747. var_dump($data, '----------12-----------1');
  748. Db::beginTransaction();
  749. // ------c_show_time********up*******
  750. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  751. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  752. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  753. $web = WebsiteCategory::where('category_id', $data['catid'])
  754. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  755. ->select('website_id',
  756. 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'))
  757. ->get();
  758. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  759. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  760. $websiteIds = $web->pluck('website_id')->toArray();
  761. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  762. if($user_type == 0){
  763. throw new \Exception("用户类型不能为空");
  764. }
  765. if($user_type == 10000 ){
  766. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  767. $web = WebsiteCategory::where('category_id', $data['catid'])
  768. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  769. ->select('website_id',
  770. 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'))
  771. ->get();
  772. // 非核心站与核心站----显示时间-----间隔
  773. $time = 20;
  774. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  775. $waiting_interval = 5;
  776. $webArray = $web->toArray();
  777. if(empty($webArray)){
  778. throw new \Exception('网站分类不存在');
  779. }
  780. // 直接使用当前系统时间,不再强制添加8小时
  781. $now = date('Y-m-d H:i:s');
  782. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  783. // 检查 $item 对象是否有 is_core 属性
  784. if (!isset($item['is_core'])) {
  785. throw new \Exception('$item 对象缺少 is_core 属性');
  786. }
  787. // 当 is_core 为 2 时,则表示此网站不存在
  788. if ($item['is_core'] == 2) {
  789. return null;
  790. }else if($item['is_core'] == 1){
  791. // 当 is_core 为 1 时,则表示此网站是核心站
  792. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  793. }else{
  794. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  795. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  796. if ($item['is_core'] == 0) {
  797. $time += $waiting_interval;
  798. }
  799. }
  800. return [
  801. 'article_id' => $data['id'],
  802. 'website_id' => $item['website_id'],
  803. 'c_show_time' => $c_show_time,
  804. ];
  805. }, array_keys($webArray), $webArray)));
  806. if(!empty($article_ignore)){
  807. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  808. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  809. $article_ignores = ArticleIgnore::upsert(
  810. $article_ignore,
  811. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  812. ['c_show_time'] // 需要更新的字段
  813. );
  814. if(!$article_ignores){
  815. throw new \Exception('c端展示时间插入失败');
  816. }
  817. }
  818. // Db::commit();
  819. // return Result::success($article_ignore);
  820. }
  821. // ------c_show_time********up*******
  822. unset($data['user_type']);
  823. // unset($data['web_site_id']);
  824. unset($data['nav_add_pool_id']);
  825. try {
  826. //处理投票
  827. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  828. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  829. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  830. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  831. unset($data['is_survey']);
  832. unset($data['survey_name']);
  833. unset($data['suvey_array']);
  834. unset($data['website_id']);
  835. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  836. if ($data['hits'] == '') {
  837. $data['hits'] = 0;
  838. }
  839. if ($data['is_original'] == '') {
  840. $data['is_original'] = 0;
  841. }
  842. if ($data['status'] == '') {
  843. $data['status'] = 0;
  844. }
  845. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  846. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  847. $articleData = $data;
  848. unset($articleData['content']);
  849. unset($articleData['status_name']);
  850. unset($articleData['name']);
  851. unset($articleData['content']);
  852. unset($articleData['pid_arr']);
  853. unset($articleData['pid']);
  854. //自动处理缩略图、关键字、描述
  855. if ($articleData['imgurl'] == '') {
  856. //如果没有图,设置level=0
  857. $levelArr = json_decode($articleData['level'], true);
  858. var_dump($levelArr, '----------levelArr-----------1');
  859. //content中提取图片第一个图,正则提取
  860. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  861. preg_match_all($reg, $data['content'], $matches);
  862. if (isset($matches[1][0])) {
  863. //截取varchar240
  864. // 截取到第一个<
  865. $articleData['imgurl'] = $matches[1][0];
  866. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  867. $pos = strpos($articleData['imgurl'], '"');
  868. if ($pos !== false) {
  869. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  870. }
  871. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  872. //如果有图,设置level=3
  873. if (!in_array(3, $levelArr)) {
  874. $levelArr[] = 3;
  875. }
  876. $articleData['level'] = json_encode($levelArr);
  877. } else {
  878. if (!in_array(0, $levelArr)) {
  879. $levelArr[] = 0;
  880. }
  881. $articleData['level'] = json_encode($levelArr);
  882. }
  883. }
  884. var_dump($articleData['level'], '----------$articleData[level]----------1');
  885. if ($articleData['keyword'] == '') {
  886. //提取标题+内容中的关键词
  887. $articleData['keyword'] = $data['title'];
  888. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  889. Jieba::init(); // 初始化 jieba-php
  890. Finalseg::init();
  891. $segList = Jieba::cut($articleData['keyword']);
  892. $segList1 = array_slice($segList, 0, 8);
  893. $articleData['keyword'] = implode(',', $segList1);
  894. }
  895. if ($articleData['introduce'] == '') {
  896. //提取内容中的描述
  897. $content = $data['content'];
  898. // 去除 <style> 和 <script> 标签及其内容
  899. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  900. // 去除所有 HTML 标签
  901. $content = strip_tags($content);
  902. // 去除 HTML 实体
  903. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  904. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  905. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  906. // 去除多余空白
  907. $content = preg_replace('/\s+/u', '', $content);
  908. // 截取 100 个字符
  909. $articleData['introduce'] = mb_substr($content, 0, 100);
  910. }
  911. if ($articleData['status'] == 0) {
  912. $this->sendMessage([
  913. 'talk_type' => 100,
  914. 'title' => $articleData['title'],
  915. 'content' => '提交了审核',
  916. 'messageType' => 2,
  917. ]);
  918. }
  919. $id = Article::where(['id' => $data['id']])->update($articleData);
  920. $articleDataContent = [
  921. 'content' => $data['content'],
  922. ];
  923. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  924. //处理投票
  925. $id = $data['id'];
  926. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  927. var_dump($suvey_array, 'suvey_array________delete');
  928. //处理投票
  929. if ($is_survey == 1) {
  930. //生成年月日时分秒+8位随机数
  931. $uuid = date('YmdHis') . rand(10000000, 99999999);
  932. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  933. var_dump($suveys_array, '---------------------1');
  934. $suvey_data = [];
  935. if (is_array($suveys_array)) {
  936. foreach ($suveys_array as $key => $value) {
  937. if ($value == '') {
  938. continue;
  939. }
  940. if (is_array($value)) {
  941. $suvey_data[] = [
  942. 'sur_id' => $uuid,
  943. 'art_id' => $id,
  944. 'website_id' => $website_id ?? 2,
  945. 'survey_name' => $survey_name,
  946. 'choice_name' => $value[1],
  947. 'is_other' => 1,
  948. 'other_id' => 0,
  949. 'results' => 0,
  950. ];
  951. } else {
  952. $suvey_data[] = [
  953. 'sur_id' => $uuid,
  954. 'art_id' => $id,
  955. 'website_id' => $website_id ?? 2,
  956. 'survey_name' => $survey_name,
  957. 'choice_name' => $value,
  958. 'is_other' => 0,
  959. 'other_id' => 0,
  960. 'results' => 0,
  961. ];
  962. }
  963. if (empty($suvey_data)) {
  964. throw new \Exception("投票数据为空");
  965. }
  966. }
  967. }
  968. $result = ArticleSurvey::insert($suvey_data);
  969. if (!$result) {
  970. throw new \Exception("投票失败");
  971. }
  972. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  973. if (!$result) {
  974. throw new \Exception("投票失败");
  975. }
  976. } else {
  977. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  978. }
  979. Db::commit();
  980. return Result::success([]);
  981. } catch (\Throwable $ex) {
  982. Db::rollBack();
  983. var_dump($ex->getMessage());
  984. return Result::error("更新失败" . $ex->getMessage(), 0);
  985. }
  986. }
  987. /**
  988. * 更新资讯状态
  989. * @param array $data
  990. * @return array
  991. */
  992. public function upArticleStatus(array $data): array
  993. {
  994. $articleData = Article::where(['id' => $data['id']])->first();
  995. //发送10次
  996. // for ($i = 0; $i < 10; $i++) {
  997. // $this->sendMessage([
  998. // 'talk_type' => 100,
  999. // 'title' => $i . $articleData['title'],
  1000. // 'content' => '审核通过',
  1001. // 'messageType' => 2,
  1002. // 'user_id' => $articleData['admin_user_id'],
  1003. // ]);
  1004. // }
  1005. // var_dump($data['status'], 'status');
  1006. // return Result::success();
  1007. if ($data['status'] == 1) {
  1008. $this->sendMessage([
  1009. 'talk_type' => 101,
  1010. 'title' => $articleData['title'],
  1011. 'content' => '审核通过',
  1012. 'messageType' => 2,
  1013. 'user_id' => $articleData['admin_user_id'],
  1014. ]);
  1015. }
  1016. if ($data['status'] == 2) {
  1017. $this->sendMessage([
  1018. 'talk_type' => 101,
  1019. 'title' => $articleData['title'],
  1020. 'content' => '审核拒绝',
  1021. 'messageType' => 2,
  1022. 'user_id' => $articleData['admin_user_id'],
  1023. ]);
  1024. }
  1025. if ($data['status'] == 0) {
  1026. $this->sendMessage([
  1027. 'talk_type' => 100,
  1028. 'title' => $articleData['title'],
  1029. 'content' => '提交了审核',
  1030. 'messageType' => 2,
  1031. ]);
  1032. }
  1033. $result = Article::where(['id' => $data['id']])->update($data);
  1034. // ------c_show_time********up_status*******
  1035. // 若是审核通过 则更新c_show_time
  1036. if($data['status'] == 1){
  1037. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1038. $web = Article::where('article.id',$data['id'])
  1039. ->leftJoin('website_category','article.catid','website_category.category_id')
  1040. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1041. ->select('website_id',
  1042. 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'))
  1043. ->get();
  1044. // 非核心站与核心站----显示时间-----间隔
  1045. $time = 20;
  1046. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1047. $waiting_interval = 5;
  1048. $webArray = $web->toArray();
  1049. if(empty($webArray)){
  1050. throw new \Exception('网站分类不存在');
  1051. }
  1052. // 直接使用当前系统时间,不再强制添加8小时
  1053. $now = date('Y-m-d H:i:s');
  1054. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1055. if(isset($data['ignore_ids'])){
  1056. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1057. if(in_array($item['website_id'], $ignore_website_ids)){
  1058. $is_ignore = 1;
  1059. }else{
  1060. $is_ignore = 0;
  1061. }
  1062. return [
  1063. 'article_id' => $data['id'],
  1064. 'website_id' => $item['website_id'],
  1065. 'is_ignore' => $is_ignore,
  1066. ];
  1067. }else{
  1068. // 检查 $item 对象是否有 is_core 属性
  1069. if (!isset($item['is_core'])) {
  1070. throw new \Exception('$item 对象缺少 is_core 属性');
  1071. }
  1072. // 当 is_core 为 2 时,则表示此网站不存在
  1073. if ($item['is_core'] == 2) {
  1074. return null;
  1075. }else if($item['is_core'] == 1){
  1076. // 当 is_core 为 1 时,则表示此网站是核心站
  1077. $c_show_time = $now;
  1078. }else{
  1079. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1080. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1081. if ($item['is_core'] == 0) {
  1082. $time += $waiting_interval;
  1083. }
  1084. }
  1085. return [
  1086. 'article_id' => $data['id'],
  1087. 'website_id' => $item['website_id'],
  1088. 'c_show_time' => $c_show_time,
  1089. ];
  1090. }
  1091. }, array_keys($webArray), $webArray)));
  1092. if(!empty($article_ignore) && !isset($data['ignore_ids'])){
  1093. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1094. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1095. $websiteIds = $web->pluck('website_id')->toArray();
  1096. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1097. $article_ignores = ArticleIgnore::upsert(
  1098. $article_ignore,
  1099. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1100. ['c_show_time'] // 需要更新的字段
  1101. );
  1102. if(!$article_ignores){
  1103. throw new \Exception('c端展示时间插入失败');
  1104. }
  1105. }
  1106. if(!empty($data['ignore_ids'])){
  1107. // return Result::success($article_ignore);
  1108. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1109. if(!empty($article_ignore)){
  1110. $article_ignores = ArticleIgnore::upsert(
  1111. $article_ignore,
  1112. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1113. ['is_ignore'] // 需要更新的字段
  1114. );
  1115. // if(!$article_ignores){
  1116. // throw new \Exception('屏蔽网站更新失败');
  1117. // }
  1118. }
  1119. }
  1120. }
  1121. // ------c_show_time********up_status*******
  1122. if ($result) {
  1123. return Result::success();
  1124. } else {
  1125. return Result::error("更新状态失败", 0);
  1126. }
  1127. }
  1128. /**
  1129. * 获取新闻详情
  1130. * @param array $data
  1131. * @return array
  1132. */
  1133. public function getArticleInfo(array $data): array
  1134. {
  1135. $where = [
  1136. 'article.id' => $data['id'],
  1137. // 'article.status' => 1,
  1138. ];
  1139. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1140. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1141. $info = $result;
  1142. // var_dump($info, 'info');
  1143. $info['survey_array'] = $articleSurvey;
  1144. if ($result) {
  1145. return Result::success($info);
  1146. } else {
  1147. return Result::error("查询失败", 0);
  1148. }
  1149. }
  1150. /**
  1151. * 获取头条新闻
  1152. * @param array $data
  1153. * @return array
  1154. */
  1155. public function getWebsiteArticlett(array $data): array
  1156. {
  1157. $website_id = $data['website_id'];
  1158. $website = Website::where('id', $data['website_id'])->first();
  1159. if (empty($website)) {
  1160. return Result::error("网站不存在", 0);
  1161. }
  1162. $categorys = $this->processArticlePro($website_id);
  1163. $catiall = $categorys['catiall'];
  1164. $categoryIds = $categorys['categoryIds'];
  1165. $where = [
  1166. 'status' => 1
  1167. ];
  1168. // $website_column = $website['column'];
  1169. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1170. $website_column = json_decode($website['website_column_arr_id'], true);
  1171. }
  1172. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1173. // return Result::success($diff_pid_categoryIds);
  1174. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1175. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1176. }
  1177. // $website_id = $data['website_id'];
  1178. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1179. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1180. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1181. switch ($data['level']) {
  1182. case 1:
  1183. case 2:
  1184. case 3:
  1185. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1186. $query = Article::where($where)
  1187. ->where('level', 'like', '%' . $data['level'] . '%')
  1188. ->orderBy('updated_at', 'desc');
  1189. break;
  1190. case 4: //最新资讯
  1191. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1192. break;
  1193. case 5: //资讯推荐
  1194. $query = Article::where($where)
  1195. ->where('updated_at', '>', $month);
  1196. break;
  1197. case 7: //资讯分类
  1198. if (isset($data['id']) && !empty($data['id'])) {
  1199. $keyword = Article::where('id', $data['id'])->value('keyword');
  1200. $keywordArray = explode(',', $keyword);
  1201. $whereL7 = [];
  1202. foreach ($keywordArray as $k => $v) {
  1203. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1204. }
  1205. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1206. break;
  1207. } else {
  1208. return Result::error("请输入资讯ID", 0);
  1209. break;
  1210. }
  1211. default:
  1212. break;
  1213. }
  1214. // $whereL7 = [];
  1215. // if(isset($data['id']) && !empty($data['id'])){
  1216. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1217. // $keywordArray = explode(',', $keyword);
  1218. // foreach ($keywordArray as $k => $v) {
  1219. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1220. // }
  1221. // }
  1222. // $query = Article::where($where)
  1223. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1224. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1225. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1226. // }
  1227. // if($data['level'] == 7){
  1228. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1229. // }
  1230. // if($data['level'] == 4){
  1231. // $query = $query->inRandomOrder()
  1232. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1233. // }
  1234. // if($data['level'] == 5){
  1235. // $query = $query->orderBy('updated_at','desc');
  1236. // }
  1237. // });
  1238. if ($data['textnum'] > 0) {
  1239. $query = clone $query;
  1240. $result['text'] = $query
  1241. ->whereIn('catid', $categoryIds)
  1242. ->leftJoinSub(function ($query) use ($website_id) {
  1243. $query->from('article_ignore')
  1244. ->where('website_id', $website_id);
  1245. }, 'article_ignore', function ($join) {
  1246. $join->on('article_ignore.article_id', '=', 'article.id');
  1247. })
  1248. ->where(function ($query) {
  1249. $query->whereNull('article_ignore.article_id')
  1250. ->orWhere(function ($subQuery) {
  1251. $subQuery->whereNotNull('article_ignore.article_id')
  1252. ->where('article_ignore.is_ignore', 0)
  1253. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1254. });
  1255. })
  1256. // ->where(function ($query) use ($website_id) {
  1257. // $query->whereNull('article_ignore.article_id')
  1258. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1259. // })
  1260. ->select(
  1261. 'article.id',
  1262. 'article.title',
  1263. 'article.author',
  1264. 'article.updated_at',
  1265. 'article.introduce',
  1266. 'article.islink',
  1267. 'article.linkurl',
  1268. 'article.copyfrom',
  1269. 'article.cat_arr_id',
  1270. 'article.catid',
  1271. 'article.level',
  1272. // 'article_ignore.is_ignore',
  1273. // 'article_ignore.c_show_time',
  1274. )
  1275. ->offset($data['placeid'])
  1276. ->limit($data['textnum'])
  1277. ->get()->all();
  1278. foreach ($result['text'] as $k => $v) {
  1279. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1280. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1281. }
  1282. }
  1283. if ($data['imgnum'] > 0) {
  1284. $query = clone $query;
  1285. if($data['textnum'] == 0){
  1286. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1287. $query->from('article_ignore')
  1288. ->where('website_id', $website_id);
  1289. }, 'article_ignore', function ($join) {
  1290. $join->on('article_ignore.article_id', '=', 'article.id');
  1291. })
  1292. ->where(function ($query) {
  1293. $query->whereNull('article_ignore.article_id')
  1294. ->orWhere(function ($subQuery) {
  1295. $subQuery->whereNotNull('article_ignore.article_id')
  1296. ->where('article_ignore.is_ignore', 0)
  1297. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1298. });
  1299. });
  1300. }
  1301. $result['img'] = $query
  1302. ->whereIn('catid', $categoryIds)
  1303. ->where('article.imgurl', '!=', '')
  1304. ->select(
  1305. 'article.id',
  1306. 'article.title',
  1307. 'article.imgurl',
  1308. 'article.author',
  1309. 'article.updated_at',
  1310. 'article.introduce',
  1311. 'article.islink',
  1312. 'article.linkurl',
  1313. 'article.copyfrom',
  1314. 'article.cat_arr_id',
  1315. 'article.catid',
  1316. 'article.level',
  1317. // 'article_ignore.is_ignore',
  1318. // 'article_ignore.c_show_time',
  1319. )
  1320. ->offset($data['placeid'])
  1321. ->limit($data['imgnum'])
  1322. ->get()->all();
  1323. foreach ($result['img'] as $k => $v) {
  1324. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1325. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1326. }
  1327. }
  1328. if (empty($result)) {
  1329. return Result::error("暂无相关资讯", 0);
  1330. }
  1331. return Result::success($result);
  1332. }
  1333. /**
  1334. * 获取模块新闻
  1335. * @param array $data
  1336. * @return array
  1337. */
  1338. public function getWebsiteModelArticles(array $data): array
  1339. {
  1340. $catid = $data['catid'];
  1341. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1342. $category = $category->toArray();
  1343. if (!empty($category)) {
  1344. $where = [
  1345. 'status' => 1,
  1346. 'catid' => $catid,
  1347. ];
  1348. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1349. // 1:文字新闻;2:轮播图;3:图文;
  1350. // 级别:0:未分类
  1351. // 3:推荐图片
  1352. if ($data['level'] == 1) {
  1353. $data['level'] = 0;
  1354. }
  1355. $result = Article::where($where)
  1356. ->where(function ($query) use ($data) {
  1357. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1358. ->orWhereNull("level")
  1359. ->orWhereRaw("level = '[]'");
  1360. })
  1361. ->leftJoinSub(function ($query) use ($data) {
  1362. $query->from('article_ignore')
  1363. ->where('website_id', $data['website_id']);
  1364. }, 'article_ignore', function ($join) {
  1365. $join->on('article_ignore.article_id', '=', 'article.id');
  1366. })
  1367. ->where(function ($query) {
  1368. $query->whereNull('article_ignore.article_id')
  1369. ->orWhere(function ($subQuery) {
  1370. $subQuery->whereNotNull('article_ignore.article_id')
  1371. ->where('article_ignore.is_ignore', 0)
  1372. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1373. });
  1374. })
  1375. // ->where(function ($query) use ($data) {
  1376. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1377. // ->orWhereNull("ignore_ids");
  1378. // })
  1379. ->orderBy("updated_at", "desc")
  1380. ->offset($placeid)
  1381. ->limit($data['pagesize'])
  1382. ->get();
  1383. if (empty($result)) {
  1384. return Result::error("此栏目暂无相关新闻", 0);
  1385. }
  1386. } else {
  1387. return Result::error("此网站暂无此栏目", 0);
  1388. }
  1389. return Result::success($result);
  1390. }
  1391. /**
  1392. *获取新闻列表
  1393. * @param array $data
  1394. * @return array
  1395. */
  1396. public function getWebsiteArticleList(array $data): array
  1397. {
  1398. // return Result::success($data);
  1399. $where[] = ['status', '=', 1];
  1400. $website_id = $data['website_id'];
  1401. $website = Website::where('id', $data['website_id'])->first();
  1402. if (empty($website)) {
  1403. return Result::error("网站不存在", 0);
  1404. }
  1405. // $website_column = $website['column'];
  1406. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1407. $website_column = json_decode($website['website_column_arr_id'], true);
  1408. }
  1409. $categorys = $this->processArticlePro($website_id);
  1410. $cat_1st_arr = $categorys['cat_1st_arr'];
  1411. $catiall = $categorys['catiall'];
  1412. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1413. // return Result::success($diff_pid_categoryIds);
  1414. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1415. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1416. }
  1417. if (isset($data['catid']) && !empty($data['catid'])) {
  1418. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1419. if (empty($category)) {
  1420. return Result::error("此网站暂无此栏目", 0);
  1421. }
  1422. array_push($where, ['catid', '=', $data['catid']]);
  1423. }
  1424. // return Result::success($where);
  1425. $query = Article::where($where)
  1426. ->leftJoinSub(function ($query) use ($website_id) {
  1427. $query->from('article_ignore')
  1428. ->where('website_id', $website_id);
  1429. }, 'article_ignore', function ($join) {
  1430. $join->on('article_ignore.article_id', '=', 'article.id');
  1431. })
  1432. ->where(function ($query) {
  1433. $query->whereNull('article_ignore.article_id')
  1434. ->orWhere(function ($subQuery) {
  1435. $subQuery->whereNotNull('article_ignore.article_id')
  1436. ->where('article_ignore.is_ignore', 0)
  1437. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1438. });
  1439. })
  1440. ->select(
  1441. 'article.id',
  1442. 'article.title',
  1443. 'article.imgurl',
  1444. 'article.author',
  1445. 'article.updated_at',
  1446. 'article.introduce',
  1447. 'article.islink',
  1448. 'article.linkurl',
  1449. 'article.copyfrom',
  1450. 'article.cat_arr_id',
  1451. 'article.catid'
  1452. );
  1453. $count = $query->count();
  1454. $rep = $query->orderBy("updated_at", "desc")
  1455. ->offset(($data['page'] - 1) * $data['pageSize'])
  1456. ->limit($data['pageSize'])
  1457. ->get()->all();
  1458. $categorys = $this->processArticlePro($website_id);
  1459. $cat_1st_arr = $categorys['cat_1st_arr'];
  1460. $catiall = $categorys['catiall'];
  1461. // $web['website_id'] = $data['website_id'];
  1462. foreach ($rep as $k => $v) {
  1463. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1464. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1465. }
  1466. // $rep = $this->processArticles($rep,$web);
  1467. $data = [
  1468. 'rows' => $rep,
  1469. 'count' => $count,
  1470. ];
  1471. if (empty($rep)) {
  1472. return Result::error("没有信息数据");
  1473. }
  1474. return Result::success($data);
  1475. }
  1476. /**
  1477. * 前端-获取新闻详情
  1478. * @param array $data
  1479. * @return array
  1480. */
  1481. public function selectWebsiteArticleInfo(array $data): array
  1482. {
  1483. $where = [
  1484. 'article.id' => $data['id'],
  1485. 'article.status' => 1,
  1486. ];
  1487. $result = Article::where($where)
  1488. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1489. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1490. // ->where(function ($query) use ($data) {
  1491. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1492. // ->orWhereNull("ignore_ids");
  1493. // })
  1494. ->leftJoinSub(function ($query) use ($data) {
  1495. $query->from('article_ignore')
  1496. ->where('website_id', $data['website_id']);
  1497. }, 'article_ignore', function ($join) {
  1498. $join->on('article_ignore.article_id', '=', 'article.id');
  1499. })
  1500. ->where(function ($query) {
  1501. $query->whereNull('article_ignore.article_id')
  1502. ->orWhere(function ($subQuery) {
  1503. $subQuery->whereNotNull('article_ignore.article_id')
  1504. ->where('article_ignore.is_ignore', 0)
  1505. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1506. });
  1507. })
  1508. ->select(
  1509. 'article.*',
  1510. 'article_data.content',
  1511. 'article_data.article_id',
  1512. 'article_extend.website_url',
  1513. 'article_extend.email',
  1514. 'article_extend.contacts',
  1515. 'article_extend.contacts_mobile',
  1516. 'article_extend.contacts_address',
  1517. 'article_extend.zip_code',
  1518. 'article_extend.enterprise_name'
  1519. )
  1520. ->first();
  1521. if (empty($result)) {
  1522. return Result::error("暂无此新闻!", 0);
  1523. }
  1524. if (!empty($result['publiced_at'])) {
  1525. $result['updated_at'] = $result['publiced_at'];
  1526. }
  1527. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1528. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1529. ->where('website_category.website_id', $data['website_id'])
  1530. ->where(['website_category.category_id' => $result['catid']])
  1531. ->first();
  1532. if (empty($category)) {
  1533. return Result::error("查询失败", 0);
  1534. }
  1535. //手动推荐文章
  1536. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1537. if (empty($commend_ids)) {
  1538. $commendArticle = [];
  1539. } else {
  1540. //去除不存在的文章ID
  1541. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1542. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1543. ->leftJoinSub(function ($query) use ($data) {
  1544. $query->from('article_ignore')
  1545. ->where('website_id', $data['website_id']);
  1546. }, 'article_ignore', function ($join) {
  1547. $join->on('article_ignore.article_id', '=', 'article.id');
  1548. })
  1549. ->where(function ($query) {
  1550. $query->whereNull('article_ignore.article_id')
  1551. ->orWhere(function ($subQuery) {
  1552. $subQuery->whereNotNull('article_ignore.article_id')
  1553. ->where('article_ignore.is_ignore', 0)
  1554. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1555. });
  1556. })
  1557. ->where('article.status', 1)
  1558. ->where('website_category.website_id', $data['website_id'])
  1559. ->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')
  1560. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1561. // ->orderBy('article.updated_at', 'desc')
  1562. ->limit(5)
  1563. ->get();
  1564. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1565. foreach ($commendArticle as $k => $v) {
  1566. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1567. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1568. $cat_arr_id = array_unique($cat_arr_id);
  1569. // 从website_category取出alias_pinyin
  1570. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1571. ->whereIn('category_id', $cat_arr_id)
  1572. ->pluck('alias_pinyin', 'category_id')
  1573. ->toArray();
  1574. // 将cat_arr_id的json转成路径/隔开
  1575. $path_parts = [];
  1576. foreach ($cat_arr_id as $cat_id) {
  1577. if (isset($cat_arr[$cat_id])) {
  1578. $path_parts[] = $cat_arr[$cat_id];
  1579. }
  1580. }
  1581. $v->alias_pinyin = implode('/', $path_parts);
  1582. } else {
  1583. $v->alias_pinyin = '';
  1584. }
  1585. }
  1586. }
  1587. $result['category_id'] = $category['category_id'];
  1588. $result['cat_name'] = $category['alias'];
  1589. $result['website_name'] = $category['website_name'] ?? "";
  1590. $result['suffix'] = $category['suffix'] ?? "";
  1591. $result['commendArticle'] = $commendArticle;
  1592. $result['commend_ids'] = $commend_ids;
  1593. return Result::success($result);
  1594. }
  1595. /**
  1596. * 前端-获取网站调查问卷
  1597. * @param array $data
  1598. * @return array
  1599. */
  1600. public function getWebsiteSurvey(array $data): array
  1601. {
  1602. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1603. $website = Website::where('id', $data['website_id'])->first();
  1604. if (empty($website)) {
  1605. return Result::error("暂无此网站", 0);
  1606. }
  1607. }
  1608. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1609. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1610. if (empty($article)) {
  1611. return Result::error("暂无此文章", 0);
  1612. }
  1613. // return Result::error($data,0);
  1614. $where['art_id'] = $data['art_id'];
  1615. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1616. } else {
  1617. $survey = Article::where(function ($query) {
  1618. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1619. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1620. })
  1621. ->where('status', 1)
  1622. ->where('is_survey', 1)
  1623. ->select('survey_id')
  1624. ->orderBy('updated_at', 'desc')
  1625. ->first();
  1626. if (empty($survey)) {
  1627. return Result::error("暂无调查问卷", 0);
  1628. }
  1629. $where['sur_id'] = $survey['survey_id'];
  1630. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1631. }
  1632. // return Result::success($where);
  1633. $result = ArticleSurvey::where($where)
  1634. ->where(function ($query) {
  1635. $query->where('is_other', 0)
  1636. ->orWhere(function ($subQuery) {
  1637. $subQuery->where('is_other', 1)
  1638. ->where('other_id', 0);
  1639. });
  1640. })
  1641. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1642. ->select('article_survey.*', 'article.survey_type')
  1643. ->get()->all();
  1644. if (empty($result)) {
  1645. return Result::error("此文章暂无调查问卷", 0);
  1646. }
  1647. return Result::success($result);
  1648. }
  1649. /**
  1650. * 前端-添加网站调查问卷选项
  1651. * @param array $data
  1652. * @return array
  1653. */
  1654. public function addWebsiteSurveyOption(array $data): array
  1655. {
  1656. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1657. $website = Website::where('id', $data['website_id'])->first();
  1658. if (empty($website)) {
  1659. return Result::error("暂无此网站", 0);
  1660. }
  1661. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1662. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1663. if (empty($survey)) {
  1664. return Result::error("此调查问卷不可添加选项", 0);
  1665. }
  1666. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1667. $choice = [
  1668. 'art_id' => $survey['art_id'],
  1669. 'website_id' => $data['website_id'],
  1670. 'survey_name' => $survey['survey_name'],
  1671. 'choice_name' => $data['choice_name'],
  1672. 'sur_id' => $survey['sur_id'],
  1673. 'is_other' => 1,
  1674. 'other_id' => $survey['id'],
  1675. ];
  1676. $result = ArticleSurvey::insertGetId($choice);
  1677. if (empty($result)) {
  1678. return Result::error("添加失败", 0);
  1679. }
  1680. return Result::success($result);
  1681. }
  1682. }
  1683. return Result::error("添加失败", 0);
  1684. }
  1685. return Result::error("添加失败", 0);
  1686. }
  1687. /**
  1688. * 前端-调查问卷投票
  1689. * @param array $data
  1690. * @return array
  1691. */
  1692. public function addWebsiteSurveyVote(array $data): array
  1693. {
  1694. // return Result::success($data);
  1695. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1696. $website = Website::where('id', $data['website_id'])->first();
  1697. if (empty($website)) {
  1698. return Result::error("暂无此网站", 0);
  1699. }
  1700. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1701. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1702. // return Result::success($survey);
  1703. if (empty($is_survey)) {
  1704. return Result::error("此调查问卷不存在", 0);
  1705. }
  1706. // return Result::success($survey);
  1707. // 调查问卷类型
  1708. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1709. //多选 若是json型则转化成数组类型
  1710. if (strpos($data['choice_id'], '[') === 0) {
  1711. $data['choice_id'] = json_decode($data['choice_id'], true);
  1712. } else {
  1713. // 单选 也转换成数组
  1714. $data['choice_id'] = [$data['choice_id']];
  1715. }
  1716. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1717. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1718. // ->where('website_id',$data['website_id'])
  1719. ->where('is_other', 1)
  1720. ->where('other_id', 0)
  1721. ->first();
  1722. if (!empty($other)) {
  1723. return Result::error("请选择已有的选项!", 0);
  1724. }
  1725. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1726. // ->where('website_id',$data['website_id'])
  1727. ->where('is_other', 1)
  1728. ->where('other_id', '!=', 0)
  1729. ->first();
  1730. // return Result::success($choice['other']);
  1731. $choice_id = $data['choice_id'];
  1732. if (!empty($choice['other'])) {
  1733. // array_push($data['choice_id'],$choice['other']['other_id']);
  1734. if (!empty($choice_id)) {
  1735. $key = array_search($choice['other']['id'], $choice_id);
  1736. if ($key !== false) {
  1737. unset($choice_id[$key]);
  1738. $choice_id = array_values($choice_id);
  1739. }
  1740. array_push($choice_id, $choice['other']['other_id']);
  1741. } else {
  1742. $choice_id[0] = $choice['other']['other_id'];
  1743. }
  1744. array_push($data['choice_id'], $choice['other']['other_id']);
  1745. }
  1746. // return Result::success($data);
  1747. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1748. // ->where('website_id',$data['website_id'])
  1749. ->increment('results', 1);
  1750. if (empty($choice)) {
  1751. return Result::error("请选择已有的选项!", 0);
  1752. }
  1753. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1754. // ->where('website_id',$data['website_id'])
  1755. ->where('other_id', 0)
  1756. ->get();
  1757. $survey['choice'] = $choice_id;
  1758. return Result::success($survey);
  1759. }
  1760. return Result::error("参数必填!");
  1761. }
  1762. return Result::error("此调查问卷不存在", 0);
  1763. }
  1764. return Result::error("参数必填!");
  1765. }
  1766. /**
  1767. * 后端-获取网站调查问卷列表
  1768. * @param array $data
  1769. * @return array
  1770. */
  1771. public function getSurveyList(array $data): array
  1772. {
  1773. $where = [];
  1774. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1775. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1776. }
  1777. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1778. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1779. }
  1780. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1781. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1782. }
  1783. // return Result::success($where);
  1784. if (!empty($where)) {
  1785. $query = Article::where($where)->where(function ($q) {
  1786. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1787. });
  1788. } else {
  1789. $query = Article::where(function ($q) {
  1790. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1791. });
  1792. }
  1793. $count = $query->count();
  1794. $survey = $query->orderByDesc('id')
  1795. ->limit($data['pageSize'])
  1796. ->offset(($data['page'] - 1) * $data['pageSize'])
  1797. ->get();
  1798. if (empty($survey->toArray())) {
  1799. return Result::error("暂无调查问卷!", 0);
  1800. }
  1801. $result = [
  1802. 'rows' => $survey,
  1803. 'count' => $count,
  1804. ];
  1805. return Result::success($result);
  1806. }
  1807. /**
  1808. * 后端-获取网站调查问卷详情
  1809. * @param array $data
  1810. * @return array
  1811. */
  1812. public function getSurveyInfo(array $data): array
  1813. {
  1814. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1815. $where = ['sur_id' => $data['sur_id']];
  1816. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1817. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1818. ->select('article_survey.*', 'article.survey_type')
  1819. ->get()->all();
  1820. if (empty($choose)) {
  1821. return Result::error("此调查问卷不存在", 0);
  1822. }
  1823. $resultsArray = array_column($choose, 'results');
  1824. $total = array_sum($resultsArray);
  1825. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1826. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1827. // $total = 0;
  1828. if (!empty($other)) {
  1829. $total = $total + $other['results'];
  1830. $other['choice_name'] = '(其他)';
  1831. if (!empty($others)) {
  1832. $other['hasChildren'] = true;
  1833. // array_push($other,['hasChildren','=',true]);
  1834. $other['children'] = $others;
  1835. $other_choices = [$other->toArray()];
  1836. $mer_choice = array_merge($choose, $other_choices);
  1837. $value_choice = array_values($mer_choice);
  1838. } else {
  1839. // return Result::error('1111');
  1840. $other_choices = [$other->toArray()];
  1841. $other_choices = array_merge($choose, $other_choices);
  1842. $value_choice = array_values($other_choices);
  1843. // return Result::success($result);
  1844. }
  1845. } else {
  1846. $value_choice = $choose;
  1847. }
  1848. $result = [
  1849. 'choose' => $value_choice,
  1850. 'total' => $total,
  1851. ];
  1852. }
  1853. return Result::success($result);
  1854. }
  1855. /**
  1856. * 前端-搜索新闻列表
  1857. * @param array $data
  1858. * @return array
  1859. */
  1860. public function selectWebsiteArticle(array $data): array
  1861. {
  1862. $website = Website::where('id', $data['website_id'])->first();
  1863. if (empty($website)) {
  1864. return Result::error("网站不存在", 0);
  1865. }
  1866. // $website_column = $website['column'];
  1867. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1868. $website_column = json_decode($website['website_column_arr_id'], true);
  1869. }
  1870. $website_id = $data['website_id'];
  1871. $categorys = $this->processArticlePro($website_id);
  1872. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1873. // return Result::success($diff_pid_categoryIds);
  1874. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1875. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1876. }
  1877. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1878. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1879. $catiall = $categorys['catiall'];
  1880. $categoryIds = $categorys['categoryIds'];
  1881. // return Result::success($categoryIds);
  1882. $query = Article::where('status', 1)
  1883. ->whereIn('catid', $categoryIds)
  1884. ->leftJoinSub(function ($query) use ($website_id) {
  1885. $query->from('article_ignore')
  1886. ->where('website_id', $website_id);
  1887. }, 'article_ignore', function ($join) {
  1888. $join->on('article_ignore.article_id', '=', 'article.id');
  1889. })
  1890. ->where(function ($query) {
  1891. $query->whereNull('article_ignore.article_id')
  1892. ->orWhere(function ($subQuery) {
  1893. $subQuery->whereNotNull('article_ignore.article_id')
  1894. ->where('article_ignore.is_ignore', 0)
  1895. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1896. });
  1897. });
  1898. // ->get()->all();
  1899. // return Result::success($query);
  1900. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1901. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1902. }
  1903. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1904. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1905. }
  1906. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1907. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1908. }
  1909. // 计算总数
  1910. $count = $query->count();
  1911. // return Result::success($count);
  1912. // 分页查询
  1913. $articles = $query
  1914. ->select(
  1915. 'article.id',
  1916. 'article.title',
  1917. 'article.imgurl',
  1918. 'article.author',
  1919. 'article.updated_at',
  1920. 'article.introduce',
  1921. 'article.islink',
  1922. 'article.linkurl',
  1923. 'article.copyfrom',
  1924. 'article.cat_arr_id',
  1925. 'article.catid',
  1926. 'article.department_arr_id',
  1927. 'article.city_arr_id',
  1928. // 'article_ignore.c_show_time',
  1929. // 'article_ignore.is_ignore'
  1930. )
  1931. ->orderBy("updated_at", "desc")
  1932. ->offset(($data['page'] - 1) * $data['pageSize'])
  1933. ->limit($data['pageSize'])
  1934. ->get();
  1935. // return Result::success($articles);
  1936. foreach ($articles as $k => $v) {
  1937. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1938. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1939. }
  1940. if (empty($articles)) {
  1941. return Result::error("没有符合条件的资讯数据");
  1942. }
  1943. $result = [
  1944. 'rows' => $articles,
  1945. 'count' => $count,
  1946. ];
  1947. return Result::success($result);
  1948. }
  1949. /**
  1950. * 模块新闻加强版
  1951. * @param array $data
  1952. * @return array
  1953. */
  1954. public function getWebsiteCatidArticle(array $data): array
  1955. {
  1956. $where = [
  1957. 'website_category.category_id' => $data['catid'],
  1958. 'website_category.website_id' => $data['website_id'],
  1959. ];
  1960. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1961. $child_catnum = $data['child_catnum'] ?? 1;
  1962. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1963. $childCategoryIds = array_column($category['child'], 'category_id');
  1964. if (empty($childCategoryIds)) {
  1965. return Result::error("暂无子栏目", 0);
  1966. }
  1967. $imgArticles = [];
  1968. $textArticles = [];
  1969. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1970. // 初始化子分类图片新闻和文字新闻数组
  1971. // 查询所有子级栏目的图文新闻
  1972. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1973. ->where(function ($query) use ($data) {
  1974. $query->where(function ($subQuery) use ($data) {
  1975. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1976. })->orWhereNull("ignore_ids");
  1977. })
  1978. ->where('status', 1)
  1979. ->where('imgurl', '!=', '')
  1980. ->select('*')
  1981. ->orderBy('updated_at', 'desc')
  1982. ->limit($data['child_imgnum'])
  1983. ->get();
  1984. }
  1985. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1986. // 查询所有子级栏目的文字新闻
  1987. $textArticles = Article::where('catid', $childCategoryIds[0])
  1988. ->where('status', 1)
  1989. ->where(function ($query) use ($data) {
  1990. $query->where(function ($subQuery) use ($data) {
  1991. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1992. })->orWhereNull("ignore_ids");
  1993. })
  1994. ->select('*')
  1995. ->orderBy('updated_at', 'desc')
  1996. ->limit($data['child_textnum'])
  1997. ->get();
  1998. }
  1999. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2000. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2001. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2002. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2003. return $child;
  2004. }, $category['child']);
  2005. }
  2006. // }
  2007. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2008. $category['img'] = WebsiteCategory::where($where)
  2009. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2010. ->where('article.status', 1)
  2011. ->where('article.imgurl', '!=', '')
  2012. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2013. ->orderBy('article.updated_at', 'desc')
  2014. ->limit($data['img_num'])
  2015. ->get();
  2016. }
  2017. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2018. $category['text'] = WebsiteCategory::where($where)
  2019. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2020. ->where('article.status', 1)
  2021. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2022. ->orderBy('article.updated_at', 'desc')
  2023. ->limit($data['text_num'])
  2024. ->get();
  2025. }
  2026. // $category = $category->get();
  2027. if (empty($category)) {
  2028. return Result::error("查询失败", 0);
  2029. }
  2030. return Result::success($category);
  2031. }
  2032. /**
  2033. * 模块新闻加强plus版
  2034. * @param array $data
  2035. * @return array
  2036. */
  2037. public function getWebsiteAllArticle(array $data): array
  2038. {
  2039. // return Result::success($data);
  2040. $time1 = microtime(true);
  2041. $wetbsite_id = $data['website_id'] ?? 2;
  2042. $data = json_decode($data['id'], true);
  2043. $website = Website::where('id', $wetbsite_id)->first();
  2044. if (empty($website)) {
  2045. return Result::error("网站不存在", 0);
  2046. }
  2047. // return Result::success($website);
  2048. $website_column = $website['website_column_arr_id'] ?? '[]';
  2049. $website_column = json_decode($website_column, true);
  2050. $categorys = $this->processArticlePro($wetbsite_id);
  2051. $cat_1st_arr = $categorys['cat_1st_arr'];
  2052. $catiall = $categorys['catiall'];
  2053. // return Result::success($catiall);
  2054. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2055. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2056. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2057. }
  2058. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2059. // return Result::success($categorys);
  2060. $parent_category = array_column($data, 'parent');
  2061. $parent_cat = [];
  2062. $child_category = array_column($data, 'child');
  2063. if (!empty($parent_category)) {
  2064. foreach ($parent_category as $key => $value) {
  2065. $arr = array_map('intval', explode(',', $value));
  2066. $parent_cat[$key] = $arr[0] ?? 0;
  2067. $parent_category = $arr[0] ?? 0;
  2068. $article_imgnum = $arr[1] ?? 0;
  2069. $article_textnum = $arr[2] ?? 0;
  2070. if ($parent_category != 0) {
  2071. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2072. // return Result::success($category_arr);
  2073. if ($article_imgnum != 0) {
  2074. $img_article = Article::whereIn('catid', $category_arr)
  2075. ->where('status', 1)
  2076. ->where('imgurl', '!=', '')
  2077. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2078. $query->from('article_ignore')
  2079. ->where('website_id', $wetbsite_id);
  2080. }, 'article_ignore', function ($join) {
  2081. $join->on('article_ignore.article_id', '=', 'article.id');
  2082. })
  2083. ->where(function ($query) {
  2084. $query->whereNull('article_ignore.article_id')
  2085. ->orWhere(function ($subQuery) {
  2086. $subQuery->whereNotNull('article_ignore.article_id')
  2087. ->where('article_ignore.is_ignore', 0)
  2088. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2089. });
  2090. })
  2091. ->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')
  2092. ->orderBy('updated_at', 'desc')
  2093. ->limit($article_imgnum)
  2094. ->get()->all();
  2095. foreach ($img_article as $k => $v) {
  2096. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2097. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2098. }
  2099. } else {
  2100. $img_article = [];
  2101. }
  2102. if ($article_textnum != 0) {
  2103. $text_article = Article::whereIn('catid', $category_arr)
  2104. ->where('status', 1)
  2105. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2106. $query->from('article_ignore')
  2107. ->where('website_id', $wetbsite_id);
  2108. }, 'article_ignore', function ($join) {
  2109. $join->on('article_ignore.article_id', '=', 'article.id');
  2110. })
  2111. ->where(function ($query) {
  2112. $query->whereNull('article_ignore.article_id')
  2113. ->orWhere(function ($subQuery) {
  2114. $subQuery->whereNotNull('article_ignore.article_id')
  2115. ->where('article_ignore.is_ignore', 0)
  2116. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2117. });
  2118. })
  2119. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2120. ->orderBy('updated_at', 'desc')
  2121. ->limit($article_textnum)
  2122. ->get()->all();
  2123. foreach ($text_article as $k => $v) {
  2124. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2125. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2126. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2127. }
  2128. } else {
  2129. $text_article = [];
  2130. }
  2131. $catiall[$parent_category]['imgnum'] = $img_article;
  2132. $catiall[$parent_category]['textnum'] = $text_article;
  2133. $parent[$key] = $catiall[$parent_category];
  2134. } else {
  2135. $parent[$key] = '';
  2136. }
  2137. }
  2138. }
  2139. if (!empty($child_category)) {
  2140. foreach ($child_category as $key => $value) {
  2141. $arr = array_map('intval', explode(',', $value));
  2142. $parent_category = $parent_cat[$key];
  2143. $child_category = $arr[0] ?? 0;
  2144. $article_imgnum = $arr[1] ?? 0;
  2145. $article_textnum = $arr[2] ?? 0;
  2146. if ($child_category != 0) {
  2147. $all_childcat = $cat_1st_arr[$parent_category];
  2148. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2149. // 从 $websiteInfoIndexed 中获取对应的数据
  2150. $info = $websiteInfoIndexed[$v];
  2151. // 返回一个包含所需信息的数组
  2152. return [
  2153. 'alias' => $info->alias,
  2154. 'category_id' => $info->category_id,
  2155. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2156. 'pid' => $info->pid,
  2157. 'type' => $info->type,
  2158. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2159. 'pinyin' => $info->pinyin,
  2160. ];
  2161. }, $all_childcat);
  2162. if ($article_imgnum != 0) {
  2163. $img_article = Article::where('catid', $child_category)
  2164. ->where('status', 1)
  2165. ->where('imgurl', '!=', '')
  2166. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2167. $query->from('article_ignore')
  2168. ->where('website_id', $wetbsite_id);
  2169. }, 'article_ignore', function ($join) {
  2170. $join->on('article_ignore.article_id', '=', 'article.id');
  2171. })
  2172. ->where(function ($query) {
  2173. $query->whereNull('article_ignore.article_id')
  2174. ->orWhere(function ($subQuery) {
  2175. $subQuery->whereNotNull('article_ignore.article_id')
  2176. ->where('article_ignore.is_ignore', 0)
  2177. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2178. });
  2179. })
  2180. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2181. ->orderBy('updated_at', 'desc')
  2182. ->limit($article_imgnum)
  2183. ->get()->all();
  2184. foreach ($img_article as $k => $v) {
  2185. // var_dump($v);
  2186. // var_dump($k);
  2187. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2188. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2189. }
  2190. } else {
  2191. $img_article = [];
  2192. }
  2193. if ($article_textnum != 0) {
  2194. $text_article = Article::where('catid', $child_category)
  2195. ->where('status', 1)
  2196. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2197. $query->from('article_ignore')
  2198. ->where('website_id', $wetbsite_id);
  2199. }, 'article_ignore', function ($join) {
  2200. $join->on('article_ignore.article_id', '=', 'article.id');
  2201. })
  2202. ->where(function ($query) {
  2203. $query->whereNull('article_ignore.article_id')
  2204. ->orWhere(function ($subQuery) {
  2205. $subQuery->whereNotNull('article_ignore.article_id')
  2206. ->where('article_ignore.is_ignore', 0)
  2207. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2208. });
  2209. })
  2210. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2211. ->orderBy('updated_at', 'desc')
  2212. ->limit($article_textnum)
  2213. ->get()->all();
  2214. foreach ($text_article as $k => $v) {
  2215. // var_dump($v);
  2216. // var_dump($k);
  2217. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2218. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2219. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2220. }
  2221. } else {
  2222. $text_article = [];
  2223. }
  2224. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2225. $catiall[$child_category]['imgnum'] = $img_article;
  2226. $catiall[$child_category]['textnum'] = $text_article;
  2227. $child[$key] = $catiall[$child_category];
  2228. // var_dump($pids);
  2229. } else {
  2230. $child[$key] = '';
  2231. }
  2232. }
  2233. }
  2234. foreach ($parent as $key => $value) {
  2235. $result[$key] = $value;
  2236. if (!empty($child[$key])) {
  2237. // var_dump($child[$key]);
  2238. $result[$key]['child'] = $child[$key];
  2239. // $value[$key]['child'] = $child[$key];
  2240. } else {
  2241. $result[$key]['child'] = [
  2242. "alias" => null,
  2243. "category_id" => null,
  2244. "type" => null,
  2245. "pinyin" => null,
  2246. "all_childcat" => [],
  2247. "imgnum" => [],
  2248. "textnum" => []
  2249. ];
  2250. }
  2251. }
  2252. return Result::success($result);
  2253. }
  2254. /**
  2255. * 辅助方法:获取文章列表
  2256. */
  2257. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2258. {
  2259. sleep(1);
  2260. $query = Article::where('article.status', 1)
  2261. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2262. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2263. ->where(function ($query) use ($website) {
  2264. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2265. })
  2266. ->leftJoin('website_category', function ($join) use ($website) {
  2267. $join->on('article.catid', '=', 'website_category.category_id')
  2268. ->where('website_category.website_id', '=', $website['website_id']);
  2269. })
  2270. ->select(
  2271. 'article.id',
  2272. 'article.title',
  2273. 'article.imgurl',
  2274. 'article.author',
  2275. 'article.updated_at',
  2276. 'article.introduce',
  2277. 'article.islink',
  2278. 'article.linkurl',
  2279. 'article.copyfrom',
  2280. 'article.cat_arr_id',
  2281. 'article.catid',
  2282. 'website_category.alias as category_name'
  2283. )
  2284. ->orderBy('updated_at', 'desc')
  2285. ->limit($limit);
  2286. // 如果是图片文章,添加图片URL条件
  2287. if ($isImageArticle) {
  2288. $query->where('imgurl', '!=', '');
  2289. } else {
  2290. // 文字文章不需要imgurl字段
  2291. $query->addSelect('article.introduce');
  2292. }
  2293. $articles = $query->get();
  2294. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2295. }
  2296. /**
  2297. * 乡村网-获取特殊新闻模块
  2298. * @param array $data
  2299. * @return array
  2300. */
  2301. public function getWebsiteArticles(array $data): array
  2302. {
  2303. $website_id = $data['website_id'];
  2304. $website = Website::where('id', $website_id)->first();
  2305. if (empty($website)) {
  2306. return Result::error("网站不存在", 0);
  2307. }
  2308. // return Result::success($website);
  2309. $website_column = $website['website_column_arr_id'] ?? '[]';
  2310. $website_column = json_decode($website_column, true);
  2311. $catids = json_decode($data['id'], true);
  2312. $parent_category = array_column($catids, 'parent');
  2313. if (!empty($parent_category) && is_array($parent_category)) {
  2314. $categorys = $this->processArticlePro($website_id);
  2315. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2316. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2317. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2318. }
  2319. $catiall = $categorys['catiall'];
  2320. $cat_1st_arr = $categorys['cat_1st_arr'];
  2321. // return Result::success($categorys);
  2322. foreach ($parent_category as $key => $value) {
  2323. $arr = array_map('intval', explode(',', $value));
  2324. $parent_category = $arr[0] ?? 0;
  2325. $article_imgnum = $arr[1] ?? 0;
  2326. $article_textnum = $arr[2] ?? 0;
  2327. if ($parent_category != 0) {
  2328. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2329. // return Result::success($category_arr);
  2330. if ($article_imgnum != 0) {
  2331. $img_article = Article::whereIn('article.catid', $category_arr)
  2332. ->where('article.status', 1)
  2333. ->where('article.imgurl', '!=', '')
  2334. ->leftJoinSub(function ($query) use ($website_id) {
  2335. $query->from('article_ignore')
  2336. ->where('website_id', $website_id);
  2337. }, 'article_ignore', function ($join) {
  2338. $join->on('article_ignore.article_id', '=', 'article.id');
  2339. })
  2340. ->where(function ($query) {
  2341. $query->whereNull('article_ignore.article_id')
  2342. ->orWhere(function ($subQuery) {
  2343. $subQuery->whereNotNull('article_ignore.article_id')
  2344. ->where('article_ignore.is_ignore', 0)
  2345. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2346. });
  2347. })
  2348. ->select(
  2349. 'article.id',
  2350. 'article.title',
  2351. 'article.imgurl',
  2352. 'article.author',
  2353. 'article.updated_at',
  2354. 'article.introduce',
  2355. 'article.islink',
  2356. 'article.linkurl',
  2357. 'article.copyfrom',
  2358. 'article.cat_arr_id',
  2359. 'article.catid as category_id'
  2360. )
  2361. ->orderBy('updated_at', 'desc')
  2362. ->limit($article_imgnum)
  2363. ->get()->all();
  2364. foreach ($img_article as $k => $v) {
  2365. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2366. // return Result::success($v);
  2367. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2368. }
  2369. } else {
  2370. $img_article = [];
  2371. }
  2372. if ($article_textnum != 0) {
  2373. $text_article = Article::whereIn('article.catid', $category_arr)
  2374. ->where('article.status', 1)
  2375. ->leftJoinSub(function ($query) use ($website_id) {
  2376. $query->from('article_ignore')
  2377. ->where('website_id', $website_id);
  2378. }, 'article_ignore', function ($join) {
  2379. $join->on('article_ignore.article_id', '=', 'article.id');
  2380. })
  2381. ->where(function ($query) {
  2382. $query->whereNull('article_ignore.article_id')
  2383. ->orWhere(function ($subQuery) {
  2384. $subQuery->whereNotNull('article_ignore.article_id')
  2385. ->where('article_ignore.is_ignore', 0)
  2386. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2387. });
  2388. })
  2389. ->select(
  2390. 'article.id',
  2391. 'article.title',
  2392. 'article.author',
  2393. 'article.updated_at',
  2394. 'article.introduce',
  2395. 'article.islink',
  2396. 'article.linkurl',
  2397. 'article.copyfrom',
  2398. 'article.cat_arr_id',
  2399. 'article.catid as category_id'
  2400. )
  2401. ->orderBy('updated_at', 'desc')
  2402. ->limit($article_textnum)
  2403. ->get()->all();
  2404. foreach ($text_article as $k => $v) {
  2405. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2406. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2407. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2408. }
  2409. } else {
  2410. $text_article = [];
  2411. }
  2412. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2413. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2414. $parent[$key] = $catiall[$parent_category];
  2415. } else {
  2416. $parent[$key] = [];
  2417. }
  2418. }
  2419. }
  2420. return Result::success($parent);
  2421. }
  2422. // 封装处理商品的路由问题
  2423. function processGoods($goods, $data)
  2424. {
  2425. return $goods->map(function ($good) use ($data) {
  2426. $catid = $good->catid ?? 0;
  2427. // $pinyin = '';
  2428. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2429. if (!empty($category->pid) && $category->pid != 0) {
  2430. $level = json_decode($category->category_arr_id, true);
  2431. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2432. ->whereIn('category_id', $level)
  2433. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2434. ->get(['aLIas_pinyin'])
  2435. ->pluck('aLIas_pinyin')
  2436. ->implode('/');
  2437. } else {
  2438. $pinyin = $category->aLIas_pinyin ?? '';
  2439. }
  2440. if (isset($good->city_id) && !empty($good->city_id)) {
  2441. $city = District::where('id', $good->city_id)->first(['name']);
  2442. $good->city_name = $city->name ?? '';
  2443. }
  2444. // 解析imgurl JSON并取第一条数据
  2445. $imgUrls = json_decode($good->imgurl, true);
  2446. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2447. $good->pinyin = $pinyin;
  2448. return $good;
  2449. });
  2450. }
  2451. /**
  2452. * 获取商城首页-根据栏目id
  2453. * @param array $data
  2454. * @return array
  2455. * */
  2456. function getWebsiteCatidshop(array $data): array
  2457. {
  2458. $input['catid'] = $data['catid'];
  2459. $input['website_id'] = $data['website_id'];
  2460. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2461. $result = array_map(function ($item) use ($input) {
  2462. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2463. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2464. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2465. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2466. if (empty($category) || $category->type != 2) {
  2467. return Result::error("暂无此栏目", 0);
  2468. } else {
  2469. $website['website_id'] = $input['website_id'];
  2470. $goods = Good::where('good.status', 2)
  2471. ->where('good.website_id', $website['website_id'])
  2472. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2473. ->select(
  2474. 'good.id',
  2475. 'good.name',
  2476. 'good.imgurl',
  2477. 'good.description',
  2478. 'good.updated_at',
  2479. 'good.catid',
  2480. 'good.type_id',
  2481. 'good.price',
  2482. 'good.com',
  2483. 'good.level',
  2484. 'good.unit'
  2485. )
  2486. ->orderBy('updated_at', 'desc')
  2487. ->offset($goodStart)
  2488. ->limit($goodNum);
  2489. $all_goods = $goods->get();
  2490. $all_goods = $this->processGoods($all_goods, $website);
  2491. }
  2492. return $all_goods ?? [];
  2493. }
  2494. }, $data);
  2495. return Result::success($result);
  2496. }
  2497. /**
  2498. * 获取商品模块
  2499. * @param array $data
  2500. * @return array
  2501. * */
  2502. public function getWebsiteshop(array $data): array
  2503. {
  2504. $input['id'] = $data['id'];
  2505. $input['website_id'] = $data['website_id'];
  2506. $catid = $data['catid'];
  2507. $data = json_decode($input['id'] ?? '', true) ?? [];
  2508. $result['goods'] = array_map(function ($item) use ($input) {
  2509. // 检查parent元素是否存在且不是undefined
  2510. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2511. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2512. $website = $input['website_id'];
  2513. $query = Good::where('good.status', 2)
  2514. ->where('good.website_id', $website);
  2515. switch ($Levelid) {
  2516. case 1:
  2517. case 2:
  2518. case 3:
  2519. $goods = $query->where(function ($q) use ($Levelid) {
  2520. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2521. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2522. });
  2523. break;
  2524. case 4:
  2525. $goods = $query;
  2526. break;
  2527. case 5:
  2528. $goods = $query->where('type_id', 1);
  2529. break;
  2530. case 6:
  2531. $goods = $query->where('type_id', 2);
  2532. break;
  2533. default:
  2534. return [];
  2535. }
  2536. $all_goods = $goods
  2537. ->select(
  2538. 'good.id',
  2539. 'good.name',
  2540. 'good.imgurl',
  2541. 'good.description',
  2542. 'good.updated_at',
  2543. 'good.catid',
  2544. 'good.type_id',
  2545. 'good.price',
  2546. 'good.level',
  2547. 'good.website_id'
  2548. )
  2549. ->orderBy('updated_at', 'desc')
  2550. ->offset($goodStart)
  2551. ->limit($goodNum)
  2552. ->get();
  2553. $web['website_id'] = $website;
  2554. $all_goods = $this->processGoods($all_goods, $web);
  2555. }
  2556. return $all_goods;
  2557. }, $data);
  2558. $website = $input['website_id'];
  2559. $result['article'] = Article::where(function ($query) use ($website) {
  2560. $query->where(function ($subQuery) use ($website) {
  2561. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2562. })->orWhereNull("ignore_ids");
  2563. })
  2564. ->where('catid', $catid)
  2565. ->where('article.status', 1)
  2566. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2567. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2568. ->orderBy('article.updated_at', 'desc')
  2569. ->first();
  2570. return Result::success($result);
  2571. }
  2572. /**
  2573. * 获取商品分类
  2574. * @param array $data
  2575. * @return array
  2576. * */
  2577. public function getWebsiteshopCat(array $data): array
  2578. {
  2579. $website = $data['website_id'];
  2580. $category = WebsiteCategory::where('website_id', $website)
  2581. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2582. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2583. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2584. ->orderBy('sort')
  2585. ->get();
  2586. $cat = $category->map(function ($item) use ($website) {
  2587. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2588. $pid = $item->pid ?? 0;
  2589. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2590. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2591. ->where('website_id', $website)
  2592. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2593. ->get(['aLIas_pinyin'])
  2594. ->pluck('aLIas_pinyin')
  2595. ->implode('/');
  2596. } else {
  2597. $pinyin = $item->aLIas_pinyin ?? '';
  2598. }
  2599. $item->pinyin = $pinyin;
  2600. });
  2601. if (empty($category)) {
  2602. return Result::error("栏目查询失败", 0);
  2603. }
  2604. $cat_tree = Result::buildMenuTree($category);
  2605. $web['website_id'] = $website;
  2606. $goods = Good::where('website_id', $website)
  2607. ->where('status', 2)
  2608. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2609. ->latest('updated_at')
  2610. ->offset(($data['page'] - 1) * $data['pageSize'])
  2611. ->limit($data['pageSize'])
  2612. ->get();
  2613. if (!empty($goods)) {
  2614. if ($goods->count() > 1 && !empty($goods)) {
  2615. $goods = $this->processGoods($goods, $web);
  2616. }
  2617. } else {
  2618. $goods = [];
  2619. }
  2620. $result = [
  2621. 'category' => $cat_tree,
  2622. 'goods' => $goods,
  2623. ];
  2624. // $resul['goods'] = $goods;
  2625. if (empty($result)) {
  2626. return Result::error("查询失败", 0);
  2627. }
  2628. return Result::success($result);
  2629. }
  2630. /*
  2631. * 获取商品列表
  2632. * @param array $data
  2633. * @return array
  2634. * */
  2635. public function getWebsiteshopList(array $data): array
  2636. {
  2637. // return Result::success($data);
  2638. $where = [
  2639. 'status' => 2,
  2640. 'website_id' => $data['website_id'],
  2641. ];
  2642. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2643. // return Result::error("查询失败", 0);
  2644. // }
  2645. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2646. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2647. $data['catid'] = $category->category_id ?? 0;
  2648. }
  2649. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2650. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2651. }
  2652. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2653. array_push($where, ['type_id', $data['type_id']]);
  2654. }
  2655. $query = Good::where($where)
  2656. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2657. $query->where(function ($q) use ($data) {
  2658. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2659. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2660. });
  2661. })
  2662. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2663. $query->where(function ($q) use ($data) {
  2664. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2665. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2666. });
  2667. })
  2668. ->select(
  2669. 'good.id',
  2670. 'good.name',
  2671. 'good.imgurl',
  2672. 'good.description',
  2673. 'good.updated_at',
  2674. 'good.com',
  2675. 'good.catid',
  2676. 'good.type_id',
  2677. 'good.website_id',
  2678. 'good.cat_arr_id',
  2679. 'good.created_at',
  2680. 'good.city_id'
  2681. )
  2682. ->latest('updated_at');
  2683. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2684. $result['count'] = $query->clone()->count();
  2685. $result['goods'] = $this->processGoods(
  2686. $query->clone()
  2687. ->offset(($data['page'] - 1) * $data['pageSize'])
  2688. ->limit($data['pageSize'])
  2689. ->get(),
  2690. $data
  2691. );
  2692. } else {
  2693. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2694. // 获取 type_id 为 1 的数据
  2695. $result['type1'] = $this->processGoods(
  2696. $query->clone()
  2697. ->where('type_id', 1)
  2698. ->offset(($data['page'] - 1) * $data['pageSize'])
  2699. ->limit($data['pageSize'])
  2700. ->get(),
  2701. $data
  2702. );
  2703. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2704. // 获取 type_id 为 2 的数据
  2705. $result['type2'] = $this->processGoods(
  2706. $query->clone()
  2707. ->where('type_id', 2)
  2708. ->offset(($data['page'] - 1) * $data['pageSize'])
  2709. ->limit($data['pageSize'])
  2710. ->get(),
  2711. $data
  2712. );
  2713. }
  2714. if (empty($result)) {
  2715. return Result::error("查询失败", 0);
  2716. }
  2717. return Result::success($result);
  2718. }
  2719. /**
  2720. * 获取商品详情
  2721. * @param array $data
  2722. * @return array
  2723. * */
  2724. public function getWebsiteshopInfo(array $data): array
  2725. {
  2726. $where = [
  2727. 'good.status' => 2,
  2728. 'good.website_id' => $data['website_id'],
  2729. 'good.id' => $data['id'],
  2730. ];
  2731. $goods = Good::where($where)
  2732. ->where('good.id', $data['id'])
  2733. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2734. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2735. ->first();
  2736. if (empty($goods)) {
  2737. return Result::error("查询失败", 0);
  2738. }
  2739. $goods->imgurl = json_decode($goods->imgurl, true);
  2740. return Result::success($goods);
  2741. }
  2742. /**
  2743. * plus pro 处理文章路由问题
  2744. */
  2745. function processArticlePro($website_id)
  2746. {
  2747. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2748. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2749. // // 取出category_id 对应的aLIas_pinyin
  2750. // $categoryIds = array_column($categorys, 'category_id');
  2751. // $categoryPIds = array_column($categorys, 'pid');
  2752. // $aliasPinyins = array_column($categorys, 'path');
  2753. // $alias = array_column($categorys, 'alias');
  2754. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2755. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2756. // // return Result::success($cat_arr);
  2757. // // $catiall = [];
  2758. // //一级所有子级的记录
  2759. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2760. // return [
  2761. // 'cat_1st_arr' => $cat_alias_arr,
  2762. // 'catiall' => $cat_arr,
  2763. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2764. // 'categoryIds' => $categoryIds,
  2765. // ];
  2766. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2767. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2768. // 取出category_id 对应的aLIas_pinyin
  2769. $categoryIds = array_column($categorys, 'category_id');
  2770. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2771. return $pid != 0;
  2772. })));
  2773. $category_path = array_column($categorys, 'path');
  2774. $cat_arr = array_combine($categoryIds, $category_path);
  2775. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2776. $catiall = [];
  2777. //一级所有子级的记录
  2778. $cat_1st_arr = [];
  2779. foreach ($categorys as $key => $value) {
  2780. // $category_arr_id = json_decode($value->category_arr_id);
  2781. // $pinyin_str = '';
  2782. // // 算出一级 并且算出子级
  2783. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2784. $cat_1st_arr[$value->pid][] = $value->category_id;
  2785. }
  2786. // foreach ($category_arr_id as $k => $v) {
  2787. // $pinyin_str .= $cat_arr[$v] . '/';
  2788. // }
  2789. // $pinyin_str = rtrim($pinyin_str, '/');
  2790. $catiall[$value->category_id]['alias'] = $value->alias;
  2791. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2792. $catiall[$value->category_id]['type'] = $value->type;
  2793. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2794. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2795. }
  2796. return [
  2797. 'cat_1st_arr' => $cat_1st_arr,
  2798. 'catiall' => $catiall,
  2799. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2800. 'categoryIds' => $categoryIds,
  2801. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2802. 'categoryPIds' => $categoryPIds,
  2803. ];
  2804. }
  2805. /**
  2806. * 封装处理文章的路由问题
  2807. * */
  2808. function processArticles($articles, $data)
  2809. {
  2810. // 检查 $articles 是否为数组或可迭代对象
  2811. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2812. return $articles->map(function ($article) use ($data) {
  2813. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2814. $catid = $article->cat_arr_id ?? '';
  2815. }
  2816. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2817. $catid = $article->category_arr_id ?? '';
  2818. }
  2819. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2820. $level = json_decode($catid, true);
  2821. if (!is_array($level)) {
  2822. return $article;
  2823. } else {
  2824. $level = array_map('intval', $level);
  2825. }
  2826. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2827. ->where($data)
  2828. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2829. ->pluck('aLIas_pinyin')
  2830. ->implode('/');
  2831. $article->pinyin = $pinyin ?? '';
  2832. return $article;
  2833. });
  2834. } else {
  2835. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2836. $catid = $articles->cat_arr_id ?? '';
  2837. $level = json_decode($catid, true);
  2838. if (!is_array($level)) {
  2839. return $articles;
  2840. } else {
  2841. $level = array_map('intval', $level);
  2842. }
  2843. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2844. ->where($data)
  2845. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2846. ->pluck('aLIas_pinyin')
  2847. ->implode('/');
  2848. $articles->pinyin = $pinyin ?? '';
  2849. return $articles;
  2850. }
  2851. }
  2852. // 封装处理由问题
  2853. function processJob($job, $data)
  2854. {
  2855. return $job->map(function ($job) use ($data) {
  2856. $category = $job->cat_arr_id ?? '';
  2857. $cityid = $job->city_arr_id ?? '';
  2858. $city = json_decode($cityid, true);
  2859. $pinyin = '';
  2860. $level = json_decode($category, true);
  2861. // 路由
  2862. if (!empty($level) && is_array($level)) {
  2863. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2864. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2865. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2866. ->get(['aLIas_pinyin'])
  2867. ->pluck('aLIas_pinyin')
  2868. ->implode('/');
  2869. if (empty($pinyin)) {
  2870. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2871. }
  2872. $job->pinyin = $pinyin;
  2873. }
  2874. // 取职位-城市 市??省
  2875. if (!empty($city) && is_array($city)) {
  2876. if (isset($city[1]) && !empty($city[1])) {
  2877. $city = District::where('id', $city[1])->first(['name']);
  2878. $job->city_name = $city->name ?? '';
  2879. } else if (isset($city[0]) && !empty($city[0])) {
  2880. $city = District::where('id', $city[0])->first(['name']);
  2881. $job->city_name = $city->name ?? '';
  2882. } else {
  2883. $job->city_name = '全国';
  2884. }
  2885. }
  2886. // 获取简历最后一级地区
  2887. if (isset($job->city_id) && !empty($job->city_id)) {
  2888. $city = District::where('id', $job->city_id)->first(['name']);
  2889. $job->hunt_cityname = $city->name ?? '';
  2890. }
  2891. // 组合详细地址
  2892. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2893. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2894. if (is_array($address_id) && !empty($address_id)) {
  2895. $address = District::whereIn('id', $address_id)
  2896. ->orderBy('level', 'asc')
  2897. ->get(['name'])
  2898. ->pluck('name')
  2899. ->implode('');
  2900. // $job->address_name = $address ?? '';
  2901. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2902. }
  2903. }
  2904. // 取行业
  2905. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2906. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2907. if (!empty($job->industry)) {
  2908. $query->where('hyid', $job->industry);
  2909. } else if (!empty($job->hy_id)) {
  2910. $query->where('hyid', $job->hy_id);
  2911. } else if (!empty($job->company_hy_id)) {
  2912. $query->where('hyid', $job->company_hy_id);
  2913. } else {
  2914. $query->where('hyid', $job->job_industry);
  2915. }
  2916. })->first(['hyname']);
  2917. $job->hy_name = $hy_name->hyname ?? '';
  2918. }
  2919. // 取职位类别
  2920. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2921. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2922. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2923. $job->zw_name = $zw_name->zwname ?? '';
  2924. }
  2925. // 取具体职位
  2926. 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))) {
  2927. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2928. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2929. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2930. }
  2931. // 取工作经验
  2932. if (isset($job->experience) && !empty($job->experience)) {
  2933. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2934. $job->experience_name = $experience->ename ?? '';
  2935. }
  2936. // 取学历
  2937. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2938. $education = $job->educational ?? $job->school_education;
  2939. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2940. $job->education_name = $education->ename ?? '';
  2941. }
  2942. // 语言
  2943. if (isset($job->language) && !empty($job->language)) {
  2944. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2945. $job->language_name = $language->ename ?? '';
  2946. }
  2947. // 薪资
  2948. if (isset($job->salary) && !empty($job->salary)) {
  2949. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2950. $job->salary_name = $salary->ename ?? '';
  2951. }
  2952. // 职位性质
  2953. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2954. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2955. $job->job_nature_name = $job_nature->ename ?? '';
  2956. }
  2957. // 公司规模
  2958. if (isset($job->company_size) && !empty($job->company_size)) {
  2959. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2960. $job->company_size_name = $company_size->ename ?? '';
  2961. }
  2962. // 公司性质
  2963. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2964. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2965. $job->company_nature_name = $company_nature->nature_name ?? '';
  2966. }
  2967. // $job->pinyin = $pinyin;
  2968. return $job;
  2969. });
  2970. }
  2971. /**
  2972. * 获取书籍模块
  2973. * @param array $data
  2974. * @return array
  2975. * */
  2976. public function getWebsiteBook(array $data): array
  2977. {
  2978. $input['id'] = $data['id'];
  2979. $input['website_id'] = $data['website_id'];
  2980. // 将 JSON 字符串转换为 PHP 数组
  2981. $data = json_decode($input['id'], true);
  2982. // 使用 array_map 处理每个元素
  2983. $result = array_map(function ($item) use ($input) {
  2984. // 检查parent元素是否存在且不是undefined
  2985. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2986. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2987. $website = [
  2988. 'website_id' => $input['website_id'],
  2989. ];
  2990. // 查询栏目名称
  2991. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2992. if (empty($category)) {
  2993. $parent_alias = '';
  2994. $parent_pinyin = null;
  2995. $imgBooks = [];
  2996. $textBooks = [];
  2997. } else {
  2998. $parent_alias = $category->alias ?? '';
  2999. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3000. // 查找子分类ID数组
  3001. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3002. array_push($childCategoryIds, $parentCatId);
  3003. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3004. if ($parentImgNum != 0) {
  3005. // 查询图片新闻
  3006. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3007. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3008. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3009. })
  3010. ->where('book.status', 2)
  3011. ->where('book.img_url', '!=', '')
  3012. ->where('book.website_id', $website['website_id'])
  3013. ->leftJoin('website_category', function ($join) use ($website) {
  3014. $join->on('book.cat_id', '=', 'website_category.category_id')
  3015. ->where('website_category.website_id', '=', $website['website_id']);
  3016. })
  3017. ->select(
  3018. 'book.id',
  3019. 'book.title',
  3020. 'book.img_url',
  3021. 'book.price',
  3022. 'book.market_price',
  3023. 'book.description',
  3024. 'book.cat_id',
  3025. 'book.description',
  3026. 'book.updated_at',
  3027. 'website_category.alias as category_name',
  3028. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3029. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3030. )
  3031. ->orderBy('updated_at', 'desc')
  3032. ->limit($parentImgNum)
  3033. ->get()->all();
  3034. // 查询文字新闻
  3035. }
  3036. if ($parentTextNum != 0) {
  3037. $textBooks = [];
  3038. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3039. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3040. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3041. })
  3042. ->where('book.status', 2)
  3043. ->where('book.website_id', $website['website_id'])
  3044. ->leftJoin('website_category', function ($join) use ($website) {
  3045. $join->on('book.cat_id', '=', 'website_category.category_id')
  3046. ->where('website_category.website_id', '=', $website['website_id']);
  3047. })
  3048. ->select(
  3049. 'book.id',
  3050. 'book.title',
  3051. 'book.img_url',
  3052. 'book.price',
  3053. 'book.market_price',
  3054. 'book.description',
  3055. 'book.cat_id',
  3056. 'book.description',
  3057. 'book.updated_at',
  3058. 'website_category.alias as category_name',
  3059. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3060. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3061. )
  3062. ->orderBy('updated_at', 'desc')
  3063. ->limit($parentTextNum)
  3064. ->get()->all();
  3065. }
  3066. }
  3067. }
  3068. $resultItem = [
  3069. 'alias' => $parent_alias ?? '',
  3070. 'category_id' => $parentCatId ?? 0,
  3071. 'pinyin' => $parent_pinyin ?? null,
  3072. 'imgnum' => $imgBooks ?? [],
  3073. 'textnum' => $textBooks ?? [],
  3074. ];
  3075. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3076. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3077. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3078. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3079. ->get()->all();
  3080. if (!empty($childCategory)) {
  3081. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3082. // 查询子栏目名称
  3083. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3084. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3085. ->first();
  3086. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3087. $childImgArticles = [];
  3088. $childTextArticles = [];
  3089. $resultItem['child'] = [];
  3090. } else {
  3091. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3092. // 查询子栏目图片新闻
  3093. $childImgArticles = Book::where('cat_id', $childCatId)
  3094. ->where('status', 2)
  3095. ->where('img_url', '!=', '')
  3096. ->where('book.website_id', $website['website_id'])
  3097. ->leftJoin('website_category', function ($join) use ($website) {
  3098. $join->on('book.cat_id', '=', 'website_category.category_id')
  3099. ->where('website_category.website_id', '=', $website['website_id']);
  3100. })
  3101. ->select(
  3102. 'book.id',
  3103. 'book.title',
  3104. 'book.img_url',
  3105. 'book.price',
  3106. 'book.market_price',
  3107. 'book.description',
  3108. 'book.cat_id',
  3109. 'book.description',
  3110. 'book.updated_at',
  3111. DB::raw("'$child_pinyin' as pinyin")
  3112. )
  3113. ->orderBy('updated_at', 'desc')
  3114. ->limit($childImgNum)
  3115. ->get()->all();
  3116. // 查询子栏目文字新闻
  3117. $childTextArticles = Book::where('cat_id', $childCatId)
  3118. ->where('status', 2)
  3119. ->where('book.website_id', $website['website_id'])
  3120. ->leftJoin('website_category', function ($join) use ($website) {
  3121. $join->on('book.cat_id', '=', 'website_category.category_id')
  3122. ->where('website_category.website_id', '=', $website['website_id']);
  3123. })
  3124. ->select(
  3125. 'book.id',
  3126. 'book.title',
  3127. 'book.img_url',
  3128. 'book.price',
  3129. 'book.market_price',
  3130. 'book.description',
  3131. 'book.cat_id',
  3132. 'book.description',
  3133. 'book.updated_at',
  3134. DB::raw("'$child_pinyin' as pinyin")
  3135. )
  3136. ->orderBy('updated_at', 'desc')
  3137. ->limit($childTextNum)
  3138. ->get()->all();
  3139. $resultItem['child'] = [
  3140. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3141. 'category_id' => $childCatId,
  3142. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3143. 'all_childcat' => $childCategory,
  3144. 'imgnum' => $childImgArticles,
  3145. 'textnum' => $childTextArticles,
  3146. ];
  3147. }
  3148. }
  3149. } else {
  3150. $resultItem['child'] = [];
  3151. }
  3152. return $resultItem;
  3153. }, $data);
  3154. return Result::success($result);
  3155. }
  3156. /**
  3157. * 获取书刊列表
  3158. * @param array $data
  3159. * @return array
  3160. * */
  3161. public function getWebsiteBookList(array $data): array
  3162. {
  3163. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3164. if (empty($web)) {
  3165. return Result::error("查询失败", 0);
  3166. }
  3167. $catid = $data['id'];
  3168. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3169. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3170. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3171. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3172. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3173. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3174. ->where('pid', $category['pid'])
  3175. ->select(
  3176. 'category_id',
  3177. 'alias',
  3178. 'aLIas_pinyin',
  3179. 'pid',
  3180. 'sort',
  3181. 'is_url',
  3182. 'web_url',
  3183. 'seo_title',
  3184. 'seo_keywords',
  3185. 'seo_description',
  3186. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3187. )
  3188. ->orderBy('sort')
  3189. ->get()->all();
  3190. if (empty($category)) {
  3191. return Result::error("查询失败", 0);
  3192. }
  3193. $query = Book::where('book.status', 2)
  3194. ->where('book.website_id', $data['website_id'])
  3195. ->where('book.cat_id', $catid)
  3196. ->select(
  3197. 'book.id',
  3198. 'book.title',
  3199. 'book.img_url',
  3200. 'book.description',
  3201. 'book.updated_at',
  3202. 'book.cat_id',
  3203. DB::raw("'$pinyin' as pinyin")
  3204. )
  3205. ->orderBy('book.updated_at', 'desc');
  3206. $count = $query->count();
  3207. $query = clone $query;
  3208. $Book = $query
  3209. ->limit($data['pageSize'])
  3210. ->offset(($data['page'] - 1) * $data['pageSize'])
  3211. ->get()->all();
  3212. $result = [
  3213. 'category' => $categorys,
  3214. 'books' => $Book,
  3215. 'count' => $count,
  3216. ];
  3217. // if(empty($result)){
  3218. // return Result::error("查询失败", 0);
  3219. // }
  3220. return Result::success($result);
  3221. }
  3222. /**
  3223. * 获取书刊详情
  3224. * @param array $data
  3225. * @return array
  3226. * */
  3227. public function getWebsiteBookInfo(array $data): array
  3228. {
  3229. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3230. if (empty($web)) {
  3231. return Result::error("查询失败", 0);
  3232. }
  3233. $book = Book::where('status', 2)
  3234. ->where('website_id', $data['website_id'])
  3235. ->where('id', $data['id'])
  3236. ->select(
  3237. 'book.*',
  3238. )
  3239. ->orderBy('updated_at', 'desc')
  3240. ->first();
  3241. if (empty($book)) {
  3242. return Result::error("查询失败", 0);
  3243. }
  3244. // 先查询当前分类的 pid
  3245. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3246. ->where('category_id', $book['cat_id'])
  3247. ->first(['pid', 'category_id']);
  3248. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3249. if (!empty($carpid)) {
  3250. if ($carpid->pid != 0) {
  3251. $pid = $carpid['pid'];
  3252. // $parent_pinyin = '';
  3253. } else {
  3254. $pid = $carpid['category_id'];
  3255. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3256. }
  3257. }
  3258. $categorys = $query->where('pid', $pid)
  3259. ->select(
  3260. 'category_id',
  3261. 'alias',
  3262. 'aLIas_pinyin',
  3263. 'pid',
  3264. 'sort',
  3265. 'is_url',
  3266. 'web_url',
  3267. 'category_arr_id as cat_arr_id',
  3268. )
  3269. ->orderBy('sort')
  3270. ->get();
  3271. $category = $this->processArticle($categorys, $data);
  3272. $result = [
  3273. 'category' => $category,
  3274. 'books' => $book,
  3275. ];
  3276. return Result::success($result);
  3277. }
  3278. /**
  3279. * 尝试
  3280. * @param array $data
  3281. * @return array
  3282. * */
  3283. public function test(array $data): array
  3284. {
  3285. $input['id'] = $data['id'];
  3286. $input['website_id'] = $data['website_id'];
  3287. // 将 JSON 字符串转换为 PHP 数组
  3288. $data = json_decode($input['id'], true);
  3289. $result = [];
  3290. $article = $data;
  3291. $result = array_map(function ($item) use ($input) {
  3292. $website = [
  3293. 'website_id' => $input['website_id'],
  3294. ];
  3295. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3296. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3297. $parent = [
  3298. 0 => $category['category_id'] ?? [],
  3299. 1 => $parentImgNum ?? [],
  3300. 2 => $parentTextNum ?? [],
  3301. ];
  3302. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3303. $child = [];
  3304. $resultItem = [
  3305. // 'alias' => $parent_alias ?? '',
  3306. 'category_id' => $parentCatId ?? 0,
  3307. 'pinyin' => $parentImgNum ?? null,
  3308. 'imgnum' => $parentTextNum ?? [],
  3309. // 'textnum' => $textArticles ?? [],
  3310. ];
  3311. return $parent;
  3312. }, $data);
  3313. return Result::success($result);
  3314. // });
  3315. }
  3316. /**
  3317. * 封装处理文章的路由问题
  3318. * */
  3319. function processArticle($article, $data)
  3320. {
  3321. return $article->map(function ($article) use ($data) {
  3322. $catid = $article->cat_arr_id ?? '';
  3323. $level = json_decode($catid, true);
  3324. $pinyin = '';
  3325. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3326. if (!empty($level) && is_array($level)) {
  3327. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3328. ->where('website_id', $data['website_id'])
  3329. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3330. ->get(['aLIas_pinyin'])
  3331. ->pluck('aLIas_pinyin')
  3332. ->implode('/');
  3333. } else {
  3334. $pinyin = '';
  3335. }
  3336. $article->pinyin = $pinyin;
  3337. return $article;
  3338. });
  3339. }
  3340. /**
  3341. * c端-获取招工招聘下拉选框
  3342. * @param array $data
  3343. * @return array
  3344. * */
  3345. public function getWebsiteJobSelect(array $data): array
  3346. {
  3347. $web = Website::where('id', $data['website_id'])->first();
  3348. if (empty($web)) {
  3349. return Result::error("该网站不存在", 0);
  3350. }
  3351. $hy = JobIndustry::get()->all();
  3352. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3353. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3354. $result = [
  3355. 'hy' => $hy,
  3356. 'zw' => $zw,
  3357. 'jtzw' => $jtzw,
  3358. ];
  3359. if (empty($result)) {
  3360. return Result::error("查询失败", 0);
  3361. }
  3362. return Result::success($result);
  3363. }
  3364. /**
  3365. * c端-获取招工招聘
  3366. * @param array $data
  3367. * @return array
  3368. * */
  3369. public function getWebsiteJob(array $data): array
  3370. {
  3371. $web = Website::where('id', $data['website_id'])->first();
  3372. if (empty($web)) {
  3373. return Result::error("该网站不存在", 0);
  3374. }
  3375. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3376. ->where('job_hunting.website_id', $data['website_id'])
  3377. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3378. $query->where(function ($q) use ($data) {
  3379. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3380. });
  3381. })
  3382. ->select(
  3383. 'job_hunting.id',
  3384. 'job_hunting.catid',
  3385. 'job_hunting.cat_arr_id',
  3386. 'job_hunting.job_name_get',
  3387. 'job_hunting.industry',
  3388. 'job_hunting.name',
  3389. 'job_hunting.sexy',
  3390. 'job_hunting.origin',
  3391. 'job_hunting.city_arr_id',
  3392. 'job_hunting.experience',
  3393. 'job_hunting.updated_at',
  3394. 'job_hunting.salary',
  3395. 'job_hunting.skillList',
  3396. 'job_hunting.slelf_evaluation',
  3397. )
  3398. ->orderBy('updated_at', 'desc')
  3399. ->limit($data['job1_num'])
  3400. ->get();
  3401. $web['website_id'] = $data['website_id'];
  3402. if (empty($job_hunting)) {
  3403. $job_huntings = "未查询到相关简历信息";
  3404. } else {
  3405. $job_huntings = $this->processJob($job_hunting, $web);
  3406. }
  3407. // 0:待审核 1:已通过 2:已拒绝
  3408. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3409. ->where('job_recruiting.website_id', $data['website_id'])
  3410. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3411. $query->where(function ($q) use ($data) {
  3412. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3413. });
  3414. })
  3415. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3416. ->select(
  3417. 'job_recruiting.id',
  3418. 'job_recruiting.catid',
  3419. 'job_recruiting.cat_arr_id',
  3420. 'job_recruiting.title',
  3421. 'job_recruiting.jtzw_id',
  3422. 'job_recruiting.hy_id',
  3423. 'job_recruiting.city_arr_id',
  3424. 'job_recruiting.due_data',
  3425. 'job_recruiting.updated_at',
  3426. 'job_recruiting.experience',
  3427. 'job_recruiting.educational',
  3428. 'job_recruiting.salary',
  3429. 'job_recruiting.zw_id',
  3430. 'job_company.business_name',
  3431. 'job_recruiting.keyword',
  3432. 'job_recruiting.description',
  3433. )
  3434. ->orderBy('updated_at', 'desc')
  3435. ->limit($data['job2_num'])
  3436. ->get();
  3437. if (empty($job_recruiting->toArray())) {
  3438. $job_recruitings = "未查询到相关职位信息";
  3439. } else {
  3440. $job_recruitings = $this->processJob($job_recruiting, $web);
  3441. }
  3442. $result = [
  3443. 'job_hunting' => $job_huntings,
  3444. 'job_recuiting' => $job_recruitings,
  3445. ];
  3446. return Result::success($result);
  3447. }
  3448. /**
  3449. * c端-获取招工招聘列表
  3450. * @param array $data
  3451. * @return array
  3452. * */
  3453. public function getWebsiteJobList(array $data): array
  3454. {
  3455. $recruit_where = [];
  3456. $hunt_where = [];
  3457. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3458. if (empty($web)) {
  3459. return Result::error("此网站不存在", 0);
  3460. }
  3461. $website_id['website_id'] = $data['website_id'];
  3462. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3463. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3464. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3465. }
  3466. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3467. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3468. }
  3469. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3470. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3471. }
  3472. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3473. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3474. }
  3475. $query = JobRecruiting::where('job_recruiting.status', 1)
  3476. ->where('job_recruiting.website_id', $data['website_id'])
  3477. ->where($recruit_where)
  3478. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3479. $query->where(function ($q) use ($data) {
  3480. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3481. });
  3482. })
  3483. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3484. $query->where(function ($q) use ($data) {
  3485. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3486. });
  3487. })
  3488. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3489. ->select(
  3490. 'job_recruiting.id',
  3491. 'job_recruiting.catid',
  3492. 'job_recruiting.hy_id',
  3493. 'job_recruiting.title',
  3494. 'job_recruiting.zw_id',
  3495. 'job_recruiting.educational',
  3496. 'job_recruiting.jtzw_id',
  3497. 'job_recruiting.city_arr_id',
  3498. 'job_recruiting.due_data',
  3499. 'job_recruiting.experience',
  3500. 'job_recruiting.cat_arr_id',
  3501. 'job_recruiting.updated_at',
  3502. 'job_company.business_name',
  3503. 'job_recruiting.keyword',
  3504. 'job_recruiting.description',
  3505. )
  3506. ->orderBy('job_recruiting.updated_at', 'desc');
  3507. $recruit_count = $query->count();
  3508. $query = clone $query;
  3509. $JobRecruiting = $query
  3510. ->offset(($data['page'] - 1) * $data['pageSize'])
  3511. ->limit($data['pageSize'])
  3512. ->get();
  3513. if (empty($JobRecruiting)) {
  3514. $JobRecruiting = "暂无相关职位信息";
  3515. } else {
  3516. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3517. }
  3518. }
  3519. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3520. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3521. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3522. }
  3523. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3524. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3525. }
  3526. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3527. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3528. }
  3529. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3530. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3531. }
  3532. $query = JobHunting::where('job_hunting.status', 2)
  3533. ->where('job_hunting.website_id', $data['website_id'])
  3534. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3535. ->where($hunt_where)
  3536. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3537. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3538. // })
  3539. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3540. $query->where(function ($q) use ($data) {
  3541. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3542. });
  3543. })
  3544. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3545. $query->where(function ($q) use ($data) {
  3546. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3547. });
  3548. })
  3549. ->select(
  3550. 'job_hunting.id',
  3551. 'job_hunting.catid',
  3552. 'job_hunting.sexy',
  3553. 'job_hunting.experience',
  3554. 'job_hunting.origin',
  3555. 'job_hunting.industry',
  3556. 'job_hunting.name',
  3557. 'job_hunting.job',
  3558. 'job_hunting.job_name_get',
  3559. 'job_hunting.city_arr_id',
  3560. 'job_hunting.cat_arr_id',
  3561. 'job_hunting.created_at',
  3562. 'job_hunting.updated_at',
  3563. 'job_position.zwname as job_name',
  3564. 'job_hunting.skillList',
  3565. 'job_hunting.slelf_evaluation',
  3566. )
  3567. ->orderBy('job_hunting.updated_at', 'desc');
  3568. $hunt_count = $query->count();
  3569. $query = clone $query;
  3570. $JobHunting = $query
  3571. ->offset(($data['page'] - 1) * $data['pageSize'])
  3572. ->limit($data['pageSize'])
  3573. ->get();
  3574. if (empty($JobHunting)) {
  3575. $JobRecruiting = "暂无相关简历信息";
  3576. } else {
  3577. $JobHunting = $this->processJob($JobHunting, $website_id);
  3578. }
  3579. }
  3580. $result = [
  3581. 'JobRecruiting' => $JobRecruiting ?? [],
  3582. 'recruit_count' => $recruit_count ?? 0,
  3583. 'JobHunting' => $JobHunting ?? [],
  3584. 'hunt_count' => $hunt_count ?? 0,
  3585. ];
  3586. return Result::success($result);
  3587. }
  3588. /**
  3589. * c端-获取招工招聘详情
  3590. * @param array $data
  3591. * @return array
  3592. * */
  3593. public function getWebsiteJobInfo(array $data): array
  3594. {
  3595. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3596. if (empty($web)) {
  3597. return Result::error("该网站不存在", 0);
  3598. }
  3599. $webid = [
  3600. 'website_id' => $data['website_id'],
  3601. ];
  3602. // 职位相关信息
  3603. if ($data['type'] == 1) {
  3604. $query = JobRecruiting::where('status', 1)
  3605. ->where('website_id', $data['website_id'])
  3606. ->select('*');
  3607. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3608. $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();
  3609. if (!empty($company)) {
  3610. $result['company'] = $this->processJob($company, $webid);
  3611. }
  3612. $other_job = JobRecruiting::where('status', 1)
  3613. ->where('website_id', $data['website_id'])
  3614. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3615. ->where('id', '!=', $data['id'])
  3616. ->where('user_id', '=', $job[0]['user_id'])
  3617. ->limit($data['pageSize'])
  3618. ->get();
  3619. if (!empty($other_job)) {
  3620. $result['other_job'] = $this->processJob($other_job, $webid);
  3621. }
  3622. } else {
  3623. // 简历相关信息
  3624. $job = JobHunting::where('job_hunting.status', 2)
  3625. ->where('job_hunting.website_id', $data['website_id'])
  3626. ->where('job_hunting.id', $data['id'])
  3627. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3628. ->select('job_hunting.*', 'user_name')
  3629. ->get();
  3630. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3631. if (!empty($resume->toArray())) {
  3632. $result['resume'] = 1;
  3633. } else {
  3634. $result['resume'] = 0;
  3635. }
  3636. }
  3637. if (empty($job->toArray())) {
  3638. return Result::error("id参数错误", 0);
  3639. }
  3640. if (!empty($job[0]['job_experience'])) {
  3641. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3642. if (!empty($job_experience)) {
  3643. // $hy = [];
  3644. foreach ($job_experience as $key => $value) {
  3645. // $id = $value['id'];
  3646. $hy[$key] = $value['job_industry'];
  3647. $zw_id[$key] = $value['job_typename'];
  3648. $jtzw_id[$key] = $value['job_name'];
  3649. }
  3650. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3651. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3652. // 先将关联表转换为索引数组,提高查找效率
  3653. $hyLookup = [];
  3654. foreach ($hy_table as $item) {
  3655. $hyLookup[$item['hyid']] = $item['hyname'];
  3656. }
  3657. $zwLookup = [];
  3658. foreach ($zw_table as $item) {
  3659. $zwLookup[$item['zwid']] = $item['zwname'];
  3660. }
  3661. foreach ($job_experience as $key => &$value) {
  3662. // 处理行业名称
  3663. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3664. $value['hy_name'] = $hyLookup[$hy[$key]];
  3665. }
  3666. // 处理职位名称
  3667. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3668. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3669. }
  3670. // 处理具体职位名称
  3671. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3672. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3673. }
  3674. }
  3675. // 释放引用,防止意外修改后续代码
  3676. unset($value);
  3677. }
  3678. $result['job_experience'] = $job_experience ?? [];
  3679. }
  3680. if (!empty($job[0]['education_experience'])) {
  3681. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3682. if (!empty($education_experience)) {
  3683. foreach ($education_experience as $key => $value) {
  3684. // $id = $value['id'];
  3685. $education[$key] = $value['school_education'];
  3686. }
  3687. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3688. // // 先将关联表转换为索引数组,提高查找效率
  3689. $educationLookup = [];
  3690. foreach ($education_table as $item) {
  3691. $educationLookup[$item['evalue']] = $item['ename'];
  3692. }
  3693. foreach ($education_experience as $key => &$value) {
  3694. // 处理学历名称
  3695. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3696. $value['education_name'] = $educationLookup[$education[$key]];
  3697. }
  3698. }
  3699. }
  3700. $result['education_experience'] = $job_experience ?? [];
  3701. }
  3702. $result['job'] = $this->processJob($job, $webid);
  3703. // // 返现对应的栏目
  3704. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3705. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3706. ->whereIn('category_id', $catid)
  3707. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3708. ->orderBy('pid')->get()->all();
  3709. if (!empty($category)) {
  3710. $result['category'] = $category;
  3711. }
  3712. $result['job'] = $job;
  3713. $result['job_experience'] = $job_experience ?? [];
  3714. $result['education_experience'] = $education_experience ?? [];
  3715. if (empty($result)) {
  3716. return Result::error("参数错误", 0);
  3717. }
  3718. return Result::success($result);
  3719. }
  3720. /**
  3721. * c端-申请职位
  3722. * @param array $data
  3723. * @return array
  3724. * */
  3725. public function getWebsiteJobApply(array $data): array
  3726. {
  3727. // 首先验证网站是否存在
  3728. // return Result::success($data);
  3729. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3730. if (empty($web)) {
  3731. return Result::error("该网站不存在", 0);
  3732. }
  3733. // 验证用户是否存在且为个人会员/管理员
  3734. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3735. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3736. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3737. return Result::error("用户不存在", 0);
  3738. }
  3739. // 去除重复元素和空元素,并保持原始顺序
  3740. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3741. return !empty($value);
  3742. }));
  3743. // 验证职位是否存在 1:审核通过
  3744. $recruiting = JobRecruiting::where('status', 1)
  3745. ->where('website_id', $data['website_id'])
  3746. ->whereIn('id', $data['recruit_id'])
  3747. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3748. if (empty($recruiting)) {
  3749. return Result::error("该职位不存在", 0);
  3750. }
  3751. // 简历是否存在
  3752. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3753. if (empty($hunt_id)) {
  3754. return Result::error("该简历不存在", 0);
  3755. }
  3756. $data['hunt_id'] = $hunt_id['hunt_id'];
  3757. // // 验证是否已投递过该职位
  3758. $apply = JobApply::where('user_id', $data['user_id'])
  3759. ->where('hunt_id', $data['hunt_id'])
  3760. ->where('website_id', $data['website_id'])
  3761. ->whereIn('recruit_id', $data['recruit_id'])
  3762. ->get(['recruit_id']);
  3763. if (!empty($apply->toArray())) {
  3764. return Result::error("您已投递过该职位!");
  3765. }
  3766. $insertData = array_map(function ($recruiting) use ($data) {
  3767. return [
  3768. 'user_id' => $data['user_id'],
  3769. 'hunt_id' => $data['hunt_id'],
  3770. 'website_id' => $data['website_id'],
  3771. 'recruit_id' => $recruiting['recruit_id'],
  3772. 'receiver_id' => $recruiting['receiver_id'],
  3773. 'status' => 1,
  3774. ];
  3775. }, $recruiting);
  3776. // 批量插入数据
  3777. $result = JobApply::insert($insertData);
  3778. if (empty($result)) {
  3779. return Result::error("投递失败", 0);
  3780. }
  3781. return Result::success($result);
  3782. }
  3783. /**
  3784. * 招工招聘-沟通简历
  3785. * @param array $data
  3786. * @return array
  3787. * */
  3788. public function getWebsiteJobResume(array $data): array
  3789. {
  3790. // 首先验证网站是否存在
  3791. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3792. if (empty($web)) {
  3793. return Result::error("该网站不存在", 0);
  3794. }
  3795. // return Result::success($data);
  3796. // 验证用户是否存在且为企业会员/管理员
  3797. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3798. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3799. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3800. return Result::error("用户不存在", 0);
  3801. }
  3802. // 去除重复元素和空元素,并保持原始顺序
  3803. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3804. return !empty($value);
  3805. }));
  3806. // 验证简历是否存在
  3807. $hunting = JobHunting::where('status', 2)
  3808. ->where('website_id', $data['website_id'])
  3809. ->whereIn('id', $data['hunt_id'])
  3810. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3811. if (empty($hunting)) {
  3812. return Result::error("该简历不存在", 0);
  3813. }
  3814. // 验证是否已沟通过该简历
  3815. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3816. ->where('recruit_id', $data['recruit_id'])
  3817. ->where('website_id', $data['website_id'])
  3818. ->whereIn('hunt_id', $data['hunt_id'])
  3819. ->get(['hunt_id']);
  3820. if (!empty($remuse->toArray())) {
  3821. return Result::error("您已沟通过该简历!");
  3822. }
  3823. // 准备要插入的数据数组
  3824. $insertData = array_map(function ($hunting) use ($data) {
  3825. return [
  3826. 'user_id' => $data['user_id'],
  3827. 'recruit_id' => $data['recruit_id'],
  3828. 'website_id' => $data['website_id'],
  3829. 'hunt_id' => $hunting['hunt_id'],
  3830. 'receiver_id' => $hunting['receiver_id'],
  3831. 'status' => 1,
  3832. ];
  3833. }, $hunting);
  3834. // 批量插入数据
  3835. $result = JobRemuse::insert($insertData);
  3836. if (empty($result)) {
  3837. return Result::error("沟通失败", 0);
  3838. }
  3839. return Result::success($result);
  3840. }
  3841. /**
  3842. * 招工招聘 -我的职位(企业会员)
  3843. * @param array $data
  3844. * @return array
  3845. */
  3846. public function getWebsiteJobRecruiting(array $data): array
  3847. {
  3848. $web = Website::where('id', $data['website_id'])->first('id');
  3849. if (empty($web)) {
  3850. return Result::error("该网站不存在", 0);
  3851. }
  3852. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3853. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3854. return Result::error("用户暂无权限!", 0);
  3855. }
  3856. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3857. $result = JobRecruiting::where('website_id', $data['website_id'])
  3858. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3859. $query->where('user_id', $user['id']);
  3860. })
  3861. ->where('status', 1)
  3862. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3863. ->orderBy('updated_at', 'desc')
  3864. ->limit($data['pageSize'])
  3865. ->get();
  3866. if (empty($result)) {
  3867. return Result::error("暂无相关职位信息", 0);
  3868. }
  3869. return Result::success($result);
  3870. }
  3871. /**
  3872. * c端 - 验证路由
  3873. * @param array $data
  3874. * @return array
  3875. */
  3876. /**
  3877. * c端 - 验证路由
  3878. * @param array $data
  3879. * @return array
  3880. */
  3881. public function checkWebsiteRoute(array $data): array
  3882. {
  3883. // 测试001111111222
  3884. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3885. if (empty($web)) {
  3886. return Result::error("该网站不存在", 0);
  3887. } elseif ($web['status'] != 1) {
  3888. return Result::error("网站已经关闭", 0);
  3889. }
  3890. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3891. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3892. // 验证路由是否存在
  3893. if (empty($whiteRouterInfo)) {
  3894. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3895. }
  3896. if (!empty($whiteRouterInfo)) {
  3897. return Result::success($whiteRouterInfo->toArray());
  3898. }
  3899. }
  3900. // 验证栏目路由
  3901. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3902. ->where('path', $data['all_route'])
  3903. ->get()->all();
  3904. if (count($last_category) == 0) {
  3905. return Result::error("该栏目不存在", 0);
  3906. }
  3907. if (count($last_category) > 1) {
  3908. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3909. }
  3910. if (count($last_category) == 1) {
  3911. $last_category = $last_category[0];
  3912. }
  3913. // return Result::success($last_category);
  3914. if (isset($data['id']) && !empty($data['id'])) {
  3915. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3916. switch ($last_category['type']) {
  3917. case 1:
  3918. // 文章
  3919. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3920. $article = Article::where('status', 1)
  3921. ->where('id', $data['id'])
  3922. ->where(function ($query) use ($data) {
  3923. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3924. ->orWhereNull("ignore_ids");
  3925. })
  3926. ->first(['catid']);
  3927. if (empty($article)) {
  3928. return Result::error("该文章不存在", 0);
  3929. }
  3930. // return Result::success($article);
  3931. break;
  3932. case 2:
  3933. // 商品
  3934. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3935. $article = Good::where('website_id', $data['website_id'])
  3936. ->where('status', 2)
  3937. ->where('id', $data['id'])
  3938. ->first(['cat_arr_id']);
  3939. if (empty($article)) {
  3940. return Result::error("该商品不存在", 0);
  3941. }
  3942. break;
  3943. case 3:
  3944. // 书刊信息
  3945. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3946. $article = Book::where('website_id', $data['website_id'])
  3947. ->where('status', 2)
  3948. ->where('id', $data['id'])
  3949. ->first(['id', 'cat_arr_id']);
  3950. if (empty($article)) {
  3951. return Result::error("该书刊不存在", 0);
  3952. }
  3953. break;
  3954. case 4:
  3955. // 招聘
  3956. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3957. $article = JobRecruiting::where('website_id', $data['website_id'])
  3958. ->where('status', 1)
  3959. ->where('id', $data['id'])
  3960. ->first(['cat_arr_id']);
  3961. if (empty($article)) {
  3962. return Result::error("该招聘不存在", 0);
  3963. }
  3964. break;
  3965. case 5:
  3966. // 求职
  3967. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3968. $article = JobHunting::where('website_id', $data['website_id'])
  3969. ->where('status', 2)
  3970. ->where('id', $data['id'])
  3971. ->first(['cat_arr_id']);
  3972. if (empty($article)) {
  3973. return Result::error("该求职不存在", 0);
  3974. }
  3975. break;
  3976. case 6:
  3977. // 企业
  3978. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3979. $article = Company::
  3980. // where('website_id', $data['website_id'])
  3981. // ->
  3982. where('status', 1)
  3983. ->where('id', $data['id'])
  3984. ->first(['cat_arr_id']);
  3985. if (empty($article)) {
  3986. return Result::error("该企业不存在", 0);
  3987. }
  3988. break;
  3989. case 7:
  3990. // 项目
  3991. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3992. $article = Project::where('website_id', $data['website_id'])
  3993. ->where('status', 1)
  3994. ->where('id', $data['id'])
  3995. ->first(['cat_arr_id']);
  3996. if (empty($article)) {
  3997. return Result::error("该项目不存在", 0);
  3998. }
  3999. break;
  4000. default:
  4001. return Result::error("该数据不存在", 0);
  4002. break;
  4003. }
  4004. // return Result::success($article);
  4005. // $catid =0 ;
  4006. if (!isset($article['cat_arr_id'])) {
  4007. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4008. } else {
  4009. $catidArray = json_decode($article['cat_arr_id'], true);
  4010. $catid = !empty($catidArray) ? end($catidArray) : null;
  4011. }
  4012. // return Result::success($catid);
  4013. // // return Result::success($article['cat_arr_id']);
  4014. if (empty($catid)) {
  4015. return Result::error("该栏目路径不存在", 0);
  4016. }
  4017. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4018. ->where('category_id', $catid)
  4019. ->first('path');
  4020. }
  4021. // else{
  4022. // // if ($last_category['pid'] != 0) {
  4023. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4024. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4025. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4026. // ->where('category_id',$catid)
  4027. // ->where('path',$data['all_route'])
  4028. // ->first('path');
  4029. // // } else {
  4030. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4031. // // }
  4032. // }
  4033. // return Result::success($path);
  4034. if (!empty($path) && $path['path'] != $data['all_route']) {
  4035. return Result::error('非法路径!');
  4036. } else {
  4037. return Result::success($last_category['path']);
  4038. }
  4039. }
  4040. /**
  4041. * 招工招聘 - 获取推荐职位
  4042. * @param array $data
  4043. * @return array
  4044. */
  4045. public function getWebsiteLevelJob(array $data): array
  4046. {
  4047. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4048. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4049. ->where('job_recruiting.status', 1)
  4050. ->where('job_level', $data['job_level'])
  4051. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4052. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4053. ->orderBy('job_recruiting.updated_at', 'desc')
  4054. ->limit($data['pageSize'])
  4055. ->get();
  4056. $web = ['website_id' => $data['website_id']];
  4057. if (!empty($job)) {
  4058. $result = $this->processJob($job, $web);
  4059. }
  4060. if (empty($result)) {
  4061. return Result::error("暂无相关职位信息", 0);
  4062. }
  4063. return Result::success($result);
  4064. }
  4065. /**
  4066. * 验证导航名称是否重复
  4067. * @return void
  4068. */
  4069. //20250226 产品列表
  4070. public function getGoodList(array $data): array
  4071. {
  4072. var_dump($data, '---------1-2--');
  4073. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4074. unset($data['user_type_id']);
  4075. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4076. $where = [];
  4077. if ($type_id != '10000') {
  4078. $where = [
  4079. 'good.user_id' => $user_id,
  4080. ];
  4081. }
  4082. //类型
  4083. if (isset($data['type_id']) && $data['type_id']) {
  4084. $where['good.type_id'] = $data['type_id'];
  4085. }
  4086. //名称
  4087. if (isset($data['name']) && $data['name']) {
  4088. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4089. }
  4090. //status
  4091. if (isset($data['status']) && $data['status'] != '') {
  4092. $where['good.status'] = $data['status'];
  4093. }
  4094. //status1
  4095. // if (isset($data['status1']) && $data['status1'] == 1) {
  4096. // $status1 = 1;
  4097. // }
  4098. $where1 = [];
  4099. //website_id
  4100. // if (isset($data['website_id']) && $data['website_id']) {
  4101. // $where1 = [
  4102. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4103. // ];
  4104. // }
  4105. // website_name
  4106. if (isset($data['website_name']) && $data['website_name']) {
  4107. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4108. }
  4109. // catid
  4110. if (isset($data['category_name']) && $data['category_name']) {
  4111. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4112. }
  4113. // $result = Good::where($where)
  4114. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4115. var_dump($where, '---------1---');
  4116. $result = Good::where($where)
  4117. ->when(!empty($where1), function ($query) use ($where1) {
  4118. return $query->where($where1);
  4119. })
  4120. //status 1待审核2已审核3已拒绝
  4121. ->when(isset($data['status1']), function ($query) {
  4122. return $query->whereIn('good.status', [1, 3]);
  4123. })
  4124. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4125. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4126. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4127. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4128. ->orderBy("updated_at", "desc")
  4129. ->limit($data['page_size'])
  4130. ->offset(($data['page'] - 1) * $data['page_size'])
  4131. ->get();
  4132. $count = Good::where($where)
  4133. ->when(!empty($where1), function ($query) use ($where1) {
  4134. return $query->where($where1);
  4135. })
  4136. //status 1待审核2已审核3已拒绝
  4137. ->when(isset($data['status1']), function ($query) {
  4138. return $query->whereIn('good.status', [1, 3]);
  4139. })
  4140. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4141. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4142. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4143. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4144. ->orderBy("updated_at", "desc")->count();
  4145. $data = [
  4146. 'rows' => $result->toArray(),
  4147. 'count' => $count,
  4148. ];
  4149. if (empty($result)) {
  4150. return Result::error("此栏目暂无相关产品", 0);
  4151. }
  4152. return Result::success($data);
  4153. }
  4154. public function getGoodInfo(array $data): array
  4155. {
  4156. $result = Good::where('id', $data['id'])->first();
  4157. if (empty($result)) {
  4158. return Result::error("此产品不存在", 0);
  4159. }
  4160. return Result::success($result);
  4161. }
  4162. public function addGood(array $data): array
  4163. {
  4164. // unset($data['city_arr_id']);
  4165. // unset($data['cat_arr_id']);
  4166. $data['city_id'] = end($data['city_arr_id']);
  4167. $data['catid'] = end($data['cat_arr_id']);
  4168. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4169. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4170. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4171. unset($data['imgUrl']); //大小写
  4172. if (isset($data['price']) && $data['price'] == '') {
  4173. $data['price'] = 0;
  4174. }
  4175. if ($data['imgurl'] == '') {
  4176. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4177. preg_match_all($reg, $data['detail'], $matches);
  4178. if (isset($matches[1][0])) {
  4179. //截取varchar240
  4180. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4181. }
  4182. }
  4183. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4184. //提取标题+内容中的关键词
  4185. $data['keyword'] = $data['name'];
  4186. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4187. Jieba::init(); // 初始化 jieba-php
  4188. Finalseg::init();
  4189. $segList = Jieba::cut($data['keyword']);
  4190. $segList1 = array_slice($segList, 0, 8);
  4191. $data['keyword'] = implode(',', $segList1);
  4192. }
  4193. if ($data['description'] == '') {
  4194. //提取内容中的描述
  4195. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4196. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4197. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4198. }
  4199. if ($data['status'] == 1) {
  4200. $this->sendMessage([
  4201. 'talk_type' => 200,
  4202. 'title' => $data['name'],
  4203. 'content' => '提交了审核',
  4204. 'messageType' => 3,
  4205. ]);
  4206. }
  4207. $result = Good::insert($data);
  4208. if (empty($result)) {
  4209. return Result::error("添加失败", 0);
  4210. }
  4211. return Result::success($result);
  4212. }
  4213. public function updateGood(array $data): array
  4214. {
  4215. $data['city_id'] = end($data['city_arr_id']);
  4216. $data['catid'] = end($data['cat_arr_id']);
  4217. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4218. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4219. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4220. //设置东八区
  4221. date_default_timezone_set('Asia/Shanghai');
  4222. $data['updated_at'] = date('Y-m-d H:i:s');
  4223. if (isset($data['price']) && $data['price'] == '') {
  4224. $data['price'] = 0;
  4225. }
  4226. if ($data['imgurl'] == '') {
  4227. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4228. preg_match_all($reg, $data['detail'], $matches);
  4229. if (isset($matches[1][0])) {
  4230. //截取varchar240
  4231. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4232. }
  4233. }
  4234. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4235. //提取标题+内容中的关键词
  4236. $data['keyword'] = $data['name'];
  4237. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4238. Jieba::init(); // 初始化 jieba-php
  4239. Finalseg::init();
  4240. $segList = Jieba::cut($data['keyword']);
  4241. $segList1 = array_slice($segList, 0, 8);
  4242. $data['keyword'] = implode(',', $segList1);
  4243. }
  4244. if ($data['description'] == '') {
  4245. //提取内容中的描述
  4246. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4247. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4248. }
  4249. if ($data['status'] == 1) {
  4250. $this->sendMessage([
  4251. 'talk_type' => 200,
  4252. 'title' => $data['name'],
  4253. 'content' => '提交了审核',
  4254. 'messageType' => 3,
  4255. ]);
  4256. }
  4257. $result = Good::where('id', $data['id'])->update($data);
  4258. if (empty($result)) {
  4259. return Result::error("更新失败", 0);
  4260. }
  4261. return Result::success($result);
  4262. }
  4263. public function delGood(array $data): array
  4264. {
  4265. $result = Good::where('id', $data['id'])->delete();
  4266. if (empty($result)) {
  4267. return Result::error("删除失败", 0);
  4268. }
  4269. return Result::success($result);
  4270. }
  4271. //20250226 产品列表
  4272. //20250306 求职信息
  4273. public function getJobHuntingList(array $data): array
  4274. {
  4275. $where = [];
  4276. if (isset($data['username']) && !empty($data['username'])) {
  4277. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4278. }
  4279. //status 1待审核2已审核3已拒绝
  4280. if (isset($data['status']) && $data['status'] != '') {
  4281. $where = [
  4282. 'job_hunting.status' => $data['status'],
  4283. ];
  4284. }
  4285. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4286. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4287. unset($data['type_id']);
  4288. if ($type_id != '10000') {
  4289. $where[] = ['job_hunting.user_id', '=', $user_id];
  4290. }
  4291. $result = JobHunting::where($where)
  4292. ->when(!empty($data['status1']), function ($query) use ($data) {
  4293. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4294. })
  4295. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4296. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4297. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4298. ->orderBy("updated_at", "desc")
  4299. ->limit($data['page_size'])
  4300. ->offset(($data['page'] - 1) * $data['page_size'])
  4301. ->get();
  4302. if (empty($result)) {
  4303. return Result::error("查询失败", 0);
  4304. }
  4305. $count = JobHunting::where($where)
  4306. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4307. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4308. ->count();
  4309. $data = [
  4310. 'rows' => $result->toArray(),
  4311. 'count' => $count,
  4312. ];
  4313. return Result::success($data);
  4314. }
  4315. public function getJobHuntingApply(array $data): array
  4316. {
  4317. var_dump($data, '-----------------test--------1-');
  4318. $where = [];
  4319. if (isset($data['username']) && !empty($data['username'])) {
  4320. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4321. }
  4322. if (isset($data['salary']) && !empty($data['salary'])) {
  4323. $where[] = [
  4324. 'job_hunting.salary',
  4325. '=',
  4326. $data['salary'],
  4327. ];
  4328. }
  4329. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4330. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4331. unset($data['type_id']);
  4332. if ($type_id != '10000') {
  4333. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4334. }
  4335. var_dump($where, '-----------------test---------');
  4336. $result = jobApply::where($where)
  4337. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4338. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4339. // })
  4340. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4341. ->where('job_enum.egroup', '=', 'income')
  4342. ->where('job_hunting.status', 2) //已审核
  4343. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4344. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4345. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4346. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4347. //职位----是申请职位
  4348. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4349. ->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')
  4350. ->orderBy("job_hunting.updated_at", "desc")
  4351. ->limit($data['page_size'])
  4352. ->offset(($data['page'] - 1) * $data['page_size'])
  4353. ->get();
  4354. if (empty($result)) {
  4355. return Result::error("查询失败", 0);
  4356. }
  4357. $count = jobApply::where($where)
  4358. ->where('job_enum.egroup', '=', 'income')
  4359. ->where('job_hunting.status', 2) //已审核
  4360. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4361. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4362. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4363. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4364. //职位----是申请职位
  4365. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4366. ->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')
  4367. ->count();
  4368. $data = [
  4369. 'rows' => $result->toArray(),
  4370. 'count' => $count,
  4371. ];
  4372. return Result::success($data);
  4373. }
  4374. public function addJobHunting(array $data): array
  4375. {
  4376. date_default_timezone_set('Asia/Shanghai');
  4377. unset($data['company_name']);
  4378. unset($data['job_industry']);
  4379. unset($data['job_name']);
  4380. unset($data['department']);
  4381. unset($data['job_timeList']);
  4382. unset($data['job_content']);
  4383. unset($data['job_typename']); //不知道这是啥,
  4384. $data['created_at'] = date('Y-m-d H:i:s');
  4385. $data['updated_at'] = date('Y-m-d H:i:s');
  4386. //根据用户 user_id 只能添加一次
  4387. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4388. if (!empty($result)) {
  4389. return Result::error("您已添加过求职信息", 0);
  4390. }
  4391. var_dump($result, '-----------------test---------');
  4392. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4393. if (is_string($data['city_arr_id'])) {
  4394. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4395. $cityArr = json_decode($data['city_arr_id'], true);
  4396. // 确保 $cityArr 是数组
  4397. if (is_array($cityArr)) {
  4398. $data['city_id'] = end($cityArr);
  4399. }
  4400. } else {
  4401. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4402. if (is_array($data['city_arr_id'])) {
  4403. $data['city_id'] = end($data['city_arr_id']);
  4404. }
  4405. }
  4406. }
  4407. // 处理求职所绑定栏目
  4408. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4409. if (is_string($data['cat_arr_id'])) {
  4410. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4411. // 先清理可能存在的无效 JSON 字符
  4412. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4413. $catArr = json_decode($cleanedCatArrStr, true);
  4414. // 检查 JSON 解码是否成功且结果是数组
  4415. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4416. $data['catid'] = end($catArr);
  4417. }
  4418. } else {
  4419. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4420. if (is_array($data['cat_arr_id'])) {
  4421. $data['catid'] = end($data['cat_arr_id']);
  4422. }
  4423. }
  4424. }
  4425. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4426. $this->sendMessage([
  4427. 'talk_type' => 600,
  4428. 'title' => $data['name'],
  4429. 'content' => '提交了审核',
  4430. 'messageType' => 11,
  4431. ]);
  4432. }
  4433. $result = JobHunting::create($data);
  4434. if (empty($result)) {
  4435. return Result::error("添加失败", 0);
  4436. }
  4437. return Result::success($result);
  4438. }
  4439. public function delJobHunting(array $data): array
  4440. {
  4441. $result = JobHunting::where('id', $data['id'])->delete();
  4442. if (empty($result)) {
  4443. return Result::error("删除失败", 0);
  4444. }
  4445. return Result::success($result);
  4446. }
  4447. public function updateJobHunting(array $data): array
  4448. {
  4449. //设置东八区
  4450. date_default_timezone_set('Asia/Shanghai');
  4451. unset($data['company_name']);
  4452. unset($data['job_industry']);
  4453. unset($data['job_name']);
  4454. unset($data['department']);
  4455. unset($data['job_timeList']);
  4456. unset($data['job_content']);
  4457. unset($data['job_typename']); //不知道这是啥,
  4458. $data['created_at'] = date('Y-m-d H:i:s');
  4459. $data['updated_at'] = date('Y-m-d H:i:s');
  4460. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4461. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4462. $cityArr = json_decode($data['city_arr_id'], true);
  4463. $data['city_id'] = end($cityArr);
  4464. } else {
  4465. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4466. $data['city_id'] = end($data['city_arr_id']);
  4467. }
  4468. // 处理求职所绑定栏目
  4469. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4470. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4471. $catArr = json_decode($data['cat_arr_id'], true);
  4472. $data['catid'] = end($catArr);
  4473. } else {
  4474. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4475. $data['catid'] = end($data['cat_arr_id']);
  4476. }
  4477. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4478. $this->sendMessage([
  4479. 'talk_type' => 600,
  4480. 'title' => $data['name'],
  4481. 'content' => '提交了审核',
  4482. 'messageType' => 11,
  4483. ]);
  4484. }
  4485. $result = JobHunting::where('id', $data['id'])->update($data);
  4486. if (empty($result)) {
  4487. return Result::error("更新失败", 0);
  4488. }
  4489. return Result::success($result);
  4490. }
  4491. public function getJobHuntingInfo(array $data): array
  4492. {
  4493. $result = JobHunting::where('id', $data['id'])->first();
  4494. if (empty($result)) {
  4495. return Result::error("查询失败", 0);
  4496. }
  4497. return Result::success($result);
  4498. }
  4499. public function getJobHuntingData(array $data): array
  4500. {
  4501. $jobEnum = JobEnum::get();
  4502. $jobIndustry = JobIndustry::get();
  4503. $jobNature = JobNature::get();
  4504. $jobPosition = JobPosition::get();
  4505. $data = [
  4506. 'jobEnum' => $jobEnum,
  4507. 'jobIndustry' => $jobIndustry,
  4508. 'jobNature' => $jobNature,
  4509. 'jobPosition' => $jobPosition,
  4510. ];
  4511. return Result::success($data);
  4512. }
  4513. public function delJobHuntingInfo(array $data): array
  4514. {
  4515. $result = JobHunting::where('id', $data['id'])->delete();
  4516. return Result::success();
  4517. }
  4518. //20250324 通知,公告,消息
  4519. public function delNotice(array $data): array
  4520. {
  4521. $result = Notice::where('id', $data['id'])->delete();
  4522. if ($result) {
  4523. return Result::success();
  4524. } else {
  4525. return Result::error("删除失败", 0);
  4526. }
  4527. }
  4528. public function getNoticeInfo(array $data): array
  4529. {
  4530. $result = Notice::where('id', $data['id'])->first();
  4531. // var_dump($result['re_user_ids'], '--------------------');
  4532. if (empty($result)) {
  4533. return Result::error("查询失败", 0);
  4534. }
  4535. return Result::success($result);
  4536. }
  4537. public function readNotice(array $data): array
  4538. {
  4539. $result = Notice::where('id', $data['id'])->first();
  4540. // var_dump($result['re_user_ids'], '--------------------');
  4541. if (empty($result)) {
  4542. return Result::error("查询失败", 0);
  4543. }
  4544. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4545. $re_user_ids = json_decode($result['re_user_ids'], true);
  4546. var_dump($re_user_ids, '--------------1---test---------');
  4547. var_dump($data, '--------------1---test---------');
  4548. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4549. //如果已经存在,就不再添加
  4550. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4551. $read_id = json_decode($result['read_id'], true);
  4552. if (!is_array($read_id)) {
  4553. $read_id = [];
  4554. }
  4555. if (!in_array($data['user_id'], $read_id)) {
  4556. $read_id[] = $data['user_id'];
  4557. $result['read_id'] = json_encode($read_id);
  4558. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4559. }
  4560. } else {
  4561. //如果不存在,就添加
  4562. $result['read_id'] = json_encode([$data['user_id']]);
  4563. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4564. }
  4565. }
  4566. return Result::success($result);
  4567. }
  4568. public function addNotice(array $data): array
  4569. {
  4570. date_default_timezone_set('Asia/Shanghai');
  4571. $data['created_at'] = date('Y-m-d H:i:s');
  4572. $data['updated_at'] = date('Y-m-d H:i:s');
  4573. $user_id = UserInfo::
  4574. //city_id不是null
  4575. whereNotNull('city_id')
  4576. ->whereNotNull('department_id')
  4577. ->where(function ($query) use ($data) {
  4578. $query->where(function ($subQuery) use ($data) {
  4579. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4580. });
  4581. })
  4582. ->where(function ($query) use ($data) {
  4583. $query->where(function ($subQuery) use ($data) {
  4584. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4585. });
  4586. })
  4587. ->pluck('user_id')->toArray();
  4588. $user_id = array_unique($user_id);
  4589. $chat_ids = $user_id;
  4590. $user_id = json_encode($user_id);
  4591. $data['re_user_ids'] = $user_id;
  4592. $this->sendMessage([
  4593. 'talk_type' => 700,
  4594. 'title' => $data['title'],
  4595. 'content' => '提交了审核',
  4596. 'messageType' => 5,
  4597. ]);
  4598. $result = Notice::insertGetId($data);
  4599. if (empty($result)) {
  4600. return Result::error("添加失败", 0);
  4601. }
  4602. return Result::success($result);
  4603. }
  4604. public function updateNotice(array $data): array
  4605. {
  4606. date_default_timezone_set('Asia/Shanghai');
  4607. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4608. $user_id = UserInfo::
  4609. //city_id不是null
  4610. whereNotNull('city_id')
  4611. ->whereNotNull('department_id')
  4612. ->where(function ($query) use ($data) {
  4613. $query->where(function ($subQuery) use ($data) {
  4614. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4615. });
  4616. })
  4617. ->where(function ($query) use ($data) {
  4618. $query->where(function ($subQuery) use ($data) {
  4619. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4620. });
  4621. })
  4622. ->pluck('user_id')->toArray();
  4623. $user_id = array_unique($user_id);
  4624. $user_id = json_encode($user_id);
  4625. $data['re_user_ids'] = $user_id;
  4626. $data['updated_at'] = date('Y-m-d H:i:s');
  4627. $this->sendMessage([
  4628. 'talk_type' => 700,
  4629. 'title' => $data['title'],
  4630. 'content' => '提交了审核',
  4631. 'messageType' => 5,
  4632. ]);
  4633. $result = Notice::where('id', $data['id'])->update($data);
  4634. return Result::success($result);
  4635. }
  4636. public function getNoticeList(array $data): array
  4637. {
  4638. $where = [];
  4639. //title
  4640. if (isset($data['title']) && !empty($data['title'])) {
  4641. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4642. }
  4643. //level
  4644. if (isset($data['level']) && !empty($data['level'])) {
  4645. $where[] = ['notice.level', '=', $data['level']];
  4646. }
  4647. //status
  4648. if (isset($data['status']) && !empty($data['status'])) {
  4649. $where[] = ['notice.status', '=', $data['status']];
  4650. }
  4651. //type
  4652. if (isset($data['type']) && !empty($data['type'])) {
  4653. $where[] = ['notice.type', '=', $data['type']];
  4654. }
  4655. var_dump($data, '------------11111-2----test---------');
  4656. if ($data['type_id'] == 10000) {
  4657. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4658. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4659. })
  4660. ->where($where)
  4661. ->orderBy('updated_at', 'desc')
  4662. ->limit($data['page_size'])
  4663. ->offset(($data['page'] - 1) * $data['page_size'])
  4664. ->get();
  4665. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4666. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4667. })
  4668. ->where($where)
  4669. ->orderBy('updated_at', 'desc')
  4670. ->count();
  4671. } else {
  4672. $result = Notice::where($where)
  4673. // ->where('user_id', $data['user_id'])
  4674. ->Where(function ($query) use ($data) {
  4675. $query->Where(function ($q) use ($data) {
  4676. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4677. ->orWhere('notice.user_id', $data['user_id']);
  4678. });
  4679. })
  4680. ->when(!empty($data['status1']), function ($query) use ($data) {
  4681. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4682. })
  4683. ->orderBy('updated_at', 'desc')
  4684. ->limit($data['page_size'])
  4685. ->offset(($data['page'] - 1) * $data['page_size'])
  4686. ->get();
  4687. $total = Notice::where($where)
  4688. ->when(!empty($data['status1']), function ($query) use ($data) {
  4689. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4690. })
  4691. // ->where('user_id', $data['user_id'])
  4692. ->Where(function ($query) use ($data) {
  4693. $query->Where(function ($q) use ($data) {
  4694. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4695. ->orWhere('notice.user_id', $data['user_id']);
  4696. });
  4697. })
  4698. ->count();
  4699. }
  4700. if (empty($result)) {
  4701. return Result::error("查询失败", 0);
  4702. }
  4703. $data = [
  4704. 'rows' => $result,
  4705. 'count' => $total,
  4706. ];
  4707. return Result::success($data);
  4708. }
  4709. public function noticeList(array $data): array
  4710. {
  4711. $where = [];
  4712. //title
  4713. if (isset($data['title']) && !empty($data['title'])) {
  4714. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4715. }
  4716. //level
  4717. if (isset($data['level']) && !empty($data['level'])) {
  4718. $where[] = ['notice.level', '=', $data['level']];
  4719. }
  4720. //status
  4721. if (isset($data['status']) && !empty($data['status'])) {
  4722. $where[] = ['notice.status', '=', $data['status']];
  4723. }
  4724. //type
  4725. if (isset($data['type']) && !empty($data['type'])) {
  4726. $where[] = ['notice.type', '=', $data['type']];
  4727. }
  4728. var_dump($data, '------------11111-2----test---------');
  4729. if ($data['type_id'] == 10000) {
  4730. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4731. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4732. })
  4733. ->where($where)
  4734. ->orderBy('updated_at', 'desc')
  4735. ->limit($data['page_size'])
  4736. ->offset(($data['page'] - 1) * $data['page_size'])
  4737. ->get();
  4738. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4739. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4740. })
  4741. ->where($where)
  4742. ->orderBy('updated_at', 'desc')
  4743. ->count();
  4744. } else {
  4745. $result = Notice::where($where)
  4746. // ->where('user_id', $data['user_id'])
  4747. ->Where(function ($query) use ($data) {
  4748. $query->Where(function ($q) use ($data) {
  4749. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4750. ->orWhere('notice.user_id', $data['user_id']);
  4751. });
  4752. })
  4753. ->when(!empty($data['status1']), function ($query) use ($data) {
  4754. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4755. })
  4756. ->orderBy('updated_at', 'desc')
  4757. ->limit($data['page_size'])
  4758. ->offset(($data['page'] - 1) * $data['page_size'])
  4759. ->get();
  4760. $total = Notice::where($where)
  4761. ->when(!empty($data['status1']), function ($query) use ($data) {
  4762. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4763. })
  4764. // ->where('user_id', $data['user_id'])
  4765. ->Where(function ($query) use ($data) {
  4766. $query->Where(function ($q) use ($data) {
  4767. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4768. ->orWhere('notice.user_id', $data['user_id']);
  4769. });
  4770. })
  4771. ->count();
  4772. }
  4773. if (empty($result)) {
  4774. return Result::error("查询失败", 0);
  4775. }
  4776. $data = [
  4777. 'rows' => $result,
  4778. 'count' => $total,
  4779. ];
  4780. return Result::success($data);
  4781. }
  4782. public function getNoticeDetail(array $data): array
  4783. {
  4784. $result = Notice::where('id', $data['id'])->first();
  4785. if (empty($result)) {
  4786. return Result::error("查询失败", 0);
  4787. }
  4788. return Result::success($result);
  4789. }
  4790. public function deleteNotice(array $data): array
  4791. {
  4792. $notice = Notice::where('id', $data['id'])->first();
  4793. if (empty($notice)) {
  4794. return Result::error("删除失败", 0);
  4795. }
  4796. $chat_group_id = $notice->group_id;
  4797. if ($chat_group_id) {
  4798. //删除群聊
  4799. ChatGroups::where('id', $chat_group_id)->delete();
  4800. //删除群成员
  4801. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4802. //删除群聊记录
  4803. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4804. }
  4805. $result = Notice::where('id', $data['id'])->delete();
  4806. return Result::success($result);
  4807. }
  4808. public function complaintList(array $data): array
  4809. {
  4810. var_dump($data, '---------1---------');
  4811. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4812. unset($data['type_id']);
  4813. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4814. $where = [];
  4815. if ($type_id != 10000 && empty($data['deal_user'])) {
  4816. // $where['complaint.user_id'] = $user_id;
  4817. }
  4818. if (!empty($data['title'])) {
  4819. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4820. }
  4821. if (!empty($data['department_id'])) {
  4822. $where['complaint.department_id'] = $data['department_id'];
  4823. }
  4824. if (!empty($data['deal'])) {
  4825. $where['complaint.deal'] = $data['deal'];
  4826. }
  4827. if (!empty($data['status'])) {
  4828. $where['complaint.status'] = $data['status'];
  4829. }
  4830. var_dump(!empty($data['deal_user']), '----------1');
  4831. var_dump($where, '----------2');
  4832. $result = Complaint::where($where)
  4833. ->when(!empty($data['status1']), function ($query) use ($data) {
  4834. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4835. })
  4836. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4837. //json re_user_ids data[user_id]是不是在里面
  4838. $query->Where(function ($q) use ($data) {
  4839. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4840. ->where('complaint.status', 2);
  4841. });
  4842. })
  4843. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4844. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4845. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4846. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4847. ->orderBy('updated_at', 'desc')
  4848. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4849. //sql输出
  4850. if (empty($result)) {
  4851. return Result::error("暂无投诉信息", 0);
  4852. }
  4853. // 取出数据
  4854. $rows = $result->items();
  4855. $count = $result->total();
  4856. $responseData = [
  4857. 'rows' => $rows,
  4858. 'count' => $count,
  4859. ];
  4860. return Result::success($responseData);
  4861. }
  4862. public function getComplaintList(array $data): array
  4863. {
  4864. var_dump($data, '00000001000000000000');
  4865. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4866. unset($data['type_id']);
  4867. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4868. $where = [];
  4869. if ($type_id != 10000 && empty($data['deal_user'])) {
  4870. $where['complaint.user_id'] = $user_id;
  4871. }
  4872. if (!empty($data['title'])) {
  4873. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4874. }
  4875. if (!empty($data['department_id'])) {
  4876. $where['complaint.department_id'] = $data['department_id'];
  4877. }
  4878. if (!empty($data['deal'])) {
  4879. $where['complaint.deal'] = $data['deal'];
  4880. }
  4881. if (!empty($data['status'])) {
  4882. $where['complaint.status'] = $data['status'];
  4883. }
  4884. var_dump(!empty($data['deal_user']), '----------1');
  4885. var_dump($where, '----------2');
  4886. $result = Complaint::where($where)
  4887. ->when(!empty($data['status1']), function ($query) use ($data) {
  4888. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4889. })
  4890. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4891. // //json re_user_ids data[user_id]是不是在里面
  4892. // $query->Where(function ($q) use ($data) {
  4893. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4894. // ->where('complaint.status', 2);
  4895. // });
  4896. // })
  4897. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4898. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4899. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4900. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4901. ->orderBy('updated_at', 'desc')
  4902. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4903. //sql输出
  4904. if (empty($result)) {
  4905. return Result::error("暂无投诉信息", 0);
  4906. }
  4907. // 取出数据
  4908. $rows = $result->items();
  4909. $count = $result->total();
  4910. $responseData = [
  4911. 'rows' => $rows,
  4912. 'count' => $count,
  4913. ];
  4914. return Result::success($responseData);
  4915. }
  4916. public function getComplaintInfo(array $data): array
  4917. {
  4918. $result = Complaint::where('id', $data['id'])->first();
  4919. if (empty($result)) {
  4920. return Result::error("查询失败", 0);
  4921. }
  4922. return Result::success($result);
  4923. }
  4924. public function readComplaint(array $data): array
  4925. {
  4926. $result = Complaint::where('id', $data['id'])->first();
  4927. if (empty($result)) {
  4928. return Result::error("查询失败", 0);
  4929. }
  4930. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4931. $re_user_ids = json_decode($result['re_user_ids'], true);
  4932. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4933. //如果已经存在,就不再添加
  4934. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4935. $read_id = json_decode($result['read_id'], true);
  4936. if (!is_array($read_id)) {
  4937. $read_id = [];
  4938. }
  4939. if (!in_array($data['user_id'], $read_id)) {
  4940. $read_id[] = $data['user_id'];
  4941. $result['read_id'] = json_encode($read_id);
  4942. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4943. }
  4944. } else {
  4945. //如果不存在,就添加
  4946. $result['read_id'] = json_encode([$data['user_id']]);
  4947. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4948. }
  4949. }
  4950. return Result::success($result);
  4951. }
  4952. public function addComplaint(array $data): array
  4953. {
  4954. date_default_timezone_set('Asia/Shanghai');
  4955. $data['created_at'] = date('Y-m-d H:i:s');
  4956. $data['updated_at'] = date('Y-m-d H:i:s');
  4957. $this->sendMessage([
  4958. 'talk_type' => 800,
  4959. 'title' => $data['title'],
  4960. 'content' => '提交了审核',
  4961. 'messageType' => 6,
  4962. ]);
  4963. $result = Complaint::create($data);
  4964. return Result::success($result);
  4965. }
  4966. public function updateComplaint(array $data): array
  4967. {
  4968. date_default_timezone_set('Asia/Shanghai');
  4969. $data['updated_at'] = date('Y-m-d H:i:s');
  4970. $user_id = $data['user_id'] ?? 0;
  4971. $type_id = $data['type_id'] ?? 0;
  4972. unset($data['user_id']);
  4973. unset($data['type_id']);
  4974. $this->sendMessage([
  4975. 'talk_type' => 800,
  4976. 'title' => $data['title'],
  4977. 'content' => '提交了审核',
  4978. 'messageType' => 6,
  4979. ]);
  4980. $result = Complaint::where('id', $data['id'])->update($data);
  4981. return Result::success($result);
  4982. }
  4983. public function deleteComplaint(array $data): array
  4984. {
  4985. $result = Complaint::where('id', $data['id'])->delete();
  4986. return Result::success($result);
  4987. }
  4988. public function getComplainInfo(array $data): array
  4989. {
  4990. $result = Complaint::where('id', $data['id'])->first();
  4991. if (empty($result)) {
  4992. return Result::error("查询失败", 0);
  4993. }
  4994. return Result::success($result);
  4995. }
  4996. public function updateComplaintStatus(array $data): array
  4997. {
  4998. date_default_timezone_set('Asia/Shanghai');
  4999. $data['updated_at'] = date('Y-m-d H:i:s');
  5000. $user_id = $data['user_id'] ?? 0;
  5001. $type_id = $data['type_id'] ?? 0;
  5002. unset($data['user_id']);
  5003. unset($data['type_id']);
  5004. //处理, 写入处理人
  5005. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5006. $data['real_deal_user'] = $user_id;
  5007. }
  5008. //如果是deal 23,则判断是不是处理人
  5009. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5010. $complaintInof = Complaint::where('id', $data['id'])
  5011. ->where('real_deal_user', $user_id)
  5012. ->first();
  5013. if (empty($complaintInof)) {
  5014. return Result::error("处理人错误", 0);
  5015. }
  5016. }
  5017. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5018. if ($data['status'] == 1) {
  5019. $this->sendMessage([
  5020. 'talk_type' => 800,
  5021. 'title' => $complaintInfo['title'],
  5022. 'content' => '提交了审核',
  5023. 'messageType' => 6,
  5024. ]);
  5025. }
  5026. if ($data['status'] == 2 && !isset($data['deal'])) {
  5027. $this->sendMessage([
  5028. 'talk_type' => 801,
  5029. 'title' => $complaintInfo['title'],
  5030. 'content' => '审核通过',
  5031. 'messageType' => 6,
  5032. 'user_id' => $complaintInfo['user_id'],
  5033. ]);
  5034. $this->sendMessage([
  5035. 'talk_type' => 802,
  5036. 'title' => $complaintInfo['title'],
  5037. 'content' => '待处理',
  5038. 'messageType' => 6,
  5039. 'user_id' => $complaintInfo['re_user_ids'],
  5040. ]);
  5041. }
  5042. if ($data['status'] == 3 && !isset($data['deal'])) {
  5043. $this->sendMessage([
  5044. 'talk_type' => 801,
  5045. 'title' => $complaintInfo['title'],
  5046. 'content' => '审核拒绝',
  5047. 'messageType' => 6,
  5048. 'user_id' => $complaintInfo['user_id'],
  5049. ]);
  5050. }
  5051. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5052. $this->sendMessage([
  5053. 'talk_type' => 802,
  5054. 'title' => $complaintInfo['title'],
  5055. 'content' => '处理中',
  5056. 'messageType' => 6,
  5057. 'user_id' => $complaintInfo['re_user_ids'],
  5058. ]);
  5059. }
  5060. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5061. $this->sendMessage([
  5062. 'talk_type' => 802,
  5063. 'title' => $complaintInfo['title'],
  5064. 'content' => '不予处理',
  5065. 'messageType' => 6,
  5066. 'user_id' => $complaintInfo['re_user_ids'],
  5067. ]);
  5068. }
  5069. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5070. $this->sendMessage([
  5071. 'talk_type' => 802,
  5072. 'title' => $complaintInfo['title'],
  5073. 'content' => '已完结',
  5074. 'messageType' => 6,
  5075. 'user_id' => $complaintInfo['re_user_ids'],
  5076. ]);
  5077. }
  5078. $result = complaint::where('id', $data['id'])->update($data);
  5079. return Result::success($result);
  5080. }
  5081. public function updateGoodStatus(array $data): array
  5082. {
  5083. $user_id = $data['user_id'] ?? 0;
  5084. $type_id = $data['type_id'] ?? 0;
  5085. unset($data['user_id']);
  5086. unset($data['type_id']);
  5087. $goodInfo = Good::where('id', $data['id'])->first();
  5088. if ($data['status'] == 2) {
  5089. $this->sendMessage([
  5090. 'talk_type' => 201,
  5091. 'title' => $goodInfo['name'],
  5092. 'content' => '审核通过',
  5093. 'messageType' => 3,
  5094. 'user_id' => $goodInfo['user_id'],
  5095. ]);
  5096. }
  5097. if ($data['status'] == 3) {
  5098. $this->sendMessage([
  5099. 'talk_type' => 201,
  5100. 'title' => $goodInfo['name'],
  5101. 'content' => '审核拒绝',
  5102. 'messageType' => 3,
  5103. 'user_id' => $goodInfo['user_id'],
  5104. ]);
  5105. }
  5106. if ($data['status'] == 1) {
  5107. $this->sendMessage([
  5108. 'talk_type' => 200,
  5109. 'title' => $goodInfo['name'],
  5110. 'content' => '提交了审核',
  5111. 'messageType' => 3,
  5112. ]);
  5113. }
  5114. $result = Good::where('id', $data['id'])->update($data);
  5115. return Result::success($result);
  5116. }
  5117. public function updateJobHuntingStatus(array $data): array
  5118. {
  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. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5124. if ($data['status'] == 2) {
  5125. $this->sendMessage([
  5126. 'talk_type' => 601,
  5127. 'title' => $jogHuntingInfo['name'],
  5128. 'content' => '审核通过',
  5129. 'messageType' => 11,
  5130. 'user_id' => $jogHuntingInfo['user_id'],
  5131. ]);
  5132. }
  5133. if ($data['status'] == 3) {
  5134. $this->sendMessage([
  5135. 'talk_type' => 601,
  5136. 'title' => $jogHuntingInfo['name'],
  5137. 'content' => '审核拒绝',
  5138. 'messageType' => 11,
  5139. 'user_id' => $jogHuntingInfo['user_id'],
  5140. ]);
  5141. }
  5142. if ($data['status'] == 1) {
  5143. $this->sendMessage([
  5144. 'talk_type' => 600,
  5145. 'title' => $jogHuntingInfo['name'],
  5146. 'content' => '提交了审核',
  5147. 'messageType' => 11,
  5148. ]);
  5149. }
  5150. $result = JobHunting::where('id', $data['id'])->update($data);
  5151. return Result::success($result);
  5152. }
  5153. public function updateNoticeStatus(array $data): array
  5154. {
  5155. $user_id = $data['user_id'] ?? 0;
  5156. $type_id = $data['type_id'] ?? 0;
  5157. unset($data['user_id']);
  5158. unset($data['type_id']);
  5159. //查询公告
  5160. $notice = Notice::where('id', $data['id'])->first();
  5161. if (empty($notice)) {
  5162. return Result::error("公告不存在", 0);
  5163. }
  5164. //$chat_ids 去除掉$data['user_id']
  5165. $chat_ids = json_decode($notice['re_user_ids'], true);
  5166. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5167. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5168. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5169. //chat_group
  5170. $group_id = PublicData::uuid();
  5171. $groupData = [
  5172. 'id' => $group_id,
  5173. 'creator_id' => $notice['user_id'],
  5174. 'group_name' => $notice['group_name'] ?? '',
  5175. 'profile' => $notice['profile'] ?? 0,
  5176. ];
  5177. var_dump($groupData, '-----------------groupData-------');
  5178. $groupResult = ChatGroups::insertGetId($groupData);
  5179. var_dump($groupResult, '-----------------groupid-------');
  5180. $groupMemberData = [
  5181. 'id' => PublicData::uuid(),
  5182. 'user_id' => $notice['user_id'],
  5183. 'group_id' => $group_id,
  5184. 'leader' => 2,
  5185. ];
  5186. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5187. //插入群成员表
  5188. $groupMemberDataUser = [];
  5189. $chatData = [];
  5190. foreach ($chat_ids as $key => $value) {
  5191. $groupMemberDataUser[] = [
  5192. 'id' => PublicData::uuid(),
  5193. 'user_id' => $value,
  5194. 'group_id' => $group_id,
  5195. 'leader' => 1,
  5196. ];
  5197. $chatData[] = [
  5198. 'user_id' => $value,
  5199. 'msg_type' => 1,
  5200. 'receiver_id' => $group_id,
  5201. 'content' => '通过通知创建群聊',
  5202. 'group_receiver_id' => $notice['user_id'],
  5203. 'action' => 'recieved',
  5204. 'created_at' => date('Y-m-d H:i:s'),
  5205. ];
  5206. }
  5207. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5208. ChatGroupsMember::insert($groupMemberDataUser);
  5209. //插入一条管理员聊天记录
  5210. $chatData[] = [
  5211. 'user_id' => $notice['user_id'],
  5212. 'msg_type' => 1,
  5213. 'receiver_id' => $group_id,
  5214. 'content' => '通过通知创建群聊',
  5215. 'group_receiver_id' => $notice['user_id'],
  5216. 'action' => 'said',
  5217. 'created_at' => date('Y-m-d H:i:s'),
  5218. ];
  5219. var_dump($chatData, '-----------------chatData-------');
  5220. $chatResult = ChatRecords::insert($chatData);
  5221. //处理imp
  5222. $group = [
  5223. 'type' => 1,
  5224. 'name' => $notice['group_name'] ?? '',
  5225. 'profile' => '',
  5226. 'avatar' => '',
  5227. 'creator_id' => $notice['user_id'],
  5228. ];
  5229. $groupResult = GroupImp::insertGetId($group);
  5230. var_dump($groupResult, '获取imp group_id');
  5231. $groupMember = [
  5232. 'user_id' => $notice['user_id'],
  5233. 'group_id' => $groupResult,
  5234. 'leader' => 1,
  5235. 'join_time' => Date('Y-m-d H:i:s')
  5236. ];
  5237. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5238. $talk_session = [
  5239. 'user_id' => $notice['user_id'],
  5240. 'to_from_id' => $groupResult,
  5241. 'talk_mode' => 2,
  5242. 'created_at' => Date('Y-m-d H:i:s'),
  5243. 'updated_at' => Date('Y-m-d H:i:s'),
  5244. ];
  5245. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5246. //被通知人员处理
  5247. foreach ($chat_ids as $key => $value) {
  5248. $groupMemberdata[] = [
  5249. 'user_id' => $value,
  5250. 'group_id' => $groupResult,
  5251. 'leader' => 3,
  5252. 'join_time' => Date('Y-m-d H:i:s')
  5253. ];
  5254. $talk_sessionData[] = [
  5255. 'user_id' => $value,
  5256. 'to_from_id' => $groupResult,
  5257. 'talk_mode' => 2,
  5258. 'created_at' => Date('Y-m-d H:i:s'),
  5259. 'updated_at' => Date('Y-m-d H:i:s'),
  5260. ];
  5261. }
  5262. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5263. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5264. $group_id = $groupResult;
  5265. //更新result的 group_id
  5266. $data['group_id'] = $group_id;
  5267. Notice::where(['id' => $data['id']])->update($data);
  5268. }
  5269. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5270. //删除掉信息
  5271. GroupImp::where('id', $notice['group_id'])->delete();
  5272. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5273. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5274. foreach ($chat_ids as $key => $value) {
  5275. }
  5276. //聊天记录删除
  5277. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5278. $data['group_id'] = null;
  5279. Notice::where(['id' => $data['id']])->update($data);
  5280. }
  5281. $result = Notice::where('id', $data['id'])->update($data);
  5282. $noticeInfo = Notice::where('id', $data['id'])->first();
  5283. if ($data['status'] == 2) {
  5284. $this->sendMessage([
  5285. 'talk_type' => 701,
  5286. 'title' => $noticeInfo['title'],
  5287. 'content' => '审核通过',
  5288. 'messageType' => 3,
  5289. 'user_id' => $noticeInfo['user_id'],
  5290. ]);
  5291. }
  5292. if ($data['status'] == 3) {
  5293. $this->sendMessage([
  5294. 'talk_type' => 701,
  5295. 'title' => $noticeInfo['title'],
  5296. 'content' => '审核拒绝',
  5297. 'messageType' => 3,
  5298. 'user_id' => $noticeInfo['user_id'],
  5299. ]);
  5300. }
  5301. if ($data['status'] == 1) {
  5302. $this->sendMessage([
  5303. 'talk_type' => 700,
  5304. 'title' => $noticeInfo['title'],
  5305. 'content' => '提交了审核',
  5306. 'messageType' => 3,
  5307. ]);
  5308. }
  5309. return Result::success($result);
  5310. }
  5311. public function getDUser(array $data): array
  5312. {
  5313. if (!empty($data['ids'])) {
  5314. $user = User::whereIn('id', $data['ids'])->getall();
  5315. if (empty($user)) {
  5316. return Result::error('无数据', 0);
  5317. }
  5318. return Result::success($user);
  5319. }
  5320. $where = [];
  5321. if (!empty($data['department_id'])) {
  5322. $where['department_id'] = $data['department_id'];
  5323. }
  5324. if (!empty($data['city_id'])) {
  5325. $where['city_id'] = $data['city_id'];
  5326. }
  5327. $result = User::where('type_id', 2)
  5328. ->where('status', 1)
  5329. ->where($where)
  5330. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5331. ->get();
  5332. if (empty($result)) {
  5333. return Result::error("查询失败", 0);
  5334. }
  5335. return Result::success($result);
  5336. }
  5337. /**
  5338. * 验证导航名称是否重复
  5339. * @return void
  5340. */
  5341. public function checkCategoryName(array $data): array
  5342. {
  5343. $result = Category::when($data, function ($query) use ($data) {
  5344. if (isset($data['name']) && $data['name']) {
  5345. $query->where("name", $data['name']);
  5346. }
  5347. if (isset($data['id']) && $data['id']) {
  5348. $query->where("id", "!=", $data['id']);
  5349. }
  5350. })->first();
  5351. if ($result) {
  5352. return Result::error("已存在");
  5353. } else {
  5354. return Result::success();
  5355. }
  5356. }
  5357. //20250226 产品列表
  5358. // 20250306 -------招聘--------fr
  5359. /*
  5360. * 招聘列表
  5361. * */
  5362. public function getJobRecruitingList(array $data): array
  5363. {
  5364. $where = [];
  5365. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5366. if ($data['checkout'] == 0) {
  5367. $job_status = [0, 2];
  5368. } else {
  5369. $job_status = [1];
  5370. }
  5371. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5372. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5373. }
  5374. $user = User::where('id', $data['user_id'])->first();
  5375. if (empty($user)) {
  5376. return Result::error("用户不存在", 0);
  5377. }
  5378. // 3:企业会员
  5379. if ($user['type_id'] == 3) {
  5380. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5381. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5382. }
  5383. // 如果 $where 为空,则不添加 where 条件
  5384. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5385. return $query->where($where);
  5386. })
  5387. ->whereIn('job_recruiting.status', $job_status)
  5388. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5389. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5390. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5391. ->orderBy("updated_at", "desc")
  5392. ->offset(($data['page'] - 1) * $data['page_size'])
  5393. ->limit($data['page_size'])
  5394. ->get()
  5395. ->all();
  5396. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5397. return $query->where($where);
  5398. })
  5399. ->whereIn('job_recruiting.status', $job_status)
  5400. ->count();
  5401. if (empty($result)) {
  5402. return Result::error("暂无招聘信息", 0);
  5403. }
  5404. return Result::success($result);
  5405. }
  5406. /*
  5407. * 招聘信息添加
  5408. * */
  5409. public function addJobRecruiting(array $data): array
  5410. {
  5411. // var_dump('添加招聘进入news------data',$data);
  5412. // return Result::success($data);
  5413. $user = User::where('user.id', $data['user_id'])
  5414. ->where('user.status', 1)
  5415. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5416. ->select(
  5417. 'user.type_id',
  5418. 'user.mobile',
  5419. 'user.email',
  5420. 'user_info.business_name',
  5421. 'user_info.company_hy_id',
  5422. 'user_info.company_nature',
  5423. 'user_info.company_size',
  5424. 'user_info.introduction',
  5425. 'user_info.real_name',
  5426. 'user_info.company_url',
  5427. 'user_info.address_arr_id',
  5428. 'user_info.address'
  5429. )
  5430. ->first();
  5431. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5432. return Result::error("用户不存在", 0);
  5433. }
  5434. $web = Website::where('id', $data['website_id'])->first();
  5435. if (empty($web)) {
  5436. return Result::error("网站不存在", 0);
  5437. }
  5438. // var_dump('添加招聘进入news---user---user',$user);
  5439. // 处理招聘关键词
  5440. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5441. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5442. } else {
  5443. Jieba::init(); // 初始化 jieba-php
  5444. Finalseg::init();
  5445. $segList = Jieba::cut($data['title']);
  5446. $segList1 = array_slice($segList, 0, 8);
  5447. $data['keyword'] = implode(',', $segList1);
  5448. }
  5449. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5450. $content = $data['description'];
  5451. // 去除 <style> 和 <script> 标签及其内容
  5452. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5453. // 去除所有 HTML 标签
  5454. $content = strip_tags($content);
  5455. // 去除 HTML 实体
  5456. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5457. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5458. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5459. // 去除多余空白
  5460. $content = preg_replace('/\s+/u', '', $content);
  5461. // 截取 100 个字符
  5462. $data['seo_description'] = mb_substr($content, 0, 100);
  5463. }
  5464. // return Result::success($user);
  5465. $data['action_id'] = $data['user_id'] ?? null;
  5466. $data['user_type'] = $user['type_id'] ?? null;
  5467. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5468. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5469. $data['catid'] = end($data['cat_arr_id']);
  5470. } else {
  5471. $data['catid'] = 0;
  5472. }
  5473. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5474. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5475. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5476. // 公司地址 管理员必填
  5477. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5478. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5479. // 管理员-企业相关信息
  5480. $company = [
  5481. // 'user_id' => $data['user_id']?? null,
  5482. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5483. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5484. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5485. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5486. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5487. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5488. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5489. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5490. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5491. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5492. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5493. ];
  5494. //去掉相关企业信息
  5495. $job = array_diff_key($data, array_flip(array_keys($company)));
  5496. // var_dump('添加招聘进入news---job---user',$job);
  5497. Db::beginTransaction();
  5498. try {
  5499. // // 先添加职位相关信息
  5500. if ($user['type_id'] == 10000) {
  5501. $job['status'] = 1;
  5502. }
  5503. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5504. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5505. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5506. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5507. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5508. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5509. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5510. // return Result::success($job);
  5511. $jobId = JobRecruiting::insertGetId($job);
  5512. if (empty($jobId)) {
  5513. Db::rollBack();
  5514. return Result::error("添加失败");
  5515. }
  5516. // 添加公司信息
  5517. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5518. $company['job_id'] = $jobId;
  5519. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5520. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5521. if ($user['type_id'] == 10000) {
  5522. // 管理员添加企业信息
  5523. $companyId = JobCompany::insertGetId($company);
  5524. if (empty($companyId)) {
  5525. Db::rollBack();
  5526. return Result::error("添加失败");
  5527. }
  5528. } else {
  5529. // 企业会员添加企业信息
  5530. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5531. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5532. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5533. $company['job_id'] = $jobId;
  5534. $companyId = JobCompany::insertGetId($company);
  5535. if (empty($companyId)) {
  5536. Db::rollBack();
  5537. return Result::error("添加失败");
  5538. }
  5539. }
  5540. Db::commit();
  5541. $result = [
  5542. 'job_id' => $jobId,
  5543. 'company_id' => $companyId,
  5544. ];
  5545. return Result::success($result);
  5546. } catch (\Exception $e) {
  5547. Db::rollBack();
  5548. return Result::error($e->getMessage(), 0);
  5549. }
  5550. // return Result::success($result);
  5551. }
  5552. /*
  5553. * 获取招聘信息详情
  5554. * */
  5555. public function getJobRecruitingInfo(array $data): array
  5556. {
  5557. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5558. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5559. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5560. ->select(
  5561. 'job_recruiting.*',
  5562. 'website.website_name as website_name',
  5563. 'job_company.business_name',
  5564. 'job_company.company_hy_id',
  5565. 'job_company.company_size',
  5566. 'job_company.company_nature',
  5567. 'job_company.introduction',
  5568. 'job_company.real_name',
  5569. 'job_company.mobile',
  5570. 'job_company.company_url',
  5571. 'job_company.address_arr_id',
  5572. 'job_company.address',
  5573. 'job_company.email'
  5574. )
  5575. ->first();
  5576. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5577. if (!empty($cityId)) {
  5578. if (isset($cityId[1]) && $cityId[1] != null) {
  5579. $city = District::where('id', $cityId[1])->first(['name']);
  5580. } else {
  5581. $city = District::where('id', $cityId[0])->first(['name']);
  5582. }
  5583. $result['city'] = $city['name'] ?? '';
  5584. }
  5585. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5586. if (is_array($addressId) && !empty($addressId)) {
  5587. $address = District::whereIn('id', $addressId)
  5588. ->orderBy('level', 'asc')
  5589. ->get(['name'])
  5590. ->pluck('name')
  5591. ->implode('');
  5592. // $job->address_name = $address ?? '';
  5593. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5594. }
  5595. if (empty($result)) {
  5596. return Result::error("招聘信息不存在", 0);
  5597. }
  5598. // return Result::success($job);
  5599. return Result::success($result);
  5600. }
  5601. /*
  5602. * 修改招聘信息
  5603. * */
  5604. public function upJobRecruiting(array $data): array
  5605. {
  5606. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5607. // return Result::success($job);
  5608. if (empty($job)) {
  5609. return Result::error("招聘信息不存在", 0);
  5610. }
  5611. $user = User::where('id', $data['user_id'])->first();
  5612. // return Result::success($user);
  5613. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5614. return Result::error("用户不存在", 0);
  5615. }
  5616. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5617. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5618. }
  5619. // 处理招聘关键词
  5620. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5621. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5622. } else {
  5623. Jieba::init(); // 初始化 jieba-php
  5624. Finalseg::init();
  5625. $segList = Jieba::cut($data['title']);
  5626. $segList1 = array_slice($segList, 0, 8);
  5627. $data['keyword'] = implode(',', $segList1);
  5628. }
  5629. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5630. $content = $data['description'];
  5631. // 去除 <style> 和 <script> 标签及其内容
  5632. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5633. // 去除所有 HTML 标签
  5634. $content = strip_tags($content);
  5635. // 去除 HTML 实体
  5636. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5637. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5638. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5639. // 去除多余空白
  5640. $content = preg_replace('/\s+/u', '', $content);
  5641. // 截取 100 个字符
  5642. $data['seo_description'] = mb_substr($content, 0, 100);
  5643. }
  5644. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5645. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5646. $data['catid'] = end($data['cat_arr_id']);
  5647. } else {
  5648. }
  5649. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5650. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5651. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5652. // 公司地址 管理员必填
  5653. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5654. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5655. // 管理员-企业相关信息
  5656. $company = [
  5657. // 'user_id' => $data['user_id']?? null,
  5658. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5659. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5660. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5661. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5662. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5663. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5664. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5665. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5666. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5667. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5668. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5669. ];
  5670. //去掉相关企业信息
  5671. $data = array_diff_key($data, array_flip(array_keys($company)));
  5672. $jobId = $data['id'];
  5673. $web = $data['website_id'];
  5674. $data['action_id'] = $data['user_id'];
  5675. unset($data['user_id']);
  5676. unset($data['user_type']);
  5677. unset($data['id']);
  5678. unset($data['website_id']);
  5679. // return Result::success($data);
  5680. Db::beginTransaction();
  5681. try {
  5682. // 管理员修改招聘信息
  5683. if ($user['type_id'] == 10000) {
  5684. $data['website_id'] = $web;
  5685. $company['website_id'] = $data['website_id'];
  5686. $data['status'] = 1;
  5687. } else {
  5688. $data['status'] = 0;
  5689. }
  5690. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5691. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5692. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5693. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5694. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5695. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5696. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5697. // return Result::success($job);
  5698. // Db::rollBack();
  5699. // return Result::success($company);
  5700. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5701. $this->sendMessage([
  5702. 'talk_type' => 500,
  5703. 'title' => $data['title'],
  5704. 'content' => '提交了审核',
  5705. 'messageType' => 10,
  5706. ]);
  5707. }
  5708. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5709. if (empty($result['job'])) {
  5710. Db::rollBack();
  5711. return Result::error("修改招聘信息失败");
  5712. }
  5713. // 管理员修改企业相关信息
  5714. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5715. if (empty($result['company'])) {
  5716. Db::rollBack();
  5717. return Result::error("修改企业相关信息失败");
  5718. }
  5719. Db::commit();
  5720. // return Result::success($result);
  5721. } catch (\Exception $e) {
  5722. Db::rollBack();
  5723. return Result::error($e->getMessage(), 0);
  5724. }
  5725. return Result::success($result);
  5726. }
  5727. /*
  5728. * 招聘信息删除
  5729. * */
  5730. public function delJobRecruiting(array $data): array
  5731. {
  5732. $user = User::where('id', $data['user_id'])->first();
  5733. if (empty($user)) {
  5734. return Result::error("用户不存在", 0);
  5735. }
  5736. $job = JobRecruiting::where('id', $data['id'])->first();
  5737. if (empty($job)) {
  5738. return Result::error("招聘信息不存在", 0);
  5739. }
  5740. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5741. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5742. }
  5743. Db::beginTransaction();
  5744. try {
  5745. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5746. if (empty($result['job'])) {
  5747. Db::rollBack();
  5748. return Result::error("删除招聘信息失败");
  5749. }
  5750. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5751. if (empty($result['company'])) {
  5752. Db::rollBack();
  5753. return Result::error("删除企业相关信息失败");
  5754. }
  5755. Db::commit();
  5756. } catch (\Exception $e) {
  5757. Db::rollBack();
  5758. return Result::error($e->getMessage(), 0);
  5759. }
  5760. return Result::success($result);
  5761. }
  5762. /*
  5763. * 获取公司信息
  5764. * */
  5765. public function getJobCompany(array $data): array
  5766. {
  5767. $user = User::where('user.id', $data['user_id'])
  5768. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5769. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5770. ->first();
  5771. // return Result::success($user);
  5772. if (empty($user)) {
  5773. return Result::error("用户不存在", 0);
  5774. }
  5775. if ($user['type_id'] == 3) {
  5776. $result = [
  5777. // 'id' => 0,
  5778. 'user_id' => $data['user_id'],
  5779. 'website_id' => $data['website_id'],
  5780. 'business_name' => $user['business_name'], // 企业名称
  5781. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5782. 'company_nature' => $user['company_nature'], // 公司性质
  5783. 'company_size' => $user['company_size'], // 公司规模
  5784. 'introduction' => $user['introduction'], // 公司简介
  5785. 'real_name' => $user['real_name'], // 企业联系人
  5786. 'mobile' => $user['mobile'], // 企业联系电话
  5787. 'company_url' => $user['company_url'], // 企业网址
  5788. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5789. 'address' => $user['address'], // 企业地址
  5790. 'email' => $user['email'], // 企业邮箱
  5791. ];
  5792. } else {
  5793. return Result::error("用户类型错误", 0);
  5794. }
  5795. if (empty($result)) {
  5796. return Result::error("公司信息不存在", 0);
  5797. }
  5798. return Result::success($result);
  5799. }
  5800. /*
  5801. * 修改公司信息
  5802. * */
  5803. public function upJobCompany(array $data): array
  5804. {
  5805. // return Result::success($data);
  5806. $user = User::where('user.id', $data['user_id'])
  5807. ->where('user.status', 1)
  5808. ->select('user.user_name', 'user.type_id')
  5809. ->first();
  5810. if (empty($user)) {
  5811. return Result::error("用户不存在", 0);
  5812. }
  5813. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5814. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5815. $company = [
  5816. 'business_name' => $data['business_name'], // 企业名称
  5817. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5818. 'company_nature' => $data['company_nature'], // 公司性质
  5819. 'company_size' => $data['company_size'], // 公司规模
  5820. 'introduction' => $data['introduction'], // 公司简介
  5821. // 'real_name' => $data['real_name'], // 企业联系人
  5822. 'company_url' => $data['company_url'], // 企业网址
  5823. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5824. 'address' => $data['address'], // 企业详细地址
  5825. // 'email' => $data['email'], // 企业邮箱
  5826. ];
  5827. if ($user['type_id'] == 3) {
  5828. Db::beginTransaction();
  5829. try {
  5830. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5831. 'business_name' => $data['business_name'], // 企业名称
  5832. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5833. 'company_nature' => $data['company_nature'], // 公司性质
  5834. 'company_size' => $data['company_size'], // 公司规模
  5835. 'introduction' => $data['introduction'], // 公司简介
  5836. // 'real_name' => $data['real_name'], // 企业联系人
  5837. 'company_url' => $data['company_url'], // 企业网址
  5838. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5839. 'address' => $data['address'], // 企业详细地址
  5840. ]);
  5841. if (empty($result['userinfo'])) {
  5842. Db::rollBack();
  5843. return Result::error('修改企业会员信息失败!');
  5844. }
  5845. $result['user'] = User::where('id', $data['user_id'])->update([
  5846. 'email' => $data['email'], // 企业邮箱
  5847. ]);
  5848. if (empty($result['user'])) {
  5849. Db::rollBack();
  5850. return Result::error('修改个人中心信息失败!');
  5851. }
  5852. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5853. if (!empty($job_company)) {
  5854. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5855. if (empty($result['job_company'])) {
  5856. Db::rollBack();
  5857. return Result::error('修改企业会员信息失败!');
  5858. }
  5859. }
  5860. Db::commit();
  5861. return Result::success($result);
  5862. } catch (\Exception $e) {
  5863. Db::rollBack();
  5864. return Result::error($e->getMessage(), 0);
  5865. }
  5866. } else {
  5867. return Result::error("用户类型错误", 0);
  5868. }
  5869. }
  5870. /*
  5871. * 获取省-市
  5872. * */
  5873. public function getJobRecruitingArea(array $data): array
  5874. {
  5875. if (isset($data['pid']) && $data['pid'] != null) {
  5876. $result = District::where('pid', $data['pid'])->get()->all();
  5877. } else {
  5878. $result = District::where('level', 1)->get()->all();
  5879. }
  5880. if (empty($result)) {
  5881. return Result::error("暂无此省市", 0);
  5882. }
  5883. return Result::success($result);
  5884. }
  5885. /*
  5886. * 获取行业分类
  5887. * */
  5888. public function getIndustry(array $data): array
  5889. {
  5890. $result = JobIndustry::get()->all();
  5891. if (empty($result)) {
  5892. return Result::error("暂无行业分类", 0);
  5893. }
  5894. return Result::success($result);
  5895. }
  5896. /*
  5897. * 获取职位
  5898. * */
  5899. public function getPositionList(array $data): array
  5900. {
  5901. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5902. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5903. } else {
  5904. $result = JobPosition::where('zwpid', 0)->get()->all();
  5905. }
  5906. if (empty($result)) {
  5907. return Result::error("暂无此职位", 0);
  5908. }
  5909. return Result::success($result);
  5910. }
  5911. /*
  5912. * 获取工作性质-菜单
  5913. * */
  5914. public function getJobNature(array $data): array
  5915. {
  5916. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5917. if (empty($result)) {
  5918. return Result::error("暂无工作性质", 0);
  5919. }
  5920. return Result::success($result);
  5921. }
  5922. /*
  5923. * 获取工作经验-菜单
  5924. * */
  5925. public function getExperience(array $data): array
  5926. {
  5927. $result = JobEnum::where('egroup', 'years')->get()->all();
  5928. if (empty($result)) {
  5929. return Result::error("暂无工作经验", 0);
  5930. }
  5931. return Result::success($result);
  5932. }
  5933. /*
  5934. * 获取学历-菜单
  5935. * */
  5936. public function getEducation(array $data): array
  5937. {
  5938. $result = JobEnum::where('egroup', 'education')->get()->all();
  5939. if (empty($result)) {
  5940. return Result::error("暂无学历", 0);
  5941. }
  5942. return Result::success($result);
  5943. }
  5944. /*
  5945. * 获取薪资-菜单
  5946. * */
  5947. public function getSalary(array $data): array
  5948. {
  5949. $result = JobEnum::where('egroup', 'income')->get()->all();
  5950. if (empty($result)) {
  5951. return Result::error("暂无薪资", 0);
  5952. }
  5953. return Result::success($result);
  5954. }
  5955. /*
  5956. * 获取语言-菜单
  5957. * */
  5958. public function getLanguage(array $data): array
  5959. {
  5960. $result = JobEnum::where('egroup', 'language')->get()->all();
  5961. if (empty($result)) {
  5962. return Result::error("暂无语言", 0);
  5963. }
  5964. return Result::success($result);
  5965. }
  5966. /*
  5967. * 获取掌握程度-菜单
  5968. * */
  5969. public function getLevel(array $data): array
  5970. {
  5971. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5972. if (empty($result)) {
  5973. return Result::error("暂无工作性质", 0);
  5974. }
  5975. return Result::success($result);
  5976. }
  5977. // 公司信息
  5978. /*
  5979. * 获取公司性质-菜单
  5980. * */
  5981. public function getCompanyNature(array $data): array
  5982. {
  5983. $result = JobNature::get()->all();
  5984. if (empty($result)) {
  5985. return Result::error("暂无公司性质", 0);
  5986. }
  5987. return Result::success($result);
  5988. }
  5989. /*
  5990. * 获取公司规模-菜单
  5991. * */
  5992. public function getCompanySize(array $data): array
  5993. {
  5994. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5995. if (empty($result)) {
  5996. return Result::error("暂无公司规模", 0);
  5997. }
  5998. return Result::success($result);
  5999. }
  6000. /*
  6001. * 招聘信息审核
  6002. * */
  6003. public function checkJobRecruiting(array $data): array
  6004. {
  6005. $user = User::where('id', $data['user_id'])->first();
  6006. if (empty($user)) {
  6007. return Result::error("用户不存在", 0);
  6008. }
  6009. $job = JobRecruiting::where('id', $data['id'])->first();
  6010. if (empty($job)) {
  6011. return Result::error("招聘信息不存在", 0);
  6012. }
  6013. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6014. if ($user['type_id'] != 10000) {
  6015. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6016. }
  6017. // 驳回原因
  6018. if ($data['status'] == 2) {
  6019. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6020. }
  6021. $data['action_id'] = $data['user_id'];
  6022. unset($data['user_id']);
  6023. if ($data['status'] == 1) {
  6024. $this->sendMessage([
  6025. 'talk_type' => 501,
  6026. 'title' => $job['title'],
  6027. 'content' => '审核通过',
  6028. 'messageType' => 10,
  6029. 'user_id' => $job['user_id'],
  6030. ]);
  6031. }
  6032. if ($data['status'] == 2) {
  6033. $this->sendMessage([
  6034. 'talk_type' => 501,
  6035. 'title' => $job['title'],
  6036. 'content' => '审核拒绝',
  6037. 'messageType' => 10,
  6038. 'user_id' => $job['user_id'],
  6039. ]);
  6040. }
  6041. if ($data['status'] == 0) {
  6042. $this->sendMessage([
  6043. 'talk_type' => 500,
  6044. 'title' => $job['title'],
  6045. 'content' => '提交了审核',
  6046. 'messageType' => 10,
  6047. ]);
  6048. }
  6049. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6050. if (empty($result)) {
  6051. return Result::error("审核失败", 0);
  6052. }
  6053. return Result::success($result);
  6054. }
  6055. public function myApplyList(array $data): array
  6056. {
  6057. var_dump($data, '------参数');
  6058. $user = User::where('id', $data['user_id'])->first();
  6059. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6060. return Result::error("用户不存在", 0);
  6061. }
  6062. // 1:个人会员 职场机会
  6063. if ($user['type_id'] == 1) {
  6064. $where['user_id'] = $user['id'];
  6065. }
  6066. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6067. $query->where('user_id', $user['id']);
  6068. })
  6069. ->pluck('recruit_id');
  6070. $where = [];
  6071. if (isset($data['salary']) && $data['salary'] != null) {
  6072. $where['job_recruiting.salary'] = $data['salary'];
  6073. }
  6074. if (isset($data['experience']) && $data['experience'] != null) {
  6075. $where['job_recruiting.experience'] = $data['experience'];
  6076. }
  6077. if (isset($data['business_name']) && $data['business_name'] != null) {
  6078. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6079. }
  6080. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6081. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6082. ->where($where);
  6083. // ->count();
  6084. $count = $query->count();
  6085. $query = clone $query;
  6086. $job = $query
  6087. ->leftJoin('job_enum as income_enum', function ($join) {
  6088. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6089. ->where('income_enum.egroup', 'income');
  6090. })
  6091. ->leftJoin('job_enum as years_enum', function ($join) {
  6092. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6093. ->where('years_enum.egroup', 'years');
  6094. })
  6095. // ->where($where)
  6096. ->orderBy('job_recruiting.updated_at', 'desc')
  6097. ->select(
  6098. 'job_recruiting.id',
  6099. 'job_recruiting.title',
  6100. 'job_company.business_name',
  6101. 'income_enum.evalue as salary_evalue',
  6102. 'income_enum.ename as salary_ename',
  6103. 'years_enum.evalue as experience_evalue',
  6104. 'years_enum.ename as experience_ename',
  6105. 'job_recruiting.updated_at'
  6106. )
  6107. ->offset(($data['page'] - 1) * $data['pageSize'])
  6108. ->limit($data['pageSize'])
  6109. ->get()
  6110. ->all();
  6111. if (empty($job)) {
  6112. return Result::error("暂无招聘信息", 0);
  6113. }
  6114. $result = [
  6115. 'row' => $job,
  6116. 'count' => $count,
  6117. ];
  6118. return Result::success($result);
  6119. }
  6120. public function readJobApply(array $data): array
  6121. {
  6122. $result = JobApply::where('id', $data['id'])->first();
  6123. if (empty($result)) {
  6124. return Result::error("查询失败", 0);
  6125. }
  6126. $result = JobApply::where('id', $data['id'])->update([
  6127. 'status' => 2,
  6128. ]);
  6129. return Result::success($result);
  6130. }
  6131. /*
  6132. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6133. * */
  6134. public function getRecruitingList(array $data): array
  6135. {
  6136. $user = User::where('id', $data['user_id'])->first();
  6137. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6138. return Result::error("用户不存在", 0);
  6139. }
  6140. // 1:个人会员 职场机会
  6141. if ($user['type_id'] == 1) {
  6142. $where['user_id'] = $user['id'];
  6143. }
  6144. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6145. $query->where('receiver_id', $user['id']);
  6146. })
  6147. ->pluck('recruit_id');
  6148. // return Result::success($recruitingId);
  6149. $where = [];
  6150. if (isset($data['salary']) && $data['salary'] != null) {
  6151. $where['job_recruiting.salary'] = $data['salary'];
  6152. }
  6153. if (isset($data['experience']) && $data['experience'] != null) {
  6154. $where['job_recruiting.experience'] = $data['experience'];
  6155. }
  6156. if (isset($data['business_name']) && $data['business_name'] != null) {
  6157. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6158. }
  6159. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6160. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6161. ->where($where);
  6162. // ->count();
  6163. $count = $query->count();
  6164. $query = clone $query;
  6165. $job = $query
  6166. ->leftJoin('job_enum as income_enum', function ($join) {
  6167. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6168. ->where('income_enum.egroup', 'income');
  6169. })
  6170. ->leftJoin('job_enum as years_enum', function ($join) {
  6171. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6172. ->where('years_enum.egroup', 'years');
  6173. })
  6174. // ->where($where)
  6175. ->orderBy('job_recruiting.updated_at', 'desc')
  6176. ->select(
  6177. 'job_recruiting.id',
  6178. 'job_recruiting.title',
  6179. 'job_company.business_name',
  6180. 'income_enum.evalue as salary_evalue',
  6181. 'income_enum.ename as salary_ename',
  6182. 'years_enum.evalue as experience_evalue',
  6183. 'years_enum.ename as experience_ename',
  6184. 'job_recruiting.updated_at'
  6185. )
  6186. ->offset(($data['page'] - 1) * $data['pageSize'])
  6187. ->limit($data['pageSize'])
  6188. ->get()
  6189. ->all();
  6190. if (empty($job)) {
  6191. return Result::error("暂无招聘信息", 0);
  6192. }
  6193. $result = [
  6194. 'row' => $job,
  6195. 'count' => $count,
  6196. ];
  6197. return Result::success($result);
  6198. }
  6199. /*
  6200. * 获取企业会员-招聘信息列表
  6201. * */
  6202. public function getRecruitingInfo(array $data): array
  6203. {
  6204. $user = User::where('id', $data['user_id'])->first();
  6205. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6206. return Result::error("用户不存在", 0);
  6207. }
  6208. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6209. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6210. ->select(
  6211. 'job_recruiting.*',
  6212. 'job_company.business_name',
  6213. 'job_company.company_hy_id',
  6214. 'job_company.company_size',
  6215. 'job_company.company_nature',
  6216. 'job_company.introduction',
  6217. 'job_company.real_name',
  6218. 'job_company.mobile',
  6219. 'job_company.company_url',
  6220. 'job_company.address_arr_id',
  6221. 'job_company.address',
  6222. 'job_company.email'
  6223. )
  6224. ->get();
  6225. if (empty($recruiting)) {
  6226. return Result::error("暂无招聘信息", 0);
  6227. }
  6228. return Result::success($recruiting);
  6229. }
  6230. /*
  6231. * 获取企业会员-我的沟通
  6232. * */
  6233. public function getJobResumeList(array $data): array
  6234. {
  6235. $user = User::where('id', $data['user_id'])->first();
  6236. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6237. return Result::error("用户不存在", 0);
  6238. }
  6239. $where = [];
  6240. if (isset($data['salary']) && $data['salary'] != null) {
  6241. $where['job_hunting.salary'] = $data['salary'];
  6242. }
  6243. if (isset($data['user_name']) && $data['user_name'] != null) {
  6244. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6245. }
  6246. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6247. $query->where('job_resume.user_id', $user['id']);
  6248. })
  6249. ->when(!empty($where), function ($query) use ($where) {
  6250. $query->where($where);
  6251. })
  6252. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6253. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6254. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6255. ->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');
  6256. $count = $job->count();
  6257. if ($count == 0) {
  6258. return Result::error("暂无沟通记录", 0);
  6259. }
  6260. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6261. ->offset(($data['page'] - 1) * $data['pageSize'])
  6262. ->limit($data['pageSize'])
  6263. ->get();
  6264. if (empty($jobs)) {
  6265. return Result::error("暂无沟通记录", 0);
  6266. }
  6267. $result['row'] = $this->processJob($jobs, '');
  6268. $result['count'] = $count;
  6269. return Result::success($result);
  6270. }
  6271. public function readJobResume(array $data): array
  6272. {
  6273. $result = JobResume::where('id', $data['id'])->first();
  6274. if (empty($result)) {
  6275. return Result::error("查询失败", 0);
  6276. }
  6277. $result = JobResume::where('id', $data['id'])->update([
  6278. 'status' => 2,
  6279. ]);
  6280. return Result::success($result);
  6281. }
  6282. // 20250306 招聘
  6283. //20250422 书刊音像
  6284. public function addBook(array $data): array
  6285. {
  6286. $user_id = $data['user_id'] ?? 0;
  6287. $type_id = $data['type_id'] ?? 0;
  6288. // $website_id = $data['website_id'] ?? 0;
  6289. // unset($data['user_id']);
  6290. unset($data['type_id']);
  6291. // unset($data['website_id']);
  6292. //处理数组
  6293. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6294. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6295. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6296. if ($data['img_url'] == '') {
  6297. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6298. preg_match_all($reg, $data['detail'], $matches);
  6299. if (isset($matches[1][0])) {
  6300. //截取varchar240
  6301. $data['img_url'] = substr($matches[1][0], 0, 240);
  6302. }
  6303. }
  6304. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6305. //提取标题+内容中的关键词
  6306. $data['keyword'] = $data['title'];
  6307. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6308. Jieba::init(); // 初始化 jieba-php
  6309. Finalseg::init();
  6310. $segList = Jieba::cut($data['keyword']);
  6311. $segList1 = array_slice($segList, 0, 8);
  6312. $data['keyword'] = implode(',', $segList1);
  6313. }
  6314. if ($data['description'] == '') {
  6315. //提取内容中的描述
  6316. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6317. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6318. }
  6319. var_dump($data, '--');
  6320. if ($data['status'] == 1) {
  6321. $this->sendMessage([
  6322. 'talk_type' => 400,
  6323. 'title' => $data['title'],
  6324. 'content' => '提交了审核',
  6325. 'messageType' => 7,
  6326. ]);
  6327. }
  6328. $result = Book::insertGetId($data);
  6329. if (empty($result)) {
  6330. return Result::error("添加失败", 0);
  6331. }
  6332. return Result::success($result);
  6333. }
  6334. public function getBookList(array $data): array
  6335. {
  6336. $where = [];
  6337. if (!empty($data["title"])) {
  6338. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6339. }
  6340. if (!empty($data['website_name'])) {
  6341. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6342. }
  6343. if (!empty($data['status'])) {
  6344. $where[] = ['book.status', '=', $data['status']];
  6345. }
  6346. $user_id = $data['user_id'];
  6347. $type_id = $data['type_id'];
  6348. // $type_id = 4;
  6349. var_dump($type_id, '------1--------');
  6350. if ($type_id != 10000) {
  6351. $where[] = ['book.user_id', '=', $user_id];
  6352. }
  6353. var_dump(!empty($data['status1']), '=-===1');
  6354. $result = Book::where($where)
  6355. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6356. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6357. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6358. ->when(isset($data['status1']), function ($query) use ($data) {
  6359. $query->whereIn('book.status', [1, 3]);
  6360. })
  6361. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6362. ->orderBy("updated_at", "desc")
  6363. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6364. if (empty($result)) {
  6365. return Result::error("暂无数据", 0);
  6366. }
  6367. // 取出数据
  6368. $rows = $result->items();
  6369. $count = $result->total();
  6370. $responseData = [
  6371. 'rows' => $rows,
  6372. 'count' => $count,
  6373. ];
  6374. return Result::success($responseData);
  6375. }
  6376. public function deleteBook(array $data): array
  6377. {
  6378. $result = Book::where('id', $data['id'])->delete();
  6379. if (empty($result)) {
  6380. return Result::error("删除失败", 0);
  6381. }
  6382. return Result::success($result);
  6383. }
  6384. public function updateBook(array $data): array
  6385. {
  6386. // $user_id = $data['user_id'] ?? 0;
  6387. $type_id = $data['type_id'] ?? 0;
  6388. // $website_id = $data['website_id'] ?? 0;
  6389. unset($data['user_id']);
  6390. unset($data['type_id']);
  6391. // unset($data['website_id']);
  6392. //处理数组
  6393. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6394. if ($data['img_url'] == '') {
  6395. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6396. preg_match_all($reg, $data['detail'], $matches);
  6397. if (isset($matches[1][0])) {
  6398. //截取varchar240
  6399. $data['img_url'] = substr($matches[1][0], 0, 240);
  6400. }
  6401. }
  6402. if ($data['keyword'] == '') {
  6403. //提取标题+内容中的关键词
  6404. $data['keyword'] = $data['title'];
  6405. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6406. Jieba::init(); // 初始化 jieba-php
  6407. Finalseg::init();
  6408. $segList = Jieba::cut($data['keyword']);
  6409. $segList1 = array_slice($segList, 0, 8);
  6410. $data['keyword'] = implode(',', $segList1);
  6411. }
  6412. if ($data['description'] == '') {
  6413. //提取内容中的描述
  6414. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6415. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6416. }
  6417. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6418. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6419. if ($data['status'] == 1) {
  6420. $this->sendMessage([
  6421. 'talk_type' => 400,
  6422. 'title' => $data['title'],
  6423. 'content' => '提交了审核',
  6424. 'messageType' => 7,
  6425. ]);
  6426. }
  6427. $result = Book::where("id", $data["id"])->update($data);
  6428. if (empty($result)) {
  6429. return Result::error("更新失败", 0);
  6430. }
  6431. return Result::success($result);
  6432. }
  6433. public function getBookInfo(array $data): array
  6434. {
  6435. $result = Book::where("id", $data["id"])->first();
  6436. if (empty($result)) {
  6437. return Result::error("获取失败", 0);
  6438. }
  6439. return Result::success($result);
  6440. }
  6441. public function updateBookStatus(array $data): array
  6442. {
  6443. //审核
  6444. unset($data['user_id']);
  6445. $bookInfo = Book::where("id", $data["id"])->first();
  6446. var_dump($bookInfo, '----');
  6447. if ($data['status'] == 2) {
  6448. $this->sendMessage([
  6449. 'talk_type' => 401,
  6450. 'title' => $bookInfo['title'],
  6451. 'content' => '审核通过',
  6452. 'messageType' => 7,
  6453. 'user_id' => $bookInfo['user_id'],
  6454. ]);
  6455. }
  6456. if ($data['status'] == 3) {
  6457. $this->sendMessage([
  6458. 'talk_type' => 401,
  6459. 'title' => $bookInfo['title'],
  6460. 'content' => '审核拒绝',
  6461. 'messageType' => 7,
  6462. 'user_id' => $bookInfo['user_id'],
  6463. ]);
  6464. }
  6465. if ($data['status'] == 1) {
  6466. $this->sendMessage([
  6467. 'talk_type' => 400,
  6468. 'title' => $bookInfo['title'],
  6469. 'content' => '提交了审核',
  6470. 'messageType' => 7,
  6471. // 'user_id'=>$bookInfo['user_id'],
  6472. ]);
  6473. }
  6474. $result = Book::where("id", $data["id"])->update($data);
  6475. if (empty($result)) {
  6476. return Result::error("更新失败", 0);
  6477. }
  6478. return Result::success($result);
  6479. }
  6480. //20250422 书刊音像
  6481. /**
  6482. * 贴身宝贝
  6483. * @param array $data
  6484. * @return array
  6485. */
  6486. public function getWebsiteTsbb(array $data): array
  6487. {
  6488. $month = $data['month'] ?? date('m');
  6489. $day = $data['day'] ?? date('d');
  6490. // 使用缓存键
  6491. $cacheKey = "tsbb_data_{$month}_{$day}";
  6492. // 尝试从缓存获取数据
  6493. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6494. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6495. if ($cachedData = $cache->get($cacheKey)) {
  6496. return Result::success(unserialize($cachedData));
  6497. }
  6498. //查询老黄历
  6499. try {
  6500. $date = date('Y-m-d');
  6501. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6502. // 使用 curl 替代 file_get_contents
  6503. $ch = curl_init();
  6504. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6505. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6506. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6507. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6508. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6509. 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');
  6510. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6511. 'Accept: application/json',
  6512. 'Content-Type: application/json',
  6513. 'Referer: https://www.36jxs.com/'
  6514. ]);
  6515. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6516. curl_setopt($ch, CURLOPT_ENCODING, '');
  6517. $almanacResponse = curl_exec($ch);
  6518. var_dump("====:", $almanacResponse);
  6519. if (curl_errno($ch)) {
  6520. var_dump('Curl error:', curl_error($ch));
  6521. throw new \Exception('Curl error: ' . curl_error($ch));
  6522. }
  6523. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6524. curl_close($ch);
  6525. if ($almanacResponse === false) {
  6526. throw new \Exception('Failed to fetch almanac data');
  6527. }
  6528. $almanacData = json_decode($almanacResponse, true);
  6529. if (json_last_error() !== JSON_ERROR_NONE) {
  6530. throw new \Exception('Failed to parse almanac data');
  6531. }
  6532. $almanacInfo = $almanacData['data'] ?? [];
  6533. } catch (\Exception $e) {
  6534. var_dump('Exception:', $e->getMessage());
  6535. $almanacInfo = [];
  6536. }
  6537. // 获取历史上的今天数据
  6538. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6539. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6540. ->orderBy('year', 'asc')
  6541. ->select("title", "id", "year", DB::raw('1 as type'))
  6542. ->limit(16)
  6543. ->get();
  6544. // 获取节日数据 - 从今天开始获取未来4条
  6545. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6546. ->orderBy('showtime', 'asc')
  6547. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6548. ->limit(16)
  6549. ->get();
  6550. //说文解字
  6551. $chartacterList = Character::orderBy('updated_at', 'desc')
  6552. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6553. ->limit(6)
  6554. ->get();
  6555. //谜语沙龙
  6556. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6557. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6558. ->limit(4)
  6559. ->get();
  6560. //成语欣赏
  6561. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6562. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6563. ->limit(32)
  6564. ->get();
  6565. //名联赏析
  6566. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6567. ->select("id", "first", "second", DB::raw('6 as type'))
  6568. ->limit(6)
  6569. ->get();
  6570. // 获取分类文章数据
  6571. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6572. ->pluck('category_id')
  6573. ->toArray();
  6574. $articlesList = [];
  6575. foreach ($categoryIds as $catid) {
  6576. // 先查有图片的
  6577. $withImg = DB::table('article')
  6578. ->where('status', 1)
  6579. ->where('catid', $catid)
  6580. ->whereNotNull('imgurl')
  6581. ->where('imgurl', '!=', '')
  6582. ->orderBy('updated_at', 'desc')
  6583. ->limit(6)
  6584. ->get();
  6585. $count = $withImg->count();
  6586. if ($count < 6) {
  6587. // 不足6条再查无图片的补足
  6588. $withoutImg = DB::table('article')
  6589. ->where('status', 1)
  6590. ->where('catid', $catid)
  6591. ->where(function ($q) {
  6592. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6593. })
  6594. ->orderBy('updated_at', 'desc')
  6595. ->limit(6 - $count)
  6596. ->get();
  6597. $articles = $withImg->concat($withoutImg);
  6598. } else {
  6599. $articles = $withImg;
  6600. }
  6601. // 组装
  6602. $category = \App\Model\Category::find($catid);
  6603. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6604. $articlesList[] = [
  6605. 'category_name' => $category ? $category->name : '',
  6606. 'catid' => $catid,
  6607. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6608. 'type' => 100,
  6609. 'list' => $articles->map(function ($item) {
  6610. return [
  6611. 'id' => $item->id,
  6612. 'title' => $item->title,
  6613. 'imgurl' => $item->imgurl,
  6614. 'created_at' => $item->created_at
  6615. ];
  6616. })->values()
  6617. ];
  6618. }
  6619. $result = [
  6620. 'almanac' => $almanacInfo,
  6621. 'historyTodayList' => [
  6622. 'category_name' => '历史上的今天',
  6623. 'list' => $historyTodayList,
  6624. 'type' => 1
  6625. ],
  6626. 'festivalList' => [
  6627. 'category_name' => '节日预告',
  6628. 'list' => $festivalList,
  6629. 'type' => 2
  6630. ],
  6631. 'chartacterList' => [
  6632. 'category_name' => '说文解字',
  6633. 'list' => $chartacterList,
  6634. 'type' => 3
  6635. ],
  6636. 'coupletList' => [
  6637. 'category_name' => '名联赏析',
  6638. 'list' => $coupletList,
  6639. 'type' => 6
  6640. ],
  6641. 'riddletList' => [
  6642. 'category_name' => '谜语沙龙',
  6643. 'list' => $riddletList,
  6644. 'type' => 4
  6645. ],
  6646. 'idiomList' => [
  6647. 'category_name' => '成语欣赏',
  6648. 'list' => $idiomList,
  6649. 'type' => 5
  6650. ],
  6651. 'articlesList' => $articlesList
  6652. ];
  6653. // 缓存结果,设置1小时过期
  6654. $cache->set($cacheKey, serialize($result), 3600);
  6655. return Result::success($result);
  6656. }
  6657. /**
  6658. * 获取资讯列表
  6659. */
  6660. public function getWebsiteTsbbList(array $data): array
  6661. {
  6662. $page = $data['page'] ?? 1;
  6663. $pageSize = $data['pageSize'] ?? 10;
  6664. // 如果没有传入月份和日期,则使用今天的日期
  6665. $month = $data['month'] ?? date('m');
  6666. $day = $data['day'] ?? date('d');
  6667. $total = 0;
  6668. $result = [];
  6669. $data['type'] = intval($data['type']);
  6670. var_dump("接收参数:", $data);
  6671. switch ($data['type']) {
  6672. case 1:
  6673. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6674. // 当前月份之后的数据
  6675. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6676. // 或者当前月份且日期大于等于当前日期的数据
  6677. ->orWhere(function ($q) use ($month, $day) {
  6678. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6679. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6680. });
  6681. })
  6682. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6683. $total = $query->count();
  6684. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6685. ->offset(($page - 1) * $pageSize)
  6686. ->limit($pageSize)
  6687. ->get();
  6688. break;
  6689. case 2:
  6690. $query = Festival::where(function ($q) use ($month, $day) {
  6691. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6692. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6693. ->orWhere(function ($q) use ($month, $day) {
  6694. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6695. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6696. });
  6697. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6698. $total = $query->count();
  6699. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6700. ->offset(($page - 1) * $pageSize)
  6701. ->limit($pageSize)
  6702. ->get();
  6703. break;
  6704. case 3:
  6705. $query = Character::orderBy("updated_at", "desc");
  6706. $total = $query->count();
  6707. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6708. ->offset(($page - 1) * $pageSize)
  6709. ->limit($pageSize)
  6710. ->get();
  6711. break;
  6712. case 4:
  6713. $query = Riddle::orderBy("updated_at", "desc");
  6714. $total = $query->count();
  6715. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6716. ->offset(($page - 1) * $pageSize)
  6717. ->limit($pageSize)
  6718. ->get();
  6719. break;
  6720. case 5:
  6721. $query = Idiom::orderBy("updated_at", "desc");
  6722. $total = $query->count();
  6723. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6724. ->offset(($page - 1) * $pageSize)
  6725. ->limit($pageSize)
  6726. ->get();
  6727. break;
  6728. case 6:
  6729. $query = Couplet::orderBy("updated_at", "desc");
  6730. $total = $query->count();
  6731. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6732. ->offset(($page - 1) * $pageSize)
  6733. ->limit($pageSize)
  6734. ->get();
  6735. break;
  6736. default:
  6737. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6738. $total = $query->count();
  6739. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6740. ->offset(($page - 1) * $pageSize)
  6741. ->limit($pageSize)
  6742. ->get();
  6743. }
  6744. return Result::success([
  6745. 'list' => $result,
  6746. 'total' => $total,
  6747. 'page' => (int)$page,
  6748. 'pageSize' => (int)$pageSize,
  6749. 'month' => $month,
  6750. 'day' => $day
  6751. ]);
  6752. }
  6753. /**
  6754. * 1:历史上的今天
  6755. * 2:节日
  6756. * 3:文章
  6757. *
  6758. * 资讯详情信息
  6759. */
  6760. public function getWebsiteTsbbDetail(array $data): array
  6761. {
  6762. $data['type'] = intval($data['type']);
  6763. switch ($data['type']) {
  6764. case 1:
  6765. $result = HistoryToday::where("id", $data['id'])->first();
  6766. break;
  6767. case 2:
  6768. $result = Festival::where("id", $data['id'])->first();
  6769. break;
  6770. case 3:
  6771. $result = Character::where("id", $data['id'])->first();
  6772. break;
  6773. case 4:
  6774. $result = Riddle::where("id", $data['id'])->first();
  6775. break;
  6776. case 5:
  6777. $result = Idiom::where("id", $data['id'])->first();
  6778. break;
  6779. case 6:
  6780. $result = Couplet::where("id", $data['id'])->first();
  6781. break;
  6782. default:
  6783. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6784. break;
  6785. }
  6786. return Result::success($result);
  6787. }
  6788. /**
  6789. * 农网导航首页数据
  6790. */
  6791. public function getWebsiteNwHomeList(array $data): array
  6792. {
  6793. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6794. ->pluck('category_id')
  6795. ->toArray();
  6796. // 使用子查询优化
  6797. $articlesList = DB::table('article')
  6798. ->select([
  6799. 'article.id',
  6800. 'article.title',
  6801. 'article.imgurl',
  6802. 'article.created_at',
  6803. 'category.name as category_name',
  6804. 'category.id as category_id',
  6805. 'website_category.aLIas_pinyin as pinyin',
  6806. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6807. DB::raw('100 as type')
  6808. ])
  6809. ->join('category', 'article.catid', '=', 'category.id')
  6810. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6811. ->leftJoin('website_category as parent_wc', function ($join) {
  6812. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6813. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6814. })
  6815. ->where('website_category.website_id', $data['website_id'])
  6816. ->where('article.status', 1)
  6817. ->whereIn('category.id', $categoryIds)
  6818. ->orderBy('article.created_at', 'desc')
  6819. ->get()
  6820. ->groupBy('category_id')
  6821. ->map(function ($group) {
  6822. // 确保第一条数据有图片
  6823. $firstWithImage = $group->first(function ($item) {
  6824. return !empty($item->imgurl);
  6825. });
  6826. if ($firstWithImage) {
  6827. // 如果有带图片的文章,将其放在第一位
  6828. $group = $group->filter(function ($item) use ($firstWithImage) {
  6829. return $item->id !== $firstWithImage->id;
  6830. })->prepend($firstWithImage);
  6831. }
  6832. return [
  6833. 'category_name' => $group->first()->category_name,
  6834. 'catid' => $group->first()->category_id,
  6835. 'pinyin' => $group->first()->pinyin,
  6836. 'parent_pinyin' => $group->first()->parent_pinyin,
  6837. 'list' => $group->take(4)->map(function ($item) {
  6838. return [
  6839. 'id' => $item->id,
  6840. 'title' => $item->title,
  6841. ];
  6842. })->values()
  6843. ];
  6844. })
  6845. ->values()
  6846. ->toArray();
  6847. return Result::success($articlesList);
  6848. }
  6849. /**
  6850. * 企业管理
  6851. * @param array $data
  6852. * @return array
  6853. */
  6854. public function getCompanyList(array $data): array
  6855. {
  6856. // return Result::success($data);
  6857. $where = [];
  6858. $user = User::where('id', $data['user_id'])->first();
  6859. if (empty($user)) {
  6860. return Result::error('用户不存在!');
  6861. }
  6862. if ($user['type_id'] != 10000) {
  6863. $where['user_id'] = $data['user_id'];
  6864. }
  6865. if (isset($data['title']) && !empty($data['title'])) {
  6866. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6867. }
  6868. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6869. array_push($where, ['website.id', $data['website_id']]);
  6870. }
  6871. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6872. if ($data['ischeck'] == 1) {
  6873. if (isset($data['status']) && $data['status'] != '') {
  6874. array_push($where, ['company.status', $data['status']]);
  6875. $query = Company::where($where);
  6876. } else {
  6877. $query = Company::whereIn('company.status', [0, 2]);
  6878. }
  6879. } else {
  6880. $query = Company::where('company.status', 1);
  6881. }
  6882. }
  6883. $result = $query->where($where)
  6884. ->leftJoin('website_category', function ($query) {
  6885. $query->on('website_category.category_id', '=', 'company.category_id')
  6886. ->on('website_category.website_id', '=', 'company.website_id');
  6887. })
  6888. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6889. ->select(
  6890. 'company.id',
  6891. 'company.title',
  6892. 'company.website_id',
  6893. 'company.category_id',
  6894. 'website.website_name',
  6895. 'website_category.alias as category_name',
  6896. 'company.status',
  6897. 'company.updated_at',
  6898. 'company.user_id'
  6899. )
  6900. ->orderBy('company.updated_at', 'desc')
  6901. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6902. if ($result->isEmpty()) {
  6903. return Result::error("暂无企业", 0);
  6904. }
  6905. return Result::success($result);
  6906. }
  6907. /**
  6908. * 添加企业
  6909. * @param array $data
  6910. * @return array
  6911. */
  6912. public function addCompany(array $data): array
  6913. {
  6914. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6915. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6916. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6917. $data['cat_arr_id'] = json_encode($car_arr_id);
  6918. } else {
  6919. $data['cat_arr_id'] = '';
  6920. }
  6921. if ($data['imgurl'] == '') {
  6922. //content中提取图片第一个图,正则提取
  6923. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6924. preg_match_all($reg, $data['content'], $matches);
  6925. if (isset($matches[1][0])) {
  6926. //截取varchar240
  6927. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6928. }
  6929. }
  6930. if ($data['keyword'] == '') {
  6931. //提取标题+内容中的关键词
  6932. $data['keyword'] = $data['title'];
  6933. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6934. Jieba::init(); // 初始化 jieba-php
  6935. Finalseg::init();
  6936. $segList = Jieba::cut($data['keyword']);
  6937. $segList1 = array_slice($segList, 0, 8);
  6938. $data['keyword'] = implode(',', $segList1);
  6939. }
  6940. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6941. //提取内容中的描述
  6942. $content = $data['content'];
  6943. // 去除 <style> 和 <script> 标签及其内容
  6944. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6945. // 去除所有 HTML 标签
  6946. $content = strip_tags($content);
  6947. // 去除 HTML 实体
  6948. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6949. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6950. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6951. // 去除多余空白
  6952. $content = preg_replace('/\s+/u', '', $content);
  6953. // 截取 100 个字符
  6954. $data['introduce'] = mb_substr($content, 0, 100);
  6955. }
  6956. $user = User::where('id', $data['user_id'])->first();
  6957. if (empty($user)) {
  6958. return Result::error('用户不存在!');
  6959. }
  6960. if ($user['type_id'] == 10000) {
  6961. $data['status'] = 1;
  6962. }
  6963. if (isset($data['level']) && $data['level'] != null) {
  6964. $data['level'] = intval($data['level']);
  6965. } else {
  6966. $data['level'] = null;
  6967. }
  6968. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6969. $this->sendMessage([
  6970. 'talk_type' => 900,
  6971. 'title' => $data['title'],
  6972. 'content' => '提交了审核',
  6973. 'messageType' => 8,
  6974. ]);
  6975. }
  6976. $result = Company::insertGetId($data);
  6977. if ($result) {
  6978. return Result::success($result);
  6979. } else {
  6980. return Result::error('添加失败');
  6981. }
  6982. }
  6983. /**
  6984. * 更新企业
  6985. * @param array $data
  6986. * @return array
  6987. */
  6988. public function upCompany(array $data): array
  6989. {
  6990. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6991. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6992. $data['cat_arr_id'] = json_encode($car_arr_id);
  6993. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6994. } else {
  6995. $data['cat_arr_id'] = '';
  6996. }
  6997. if ($data['imgurl'] == '') {
  6998. //content中提取图片第一个图,正则提取
  6999. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7000. preg_match_all($reg, $data['content'], $matches);
  7001. if (isset($matches[1][0])) {
  7002. //截取varchar
  7003. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7004. }
  7005. }
  7006. if ($data['keyword'] == '') {
  7007. //提取标题+内容中的关键词
  7008. $data['keyword'] = $data['title'];
  7009. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7010. Jieba::init(); // 初始化 jieba-php
  7011. Finalseg::init();
  7012. $segList = Jieba::cut($data['keyword']);
  7013. $segList1 = array_slice($segList, 0, 8);
  7014. $data['keyword'] = implode(',', $segList1);
  7015. }
  7016. if ($data['introduce'] == '') {
  7017. //提取内容中的描述
  7018. $content = $data['content'];
  7019. // 去除 <style> 和 <script> 标签及其内容
  7020. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7021. // 去除所有 HTML 标签
  7022. $content = strip_tags($content);
  7023. // 去除 HTML 实体
  7024. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7025. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7026. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7027. // 去除多余空白
  7028. $content = preg_replace('/\s+/u', '', $content);
  7029. // 截取 100 个字符
  7030. $data['introduce'] = mb_substr($content, 0, 100);
  7031. }
  7032. if (isset($data['level']) && $data['level'] != null) {
  7033. $data['level'] = intval($data['level']);
  7034. } else {
  7035. $data['level'] = null;
  7036. }
  7037. $user = User::where('id', $data['user_id'])->first();
  7038. if (empty($user)) {
  7039. return Result::error('用户不存在!');
  7040. }
  7041. if ($user['type_id'] == 10000) {
  7042. $data['status'] = 1;
  7043. } else {
  7044. $data['status'] = 0;
  7045. }
  7046. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7047. $this->sendMessage([
  7048. 'talk_type' => 900,
  7049. 'title' => $data['title'],
  7050. 'content' => '提交了审核',
  7051. 'messageType' => 8,
  7052. ]);
  7053. }
  7054. $result = Company::where('id', $data['id'])->update($data);
  7055. if ($result) {
  7056. return Result::success($result);
  7057. } else {
  7058. return Result::error('修改失败');
  7059. }
  7060. }
  7061. /**
  7062. * 删除企业
  7063. * @param array $data
  7064. * @return array
  7065. */
  7066. public function delCompany(array $data): array
  7067. {
  7068. $result = Company::where('id', $data['id'])->delete();
  7069. if ($result) {
  7070. return Result::success($result);
  7071. } else {
  7072. return Result::error('删除失败');
  7073. }
  7074. }
  7075. /**
  7076. * 审核企业
  7077. * @param array $data
  7078. * @return array
  7079. */
  7080. public function checkCompany(array $data): array
  7081. {
  7082. $user = User::where('id', $data['user_id'])->first();
  7083. if (empty($user)) {
  7084. return Result::error('用户不存在!');
  7085. }
  7086. $company = Company::where('id', $data['id'])->first();
  7087. if (empty($company)) {
  7088. return Result::error('企业不存在!');
  7089. }
  7090. // 状态:0:未审核 1:已审核 2:已拒绝
  7091. if ($data['status'] == 2 || $data['status'] == '2') {
  7092. $this->sendMessage([
  7093. 'talk_type' => 901,
  7094. 'title' => $company['title'],
  7095. 'content' => '审核拒绝',
  7096. 'messageType' => 8,
  7097. 'user_id' => $company['user_id'],
  7098. ]);
  7099. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7100. } else {
  7101. if ($data['status'] == 1) {
  7102. $this->sendMessage([
  7103. 'talk_type' => 901,
  7104. 'title' => $company['title'],
  7105. 'content' => '审核通过',
  7106. 'messageType' => 8,
  7107. 'user_id' => $company['user_id'],
  7108. ]);
  7109. } else if ($data['status'] == 0) {
  7110. $this->sendMessage([
  7111. 'talk_type' => 900,
  7112. 'title' => $company['title'],
  7113. 'content' => '提交了审核',
  7114. 'messageType' => 8,
  7115. ]);
  7116. }
  7117. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7118. }
  7119. if (empty($result)) {
  7120. return Result::error('审核失败!');
  7121. } else {
  7122. return Result::success($result);
  7123. }
  7124. }
  7125. /**
  7126. * 获取企业信息
  7127. * @param array $data
  7128. * @return array
  7129. */
  7130. public function getCompanyInfo(array $data): array
  7131. {
  7132. $result = Company::where('id', $data['id'])->first();
  7133. $city_arr = json_decode($result['city_arr_id']);
  7134. $result['city_name'] = District::whereIn('id', $city_arr)
  7135. ->pluck('name')
  7136. ->implode('-');
  7137. if (empty($result)) {
  7138. return Result::error('企业不存在!');
  7139. } else {
  7140. return Result::success($result);
  7141. }
  7142. }
  7143. /**
  7144. * @param array $data
  7145. * @return array
  7146. */
  7147. public function getWebsiteCompany(array $data): array
  7148. {
  7149. $categorys = json_decode($data['id'], true);
  7150. $category_arr = $this->processArticlePro($data['website_id']);
  7151. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7152. $catiall = $category_arr['catiall'];
  7153. $categoryIds = $category_arr['categoryIds'];
  7154. // return Result::success($category_arr);
  7155. foreach ($categorys as $key => $value) {
  7156. if (array_key_exists('level', $value)) {
  7157. $parts = explode(',', $value['level']);
  7158. $level = $parts[0] ?? null;
  7159. $imgnum = $parts[1] ?? null;
  7160. $textnum = $parts[2] ?? null;
  7161. if (!empty($textnum) && $textnum > 0) {
  7162. $text_num = Company::where('level', $level)
  7163. ->whereIn('category_id', $categoryIds)
  7164. ->where('status', 1)
  7165. ->select(
  7166. 'company.id',
  7167. 'company.title',
  7168. 'company.description',
  7169. 'company.updated_at',
  7170. 'company.category_id',
  7171. 'company.cat_arr_id'
  7172. )
  7173. ->orderBy('updated_at', 'desc')
  7174. ->limit($textnum)
  7175. ->get()->all();
  7176. }
  7177. if (!empty($imgnum) && $imgnum > 0) {
  7178. $img_num = Company::where('level', $level)
  7179. ->whereIn('category_id', $categoryIds)
  7180. ->where('status', 1)
  7181. ->where('imgurl', '!=', '')
  7182. ->whereNotNull('imgurl')
  7183. ->select(
  7184. 'company.id',
  7185. 'company.title',
  7186. 'company.description',
  7187. 'company.updated_at',
  7188. 'company.imgurl as imgs',
  7189. 'company.category_id',
  7190. 'company.cat_arr_id'
  7191. )
  7192. ->orderBy('updated_at', 'desc')
  7193. ->limit($imgnum)
  7194. ->get()->all();
  7195. }
  7196. }
  7197. if (array_key_exists('id', $value)) {
  7198. $parts = explode(',', $value['id']);
  7199. $category_id = $parts[0] ?? null;
  7200. $imgnum = $parts[1] ?? null;
  7201. $textnum = $parts[2] ?? null;
  7202. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7203. if (!empty($textnum) && $textnum > 0) {
  7204. $text_num = Company::whereIn('category_id', $category_arr)
  7205. // ->where('website_id', $data['website_id'])
  7206. ->where('status', 1)
  7207. ->select(
  7208. 'company.id',
  7209. 'company.title',
  7210. 'company.description',
  7211. 'company.updated_at',
  7212. 'company.category_id',
  7213. 'company.cat_arr_id'
  7214. )
  7215. ->orderBy('updated_at', 'desc')
  7216. ->limit($textnum)
  7217. ->get()->all();
  7218. }
  7219. if (!empty($imgnum) && $imgnum > 0) {
  7220. $img_num = Company::whereIn('category_id', $category_arr)
  7221. // ->where('website_id', $data['website_id'])
  7222. ->where('status', 1)
  7223. ->where('imgurl', '!=', '')
  7224. ->whereNotNull('imgurl')
  7225. ->select(
  7226. 'company.id',
  7227. 'company.title',
  7228. 'company.description',
  7229. 'company.updated_at',
  7230. 'company.imgurl as imgs',
  7231. 'company.category_id',
  7232. 'company.cat_arr_id'
  7233. )
  7234. ->orderBy('updated_at', 'desc')
  7235. ->limit($imgnum)
  7236. ->get()->all();
  7237. }
  7238. }
  7239. if (!empty($text_num)) {
  7240. foreach ($text_num as $k => $v) {
  7241. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7242. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7243. }
  7244. }
  7245. if (!empty($img_num)) {
  7246. foreach ($img_num as $k => $v) {
  7247. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7248. $imgurl = json_decode($v['imgs'], true);
  7249. if (!empty($imgurl)) {
  7250. $img_num[$k]->imgurl = $imgurl[0];
  7251. }
  7252. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7253. }
  7254. }
  7255. $company[$key]['img_num'] = $img_num ?? [];
  7256. $company[$key]['text_num'] = $text_num ?? [];
  7257. }
  7258. if (empty($company)) {
  7259. return Result::error("暂无相关企业信息", 0);
  7260. }
  7261. return Result::success($company);
  7262. }
  7263. /**
  7264. * @param array $data
  7265. * @return array
  7266. */
  7267. public function getWebsiteCompanyList(array $data): array
  7268. {
  7269. $where['website_id'] = $data['website_id'];
  7270. $where['status'] = 1;
  7271. $categoryIds = [];
  7272. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7273. $category_id = $data['category_id'];
  7274. }
  7275. $category_arr = $this->processArticlePro($data['website_id']);
  7276. $categoryIds = $category_arr['categoryIds'];
  7277. // return Result::success($cat_1st_arr);
  7278. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7279. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7280. })
  7281. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7282. $query->whereIn('category_id', $categoryIds);
  7283. })
  7284. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7285. $query->where('category_id', $category_id);
  7286. })
  7287. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7288. ->orderBy('updated_at', 'desc')
  7289. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7290. if (empty($company)) {
  7291. return Result::error("暂无相关公司信息", 0);
  7292. }
  7293. $result = [
  7294. 'count' => $company->total(),
  7295. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7296. ];
  7297. return Result::success($result);
  7298. }
  7299. /**
  7300. * 获取项目列表
  7301. * @param array $data
  7302. * @return array
  7303. */
  7304. public function getProjectList(array $data): array
  7305. {
  7306. $where = [];
  7307. $user = User::where('id', $data['user_id'])->first();
  7308. if (empty($user)) {
  7309. return Result::error('用户不存在!');
  7310. }
  7311. if ($user->type_id != 10000) {
  7312. array_push($where, ['project.user_id', $data['user_id']]);
  7313. }
  7314. $query = Project::query();
  7315. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7316. array_push($where, ['project.website_id', $data['website_id']]);
  7317. }
  7318. if (isset($data['title']) && !empty($data['title'])) {
  7319. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7320. }
  7321. if ($data['status'] != 3) {
  7322. array_push($where, ['project.status', $data['status']]);
  7323. }
  7324. $query = Project::where($where)
  7325. ->when($data['status'] == 3, function ($query) {
  7326. $query->whereIn('project.status', [0, 2]);
  7327. });
  7328. $count = $query->clone()
  7329. ->count();
  7330. $rows = $query->clone()
  7331. ->leftJoin('website', 'project.website_id', 'website.id')
  7332. ->leftJoin('website_category', function ($join) {
  7333. $join->on('project.website_id', '=', 'website_category.website_id')
  7334. ->on('project.category_id', '=', 'website_category.category_id');
  7335. })
  7336. ->select(
  7337. 'project.id',
  7338. 'project.title',
  7339. 'project.updated_at',
  7340. 'project.status',
  7341. 'website.website_name',
  7342. 'website_category.alias as category_name',
  7343. 'project.website_id',
  7344. 'project.user_id'
  7345. )
  7346. ->orderBy('project.updated_at', 'desc')
  7347. ->offset(($data['page'] - 1) * $data['pageSize'])
  7348. ->limit($data['pageSize'])
  7349. ->get();
  7350. if ($rows->isEmpty()) {
  7351. return Result::error("暂无相关项目信息", 0);
  7352. }
  7353. $result = [
  7354. 'count' => $count,
  7355. 'rows' => $rows,
  7356. ];
  7357. return Result::success($result);
  7358. }
  7359. /**
  7360. * 添加项目
  7361. * @param array $data
  7362. * @return array
  7363. */
  7364. public function addProject(array $data): array
  7365. {
  7366. $user = User::where('id', $data['user_id'])->first();
  7367. if (empty($user)) {
  7368. return Result::error("暂无相关用户信息", 0);
  7369. }
  7370. if ($user->type_id == 10000) {
  7371. $data['status'] = 1;
  7372. } else {
  7373. $data['status'] = 0;
  7374. }
  7375. if ($data['keyword'] == '') {
  7376. //提取标题+内容中的关键词
  7377. $data['keyword'] = $data['title'];
  7378. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7379. Jieba::init(); // 初始化 jieba-php
  7380. Finalseg::init();
  7381. $segList = Jieba::cut($data['keyword']);
  7382. $segList1 = array_slice($segList, 0, 8);
  7383. $data['keyword'] = implode(',', $segList1);
  7384. }
  7385. if ($data['description'] == '') {
  7386. //提取内容中的描述
  7387. // var_dump(11111);
  7388. //提取内容中的描述
  7389. $content = $data['introduce'];
  7390. // 去除 <style> 和 <script> 标签及其内容
  7391. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7392. // 去除所有 HTML 标签
  7393. $content = strip_tags($content);
  7394. // 去除 HTML 实体
  7395. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7396. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7397. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7398. // 去除多余空白
  7399. $content = preg_replace('/\s+/u', '', $content);
  7400. // 截取 100 个字符
  7401. $data['description'] = mb_substr($content, 0, 100);
  7402. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7403. }
  7404. if ($data['status'] == 0) {
  7405. $this->sendMessage([
  7406. 'talk_type' => 1000,
  7407. 'title' => $data['title'],
  7408. 'content' => '提交了审核',
  7409. 'messageType' => 9,
  7410. ]);
  7411. }
  7412. $project = Project::insertGetId($data);
  7413. if (empty($project)) {
  7414. return Result::error("暂无相关项目信息", 0);
  7415. }
  7416. return Result::success($project);
  7417. }
  7418. /**
  7419. * 更新项目
  7420. * @param array $data
  7421. * @return array
  7422. */
  7423. public function upProject(array $data): array
  7424. {
  7425. $project = Project::where('id', $data['id'])->first();
  7426. if (empty($project)) {
  7427. return Result::error("暂无相关项目信息", 0);
  7428. }
  7429. $id = $data['id'];
  7430. unset($data['id']);
  7431. $user = User::where('id', $data['user_id'])->first();
  7432. if (empty($user)) {
  7433. return Result::error("暂无相关用户信息", 0);
  7434. }
  7435. if ($user->type_id == 10000) {
  7436. $data['status'] = 1;
  7437. } else {
  7438. $data['status'] = 0;
  7439. }
  7440. unset($data['user_id']);
  7441. if ($data['keyword'] == '') {
  7442. //提取标题+内容中的关键词
  7443. $data['keyword'] = $data['title'];
  7444. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7445. Jieba::init(); // 初始化 jieba-php
  7446. Finalseg::init();
  7447. $segList = Jieba::cut($data['keyword']);
  7448. $segList1 = array_slice($segList, 0, 8);
  7449. $data['keyword'] = implode(',', $segList1);
  7450. }
  7451. if ($data['description'] == '') {
  7452. //提取内容中的描述
  7453. // var_dump(11111);
  7454. //提取内容中的描述
  7455. $content = $data['introduce'];
  7456. // 去除 <style> 和 <script> 标签及其内容
  7457. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7458. // 去除所有 HTML 标签
  7459. $content = strip_tags($content);
  7460. // 去除 HTML 实体
  7461. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7462. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7463. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7464. // 去除多余空白
  7465. $content = preg_replace('/\s+/u', '', $content);
  7466. // 截取 100 个字符
  7467. $data['description'] = mb_substr($content, 0, 100);
  7468. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7469. }
  7470. if ($data['status'] == 0) {
  7471. $this->sendMessage([
  7472. 'talk_type' => 1000,
  7473. 'title' => $data['title'],
  7474. 'content' => '提交了审核',
  7475. 'messageType' => 9,
  7476. ]);
  7477. }
  7478. $result = Project::where('id', $id)->update($data);
  7479. if (empty($result)) {
  7480. return Result::error("更新失败", 0);
  7481. }
  7482. return Result::success($result);
  7483. }
  7484. /**
  7485. * 删除项目
  7486. * @param array $data
  7487. * @return array
  7488. */
  7489. public function delProject(array $data): array
  7490. {
  7491. $user = User::where('id', $data['user_id'])->first();
  7492. if (empty($user)) {
  7493. return Result::error("暂无相关用户信息", 0);
  7494. }
  7495. $project = Project::where('id', $data['id'])->first();
  7496. if (empty($project)) {
  7497. return Result::error("暂无相关项目信息", 0);
  7498. }
  7499. $result = Project::where('id', $data['id'])->delete();
  7500. if (empty($result)) {
  7501. return Result::error("删除失败", 0);
  7502. }
  7503. return Result::success($result);
  7504. }
  7505. /**
  7506. * 审核项目
  7507. * @param array $data
  7508. * @return array
  7509. */
  7510. public function checkProject(array $data): array
  7511. {
  7512. $user = User::where('id', $data['user_id'])->first();
  7513. if (empty($user)) {
  7514. return Result::error("暂无相关用户信息", 0);
  7515. }
  7516. // 0:未审核; 1:已审核; 2:已拒绝;
  7517. if ($user->type_id != 10000) {
  7518. if ($data['status'] == 1 || $data['status'] == 2) {
  7519. return Result::error("此用户权限不足", 0);
  7520. }
  7521. }
  7522. $project = Project::where('id', $data['id'])->first();
  7523. if (empty($project)) {
  7524. return Result::error("暂无相关项目信息", 0);
  7525. }
  7526. if ($data['status'] == 2) {
  7527. $this->sendMessage([
  7528. 'talk_type' => 1001,
  7529. 'title' => $project['title'],
  7530. 'content' => '审核拒绝',
  7531. 'messageType' => 9,
  7532. 'user_id' => $project['user_id'],
  7533. ]);
  7534. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7535. } else {
  7536. if ($data['status'] == 1) {
  7537. $this->sendMessage([
  7538. 'talk_type' => 1001,
  7539. 'title' => $project['title'],
  7540. 'content' => '审核通过',
  7541. 'messageType' => 9,
  7542. 'user_id' => $project['user_id'],
  7543. ]);
  7544. } else if ($data['status'] == 0) {
  7545. $this->sendMessage([
  7546. 'talk_type' => 1000,
  7547. 'title' => $project['title'],
  7548. 'content' => '提交了审核',
  7549. 'messageType' => 9,
  7550. ]);
  7551. }
  7552. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7553. }
  7554. if (empty($result)) {
  7555. return Result::error("审核失败", 0);
  7556. }
  7557. return Result::success($result);
  7558. }
  7559. /**
  7560. * 获取项目详情
  7561. * @param array $data
  7562. * @return array
  7563. */
  7564. public function getProjectInfo(array $data): array
  7565. {
  7566. $project = Project::where('id', $data['id'])->first();
  7567. if (empty($project)) {
  7568. return Result::error("暂无相关项目信息", 0);
  7569. }
  7570. return Result::success($project);
  7571. }
  7572. public function getWebsiteCompanyInfo(array $data): array
  7573. {
  7574. $company = Company::where('id', $data['id'])
  7575. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7576. ->where('status', 1)
  7577. // ->where('website_id', $data['website_id'])
  7578. ->select('company.*', 'job_industry.hyname as hy_name')
  7579. ->first();
  7580. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7581. switch ($company->jobnature_id) {
  7582. case null:
  7583. $company->jobnature_name = '';
  7584. break;
  7585. case 0:
  7586. $company->jobnature_name = '市场监督';
  7587. break;
  7588. case 1:
  7589. $company->jobnature_name = '信访纪检';
  7590. break;
  7591. case 2:
  7592. $company->jobnature_name = '公检法司';
  7593. break;
  7594. case 3:
  7595. $company->jobnature_name = '高关注机构';
  7596. break;
  7597. default:
  7598. $company->jobnature_name = '';
  7599. break;
  7600. }
  7601. $city_arr = $company->city_arr_id;
  7602. if (!empty($city_arr)) {
  7603. $city_arr = json_decode($city_arr, true);
  7604. $cityNames = District::whereIn('id', $city_arr)
  7605. ->pluck('name')
  7606. ->implode('-');
  7607. $company->city_name = $cityNames;
  7608. } else {
  7609. $company->city_name = '';
  7610. }
  7611. if (empty($company)) {
  7612. return Result::error("暂无相关公司信息", 0);
  7613. }
  7614. return Result::success($company);
  7615. }
  7616. public function getMSG(array $data): array
  7617. {
  7618. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7619. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7620. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7621. $result = [];
  7622. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7623. //最近的5篇已审的文章
  7624. $apply_articale = Article::where('status', 1)
  7625. ->where('admin_user_id', $user_id)
  7626. ->orderBy('updated_at', 'desc')
  7627. // ->limit(5)
  7628. ->get();
  7629. //获取5条用户的已审核商品
  7630. $good = Good::where('status', 2)
  7631. ->where('user_id', $user_id)
  7632. ->orderBy('updated_at', 'desc')
  7633. // ->limit(5)
  7634. ->get();
  7635. //获取5条用户待审核的公告
  7636. $notice = Notice::where('status', 2)
  7637. ->where('user_id', $user_id)
  7638. ->orderBy('updated_at', 'desc')
  7639. ->limit(5)->get();
  7640. //获取5条用户的待审核投诉
  7641. $complaint = Complaint::where('status', 2)
  7642. ->where('user_id', $user_id)
  7643. ->orderBy('updated_at', 'desc')
  7644. // ->limit(5)
  7645. ->get();
  7646. //获取5条用户的book
  7647. $book = Book::where('status', 2)
  7648. ->where('user_id', $user_id)
  7649. ->orderBy('updated_at', 'desc')
  7650. // ->limit(5)
  7651. ->get();
  7652. //获取5条用户的求职
  7653. //获取5条用户的求职 1
  7654. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7655. ->where('job_hunting.user_id', $user_id)
  7656. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7657. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7658. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7659. ->orderBy('updated_at', 'desc')
  7660. // ->limit(5)
  7661. ->get();
  7662. //获取5条用户的求职 2
  7663. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7664. ->where('job_recruiting.user_id', $user_id)
  7665. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7666. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7667. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7668. ->orderBy('updated_at', 'desc')
  7669. // ->limit(5)
  7670. ->get();
  7671. //人才库 1
  7672. $job_apply = JobApply::where('job_apply.status', 1)
  7673. ->where('job_apply.receiver_id', $user_id)
  7674. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7675. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7676. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7677. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7678. ->select('job_recruiting', 'job_recruiting.', '', '')
  7679. ->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')
  7680. ->orderBy('updated_at', 'desc')
  7681. // ->limit(5)
  7682. ->get();
  7683. // 职场机会 2
  7684. $job_resume = JobResume::where('job_resume.status', 1)
  7685. ->where('job_resume.receiver_id', $user_id)
  7686. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7687. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7688. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7689. ->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')
  7690. ->orderBy('updated_at', 'desc')
  7691. // ->limit(5)
  7692. ->get();
  7693. //获取5条用户待处理的投诉
  7694. $complaint_deal = Complaint::where('status', 2)
  7695. ->where('deal', 1)
  7696. ->whereJsonContains('re_user_ids', $user_id)
  7697. ->orderBy('updated_at', 'desc')
  7698. // ->limit(5)
  7699. ->get();
  7700. //获取 被通知者未读信息
  7701. $notice_unread = Notice::where('status', 2)
  7702. ->whereJsonContains('re_user_ids', $user_id)
  7703. //未读消息
  7704. ->where(function ($query) use ($user_id) {
  7705. $query->whereJsonDoesntContain('read_id', $user_id)
  7706. ->orWhereNull('read_id');
  7707. })
  7708. ->orderBy('updated_at', 'desc')
  7709. ->get();
  7710. $complaint_unread = Complaint::where('status', 2)
  7711. ->whereJsonContains('re_user_ids', $user_id)
  7712. //未读消息
  7713. ->where(function ($query) use ($user_id) {
  7714. $query->whereJsonDoesntContain('read_id', $user_id)
  7715. ->orWhereNull('read_id');
  7716. })
  7717. ->orderBy('updated_at', 'desc')
  7718. ->get();
  7719. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7720. $complany = Company::where('status', 1)
  7721. ->where('user_id', $user_id)
  7722. ->orderBy('updated_at', 'desc')
  7723. // ->limit(5)
  7724. ->get();
  7725. //获取5条单聊未读聊天消息
  7726. // $chat = ChatRecords::where('is_read', 0)
  7727. // ->where('user_id', $user_id)
  7728. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7729. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7730. // ->where('action', 'recieved')
  7731. // ->where('talk_type', 1)
  7732. // ->orderBy('created_at', 'desc')
  7733. // // ->limit(5)
  7734. // ->get();
  7735. //获取5条未读群聊信息
  7736. // $chat_group = ChatRecords::where('is_read', 0)
  7737. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7738. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7739. // ->where('user_id', $user_id)
  7740. // ->where('talk_type', 2)
  7741. // ->orderBy('created_at', 'desc')
  7742. // // ->limit(5)
  7743. // ->get();
  7744. //获取5条用户的待审核项目
  7745. $project = Project::where('status', 1)
  7746. ->where('user_id', $user_id)
  7747. ->orderBy('updated_at', 'desc')
  7748. // ->limit(5)
  7749. ->get();
  7750. // count($chat) + count($chat_group) +
  7751. $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)
  7752. + count($complany)
  7753. + count($project)
  7754. + count($notice_unread)
  7755. + count($complaint_unread)
  7756. // + count($chat) + count($chat_group)
  7757. ;
  7758. $result = [
  7759. 'apply_articale' => $apply_articale,
  7760. // 'chat' => $chat,
  7761. // 'chat_group' => $chat_group,
  7762. 'good' => $good,
  7763. 'notice' => $notice,
  7764. 'complaint' => $complaint,
  7765. 'book' => $book,
  7766. 'job_hunting' => $job_hunting,
  7767. 'job_recruiting' => $job_recruiting,
  7768. 'job_apply' => $job_apply,
  7769. 'job_resume' => $job_resume,
  7770. 'complaint_deal' => $complaint_deal,
  7771. 'complany' => $complany,
  7772. 'project' => $project,
  7773. 'notice_unread' => $notice_unread,
  7774. 'complaint_unread' => $complaint_unread,
  7775. 'count' => $count,
  7776. ];
  7777. } elseif ($type_id == 12) {
  7778. //最近的5篇已审的文章
  7779. $apply_articale = Article::where('status', 1)
  7780. ->where('admin_user_id', $user_id)
  7781. ->limit(5)->get();
  7782. //获取5条单聊未读聊天消息
  7783. $chat = ChatRecords::where('is_read', 0)
  7784. ->where('user_id', $user_id)
  7785. ->where('talk_type', 1)
  7786. ->orderBy('created_at', 'desc')
  7787. ->limit(5)->get();
  7788. //获取5条未读群聊信息
  7789. $chat_group = ChatRecords::where('is_read', 0)
  7790. ->where('user_id', $user_id)
  7791. ->where('talk_type', 2)
  7792. ->orderBy('created_at', 'desc')
  7793. ->limit(5)->get();
  7794. //获取5条用户的已审核商品
  7795. $good = Good::where('status', 2)
  7796. ->where('user_id', $user_id)
  7797. ->orderBy('updated_at', 'desc')
  7798. ->limit(5)->get();
  7799. //获取5条用户的book
  7800. $book = Book::where('status', 2)
  7801. ->where('user_id', $user_id)
  7802. ->orderBy('updated_at', 'desc')
  7803. ->limit(5)->get();
  7804. //获取5条用户的求职
  7805. //获取5条用户的求职 1
  7806. //count($chat) + count($chat_group)
  7807. $count = count($apply_articale) + count($good);
  7808. $result = [
  7809. 'apply_articale' => $apply_articale,
  7810. 'chat' => $chat,
  7811. 'chat_group' => $chat_group,
  7812. 'good' => $good,
  7813. 'book' => $book,
  7814. 'count' => $count,
  7815. ];
  7816. } elseif ($type_id == 13) {
  7817. //最近的5篇已审的文章
  7818. $apply_articale = Article::where('status', 1)
  7819. ->where('admin_user_id', $user_id)
  7820. ->limit(5)->get();
  7821. //获取5条单聊未读聊天消息
  7822. $chat = ChatRecords::where('is_read', 0)
  7823. ->where('user_id', $user_id)
  7824. ->where('talk_type', 1)
  7825. ->orderBy('created_at', 'desc')
  7826. ->limit(5)->get();
  7827. //获取5条未读群聊信息
  7828. $chat_group = ChatRecords::where('is_read', 0)
  7829. ->where('user_id', $user_id)
  7830. ->where('talk_type', 2)
  7831. ->orderBy('created_at', 'desc')
  7832. ->limit(5)->get();
  7833. //获取5条用户的已审核商品
  7834. $good = Good::where('status', 2)
  7835. ->where('user_id', $user_id)
  7836. ->orderBy('updated_at', 'desc')
  7837. ->limit(5)->get();
  7838. //count($chat) + count($chat_group) +
  7839. $count = count($apply_articale) + count($good);
  7840. $result = [
  7841. 'apply_articale' => $apply_articale,
  7842. 'chat' => $chat,
  7843. 'chat_group' => $chat_group,
  7844. 'good' => $good,
  7845. 'count' => $count,
  7846. ];
  7847. } elseif ($type_id == 14) {
  7848. //最近的5篇已审的文章
  7849. $apply_articale = Article::where('status', 1)
  7850. ->where('admin_user_id', $user_id)
  7851. // ->limit(5)
  7852. ->get();
  7853. //获取5条用户的已审核商品
  7854. $good = Good::where('status', 2)
  7855. ->where('user_id', $user_id)
  7856. ->orderBy('updated_at', 'desc')
  7857. // ->limit(5)
  7858. ->get();
  7859. $count = count($apply_articale) + count($good);
  7860. $result = [
  7861. 'apply_articale' => $apply_articale,
  7862. 'chat' => '',
  7863. 'chat_group' => '',
  7864. 'good' => $good,
  7865. 'count' => $count,
  7866. ];
  7867. } elseif ($type_id == 10000) {
  7868. //获取未审核的5篇文章
  7869. $apply_articale = Article::where('status', 0)
  7870. ->orderBy('updated_at', 'desc')
  7871. // ->limit(5)
  7872. ->get();
  7873. //获取5条单聊未读聊天消息
  7874. //获取5条单聊未读聊天消息
  7875. // $chat = ChatRecords::where('is_read', 0)
  7876. // ->where('user_id', $user_id)
  7877. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7878. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7879. // ->where('action', 'recieved')
  7880. // ->where('talk_type', 1)
  7881. // ->orderBy('created_at', 'desc')
  7882. // // ->limit(5)
  7883. // ->get();
  7884. // //获取5条未读群聊信息
  7885. // $chat_group = ChatRecords::where('is_read', 0)
  7886. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7887. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7888. // ->where('user_id', $user_id)
  7889. // ->where('talk_type', 2)
  7890. // ->orderBy('created_at', 'desc')
  7891. // // ->limit(5)
  7892. // ->get();
  7893. //获取5条用户的已审核商品
  7894. $good = Good::where('status', 1)
  7895. // ->where('user_id', $user_id)
  7896. ->orderBy('updated_at', 'desc')
  7897. // ->limit(5)
  7898. ->get();
  7899. //获取5条用户待审核的公告
  7900. $notice = Notice::where('status', 1)
  7901. ->orderBy('updated_at', 'desc')
  7902. // ->limit(5)
  7903. ->get();
  7904. //获取5条用户的待审核投诉
  7905. $complaint = Complaint::where('status', 1)
  7906. ->orderBy('updated_at', 'desc')
  7907. // ->limit(5)
  7908. ->get();
  7909. //获取5条用户的book
  7910. $book = Book::where('status', 1)
  7911. ->orderBy('updated_at', 'desc')
  7912. // ->limit(5)
  7913. ->get();
  7914. //获取5条用户的求职 1
  7915. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7916. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7917. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7918. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7919. ->orderBy('updated_at', 'desc')
  7920. // ->limit(5)
  7921. ->get();
  7922. //获取5条用户的求职 2
  7923. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7924. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7925. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7926. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7927. ->orderBy('updated_at', 'desc')
  7928. // ->limit(5)
  7929. ->get();
  7930. //人才库 1
  7931. $job_apply = JobApply::where('job_apply.status', 1)
  7932. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7933. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7934. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7935. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7936. ->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')
  7937. ->orderBy('updated_at', 'desc')
  7938. // ->limit(5)
  7939. ->get();
  7940. // 职场机会 2
  7941. $job_resume = JobResume::where('job_resume.status', 1)
  7942. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7943. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7944. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7945. ->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')
  7946. ->orderBy('updated_at', 'desc')
  7947. // ->limit(5)
  7948. ->get();
  7949. //待审核数据com pro
  7950. $complany = Company::where('status', 0)
  7951. ->orderBy('updated_at', 'desc')
  7952. // ->limit(5)
  7953. ->get();
  7954. $project = Project::where('status', 0)
  7955. ->orderBy('updated_at', 'desc')
  7956. // ->limit(5)
  7957. ->get();
  7958. $count =
  7959. // count($chat) +
  7960. // count($chat_group) +
  7961. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7962. // + count($job_apply)
  7963. // + count($job_resume)
  7964. + count($complany)
  7965. + count($project);
  7966. $result = [
  7967. 'apply_articale' => $apply_articale,
  7968. // 'chat' => $chat,
  7969. // 'chat_group' => $chat_group,
  7970. 'good' => $good,
  7971. 'notice' => $notice,
  7972. 'complaint' => $complaint,
  7973. 'book' => $book,
  7974. 'job_hunting' => $job_hunting,
  7975. 'job_recruiting' => $job_recruiting,
  7976. // 'job_apply' => $job_apply,
  7977. // 'job_resume' => $job_resume,
  7978. 'complany' => $complany,
  7979. 'project' => $project,
  7980. 'count' => $count,
  7981. ];
  7982. } elseif ($type_id == 20000) {
  7983. }
  7984. var_dump($type_id, '-----------------test---------');
  7985. return Result::success($result);
  7986. }
  7987. /**
  7988. * @param array $data
  7989. * @return array
  7990. */
  7991. public function getWebsiteProject(array $data): array
  7992. {
  7993. $categorys = json_decode($data['id'], true);
  7994. if (!empty($categorys)) {
  7995. $category_arr = $this->processArticlePro($data['website_id']);
  7996. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7997. $catiall = $category_arr['catiall'];
  7998. // return Result::success($catiall);
  7999. foreach ($categorys as $key => $val) {
  8000. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8001. $level = explode(',', $val['level'])[0];
  8002. $imgnum = explode(',', $val['level'])[1] ?? null;
  8003. $textnum = explode(',', $val['level'])[2] ?? null;
  8004. if ($level == 1) {
  8005. if (!empty($textnum) && $textnum > 0) {
  8006. $text_num = Project::where('level', $level)
  8007. ->where('website_id', $data['website_id'])
  8008. ->where('status', 1)
  8009. ->select(
  8010. 'project.id',
  8011. 'project.title',
  8012. 'project.description',
  8013. 'project.updated_at',
  8014. 'project.category_id',
  8015. 'project.cat_arr_id'
  8016. )
  8017. ->orderBy('updated_at', 'desc')
  8018. ->limit($textnum)
  8019. ->get()->all();
  8020. }
  8021. if (!empty($imgnum) && $imgnum > 0) {
  8022. $img_num = Project::where('level', $level)
  8023. ->where('website_id', $data['website_id'])
  8024. ->where('status', 1)
  8025. ->where('imgurl', '!=', '')
  8026. ->whereNotNull('imgurl')
  8027. ->select(
  8028. 'project.id',
  8029. 'project.title',
  8030. 'project.description',
  8031. 'project.updated_at',
  8032. 'project.imgurl as imgs',
  8033. 'project.category_id',
  8034. 'project.cat_arr_id'
  8035. )
  8036. ->orderBy('updated_at', 'desc')
  8037. ->limit($imgnum)
  8038. ->get()->all();
  8039. }
  8040. } else {
  8041. if (!empty($textnum) && $textnum > 0) {
  8042. $text_num = Project::where('website_id', $data['website_id'])
  8043. ->where('status', 1)
  8044. ->select(
  8045. 'project.id',
  8046. 'project.title',
  8047. 'project.description',
  8048. 'project.updated_at',
  8049. 'project.category_id',
  8050. 'project.cat_arr_id',
  8051. 'project.website_id',
  8052. 'project.updated_at',
  8053. 'project.created_at'
  8054. )
  8055. ->orderBy('updated_at', 'desc')
  8056. ->limit($textnum)
  8057. ->get()->all();
  8058. }
  8059. if (!empty($imgnum) && $imgnum > 0) {
  8060. $img_num = Project::where('website_id', $data['website_id'])
  8061. ->where('status', 1)
  8062. ->where('imgurl', '!=', '')
  8063. ->whereNotNull('imgurl')
  8064. ->select(
  8065. 'project.id',
  8066. 'project.title',
  8067. 'project.description',
  8068. 'project.updated_at',
  8069. 'project.imgurl as imgs',
  8070. 'project.category_id',
  8071. 'project.cat_arr_id'
  8072. )
  8073. ->orderBy('updated_at', 'desc')
  8074. ->limit($imgnum)
  8075. ->get()->all();
  8076. }
  8077. }
  8078. }
  8079. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8080. $category_ids = explode(',', $val['id'])[0];
  8081. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8082. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8083. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8084. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8085. $text_num = Project::whereIn('category_id', $category_arr)
  8086. ->where('website_id', $data['website_id'])
  8087. ->where('status', 1)
  8088. ->select(
  8089. 'project.id',
  8090. 'project.title',
  8091. 'project.description',
  8092. 'project.updated_at',
  8093. 'project.category_id',
  8094. 'project.cat_arr_id'
  8095. )
  8096. ->orderBy('updated_at', 'desc')
  8097. ->limit($cat_textnum)
  8098. ->get()->all();
  8099. }
  8100. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8101. $img_num = Project::whereIn('category_id', $category_arr)
  8102. ->where('website_id', $data['website_id'])
  8103. ->where('status', 1)
  8104. ->where('imgurl', '!=', '')
  8105. ->whereNotNull('imgurl')
  8106. ->select(
  8107. 'project.id',
  8108. 'project.title',
  8109. 'project.description',
  8110. 'project.updated_at',
  8111. 'project.imgurl as imgs',
  8112. 'project.category_id',
  8113. 'project.cat_arr_id'
  8114. )
  8115. ->orderBy('updated_at', 'desc')
  8116. ->limit($cat_imgnum)
  8117. ->get()->all();
  8118. }
  8119. }
  8120. if (!empty($img_num)) {
  8121. foreach ($img_num as $k => $v) {
  8122. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8123. $imgurl = json_decode($v['imgs'], true);
  8124. if (!empty($imgurl)) {
  8125. $img_num[$k]->imgurl = $imgurl[0];
  8126. }
  8127. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8128. }
  8129. }
  8130. if (!empty($text_num)) {
  8131. foreach ($text_num as $k => $v) {
  8132. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8133. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8134. }
  8135. }
  8136. $project[$key]['img_num'] = $img_num ?? [];
  8137. $project[$key]['text_num'] = $text_num ?? [];
  8138. }
  8139. }
  8140. if (empty($project)) {
  8141. return Result::error("暂无相关项目信息", 0);
  8142. }
  8143. return Result::success($project);
  8144. }
  8145. /**
  8146. * @param array $data
  8147. * @return array
  8148. */
  8149. public function getWebsiteProjectInfo(array $data): array
  8150. {
  8151. $project = Project::where('id', $data['id'])
  8152. ->where('status', 1)
  8153. ->where('website_id', $data['website_id'])
  8154. ->select('project.*')
  8155. ->first();
  8156. if (empty($project)) {
  8157. return Result::error("暂无相关项目信息", 0);
  8158. }
  8159. return Result::success($project);
  8160. }
  8161. /**
  8162. * @param array $data
  8163. * @return array
  8164. */
  8165. public function getWebsiteProjectList(array $data): array
  8166. {
  8167. $where = [];
  8168. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8169. $where['category_id'] = $data['category_id'];
  8170. }
  8171. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8172. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8173. }
  8174. $query = Project::where($where)
  8175. ->where('status', 1)
  8176. ->where('website_id', $data['website_id'])
  8177. ->select(
  8178. 'project.id',
  8179. 'project.title',
  8180. 'project.description',
  8181. 'project.imgurl as imgs',
  8182. 'project.category_id',
  8183. 'project.cat_arr_id'
  8184. )
  8185. ->orderBy('updated_at', 'desc');
  8186. $count = $query->count();
  8187. $project = $query->clone()
  8188. ->offset(($data['page'] - 1) * $data['pageSize'])
  8189. ->limit($data['pageSize'])
  8190. ->get()->all();
  8191. if (empty($project)) {
  8192. return Result::error("暂无相关项目信息", 0);
  8193. }
  8194. $categorys = $this->processArticlePro($data['website_id']);
  8195. $catiall = $categorys['catiall'];
  8196. foreach ($project as $key => $val) {
  8197. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8198. if (!empty($val['imgs'])) {
  8199. $imgurl = json_decode($val['imgs'], true);
  8200. if (!empty($imgurl)) {
  8201. $project[$key]->imgurl = $imgurl[0];
  8202. }
  8203. } else {
  8204. $project[$key]->imgurl = '';
  8205. }
  8206. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8207. }
  8208. $result = [
  8209. 'rows' => $project,
  8210. 'count' => $count,
  8211. ];
  8212. return Result::success($result);
  8213. }
  8214. /**
  8215. * @param array $data
  8216. * @return array
  8217. */
  8218. public function getWebsiteCategoryJob(array $data): array
  8219. {
  8220. $categorys = json_decode($data['id'], true);
  8221. if (!empty($categorys)) {
  8222. $category_arr = $this->processArticlePro($data['website_id']);
  8223. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8224. $catiall = $category_arr['catiall'];
  8225. foreach ($categorys as $key => $val) {
  8226. if (isset($val['id']) && !empty($val['id'])) {
  8227. $catid = explode(',', $val['id'])[0] ?? null;
  8228. $type = explode(',', $val['id'])[1] ?? null;
  8229. $textnum = explode(',', $val['id'])[2] ?? null;
  8230. }
  8231. // 4:招聘;5:求职;
  8232. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8233. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8234. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8235. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8236. ->where('job_recruiting.status', 1)
  8237. ->where('job_recruiting.website_id', $data['website_id'])
  8238. ->select(
  8239. 'job_recruiting.id',
  8240. 'job_recruiting.title',
  8241. 'job_company.business_name',
  8242. 'job_recruiting.updated_at',
  8243. 'job_recruiting.cat_arr_id',
  8244. 'job_recruiting.keyword',
  8245. 'job_recruiting.description'
  8246. )
  8247. ->orderBy('job_recruiting.updated_at', 'desc')
  8248. ->limit($textnum)
  8249. ->get()->all();
  8250. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8251. // 状态 审核状态,1待审核2已审核3已拒绝
  8252. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8253. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8254. ->where('job_hunting.status', 2)
  8255. ->where('job_hunting.website_id', $data['website_id'])
  8256. ->select(
  8257. 'job_hunting.id',
  8258. 'job_hunting.name',
  8259. 'job_hunting.cat_arr_id',
  8260. 'job_position.zwname as job_name',
  8261. 'job_hunting.updated_at',
  8262. 'job_hunting.keyword',
  8263. 'job_hunting.slelf_evaluation'
  8264. )
  8265. ->orderBy('updated_at', 'desc')
  8266. ->limit($textnum)
  8267. ->get()->all();
  8268. } else {
  8269. $job = [];
  8270. }
  8271. // var_dump($catid.'222uuuuuuu'.$key);
  8272. if (!empty($job)) {
  8273. foreach ($job as $k => $value) {
  8274. if (isset($value->cat_arr_id)) {
  8275. $catArr = json_decode($value->cat_arr_id, true);
  8276. $catId = end($catArr);
  8277. } else {
  8278. continue;
  8279. }
  8280. if (isset($catiall[$catId])) {
  8281. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8282. }
  8283. }
  8284. }
  8285. // var_dump($catid.'xxxxx'.$key);
  8286. $result[$key] = $job ?? [];
  8287. }
  8288. }
  8289. if (empty($result)) {
  8290. return Result::error("暂无相关分类信息", 0);
  8291. }
  8292. return Result::success($result);
  8293. }
  8294. /**
  8295. * 发送消息
  8296. * @param array $messageData
  8297. * @return void
  8298. */
  8299. public function sendMessage($messageData)
  8300. {
  8301. $msg = [
  8302. 'talk_type' => $messageData['talk_type'],
  8303. 'title' => $messageData['title'],
  8304. 'content' => $messageData['content'],
  8305. 'messageType' => $messageData['messageType'],
  8306. 'user_id' => $messageData['user_id'] ?? '',
  8307. 'time' => microtime(),
  8308. ];
  8309. $message = new MqProducer($msg);
  8310. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8311. $producer->produce($message);
  8312. }
  8313. }