NewsService.php 327 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902
  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. $startTime = microtime(true);
  396. $rep = Article::query()
  397. // 预加载相关关联
  398. ->with([
  399. 'category' => function ($query) {
  400. $query->select('id', 'name');
  401. },
  402. 'websiteCategory' => function ($query) {
  403. $query->select('website_id', 'category_id', 'alias');
  404. },'user' => function ($query) {
  405. $query->select('id', 'nickname');
  406. }
  407. ])
  408. // 构建where条件
  409. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  410. $query->where('article.id', '=', $data['id']);
  411. })
  412. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  413. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  414. })
  415. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  416. // 使用子查询替代左连接进行模糊搜索
  417. $query->whereHas('category', function ($subQuery) use ($data) {
  418. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  419. });
  420. })
  421. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  422. $query->where('article.catid', '=', $data['catid']);
  423. })
  424. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  425. $query->where('article.author', '=', $data['author']);
  426. })
  427. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  428. $query->where('article.islink', '=', $data['islink']);
  429. })
  430. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  431. $query->where('article.status', '=', $data['status']);
  432. })
  433. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  434. // 安全地处理JSON字符串
  435. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  436. if (!empty($status1)) {
  437. $query->whereIn('article.status', $status1);
  438. }
  439. })
  440. ->select('article.*')
  441. // 非管理员限制
  442. ->when($type_id != 10000, function ($query) use ($user_id) {
  443. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  444. $query->where('article.admin_user_id', $user_id)
  445. ->leftJoin('article_ignore', function ($join) {
  446. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  447. $join->on('article_ignore.article_id', '=', 'article.id')
  448. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  449. })
  450. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  451. })
  452. // 基础条件
  453. ->whereNotIn('article.status', [404])
  454. // 排序和分页
  455. ->orderBy('article.updated_at', 'desc')
  456. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  457. // 获取结果并格式化
  458. $data = [
  459. 'rows' => $rep->items(),
  460. 'count' => $rep->total(),
  461. ];
  462. // 执行查询
  463. $endTime = microtime(true);
  464. $executionTime = ($endTime - $startTime) * 1000;
  465. echo "查询执行时间: {$executionTime}ms\n";
  466. return Result::success($data);
  467. }
  468. /**
  469. * @param array $data
  470. * @return array
  471. */
  472. public function addArticle(array $data): array
  473. {
  474. var_dump($data, '----------12-----------1');
  475. // ------c_show_time********add***1****
  476. $is_collect = $data['is_collect'] ?? 0;
  477. $user_type = $data['user_type'];
  478. unset($data['is_collect']);
  479. unset($data['user_type']);
  480. // ------c_show_time********add***1****
  481. unset($data['nav_add_pool_id']);
  482. // unset($data['commend_id']);
  483. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  484. Db::beginTransaction();
  485. try {
  486. //处理投票
  487. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  488. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  489. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  490. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  491. unset($data['is_survey']);
  492. unset($data['survey_name']);
  493. unset($data['suvey_array']);
  494. // unset($data['website_id']);
  495. // unset($data['web_site_id']);
  496. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  497. if ($data['hits'] == '') {
  498. $data['hits'] = 0;
  499. }
  500. if ($data['is_original'] == '') {
  501. $data['is_original'] = 0;
  502. }
  503. if ($data['status'] == '') {
  504. $data['status'] = 0;
  505. }
  506. $articleData = $data;
  507. unset($articleData['content']);
  508. //自动处理缩略图、关键字、描述
  509. if ($articleData['imgurl'] == '') {
  510. //如果没有图,设置level=0
  511. $levelArr = json_decode($articleData['level'], true);
  512. var_dump($levelArr, '----------levelArr-----------1');
  513. //content中提取图片第一个图,正则提取
  514. // -------采集器相关优化-----
  515. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  516. if ($is_collect == 1) {
  517. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  518. } else {
  519. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  520. }
  521. // -------采集器相关优化-----
  522. preg_match_all($reg, $data['content'], $matches);
  523. if (isset($matches[1][0])) {
  524. //截取varchar240
  525. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  526. //如果有图,设置level=3
  527. if (!in_array(3, $levelArr)) {
  528. $levelArr[] = 3;
  529. }
  530. $articleData['level'] = json_encode($levelArr);
  531. } else {
  532. if (!in_array(0, $levelArr)) {
  533. $levelArr[] = 0;
  534. }
  535. $articleData['level'] = json_encode($levelArr);
  536. }
  537. }
  538. var_dump($articleData['level'], '----------$articleData[level]----------1');
  539. if ($articleData['keyword'] == '') {
  540. //提取标题+内容中的关键词
  541. $articleData['keyword'] = $data['title'];
  542. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  543. Jieba::init(); // 初始化 jieba-php
  544. Finalseg::init();
  545. $segList = Jieba::cut($articleData['keyword']);
  546. $segList1 = array_slice($segList, 0, 8);
  547. $articleData['keyword'] = implode(',', $segList1);
  548. }
  549. if ($articleData['introduce'] == '') {
  550. //提取内容中的描述
  551. $content = $data['content'];
  552. // 去除 <style> 和 <script> 标签及其内容
  553. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  554. // 去除所有 HTML 标签
  555. $content = strip_tags($content);
  556. // 去除 HTML 实体
  557. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  558. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  559. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  560. // 去除多余空白
  561. $content = preg_replace('/\s+/u', '', $content);
  562. // 截取 100 个字符
  563. $articleData['introduce'] = mb_substr($content, 0, 100);
  564. }
  565. if ($articleData['status'] == 0) {
  566. $this->sendMessage([
  567. 'talk_type' => 100,
  568. 'title' => $articleData['title'],
  569. 'content' => '提交了审核',
  570. 'messageType' => 2,
  571. ]);
  572. }
  573. if(!empty($data['fujian'])){
  574. $articleData['fujian'] = $data['fujian'];
  575. }
  576. $id = Article::insertGetId($articleData);
  577. if (!$id) {
  578. throw new \Exception('文章插入失败');
  579. }
  580. $articleDataContent = [
  581. 'article_id' => $id,
  582. 'content' => $data['content'],
  583. ];
  584. // 采集器中的文章内容,在添加时,去掉div标签
  585. if ($is_collect == 1) {
  586. // 采集来的文章,content中可能包含div标签,需要先移除
  587. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  588. $article_data = preg_replace($pattern, '', $data['content']);
  589. $$articleDataContent['content'] = $article_data;
  590. }
  591. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  592. if (!$contentInsertId) {
  593. throw new \Exception('文章内容插入失败');
  594. }
  595. // ------c_show_time********add***2****
  596. // 直接使用当前系统时间,不再强制添加8小时
  597. $now = date('Y-m-d H:i:s');
  598. if ($user_type == 10000 || $is_collect == 1) {
  599. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  600. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  601. if (!isset($data['catid'])) {
  602. throw new \Exception('缺少必要字段:catid');
  603. }
  604. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  605. $web = WebsiteCategory::where('category_id', $data['catid'])
  606. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  607. ->select(
  608. 'website_id',
  609. 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')
  610. )
  611. ->get();
  612. // $id = 225; -----测试开启
  613. // 采集来的文章,错开时间在两小时之内发布
  614. if ($user_type == 10000 && $is_collect == 1) {
  615. $web_num = $web->where('is_core', '!=', 2)->count();
  616. $waiting_interval = 10;
  617. if ($web_num > 12) {
  618. // 若网站数量大于12个,则每个网站间隔时间取均值
  619. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  620. $waiting_interval = 120 / max(1, $web_num);
  621. }
  622. $time = 0;
  623. } else {
  624. // 非核心站与核心站----显示时间-----间隔
  625. $time = 20;
  626. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  627. $waiting_interval = 5;
  628. }
  629. // 将 Hyperf\Database\Model\Collection 转换为数组
  630. $webArray = $web->toArray();
  631. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  632. // 检查 $item 对象是否有 is_core 属性
  633. if (!isset($item['is_core'])) {
  634. throw new \Exception('$item 对象缺少 is_core 属性');
  635. }
  636. // 当 is_core 为 2 时,则表示此网站不存在
  637. if ($item['is_core'] == 2) {
  638. return null;
  639. }
  640. if ($is_collect == 1) {
  641. // 采集来的文章,错开时间在两小时之内发布
  642. // $time = 0;
  643. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  644. $time += $waiting_interval;
  645. } else if ($item['is_core'] == 1) {
  646. // 当 is_core 为 1 时,则表示此网站是核心站
  647. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  648. } else {
  649. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  650. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  651. if ($item['is_core'] == 0) {
  652. $time += $waiting_interval;
  653. }
  654. }
  655. return [
  656. 'article_id' => $id,
  657. 'website_id' => $item['website_id'],
  658. 'c_show_time' => $c_show_time,
  659. // 'is_core' => $item['is_core'],
  660. // 'time' => $time
  661. ];
  662. }, array_keys($webArray), $webArray)));
  663. // Db::commit();
  664. // return Result::success($article_ignore);
  665. if (!empty($article_ignore)) {
  666. $article_ignores = ArticleIgnore::insert($article_ignore);
  667. if (!$article_ignores) {
  668. throw new \Exception('c端展示时间插入失败');
  669. }
  670. }
  671. }
  672. // ------c_show_time********add***2****
  673. //处理投票
  674. if ($is_survey == 1) {
  675. //生成年月日时分秒+8位随机数
  676. $uuid = date('YmdHis') . rand(10000000, 99999999);
  677. var_dump($suvey_array, 'suvey_array________');
  678. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  679. var_dump($suveys_array, '---------------------1');
  680. var_dump($suvey_array, '---------------------2');
  681. $suvey_data = [];
  682. foreach ($suveys_array as $key => $value) {
  683. if ($value == '') {
  684. continue;
  685. }
  686. if (is_array($value)) {
  687. $suvey_data[] = [
  688. 'sur_id' => $uuid,
  689. 'art_id' => $id,
  690. 'website_id' => $website_id ?? 2,
  691. 'survey_name' => $survey_name,
  692. 'choice_name' => $value[1],
  693. 'is_other' => 1,
  694. 'other_id' => 0,
  695. 'results' => 0,
  696. ];
  697. } else {
  698. $suvey_data[] = [
  699. 'sur_id' => $uuid,
  700. 'art_id' => $id,
  701. 'website_id' => $website_id ?? 2,
  702. 'survey_name' => $survey_name,
  703. 'choice_name' => $value,
  704. 'is_other' => 0,
  705. 'other_id' => 0,
  706. 'results' => 0,
  707. ];
  708. }
  709. if (empty($suvey_data)) {
  710. throw new \Exception("投票数据为空");
  711. }
  712. }
  713. $result = ArticleSurvey::insert($suvey_data);
  714. if (!$result) {
  715. throw new \Exception("投票失败,ArticleSurvey插入失败");
  716. }
  717. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  718. if (!$result) {
  719. throw new \Exception("投票失败,更新主表失败");
  720. }
  721. }
  722. Db::commit();
  723. return Result::success(['id' => $id]);
  724. } catch (\Throwable $ex) {
  725. Db::rollBack();
  726. var_dump($ex->getMessage());
  727. return Result::error("创建失败", 0);
  728. }
  729. }
  730. /**
  731. * @param array $data
  732. * @return array
  733. */
  734. public function delArticle(array $data): array
  735. {
  736. // ------c_show_time********del*******
  737. Db::beginTransaction();
  738. try {
  739. $article = Article::where(['id' => $data['id']])->delete();
  740. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  741. if (!$article) {
  742. throw new \Exception("删除失败,文章删除失败");
  743. }
  744. //survey投票删除
  745. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  746. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  747. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  748. // 若文章详情删除失败,抛出异常
  749. if (!$article_data) {
  750. throw new \Exception("删除失败,文章详情删除失败");
  751. }
  752. Db::commit(); // 所有操作成功,提交事务
  753. } catch (\Throwable $ex) {
  754. Db::rollBack();
  755. var_dump($ex->getMessage());
  756. return Result::error("删除失败: " . $ex->getMessage(), 0);
  757. }
  758. // ------c_show_time********del*******
  759. if (!$article) {
  760. return Result::error("删除失败");
  761. }
  762. return Result::success($article);
  763. }
  764. /**
  765. * @param array $data
  766. * @return array
  767. */
  768. public function updateArticle(array $data): array
  769. {
  770. var_dump($data, '----------12-----------1');
  771. Db::beginTransaction();
  772. // ------c_show_time********up*******
  773. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  774. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  775. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  776. $web = WebsiteCategory::where('category_id', $data['catid'])
  777. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  778. ->select(
  779. 'website_id',
  780. 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')
  781. )
  782. ->get();
  783. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  784. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  785. $websiteIds = $web->pluck('website_id')->toArray();
  786. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  787. if ($user_type == 0) {
  788. throw new \Exception("用户类型不能为空");
  789. }
  790. if ($user_type == 10000) {
  791. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  792. $web = WebsiteCategory::where('category_id', $data['catid'])
  793. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  794. ->select(
  795. 'website_id',
  796. 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')
  797. )
  798. ->get();
  799. // 非核心站与核心站----显示时间-----间隔
  800. $time = 20;
  801. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  802. $waiting_interval = 5;
  803. $webArray = $web->toArray();
  804. if (empty($webArray)) {
  805. throw new \Exception('网站分类不存在');
  806. }
  807. // 直接使用当前系统时间,不再强制添加8小时
  808. $now = date('Y-m-d H:i:s');
  809. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  810. // 检查 $item 对象是否有 is_core 属性
  811. if (!isset($item['is_core'])) {
  812. throw new \Exception('$item 对象缺少 is_core 属性');
  813. }
  814. // 当 is_core 为 2 时,则表示此网站不存在
  815. if ($item['is_core'] == 2) {
  816. return null;
  817. } else if ($item['is_core'] == 1) {
  818. // 当 is_core 为 1 时,则表示此网站是核心站
  819. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  820. } else {
  821. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  822. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  823. if ($item['is_core'] == 0) {
  824. $time += $waiting_interval;
  825. }
  826. }
  827. return [
  828. 'article_id' => $data['id'],
  829. 'website_id' => $item['website_id'],
  830. 'c_show_time' => $c_show_time,
  831. ];
  832. }, array_keys($webArray), $webArray)));
  833. if (!empty($article_ignore)) {
  834. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  835. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  836. $article_ignores = ArticleIgnore::upsert(
  837. $article_ignore,
  838. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  839. ['c_show_time'] // 需要更新的字段
  840. );
  841. if (!$article_ignores) {
  842. throw new \Exception('c端展示时间插入失败');
  843. }
  844. }
  845. // Db::commit();
  846. // return Result::success($article_ignore);
  847. }
  848. // ------c_show_time********up*******
  849. unset($data['user_type']);
  850. // unset($data['web_site_id']);
  851. unset($data['nav_add_pool_id']);
  852. try {
  853. //处理投票
  854. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  855. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  856. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  857. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  858. unset($data['is_survey']);
  859. unset($data['survey_name']);
  860. unset($data['suvey_array']);
  861. unset($data['website_id']);
  862. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  863. if ($data['hits'] == '') {
  864. $data['hits'] = 0;
  865. }
  866. if ($data['is_original'] == '') {
  867. $data['is_original'] = 0;
  868. }
  869. if ($data['status'] == '') {
  870. $data['status'] = 0;
  871. }
  872. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  873. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  874. $articleData = $data;
  875. unset($articleData['content']);
  876. unset($articleData['status_name']);
  877. unset($articleData['name']);
  878. unset($articleData['content']);
  879. unset($articleData['pid_arr']);
  880. unset($articleData['pid']);
  881. //自动处理缩略图、关键字、描述
  882. if ($articleData['imgurl'] == '') {
  883. //如果没有图,设置level=0
  884. $levelArr = json_decode($articleData['level'], true);
  885. var_dump($levelArr, '----------levelArr-----------1');
  886. //content中提取图片第一个图,正则提取
  887. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  888. preg_match_all($reg, $data['content'], $matches);
  889. if (isset($matches[1][0])) {
  890. //截取varchar240
  891. // 截取到第一个<
  892. $articleData['imgurl'] = $matches[1][0];
  893. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  894. $pos = strpos($articleData['imgurl'], '"');
  895. if ($pos !== false) {
  896. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  897. }
  898. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  899. //如果有图,设置level=3
  900. if (!in_array(3, $levelArr)) {
  901. $levelArr[] = 3;
  902. }
  903. $articleData['level'] = json_encode($levelArr);
  904. } else {
  905. if (!in_array(0, $levelArr)) {
  906. $levelArr[] = 0;
  907. }
  908. $articleData['level'] = json_encode($levelArr);
  909. }
  910. }
  911. var_dump($articleData['level'], '----------$articleData[level]----------1');
  912. if ($articleData['keyword'] == '') {
  913. //提取标题+内容中的关键词
  914. $articleData['keyword'] = $data['title'];
  915. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  916. Jieba::init(); // 初始化 jieba-php
  917. Finalseg::init();
  918. $segList = Jieba::cut($articleData['keyword']);
  919. $segList1 = array_slice($segList, 0, 8);
  920. $articleData['keyword'] = implode(',', $segList1);
  921. }
  922. if ($articleData['introduce'] == '') {
  923. //提取内容中的描述
  924. $content = $data['content'];
  925. // 去除 <style> 和 <script> 标签及其内容
  926. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  927. // 去除所有 HTML 标签
  928. $content = strip_tags($content);
  929. // 去除 HTML 实体
  930. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  931. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  932. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  933. // 去除多余空白
  934. $content = preg_replace('/\s+/u', '', $content);
  935. // 截取 100 个字符
  936. $articleData['introduce'] = mb_substr($content, 0, 100);
  937. }
  938. if ($articleData['status'] == 0) {
  939. $this->sendMessage([
  940. 'talk_type' => 100,
  941. 'title' => $articleData['title'],
  942. 'content' => '提交了审核',
  943. 'messageType' => 2,
  944. ]);
  945. }
  946. if(!empty($data['fujian'])){
  947. $articleData['fujian'] = $data['fujian'];
  948. }
  949. $id = Article::where(['id' => $data['id']])->update($articleData);
  950. // $articleDataContent = [
  951. // 'content' => $data['content'],
  952. // ];
  953. // 采集来的文章,content中可能包含div标签,需要先移除
  954. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  955. $article_data = preg_replace($pattern, '', $data['content']);
  956. $articleDataContent['content'] = $article_data;
  957. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  958. //处理投票
  959. $id = $data['id'];
  960. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  961. var_dump($suvey_array, 'suvey_array________delete');
  962. //处理投票
  963. if ($is_survey == 1) {
  964. //生成年月日时分秒+8位随机数
  965. $uuid = date('YmdHis') . rand(10000000, 99999999);
  966. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  967. var_dump($suveys_array, '---------------------1');
  968. $suvey_data = [];
  969. if (is_array($suveys_array)) {
  970. foreach ($suveys_array as $key => $value) {
  971. if ($value == '') {
  972. continue;
  973. }
  974. if (is_array($value)) {
  975. $suvey_data[] = [
  976. 'sur_id' => $uuid,
  977. 'art_id' => $id,
  978. 'website_id' => $website_id ?? 2,
  979. 'survey_name' => $survey_name,
  980. 'choice_name' => $value[1],
  981. 'is_other' => 1,
  982. 'other_id' => 0,
  983. 'results' => 0,
  984. ];
  985. } else {
  986. $suvey_data[] = [
  987. 'sur_id' => $uuid,
  988. 'art_id' => $id,
  989. 'website_id' => $website_id ?? 2,
  990. 'survey_name' => $survey_name,
  991. 'choice_name' => $value,
  992. 'is_other' => 0,
  993. 'other_id' => 0,
  994. 'results' => 0,
  995. ];
  996. }
  997. if (empty($suvey_data)) {
  998. throw new \Exception("投票数据为空");
  999. }
  1000. }
  1001. }
  1002. $result = ArticleSurvey::insert($suvey_data);
  1003. if (!$result) {
  1004. throw new \Exception("投票失败");
  1005. }
  1006. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1007. if (!$result) {
  1008. throw new \Exception("投票失败");
  1009. }
  1010. } else {
  1011. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1012. }
  1013. Db::commit();
  1014. return Result::success([]);
  1015. } catch (\Throwable $ex) {
  1016. Db::rollBack();
  1017. var_dump($ex->getMessage());
  1018. return Result::error("更新失败" . $ex->getMessage(), 0);
  1019. }
  1020. }
  1021. /**
  1022. * 更新资讯状态
  1023. * @param array $data
  1024. * @return array
  1025. */
  1026. public function upArticleStatus(array $data): array
  1027. {
  1028. $articleData = Article::where(['id' => $data['id']])->first();
  1029. //发送10次
  1030. // for ($i = 0; $i < 10; $i++) {
  1031. // $this->sendMessage([
  1032. // 'talk_type' => 100,
  1033. // 'title' => $i . $articleData['title'],
  1034. // 'content' => '审核通过',
  1035. // 'messageType' => 2,
  1036. // 'user_id' => $articleData['admin_user_id'],
  1037. // ]);
  1038. // }
  1039. // var_dump($data['status'], 'status');
  1040. // return Result::success();
  1041. if ($data['status'] == 1) {
  1042. $this->sendMessage([
  1043. 'talk_type' => 101,
  1044. 'title' => $articleData['title'],
  1045. 'content' => '审核通过',
  1046. 'messageType' => 2,
  1047. 'user_id' => $articleData['admin_user_id'],
  1048. ]);
  1049. }
  1050. if ($data['status'] == 2) {
  1051. $this->sendMessage([
  1052. 'talk_type' => 101,
  1053. 'title' => $articleData['title'],
  1054. 'content' => '审核拒绝',
  1055. 'messageType' => 2,
  1056. 'user_id' => $articleData['admin_user_id'],
  1057. ]);
  1058. }
  1059. if ($data['status'] == 0) {
  1060. $this->sendMessage([
  1061. 'talk_type' => 100,
  1062. 'title' => $articleData['title'],
  1063. 'content' => '提交了审核',
  1064. 'messageType' => 2,
  1065. ]);
  1066. }
  1067. $result = Article::where(['id' => $data['id']])->update($data);
  1068. // ------c_show_time********up_status*******
  1069. // 若是审核通过 则更新c_show_time
  1070. if ($data['status'] == 1) {
  1071. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1072. $web = Article::where('article.id', $data['id'])
  1073. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1074. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1075. ->select(
  1076. 'website_id',
  1077. 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')
  1078. )
  1079. ->get();
  1080. // 非核心站与核心站----显示时间-----间隔
  1081. $time = 20;
  1082. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1083. $waiting_interval = 5;
  1084. $webArray = $web->toArray();
  1085. if (empty($webArray)) {
  1086. throw new \Exception('网站分类不存在');
  1087. }
  1088. // 直接使用当前系统时间,不再强制添加8小时
  1089. $now = date('Y-m-d H:i:s');
  1090. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1091. if (isset($data['ignore_ids'])) {
  1092. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1093. if (in_array($item['website_id'], $ignore_website_ids)) {
  1094. $is_ignore = 1;
  1095. } else {
  1096. $is_ignore = 0;
  1097. }
  1098. return [
  1099. 'article_id' => $data['id'],
  1100. 'website_id' => $item['website_id'],
  1101. 'is_ignore' => $is_ignore,
  1102. ];
  1103. } else {
  1104. // 检查 $item 对象是否有 is_core 属性
  1105. if (!isset($item['is_core'])) {
  1106. throw new \Exception('$item 对象缺少 is_core 属性');
  1107. }
  1108. // 当 is_core 为 2 时,则表示此网站不存在
  1109. if ($item['is_core'] == 2) {
  1110. return null;
  1111. } else if ($item['is_core'] == 1) {
  1112. // 当 is_core 为 1 时,则表示此网站是核心站
  1113. $c_show_time = $now;
  1114. } else {
  1115. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1116. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1117. if ($item['is_core'] == 0) {
  1118. $time += $waiting_interval;
  1119. }
  1120. }
  1121. return [
  1122. 'article_id' => $data['id'],
  1123. 'website_id' => $item['website_id'],
  1124. 'c_show_time' => $c_show_time,
  1125. ];
  1126. }
  1127. }, array_keys($webArray), $webArray)));
  1128. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1129. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1130. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1131. $websiteIds = $web->pluck('website_id')->toArray();
  1132. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1133. $article_ignores = ArticleIgnore::upsert(
  1134. $article_ignore,
  1135. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1136. ['c_show_time'] // 需要更新的字段
  1137. );
  1138. if (!$article_ignores) {
  1139. throw new \Exception('c端展示时间插入失败');
  1140. }
  1141. }
  1142. if (!empty($data['ignore_ids'])) {
  1143. // return Result::success($article_ignore);
  1144. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1145. if (!empty($article_ignore)) {
  1146. $article_ignores = ArticleIgnore::upsert(
  1147. $article_ignore,
  1148. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1149. ['is_ignore'] // 需要更新的字段
  1150. );
  1151. // if(!$article_ignores){
  1152. // throw new \Exception('屏蔽网站更新失败');
  1153. // }
  1154. }
  1155. }
  1156. }
  1157. // ------c_show_time********up_status*******
  1158. if ($result) {
  1159. return Result::success();
  1160. } else {
  1161. return Result::error("更新状态失败", 0);
  1162. }
  1163. }
  1164. /**
  1165. * 获取新闻详情
  1166. * @param array $data
  1167. * @return array
  1168. */
  1169. public function getArticleInfo(array $data): array
  1170. {
  1171. $where = [
  1172. 'article.id' => $data['id'],
  1173. // 'article.status' => 1,
  1174. ];
  1175. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1176. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1177. $info = $result;
  1178. // var_dump($info, 'info');
  1179. $info['survey_array'] = $articleSurvey;
  1180. if ($result) {
  1181. return Result::success($info);
  1182. } else {
  1183. return Result::error("查询失败", 0);
  1184. }
  1185. }
  1186. /**
  1187. * 获取头条新闻
  1188. * @param array $data
  1189. * @return array
  1190. */
  1191. public function getWebsiteArticlett(array $data): array
  1192. {
  1193. $website_id = $data['website_id'];
  1194. $website = Website::where('id', $data['website_id'])->first();
  1195. if (empty($website)) {
  1196. return Result::error("网站不存在", 0);
  1197. }
  1198. $categorys = $this->processArticlePro($website_id);
  1199. $catiall = $categorys['catiall'];
  1200. $categoryIds = $categorys['categoryIds'];
  1201. $where = [
  1202. 'status' => 1
  1203. ];
  1204. // $website_column = $website['column'];
  1205. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1206. $website_column = json_decode($website['website_column_arr_id'], true);
  1207. }
  1208. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1209. // return Result::success($diff_pid_categoryIds);
  1210. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1211. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1212. }
  1213. // $website_id = $data['website_id'];
  1214. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1215. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1216. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1217. switch ($data['level']) {
  1218. case 1:
  1219. case 2:
  1220. case 3:
  1221. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1222. $query = Article::where($where)
  1223. ->where('level', 'like', '%' . $data['level'] . '%')
  1224. ->orderBy('updated_at', 'desc');
  1225. break;
  1226. case 4: //最新资讯
  1227. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1228. break;
  1229. case 5: //资讯推荐
  1230. $query = Article::where($where)
  1231. ->where('updated_at', '>', $month);
  1232. break;
  1233. case 7: //资讯分类
  1234. if (isset($data['id']) && !empty($data['id'])) {
  1235. $keyword = Article::where('id', $data['id'])->value('keyword');
  1236. $keywordArray = explode(',', $keyword);
  1237. $whereL7 = [];
  1238. foreach ($keywordArray as $k => $v) {
  1239. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1240. }
  1241. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1242. break;
  1243. } else {
  1244. return Result::error("请输入资讯ID", 0);
  1245. break;
  1246. }
  1247. default:
  1248. break;
  1249. }
  1250. // $whereL7 = [];
  1251. // if(isset($data['id']) && !empty($data['id'])){
  1252. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1253. // $keywordArray = explode(',', $keyword);
  1254. // foreach ($keywordArray as $k => $v) {
  1255. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1256. // }
  1257. // }
  1258. // $query = Article::where($where)
  1259. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1260. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1261. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1262. // }
  1263. // if($data['level'] == 7){
  1264. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1265. // }
  1266. // if($data['level'] == 4){
  1267. // $query = $query->inRandomOrder()
  1268. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1269. // }
  1270. // if($data['level'] == 5){
  1271. // $query = $query->orderBy('updated_at','desc');
  1272. // }
  1273. // });
  1274. if ($data['textnum'] > 0) {
  1275. $query = clone $query;
  1276. $result['text'] = $query
  1277. ->whereIn('catid', $categoryIds)
  1278. ->leftJoinSub(function ($query) use ($website_id) {
  1279. $query->from('article_ignore')
  1280. ->where('website_id', $website_id);
  1281. }, 'article_ignore', function ($join) {
  1282. $join->on('article_ignore.article_id', '=', 'article.id');
  1283. })
  1284. ->where(function ($query) {
  1285. $query->whereNull('article_ignore.article_id')
  1286. ->orWhere(function ($subQuery) {
  1287. $subQuery->whereNotNull('article_ignore.article_id')
  1288. ->where('article_ignore.is_ignore', 0)
  1289. ->where(function ($subSubQuery) {
  1290. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1291. ->orWhereNull('article_ignore.c_show_time');
  1292. });
  1293. });
  1294. })
  1295. // ->where(function ($query) use ($website_id) {
  1296. // $query->whereNull('article_ignore.article_id')
  1297. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1298. // })
  1299. ->select(
  1300. 'article.id',
  1301. 'article.title',
  1302. 'article.author',
  1303. 'article.updated_at',
  1304. 'article.introduce',
  1305. 'article.islink',
  1306. 'article.linkurl',
  1307. 'article.copyfrom',
  1308. 'article.cat_arr_id',
  1309. 'article.catid',
  1310. 'article.level',
  1311. // 'article_ignore.is_ignore',
  1312. // 'article_ignore.c_show_time',
  1313. )
  1314. ->offset($data['placeid'])
  1315. ->limit($data['textnum'])
  1316. ->get()->all();
  1317. foreach ($result['text'] as $k => $v) {
  1318. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1319. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1320. }
  1321. }
  1322. if ($data['imgnum'] > 0) {
  1323. $query = clone $query;
  1324. if ($data['textnum'] == 0) {
  1325. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1326. $query->from('article_ignore')
  1327. ->where('website_id', $website_id);
  1328. }, 'article_ignore', function ($join) {
  1329. $join->on('article_ignore.article_id', '=', 'article.id');
  1330. })
  1331. ->where(function ($query) {
  1332. $query->whereNull('article_ignore.article_id')
  1333. ->orWhere(function ($subQuery) {
  1334. $subQuery->whereNotNull('article_ignore.article_id')
  1335. ->where('article_ignore.is_ignore', 0)
  1336. ->where(function ($subSubQuery) {
  1337. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1338. ->orWhereNull('article_ignore.c_show_time');
  1339. });
  1340. });
  1341. });
  1342. }
  1343. $result['img'] = $query
  1344. ->whereIn('catid', $categoryIds)
  1345. ->where('article.imgurl', '!=', '')
  1346. ->select(
  1347. 'article.id',
  1348. 'article.title',
  1349. 'article.imgurl',
  1350. 'article.author',
  1351. 'article.updated_at',
  1352. 'article.introduce',
  1353. 'article.islink',
  1354. 'article.linkurl',
  1355. 'article.copyfrom',
  1356. 'article.cat_arr_id',
  1357. 'article.catid',
  1358. 'article.level',
  1359. // 'article_ignore.is_ignore',
  1360. // 'article_ignore.c_show_time',
  1361. )
  1362. ->offset($data['placeid'])
  1363. ->limit($data['imgnum'])
  1364. ->get()->all();
  1365. foreach ($result['img'] as $k => $v) {
  1366. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1367. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1368. }
  1369. }
  1370. if (empty($result)) {
  1371. return Result::error("暂无相关资讯", 0);
  1372. }
  1373. return Result::success($result);
  1374. }
  1375. /**
  1376. * 获取模块新闻
  1377. * @param array $data
  1378. * @return array
  1379. */
  1380. public function getWebsiteModelArticles(array $data): array
  1381. {
  1382. $catid = $data['catid'];
  1383. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1384. $category = $category->toArray();
  1385. if (!empty($category)) {
  1386. $where = [
  1387. 'status' => 1,
  1388. 'catid' => $catid,
  1389. ];
  1390. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1391. // 1:文字新闻;2:轮播图;3:图文;
  1392. // 级别:0:未分类
  1393. // 3:推荐图片
  1394. if ($data['level'] == 1) {
  1395. $data['level'] = 0;
  1396. }
  1397. $result = Article::where($where)
  1398. ->where(function ($query) use ($data) {
  1399. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1400. ->orWhereNull("level")
  1401. ->orWhereRaw("level = '[]'");
  1402. })
  1403. ->leftJoinSub(function ($query) use ($data) {
  1404. $query->from('article_ignore')
  1405. ->where('website_id', $data['website_id']);
  1406. }, 'article_ignore', function ($join) {
  1407. $join->on('article_ignore.article_id', '=', 'article.id');
  1408. })
  1409. ->where(function ($query) {
  1410. $query->whereNull('article_ignore.article_id')
  1411. ->orWhere(function ($subQuery) {
  1412. $subQuery->whereNotNull('article_ignore.article_id')
  1413. ->where('article_ignore.is_ignore', 0)
  1414. ->where(function ($subSubQuery) {
  1415. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1416. ->orWhereNull('article_ignore.c_show_time');
  1417. });
  1418. });
  1419. })
  1420. // ->where(function ($query) use ($data) {
  1421. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1422. // ->orWhereNull("ignore_ids");
  1423. // })
  1424. ->orderBy("updated_at", "desc")
  1425. ->offset($placeid)
  1426. ->limit($data['pagesize'])
  1427. ->get();
  1428. if (empty($result)) {
  1429. return Result::error("此栏目暂无相关新闻", 0);
  1430. }
  1431. } else {
  1432. return Result::error("此网站暂无此栏目", 0);
  1433. }
  1434. return Result::success($result);
  1435. }
  1436. /**
  1437. *获取新闻列表
  1438. * @param array $data
  1439. * @return array
  1440. */
  1441. public function getWebsiteArticleList(array $data): array
  1442. {
  1443. // return Result::success($data);
  1444. $where[] = ['status', '=', 1];
  1445. $website_id = $data['website_id'];
  1446. $website = Website::where('id', $data['website_id'])->first();
  1447. if (empty($website)) {
  1448. return Result::error("网站不存在", 0);
  1449. }
  1450. // $website_column = $website['column'];
  1451. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1452. $website_column = json_decode($website['website_column_arr_id'], true);
  1453. }
  1454. $categorys = $this->processArticlePro($website_id);
  1455. $cat_1st_arr = $categorys['cat_1st_arr'];
  1456. $catiall = $categorys['catiall'];
  1457. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1458. // return Result::success($diff_pid_categoryIds);
  1459. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1460. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1461. }
  1462. if (isset($data['catid']) && !empty($data['catid'])) {
  1463. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1464. if (empty($category)) {
  1465. return Result::error("此网站暂无此栏目", 0);
  1466. }
  1467. array_push($where, ['catid', '=', $data['catid']]);
  1468. }
  1469. // return Result::success($where);
  1470. $query = Article::where($where)
  1471. ->leftJoinSub(function ($query) use ($website_id) {
  1472. $query->from('article_ignore')
  1473. ->where('website_id', $website_id);
  1474. }, 'article_ignore', function ($join) {
  1475. $join->on('article_ignore.article_id', '=', 'article.id');
  1476. })
  1477. ->where(function ($query) {
  1478. $query->whereNull('article_ignore.article_id')
  1479. ->orWhere(function ($subQuery) {
  1480. $subQuery->whereNotNull('article_ignore.article_id')
  1481. ->where('article_ignore.is_ignore', 0)
  1482. ->where(function ($subSubQuery) {
  1483. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1484. ->orWhereNull('article_ignore.c_show_time');
  1485. });
  1486. });
  1487. })
  1488. ->select(
  1489. 'article.id',
  1490. 'article.title',
  1491. 'article.imgurl',
  1492. 'article.author',
  1493. 'article.updated_at',
  1494. 'article.introduce',
  1495. 'article.islink',
  1496. 'article.linkurl',
  1497. 'article.copyfrom',
  1498. 'article.cat_arr_id',
  1499. 'article.catid'
  1500. );
  1501. $count = $query->count();
  1502. $rep = $query->orderBy("updated_at", "desc")
  1503. ->offset(($data['page'] - 1) * $data['pageSize'])
  1504. ->limit($data['pageSize'])
  1505. ->get()->all();
  1506. $categorys = $this->processArticlePro($website_id);
  1507. $cat_1st_arr = $categorys['cat_1st_arr'];
  1508. $catiall = $categorys['catiall'];
  1509. // $web['website_id'] = $data['website_id'];
  1510. foreach ($rep as $k => $v) {
  1511. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1512. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1513. }
  1514. // $rep = $this->processArticles($rep,$web);
  1515. $data = [
  1516. 'rows' => $rep,
  1517. 'count' => $count,
  1518. ];
  1519. if (empty($rep)) {
  1520. return Result::error("没有信息数据");
  1521. }
  1522. return Result::success($data);
  1523. }
  1524. /**
  1525. * 前端-获取新闻详情
  1526. * @param array $data
  1527. * @return array
  1528. */
  1529. public function selectWebsiteArticleInfo(array $data): array
  1530. {
  1531. $where = [
  1532. 'article.id' => $data['id'],
  1533. 'article.status' => 1,
  1534. ];
  1535. $result = Article::where($where)
  1536. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1537. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1538. // ->where(function ($query) use ($data) {
  1539. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1540. // ->orWhereNull("ignore_ids");
  1541. // })
  1542. ->leftJoinSub(function ($query) use ($data) {
  1543. $query->from('article_ignore')
  1544. ->where('website_id', $data['website_id']);
  1545. }, 'article_ignore', function ($join) {
  1546. $join->on('article_ignore.article_id', '=', 'article.id');
  1547. })
  1548. ->where(function ($query) {
  1549. $query->whereNull('article_ignore.article_id')
  1550. ->orWhere(function ($subQuery) {
  1551. $subQuery->whereNotNull('article_ignore.article_id')
  1552. ->where('article_ignore.is_ignore', 0)
  1553. ->where(function ($subSubQuery) {
  1554. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1555. ->orWhereNull('article_ignore.c_show_time');
  1556. });
  1557. });
  1558. })
  1559. ->select(
  1560. 'article.*',
  1561. 'article_data.content',
  1562. 'article_data.article_id',
  1563. 'article_extend.website_url',
  1564. 'article_extend.email',
  1565. 'article_extend.contacts',
  1566. 'article_extend.contacts_mobile',
  1567. 'article_extend.contacts_address',
  1568. 'article_extend.zip_code',
  1569. 'article_extend.enterprise_name'
  1570. )
  1571. ->first();
  1572. if (empty($result)) {
  1573. return Result::error("暂无此新闻!", 0);
  1574. }
  1575. if (!empty($result['publiced_at'])) {
  1576. $result['updated_at'] = $result['publiced_at'];
  1577. }
  1578. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1579. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1580. ->where('website_category.website_id', $data['website_id'])
  1581. ->where(['website_category.category_id' => $result['catid']])
  1582. ->first();
  1583. if (empty($category)) {
  1584. return Result::error("查询失败", 0);
  1585. }
  1586. //手动推荐文章
  1587. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1588. if (empty($commend_ids)) {
  1589. $commendArticle = [];
  1590. } else {
  1591. //去除不存在的文章ID
  1592. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1593. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1594. ->leftJoinSub(function ($query) use ($data) {
  1595. $query->from('article_ignore')
  1596. ->where('website_id', $data['website_id']);
  1597. }, 'article_ignore', function ($join) {
  1598. $join->on('article_ignore.article_id', '=', 'article.id');
  1599. })
  1600. ->where(function ($query) {
  1601. $query->whereNull('article_ignore.article_id')
  1602. ->orWhere(function ($subQuery) {
  1603. $subQuery->whereNotNull('article_ignore.article_id')
  1604. ->where('article_ignore.is_ignore', 0)
  1605. ->where(function ($subSubQuery) {
  1606. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1607. ->orWhereNull('article_ignore.c_show_time');
  1608. });
  1609. });
  1610. })
  1611. ->where('article.status', 1)
  1612. ->where('website_category.website_id', $data['website_id'])
  1613. ->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')
  1614. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1615. // ->orderBy('article.updated_at', 'desc')
  1616. ->limit(5)
  1617. ->get();
  1618. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1619. foreach ($commendArticle as $k => $v) {
  1620. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1621. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1622. $cat_arr_id = array_unique($cat_arr_id);
  1623. // 从website_category取出alias_pinyin
  1624. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1625. ->whereIn('category_id', $cat_arr_id)
  1626. ->pluck('alias_pinyin', 'category_id')
  1627. ->toArray();
  1628. // 将cat_arr_id的json转成路径/隔开
  1629. $path_parts = [];
  1630. foreach ($cat_arr_id as $cat_id) {
  1631. if (isset($cat_arr[$cat_id])) {
  1632. $path_parts[] = $cat_arr[$cat_id];
  1633. }
  1634. }
  1635. $v->alias_pinyin = implode('/', $path_parts);
  1636. } else {
  1637. $v->alias_pinyin = '';
  1638. }
  1639. }
  1640. }
  1641. $result['category_id'] = $category['category_id'];
  1642. $result['cat_name'] = $category['alias'];
  1643. $result['website_name'] = $category['website_name'] ?? "";
  1644. $result['suffix'] = $category['suffix'] ?? "";
  1645. $result['commendArticle'] = $commendArticle;
  1646. $result['commend_ids'] = $commend_ids;
  1647. return Result::success($result);
  1648. }
  1649. /**
  1650. * 前端-获取网站调查问卷
  1651. * @param array $data
  1652. * @return array
  1653. */
  1654. public function getWebsiteSurvey(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. }
  1662. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1663. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1664. if (empty($article)) {
  1665. return Result::error("暂无此文章", 0);
  1666. }
  1667. // return Result::error($data,0);
  1668. $where['art_id'] = $data['art_id'];
  1669. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1670. } else {
  1671. $survey = Article::where(function ($query) {
  1672. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1673. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1674. })
  1675. ->where('status', 1)
  1676. ->where('is_survey', 1)
  1677. ->select('survey_id')
  1678. ->orderBy('updated_at', 'desc')
  1679. ->first();
  1680. if (empty($survey)) {
  1681. return Result::error("暂无调查问卷", 0);
  1682. }
  1683. $where['sur_id'] = $survey['survey_id'];
  1684. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1685. }
  1686. // return Result::success($where);
  1687. $result = ArticleSurvey::where($where)
  1688. ->where(function ($query) {
  1689. $query->where('is_other', 0)
  1690. ->orWhere(function ($subQuery) {
  1691. $subQuery->where('is_other', 1)
  1692. ->where('other_id', 0);
  1693. });
  1694. })
  1695. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1696. ->select('article_survey.*', 'article.survey_type')
  1697. ->get()->all();
  1698. if (empty($result)) {
  1699. return Result::error("此文章暂无调查问卷", 0);
  1700. }
  1701. return Result::success($result);
  1702. }
  1703. /**
  1704. * 前端-添加网站调查问卷选项
  1705. * @param array $data
  1706. * @return array
  1707. */
  1708. public function addWebsiteSurveyOption(array $data): array
  1709. {
  1710. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1711. $website = Website::where('id', $data['website_id'])->first();
  1712. if (empty($website)) {
  1713. return Result::error("暂无此网站", 0);
  1714. }
  1715. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1716. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1717. if (empty($survey)) {
  1718. return Result::error("此调查问卷不可添加选项", 0);
  1719. }
  1720. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1721. $choice = [
  1722. 'art_id' => $survey['art_id'],
  1723. 'website_id' => $data['website_id'],
  1724. 'survey_name' => $survey['survey_name'],
  1725. 'choice_name' => $data['choice_name'],
  1726. 'sur_id' => $survey['sur_id'],
  1727. 'is_other' => 1,
  1728. 'other_id' => $survey['id'],
  1729. ];
  1730. $result = ArticleSurvey::insertGetId($choice);
  1731. if (empty($result)) {
  1732. return Result::error("添加失败", 0);
  1733. }
  1734. return Result::success($result);
  1735. }
  1736. }
  1737. return Result::error("添加失败", 0);
  1738. }
  1739. return Result::error("添加失败", 0);
  1740. }
  1741. /**
  1742. * 前端-调查问卷投票
  1743. * @param array $data
  1744. * @return array
  1745. */
  1746. public function addWebsiteSurveyVote(array $data): array
  1747. {
  1748. // return Result::success($data);
  1749. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1750. $website = Website::where('id', $data['website_id'])->first();
  1751. if (empty($website)) {
  1752. return Result::error("暂无此网站", 0);
  1753. }
  1754. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1755. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1756. // return Result::success($survey);
  1757. if (empty($is_survey)) {
  1758. return Result::error("此调查问卷不存在", 0);
  1759. }
  1760. // return Result::success($survey);
  1761. // 调查问卷类型
  1762. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1763. //多选 若是json型则转化成数组类型
  1764. if (strpos($data['choice_id'], '[') === 0) {
  1765. $data['choice_id'] = json_decode($data['choice_id'], true);
  1766. } else {
  1767. // 单选 也转换成数组
  1768. $data['choice_id'] = [$data['choice_id']];
  1769. }
  1770. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1771. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1772. // ->where('website_id',$data['website_id'])
  1773. ->where('is_other', 1)
  1774. ->where('other_id', 0)
  1775. ->first();
  1776. if (!empty($other)) {
  1777. return Result::error("请选择已有的选项!", 0);
  1778. }
  1779. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1780. // ->where('website_id',$data['website_id'])
  1781. ->where('is_other', 1)
  1782. ->where('other_id', '!=', 0)
  1783. ->first();
  1784. // return Result::success($choice['other']);
  1785. $choice_id = $data['choice_id'];
  1786. if (!empty($choice['other'])) {
  1787. // array_push($data['choice_id'],$choice['other']['other_id']);
  1788. if (!empty($choice_id)) {
  1789. $key = array_search($choice['other']['id'], $choice_id);
  1790. if ($key !== false) {
  1791. unset($choice_id[$key]);
  1792. $choice_id = array_values($choice_id);
  1793. }
  1794. array_push($choice_id, $choice['other']['other_id']);
  1795. } else {
  1796. $choice_id[0] = $choice['other']['other_id'];
  1797. }
  1798. array_push($data['choice_id'], $choice['other']['other_id']);
  1799. }
  1800. // return Result::success($data);
  1801. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1802. // ->where('website_id',$data['website_id'])
  1803. ->increment('results', 1);
  1804. if (empty($choice)) {
  1805. return Result::error("请选择已有的选项!", 0);
  1806. }
  1807. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1808. // ->where('website_id',$data['website_id'])
  1809. ->where('other_id', 0)
  1810. ->get();
  1811. $survey['choice'] = $choice_id;
  1812. return Result::success($survey);
  1813. }
  1814. return Result::error("参数必填!");
  1815. }
  1816. return Result::error("此调查问卷不存在", 0);
  1817. }
  1818. return Result::error("参数必填!");
  1819. }
  1820. /**
  1821. * 后端-获取网站调查问卷列表
  1822. * @param array $data
  1823. * @return array
  1824. */
  1825. public function getSurveyList(array $data): array
  1826. {
  1827. $where = [];
  1828. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1829. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1830. }
  1831. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1832. if (!empty($where)) {
  1833. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1834. $query = ArticleSurvey::select(
  1835. 'art_id as id',
  1836. Db::raw('MAX(id) as surid'),
  1837. Db::raw('MAX(survey_name) as survey_name'),
  1838. Db::raw('MAX(sur_id) as survey_id')
  1839. )
  1840. ->groupBy('art_id')
  1841. ->where($where)
  1842. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1843. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1844. $sub->select('id')
  1845. ->from('article')
  1846. ->where('survey_type', $survey_type);
  1847. });
  1848. })
  1849. ->with(['article' => function ($query) {
  1850. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1851. }]);
  1852. ;
  1853. }else{
  1854. $query = ArticleSurvey::select(
  1855. 'art_id as id',
  1856. Db::raw('MAX(id) as surid'),
  1857. Db::raw('MAX(survey_name) as survey_name'),
  1858. Db::raw('MAX(sur_id) as survey_id'),
  1859. )
  1860. ->groupBy('art_id')
  1861. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1862. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1863. $sub->select('id')
  1864. ->from('article')
  1865. ->where('survey_type', $survey_type);
  1866. });
  1867. })
  1868. ->with(['article' => function ($query) {
  1869. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1870. }]);
  1871. }
  1872. $count = $query->get()->count();
  1873. // 简单写法:直接统计分组后的 art_id 数量
  1874. $survey = $query->orderBy('id', 'desc')
  1875. ->limit($data['pageSize'])
  1876. ->offset(($data['page'] - 1) * $data['pageSize'])
  1877. ->get();
  1878. if (empty($survey->toArray())) {
  1879. return Result::error("暂无调查问卷!", 0);
  1880. }
  1881. $survey = array_map(function ($item) {
  1882. $item['survey_type'] = $item['article']['survey_type'];
  1883. $item['created_at'] = $item['article']['created_at'];
  1884. $item['updated_at'] = $item['article']['updated_at'];
  1885. unset($item['article']);
  1886. return $item;
  1887. }, $survey->toArray());
  1888. $result = [
  1889. 'rows' => $survey,
  1890. 'count' => $count,
  1891. ];
  1892. return Result::success($result);
  1893. }
  1894. /**
  1895. * 后端-获取网站调查问卷详情
  1896. * @param array $data
  1897. * @return array
  1898. */
  1899. public function getSurveyInfo(array $data): array
  1900. {
  1901. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1902. $where = ['sur_id' => $data['sur_id']];
  1903. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1904. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1905. ->select('article_survey.*', 'article.survey_type')
  1906. ->get()->all();
  1907. if (empty($choose)) {
  1908. return Result::error("此调查问卷不存在", 0);
  1909. }
  1910. $resultsArray = array_column($choose, 'results');
  1911. $total = array_sum($resultsArray);
  1912. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1913. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1914. // $total = 0;
  1915. if (!empty($other)) {
  1916. $total = $total + $other['results'];
  1917. $other['choice_name'] = '(其他)';
  1918. if (!empty($others)) {
  1919. $other['hasChildren'] = true;
  1920. // array_push($other,['hasChildren','=',true]);
  1921. $other['children'] = $others;
  1922. $other_choices = [$other->toArray()];
  1923. $mer_choice = array_merge($choose, $other_choices);
  1924. $value_choice = array_values($mer_choice);
  1925. } else {
  1926. // return Result::error('1111');
  1927. $other_choices = [$other->toArray()];
  1928. $other_choices = array_merge($choose, $other_choices);
  1929. $value_choice = array_values($other_choices);
  1930. // return Result::success($result);
  1931. }
  1932. } else {
  1933. $value_choice = $choose;
  1934. }
  1935. $result = [
  1936. 'choose' => $value_choice,
  1937. 'total' => $total,
  1938. ];
  1939. }
  1940. return Result::success($result);
  1941. }
  1942. /**
  1943. * 前端-搜索新闻列表
  1944. * @param array $data
  1945. * @return array
  1946. */
  1947. public function selectWebsiteArticle(array $data): array
  1948. {
  1949. $website = Website::where('id', $data['website_id'])->first();
  1950. if (empty($website)) {
  1951. return Result::error("网站不存在", 0);
  1952. }
  1953. // $website_column = $website['column'];
  1954. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1955. $website_column = json_decode($website['website_column_arr_id'], true);
  1956. }
  1957. $website_id = $data['website_id'];
  1958. $categorys = $this->processArticlePro($website_id);
  1959. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1960. // return Result::success($diff_pid_categoryIds);
  1961. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1962. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1963. }
  1964. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1965. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1966. $catiall = $categorys['catiall'];
  1967. $categoryIds = $categorys['categoryIds'];
  1968. // return Result::success($categoryIds);
  1969. $query = Article::where('status', 1)
  1970. ->whereIn('catid', $categoryIds)
  1971. ->leftJoinSub(function ($query) use ($website_id) {
  1972. $query->from('article_ignore')
  1973. ->where('website_id', $website_id);
  1974. }, 'article_ignore', function ($join) {
  1975. $join->on('article_ignore.article_id', '=', 'article.id');
  1976. })
  1977. ->where(function ($query) {
  1978. $query->whereNull('article_ignore.article_id')
  1979. ->orWhere(function ($subQuery) {
  1980. $subQuery->whereNotNull('article_ignore.article_id')
  1981. ->where('article_ignore.is_ignore', 0)
  1982. ->where(function ($subSubQuery) {
  1983. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1984. ->orWhereNull('article_ignore.c_show_time');
  1985. });
  1986. });
  1987. });
  1988. // ->get()->all();
  1989. // return Result::success($query);
  1990. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1991. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1992. }
  1993. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1994. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1995. }
  1996. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1997. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1998. }
  1999. // 计算总数
  2000. $count = $query->count();
  2001. // return Result::success($count);
  2002. // 分页查询
  2003. $articles = $query
  2004. ->select(
  2005. 'article.id',
  2006. 'article.title',
  2007. 'article.imgurl',
  2008. 'article.author',
  2009. 'article.updated_at',
  2010. 'article.introduce',
  2011. 'article.islink',
  2012. 'article.linkurl',
  2013. 'article.copyfrom',
  2014. 'article.cat_arr_id',
  2015. 'article.catid',
  2016. 'article.department_arr_id',
  2017. 'article.city_arr_id',
  2018. // 'article_ignore.c_show_time',
  2019. // 'article_ignore.is_ignore'
  2020. )
  2021. ->orderBy("updated_at", "desc")
  2022. ->offset(($data['page'] - 1) * $data['pageSize'])
  2023. ->limit($data['pageSize'])
  2024. ->get();
  2025. // return Result::success($articles);
  2026. foreach ($articles as $k => $v) {
  2027. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2028. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2029. }
  2030. if (empty($articles)) {
  2031. return Result::error("没有符合条件的资讯数据");
  2032. }
  2033. $result = [
  2034. 'rows' => $articles,
  2035. 'count' => $count,
  2036. ];
  2037. return Result::success($result);
  2038. }
  2039. /**
  2040. * 模块新闻加强版
  2041. * @param array $data
  2042. * @return array
  2043. */
  2044. public function getWebsiteCatidArticle(array $data): array
  2045. {
  2046. $where = [
  2047. 'website_category.category_id' => $data['catid'],
  2048. 'website_category.website_id' => $data['website_id'],
  2049. ];
  2050. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2051. $child_catnum = $data['child_catnum'] ?? 1;
  2052. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2053. $childCategoryIds = array_column($category['child'], 'category_id');
  2054. if (empty($childCategoryIds)) {
  2055. return Result::error("暂无子栏目", 0);
  2056. }
  2057. $imgArticles = [];
  2058. $textArticles = [];
  2059. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2060. // 初始化子分类图片新闻和文字新闻数组
  2061. // 查询所有子级栏目的图文新闻
  2062. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2063. ->where(function ($query) use ($data) {
  2064. $query->where(function ($subQuery) use ($data) {
  2065. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2066. })->orWhereNull("ignore_ids");
  2067. })
  2068. ->where('status', 1)
  2069. ->where('imgurl', '!=', '')
  2070. ->select('*')
  2071. ->orderBy('updated_at', 'desc')
  2072. ->limit($data['child_imgnum'])
  2073. ->get();
  2074. }
  2075. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2076. // 查询所有子级栏目的文字新闻
  2077. $textArticles = Article::where('catid', $childCategoryIds[0])
  2078. ->where('status', 1)
  2079. ->where(function ($query) use ($data) {
  2080. $query->where(function ($subQuery) use ($data) {
  2081. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2082. })->orWhereNull("ignore_ids");
  2083. })
  2084. ->select('*')
  2085. ->orderBy('updated_at', 'desc')
  2086. ->limit($data['child_textnum'])
  2087. ->get();
  2088. }
  2089. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2090. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2091. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2092. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2093. return $child;
  2094. }, $category['child']);
  2095. }
  2096. // }
  2097. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2098. $category['img'] = WebsiteCategory::where($where)
  2099. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2100. ->where('article.status', 1)
  2101. ->where('article.imgurl', '!=', '')
  2102. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2103. ->orderBy('article.updated_at', 'desc')
  2104. ->limit($data['img_num'])
  2105. ->get();
  2106. }
  2107. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2108. $category['text'] = WebsiteCategory::where($where)
  2109. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2110. ->where('article.status', 1)
  2111. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2112. ->orderBy('article.updated_at', 'desc')
  2113. ->limit($data['text_num'])
  2114. ->get();
  2115. }
  2116. // $category = $category->get();
  2117. if (empty($category)) {
  2118. return Result::error("查询失败", 0);
  2119. }
  2120. return Result::success($category);
  2121. }
  2122. /**
  2123. * 模块新闻加强plus版
  2124. * @param array $data
  2125. * @return array
  2126. */
  2127. public function getWebsiteAllArticle(array $data): array
  2128. {
  2129. // return Result::success($data);
  2130. $time1 = microtime(true);
  2131. $wetbsite_id = $data['website_id'] ?? 2;
  2132. $data = json_decode($data['id'], true);
  2133. $website = Website::where('id', $wetbsite_id)->first();
  2134. if (empty($website)) {
  2135. return Result::error("网站不存在", 0);
  2136. }
  2137. // return Result::success($website);
  2138. $website_column = $website['website_column_arr_id'] ?? '[]';
  2139. $website_column = json_decode($website_column, true);
  2140. $categorys = $this->processArticlePro($wetbsite_id);
  2141. $cat_1st_arr = $categorys['cat_1st_arr'];
  2142. $catiall = $categorys['catiall'];
  2143. // return Result::success($catiall);
  2144. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2145. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2146. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2147. }
  2148. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2149. // return Result::success($categorys);
  2150. $parent_category = array_column($data, 'parent');
  2151. $parent_cat = [];
  2152. $child_category = array_column($data, 'child');
  2153. if (!empty($parent_category)) {
  2154. foreach ($parent_category as $key => $value) {
  2155. $arr = array_map('intval', explode(',', $value));
  2156. $parent_cat[$key] = $arr[0] ?? 0;
  2157. $parent_category = $arr[0] ?? 0;
  2158. $article_imgnum = $arr[1] ?? 0;
  2159. $article_textnum = $arr[2] ?? 0;
  2160. if ($parent_category != 0) {
  2161. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2162. // return Result::success($category_arr);
  2163. if ($article_imgnum != 0) {
  2164. $img_article = Article::whereIn('catid', $category_arr)
  2165. ->where('status', 1)
  2166. ->where('imgurl', '!=', '')
  2167. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2168. $query->from('article_ignore')
  2169. ->where('website_id', $wetbsite_id);
  2170. }, 'article_ignore', function ($join) {
  2171. $join->on('article_ignore.article_id', '=', 'article.id');
  2172. })
  2173. ->where(function ($query) {
  2174. $query->whereNull('article_ignore.article_id')
  2175. ->orWhere(function ($subQuery) {
  2176. $subQuery->whereNotNull('article_ignore.article_id')
  2177. ->where('article_ignore.is_ignore', 0)
  2178. ->where(function ($subSubQuery) {
  2179. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2180. ->orWhereNull('article_ignore.c_show_time');
  2181. });
  2182. });
  2183. })
  2184. ->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')
  2185. ->orderBy('updated_at', 'desc')
  2186. ->limit($article_imgnum)
  2187. ->get()->all();
  2188. foreach ($img_article as $k => $v) {
  2189. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2190. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2191. }
  2192. } else {
  2193. $img_article = [];
  2194. }
  2195. if ($article_textnum != 0) {
  2196. $text_article = Article::whereIn('catid', $category_arr)
  2197. ->where('status', 1)
  2198. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2199. $query->from('article_ignore')
  2200. ->where('website_id', $wetbsite_id);
  2201. }, 'article_ignore', function ($join) {
  2202. $join->on('article_ignore.article_id', '=', 'article.id');
  2203. })
  2204. ->where(function ($query) {
  2205. $query->whereNull('article_ignore.article_id')
  2206. ->orWhere(function ($subQuery) {
  2207. $subQuery->whereNotNull('article_ignore.article_id')
  2208. ->where('article_ignore.is_ignore', 0)
  2209. ->where(function ($subSubQuery) {
  2210. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2211. ->orWhereNull('article_ignore.c_show_time');
  2212. });
  2213. });
  2214. })
  2215. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2216. ->orderBy('updated_at', 'desc')
  2217. ->limit($article_textnum)
  2218. ->get()->all();
  2219. foreach ($text_article as $k => $v) {
  2220. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2221. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2222. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2223. }
  2224. } else {
  2225. $text_article = [];
  2226. }
  2227. $catiall[$parent_category]['imgnum'] = $img_article;
  2228. $catiall[$parent_category]['textnum'] = $text_article;
  2229. $parent[$key] = $catiall[$parent_category];
  2230. } else {
  2231. $parent[$key] = '';
  2232. }
  2233. }
  2234. }
  2235. if (!empty($child_category)) {
  2236. foreach ($child_category as $key => $value) {
  2237. $arr = array_map('intval', explode(',', $value));
  2238. $parent_category = $parent_cat[$key];
  2239. $child_category = $arr[0] ?? 0;
  2240. $article_imgnum = $arr[1] ?? 0;
  2241. $article_textnum = $arr[2] ?? 0;
  2242. if ($child_category != 0) {
  2243. $all_childcat = $cat_1st_arr[$parent_category];
  2244. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2245. // 从 $websiteInfoIndexed 中获取对应的数据
  2246. $info = $websiteInfoIndexed[$v];
  2247. // 返回一个包含所需信息的数组
  2248. return [
  2249. 'alias' => $info->alias,
  2250. 'category_id' => $info->category_id,
  2251. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2252. 'pid' => $info->pid,
  2253. 'type' => $info->type,
  2254. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2255. 'pinyin' => $info->pinyin,
  2256. ];
  2257. }, $all_childcat);
  2258. if ($article_imgnum != 0) {
  2259. $img_article = Article::where('catid', $child_category)
  2260. ->where('status', 1)
  2261. ->where('imgurl', '!=', '')
  2262. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2263. $query->from('article_ignore')
  2264. ->where('website_id', $wetbsite_id);
  2265. }, 'article_ignore', function ($join) {
  2266. $join->on('article_ignore.article_id', '=', 'article.id');
  2267. })
  2268. ->where(function ($query) {
  2269. $query->whereNull('article_ignore.article_id')
  2270. ->orWhere(function ($subQuery) {
  2271. $subQuery->whereNotNull('article_ignore.article_id')
  2272. ->where('article_ignore.is_ignore', 0)
  2273. ->where(function ($subSubQuery) {
  2274. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2275. ->orWhereNull('article_ignore.c_show_time');
  2276. });
  2277. });
  2278. })
  2279. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2280. ->orderBy('updated_at', 'desc')
  2281. ->limit($article_imgnum)
  2282. ->get()->all();
  2283. foreach ($img_article as $k => $v) {
  2284. // var_dump($v);
  2285. // var_dump($k);
  2286. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2287. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2288. }
  2289. } else {
  2290. $img_article = [];
  2291. }
  2292. if ($article_textnum != 0) {
  2293. $text_article = Article::where('catid', $child_category)
  2294. ->where('status', 1)
  2295. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2296. $query->from('article_ignore')
  2297. ->where('website_id', $wetbsite_id);
  2298. }, 'article_ignore', function ($join) {
  2299. $join->on('article_ignore.article_id', '=', 'article.id');
  2300. })
  2301. ->where(function ($query) {
  2302. $query->whereNull('article_ignore.article_id')
  2303. ->orWhere(function ($subQuery) {
  2304. $subQuery->whereNotNull('article_ignore.article_id')
  2305. ->where('article_ignore.is_ignore', 0)
  2306. ->where(function ($subSubQuery) {
  2307. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2308. ->orWhereNull('article_ignore.c_show_time');
  2309. });
  2310. });
  2311. })
  2312. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2313. ->orderBy('updated_at', 'desc')
  2314. ->limit($article_textnum)
  2315. ->get()->all();
  2316. foreach ($text_article as $k => $v) {
  2317. // var_dump($v);
  2318. // var_dump($k);
  2319. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2320. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2321. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2322. }
  2323. } else {
  2324. $text_article = [];
  2325. }
  2326. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2327. $catiall[$child_category]['imgnum'] = $img_article;
  2328. $catiall[$child_category]['textnum'] = $text_article;
  2329. $child[$key] = $catiall[$child_category];
  2330. // var_dump($pids);
  2331. } else {
  2332. $child[$key] = '';
  2333. }
  2334. }
  2335. }
  2336. foreach ($parent as $key => $value) {
  2337. $result[$key] = $value;
  2338. if (!empty($child[$key])) {
  2339. // var_dump($child[$key]);
  2340. $result[$key]['child'] = $child[$key];
  2341. // $value[$key]['child'] = $child[$key];
  2342. } else {
  2343. $result[$key]['child'] = [
  2344. "alias" => null,
  2345. "category_id" => null,
  2346. "type" => null,
  2347. "pinyin" => null,
  2348. "all_childcat" => [],
  2349. "imgnum" => [],
  2350. "textnum" => []
  2351. ];
  2352. }
  2353. }
  2354. return Result::success($result);
  2355. }
  2356. /**
  2357. * 辅助方法:获取文章列表
  2358. */
  2359. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2360. {
  2361. sleep(1);
  2362. $query = Article::where('article.status', 1)
  2363. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2364. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2365. ->where(function ($query) use ($website) {
  2366. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2367. })
  2368. ->leftJoin('website_category', function ($join) use ($website) {
  2369. $join->on('article.catid', '=', 'website_category.category_id')
  2370. ->where('website_category.website_id', '=', $website['website_id']);
  2371. })
  2372. ->select(
  2373. 'article.id',
  2374. 'article.title',
  2375. 'article.imgurl',
  2376. 'article.author',
  2377. 'article.updated_at',
  2378. 'article.introduce',
  2379. 'article.islink',
  2380. 'article.linkurl',
  2381. 'article.copyfrom',
  2382. 'article.cat_arr_id',
  2383. 'article.catid',
  2384. 'website_category.alias as category_name'
  2385. )
  2386. ->orderBy('updated_at', 'desc')
  2387. ->limit($limit);
  2388. // 如果是图片文章,添加图片URL条件
  2389. if ($isImageArticle) {
  2390. $query->where('imgurl', '!=', '');
  2391. } else {
  2392. // 文字文章不需要imgurl字段
  2393. $query->addSelect('article.introduce');
  2394. }
  2395. $articles = $query->get();
  2396. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2397. }
  2398. /**
  2399. * 乡村网-获取特殊新闻模块
  2400. * @param array $data
  2401. * @return array
  2402. */
  2403. public function getWebsiteArticles(array $data): array
  2404. {
  2405. $website_id = $data['website_id'];
  2406. $website = Website::where('id', $website_id)->first();
  2407. if (empty($website)) {
  2408. return Result::error("网站不存在", 0);
  2409. }
  2410. // return Result::success($website);
  2411. $website_column = $website['website_column_arr_id'] ?? '[]';
  2412. $website_column = json_decode($website_column, true);
  2413. $catids = json_decode($data['id'], true);
  2414. $parent_category = array_column($catids, 'parent');
  2415. if (!empty($parent_category) && is_array($parent_category)) {
  2416. $categorys = $this->processArticlePro($website_id);
  2417. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2418. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2419. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2420. }
  2421. $catiall = $categorys['catiall'];
  2422. $cat_1st_arr = $categorys['cat_1st_arr'];
  2423. // return Result::success($categorys);
  2424. foreach ($parent_category as $key => $value) {
  2425. $arr = array_map('intval', explode(',', $value));
  2426. $parent_category = $arr[0] ?? 0;
  2427. $article_imgnum = $arr[1] ?? 0;
  2428. $article_textnum = $arr[2] ?? 0;
  2429. if ($parent_category != 0) {
  2430. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2431. // return Result::success($category_arr);
  2432. if ($article_imgnum != 0) {
  2433. $img_article = Article::whereIn('article.catid', $category_arr)
  2434. ->where('article.status', 1)
  2435. ->where('article.imgurl', '!=', '')
  2436. ->leftJoinSub(function ($query) use ($website_id) {
  2437. $query->from('article_ignore')
  2438. ->where('website_id', $website_id);
  2439. }, 'article_ignore', function ($join) {
  2440. $join->on('article_ignore.article_id', '=', 'article.id');
  2441. })
  2442. ->where(function ($query) {
  2443. $query->whereNull('article_ignore.article_id')
  2444. ->orWhere(function ($subQuery) {
  2445. $subQuery->whereNotNull('article_ignore.article_id')
  2446. ->where('article_ignore.is_ignore', 0)
  2447. ->where(function ($subSubQuery) {
  2448. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2449. ->orWhereNull('article_ignore.c_show_time');
  2450. });
  2451. });
  2452. })
  2453. ->select(
  2454. 'article.id',
  2455. 'article.title',
  2456. 'article.imgurl',
  2457. 'article.author',
  2458. 'article.updated_at',
  2459. 'article.introduce',
  2460. 'article.islink',
  2461. 'article.linkurl',
  2462. 'article.copyfrom',
  2463. 'article.cat_arr_id',
  2464. 'article.catid as category_id'
  2465. )
  2466. ->orderBy('updated_at', 'desc')
  2467. ->limit($article_imgnum)
  2468. ->get()->all();
  2469. foreach ($img_article as $k => $v) {
  2470. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2471. // return Result::success($v);
  2472. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2473. }
  2474. } else {
  2475. $img_article = [];
  2476. }
  2477. if ($article_textnum != 0) {
  2478. $text_article = Article::whereIn('article.catid', $category_arr)
  2479. ->where('article.status', 1)
  2480. ->leftJoinSub(function ($query) use ($website_id) {
  2481. $query->from('article_ignore')
  2482. ->where('website_id', $website_id);
  2483. }, 'article_ignore', function ($join) {
  2484. $join->on('article_ignore.article_id', '=', 'article.id');
  2485. })
  2486. ->where(function ($query) {
  2487. $query->whereNull('article_ignore.article_id')
  2488. ->orWhere(function ($subQuery) {
  2489. $subQuery->whereNotNull('article_ignore.article_id')
  2490. ->where('article_ignore.is_ignore', 0)
  2491. ->where(function ($subSubQuery) {
  2492. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2493. ->orWhereNull('article_ignore.c_show_time');
  2494. });
  2495. });
  2496. })
  2497. ->select(
  2498. 'article.id',
  2499. 'article.title',
  2500. 'article.author',
  2501. 'article.updated_at',
  2502. 'article.introduce',
  2503. 'article.islink',
  2504. 'article.linkurl',
  2505. 'article.copyfrom',
  2506. 'article.cat_arr_id',
  2507. 'article.catid as category_id'
  2508. )
  2509. ->orderBy('updated_at', 'desc')
  2510. ->limit($article_textnum)
  2511. ->get()->all();
  2512. foreach ($text_article as $k => $v) {
  2513. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2514. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2515. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2516. }
  2517. } else {
  2518. $text_article = [];
  2519. }
  2520. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2521. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2522. $parent[$key] = $catiall[$parent_category];
  2523. } else {
  2524. $parent[$key] = [];
  2525. }
  2526. }
  2527. }
  2528. return Result::success($parent);
  2529. }
  2530. // 封装处理商品的路由问题
  2531. function processGoods($goods, $data)
  2532. {
  2533. return $goods->map(function ($good) use ($data) {
  2534. $catid = $good->catid ?? 0;
  2535. // $pinyin = '';
  2536. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2537. if (!empty($category->pid) && $category->pid != 0) {
  2538. $level = json_decode($category->category_arr_id, true);
  2539. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2540. ->whereIn('category_id', $level)
  2541. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2542. ->get(['aLIas_pinyin'])
  2543. ->pluck('aLIas_pinyin')
  2544. ->implode('/');
  2545. } else {
  2546. $pinyin = $category->aLIas_pinyin ?? '';
  2547. }
  2548. if (isset($good->city_id) && !empty($good->city_id)) {
  2549. $city = District::where('id', $good->city_id)->first(['name']);
  2550. $good->city_name = $city->name ?? '';
  2551. }
  2552. // 解析imgurl JSON并取第一条数据
  2553. $imgUrls = json_decode($good->imgurl, true);
  2554. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2555. $good->pinyin = $pinyin;
  2556. return $good;
  2557. });
  2558. }
  2559. /**
  2560. * 获取商城首页-根据栏目id
  2561. * @param array $data
  2562. * @return array
  2563. * */
  2564. function getWebsiteCatidshop(array $data): array
  2565. {
  2566. $input['catid'] = $data['catid'];
  2567. $input['website_id'] = $data['website_id'];
  2568. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2569. $result = array_map(function ($item) use ($input) {
  2570. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2571. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2572. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2573. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2574. if (empty($category) || $category->type != 2) {
  2575. return Result::error("暂无此栏目", 0);
  2576. } else {
  2577. $website['website_id'] = $input['website_id'];
  2578. $goods = Good::where('good.status', 2)
  2579. ->where('good.website_id', $website['website_id'])
  2580. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2581. ->select(
  2582. 'good.id',
  2583. 'good.name',
  2584. 'good.imgurl',
  2585. 'good.description',
  2586. 'good.updated_at',
  2587. 'good.catid',
  2588. 'good.type_id',
  2589. 'good.price',
  2590. 'good.com',
  2591. 'good.level',
  2592. 'good.unit'
  2593. )
  2594. ->orderBy('updated_at', 'desc')
  2595. ->offset($goodStart)
  2596. ->limit($goodNum);
  2597. $all_goods = $goods->get();
  2598. $all_goods = $this->processGoods($all_goods, $website);
  2599. }
  2600. return $all_goods ?? [];
  2601. }
  2602. }, $data);
  2603. return Result::success($result);
  2604. }
  2605. /**
  2606. * 获取商品模块
  2607. * @param array $data
  2608. * @return array
  2609. * */
  2610. public function getWebsiteshop(array $data): array
  2611. {
  2612. $input['id'] = $data['id'];
  2613. $input['website_id'] = $data['website_id'];
  2614. $catid = $data['catid'];
  2615. $data = json_decode($input['id'] ?? '', true) ?? [];
  2616. $result['goods'] = array_map(function ($item) use ($input) {
  2617. // 检查parent元素是否存在且不是undefined
  2618. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2619. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2620. $website = $input['website_id'];
  2621. $query = Good::where('good.status', 2)
  2622. ->where('good.website_id', $website);
  2623. switch ($Levelid) {
  2624. case 1:
  2625. case 2:
  2626. case 3:
  2627. $goods = $query->where(function ($q) use ($Levelid) {
  2628. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2629. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2630. });
  2631. break;
  2632. case 4:
  2633. $goods = $query;
  2634. break;
  2635. case 5:
  2636. $goods = $query->where('type_id', 1);
  2637. break;
  2638. case 6:
  2639. $goods = $query->where('type_id', 2);
  2640. break;
  2641. default:
  2642. return [];
  2643. }
  2644. $all_goods = $goods
  2645. ->select(
  2646. 'good.id',
  2647. 'good.name',
  2648. 'good.imgurl',
  2649. 'good.description',
  2650. 'good.updated_at',
  2651. 'good.catid',
  2652. 'good.type_id',
  2653. 'good.price',
  2654. 'good.level',
  2655. 'good.website_id'
  2656. )
  2657. ->orderBy('updated_at', 'desc')
  2658. ->offset($goodStart)
  2659. ->limit($goodNum)
  2660. ->get();
  2661. $web['website_id'] = $website;
  2662. $all_goods = $this->processGoods($all_goods, $web);
  2663. }
  2664. return $all_goods;
  2665. }, $data);
  2666. $website = $input['website_id'];
  2667. $result['article'] = Article::where(function ($query) use ($website) {
  2668. $query->where(function ($subQuery) use ($website) {
  2669. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2670. })->orWhereNull("ignore_ids");
  2671. })
  2672. ->where('catid', $catid)
  2673. ->where('article.status', 1)
  2674. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2675. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2676. ->orderBy('article.updated_at', 'desc')
  2677. ->first();
  2678. return Result::success($result);
  2679. }
  2680. /**
  2681. * 获取商品分类
  2682. * @param array $data
  2683. * @return array
  2684. * */
  2685. public function getWebsiteshopCat(array $data): array
  2686. {
  2687. $website = $data['website_id'];
  2688. $category = WebsiteCategory::where('website_id', $website)
  2689. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2690. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2691. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2692. ->orderBy('sort')
  2693. ->get();
  2694. $cat = $category->map(function ($item) use ($website) {
  2695. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2696. $pid = $item->pid ?? 0;
  2697. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2698. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2699. ->where('website_id', $website)
  2700. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2701. ->get(['aLIas_pinyin'])
  2702. ->pluck('aLIas_pinyin')
  2703. ->implode('/');
  2704. } else {
  2705. $pinyin = $item->aLIas_pinyin ?? '';
  2706. }
  2707. $item->pinyin = $pinyin;
  2708. });
  2709. if (empty($category)) {
  2710. return Result::error("栏目查询失败", 0);
  2711. }
  2712. $cat_tree = Result::buildMenuTree($category);
  2713. $web['website_id'] = $website;
  2714. $goods = Good::where('website_id', $website)
  2715. ->where('status', 2)
  2716. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2717. ->latest('updated_at')
  2718. ->offset(($data['page'] - 1) * $data['pageSize'])
  2719. ->limit($data['pageSize'])
  2720. ->get();
  2721. if (!empty($goods)) {
  2722. if ($goods->count() > 1 && !empty($goods)) {
  2723. $goods = $this->processGoods($goods, $web);
  2724. }
  2725. } else {
  2726. $goods = [];
  2727. }
  2728. $result = [
  2729. 'category' => $cat_tree,
  2730. 'goods' => $goods,
  2731. ];
  2732. // $resul['goods'] = $goods;
  2733. if (empty($result)) {
  2734. return Result::error("查询失败", 0);
  2735. }
  2736. return Result::success($result);
  2737. }
  2738. /*
  2739. * 获取商品列表
  2740. * @param array $data
  2741. * @return array
  2742. * */
  2743. public function getWebsiteshopList(array $data): array
  2744. {
  2745. // return Result::success($data);
  2746. $where = [
  2747. 'status' => 2,
  2748. 'website_id' => $data['website_id'],
  2749. ];
  2750. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2751. // return Result::error("查询失败", 0);
  2752. // }
  2753. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2754. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2755. $data['catid'] = $category->category_id ?? 0;
  2756. }
  2757. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2758. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2759. }
  2760. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2761. array_push($where, ['type_id', $data['type_id']]);
  2762. }
  2763. $query = Good::where($where)
  2764. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2765. $query->where(function ($q) use ($data) {
  2766. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2767. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2768. });
  2769. })
  2770. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2771. $query->where(function ($q) use ($data) {
  2772. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2773. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2774. });
  2775. })
  2776. ->select(
  2777. 'good.id',
  2778. 'good.name',
  2779. 'good.imgurl',
  2780. 'good.description',
  2781. 'good.updated_at',
  2782. 'good.com',
  2783. 'good.catid',
  2784. 'good.type_id',
  2785. 'good.website_id',
  2786. 'good.cat_arr_id',
  2787. 'good.created_at',
  2788. 'good.city_id'
  2789. )
  2790. ->latest('updated_at');
  2791. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2792. $result['count'] = $query->clone()->count();
  2793. $result['goods'] = $this->processGoods(
  2794. $query->clone()
  2795. ->offset(($data['page'] - 1) * $data['pageSize'])
  2796. ->limit($data['pageSize'])
  2797. ->get(),
  2798. $data
  2799. );
  2800. } else {
  2801. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2802. // 获取 type_id 为 1 的数据
  2803. $result['type1'] = $this->processGoods(
  2804. $query->clone()
  2805. ->where('type_id', 1)
  2806. ->offset(($data['page'] - 1) * $data['pageSize'])
  2807. ->limit($data['pageSize'])
  2808. ->get(),
  2809. $data
  2810. );
  2811. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2812. // 获取 type_id 为 2 的数据
  2813. $result['type2'] = $this->processGoods(
  2814. $query->clone()
  2815. ->where('type_id', 2)
  2816. ->offset(($data['page'] - 1) * $data['pageSize'])
  2817. ->limit($data['pageSize'])
  2818. ->get(),
  2819. $data
  2820. );
  2821. }
  2822. if (empty($result)) {
  2823. return Result::error("查询失败", 0);
  2824. }
  2825. return Result::success($result);
  2826. }
  2827. /**
  2828. * 获取商品详情
  2829. * @param array $data
  2830. * @return array
  2831. * */
  2832. public function getWebsiteshopInfo(array $data): array
  2833. {
  2834. $where = [
  2835. 'good.status' => 2,
  2836. 'good.website_id' => $data['website_id'],
  2837. 'good.id' => $data['id'],
  2838. ];
  2839. $goods = Good::where($where)
  2840. ->where('good.id', $data['id'])
  2841. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2842. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2843. ->first();
  2844. if (empty($goods)) {
  2845. return Result::error("查询失败", 0);
  2846. }
  2847. $goods->imgurl = json_decode($goods->imgurl, true);
  2848. return Result::success($goods);
  2849. }
  2850. /**
  2851. * plus pro 处理文章路由问题
  2852. */
  2853. function processArticlePro($website_id)
  2854. {
  2855. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2856. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2857. // // 取出category_id 对应的aLIas_pinyin
  2858. // $categoryIds = array_column($categorys, 'category_id');
  2859. // $categoryPIds = array_column($categorys, 'pid');
  2860. // $aliasPinyins = array_column($categorys, 'path');
  2861. // $alias = array_column($categorys, 'alias');
  2862. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2863. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2864. // // return Result::success($cat_arr);
  2865. // // $catiall = [];
  2866. // //一级所有子级的记录
  2867. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2868. // return [
  2869. // 'cat_1st_arr' => $cat_alias_arr,
  2870. // 'catiall' => $cat_arr,
  2871. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2872. // 'categoryIds' => $categoryIds,
  2873. // ];
  2874. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2875. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2876. // 取出category_id 对应的aLIas_pinyin
  2877. $categoryIds = array_column($categorys, 'category_id');
  2878. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2879. return $pid != 0;
  2880. })));
  2881. $category_path = array_column($categorys, 'path');
  2882. $cat_arr = array_combine($categoryIds, $category_path);
  2883. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2884. $catiall = [];
  2885. //一级所有子级的记录
  2886. $cat_1st_arr = [];
  2887. foreach ($categorys as $key => $value) {
  2888. // $category_arr_id = json_decode($value->category_arr_id);
  2889. // $pinyin_str = '';
  2890. // // 算出一级 并且算出子级
  2891. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2892. $cat_1st_arr[$value->pid][] = $value->category_id;
  2893. }
  2894. // foreach ($category_arr_id as $k => $v) {
  2895. // $pinyin_str .= $cat_arr[$v] . '/';
  2896. // }
  2897. // $pinyin_str = rtrim($pinyin_str, '/');
  2898. $catiall[$value->category_id]['alias'] = $value->alias;
  2899. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2900. $catiall[$value->category_id]['type'] = $value->type;
  2901. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2902. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2903. }
  2904. return [
  2905. 'cat_1st_arr' => $cat_1st_arr,
  2906. 'catiall' => $catiall,
  2907. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2908. 'categoryIds' => $categoryIds,
  2909. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2910. 'categoryPIds' => $categoryPIds,
  2911. ];
  2912. }
  2913. /**
  2914. * 封装处理文章的路由问题
  2915. * */
  2916. function processArticles($articles, $data)
  2917. {
  2918. // 检查 $articles 是否为数组或可迭代对象
  2919. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2920. return $articles->map(function ($article) use ($data) {
  2921. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2922. $catid = $article->cat_arr_id ?? '';
  2923. }
  2924. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2925. $catid = $article->category_arr_id ?? '';
  2926. }
  2927. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2928. $level = json_decode($catid, true);
  2929. if (!is_array($level)) {
  2930. return $article;
  2931. } else {
  2932. $level = array_map('intval', $level);
  2933. }
  2934. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2935. ->where($data)
  2936. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2937. ->pluck('aLIas_pinyin')
  2938. ->implode('/');
  2939. $article->pinyin = $pinyin ?? '';
  2940. return $article;
  2941. });
  2942. } else {
  2943. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2944. $catid = $articles->cat_arr_id ?? '';
  2945. $level = json_decode($catid, true);
  2946. if (!is_array($level)) {
  2947. return $articles;
  2948. } else {
  2949. $level = array_map('intval', $level);
  2950. }
  2951. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2952. ->where($data)
  2953. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2954. ->pluck('aLIas_pinyin')
  2955. ->implode('/');
  2956. $articles->pinyin = $pinyin ?? '';
  2957. return $articles;
  2958. }
  2959. }
  2960. // 封装处理由问题
  2961. function processJob($job, $data)
  2962. {
  2963. return $job->map(function ($job) use ($data) {
  2964. $category = $job->cat_arr_id ?? '';
  2965. $cityid = $job->city_arr_id ?? '';
  2966. $city = json_decode($cityid, true);
  2967. $pinyin = '';
  2968. $level = json_decode($category, true);
  2969. // 路由
  2970. if (!empty($level) && is_array($level)) {
  2971. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2972. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2973. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2974. ->get(['aLIas_pinyin'])
  2975. ->pluck('aLIas_pinyin')
  2976. ->implode('/');
  2977. if (empty($pinyin)) {
  2978. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2979. }
  2980. $job->pinyin = $pinyin;
  2981. }
  2982. // 取职位-城市 市??省
  2983. if (!empty($city) && is_array($city)) {
  2984. if (isset($city[1]) && !empty($city[1])) {
  2985. $city = District::where('id', $city[1])->first(['name']);
  2986. $job->city_name = $city->name ?? '';
  2987. } else if (isset($city[0]) && !empty($city[0])) {
  2988. $city = District::where('id', $city[0])->first(['name']);
  2989. $job->city_name = $city->name ?? '';
  2990. } else {
  2991. $job->city_name = '全国';
  2992. }
  2993. }
  2994. // 获取简历最后一级地区
  2995. if (isset($job->city_id) && !empty($job->city_id)) {
  2996. $city = District::where('id', $job->city_id)->first(['name']);
  2997. $job->hunt_cityname = $city->name ?? '';
  2998. }
  2999. // 组合详细地址
  3000. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3001. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3002. if (is_array($address_id) && !empty($address_id)) {
  3003. $address = District::whereIn('id', $address_id)
  3004. ->orderBy('level', 'asc')
  3005. ->get(['name'])
  3006. ->pluck('name')
  3007. ->implode('');
  3008. // $job->address_name = $address ?? '';
  3009. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3010. }
  3011. }
  3012. // 取行业
  3013. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3014. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3015. if (!empty($job->industry)) {
  3016. $query->where('hyid', $job->industry);
  3017. } else if (!empty($job->hy_id)) {
  3018. $query->where('hyid', $job->hy_id);
  3019. } else if (!empty($job->company_hy_id)) {
  3020. $query->where('hyid', $job->company_hy_id);
  3021. } else {
  3022. $query->where('hyid', $job->job_industry);
  3023. }
  3024. })->first(['hyname']);
  3025. $job->hy_name = $hy_name->hyname ?? '';
  3026. }
  3027. // 取职位类别
  3028. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3029. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3030. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3031. $job->zw_name = $zw_name->zwname ?? '';
  3032. }
  3033. // 取具体职位
  3034. 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))) {
  3035. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3036. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3037. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3038. }
  3039. // 取工作经验
  3040. if (isset($job->experience) && !empty($job->experience)) {
  3041. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3042. $job->experience_name = $experience->ename ?? '';
  3043. }
  3044. // 取学历
  3045. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3046. $education = $job->educational ?? $job->school_education;
  3047. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3048. $job->education_name = $education->ename ?? '';
  3049. }
  3050. // 语言
  3051. if (isset($job->language) && !empty($job->language)) {
  3052. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3053. $job->language_name = $language->ename ?? '';
  3054. }
  3055. // 薪资
  3056. if (isset($job->salary) && !empty($job->salary)) {
  3057. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3058. $job->salary_name = $salary->ename ?? '';
  3059. }
  3060. // 职位性质
  3061. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3062. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3063. $job->job_nature_name = $job_nature->ename ?? '';
  3064. }
  3065. // 公司规模
  3066. if (isset($job->company_size) && !empty($job->company_size)) {
  3067. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3068. $job->company_size_name = $company_size->ename ?? '';
  3069. }
  3070. // 公司性质
  3071. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3072. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3073. $job->company_nature_name = $company_nature->nature_name ?? '';
  3074. }
  3075. // $job->pinyin = $pinyin;
  3076. return $job;
  3077. });
  3078. }
  3079. /**
  3080. * 获取书籍模块
  3081. * @param array $data
  3082. * @return array
  3083. * */
  3084. public function getWebsiteBook(array $data): array
  3085. {
  3086. $input['id'] = $data['id'];
  3087. $input['website_id'] = $data['website_id'];
  3088. // 将 JSON 字符串转换为 PHP 数组
  3089. $data = json_decode($input['id'], true);
  3090. // 使用 array_map 处理每个元素
  3091. $result = array_map(function ($item) use ($input) {
  3092. // 检查parent元素是否存在且不是undefined
  3093. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3094. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3095. $website = [
  3096. 'website_id' => $input['website_id'],
  3097. ];
  3098. // 查询栏目名称
  3099. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3100. if (empty($category)) {
  3101. $parent_alias = '';
  3102. $parent_pinyin = null;
  3103. $imgBooks = [];
  3104. $textBooks = [];
  3105. } else {
  3106. $parent_alias = $category->alias ?? '';
  3107. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3108. // 查找子分类ID数组
  3109. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3110. array_push($childCategoryIds, $parentCatId);
  3111. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3112. if ($parentImgNum != 0) {
  3113. // 查询图片新闻
  3114. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3115. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3116. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3117. })
  3118. ->where('book.status', 2)
  3119. ->where('book.img_url', '!=', '')
  3120. ->where('book.website_id', $website['website_id'])
  3121. ->leftJoin('website_category', function ($join) use ($website) {
  3122. $join->on('book.cat_id', '=', 'website_category.category_id')
  3123. ->where('website_category.website_id', '=', $website['website_id']);
  3124. })
  3125. ->select(
  3126. 'book.id',
  3127. 'book.title',
  3128. 'book.img_url',
  3129. 'book.price',
  3130. 'book.market_price',
  3131. 'book.description',
  3132. 'book.cat_id',
  3133. 'book.description',
  3134. 'book.updated_at',
  3135. 'website_category.alias as category_name',
  3136. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3137. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3138. )
  3139. ->orderBy('updated_at', 'desc')
  3140. ->limit($parentImgNum)
  3141. ->get()->all();
  3142. // 查询文字新闻
  3143. }
  3144. if ($parentTextNum != 0) {
  3145. $textBooks = [];
  3146. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3147. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3148. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3149. })
  3150. ->where('book.status', 2)
  3151. ->where('book.website_id', $website['website_id'])
  3152. ->leftJoin('website_category', function ($join) use ($website) {
  3153. $join->on('book.cat_id', '=', 'website_category.category_id')
  3154. ->where('website_category.website_id', '=', $website['website_id']);
  3155. })
  3156. ->select(
  3157. 'book.id',
  3158. 'book.title',
  3159. 'book.img_url',
  3160. 'book.price',
  3161. 'book.market_price',
  3162. 'book.description',
  3163. 'book.cat_id',
  3164. 'book.description',
  3165. 'book.updated_at',
  3166. 'website_category.alias as category_name',
  3167. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3168. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3169. )
  3170. ->orderBy('updated_at', 'desc')
  3171. ->limit($parentTextNum)
  3172. ->get()->all();
  3173. }
  3174. }
  3175. }
  3176. $resultItem = [
  3177. 'alias' => $parent_alias ?? '',
  3178. 'category_id' => $parentCatId ?? 0,
  3179. 'pinyin' => $parent_pinyin ?? null,
  3180. 'imgnum' => $imgBooks ?? [],
  3181. 'textnum' => $textBooks ?? [],
  3182. ];
  3183. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3184. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3185. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3186. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3187. ->get()->all();
  3188. if (!empty($childCategory)) {
  3189. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3190. // 查询子栏目名称
  3191. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3192. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3193. ->first();
  3194. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3195. $childImgArticles = [];
  3196. $childTextArticles = [];
  3197. $resultItem['child'] = [];
  3198. } else {
  3199. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3200. // 查询子栏目图片新闻
  3201. $childImgArticles = Book::where('cat_id', $childCatId)
  3202. ->where('status', 2)
  3203. ->where('img_url', '!=', '')
  3204. ->where('book.website_id', $website['website_id'])
  3205. ->leftJoin('website_category', function ($join) use ($website) {
  3206. $join->on('book.cat_id', '=', 'website_category.category_id')
  3207. ->where('website_category.website_id', '=', $website['website_id']);
  3208. })
  3209. ->select(
  3210. 'book.id',
  3211. 'book.title',
  3212. 'book.img_url',
  3213. 'book.price',
  3214. 'book.market_price',
  3215. 'book.description',
  3216. 'book.cat_id',
  3217. 'book.description',
  3218. 'book.updated_at',
  3219. DB::raw("'$child_pinyin' as pinyin")
  3220. )
  3221. ->orderBy('updated_at', 'desc')
  3222. ->limit($childImgNum)
  3223. ->get()->all();
  3224. // 查询子栏目文字新闻
  3225. $childTextArticles = Book::where('cat_id', $childCatId)
  3226. ->where('status', 2)
  3227. ->where('book.website_id', $website['website_id'])
  3228. ->leftJoin('website_category', function ($join) use ($website) {
  3229. $join->on('book.cat_id', '=', 'website_category.category_id')
  3230. ->where('website_category.website_id', '=', $website['website_id']);
  3231. })
  3232. ->select(
  3233. 'book.id',
  3234. 'book.title',
  3235. 'book.img_url',
  3236. 'book.price',
  3237. 'book.market_price',
  3238. 'book.description',
  3239. 'book.cat_id',
  3240. 'book.description',
  3241. 'book.updated_at',
  3242. DB::raw("'$child_pinyin' as pinyin")
  3243. )
  3244. ->orderBy('updated_at', 'desc')
  3245. ->limit($childTextNum)
  3246. ->get()->all();
  3247. $resultItem['child'] = [
  3248. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3249. 'category_id' => $childCatId,
  3250. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3251. 'all_childcat' => $childCategory,
  3252. 'imgnum' => $childImgArticles,
  3253. 'textnum' => $childTextArticles,
  3254. ];
  3255. }
  3256. }
  3257. } else {
  3258. $resultItem['child'] = [];
  3259. }
  3260. return $resultItem;
  3261. }, $data);
  3262. return Result::success($result);
  3263. }
  3264. /**
  3265. * 获取书刊列表
  3266. * @param array $data
  3267. * @return array
  3268. * */
  3269. public function getWebsiteBookList(array $data): array
  3270. {
  3271. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3272. if (empty($web)) {
  3273. return Result::error("查询失败", 0);
  3274. }
  3275. $catid = $data['id'];
  3276. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3277. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3278. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3279. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3280. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3281. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3282. ->where('pid', $category['pid'])
  3283. ->select(
  3284. 'category_id',
  3285. 'alias',
  3286. 'aLIas_pinyin',
  3287. 'pid',
  3288. 'sort',
  3289. 'is_url',
  3290. 'web_url',
  3291. 'seo_title',
  3292. 'seo_keywords',
  3293. 'seo_description',
  3294. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3295. )
  3296. ->orderBy('sort')
  3297. ->get()->all();
  3298. if (empty($category)) {
  3299. return Result::error("查询失败", 0);
  3300. }
  3301. $query = Book::where('book.status', 2)
  3302. ->where('book.website_id', $data['website_id'])
  3303. ->where('book.cat_id', $catid)
  3304. ->select(
  3305. 'book.id',
  3306. 'book.title',
  3307. 'book.img_url',
  3308. 'book.description',
  3309. 'book.updated_at',
  3310. 'book.cat_id',
  3311. DB::raw("'$pinyin' as pinyin")
  3312. )
  3313. ->orderBy('book.updated_at', 'desc');
  3314. $count = $query->count();
  3315. $query = clone $query;
  3316. $Book = $query
  3317. ->limit($data['pageSize'])
  3318. ->offset(($data['page'] - 1) * $data['pageSize'])
  3319. ->get()->all();
  3320. $result = [
  3321. 'category' => $categorys,
  3322. 'books' => $Book,
  3323. 'count' => $count,
  3324. ];
  3325. // if(empty($result)){
  3326. // return Result::error("查询失败", 0);
  3327. // }
  3328. return Result::success($result);
  3329. }
  3330. /**
  3331. * 获取书刊详情
  3332. * @param array $data
  3333. * @return array
  3334. * */
  3335. public function getWebsiteBookInfo(array $data): array
  3336. {
  3337. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3338. if (empty($web)) {
  3339. return Result::error("查询失败", 0);
  3340. }
  3341. $book = Book::where('status', 2)
  3342. ->where('website_id', $data['website_id'])
  3343. ->where('id', $data['id'])
  3344. ->select(
  3345. 'book.*',
  3346. )
  3347. ->orderBy('updated_at', 'desc')
  3348. ->first();
  3349. if (empty($book)) {
  3350. return Result::error("查询失败", 0);
  3351. }
  3352. // 先查询当前分类的 pid
  3353. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3354. ->where('category_id', $book['cat_id'])
  3355. ->first(['pid', 'category_id']);
  3356. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3357. if (!empty($carpid)) {
  3358. if ($carpid->pid != 0) {
  3359. $pid = $carpid['pid'];
  3360. // $parent_pinyin = '';
  3361. } else {
  3362. $pid = $carpid['category_id'];
  3363. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3364. }
  3365. }
  3366. $categorys = $query->where('pid', $pid)
  3367. ->select(
  3368. 'category_id',
  3369. 'alias',
  3370. 'aLIas_pinyin',
  3371. 'pid',
  3372. 'sort',
  3373. 'is_url',
  3374. 'web_url',
  3375. 'category_arr_id as cat_arr_id',
  3376. )
  3377. ->orderBy('sort')
  3378. ->get();
  3379. $category = $this->processArticle($categorys, $data);
  3380. $result = [
  3381. 'category' => $category,
  3382. 'books' => $book,
  3383. ];
  3384. return Result::success($result);
  3385. }
  3386. /**
  3387. * 尝试
  3388. * @param array $data
  3389. * @return array
  3390. * */
  3391. public function test(array $data): array
  3392. {
  3393. $input['id'] = $data['id'];
  3394. $input['website_id'] = $data['website_id'];
  3395. // 将 JSON 字符串转换为 PHP 数组
  3396. $data = json_decode($input['id'], true);
  3397. $result = [];
  3398. $article = $data;
  3399. $result = array_map(function ($item) use ($input) {
  3400. $website = [
  3401. 'website_id' => $input['website_id'],
  3402. ];
  3403. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3404. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3405. $parent = [
  3406. 0 => $category['category_id'] ?? [],
  3407. 1 => $parentImgNum ?? [],
  3408. 2 => $parentTextNum ?? [],
  3409. ];
  3410. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3411. $child = [];
  3412. $resultItem = [
  3413. // 'alias' => $parent_alias ?? '',
  3414. 'category_id' => $parentCatId ?? 0,
  3415. 'pinyin' => $parentImgNum ?? null,
  3416. 'imgnum' => $parentTextNum ?? [],
  3417. // 'textnum' => $textArticles ?? [],
  3418. ];
  3419. return $parent;
  3420. }, $data);
  3421. return Result::success($result);
  3422. // });
  3423. }
  3424. /**
  3425. * 封装处理文章的路由问题
  3426. * */
  3427. function processArticle($article, $data)
  3428. {
  3429. return $article->map(function ($article) use ($data) {
  3430. $catid = $article->cat_arr_id ?? '';
  3431. $level = json_decode($catid, true);
  3432. $pinyin = '';
  3433. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3434. if (!empty($level) && is_array($level)) {
  3435. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3436. ->where('website_id', $data['website_id'])
  3437. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3438. ->get(['aLIas_pinyin'])
  3439. ->pluck('aLIas_pinyin')
  3440. ->implode('/');
  3441. } else {
  3442. $pinyin = '';
  3443. }
  3444. $article->pinyin = $pinyin;
  3445. return $article;
  3446. });
  3447. }
  3448. /**
  3449. * c端-获取招工招聘下拉选框
  3450. * @param array $data
  3451. * @return array
  3452. * */
  3453. public function getWebsiteJobSelect(array $data): array
  3454. {
  3455. $web = Website::where('id', $data['website_id'])->first();
  3456. if (empty($web)) {
  3457. return Result::error("该网站不存在", 0);
  3458. }
  3459. $hy = JobIndustry::get()->all();
  3460. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3461. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3462. $result = [
  3463. 'hy' => $hy,
  3464. 'zw' => $zw,
  3465. 'jtzw' => $jtzw,
  3466. ];
  3467. if (empty($result)) {
  3468. return Result::error("查询失败", 0);
  3469. }
  3470. return Result::success($result);
  3471. }
  3472. /**
  3473. * c端-获取招工招聘
  3474. * @param array $data
  3475. * @return array
  3476. * */
  3477. public function getWebsiteJob(array $data): array
  3478. {
  3479. $web = Website::where('id', $data['website_id'])->first();
  3480. if (empty($web)) {
  3481. return Result::error("该网站不存在", 0);
  3482. }
  3483. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3484. ->where('job_hunting.website_id', $data['website_id'])
  3485. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3486. $query->where(function ($q) use ($data) {
  3487. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3488. });
  3489. })
  3490. ->select(
  3491. 'job_hunting.id',
  3492. 'job_hunting.catid',
  3493. 'job_hunting.cat_arr_id',
  3494. 'job_hunting.job_name_get',
  3495. 'job_hunting.industry',
  3496. 'job_hunting.name',
  3497. 'job_hunting.sexy',
  3498. 'job_hunting.origin',
  3499. 'job_hunting.city_arr_id',
  3500. 'job_hunting.experience',
  3501. 'job_hunting.updated_at',
  3502. 'job_hunting.salary',
  3503. 'job_hunting.skillList',
  3504. 'job_hunting.slelf_evaluation',
  3505. )
  3506. ->orderBy('updated_at', 'desc')
  3507. ->limit($data['job1_num'])
  3508. ->get();
  3509. $web['website_id'] = $data['website_id'];
  3510. if (empty($job_hunting)) {
  3511. $job_huntings = "未查询到相关简历信息";
  3512. } else {
  3513. $job_huntings = $this->processJob($job_hunting, $web);
  3514. }
  3515. // 0:待审核 1:已通过 2:已拒绝
  3516. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3517. ->where('job_recruiting.website_id', $data['website_id'])
  3518. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3519. $query->where(function ($q) use ($data) {
  3520. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3521. });
  3522. })
  3523. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3524. ->select(
  3525. 'job_recruiting.id',
  3526. 'job_recruiting.catid',
  3527. 'job_recruiting.cat_arr_id',
  3528. 'job_recruiting.title',
  3529. 'job_recruiting.jtzw_id',
  3530. 'job_recruiting.hy_id',
  3531. 'job_recruiting.city_arr_id',
  3532. 'job_recruiting.due_data',
  3533. 'job_recruiting.updated_at',
  3534. 'job_recruiting.experience',
  3535. 'job_recruiting.educational',
  3536. 'job_recruiting.salary',
  3537. 'job_recruiting.zw_id',
  3538. 'job_company.business_name',
  3539. 'job_recruiting.keyword',
  3540. 'job_recruiting.description',
  3541. )
  3542. ->orderBy('updated_at', 'desc')
  3543. ->limit($data['job2_num'])
  3544. ->get();
  3545. if (empty($job_recruiting->toArray())) {
  3546. $job_recruitings = "未查询到相关职位信息";
  3547. } else {
  3548. $job_recruitings = $this->processJob($job_recruiting, $web);
  3549. }
  3550. $result = [
  3551. 'job_hunting' => $job_huntings,
  3552. 'job_recuiting' => $job_recruitings,
  3553. ];
  3554. return Result::success($result);
  3555. }
  3556. /**
  3557. * c端-获取招工招聘列表
  3558. * @param array $data
  3559. * @return array
  3560. * */
  3561. public function getWebsiteJobList(array $data): array
  3562. {
  3563. $recruit_where = [];
  3564. $hunt_where = [];
  3565. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3566. if (empty($web)) {
  3567. return Result::error("此网站不存在", 0);
  3568. }
  3569. $website_id['website_id'] = $data['website_id'];
  3570. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3571. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3572. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3573. }
  3574. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3575. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3576. }
  3577. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3578. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3579. }
  3580. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3581. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3582. }
  3583. $query = JobRecruiting::where('job_recruiting.status', 1)
  3584. ->where('job_recruiting.website_id', $data['website_id'])
  3585. ->where($recruit_where)
  3586. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3587. $query->where(function ($q) use ($data) {
  3588. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3589. });
  3590. })
  3591. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3592. $query->where(function ($q) use ($data) {
  3593. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3594. });
  3595. })
  3596. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3597. ->select(
  3598. 'job_recruiting.id',
  3599. 'job_recruiting.catid',
  3600. 'job_recruiting.hy_id',
  3601. 'job_recruiting.title',
  3602. 'job_recruiting.zw_id',
  3603. 'job_recruiting.educational',
  3604. 'job_recruiting.jtzw_id',
  3605. 'job_recruiting.city_arr_id',
  3606. 'job_recruiting.due_data',
  3607. 'job_recruiting.experience',
  3608. 'job_recruiting.cat_arr_id',
  3609. 'job_recruiting.updated_at',
  3610. 'job_company.business_name',
  3611. 'job_recruiting.keyword',
  3612. 'job_recruiting.description',
  3613. )
  3614. ->orderBy('job_recruiting.updated_at', 'desc');
  3615. $recruit_count = $query->count();
  3616. $query = clone $query;
  3617. $JobRecruiting = $query
  3618. ->offset(($data['page'] - 1) * $data['pageSize'])
  3619. ->limit($data['pageSize'])
  3620. ->get();
  3621. if (empty($JobRecruiting)) {
  3622. $JobRecruiting = "暂无相关职位信息";
  3623. } else {
  3624. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3625. }
  3626. }
  3627. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3628. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3629. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3630. }
  3631. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3632. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3633. }
  3634. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3635. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3636. }
  3637. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3638. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3639. }
  3640. $query = JobHunting::where('job_hunting.status', 2)
  3641. ->where('job_hunting.website_id', $data['website_id'])
  3642. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3643. ->where($hunt_where)
  3644. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3645. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3646. // })
  3647. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3648. $query->where(function ($q) use ($data) {
  3649. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3650. });
  3651. })
  3652. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3653. $query->where(function ($q) use ($data) {
  3654. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3655. });
  3656. })
  3657. ->select(
  3658. 'job_hunting.id',
  3659. 'job_hunting.catid',
  3660. 'job_hunting.sexy',
  3661. 'job_hunting.experience',
  3662. 'job_hunting.origin',
  3663. 'job_hunting.industry',
  3664. 'job_hunting.name',
  3665. 'job_hunting.job',
  3666. 'job_hunting.job_name_get',
  3667. 'job_hunting.city_arr_id',
  3668. 'job_hunting.cat_arr_id',
  3669. 'job_hunting.created_at',
  3670. 'job_hunting.updated_at',
  3671. 'job_position.zwname as job_name',
  3672. 'job_hunting.skillList',
  3673. 'job_hunting.slelf_evaluation',
  3674. )
  3675. ->orderBy('job_hunting.updated_at', 'desc');
  3676. $hunt_count = $query->count();
  3677. $query = clone $query;
  3678. $JobHunting = $query
  3679. ->offset(($data['page'] - 1) * $data['pageSize'])
  3680. ->limit($data['pageSize'])
  3681. ->get();
  3682. if (empty($JobHunting)) {
  3683. $JobRecruiting = "暂无相关简历信息";
  3684. } else {
  3685. $JobHunting = $this->processJob($JobHunting, $website_id);
  3686. }
  3687. }
  3688. $result = [
  3689. 'JobRecruiting' => $JobRecruiting ?? [],
  3690. 'recruit_count' => $recruit_count ?? 0,
  3691. 'JobHunting' => $JobHunting ?? [],
  3692. 'hunt_count' => $hunt_count ?? 0,
  3693. ];
  3694. return Result::success($result);
  3695. }
  3696. /**
  3697. * c端-获取招工招聘详情
  3698. * @param array $data
  3699. * @return array
  3700. * */
  3701. public function getWebsiteJobInfo(array $data): array
  3702. {
  3703. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3704. if (empty($web)) {
  3705. return Result::error("该网站不存在", 0);
  3706. }
  3707. $webid = [
  3708. 'website_id' => $data['website_id'],
  3709. ];
  3710. // 职位相关信息
  3711. if ($data['type'] == 1) {
  3712. $query = JobRecruiting::where('status', 1)
  3713. ->where('website_id', $data['website_id'])
  3714. ->select('*');
  3715. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3716. $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();
  3717. if (!empty($company)) {
  3718. $result['company'] = $this->processJob($company, $webid);
  3719. }
  3720. $other_job = JobRecruiting::where('status', 1)
  3721. ->where('website_id', $data['website_id'])
  3722. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3723. ->where('id', '!=', $data['id'])
  3724. ->where('user_id', '=', $job[0]['user_id'])
  3725. ->limit($data['pageSize'])
  3726. ->get();
  3727. if (!empty($other_job)) {
  3728. $result['other_job'] = $this->processJob($other_job, $webid);
  3729. }
  3730. } else {
  3731. // 简历相关信息
  3732. $job = JobHunting::where('job_hunting.status', 2)
  3733. ->where('job_hunting.website_id', $data['website_id'])
  3734. ->where('job_hunting.id', $data['id'])
  3735. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3736. ->select('job_hunting.*', 'user_name')
  3737. ->get();
  3738. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3739. if (!empty($resume->toArray())) {
  3740. $result['resume'] = 1;
  3741. } else {
  3742. $result['resume'] = 0;
  3743. }
  3744. }
  3745. if (empty($job->toArray())) {
  3746. return Result::error("id参数错误", 0);
  3747. }
  3748. if (!empty($job[0]['job_experience'])) {
  3749. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3750. if (!empty($job_experience)) {
  3751. // $hy = [];
  3752. foreach ($job_experience as $key => $value) {
  3753. // $id = $value['id'];
  3754. $hy[$key] = $value['job_industry'];
  3755. $zw_id[$key] = $value['job_typename'];
  3756. $jtzw_id[$key] = $value['job_name'];
  3757. }
  3758. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3759. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3760. // 先将关联表转换为索引数组,提高查找效率
  3761. $hyLookup = [];
  3762. foreach ($hy_table as $item) {
  3763. $hyLookup[$item['hyid']] = $item['hyname'];
  3764. }
  3765. $zwLookup = [];
  3766. foreach ($zw_table as $item) {
  3767. $zwLookup[$item['zwid']] = $item['zwname'];
  3768. }
  3769. foreach ($job_experience as $key => &$value) {
  3770. // 处理行业名称
  3771. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3772. $value['hy_name'] = $hyLookup[$hy[$key]];
  3773. }
  3774. // 处理职位名称
  3775. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3776. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3777. }
  3778. // 处理具体职位名称
  3779. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3780. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3781. }
  3782. }
  3783. // 释放引用,防止意外修改后续代码
  3784. unset($value);
  3785. }
  3786. $result['job_experience'] = $job_experience ?? [];
  3787. }
  3788. if (!empty($job[0]['education_experience'])) {
  3789. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3790. if (!empty($education_experience)) {
  3791. foreach ($education_experience as $key => $value) {
  3792. // $id = $value['id'];
  3793. $education[$key] = $value['school_education'];
  3794. }
  3795. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3796. // // 先将关联表转换为索引数组,提高查找效率
  3797. $educationLookup = [];
  3798. foreach ($education_table as $item) {
  3799. $educationLookup[$item['evalue']] = $item['ename'];
  3800. }
  3801. foreach ($education_experience as $key => &$value) {
  3802. // 处理学历名称
  3803. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3804. $value['education_name'] = $educationLookup[$education[$key]];
  3805. }
  3806. }
  3807. }
  3808. $result['education_experience'] = $job_experience ?? [];
  3809. }
  3810. $result['job'] = $this->processJob($job, $webid);
  3811. // // 返现对应的栏目
  3812. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3813. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3814. ->whereIn('category_id', $catid)
  3815. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3816. ->orderBy('pid')->get()->all();
  3817. if (!empty($category)) {
  3818. $result['category'] = $category;
  3819. }
  3820. $result['job'] = $job;
  3821. $result['job_experience'] = $job_experience ?? [];
  3822. $result['education_experience'] = $education_experience ?? [];
  3823. if (empty($result)) {
  3824. return Result::error("参数错误", 0);
  3825. }
  3826. return Result::success($result);
  3827. }
  3828. /**
  3829. * c端-申请职位
  3830. * @param array $data
  3831. * @return array
  3832. * */
  3833. public function getWebsiteJobApply(array $data): array
  3834. {
  3835. // 首先验证网站是否存在
  3836. // return Result::success($data);
  3837. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3838. if (empty($web)) {
  3839. return Result::error("该网站不存在", 0);
  3840. }
  3841. // 验证用户是否存在且为个人会员/管理员
  3842. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3843. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3844. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3845. return Result::error("用户不存在", 0);
  3846. }
  3847. // 去除重复元素和空元素,并保持原始顺序
  3848. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3849. return !empty($value);
  3850. }));
  3851. // 验证职位是否存在 1:审核通过
  3852. $recruiting = JobRecruiting::where('status', 1)
  3853. ->where('website_id', $data['website_id'])
  3854. ->whereIn('id', $data['recruit_id'])
  3855. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3856. if (empty($recruiting)) {
  3857. return Result::error("该职位不存在", 0);
  3858. }
  3859. // 简历是否存在
  3860. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3861. if (empty($hunt_id)) {
  3862. return Result::error("该简历不存在", 0);
  3863. }
  3864. $data['hunt_id'] = $hunt_id['hunt_id'];
  3865. // // 验证是否已投递过该职位
  3866. $apply = JobApply::where('user_id', $data['user_id'])
  3867. ->where('hunt_id', $data['hunt_id'])
  3868. ->where('website_id', $data['website_id'])
  3869. ->whereIn('recruit_id', $data['recruit_id'])
  3870. ->get(['recruit_id']);
  3871. if (!empty($apply->toArray())) {
  3872. return Result::error("您已投递过该职位!");
  3873. }
  3874. $insertData = array_map(function ($recruiting) use ($data) {
  3875. return [
  3876. 'user_id' => $data['user_id'],
  3877. 'hunt_id' => $data['hunt_id'],
  3878. 'website_id' => $data['website_id'],
  3879. 'recruit_id' => $recruiting['recruit_id'],
  3880. 'receiver_id' => $recruiting['receiver_id'],
  3881. 'status' => 1,
  3882. ];
  3883. }, $recruiting);
  3884. // 批量插入数据
  3885. $result = JobApply::insert($insertData);
  3886. if (empty($result)) {
  3887. return Result::error("投递失败", 0);
  3888. }
  3889. return Result::success($result);
  3890. }
  3891. /**
  3892. * 招工招聘-沟通简历
  3893. * @param array $data
  3894. * @return array
  3895. * */
  3896. public function getWebsiteJobResume(array $data): array
  3897. {
  3898. // 首先验证网站是否存在
  3899. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3900. if (empty($web)) {
  3901. return Result::error("该网站不存在", 0);
  3902. }
  3903. // return Result::success($data);
  3904. // 验证用户是否存在且为企业会员/管理员
  3905. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3906. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3907. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3908. return Result::error("用户不存在", 0);
  3909. }
  3910. // 去除重复元素和空元素,并保持原始顺序
  3911. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3912. return !empty($value);
  3913. }));
  3914. // 验证简历是否存在
  3915. $hunting = JobHunting::where('status', 2)
  3916. ->where('website_id', $data['website_id'])
  3917. ->whereIn('id', $data['hunt_id'])
  3918. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3919. if (empty($hunting)) {
  3920. return Result::error("该简历不存在", 0);
  3921. }
  3922. // 验证是否已沟通过该简历
  3923. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3924. ->where('recruit_id', $data['recruit_id'])
  3925. ->where('website_id', $data['website_id'])
  3926. ->whereIn('hunt_id', $data['hunt_id'])
  3927. ->get(['hunt_id']);
  3928. if (!empty($remuse->toArray())) {
  3929. return Result::error("您已沟通过该简历!");
  3930. }
  3931. // 准备要插入的数据数组
  3932. $insertData = array_map(function ($hunting) use ($data) {
  3933. return [
  3934. 'user_id' => $data['user_id'],
  3935. 'recruit_id' => $data['recruit_id'],
  3936. 'website_id' => $data['website_id'],
  3937. 'hunt_id' => $hunting['hunt_id'],
  3938. 'receiver_id' => $hunting['receiver_id'],
  3939. 'status' => 1,
  3940. ];
  3941. }, $hunting);
  3942. // 批量插入数据
  3943. $result = JobRemuse::insert($insertData);
  3944. if (empty($result)) {
  3945. return Result::error("沟通失败", 0);
  3946. }
  3947. return Result::success($result);
  3948. }
  3949. /**
  3950. * 招工招聘 -我的职位(企业会员)
  3951. * @param array $data
  3952. * @return array
  3953. */
  3954. public function getWebsiteJobRecruiting(array $data): array
  3955. {
  3956. $web = Website::where('id', $data['website_id'])->first('id');
  3957. if (empty($web)) {
  3958. return Result::error("该网站不存在", 0);
  3959. }
  3960. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3961. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3962. return Result::error("用户暂无权限!", 0);
  3963. }
  3964. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3965. $result = JobRecruiting::where('website_id', $data['website_id'])
  3966. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3967. $query->where('user_id', $user['id']);
  3968. })
  3969. ->where('status', 1)
  3970. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3971. ->orderBy('updated_at', 'desc')
  3972. ->limit($data['pageSize'])
  3973. ->get();
  3974. if (empty($result)) {
  3975. return Result::error("暂无相关职位信息", 0);
  3976. }
  3977. return Result::success($result);
  3978. }
  3979. /**
  3980. * c端 - 验证路由
  3981. * @param array $data
  3982. * @return array
  3983. */
  3984. /**
  3985. * c端 - 验证路由
  3986. * @param array $data
  3987. * @return array
  3988. */
  3989. public function checkWebsiteRoute(array $data): array
  3990. {
  3991. // 测试001111111222
  3992. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3993. if (empty($web)) {
  3994. return Result::error("该网站不存在", 0);
  3995. } elseif ($web['status'] != 1) {
  3996. return Result::error("网站已经关闭", 0);
  3997. }
  3998. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3999. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4000. // 验证路由是否存在
  4001. if (empty($whiteRouterInfo)) {
  4002. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4003. }
  4004. if (!empty($whiteRouterInfo)) {
  4005. return Result::success($whiteRouterInfo->toArray());
  4006. }
  4007. }
  4008. // 验证栏目路由
  4009. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4010. ->where('path', $data['all_route'])
  4011. ->get()->all();
  4012. if (count($last_category) == 0) {
  4013. return Result::error("该栏目不存在", 0);
  4014. }
  4015. if (count($last_category) > 1) {
  4016. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4017. }
  4018. if (count($last_category) == 1) {
  4019. $last_category = $last_category[0];
  4020. }
  4021. // return Result::success($last_category);
  4022. if (isset($data['id']) && !empty($data['id'])) {
  4023. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4024. switch ($last_category['type']) {
  4025. case 1:
  4026. // 文章
  4027. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4028. $article = Article::where('status', 1)
  4029. ->where('id', $data['id'])
  4030. ->where(function ($query) use ($data) {
  4031. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4032. ->orWhereNull("ignore_ids");
  4033. })
  4034. ->first(['catid']);
  4035. if (empty($article)) {
  4036. return Result::error("该文章不存在", 0);
  4037. }
  4038. // return Result::success($article);
  4039. break;
  4040. case 2:
  4041. // 商品
  4042. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4043. $article = Good::where('website_id', $data['website_id'])
  4044. ->where('status', 2)
  4045. ->where('id', $data['id'])
  4046. ->first(['cat_arr_id']);
  4047. if (empty($article)) {
  4048. return Result::error("该商品不存在", 0);
  4049. }
  4050. break;
  4051. case 3:
  4052. // 书刊信息
  4053. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4054. $article = Book::where('website_id', $data['website_id'])
  4055. ->where('status', 2)
  4056. ->where('id', $data['id'])
  4057. ->first(['id', 'cat_arr_id']);
  4058. if (empty($article)) {
  4059. return Result::error("该书刊不存在", 0);
  4060. }
  4061. break;
  4062. case 4:
  4063. // 招聘
  4064. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4065. $article = JobRecruiting::where('website_id', $data['website_id'])
  4066. ->where('status', 1)
  4067. ->where('id', $data['id'])
  4068. ->first(['cat_arr_id']);
  4069. if (empty($article)) {
  4070. return Result::error("该招聘不存在", 0);
  4071. }
  4072. break;
  4073. case 5:
  4074. // 求职
  4075. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4076. $article = JobHunting::where('website_id', $data['website_id'])
  4077. ->where('status', 2)
  4078. ->where('id', $data['id'])
  4079. ->first(['cat_arr_id']);
  4080. if (empty($article)) {
  4081. return Result::error("该求职不存在", 0);
  4082. }
  4083. break;
  4084. case 6:
  4085. // 企业
  4086. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4087. $article = Company::
  4088. // where('website_id', $data['website_id'])
  4089. // ->
  4090. where('status', 1)
  4091. ->where('id', $data['id'])
  4092. ->first(['cat_arr_id']);
  4093. if (empty($article)) {
  4094. return Result::error("该企业不存在", 0);
  4095. }
  4096. break;
  4097. case 7:
  4098. // 项目
  4099. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4100. $article = Project::where('website_id', $data['website_id'])
  4101. ->where('status', 1)
  4102. ->where('id', $data['id'])
  4103. ->first(['cat_arr_id']);
  4104. if (empty($article)) {
  4105. return Result::error("该项目不存在", 0);
  4106. }
  4107. break;
  4108. default:
  4109. return Result::error("该数据不存在", 0);
  4110. break;
  4111. }
  4112. // return Result::success($article);
  4113. // $catid =0 ;
  4114. if (!isset($article['cat_arr_id'])) {
  4115. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4116. } else {
  4117. $catidArray = json_decode($article['cat_arr_id'], true);
  4118. $catid = !empty($catidArray) ? end($catidArray) : null;
  4119. }
  4120. // return Result::success($catid);
  4121. // // return Result::success($article['cat_arr_id']);
  4122. if (empty($catid)) {
  4123. return Result::error("该栏目路径不存在", 0);
  4124. }
  4125. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4126. ->where('category_id', $catid)
  4127. ->first('path');
  4128. }
  4129. // else{
  4130. // // if ($last_category['pid'] != 0) {
  4131. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4132. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4133. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4134. // ->where('category_id',$catid)
  4135. // ->where('path',$data['all_route'])
  4136. // ->first('path');
  4137. // // } else {
  4138. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4139. // // }
  4140. // }
  4141. // return Result::success($path);
  4142. if (!empty($path) && $path['path'] != $data['all_route']) {
  4143. return Result::error('非法路径!');
  4144. } else {
  4145. return Result::success($last_category['path']);
  4146. }
  4147. }
  4148. /**
  4149. * 招工招聘 - 获取推荐职位
  4150. * @param array $data
  4151. * @return array
  4152. */
  4153. public function getWebsiteLevelJob(array $data): array
  4154. {
  4155. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4156. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4157. ->where('job_recruiting.status', 1)
  4158. ->where('job_level', $data['job_level'])
  4159. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4160. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4161. ->orderBy('job_recruiting.updated_at', 'desc')
  4162. ->limit($data['pageSize'])
  4163. ->get();
  4164. $web = ['website_id' => $data['website_id']];
  4165. if (!empty($job)) {
  4166. $result = $this->processJob($job, $web);
  4167. }
  4168. if (empty($result)) {
  4169. return Result::error("暂无相关职位信息", 0);
  4170. }
  4171. return Result::success($result);
  4172. }
  4173. /**
  4174. * 验证导航名称是否重复
  4175. * @return void
  4176. */
  4177. //20250226 产品列表
  4178. public function getGoodList(array $data): array
  4179. {
  4180. var_dump($data, '---------1-2--');
  4181. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4182. unset($data['user_type_id']);
  4183. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4184. $where = [];
  4185. if ($type_id != '10000') {
  4186. $where = [
  4187. 'good.user_id' => $user_id,
  4188. ];
  4189. }
  4190. //类型
  4191. if (isset($data['type_id']) && $data['type_id']) {
  4192. $where['good.type_id'] = $data['type_id'];
  4193. }
  4194. //名称
  4195. if (isset($data['name']) && $data['name']) {
  4196. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4197. }
  4198. //status
  4199. if (isset($data['status']) && $data['status'] != '') {
  4200. $where['good.status'] = $data['status'];
  4201. }
  4202. //status1
  4203. // if (isset($data['status1']) && $data['status1'] == 1) {
  4204. // $status1 = 1;
  4205. // }
  4206. $where1 = [];
  4207. //website_id
  4208. // if (isset($data['website_id']) && $data['website_id']) {
  4209. // $where1 = [
  4210. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4211. // ];
  4212. // }
  4213. // website_name
  4214. if (isset($data['website_name']) && $data['website_name']) {
  4215. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4216. }
  4217. // catid
  4218. if (isset($data['category_name']) && $data['category_name']) {
  4219. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4220. }
  4221. // $result = Good::where($where)
  4222. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4223. var_dump($where, '---------1---');
  4224. $result = Good::where($where)
  4225. ->when(!empty($where1), function ($query) use ($where1) {
  4226. return $query->where($where1);
  4227. })
  4228. //status 1待审核2已审核3已拒绝
  4229. ->when(isset($data['status1']), function ($query) {
  4230. return $query->whereIn('good.status', [1, 3]);
  4231. })
  4232. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4233. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4234. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4235. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4236. ->orderBy("updated_at", "desc")
  4237. ->limit($data['page_size'])
  4238. ->offset(($data['page'] - 1) * $data['page_size'])
  4239. ->get();
  4240. $count = Good::where($where)
  4241. ->when(!empty($where1), function ($query) use ($where1) {
  4242. return $query->where($where1);
  4243. })
  4244. //status 1待审核2已审核3已拒绝
  4245. ->when(isset($data['status1']), function ($query) {
  4246. return $query->whereIn('good.status', [1, 3]);
  4247. })
  4248. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4249. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4250. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4251. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4252. ->orderBy("updated_at", "desc")->count();
  4253. $data = [
  4254. 'rows' => $result->toArray(),
  4255. 'count' => $count,
  4256. ];
  4257. if (empty($result)) {
  4258. return Result::error("此栏目暂无相关产品", 0);
  4259. }
  4260. return Result::success($data);
  4261. }
  4262. public function getGoodInfo(array $data): array
  4263. {
  4264. $result = Good::where('id', $data['id'])->first();
  4265. if (empty($result)) {
  4266. return Result::error("此产品不存在", 0);
  4267. }
  4268. return Result::success($result);
  4269. }
  4270. public function addGood(array $data): array
  4271. {
  4272. // unset($data['city_arr_id']);
  4273. // unset($data['cat_arr_id']);
  4274. $data['city_id'] = end($data['city_arr_id']);
  4275. $data['catid'] = end($data['cat_arr_id']);
  4276. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4277. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4278. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4279. unset($data['imgUrl']); //大小写
  4280. if (isset($data['price']) && $data['price'] == '') {
  4281. $data['price'] = 0;
  4282. }
  4283. if ($data['imgurl'] == '') {
  4284. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4285. preg_match_all($reg, $data['detail'], $matches);
  4286. if (isset($matches[1][0])) {
  4287. //截取varchar240
  4288. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4289. }
  4290. }
  4291. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4292. //提取标题+内容中的关键词
  4293. $data['keyword'] = $data['name'];
  4294. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4295. Jieba::init(); // 初始化 jieba-php
  4296. Finalseg::init();
  4297. $segList = Jieba::cut($data['keyword']);
  4298. $segList1 = array_slice($segList, 0, 8);
  4299. $data['keyword'] = implode(',', $segList1);
  4300. }
  4301. if ($data['description'] == '') {
  4302. //提取内容中的描述
  4303. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4304. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4305. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4306. }
  4307. if ($data['status'] == 1) {
  4308. $this->sendMessage([
  4309. 'talk_type' => 200,
  4310. 'title' => $data['name'],
  4311. 'content' => '提交了审核',
  4312. 'messageType' => 3,
  4313. ]);
  4314. }
  4315. $result = Good::insert($data);
  4316. if (empty($result)) {
  4317. return Result::error("添加失败", 0);
  4318. }
  4319. return Result::success($result);
  4320. }
  4321. public function updateGood(array $data): array
  4322. {
  4323. $data['city_id'] = end($data['city_arr_id']);
  4324. $data['catid'] = end($data['cat_arr_id']);
  4325. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4326. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4327. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4328. //设置东八区
  4329. date_default_timezone_set('Asia/Shanghai');
  4330. $data['updated_at'] = date('Y-m-d H:i:s');
  4331. if (isset($data['price']) && $data['price'] == '') {
  4332. $data['price'] = 0;
  4333. }
  4334. if ($data['imgurl'] == '') {
  4335. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4336. preg_match_all($reg, $data['detail'], $matches);
  4337. if (isset($matches[1][0])) {
  4338. //截取varchar240
  4339. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4340. }
  4341. }
  4342. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4343. //提取标题+内容中的关键词
  4344. $data['keyword'] = $data['name'];
  4345. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4346. Jieba::init(); // 初始化 jieba-php
  4347. Finalseg::init();
  4348. $segList = Jieba::cut($data['keyword']);
  4349. $segList1 = array_slice($segList, 0, 8);
  4350. $data['keyword'] = implode(',', $segList1);
  4351. }
  4352. if ($data['description'] == '') {
  4353. //提取内容中的描述
  4354. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4355. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4356. }
  4357. if ($data['status'] == 1) {
  4358. $this->sendMessage([
  4359. 'talk_type' => 200,
  4360. 'title' => $data['name'],
  4361. 'content' => '提交了审核',
  4362. 'messageType' => 3,
  4363. ]);
  4364. }
  4365. $result = Good::where('id', $data['id'])->update($data);
  4366. if (empty($result)) {
  4367. return Result::error("更新失败", 0);
  4368. }
  4369. return Result::success($result);
  4370. }
  4371. public function delGood(array $data): array
  4372. {
  4373. $result = Good::where('id', $data['id'])->delete();
  4374. if (empty($result)) {
  4375. return Result::error("删除失败", 0);
  4376. }
  4377. return Result::success($result);
  4378. }
  4379. //20250226 产品列表
  4380. //20250306 求职信息
  4381. public function getJobHuntingList(array $data): array
  4382. {
  4383. $where = [];
  4384. if (isset($data['username']) && !empty($data['username'])) {
  4385. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4386. }
  4387. //status 1待审核2已审核3已拒绝
  4388. if (isset($data['status']) && $data['status'] != '') {
  4389. $where = [
  4390. 'job_hunting.status' => $data['status'],
  4391. ];
  4392. }
  4393. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4394. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4395. unset($data['type_id']);
  4396. if ($type_id != '10000') {
  4397. $where[] = ['job_hunting.user_id', '=', $user_id];
  4398. }
  4399. $result = JobHunting::where($where)
  4400. ->when(!empty($data['status1']), function ($query) use ($data) {
  4401. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4402. })
  4403. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4404. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4405. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4406. ->orderBy("updated_at", "desc")
  4407. ->limit($data['page_size'])
  4408. ->offset(($data['page'] - 1) * $data['page_size'])
  4409. ->get();
  4410. if (empty($result)) {
  4411. return Result::error("查询失败", 0);
  4412. }
  4413. $count = JobHunting::where($where)
  4414. ->when(!empty($data['status1']), function ($query) use ($data) {
  4415. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4416. })
  4417. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4418. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4419. ->count();
  4420. $data = [
  4421. 'rows' => $result->toArray(),
  4422. 'count' => $count,
  4423. ];
  4424. return Result::success($data);
  4425. }
  4426. public function getJobHuntingApply(array $data): array
  4427. {
  4428. var_dump($data, '-----------------test--------1-');
  4429. $where = [];
  4430. if (isset($data['username']) && !empty($data['username'])) {
  4431. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4432. }
  4433. if (isset($data['salary']) && !empty($data['salary'])) {
  4434. $where[] = [
  4435. 'job_hunting.salary',
  4436. '=',
  4437. $data['salary'],
  4438. ];
  4439. }
  4440. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4441. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4442. unset($data['type_id']);
  4443. if ($type_id != '10000') {
  4444. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4445. }
  4446. var_dump($where, '-----------------test---------');
  4447. $result = jobApply::where($where)
  4448. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4449. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4450. // })
  4451. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4452. ->where('job_enum.egroup', '=', 'income')
  4453. ->where('job_hunting.status', 2) //已审核
  4454. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4455. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4456. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4457. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4458. //职位----是申请职位
  4459. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4460. ->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')
  4461. ->orderBy("job_hunting.updated_at", "desc")
  4462. ->limit($data['page_size'])
  4463. ->offset(($data['page'] - 1) * $data['page_size'])
  4464. ->get();
  4465. if (empty($result)) {
  4466. return Result::error("查询失败", 0);
  4467. }
  4468. $count = jobApply::where($where)
  4469. ->where('job_enum.egroup', '=', 'income')
  4470. ->where('job_hunting.status', 2) //已审核
  4471. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4472. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4473. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4474. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4475. //职位----是申请职位
  4476. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4477. ->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')
  4478. ->count();
  4479. $data = [
  4480. 'rows' => $result->toArray(),
  4481. 'count' => $count,
  4482. ];
  4483. return Result::success($data);
  4484. }
  4485. public function addJobHunting(array $data): array
  4486. {
  4487. date_default_timezone_set('Asia/Shanghai');
  4488. unset($data['company_name']);
  4489. unset($data['job_industry']);
  4490. unset($data['job_name']);
  4491. unset($data['department']);
  4492. unset($data['job_timeList']);
  4493. unset($data['job_content']);
  4494. unset($data['job_typename']); //不知道这是啥,
  4495. $data['created_at'] = date('Y-m-d H:i:s');
  4496. $data['updated_at'] = date('Y-m-d H:i:s');
  4497. //根据用户 user_id 只能添加一次
  4498. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4499. if (!empty($result)) {
  4500. return Result::error("您已添加过求职信息", 0);
  4501. }
  4502. var_dump($result, '-----------------test---------');
  4503. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4504. if (is_string($data['city_arr_id'])) {
  4505. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4506. $cityArr = json_decode($data['city_arr_id'], true);
  4507. // 确保 $cityArr 是数组
  4508. if (is_array($cityArr)) {
  4509. $data['city_id'] = end($cityArr);
  4510. }
  4511. } else {
  4512. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4513. if (is_array($data['city_arr_id'])) {
  4514. $data['city_id'] = end($data['city_arr_id']);
  4515. }
  4516. }
  4517. }
  4518. // 处理求职所绑定栏目
  4519. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4520. if (is_string($data['cat_arr_id'])) {
  4521. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4522. // 先清理可能存在的无效 JSON 字符
  4523. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4524. $catArr = json_decode($cleanedCatArrStr, true);
  4525. // 检查 JSON 解码是否成功且结果是数组
  4526. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4527. $data['catid'] = end($catArr);
  4528. }
  4529. } else {
  4530. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4531. if (is_array($data['cat_arr_id'])) {
  4532. $data['catid'] = end($data['cat_arr_id']);
  4533. }
  4534. }
  4535. }
  4536. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4537. $this->sendMessage([
  4538. 'talk_type' => 600,
  4539. 'title' => $data['name'],
  4540. 'content' => '提交了审核',
  4541. 'messageType' => 11,
  4542. ]);
  4543. }
  4544. $result = JobHunting::create($data);
  4545. if (empty($result)) {
  4546. return Result::error("添加失败", 0);
  4547. }
  4548. return Result::success($result);
  4549. }
  4550. public function delJobHunting(array $data): array
  4551. {
  4552. $result = JobHunting::where('id', $data['id'])->delete();
  4553. if (empty($result)) {
  4554. return Result::error("删除失败", 0);
  4555. }
  4556. return Result::success($result);
  4557. }
  4558. public function updateJobHunting(array $data): array
  4559. {
  4560. //设置东八区
  4561. date_default_timezone_set('Asia/Shanghai');
  4562. unset($data['company_name']);
  4563. unset($data['job_industry']);
  4564. unset($data['job_name']);
  4565. unset($data['department']);
  4566. unset($data['job_timeList']);
  4567. unset($data['job_content']);
  4568. unset($data['job_typename']); //不知道这是啥,
  4569. $data['created_at'] = date('Y-m-d H:i:s');
  4570. $data['updated_at'] = date('Y-m-d H:i:s');
  4571. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4572. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4573. $cityArr = json_decode($data['city_arr_id'], true);
  4574. $data['city_id'] = end($cityArr);
  4575. } else {
  4576. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4577. $data['city_id'] = end($data['city_arr_id']);
  4578. }
  4579. // 处理求职所绑定栏目
  4580. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4581. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4582. $catArr = json_decode($data['cat_arr_id'], true);
  4583. $data['catid'] = end($catArr);
  4584. } else {
  4585. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4586. $data['catid'] = end($data['cat_arr_id']);
  4587. }
  4588. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4589. $this->sendMessage([
  4590. 'talk_type' => 600,
  4591. 'title' => $data['name'],
  4592. 'content' => '提交了审核',
  4593. 'messageType' => 11,
  4594. ]);
  4595. }
  4596. $result = JobHunting::where('id', $data['id'])->update($data);
  4597. if (empty($result)) {
  4598. return Result::error("更新失败", 0);
  4599. }
  4600. return Result::success($result);
  4601. }
  4602. public function getJobHuntingInfo(array $data): array
  4603. {
  4604. $result = JobHunting::where('id', $data['id'])->first();
  4605. if (empty($result)) {
  4606. return Result::error("查询失败", 0);
  4607. }
  4608. return Result::success($result);
  4609. }
  4610. public function getJobHuntingData(array $data): array
  4611. {
  4612. $jobEnum = JobEnum::get();
  4613. $jobIndustry = JobIndustry::get();
  4614. $jobNature = JobNature::get();
  4615. $jobPosition = JobPosition::get();
  4616. $data = [
  4617. 'jobEnum' => $jobEnum,
  4618. 'jobIndustry' => $jobIndustry,
  4619. 'jobNature' => $jobNature,
  4620. 'jobPosition' => $jobPosition,
  4621. ];
  4622. return Result::success($data);
  4623. }
  4624. public function delJobHuntingInfo(array $data): array
  4625. {
  4626. $result = JobHunting::where('id', $data['id'])->delete();
  4627. return Result::success();
  4628. }
  4629. //20250324 通知,公告,消息
  4630. public function delNotice(array $data): array
  4631. {
  4632. $result = Notice::where('id', $data['id'])->delete();
  4633. if ($result) {
  4634. return Result::success();
  4635. } else {
  4636. return Result::error("删除失败", 0);
  4637. }
  4638. }
  4639. public function getNoticeInfo(array $data): array
  4640. {
  4641. $result = Notice::where('id', $data['id'])->first();
  4642. // var_dump($result['re_user_ids'], '--------------------');
  4643. if (empty($result)) {
  4644. return Result::error("查询失败", 0);
  4645. }
  4646. return Result::success($result);
  4647. }
  4648. public function readNotice(array $data): array
  4649. {
  4650. $result = Notice::where('id', $data['id'])->first();
  4651. // var_dump($result['re_user_ids'], '--------------------');
  4652. if (empty($result)) {
  4653. return Result::error("查询失败", 0);
  4654. }
  4655. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4656. $re_user_ids = json_decode($result['re_user_ids'], true);
  4657. var_dump($re_user_ids, '--------------1---test---------');
  4658. var_dump($data, '--------------1---test---------');
  4659. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4660. //如果已经存在,就不再添加
  4661. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4662. $read_id = json_decode($result['read_id'], true);
  4663. if (!is_array($read_id)) {
  4664. $read_id = [];
  4665. }
  4666. if (!in_array($data['user_id'], $read_id)) {
  4667. $read_id[] = $data['user_id'];
  4668. $result['read_id'] = json_encode($read_id);
  4669. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4670. }
  4671. } else {
  4672. //如果不存在,就添加
  4673. $result['read_id'] = json_encode([$data['user_id']]);
  4674. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4675. }
  4676. }
  4677. return Result::success($result);
  4678. }
  4679. public function addNotice(array $data): array
  4680. {
  4681. date_default_timezone_set('Asia/Shanghai');
  4682. $data['created_at'] = date('Y-m-d H:i:s');
  4683. $data['updated_at'] = date('Y-m-d H:i:s');
  4684. // $data['level'] = "1,2,3,4,5";
  4685. $level = json_decode($data['level'], true);
  4686. $user_id = UserInfo::
  4687. //city_id不是null
  4688. whereNotNull('city_id')
  4689. ->whereNotNull('department_id')
  4690. ->where(function ($query) use ($data) {
  4691. $query->where(function ($subQuery) use ($data) {
  4692. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4693. });
  4694. })
  4695. ->where(function ($query) use ($data) {
  4696. $query->where(function ($subQuery) use ($data) {
  4697. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4698. });
  4699. })
  4700. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4701. $query->whereIn('level', $level);
  4702. })
  4703. ->pluck('user_id')->toArray();
  4704. $user_id = array_unique($user_id);
  4705. $chat_ids = $user_id;
  4706. $user_id = json_encode($user_id);
  4707. $data['re_user_ids'] = $user_id;
  4708. $this->sendMessage([
  4709. 'talk_type' => 700,
  4710. 'title' => $data['title'],
  4711. 'content' => '提交了审核',
  4712. 'messageType' => 5,
  4713. ]);
  4714. $result = Notice::insertGetId($data);
  4715. if (empty($result)) {
  4716. return Result::error("添加失败", 0);
  4717. }
  4718. return Result::success($result);
  4719. }
  4720. public function updateNotice(array $data): array
  4721. {
  4722. date_default_timezone_set('Asia/Shanghai');
  4723. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4724. $user_id = UserInfo::
  4725. //city_id不是null
  4726. whereNotNull('city_id')
  4727. ->whereNotNull('department_id')
  4728. ->where(function ($query) use ($data) {
  4729. $query->where(function ($subQuery) use ($data) {
  4730. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4731. });
  4732. })
  4733. ->where(function ($query) use ($data) {
  4734. $query->where(function ($subQuery) use ($data) {
  4735. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4736. });
  4737. })
  4738. ->pluck('user_id')->toArray();
  4739. $user_id = array_unique($user_id);
  4740. $user_id = json_encode($user_id);
  4741. $data['re_user_ids'] = $user_id;
  4742. $data['updated_at'] = date('Y-m-d H:i:s');
  4743. $this->sendMessage([
  4744. 'talk_type' => 700,
  4745. 'title' => $data['title'],
  4746. 'content' => '提交了审核',
  4747. 'messageType' => 5,
  4748. ]);
  4749. $result = Notice::where('id', $data['id'])->update($data);
  4750. return Result::success($result);
  4751. }
  4752. public function getNoticeList(array $data): array
  4753. {
  4754. $where = [];
  4755. //title
  4756. if (isset($data['title']) && !empty($data['title'])) {
  4757. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4758. }
  4759. //level
  4760. if (isset($data['level']) && !empty($data['level'])) {
  4761. $where[] = ['notice.level', '=', $data['level']];
  4762. }
  4763. //status
  4764. if (isset($data['status']) && !empty($data['status'])) {
  4765. $where[] = ['notice.status', '=', $data['status']];
  4766. }
  4767. //type
  4768. if (isset($data['type']) && !empty($data['type'])) {
  4769. $where[] = ['notice.type', '=', $data['type']];
  4770. }
  4771. var_dump($data, '------------11111-2----test---------');
  4772. if ($data['type_id'] == 10000) {
  4773. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4774. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4775. })
  4776. ->where($where)
  4777. ->orderBy('updated_at', 'desc')
  4778. ->limit($data['page_size'])
  4779. ->offset(($data['page'] - 1) * $data['page_size'])
  4780. ->get();
  4781. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4782. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4783. })
  4784. ->where($where)
  4785. ->orderBy('updated_at', 'desc')
  4786. ->count();
  4787. } else {
  4788. $result = Notice::where($where)
  4789. // ->where('user_id', $data['user_id'])
  4790. ->Where(function ($query) use ($data) {
  4791. $query->Where(function ($q) use ($data) {
  4792. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4793. ->orWhere('notice.user_id', $data['user_id']);
  4794. });
  4795. })
  4796. ->when(!empty($data['status1']), function ($query) use ($data) {
  4797. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4798. })
  4799. ->orderBy('updated_at', 'desc')
  4800. ->limit($data['page_size'])
  4801. ->offset(($data['page'] - 1) * $data['page_size'])
  4802. ->get();
  4803. $total = Notice::where($where)
  4804. ->when(!empty($data['status1']), function ($query) use ($data) {
  4805. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4806. })
  4807. // ->where('user_id', $data['user_id'])
  4808. ->Where(function ($query) use ($data) {
  4809. $query->Where(function ($q) use ($data) {
  4810. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4811. ->orWhere('notice.user_id', $data['user_id']);
  4812. });
  4813. })
  4814. ->count();
  4815. }
  4816. if (empty($result)) {
  4817. return Result::error("查询失败", 0);
  4818. }
  4819. $data = [
  4820. 'rows' => $result,
  4821. 'count' => $total,
  4822. ];
  4823. return Result::success($data);
  4824. }
  4825. public function noticeList(array $data): array
  4826. {
  4827. $where = [];
  4828. //title
  4829. if (isset($data['title']) && !empty($data['title'])) {
  4830. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4831. }
  4832. //level
  4833. if (isset($data['level']) && !empty($data['level'])) {
  4834. $where[] = ['notice.level', '=', $data['level']];
  4835. }
  4836. //status
  4837. if (isset($data['status']) && !empty($data['status'])) {
  4838. $where[] = ['notice.status', '=', $data['status']];
  4839. }
  4840. //type
  4841. if (isset($data['type']) && !empty($data['type'])) {
  4842. $where[] = ['notice.type', '=', $data['type']];
  4843. }
  4844. var_dump($data, '------------11111-2----test---------');
  4845. if ($data['type_id'] == 10000) {
  4846. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4847. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4848. })
  4849. ->where($where)
  4850. ->orderBy('updated_at', 'desc')
  4851. ->limit($data['page_size'])
  4852. ->offset(($data['page'] - 1) * $data['page_size'])
  4853. ->get();
  4854. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4855. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4856. })
  4857. ->where($where)
  4858. ->orderBy('updated_at', 'desc')
  4859. ->count();
  4860. } else {
  4861. $result = Notice::where($where)
  4862. // ->where('user_id', $data['user_id'])
  4863. ->Where(function ($query) use ($data) {
  4864. $query->Where(function ($q) use ($data) {
  4865. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4866. ->orWhere('notice.user_id', $data['user_id']);
  4867. });
  4868. })
  4869. ->when(!empty($data['status1']), function ($query) use ($data) {
  4870. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4871. })
  4872. ->orderBy('updated_at', 'desc')
  4873. ->limit($data['page_size'])
  4874. ->offset(($data['page'] - 1) * $data['page_size'])
  4875. ->get();
  4876. $total = Notice::where($where)
  4877. ->when(!empty($data['status1']), function ($query) use ($data) {
  4878. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4879. })
  4880. // ->where('user_id', $data['user_id'])
  4881. ->Where(function ($query) use ($data) {
  4882. $query->Where(function ($q) use ($data) {
  4883. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4884. ->orWhere('notice.user_id', $data['user_id']);
  4885. });
  4886. })
  4887. ->count();
  4888. }
  4889. if (empty($result)) {
  4890. return Result::error("查询失败", 0);
  4891. }
  4892. $data = [
  4893. 'rows' => $result,
  4894. 'count' => $total,
  4895. ];
  4896. return Result::success($data);
  4897. }
  4898. public function getNoticeDetail(array $data): array
  4899. {
  4900. $result = Notice::where('id', $data['id'])->first();
  4901. if (empty($result)) {
  4902. return Result::error("查询失败", 0);
  4903. }
  4904. return Result::success($result);
  4905. }
  4906. public function deleteNotice(array $data): array
  4907. {
  4908. $notice = Notice::where('id', $data['id'])->first();
  4909. if (empty($notice)) {
  4910. return Result::error("删除失败", 0);
  4911. }
  4912. $chat_group_id = $notice->group_id;
  4913. if ($chat_group_id) {
  4914. //删除群聊
  4915. ChatGroups::where('id', $chat_group_id)->delete();
  4916. //删除群成员
  4917. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4918. //删除群聊记录
  4919. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4920. }
  4921. $result = Notice::where('id', $data['id'])->delete();
  4922. return Result::success($result);
  4923. }
  4924. public function complaintList(array $data): array
  4925. {
  4926. var_dump($data, '---------1---------');
  4927. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4928. unset($data['type_id']);
  4929. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4930. $where = [];
  4931. if ($type_id != 10000 && empty($data['deal_user'])) {
  4932. // $where['complaint.user_id'] = $user_id;
  4933. }
  4934. if (!empty($data['title'])) {
  4935. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4936. }
  4937. if (!empty($data['department_id'])) {
  4938. $where['complaint.department_id'] = $data['department_id'];
  4939. }
  4940. if (!empty($data['deal'])) {
  4941. $where['complaint.deal'] = $data['deal'];
  4942. }
  4943. if (!empty($data['status'])) {
  4944. $where['complaint.status'] = $data['status'];
  4945. }
  4946. var_dump(!empty($data['deal_user']), '----------1');
  4947. var_dump($where, '----------2');
  4948. $result = Complaint::where($where)
  4949. ->when(!empty($data['status1']), function ($query) use ($data) {
  4950. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4951. })
  4952. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4953. //json re_user_ids data[user_id]是不是在里面
  4954. $query->Where(function ($q) use ($data) {
  4955. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4956. ->where('complaint.status', 2);
  4957. });
  4958. })
  4959. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4960. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4961. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4962. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4963. ->orderBy('updated_at', 'desc')
  4964. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4965. //sql输出
  4966. if (empty($result)) {
  4967. return Result::error("暂无投诉信息", 0);
  4968. }
  4969. // 取出数据
  4970. $rows = $result->items();
  4971. $count = $result->total();
  4972. $responseData = [
  4973. 'rows' => $rows,
  4974. 'count' => $count,
  4975. ];
  4976. return Result::success($responseData);
  4977. }
  4978. public function getComplaintList(array $data): array
  4979. {
  4980. var_dump($data, '00000001000000000000');
  4981. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4982. unset($data['type_id']);
  4983. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4984. $where = [];
  4985. if ($type_id != 10000 && empty($data['deal_user'])) {
  4986. $where['complaint.user_id'] = $user_id;
  4987. }
  4988. if (!empty($data['title'])) {
  4989. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4990. }
  4991. if (!empty($data['department_id'])) {
  4992. $where['complaint.department_id'] = $data['department_id'];
  4993. }
  4994. if (!empty($data['deal'])) {
  4995. $where['complaint.deal'] = $data['deal'];
  4996. }
  4997. if (!empty($data['status'])) {
  4998. $where['complaint.status'] = $data['status'];
  4999. }
  5000. var_dump(!empty($data['deal_user']), '----------1');
  5001. var_dump($where, '----------2');
  5002. $result = Complaint::where($where)
  5003. ->when(!empty($data['status1']), function ($query) use ($data) {
  5004. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5005. })
  5006. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5007. // //json re_user_ids data[user_id]是不是在里面
  5008. // $query->Where(function ($q) use ($data) {
  5009. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5010. // ->where('complaint.status', 2);
  5011. // });
  5012. // })
  5013. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5014. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5015. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5016. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5017. ->orderBy('updated_at', 'desc')
  5018. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5019. //sql输出
  5020. if (empty($result)) {
  5021. return Result::error("暂无投诉信息", 0);
  5022. }
  5023. // 取出数据
  5024. $rows = $result->items();
  5025. $count = $result->total();
  5026. $responseData = [
  5027. 'rows' => $rows,
  5028. 'count' => $count,
  5029. ];
  5030. return Result::success($responseData);
  5031. }
  5032. public function getComplaintInfo(array $data): array
  5033. {
  5034. $result = Complaint::where('id', $data['id'])->first();
  5035. if (empty($result)) {
  5036. return Result::error("查询失败", 0);
  5037. }
  5038. return Result::success($result);
  5039. }
  5040. public function readComplaint(array $data): array
  5041. {
  5042. $result = Complaint::where('id', $data['id'])->first();
  5043. if (empty($result)) {
  5044. return Result::error("查询失败", 0);
  5045. }
  5046. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5047. $re_user_ids = json_decode($result['re_user_ids'], true);
  5048. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5049. //如果已经存在,就不再添加
  5050. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5051. $read_id = json_decode($result['read_id'], true);
  5052. if (!is_array($read_id)) {
  5053. $read_id = [];
  5054. }
  5055. if (!in_array($data['user_id'], $read_id)) {
  5056. $read_id[] = $data['user_id'];
  5057. $result['read_id'] = json_encode($read_id);
  5058. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5059. }
  5060. } else {
  5061. //如果不存在,就添加
  5062. $result['read_id'] = json_encode([$data['user_id']]);
  5063. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5064. }
  5065. }
  5066. return Result::success($result);
  5067. }
  5068. public function addComplaint(array $data): array
  5069. {
  5070. date_default_timezone_set('Asia/Shanghai');
  5071. $data['created_at'] = date('Y-m-d H:i:s');
  5072. $data['updated_at'] = date('Y-m-d H:i:s');
  5073. $this->sendMessage([
  5074. 'talk_type' => 800,
  5075. 'title' => $data['title'],
  5076. 'content' => '提交了审核',
  5077. 'messageType' => 6,
  5078. ]);
  5079. $result = Complaint::create($data);
  5080. return Result::success($result);
  5081. }
  5082. public function updateComplaint(array $data): array
  5083. {
  5084. date_default_timezone_set('Asia/Shanghai');
  5085. $data['updated_at'] = date('Y-m-d H:i:s');
  5086. $user_id = $data['user_id'] ?? 0;
  5087. $type_id = $data['type_id'] ?? 0;
  5088. unset($data['user_id']);
  5089. unset($data['type_id']);
  5090. $this->sendMessage([
  5091. 'talk_type' => 800,
  5092. 'title' => $data['title'],
  5093. 'content' => '提交了审核',
  5094. 'messageType' => 6,
  5095. ]);
  5096. $result = Complaint::where('id', $data['id'])->update($data);
  5097. return Result::success($result);
  5098. }
  5099. public function deleteComplaint(array $data): array
  5100. {
  5101. $result = Complaint::where('id', $data['id'])->delete();
  5102. return Result::success($result);
  5103. }
  5104. public function getComplainInfo(array $data): array
  5105. {
  5106. $result = Complaint::where('id', $data['id'])->first();
  5107. if (empty($result)) {
  5108. return Result::error("查询失败", 0);
  5109. }
  5110. return Result::success($result);
  5111. }
  5112. public function updateComplaintStatus(array $data): array
  5113. {
  5114. date_default_timezone_set('Asia/Shanghai');
  5115. $data['updated_at'] = date('Y-m-d H:i:s');
  5116. $user_id = $data['user_id'] ?? 0;
  5117. $type_id = $data['type_id'] ?? 0;
  5118. unset($data['user_id']);
  5119. unset($data['type_id']);
  5120. //处理, 写入处理人
  5121. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5122. $data['real_deal_user'] = $user_id;
  5123. }
  5124. //如果是deal 23,则判断是不是处理人
  5125. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5126. $complaintInof = Complaint::where('id', $data['id'])
  5127. ->where('real_deal_user', $user_id)
  5128. ->first();
  5129. if (empty($complaintInof)) {
  5130. return Result::error("处理人错误", 0);
  5131. }
  5132. }
  5133. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5134. if ($data['status'] == 1) {
  5135. $this->sendMessage([
  5136. 'talk_type' => 800,
  5137. 'title' => $complaintInfo['title'],
  5138. 'content' => '提交了审核',
  5139. 'messageType' => 6,
  5140. ]);
  5141. }
  5142. if ($data['status'] == 2 && !isset($data['deal'])) {
  5143. $this->sendMessage([
  5144. 'talk_type' => 801,
  5145. 'title' => $complaintInfo['title'],
  5146. 'content' => '审核通过',
  5147. 'messageType' => 6,
  5148. 'user_id' => $complaintInfo['user_id'],
  5149. ]);
  5150. $this->sendMessage([
  5151. 'talk_type' => 802,
  5152. 'title' => $complaintInfo['title'],
  5153. 'content' => '待处理',
  5154. 'messageType' => 6,
  5155. 'user_id' => $complaintInfo['re_user_ids'],
  5156. ]);
  5157. }
  5158. if ($data['status'] == 3 && !isset($data['deal'])) {
  5159. $this->sendMessage([
  5160. 'talk_type' => 801,
  5161. 'title' => $complaintInfo['title'],
  5162. 'content' => '审核拒绝',
  5163. 'messageType' => 6,
  5164. 'user_id' => $complaintInfo['user_id'],
  5165. ]);
  5166. }
  5167. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5168. $this->sendMessage([
  5169. 'talk_type' => 802,
  5170. 'title' => $complaintInfo['title'],
  5171. 'content' => '处理中',
  5172. 'messageType' => 6,
  5173. 'user_id' => $complaintInfo['re_user_ids'],
  5174. ]);
  5175. }
  5176. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5177. $this->sendMessage([
  5178. 'talk_type' => 802,
  5179. 'title' => $complaintInfo['title'],
  5180. 'content' => '不予处理',
  5181. 'messageType' => 6,
  5182. 'user_id' => $complaintInfo['re_user_ids'],
  5183. ]);
  5184. }
  5185. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5186. $this->sendMessage([
  5187. 'talk_type' => 802,
  5188. 'title' => $complaintInfo['title'],
  5189. 'content' => '已完结',
  5190. 'messageType' => 6,
  5191. 'user_id' => $complaintInfo['re_user_ids'],
  5192. ]);
  5193. }
  5194. $result = complaint::where('id', $data['id'])->update($data);
  5195. return Result::success($result);
  5196. }
  5197. public function updateGoodStatus(array $data): array
  5198. {
  5199. $user_id = $data['user_id'] ?? 0;
  5200. $type_id = $data['type_id'] ?? 0;
  5201. unset($data['user_id']);
  5202. unset($data['type_id']);
  5203. $goodInfo = Good::where('id', $data['id'])->first();
  5204. if ($data['status'] == 2) {
  5205. $this->sendMessage([
  5206. 'talk_type' => 201,
  5207. 'title' => $goodInfo['name'],
  5208. 'content' => '审核通过',
  5209. 'messageType' => 3,
  5210. 'user_id' => $goodInfo['user_id'],
  5211. ]);
  5212. }
  5213. if ($data['status'] == 3) {
  5214. $this->sendMessage([
  5215. 'talk_type' => 201,
  5216. 'title' => $goodInfo['name'],
  5217. 'content' => '审核拒绝',
  5218. 'messageType' => 3,
  5219. 'user_id' => $goodInfo['user_id'],
  5220. ]);
  5221. }
  5222. if ($data['status'] == 1) {
  5223. $this->sendMessage([
  5224. 'talk_type' => 200,
  5225. 'title' => $goodInfo['name'],
  5226. 'content' => '提交了审核',
  5227. 'messageType' => 3,
  5228. ]);
  5229. }
  5230. $result = Good::where('id', $data['id'])->update($data);
  5231. return Result::success($result);
  5232. }
  5233. public function updateJobHuntingStatus(array $data): array
  5234. {
  5235. $user_id = $data['user_id'] ?? 0;
  5236. $type_id = $data['type_id'] ?? 0;
  5237. unset($data['user_id']);
  5238. unset($data['type_id']);
  5239. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5240. if ($data['status'] == 2) {
  5241. $this->sendMessage([
  5242. 'talk_type' => 601,
  5243. 'title' => $jogHuntingInfo['name'],
  5244. 'content' => '审核通过',
  5245. 'messageType' => 11,
  5246. 'user_id' => $jogHuntingInfo['user_id'],
  5247. ]);
  5248. }
  5249. if ($data['status'] == 3) {
  5250. $this->sendMessage([
  5251. 'talk_type' => 601,
  5252. 'title' => $jogHuntingInfo['name'],
  5253. 'content' => '审核拒绝',
  5254. 'messageType' => 11,
  5255. 'user_id' => $jogHuntingInfo['user_id'],
  5256. ]);
  5257. }
  5258. if ($data['status'] == 1) {
  5259. $this->sendMessage([
  5260. 'talk_type' => 600,
  5261. 'title' => $jogHuntingInfo['name'],
  5262. 'content' => '提交了审核',
  5263. 'messageType' => 11,
  5264. ]);
  5265. }
  5266. $result = JobHunting::where('id', $data['id'])->update($data);
  5267. return Result::success($result);
  5268. }
  5269. public function updateNoticeStatus(array $data): array
  5270. {
  5271. $user_id = $data['user_id'] ?? 0;
  5272. $type_id = $data['type_id'] ?? 0;
  5273. unset($data['user_id']);
  5274. unset($data['type_id']);
  5275. //查询公告
  5276. $notice = Notice::where('id', $data['id'])->first();
  5277. if (empty($notice)) {
  5278. return Result::error("公告不存在", 0);
  5279. }
  5280. //$chat_ids 去除掉$data['user_id']
  5281. $chat_ids = json_decode($notice['re_user_ids'], true);
  5282. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5283. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5284. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5285. //chat_group
  5286. $group_id = PublicData::uuid();
  5287. $groupData = [
  5288. 'id' => $group_id,
  5289. 'creator_id' => $notice['user_id'],
  5290. 'group_name' => $notice['group_name'] ?? '',
  5291. 'profile' => $notice['profile'] ?? 0,
  5292. ];
  5293. var_dump($groupData, '-----------------groupData-------');
  5294. $groupResult = ChatGroups::insertGetId($groupData);
  5295. var_dump($groupResult, '-----------------groupid-------');
  5296. $groupMemberData = [
  5297. 'id' => PublicData::uuid(),
  5298. 'user_id' => $notice['user_id'],
  5299. 'group_id' => $group_id,
  5300. 'leader' => 2,
  5301. ];
  5302. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5303. //插入群成员表
  5304. $groupMemberDataUser = [];
  5305. $chatData = [];
  5306. foreach ($chat_ids as $key => $value) {
  5307. $groupMemberDataUser[] = [
  5308. 'id' => PublicData::uuid(),
  5309. 'user_id' => $value,
  5310. 'group_id' => $group_id,
  5311. 'leader' => 1,
  5312. ];
  5313. $chatData[] = [
  5314. 'user_id' => $value,
  5315. 'msg_type' => 1,
  5316. 'receiver_id' => $group_id,
  5317. 'content' => '通过通知创建群聊',
  5318. 'group_receiver_id' => $notice['user_id'],
  5319. 'action' => 'recieved',
  5320. 'created_at' => date('Y-m-d H:i:s'),
  5321. ];
  5322. }
  5323. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5324. ChatGroupsMember::insert($groupMemberDataUser);
  5325. //插入一条管理员聊天记录
  5326. $chatData[] = [
  5327. 'user_id' => $notice['user_id'],
  5328. 'msg_type' => 1,
  5329. 'receiver_id' => $group_id,
  5330. 'content' => '通过通知创建群聊',
  5331. 'group_receiver_id' => $notice['user_id'],
  5332. 'action' => 'said',
  5333. 'created_at' => date('Y-m-d H:i:s'),
  5334. ];
  5335. var_dump($chatData, '-----------------chatData-------');
  5336. $chatResult = ChatRecords::insert($chatData);
  5337. //处理imp
  5338. $group = [
  5339. 'type' => 1,
  5340. 'name' => $notice['group_name'] ?? '',
  5341. 'profile' => '',
  5342. 'avatar' => '',
  5343. 'creator_id' => $notice['user_id'],
  5344. ];
  5345. $groupResult = GroupImp::insertGetId($group);
  5346. var_dump($groupResult, '获取imp group_id');
  5347. $groupMember = [
  5348. 'user_id' => $notice['user_id'],
  5349. 'group_id' => $groupResult,
  5350. 'leader' => 1,
  5351. 'join_time' => Date('Y-m-d H:i:s')
  5352. ];
  5353. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5354. $talk_session = [
  5355. 'user_id' => $notice['user_id'],
  5356. 'to_from_id' => $groupResult,
  5357. 'talk_mode' => 2,
  5358. 'created_at' => Date('Y-m-d H:i:s'),
  5359. 'updated_at' => Date('Y-m-d H:i:s'),
  5360. ];
  5361. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5362. //被通知人员处理
  5363. foreach ($chat_ids as $key => $value) {
  5364. $groupMemberdata[] = [
  5365. 'user_id' => $value,
  5366. 'group_id' => $groupResult,
  5367. 'leader' => 3,
  5368. 'join_time' => Date('Y-m-d H:i:s')
  5369. ];
  5370. $talk_sessionData[] = [
  5371. 'user_id' => $value,
  5372. 'to_from_id' => $groupResult,
  5373. 'talk_mode' => 2,
  5374. 'created_at' => Date('Y-m-d H:i:s'),
  5375. 'updated_at' => Date('Y-m-d H:i:s'),
  5376. ];
  5377. }
  5378. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5379. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5380. $group_id = $groupResult;
  5381. //更新result的 group_id
  5382. $data['group_id'] = $group_id;
  5383. Notice::where(['id' => $data['id']])->update($data);
  5384. }
  5385. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5386. //删除掉信息
  5387. GroupImp::where('id', $notice['group_id'])->delete();
  5388. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5389. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5390. foreach ($chat_ids as $key => $value) {
  5391. }
  5392. //聊天记录删除
  5393. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5394. $data['group_id'] = null;
  5395. Notice::where(['id' => $data['id']])->update($data);
  5396. }
  5397. $result = Notice::where('id', $data['id'])->update($data);
  5398. $noticeInfo = Notice::where('id', $data['id'])->first();
  5399. if ($data['status'] == 2) {
  5400. $this->sendMessage([
  5401. 'talk_type' => 701,
  5402. 'title' => $noticeInfo['title'],
  5403. 'content' => '审核通过',
  5404. 'messageType' => 3,
  5405. 'user_id' => $noticeInfo['user_id'],
  5406. ]);
  5407. }
  5408. if ($data['status'] == 3) {
  5409. $this->sendMessage([
  5410. 'talk_type' => 701,
  5411. 'title' => $noticeInfo['title'],
  5412. 'content' => '审核拒绝',
  5413. 'messageType' => 3,
  5414. 'user_id' => $noticeInfo['user_id'],
  5415. ]);
  5416. }
  5417. if ($data['status'] == 1) {
  5418. $this->sendMessage([
  5419. 'talk_type' => 700,
  5420. 'title' => $noticeInfo['title'],
  5421. 'content' => '提交了审核',
  5422. 'messageType' => 3,
  5423. ]);
  5424. }
  5425. return Result::success($result);
  5426. }
  5427. public function getDUser(array $data): array
  5428. {
  5429. if (!empty($data['ids'])) {
  5430. $user = User::whereIn('id', $data['ids'])->getall();
  5431. if (empty($user)) {
  5432. return Result::error('无数据', 0);
  5433. }
  5434. return Result::success($user);
  5435. }
  5436. $where = [];
  5437. if (!empty($data['department_id'])) {
  5438. $where['department_id'] = $data['department_id'];
  5439. }
  5440. if (!empty($data['city_id'])) {
  5441. $where['city_id'] = $data['city_id'];
  5442. }
  5443. $result = User::where('type_id', 2)
  5444. ->where('status', 1)
  5445. ->where($where)
  5446. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5447. ->get();
  5448. if (empty($result)) {
  5449. return Result::error("查询失败", 0);
  5450. }
  5451. return Result::success($result);
  5452. }
  5453. /**
  5454. * 验证导航名称是否重复
  5455. * @return void
  5456. */
  5457. public function checkCategoryName(array $data): array
  5458. {
  5459. $result = Category::when($data, function ($query) use ($data) {
  5460. if (isset($data['name']) && $data['name']) {
  5461. $query->where("name", $data['name']);
  5462. }
  5463. if (isset($data['id']) && $data['id']) {
  5464. $query->where("id", "!=", $data['id']);
  5465. }
  5466. })->first();
  5467. if ($result) {
  5468. return Result::error("已存在");
  5469. } else {
  5470. return Result::success();
  5471. }
  5472. }
  5473. //20250226 产品列表
  5474. // 20250306 -------招聘--------fr
  5475. /*
  5476. * 招聘列表
  5477. * */
  5478. public function getJobRecruitingList(array $data): array
  5479. {
  5480. $where = [];
  5481. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5482. if ($data['checkout'] == 0) {
  5483. $job_status = [0, 2];
  5484. } else {
  5485. $job_status = [1];
  5486. }
  5487. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5488. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5489. }
  5490. $user = User::where('id', $data['user_id'])->first();
  5491. if (empty($user)) {
  5492. return Result::error("用户不存在", 0);
  5493. }
  5494. // 3:企业会员
  5495. if ($user['type_id'] == 3) {
  5496. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5497. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5498. }
  5499. // 如果 $where 为空,则不添加 where 条件
  5500. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5501. return $query->where($where);
  5502. })
  5503. ->whereIn('job_recruiting.status', $job_status)
  5504. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5505. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5506. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5507. ->orderBy("updated_at", "desc")
  5508. ->offset(($data['page'] - 1) * $data['page_size'])
  5509. ->limit($data['page_size'])
  5510. ->get()
  5511. ->all();
  5512. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5513. return $query->where($where);
  5514. })
  5515. ->whereIn('job_recruiting.status', $job_status)
  5516. ->count();
  5517. if (empty($result)) {
  5518. return Result::error("暂无招聘信息", 0);
  5519. }
  5520. return Result::success($result);
  5521. }
  5522. /*
  5523. * 招聘信息添加
  5524. * */
  5525. public function addJobRecruiting(array $data): array
  5526. {
  5527. // var_dump('添加招聘进入news------data',$data);
  5528. // return Result::success($data);
  5529. $user = User::where('user.id', $data['user_id'])
  5530. ->where('user.status', 1)
  5531. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5532. ->select(
  5533. 'user.type_id',
  5534. 'user.mobile',
  5535. 'user.email',
  5536. 'user_info.business_name',
  5537. 'user_info.company_hy_id',
  5538. 'user_info.company_nature',
  5539. 'user_info.company_size',
  5540. 'user_info.introduction',
  5541. 'user_info.real_name',
  5542. 'user_info.company_url',
  5543. 'user_info.address_arr_id',
  5544. 'user_info.address'
  5545. )
  5546. ->first();
  5547. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5548. return Result::error("用户不存在", 0);
  5549. }
  5550. $web = Website::where('id', $data['website_id'])->first();
  5551. if (empty($web)) {
  5552. return Result::error("网站不存在", 0);
  5553. }
  5554. // var_dump('添加招聘进入news---user---user',$user);
  5555. // 处理招聘关键词
  5556. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5557. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5558. } else {
  5559. Jieba::init(); // 初始化 jieba-php
  5560. Finalseg::init();
  5561. $segList = Jieba::cut($data['title']);
  5562. $segList1 = array_slice($segList, 0, 8);
  5563. $data['keyword'] = implode(',', $segList1);
  5564. }
  5565. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5566. $content = $data['description'];
  5567. // 去除 <style> 和 <script> 标签及其内容
  5568. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5569. // 去除所有 HTML 标签
  5570. $content = strip_tags($content);
  5571. // 去除 HTML 实体
  5572. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5573. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5574. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5575. // 去除多余空白
  5576. $content = preg_replace('/\s+/u', '', $content);
  5577. // 截取 100 个字符
  5578. $data['seo_description'] = mb_substr($content, 0, 100);
  5579. }
  5580. // return Result::success($user);
  5581. $data['action_id'] = $data['user_id'] ?? null;
  5582. $data['user_type'] = $user['type_id'] ?? null;
  5583. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5584. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5585. $data['catid'] = end($data['cat_arr_id']);
  5586. } else {
  5587. $data['catid'] = 0;
  5588. }
  5589. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5590. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5591. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5592. // 公司地址 管理员必填
  5593. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5594. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5595. // 管理员-企业相关信息
  5596. $company = [
  5597. // 'user_id' => $data['user_id']?? null,
  5598. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5599. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5600. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5601. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5602. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5603. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5604. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5605. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5606. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5607. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5608. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5609. ];
  5610. //去掉相关企业信息
  5611. $job = array_diff_key($data, array_flip(array_keys($company)));
  5612. // var_dump('添加招聘进入news---job---user',$job);
  5613. Db::beginTransaction();
  5614. try {
  5615. // // 先添加职位相关信息
  5616. if ($user['type_id'] == 10000) {
  5617. $job['status'] = 1;
  5618. }
  5619. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5620. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5621. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5622. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5623. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5624. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5625. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5626. // return Result::success($job);
  5627. $jobId = JobRecruiting::insertGetId($job);
  5628. if (empty($jobId)) {
  5629. Db::rollBack();
  5630. return Result::error("添加失败");
  5631. }
  5632. // 添加公司信息
  5633. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5634. $company['job_id'] = $jobId;
  5635. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5636. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5637. if ($user['type_id'] == 10000) {
  5638. // 管理员添加企业信息
  5639. $companyId = JobCompany::insertGetId($company);
  5640. if (empty($companyId)) {
  5641. Db::rollBack();
  5642. return Result::error("添加失败");
  5643. }
  5644. } else {
  5645. // 企业会员添加企业信息
  5646. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5647. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5648. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5649. $company['job_id'] = $jobId;
  5650. $companyId = JobCompany::insertGetId($company);
  5651. if (empty($companyId)) {
  5652. Db::rollBack();
  5653. return Result::error("添加失败");
  5654. }
  5655. }
  5656. Db::commit();
  5657. $result = [
  5658. 'job_id' => $jobId,
  5659. 'company_id' => $companyId,
  5660. ];
  5661. return Result::success($result);
  5662. } catch (\Exception $e) {
  5663. Db::rollBack();
  5664. return Result::error($e->getMessage(), 0);
  5665. }
  5666. // return Result::success($result);
  5667. }
  5668. /*
  5669. * 获取招聘信息详情
  5670. * */
  5671. public function getJobRecruitingInfo(array $data): array
  5672. {
  5673. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5674. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5675. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5676. ->select(
  5677. 'job_recruiting.*',
  5678. 'website.website_name as website_name',
  5679. 'job_company.business_name',
  5680. 'job_company.company_hy_id',
  5681. 'job_company.company_size',
  5682. 'job_company.company_nature',
  5683. 'job_company.introduction',
  5684. 'job_company.real_name',
  5685. 'job_company.mobile',
  5686. 'job_company.company_url',
  5687. 'job_company.address_arr_id',
  5688. 'job_company.address',
  5689. 'job_company.email'
  5690. )
  5691. ->first();
  5692. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5693. if (!empty($cityId)) {
  5694. if (isset($cityId[1]) && $cityId[1] != null) {
  5695. $city = District::where('id', $cityId[1])->first(['name']);
  5696. } else {
  5697. $city = District::where('id', $cityId[0])->first(['name']);
  5698. }
  5699. $result['city'] = $city['name'] ?? '';
  5700. }
  5701. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5702. if (is_array($addressId) && !empty($addressId)) {
  5703. $address = District::whereIn('id', $addressId)
  5704. ->orderBy('level', 'asc')
  5705. ->get(['name'])
  5706. ->pluck('name')
  5707. ->implode('');
  5708. // $job->address_name = $address ?? '';
  5709. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5710. }
  5711. if (empty($result)) {
  5712. return Result::error("招聘信息不存在", 0);
  5713. }
  5714. // return Result::success($job);
  5715. return Result::success($result);
  5716. }
  5717. /*
  5718. * 修改招聘信息
  5719. * */
  5720. public function upJobRecruiting(array $data): array
  5721. {
  5722. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5723. // return Result::success($job);
  5724. if (empty($job)) {
  5725. return Result::error("招聘信息不存在", 0);
  5726. }
  5727. $user = User::where('id', $data['user_id'])->first();
  5728. // return Result::success($user);
  5729. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5730. return Result::error("用户不存在", 0);
  5731. }
  5732. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5733. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5734. }
  5735. // 处理招聘关键词
  5736. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5737. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5738. } else {
  5739. Jieba::init(); // 初始化 jieba-php
  5740. Finalseg::init();
  5741. $segList = Jieba::cut($data['title']);
  5742. $segList1 = array_slice($segList, 0, 8);
  5743. $data['keyword'] = implode(',', $segList1);
  5744. }
  5745. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5746. $content = $data['description'];
  5747. // 去除 <style> 和 <script> 标签及其内容
  5748. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5749. // 去除所有 HTML 标签
  5750. $content = strip_tags($content);
  5751. // 去除 HTML 实体
  5752. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5753. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5754. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5755. // 去除多余空白
  5756. $content = preg_replace('/\s+/u', '', $content);
  5757. // 截取 100 个字符
  5758. $data['seo_description'] = mb_substr($content, 0, 100);
  5759. }
  5760. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5761. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5762. $data['catid'] = end($data['cat_arr_id']);
  5763. } else {
  5764. }
  5765. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5766. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5767. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5768. // 公司地址 管理员必填
  5769. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5770. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5771. // 管理员-企业相关信息
  5772. $company = [
  5773. // 'user_id' => $data['user_id']?? null,
  5774. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5775. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5776. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5777. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5778. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5779. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5780. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5781. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5782. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5783. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5784. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5785. ];
  5786. //去掉相关企业信息
  5787. $data = array_diff_key($data, array_flip(array_keys($company)));
  5788. $jobId = $data['id'];
  5789. $web = $data['website_id'];
  5790. $data['action_id'] = $data['user_id'];
  5791. unset($data['user_id']);
  5792. unset($data['user_type']);
  5793. unset($data['id']);
  5794. unset($data['website_id']);
  5795. // return Result::success($data);
  5796. Db::beginTransaction();
  5797. try {
  5798. // 管理员修改招聘信息
  5799. if ($user['type_id'] == 10000) {
  5800. $data['website_id'] = $web;
  5801. $company['website_id'] = $data['website_id'];
  5802. $data['status'] = 1;
  5803. } else {
  5804. $data['status'] = 0;
  5805. }
  5806. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5807. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5808. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5809. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5810. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5811. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5812. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5813. // return Result::success($job);
  5814. // Db::rollBack();
  5815. // return Result::success($company);
  5816. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5817. $this->sendMessage([
  5818. 'talk_type' => 500,
  5819. 'title' => $data['title'],
  5820. 'content' => '提交了审核',
  5821. 'messageType' => 10,
  5822. ]);
  5823. }
  5824. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5825. if (empty($result['job'])) {
  5826. Db::rollBack();
  5827. return Result::error("修改招聘信息失败");
  5828. }
  5829. // 管理员修改企业相关信息
  5830. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5831. if (empty($result['company'])) {
  5832. Db::rollBack();
  5833. return Result::error("修改企业相关信息失败");
  5834. }
  5835. Db::commit();
  5836. // return Result::success($result);
  5837. } catch (\Exception $e) {
  5838. Db::rollBack();
  5839. return Result::error($e->getMessage(), 0);
  5840. }
  5841. return Result::success($result);
  5842. }
  5843. /*
  5844. * 招聘信息删除
  5845. * */
  5846. public function delJobRecruiting(array $data): array
  5847. {
  5848. $user = User::where('id', $data['user_id'])->first();
  5849. if (empty($user)) {
  5850. return Result::error("用户不存在", 0);
  5851. }
  5852. $job = JobRecruiting::where('id', $data['id'])->first();
  5853. if (empty($job)) {
  5854. return Result::error("招聘信息不存在", 0);
  5855. }
  5856. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5857. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5858. }
  5859. Db::beginTransaction();
  5860. try {
  5861. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5862. if (empty($result['job'])) {
  5863. Db::rollBack();
  5864. return Result::error("删除招聘信息失败");
  5865. }
  5866. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5867. if (empty($result['company'])) {
  5868. Db::rollBack();
  5869. return Result::error("删除企业相关信息失败");
  5870. }
  5871. Db::commit();
  5872. } catch (\Exception $e) {
  5873. Db::rollBack();
  5874. return Result::error($e->getMessage(), 0);
  5875. }
  5876. return Result::success($result);
  5877. }
  5878. /*
  5879. * 获取公司信息
  5880. * */
  5881. public function getJobCompany(array $data): array
  5882. {
  5883. $user = User::where('user.id', $data['user_id'])
  5884. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5885. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5886. ->first();
  5887. // return Result::success($user);
  5888. if (empty($user)) {
  5889. return Result::error("用户不存在", 0);
  5890. }
  5891. if ($user['type_id'] == 3) {
  5892. $result = [
  5893. // 'id' => 0,
  5894. 'user_id' => $data['user_id'],
  5895. 'website_id' => $data['website_id'],
  5896. 'business_name' => $user['business_name'], // 企业名称
  5897. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5898. 'company_nature' => $user['company_nature'], // 公司性质
  5899. 'company_size' => $user['company_size'], // 公司规模
  5900. 'introduction' => $user['introduction'], // 公司简介
  5901. 'real_name' => $user['real_name'], // 企业联系人
  5902. 'mobile' => $user['mobile'], // 企业联系电话
  5903. 'company_url' => $user['company_url'], // 企业网址
  5904. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5905. 'address' => $user['address'], // 企业地址
  5906. 'email' => $user['email'], // 企业邮箱
  5907. ];
  5908. } else {
  5909. return Result::error("用户类型错误", 0);
  5910. }
  5911. if (empty($result)) {
  5912. return Result::error("公司信息不存在", 0);
  5913. }
  5914. return Result::success($result);
  5915. }
  5916. /*
  5917. * 修改公司信息
  5918. * */
  5919. public function upJobCompany(array $data): array
  5920. {
  5921. // return Result::success($data);
  5922. $user = User::where('user.id', $data['user_id'])
  5923. ->where('user.status', 1)
  5924. ->select('user.user_name', 'user.type_id')
  5925. ->first();
  5926. if (empty($user)) {
  5927. return Result::error("用户不存在", 0);
  5928. }
  5929. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5930. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5931. $company = [
  5932. 'business_name' => $data['business_name'], // 企业名称
  5933. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5934. 'company_nature' => $data['company_nature'], // 公司性质
  5935. 'company_size' => $data['company_size'], // 公司规模
  5936. 'introduction' => $data['introduction'], // 公司简介
  5937. // 'real_name' => $data['real_name'], // 企业联系人
  5938. 'company_url' => $data['company_url'], // 企业网址
  5939. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5940. 'address' => $data['address'], // 企业详细地址
  5941. // 'email' => $data['email'], // 企业邮箱
  5942. ];
  5943. if ($user['type_id'] == 3) {
  5944. Db::beginTransaction();
  5945. try {
  5946. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5947. 'business_name' => $data['business_name'], // 企业名称
  5948. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5949. 'company_nature' => $data['company_nature'], // 公司性质
  5950. 'company_size' => $data['company_size'], // 公司规模
  5951. 'introduction' => $data['introduction'], // 公司简介
  5952. // 'real_name' => $data['real_name'], // 企业联系人
  5953. 'company_url' => $data['company_url'], // 企业网址
  5954. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5955. 'address' => $data['address'], // 企业详细地址
  5956. ]);
  5957. if (empty($result['userinfo'])) {
  5958. Db::rollBack();
  5959. return Result::error('修改企业会员信息失败!');
  5960. }
  5961. $result['user'] = User::where('id', $data['user_id'])->update([
  5962. 'email' => $data['email'], // 企业邮箱
  5963. ]);
  5964. if (empty($result['user'])) {
  5965. Db::rollBack();
  5966. return Result::error('修改个人中心信息失败!');
  5967. }
  5968. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5969. if (!empty($job_company)) {
  5970. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5971. if (empty($result['job_company'])) {
  5972. Db::rollBack();
  5973. return Result::error('修改企业会员信息失败!');
  5974. }
  5975. }
  5976. Db::commit();
  5977. return Result::success($result);
  5978. } catch (\Exception $e) {
  5979. Db::rollBack();
  5980. return Result::error($e->getMessage(), 0);
  5981. }
  5982. } else {
  5983. return Result::error("用户类型错误", 0);
  5984. }
  5985. }
  5986. /*
  5987. * 获取省-市
  5988. * */
  5989. public function getJobRecruitingArea(array $data): array
  5990. {
  5991. if (isset($data['pid']) && $data['pid'] != null) {
  5992. $result = District::where('pid', $data['pid'])->get()->all();
  5993. } else {
  5994. $result = District::where('level', 1)->get()->all();
  5995. }
  5996. if (empty($result)) {
  5997. return Result::error("暂无此省市", 0);
  5998. }
  5999. return Result::success($result);
  6000. }
  6001. /*
  6002. * 获取行业分类
  6003. * */
  6004. public function getIndustry(array $data): array
  6005. {
  6006. $result = JobIndustry::get()->all();
  6007. if (empty($result)) {
  6008. return Result::error("暂无行业分类", 0);
  6009. }
  6010. return Result::success($result);
  6011. }
  6012. /*
  6013. * 获取职位
  6014. * */
  6015. public function getPositionList(array $data): array
  6016. {
  6017. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6018. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6019. } else {
  6020. $result = JobPosition::where('zwpid', 0)->get()->all();
  6021. }
  6022. if (empty($result)) {
  6023. return Result::error("暂无此职位", 0);
  6024. }
  6025. return Result::success($result);
  6026. }
  6027. /*
  6028. * 获取工作性质-菜单
  6029. * */
  6030. public function getJobNature(array $data): array
  6031. {
  6032. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6033. if (empty($result)) {
  6034. return Result::error("暂无工作性质", 0);
  6035. }
  6036. return Result::success($result);
  6037. }
  6038. /*
  6039. * 获取工作经验-菜单
  6040. * */
  6041. public function getExperience(array $data): array
  6042. {
  6043. $result = JobEnum::where('egroup', 'years')->get()->all();
  6044. if (empty($result)) {
  6045. return Result::error("暂无工作经验", 0);
  6046. }
  6047. return Result::success($result);
  6048. }
  6049. /*
  6050. * 获取学历-菜单
  6051. * */
  6052. public function getEducation(array $data): array
  6053. {
  6054. $result = JobEnum::where('egroup', 'education')->get()->all();
  6055. if (empty($result)) {
  6056. return Result::error("暂无学历", 0);
  6057. }
  6058. return Result::success($result);
  6059. }
  6060. /*
  6061. * 获取薪资-菜单
  6062. * */
  6063. public function getSalary(array $data): array
  6064. {
  6065. $result = JobEnum::where('egroup', 'income')->get()->all();
  6066. if (empty($result)) {
  6067. return Result::error("暂无薪资", 0);
  6068. }
  6069. return Result::success($result);
  6070. }
  6071. /*
  6072. * 获取语言-菜单
  6073. * */
  6074. public function getLanguage(array $data): array
  6075. {
  6076. $result = JobEnum::where('egroup', 'language')->get()->all();
  6077. if (empty($result)) {
  6078. return Result::error("暂无语言", 0);
  6079. }
  6080. return Result::success($result);
  6081. }
  6082. /*
  6083. * 获取掌握程度-菜单
  6084. * */
  6085. public function getLevel(array $data): array
  6086. {
  6087. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6088. if (empty($result)) {
  6089. return Result::error("暂无工作性质", 0);
  6090. }
  6091. return Result::success($result);
  6092. }
  6093. // 公司信息
  6094. /*
  6095. * 获取公司性质-菜单
  6096. * */
  6097. public function getCompanyNature(array $data): array
  6098. {
  6099. $result = JobNature::get()->all();
  6100. if (empty($result)) {
  6101. return Result::error("暂无公司性质", 0);
  6102. }
  6103. return Result::success($result);
  6104. }
  6105. /*
  6106. * 获取公司规模-菜单
  6107. * */
  6108. public function getCompanySize(array $data): array
  6109. {
  6110. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6111. if (empty($result)) {
  6112. return Result::error("暂无公司规模", 0);
  6113. }
  6114. return Result::success($result);
  6115. }
  6116. /*
  6117. * 招聘信息审核
  6118. * */
  6119. public function checkJobRecruiting(array $data): array
  6120. {
  6121. $user = User::where('id', $data['user_id'])->first();
  6122. if (empty($user)) {
  6123. return Result::error("用户不存在", 0);
  6124. }
  6125. $job = JobRecruiting::where('id', $data['id'])->first();
  6126. if (empty($job)) {
  6127. return Result::error("招聘信息不存在", 0);
  6128. }
  6129. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6130. if ($user['type_id'] != 10000) {
  6131. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6132. }
  6133. // 驳回原因
  6134. if ($data['status'] == 2) {
  6135. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6136. }
  6137. $data['action_id'] = $data['user_id'];
  6138. unset($data['user_id']);
  6139. if ($data['status'] == 1) {
  6140. $this->sendMessage([
  6141. 'talk_type' => 501,
  6142. 'title' => $job['title'],
  6143. 'content' => '审核通过',
  6144. 'messageType' => 10,
  6145. 'user_id' => $job['user_id'],
  6146. ]);
  6147. }
  6148. if ($data['status'] == 2) {
  6149. $this->sendMessage([
  6150. 'talk_type' => 501,
  6151. 'title' => $job['title'],
  6152. 'content' => '审核拒绝',
  6153. 'messageType' => 10,
  6154. 'user_id' => $job['user_id'],
  6155. ]);
  6156. }
  6157. if ($data['status'] == 0) {
  6158. $this->sendMessage([
  6159. 'talk_type' => 500,
  6160. 'title' => $job['title'],
  6161. 'content' => '提交了审核',
  6162. 'messageType' => 10,
  6163. ]);
  6164. }
  6165. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6166. if (empty($result)) {
  6167. return Result::error("审核失败", 0);
  6168. }
  6169. return Result::success($result);
  6170. }
  6171. public function myApplyList(array $data): array
  6172. {
  6173. var_dump($data, '------参数');
  6174. $user = User::where('id', $data['user_id'])->first();
  6175. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6176. return Result::error("用户不存在", 0);
  6177. }
  6178. // 1:个人会员 职场机会
  6179. if ($user['type_id'] == 1) {
  6180. $where['user_id'] = $user['id'];
  6181. }
  6182. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6183. $query->where('user_id', $user['id']);
  6184. })
  6185. ->pluck('recruit_id');
  6186. $where = [];
  6187. if (isset($data['salary']) && $data['salary'] != null) {
  6188. $where['job_recruiting.salary'] = $data['salary'];
  6189. }
  6190. if (isset($data['experience']) && $data['experience'] != null) {
  6191. $where['job_recruiting.experience'] = $data['experience'];
  6192. }
  6193. if (isset($data['business_name']) && $data['business_name'] != null) {
  6194. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6195. }
  6196. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6197. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6198. ->where($where);
  6199. // ->count();
  6200. $count = $query->count();
  6201. $query = clone $query;
  6202. $job = $query
  6203. ->leftJoin('job_enum as income_enum', function ($join) {
  6204. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6205. ->where('income_enum.egroup', 'income');
  6206. })
  6207. ->leftJoin('job_enum as years_enum', function ($join) {
  6208. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6209. ->where('years_enum.egroup', 'years');
  6210. })
  6211. // ->where($where)
  6212. ->orderBy('job_recruiting.updated_at', 'desc')
  6213. ->select(
  6214. 'job_recruiting.id',
  6215. 'job_recruiting.title',
  6216. 'job_company.business_name',
  6217. 'income_enum.evalue as salary_evalue',
  6218. 'income_enum.ename as salary_ename',
  6219. 'years_enum.evalue as experience_evalue',
  6220. 'years_enum.ename as experience_ename',
  6221. 'job_recruiting.updated_at'
  6222. )
  6223. ->offset(($data['page'] - 1) * $data['pageSize'])
  6224. ->limit($data['pageSize'])
  6225. ->get()
  6226. ->all();
  6227. if (empty($job)) {
  6228. return Result::error("暂无招聘信息", 0);
  6229. }
  6230. $result = [
  6231. 'row' => $job,
  6232. 'count' => $count,
  6233. ];
  6234. return Result::success($result);
  6235. }
  6236. public function readJobApply(array $data): array
  6237. {
  6238. $result = JobApply::where('id', $data['id'])->first();
  6239. if (empty($result)) {
  6240. return Result::error("查询失败", 0);
  6241. }
  6242. $result = JobApply::where('id', $data['id'])->update([
  6243. 'status' => 2,
  6244. ]);
  6245. return Result::success($result);
  6246. }
  6247. /*
  6248. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6249. * */
  6250. public function getRecruitingList(array $data): array
  6251. {
  6252. $user = User::where('id', $data['user_id'])->first();
  6253. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6254. return Result::error("用户不存在", 0);
  6255. }
  6256. // 1:个人会员 职场机会
  6257. if ($user['type_id'] == 1) {
  6258. $where['user_id'] = $user['id'];
  6259. }
  6260. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6261. $query->where('receiver_id', $user['id']);
  6262. })
  6263. ->pluck('recruit_id');
  6264. // return Result::success($recruitingId);
  6265. $where = [];
  6266. if (isset($data['salary']) && $data['salary'] != null) {
  6267. $where['job_recruiting.salary'] = $data['salary'];
  6268. }
  6269. if (isset($data['experience']) && $data['experience'] != null) {
  6270. $where['job_recruiting.experience'] = $data['experience'];
  6271. }
  6272. if (isset($data['business_name']) && $data['business_name'] != null) {
  6273. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6274. }
  6275. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6276. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6277. ->where($where);
  6278. // ->count();
  6279. $count = $query->count();
  6280. $query = clone $query;
  6281. $job = $query
  6282. ->leftJoin('job_enum as income_enum', function ($join) {
  6283. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6284. ->where('income_enum.egroup', 'income');
  6285. })
  6286. ->leftJoin('job_enum as years_enum', function ($join) {
  6287. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6288. ->where('years_enum.egroup', 'years');
  6289. })
  6290. // ->where($where)
  6291. ->orderBy('job_recruiting.updated_at', 'desc')
  6292. ->select(
  6293. 'job_recruiting.id',
  6294. 'job_recruiting.title',
  6295. 'job_company.business_name',
  6296. 'income_enum.evalue as salary_evalue',
  6297. 'income_enum.ename as salary_ename',
  6298. 'years_enum.evalue as experience_evalue',
  6299. 'years_enum.ename as experience_ename',
  6300. 'job_recruiting.updated_at'
  6301. )
  6302. ->offset(($data['page'] - 1) * $data['pageSize'])
  6303. ->limit($data['pageSize'])
  6304. ->get()
  6305. ->all();
  6306. if (empty($job)) {
  6307. return Result::error("暂无招聘信息", 0);
  6308. }
  6309. $result = [
  6310. 'row' => $job,
  6311. 'count' => $count,
  6312. ];
  6313. return Result::success($result);
  6314. }
  6315. /*
  6316. * 获取企业会员-招聘信息列表
  6317. * */
  6318. public function getRecruitingInfo(array $data): array
  6319. {
  6320. $user = User::where('id', $data['user_id'])->first();
  6321. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6322. return Result::error("用户不存在", 0);
  6323. }
  6324. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6325. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6326. ->select(
  6327. 'job_recruiting.*',
  6328. 'job_company.business_name',
  6329. 'job_company.company_hy_id',
  6330. 'job_company.company_size',
  6331. 'job_company.company_nature',
  6332. 'job_company.introduction',
  6333. 'job_company.real_name',
  6334. 'job_company.mobile',
  6335. 'job_company.company_url',
  6336. 'job_company.address_arr_id',
  6337. 'job_company.address',
  6338. 'job_company.email'
  6339. )
  6340. ->get();
  6341. if (empty($recruiting)) {
  6342. return Result::error("暂无招聘信息", 0);
  6343. }
  6344. return Result::success($recruiting);
  6345. }
  6346. /*
  6347. * 获取企业会员-我的沟通
  6348. * */
  6349. public function getJobResumeList(array $data): array
  6350. {
  6351. $user = User::where('id', $data['user_id'])->first();
  6352. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6353. return Result::error("用户不存在", 0);
  6354. }
  6355. $where = [];
  6356. if (isset($data['salary']) && $data['salary'] != null) {
  6357. $where['job_hunting.salary'] = $data['salary'];
  6358. }
  6359. if (isset($data['user_name']) && $data['user_name'] != null) {
  6360. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6361. }
  6362. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6363. $query->where('job_resume.user_id', $user['id']);
  6364. })
  6365. ->when(!empty($where), function ($query) use ($where) {
  6366. $query->where($where);
  6367. })
  6368. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6369. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6370. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6371. ->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');
  6372. $count = $job->count();
  6373. if ($count == 0) {
  6374. return Result::error("暂无沟通记录", 0);
  6375. }
  6376. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6377. ->offset(($data['page'] - 1) * $data['pageSize'])
  6378. ->limit($data['pageSize'])
  6379. ->get();
  6380. if (empty($jobs)) {
  6381. return Result::error("暂无沟通记录", 0);
  6382. }
  6383. $result['row'] = $this->processJob($jobs, '');
  6384. $result['count'] = $count;
  6385. return Result::success($result);
  6386. }
  6387. public function readJobResume(array $data): array
  6388. {
  6389. $result = JobResume::where('id', $data['id'])->first();
  6390. if (empty($result)) {
  6391. return Result::error("查询失败", 0);
  6392. }
  6393. $result = JobResume::where('id', $data['id'])->update([
  6394. 'status' => 2,
  6395. ]);
  6396. return Result::success($result);
  6397. }
  6398. // 20250306 招聘
  6399. //20250422 书刊音像
  6400. public function addBook(array $data): array
  6401. {
  6402. $user_id = $data['user_id'] ?? 0;
  6403. $type_id = $data['type_id'] ?? 0;
  6404. // $website_id = $data['website_id'] ?? 0;
  6405. // unset($data['user_id']);
  6406. unset($data['type_id']);
  6407. // unset($data['website_id']);
  6408. //处理数组
  6409. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6410. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6411. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6412. if ($data['img_url'] == '') {
  6413. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6414. preg_match_all($reg, $data['detail'], $matches);
  6415. if (isset($matches[1][0])) {
  6416. //截取varchar240
  6417. $data['img_url'] = substr($matches[1][0], 0, 240);
  6418. }
  6419. }
  6420. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6421. //提取标题+内容中的关键词
  6422. $data['keyword'] = $data['title'];
  6423. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6424. Jieba::init(); // 初始化 jieba-php
  6425. Finalseg::init();
  6426. $segList = Jieba::cut($data['keyword']);
  6427. $segList1 = array_slice($segList, 0, 8);
  6428. $data['keyword'] = implode(',', $segList1);
  6429. }
  6430. if ($data['description'] == '') {
  6431. //提取内容中的描述
  6432. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6433. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6434. }
  6435. var_dump($data, '--');
  6436. if ($data['status'] == 1) {
  6437. $this->sendMessage([
  6438. 'talk_type' => 400,
  6439. 'title' => $data['title'],
  6440. 'content' => '提交了审核',
  6441. 'messageType' => 7,
  6442. ]);
  6443. }
  6444. $result = Book::insertGetId($data);
  6445. if (empty($result)) {
  6446. return Result::error("添加失败", 0);
  6447. }
  6448. return Result::success($result);
  6449. }
  6450. public function getBookList(array $data): array
  6451. {
  6452. $where = [];
  6453. if (!empty($data["title"])) {
  6454. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6455. }
  6456. if (!empty($data['website_name'])) {
  6457. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6458. }
  6459. if (!empty($data['status'])) {
  6460. $where[] = ['book.status', '=', $data['status']];
  6461. }
  6462. $user_id = $data['user_id'];
  6463. $type_id = $data['type_id'];
  6464. // $type_id = 4;
  6465. var_dump($type_id, '------1--------');
  6466. if ($type_id != 10000) {
  6467. $where[] = ['book.user_id', '=', $user_id];
  6468. }
  6469. var_dump(!empty($data['status1']), '=-===1');
  6470. $result = Book::where($where)
  6471. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6472. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6473. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6474. ->when(isset($data['status1']), function ($query) use ($data) {
  6475. $query->whereIn('book.status', [1, 3]);
  6476. })
  6477. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6478. ->orderBy("updated_at", "desc")
  6479. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6480. if (empty($result)) {
  6481. return Result::error("暂无数据", 0);
  6482. }
  6483. // 取出数据
  6484. $rows = $result->items();
  6485. $count = $result->total();
  6486. $responseData = [
  6487. 'rows' => $rows,
  6488. 'count' => $count,
  6489. ];
  6490. return Result::success($responseData);
  6491. }
  6492. public function deleteBook(array $data): array
  6493. {
  6494. $result = Book::where('id', $data['id'])->delete();
  6495. if (empty($result)) {
  6496. return Result::error("删除失败", 0);
  6497. }
  6498. return Result::success($result);
  6499. }
  6500. public function updateBook(array $data): array
  6501. {
  6502. // $user_id = $data['user_id'] ?? 0;
  6503. $type_id = $data['type_id'] ?? 0;
  6504. // $website_id = $data['website_id'] ?? 0;
  6505. unset($data['user_id']);
  6506. unset($data['type_id']);
  6507. // unset($data['website_id']);
  6508. //处理数组
  6509. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6510. if ($data['img_url'] == '') {
  6511. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6512. preg_match_all($reg, $data['detail'], $matches);
  6513. if (isset($matches[1][0])) {
  6514. //截取varchar240
  6515. $data['img_url'] = substr($matches[1][0], 0, 240);
  6516. }
  6517. }
  6518. if ($data['keyword'] == '') {
  6519. //提取标题+内容中的关键词
  6520. $data['keyword'] = $data['title'];
  6521. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6522. Jieba::init(); // 初始化 jieba-php
  6523. Finalseg::init();
  6524. $segList = Jieba::cut($data['keyword']);
  6525. $segList1 = array_slice($segList, 0, 8);
  6526. $data['keyword'] = implode(',', $segList1);
  6527. }
  6528. if ($data['description'] == '') {
  6529. //提取内容中的描述
  6530. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6531. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6532. }
  6533. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6534. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6535. if ($data['status'] == 1) {
  6536. $this->sendMessage([
  6537. 'talk_type' => 400,
  6538. 'title' => $data['title'],
  6539. 'content' => '提交了审核',
  6540. 'messageType' => 7,
  6541. ]);
  6542. }
  6543. $result = Book::where("id", $data["id"])->update($data);
  6544. if (empty($result)) {
  6545. return Result::error("更新失败", 0);
  6546. }
  6547. return Result::success($result);
  6548. }
  6549. public function getBookInfo(array $data): array
  6550. {
  6551. $result = Book::where("id", $data["id"])->first();
  6552. if (empty($result)) {
  6553. return Result::error("获取失败", 0);
  6554. }
  6555. return Result::success($result);
  6556. }
  6557. public function updateBookStatus(array $data): array
  6558. {
  6559. //审核
  6560. unset($data['user_id']);
  6561. $bookInfo = Book::where("id", $data["id"])->first();
  6562. var_dump($bookInfo, '----');
  6563. if ($data['status'] == 2) {
  6564. $this->sendMessage([
  6565. 'talk_type' => 401,
  6566. 'title' => $bookInfo['title'],
  6567. 'content' => '审核通过',
  6568. 'messageType' => 7,
  6569. 'user_id' => $bookInfo['user_id'],
  6570. ]);
  6571. }
  6572. if ($data['status'] == 3) {
  6573. $this->sendMessage([
  6574. 'talk_type' => 401,
  6575. 'title' => $bookInfo['title'],
  6576. 'content' => '审核拒绝',
  6577. 'messageType' => 7,
  6578. 'user_id' => $bookInfo['user_id'],
  6579. ]);
  6580. }
  6581. if ($data['status'] == 1) {
  6582. $this->sendMessage([
  6583. 'talk_type' => 400,
  6584. 'title' => $bookInfo['title'],
  6585. 'content' => '提交了审核',
  6586. 'messageType' => 7,
  6587. // 'user_id'=>$bookInfo['user_id'],
  6588. ]);
  6589. }
  6590. $result = Book::where("id", $data["id"])->update($data);
  6591. if (empty($result)) {
  6592. return Result::error("更新失败", 0);
  6593. }
  6594. return Result::success($result);
  6595. }
  6596. //20250422 书刊音像
  6597. /**
  6598. * 贴身宝贝
  6599. * @param array $data
  6600. * @return array
  6601. */
  6602. public function getWebsiteTsbb(array $data): array
  6603. {
  6604. $month = $data['month'] ?? date('m');
  6605. $day = $data['day'] ?? date('d');
  6606. // 使用缓存键
  6607. $cacheKey = "tsbb_data_{$month}_{$day}";
  6608. // 尝试从缓存获取数据
  6609. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6610. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6611. if ($cachedData = $cache->get($cacheKey)) {
  6612. return Result::success(unserialize($cachedData));
  6613. }
  6614. //查询老黄历
  6615. try {
  6616. $date = date('Y-m-d');
  6617. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6618. // 使用 curl 替代 file_get_contents
  6619. $ch = curl_init();
  6620. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6621. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6622. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6623. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6624. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6625. 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');
  6626. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6627. 'Accept: application/json',
  6628. 'Content-Type: application/json',
  6629. 'Referer: https://www.36jxs.com/'
  6630. ]);
  6631. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6632. curl_setopt($ch, CURLOPT_ENCODING, '');
  6633. $almanacResponse = curl_exec($ch);
  6634. var_dump("====:", $almanacResponse);
  6635. if (curl_errno($ch)) {
  6636. var_dump('Curl error:', curl_error($ch));
  6637. throw new \Exception('Curl error: ' . curl_error($ch));
  6638. }
  6639. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6640. curl_close($ch);
  6641. if ($almanacResponse === false) {
  6642. throw new \Exception('Failed to fetch almanac data');
  6643. }
  6644. $almanacData = json_decode($almanacResponse, true);
  6645. if (json_last_error() !== JSON_ERROR_NONE) {
  6646. throw new \Exception('Failed to parse almanac data');
  6647. }
  6648. $almanacInfo = $almanacData['data'] ?? [];
  6649. } catch (\Exception $e) {
  6650. var_dump('Exception:', $e->getMessage());
  6651. $almanacInfo = [];
  6652. }
  6653. // 获取历史上的今天数据
  6654. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6655. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6656. ->orderBy('year', 'asc')
  6657. ->select("title", "id", "year", DB::raw('1 as type'))
  6658. ->limit(16)
  6659. ->get();
  6660. // 获取节日数据 - 从今天开始获取未来4条
  6661. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6662. ->orderBy('showtime', 'asc')
  6663. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6664. ->limit(16)
  6665. ->get();
  6666. //说文解字
  6667. $chartacterList = Character::orderBy('updated_at', 'desc')
  6668. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6669. ->limit(6)
  6670. ->get();
  6671. //谜语沙龙
  6672. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6673. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6674. ->limit(4)
  6675. ->get();
  6676. //成语欣赏
  6677. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6678. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6679. ->limit(32)
  6680. ->get();
  6681. //名联赏析
  6682. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6683. ->select("id", "first", "second", DB::raw('6 as type'))
  6684. ->limit(6)
  6685. ->get();
  6686. // 获取分类文章数据
  6687. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6688. ->pluck('category_id')
  6689. ->toArray();
  6690. $articlesList = [];
  6691. foreach ($categoryIds as $catid) {
  6692. // 先查有图片的
  6693. $withImg = DB::table('article')
  6694. ->where('status', 1)
  6695. ->where('catid', $catid)
  6696. ->whereNotNull('imgurl')
  6697. ->where('imgurl', '!=', '')
  6698. ->orderBy('updated_at', 'desc')
  6699. ->limit(6)
  6700. ->get();
  6701. $count = $withImg->count();
  6702. if ($count < 6) {
  6703. // 不足6条再查无图片的补足
  6704. $withoutImg = DB::table('article')
  6705. ->where('status', 1)
  6706. ->where('catid', $catid)
  6707. ->where(function ($q) {
  6708. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6709. })
  6710. ->orderBy('updated_at', 'desc')
  6711. ->limit(6 - $count)
  6712. ->get();
  6713. $articles = $withImg->concat($withoutImg);
  6714. } else {
  6715. $articles = $withImg;
  6716. }
  6717. // 组装
  6718. $category = \App\Model\Category::find($catid);
  6719. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6720. $articlesList[] = [
  6721. 'category_name' => $category ? $category->name : '',
  6722. 'catid' => $catid,
  6723. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6724. 'type' => 100,
  6725. 'list' => $articles->map(function ($item) {
  6726. return [
  6727. 'id' => $item->id,
  6728. 'title' => $item->title,
  6729. 'imgurl' => $item->imgurl,
  6730. 'created_at' => $item->created_at
  6731. ];
  6732. })->values()
  6733. ];
  6734. }
  6735. $result = [
  6736. 'almanac' => $almanacInfo,
  6737. 'historyTodayList' => [
  6738. 'category_name' => '历史上的今天',
  6739. 'list' => $historyTodayList,
  6740. 'type' => 1
  6741. ],
  6742. 'festivalList' => [
  6743. 'category_name' => '节日预告',
  6744. 'list' => $festivalList,
  6745. 'type' => 2
  6746. ],
  6747. 'chartacterList' => [
  6748. 'category_name' => '说文解字',
  6749. 'list' => $chartacterList,
  6750. 'type' => 3
  6751. ],
  6752. 'coupletList' => [
  6753. 'category_name' => '名联赏析',
  6754. 'list' => $coupletList,
  6755. 'type' => 6
  6756. ],
  6757. 'riddletList' => [
  6758. 'category_name' => '谜语沙龙',
  6759. 'list' => $riddletList,
  6760. 'type' => 4
  6761. ],
  6762. 'idiomList' => [
  6763. 'category_name' => '成语欣赏',
  6764. 'list' => $idiomList,
  6765. 'type' => 5
  6766. ],
  6767. 'articlesList' => $articlesList
  6768. ];
  6769. // 缓存结果,设置1小时过期
  6770. $cache->set($cacheKey, serialize($result), 3600);
  6771. return Result::success($result);
  6772. }
  6773. /**
  6774. * 获取资讯列表
  6775. */
  6776. public function getWebsiteTsbbList(array $data): array
  6777. {
  6778. $page = $data['page'] ?? 1;
  6779. $pageSize = $data['pageSize'] ?? 10;
  6780. // 如果没有传入月份和日期,则使用今天的日期
  6781. $month = $data['month'] ?? date('m');
  6782. $day = $data['day'] ?? date('d');
  6783. $total = 0;
  6784. $result = [];
  6785. $data['type'] = intval($data['type']);
  6786. var_dump("接收参数:", $data);
  6787. switch ($data['type']) {
  6788. case 1:
  6789. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6790. // 当前月份之后的数据
  6791. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6792. // 或者当前月份且日期大于等于当前日期的数据
  6793. ->orWhere(function ($q) use ($month, $day) {
  6794. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6795. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6796. });
  6797. })
  6798. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6799. $total = $query->count();
  6800. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6801. ->offset(($page - 1) * $pageSize)
  6802. ->limit($pageSize)
  6803. ->get();
  6804. break;
  6805. case 2:
  6806. $query = Festival::where(function ($q) use ($month, $day) {
  6807. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6808. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6809. ->orWhere(function ($q) use ($month, $day) {
  6810. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6811. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6812. });
  6813. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6814. $total = $query->count();
  6815. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6816. ->offset(($page - 1) * $pageSize)
  6817. ->limit($pageSize)
  6818. ->get();
  6819. break;
  6820. case 3:
  6821. $query = Character::orderBy("updated_at", "desc");
  6822. $total = $query->count();
  6823. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6824. ->offset(($page - 1) * $pageSize)
  6825. ->limit($pageSize)
  6826. ->get();
  6827. break;
  6828. case 4:
  6829. $query = Riddle::orderBy("updated_at", "desc");
  6830. $total = $query->count();
  6831. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6832. ->offset(($page - 1) * $pageSize)
  6833. ->limit($pageSize)
  6834. ->get();
  6835. break;
  6836. case 5:
  6837. $query = Idiom::orderBy("updated_at", "desc");
  6838. $total = $query->count();
  6839. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6840. ->offset(($page - 1) * $pageSize)
  6841. ->limit($pageSize)
  6842. ->get();
  6843. break;
  6844. case 6:
  6845. $query = Couplet::orderBy("updated_at", "desc");
  6846. $total = $query->count();
  6847. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6848. ->offset(($page - 1) * $pageSize)
  6849. ->limit($pageSize)
  6850. ->get();
  6851. break;
  6852. default:
  6853. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6854. $total = $query->count();
  6855. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6856. ->offset(($page - 1) * $pageSize)
  6857. ->limit($pageSize)
  6858. ->get();
  6859. }
  6860. return Result::success([
  6861. 'list' => $result,
  6862. 'total' => $total,
  6863. 'page' => (int)$page,
  6864. 'pageSize' => (int)$pageSize,
  6865. 'month' => $month,
  6866. 'day' => $day
  6867. ]);
  6868. }
  6869. /**
  6870. * 1:历史上的今天
  6871. * 2:节日
  6872. * 3:文章
  6873. *
  6874. * 资讯详情信息
  6875. */
  6876. public function getWebsiteTsbbDetail(array $data): array
  6877. {
  6878. $data['type'] = intval($data['type']);
  6879. switch ($data['type']) {
  6880. case 1:
  6881. $result = HistoryToday::where("id", $data['id'])->first();
  6882. break;
  6883. case 2:
  6884. $result = Festival::where("id", $data['id'])->first();
  6885. break;
  6886. case 3:
  6887. $result = Character::where("id", $data['id'])->first();
  6888. break;
  6889. case 4:
  6890. $result = Riddle::where("id", $data['id'])->first();
  6891. break;
  6892. case 5:
  6893. $result = Idiom::where("id", $data['id'])->first();
  6894. break;
  6895. case 6:
  6896. $result = Couplet::where("id", $data['id'])->first();
  6897. break;
  6898. default:
  6899. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6900. break;
  6901. }
  6902. return Result::success($result);
  6903. }
  6904. /**
  6905. * 农网导航首页数据
  6906. */
  6907. public function getWebsiteNwHomeList(array $data): array
  6908. {
  6909. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6910. ->pluck('category_id')
  6911. ->toArray();
  6912. // 使用子查询优化
  6913. $articlesList = DB::table('article')
  6914. ->select([
  6915. 'article.id',
  6916. 'article.title',
  6917. 'article.imgurl',
  6918. 'article.created_at',
  6919. 'category.name as category_name',
  6920. 'category.id as category_id',
  6921. 'website_category.aLIas_pinyin as pinyin',
  6922. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6923. DB::raw('100 as type')
  6924. ])
  6925. ->join('category', 'article.catid', '=', 'category.id')
  6926. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6927. ->leftJoin('website_category as parent_wc', function ($join) {
  6928. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6929. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6930. })
  6931. ->where('website_category.website_id', $data['website_id'])
  6932. ->where('article.status', 1)
  6933. ->whereIn('category.id', $categoryIds)
  6934. ->orderBy('article.created_at', 'desc')
  6935. ->get()
  6936. ->groupBy('category_id')
  6937. ->map(function ($group) {
  6938. // 确保第一条数据有图片
  6939. $firstWithImage = $group->first(function ($item) {
  6940. return !empty($item->imgurl);
  6941. });
  6942. if ($firstWithImage) {
  6943. // 如果有带图片的文章,将其放在第一位
  6944. $group = $group->filter(function ($item) use ($firstWithImage) {
  6945. return $item->id !== $firstWithImage->id;
  6946. })->prepend($firstWithImage);
  6947. }
  6948. return [
  6949. 'category_name' => $group->first()->category_name,
  6950. 'catid' => $group->first()->category_id,
  6951. 'pinyin' => $group->first()->pinyin,
  6952. 'parent_pinyin' => $group->first()->parent_pinyin,
  6953. 'list' => $group->take(4)->map(function ($item) {
  6954. return [
  6955. 'id' => $item->id,
  6956. 'title' => $item->title,
  6957. ];
  6958. })->values()
  6959. ];
  6960. })
  6961. ->values()
  6962. ->toArray();
  6963. return Result::success($articlesList);
  6964. }
  6965. /**
  6966. * 企业管理
  6967. * @param array $data
  6968. * @return array
  6969. */
  6970. public function getCompanyList(array $data): array
  6971. {
  6972. // return Result::success($data);
  6973. $where = [];
  6974. $user = User::where('id', $data['user_id'])->first();
  6975. if (empty($user)) {
  6976. return Result::error('用户不存在!');
  6977. }
  6978. if ($user['type_id'] != 10000) {
  6979. $where['user_id'] = $data['user_id'];
  6980. }
  6981. if (isset($data['title']) && !empty($data['title'])) {
  6982. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6983. }
  6984. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6985. array_push($where, ['website.id', $data['website_id']]);
  6986. }
  6987. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6988. if ($data['ischeck'] == 1) {
  6989. if (isset($data['status']) && $data['status'] != '') {
  6990. array_push($where, ['company.status', $data['status']]);
  6991. $query = Company::where($where);
  6992. } else {
  6993. $query = Company::whereIn('company.status', [0, 2]);
  6994. }
  6995. } else {
  6996. $query = Company::where('company.status', 1);
  6997. }
  6998. }
  6999. $result = $query->where($where)
  7000. ->leftJoin('website_category', function ($query) {
  7001. $query->on('website_category.category_id', '=', 'company.category_id')
  7002. ->on('website_category.website_id', '=', 'company.website_id');
  7003. })
  7004. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7005. ->select(
  7006. 'company.id',
  7007. 'company.title',
  7008. 'company.website_id',
  7009. 'company.category_id',
  7010. 'website.website_name',
  7011. 'website_category.alias as category_name',
  7012. 'company.status',
  7013. 'company.updated_at',
  7014. 'company.user_id'
  7015. )
  7016. ->orderBy('company.updated_at', 'desc')
  7017. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7018. if ($result->isEmpty()) {
  7019. return Result::error("暂无企业", 0);
  7020. }
  7021. return Result::success($result);
  7022. }
  7023. /**
  7024. * 添加企业
  7025. * @param array $data
  7026. * @return array
  7027. */
  7028. public function addCompany(array $data): array
  7029. {
  7030. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7031. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7032. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7033. $data['cat_arr_id'] = json_encode($car_arr_id);
  7034. } else {
  7035. $data['cat_arr_id'] = '';
  7036. }
  7037. if ($data['imgurl'] == '') {
  7038. //content中提取图片第一个图,正则提取
  7039. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7040. preg_match_all($reg, $data['content'], $matches);
  7041. if (isset($matches[1][0])) {
  7042. //截取varchar240
  7043. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7044. }
  7045. }
  7046. if ($data['keyword'] == '') {
  7047. //提取标题+内容中的关键词
  7048. $data['keyword'] = $data['title'];
  7049. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7050. Jieba::init(); // 初始化 jieba-php
  7051. Finalseg::init();
  7052. $segList = Jieba::cut($data['keyword']);
  7053. $segList1 = array_slice($segList, 0, 8);
  7054. $data['keyword'] = implode(',', $segList1);
  7055. }
  7056. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7057. //提取内容中的描述
  7058. $content = $data['content'];
  7059. // 去除 <style> 和 <script> 标签及其内容
  7060. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7061. // 去除所有 HTML 标签
  7062. $content = strip_tags($content);
  7063. // 去除 HTML 实体
  7064. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7065. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7066. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7067. // 去除多余空白
  7068. $content = preg_replace('/\s+/u', '', $content);
  7069. // 截取 100 个字符
  7070. $data['introduce'] = mb_substr($content, 0, 100);
  7071. }
  7072. $user = User::where('id', $data['user_id'])->first();
  7073. if (empty($user)) {
  7074. return Result::error('用户不存在!');
  7075. }
  7076. if ($user['type_id'] == 10000) {
  7077. $data['status'] = 1;
  7078. }
  7079. if (isset($data['level']) && $data['level'] != null) {
  7080. $data['level'] = intval($data['level']);
  7081. } else {
  7082. $data['level'] = null;
  7083. }
  7084. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7085. $this->sendMessage([
  7086. 'talk_type' => 900,
  7087. 'title' => $data['title'],
  7088. 'content' => '提交了审核',
  7089. 'messageType' => 8,
  7090. ]);
  7091. }
  7092. $result = Company::insertGetId($data);
  7093. if ($result) {
  7094. return Result::success($result);
  7095. } else {
  7096. return Result::error('添加失败');
  7097. }
  7098. }
  7099. /**
  7100. * 更新企业
  7101. * @param array $data
  7102. * @return array
  7103. */
  7104. public function upCompany(array $data): array
  7105. {
  7106. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7107. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7108. $data['cat_arr_id'] = json_encode($car_arr_id);
  7109. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7110. } else {
  7111. $data['cat_arr_id'] = '';
  7112. }
  7113. if ($data['imgurl'] == '') {
  7114. //content中提取图片第一个图,正则提取
  7115. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7116. preg_match_all($reg, $data['content'], $matches);
  7117. if (isset($matches[1][0])) {
  7118. //截取varchar
  7119. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7120. }
  7121. }
  7122. if ($data['keyword'] == '') {
  7123. //提取标题+内容中的关键词
  7124. $data['keyword'] = $data['title'];
  7125. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7126. Jieba::init(); // 初始化 jieba-php
  7127. Finalseg::init();
  7128. $segList = Jieba::cut($data['keyword']);
  7129. $segList1 = array_slice($segList, 0, 8);
  7130. $data['keyword'] = implode(',', $segList1);
  7131. }
  7132. if ($data['introduce'] == '') {
  7133. //提取内容中的描述
  7134. $content = $data['content'];
  7135. // 去除 <style> 和 <script> 标签及其内容
  7136. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7137. // 去除所有 HTML 标签
  7138. $content = strip_tags($content);
  7139. // 去除 HTML 实体
  7140. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7141. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7142. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7143. // 去除多余空白
  7144. $content = preg_replace('/\s+/u', '', $content);
  7145. // 截取 100 个字符
  7146. $data['introduce'] = mb_substr($content, 0, 100);
  7147. }
  7148. if (isset($data['level']) && $data['level'] != null) {
  7149. $data['level'] = intval($data['level']);
  7150. } else {
  7151. $data['level'] = null;
  7152. }
  7153. $user = User::where('id', $data['user_id'])->first();
  7154. if (empty($user)) {
  7155. return Result::error('用户不存在!');
  7156. }
  7157. if ($user['type_id'] == 10000) {
  7158. $data['status'] = 1;
  7159. } else {
  7160. $data['status'] = 0;
  7161. }
  7162. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7163. $this->sendMessage([
  7164. 'talk_type' => 900,
  7165. 'title' => $data['title'],
  7166. 'content' => '提交了审核',
  7167. 'messageType' => 8,
  7168. ]);
  7169. }
  7170. $result = Company::where('id', $data['id'])->update($data);
  7171. if ($result) {
  7172. return Result::success($result);
  7173. } else {
  7174. return Result::error('修改失败');
  7175. }
  7176. }
  7177. /**
  7178. * 删除企业
  7179. * @param array $data
  7180. * @return array
  7181. */
  7182. public function delCompany(array $data): array
  7183. {
  7184. $result = Company::where('id', $data['id'])->delete();
  7185. if ($result) {
  7186. return Result::success($result);
  7187. } else {
  7188. return Result::error('删除失败');
  7189. }
  7190. }
  7191. /**
  7192. * 审核企业
  7193. * @param array $data
  7194. * @return array
  7195. */
  7196. public function checkCompany(array $data): array
  7197. {
  7198. $user = User::where('id', $data['user_id'])->first();
  7199. if (empty($user)) {
  7200. return Result::error('用户不存在!');
  7201. }
  7202. $company = Company::where('id', $data['id'])->first();
  7203. if (empty($company)) {
  7204. return Result::error('企业不存在!');
  7205. }
  7206. // 状态:0:未审核 1:已审核 2:已拒绝
  7207. if ($data['status'] == 2 || $data['status'] == '2') {
  7208. $this->sendMessage([
  7209. 'talk_type' => 901,
  7210. 'title' => $company['title'],
  7211. 'content' => '审核拒绝',
  7212. 'messageType' => 8,
  7213. 'user_id' => $company['user_id'],
  7214. ]);
  7215. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7216. } else {
  7217. if ($data['status'] == 1) {
  7218. $this->sendMessage([
  7219. 'talk_type' => 901,
  7220. 'title' => $company['title'],
  7221. 'content' => '审核通过',
  7222. 'messageType' => 8,
  7223. 'user_id' => $company['user_id'],
  7224. ]);
  7225. } else if ($data['status'] == 0) {
  7226. $this->sendMessage([
  7227. 'talk_type' => 900,
  7228. 'title' => $company['title'],
  7229. 'content' => '提交了审核',
  7230. 'messageType' => 8,
  7231. ]);
  7232. }
  7233. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7234. }
  7235. if (empty($result)) {
  7236. return Result::error('审核失败!');
  7237. } else {
  7238. return Result::success($result);
  7239. }
  7240. }
  7241. /**
  7242. * 获取企业信息
  7243. * @param array $data
  7244. * @return array
  7245. */
  7246. public function getCompanyInfo(array $data): array
  7247. {
  7248. $result = Company::where('id', $data['id'])->first();
  7249. $city_arr = json_decode($result['city_arr_id']);
  7250. $result['city_name'] = District::whereIn('id', $city_arr)
  7251. ->pluck('name')
  7252. ->implode('-');
  7253. if (empty($result)) {
  7254. return Result::error('企业不存在!');
  7255. } else {
  7256. return Result::success($result);
  7257. }
  7258. }
  7259. /**
  7260. * @param array $data
  7261. * @return array
  7262. */
  7263. public function getWebsiteCompany(array $data): array
  7264. {
  7265. $categorys = json_decode($data['id'], true);
  7266. $category_arr = $this->processArticlePro($data['website_id']);
  7267. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7268. $catiall = $category_arr['catiall'];
  7269. $categoryIds = $category_arr['categoryIds'];
  7270. // return Result::success($category_arr);
  7271. foreach ($categorys as $key => $value) {
  7272. if (array_key_exists('level', $value)) {
  7273. $parts = explode(',', $value['level']);
  7274. $level = $parts[0] ?? null;
  7275. $imgnum = $parts[1] ?? null;
  7276. $textnum = $parts[2] ?? null;
  7277. if (!empty($textnum) && $textnum > 0) {
  7278. $text_num = Company::where('level', $level)
  7279. ->whereIn('category_id', $categoryIds)
  7280. ->where('status', 1)
  7281. ->select(
  7282. 'company.id',
  7283. 'company.title',
  7284. 'company.description',
  7285. 'company.updated_at',
  7286. 'company.category_id',
  7287. 'company.cat_arr_id'
  7288. )
  7289. ->orderBy('updated_at', 'desc')
  7290. ->limit($textnum)
  7291. ->get()->all();
  7292. }
  7293. if (!empty($imgnum) && $imgnum > 0) {
  7294. $img_num = Company::where('level', $level)
  7295. ->whereIn('category_id', $categoryIds)
  7296. ->where('status', 1)
  7297. ->where('imgurl', '!=', '')
  7298. ->whereNotNull('imgurl')
  7299. ->select(
  7300. 'company.id',
  7301. 'company.title',
  7302. 'company.description',
  7303. 'company.updated_at',
  7304. 'company.imgurl as imgs',
  7305. 'company.category_id',
  7306. 'company.cat_arr_id'
  7307. )
  7308. ->orderBy('updated_at', 'desc')
  7309. ->limit($imgnum)
  7310. ->get()->all();
  7311. }
  7312. }
  7313. if (array_key_exists('id', $value)) {
  7314. $parts = explode(',', $value['id']);
  7315. $category_id = $parts[0] ?? null;
  7316. $imgnum = $parts[1] ?? null;
  7317. $textnum = $parts[2] ?? null;
  7318. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7319. if (!empty($textnum) && $textnum > 0) {
  7320. $text_num = Company::whereIn('category_id', $category_arr)
  7321. // ->where('website_id', $data['website_id'])
  7322. ->where('status', 1)
  7323. ->select(
  7324. 'company.id',
  7325. 'company.title',
  7326. 'company.description',
  7327. 'company.updated_at',
  7328. 'company.category_id',
  7329. 'company.cat_arr_id'
  7330. )
  7331. ->orderBy('updated_at', 'desc')
  7332. ->limit($textnum)
  7333. ->get()->all();
  7334. }
  7335. if (!empty($imgnum) && $imgnum > 0) {
  7336. $img_num = Company::whereIn('category_id', $category_arr)
  7337. // ->where('website_id', $data['website_id'])
  7338. ->where('status', 1)
  7339. ->where('imgurl', '!=', '')
  7340. ->whereNotNull('imgurl')
  7341. ->select(
  7342. 'company.id',
  7343. 'company.title',
  7344. 'company.description',
  7345. 'company.updated_at',
  7346. 'company.imgurl as imgs',
  7347. 'company.category_id',
  7348. 'company.cat_arr_id'
  7349. )
  7350. ->orderBy('updated_at', 'desc')
  7351. ->limit($imgnum)
  7352. ->get()->all();
  7353. }
  7354. }
  7355. if (!empty($text_num)) {
  7356. foreach ($text_num as $k => $v) {
  7357. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7358. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7359. }
  7360. }
  7361. if (!empty($img_num)) {
  7362. foreach ($img_num as $k => $v) {
  7363. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7364. $imgurl = json_decode($v['imgs'], true);
  7365. if (!empty($imgurl)) {
  7366. $img_num[$k]->imgurl = $imgurl[0];
  7367. }
  7368. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7369. }
  7370. }
  7371. $company[$key]['img_num'] = $img_num ?? [];
  7372. $company[$key]['text_num'] = $text_num ?? [];
  7373. }
  7374. if (empty($company)) {
  7375. return Result::error("暂无相关企业信息", 0);
  7376. }
  7377. return Result::success($company);
  7378. }
  7379. /**
  7380. * @param array $data
  7381. * @return array
  7382. */
  7383. public function getWebsiteCompanyList(array $data): array
  7384. {
  7385. $where['website_id'] = $data['website_id'];
  7386. $where['status'] = 1;
  7387. $categoryIds = [];
  7388. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7389. $category_id = $data['category_id'];
  7390. }
  7391. $category_arr = $this->processArticlePro($data['website_id']);
  7392. $categoryIds = $category_arr['categoryIds'];
  7393. // return Result::success($cat_1st_arr);
  7394. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7395. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7396. })
  7397. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7398. $query->whereIn('category_id', $categoryIds);
  7399. })
  7400. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7401. $query->where('category_id', $category_id);
  7402. })
  7403. ->where('status',1)
  7404. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7405. ->orderBy('updated_at', 'desc')
  7406. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7407. if (empty($company)) {
  7408. return Result::error("暂无相关公司信息", 0);
  7409. }
  7410. $result = [
  7411. 'count' => $company->total(),
  7412. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7413. ];
  7414. return Result::success($result);
  7415. }
  7416. /**
  7417. * 获取项目列表
  7418. * @param array $data
  7419. * @return array
  7420. */
  7421. public function getProjectList(array $data): array
  7422. {
  7423. $where = [];
  7424. $user = User::where('id', $data['user_id'])->first();
  7425. if (empty($user)) {
  7426. return Result::error('用户不存在!');
  7427. }
  7428. if ($user->type_id != 10000) {
  7429. array_push($where, ['project.user_id', $data['user_id']]);
  7430. }
  7431. $query = Project::query();
  7432. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7433. array_push($where, ['project.website_id', $data['website_id']]);
  7434. }
  7435. if (isset($data['title']) && !empty($data['title'])) {
  7436. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7437. }
  7438. if ($data['status'] != 3) {
  7439. array_push($where, ['project.status', $data['status']]);
  7440. }
  7441. $query = Project::where($where)
  7442. ->when($data['status'] == 3, function ($query) {
  7443. $query->whereIn('project.status', [0, 2]);
  7444. });
  7445. $count = $query->clone()
  7446. ->count();
  7447. $rows = $query->clone()
  7448. ->leftJoin('website', 'project.website_id', 'website.id')
  7449. ->leftJoin('website_category', function ($join) {
  7450. $join->on('project.website_id', '=', 'website_category.website_id')
  7451. ->on('project.category_id', '=', 'website_category.category_id');
  7452. })
  7453. ->select(
  7454. 'project.id',
  7455. 'project.title',
  7456. 'project.updated_at',
  7457. 'project.status',
  7458. 'website.website_name',
  7459. 'website_category.alias as category_name',
  7460. 'project.website_id',
  7461. 'project.user_id'
  7462. )
  7463. ->orderBy('project.updated_at', 'desc')
  7464. ->offset(($data['page'] - 1) * $data['pageSize'])
  7465. ->limit($data['pageSize'])
  7466. ->get();
  7467. if ($rows->isEmpty()) {
  7468. return Result::error("暂无相关项目信息", 0);
  7469. }
  7470. $result = [
  7471. 'count' => $count,
  7472. 'rows' => $rows,
  7473. ];
  7474. return Result::success($result);
  7475. }
  7476. /**
  7477. * 添加项目
  7478. * @param array $data
  7479. * @return array
  7480. */
  7481. public function addProject(array $data): array
  7482. {
  7483. $user = User::where('id', $data['user_id'])->first();
  7484. if (empty($user)) {
  7485. return Result::error("暂无相关用户信息", 0);
  7486. }
  7487. if ($user->type_id == 10000) {
  7488. $data['status'] = 1;
  7489. } else {
  7490. $data['status'] = 0;
  7491. }
  7492. if ($data['keyword'] == '') {
  7493. //提取标题+内容中的关键词
  7494. $data['keyword'] = $data['title'];
  7495. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7496. Jieba::init(); // 初始化 jieba-php
  7497. Finalseg::init();
  7498. $segList = Jieba::cut($data['keyword']);
  7499. $segList1 = array_slice($segList, 0, 8);
  7500. $data['keyword'] = implode(',', $segList1);
  7501. }
  7502. if ($data['description'] == '') {
  7503. //提取内容中的描述
  7504. // var_dump(11111);
  7505. //提取内容中的描述
  7506. $content = $data['introduce'];
  7507. // 去除 <style> 和 <script> 标签及其内容
  7508. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7509. // 去除所有 HTML 标签
  7510. $content = strip_tags($content);
  7511. // 去除 HTML 实体
  7512. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7513. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7514. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7515. // 去除多余空白
  7516. $content = preg_replace('/\s+/u', '', $content);
  7517. // 截取 100 个字符
  7518. $data['description'] = mb_substr($content, 0, 100);
  7519. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7520. }
  7521. if ($data['status'] == 0) {
  7522. $this->sendMessage([
  7523. 'talk_type' => 1000,
  7524. 'title' => $data['title'],
  7525. 'content' => '提交了审核',
  7526. 'messageType' => 9,
  7527. ]);
  7528. }
  7529. $project = Project::insertGetId($data);
  7530. if (empty($project)) {
  7531. return Result::error("暂无相关项目信息", 0);
  7532. }
  7533. return Result::success($project);
  7534. }
  7535. /**
  7536. * 更新项目
  7537. * @param array $data
  7538. * @return array
  7539. */
  7540. public function upProject(array $data): array
  7541. {
  7542. $project = Project::where('id', $data['id'])->first();
  7543. if (empty($project)) {
  7544. return Result::error("暂无相关项目信息", 0);
  7545. }
  7546. $id = $data['id'];
  7547. unset($data['id']);
  7548. $user = User::where('id', $data['user_id'])->first();
  7549. if (empty($user)) {
  7550. return Result::error("暂无相关用户信息", 0);
  7551. }
  7552. if ($user->type_id == 10000) {
  7553. $data['status'] = 1;
  7554. } else {
  7555. $data['status'] = 0;
  7556. }
  7557. unset($data['user_id']);
  7558. if ($data['keyword'] == '') {
  7559. //提取标题+内容中的关键词
  7560. $data['keyword'] = $data['title'];
  7561. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7562. Jieba::init(); // 初始化 jieba-php
  7563. Finalseg::init();
  7564. $segList = Jieba::cut($data['keyword']);
  7565. $segList1 = array_slice($segList, 0, 8);
  7566. $data['keyword'] = implode(',', $segList1);
  7567. }
  7568. if ($data['description'] == '') {
  7569. //提取内容中的描述
  7570. // var_dump(11111);
  7571. //提取内容中的描述
  7572. $content = $data['introduce'];
  7573. // 去除 <style> 和 <script> 标签及其内容
  7574. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7575. // 去除所有 HTML 标签
  7576. $content = strip_tags($content);
  7577. // 去除 HTML 实体
  7578. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7579. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7580. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7581. // 去除多余空白
  7582. $content = preg_replace('/\s+/u', '', $content);
  7583. // 截取 100 个字符
  7584. $data['description'] = mb_substr($content, 0, 100);
  7585. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7586. }
  7587. if ($data['status'] == 0) {
  7588. $this->sendMessage([
  7589. 'talk_type' => 1000,
  7590. 'title' => $data['title'],
  7591. 'content' => '提交了审核',
  7592. 'messageType' => 9,
  7593. ]);
  7594. }
  7595. $result = Project::where('id', $id)->update($data);
  7596. if (empty($result)) {
  7597. return Result::error("更新失败", 0);
  7598. }
  7599. return Result::success($result);
  7600. }
  7601. /**
  7602. * 删除项目
  7603. * @param array $data
  7604. * @return array
  7605. */
  7606. public function delProject(array $data): array
  7607. {
  7608. $user = User::where('id', $data['user_id'])->first();
  7609. if (empty($user)) {
  7610. return Result::error("暂无相关用户信息", 0);
  7611. }
  7612. $project = Project::where('id', $data['id'])->first();
  7613. if (empty($project)) {
  7614. return Result::error("暂无相关项目信息", 0);
  7615. }
  7616. $result = Project::where('id', $data['id'])->delete();
  7617. if (empty($result)) {
  7618. return Result::error("删除失败", 0);
  7619. }
  7620. return Result::success($result);
  7621. }
  7622. /**
  7623. * 审核项目
  7624. * @param array $data
  7625. * @return array
  7626. */
  7627. public function checkProject(array $data): array
  7628. {
  7629. $user = User::where('id', $data['user_id'])->first();
  7630. if (empty($user)) {
  7631. return Result::error("暂无相关用户信息", 0);
  7632. }
  7633. // 0:未审核; 1:已审核; 2:已拒绝;
  7634. if ($user->type_id != 10000) {
  7635. if ($data['status'] == 1 || $data['status'] == 2) {
  7636. return Result::error("此用户权限不足", 0);
  7637. }
  7638. }
  7639. $project = Project::where('id', $data['id'])->first();
  7640. if (empty($project)) {
  7641. return Result::error("暂无相关项目信息", 0);
  7642. }
  7643. if ($data['status'] == 2) {
  7644. $this->sendMessage([
  7645. 'talk_type' => 1001,
  7646. 'title' => $project['title'],
  7647. 'content' => '审核拒绝',
  7648. 'messageType' => 9,
  7649. 'user_id' => $project['user_id'],
  7650. ]);
  7651. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7652. } else {
  7653. if ($data['status'] == 1) {
  7654. $this->sendMessage([
  7655. 'talk_type' => 1001,
  7656. 'title' => $project['title'],
  7657. 'content' => '审核通过',
  7658. 'messageType' => 9,
  7659. 'user_id' => $project['user_id'],
  7660. ]);
  7661. } else if ($data['status'] == 0) {
  7662. $this->sendMessage([
  7663. 'talk_type' => 1000,
  7664. 'title' => $project['title'],
  7665. 'content' => '提交了审核',
  7666. 'messageType' => 9,
  7667. ]);
  7668. }
  7669. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7670. }
  7671. if (empty($result)) {
  7672. return Result::error("审核失败", 0);
  7673. }
  7674. return Result::success($result);
  7675. }
  7676. /**
  7677. * 获取项目详情
  7678. * @param array $data
  7679. * @return array
  7680. */
  7681. public function getProjectInfo(array $data): array
  7682. {
  7683. $project = Project::where('id', $data['id'])->first();
  7684. if (empty($project)) {
  7685. return Result::error("暂无相关项目信息", 0);
  7686. }
  7687. return Result::success($project);
  7688. }
  7689. public function getWebsiteCompanyInfo(array $data): array
  7690. {
  7691. $company = Company::where('id', $data['id'])
  7692. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7693. ->where('status', 1)
  7694. // ->where('website_id', $data['website_id'])
  7695. ->select('company.*', 'job_industry.hyname as hy_name')
  7696. ->first();
  7697. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7698. $jobnature_id = $company['jobnature_id'] ?? null;
  7699. if ($jobnature_id !== null) {
  7700. switch ($jobnature_id) {
  7701. case 0:
  7702. $company->jobnature_name = '市场监督';
  7703. break;
  7704. case 1:
  7705. $company->jobnature_name = '信访纪检';
  7706. break;
  7707. case 2:
  7708. $company->jobnature_name = '公检法司';
  7709. break;
  7710. case 3:
  7711. $company->jobnature_name = '高关注机构';
  7712. break;
  7713. default:
  7714. $company->jobnature_name = '';
  7715. break;
  7716. }
  7717. } else {
  7718. $company->jobnature_name = '';
  7719. }
  7720. $city_arr = $company->city_arr_id;
  7721. if (!empty($city_arr)) {
  7722. $city_arr = json_decode($city_arr, true);
  7723. $cityNames = District::whereIn('id', $city_arr)
  7724. ->pluck('name')
  7725. ->implode('-');
  7726. $company->city_name = $cityNames;
  7727. } else {
  7728. $company->city_name = '';
  7729. }
  7730. if (empty($company)) {
  7731. return Result::error("暂无相关公司信息", 0);
  7732. }
  7733. return Result::success($company);
  7734. }
  7735. public function getMSG(array $data): array
  7736. {
  7737. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7738. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7739. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7740. $result = [];
  7741. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7742. //最近的5篇已审的文章
  7743. $apply_articale = Article::where('status', 1)
  7744. ->where('admin_user_id', $user_id)
  7745. ->orderBy('updated_at', 'desc')
  7746. // ->limit(5)
  7747. ->get();
  7748. //获取5条用户的已审核商品
  7749. $good = Good::where('status', 2)
  7750. ->where('user_id', $user_id)
  7751. ->orderBy('updated_at', 'desc')
  7752. // ->limit(5)
  7753. ->get();
  7754. //获取5条用户待审核的公告
  7755. $notice = Notice::where('status', 2)
  7756. ->where('user_id', $user_id)
  7757. ->orderBy('updated_at', 'desc')
  7758. ->limit(5)->get();
  7759. //获取5条用户的待审核投诉
  7760. $complaint = Complaint::where('status', 2)
  7761. ->where('user_id', $user_id)
  7762. ->orderBy('updated_at', 'desc')
  7763. // ->limit(5)
  7764. ->get();
  7765. //获取5条用户的book
  7766. $book = Book::where('status', 2)
  7767. ->where('user_id', $user_id)
  7768. ->orderBy('updated_at', 'desc')
  7769. // ->limit(5)
  7770. ->get();
  7771. //获取5条用户的求职
  7772. //获取5条用户的求职 1
  7773. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7774. ->where('job_hunting.user_id', $user_id)
  7775. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7776. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7777. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7778. ->orderBy('updated_at', 'desc')
  7779. // ->limit(5)
  7780. ->get();
  7781. //获取5条用户的求职 2
  7782. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7783. ->where('job_recruiting.user_id', $user_id)
  7784. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7785. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7786. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7787. ->orderBy('updated_at', 'desc')
  7788. // ->limit(5)
  7789. ->get();
  7790. //人才库 1
  7791. $job_apply = JobApply::where('job_apply.status', 1)
  7792. ->where('job_apply.receiver_id', $user_id)
  7793. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7794. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7795. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7796. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7797. ->select('job_recruiting', 'job_recruiting.', '', '')
  7798. ->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')
  7799. ->orderBy('updated_at', 'desc')
  7800. // ->limit(5)
  7801. ->get();
  7802. // 职场机会 2
  7803. $job_resume = JobResume::where('job_resume.status', 1)
  7804. ->where('job_resume.receiver_id', $user_id)
  7805. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7806. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7807. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7808. ->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')
  7809. ->orderBy('updated_at', 'desc')
  7810. // ->limit(5)
  7811. ->get();
  7812. //获取5条用户待处理的投诉
  7813. $complaint_deal = Complaint::where('status', 2)
  7814. ->where('deal', 1)
  7815. ->whereJsonContains('re_user_ids', $user_id)
  7816. ->orderBy('updated_at', 'desc')
  7817. // ->limit(5)
  7818. ->get();
  7819. //获取 被通知者未读信息
  7820. $notice_unread = Notice::where('status', 2)
  7821. ->whereJsonContains('re_user_ids', $user_id)
  7822. //未读消息
  7823. ->where(function ($query) use ($user_id) {
  7824. $query->whereJsonDoesntContain('read_id', $user_id)
  7825. ->orWhereNull('read_id');
  7826. })
  7827. ->orderBy('updated_at', 'desc')
  7828. ->get();
  7829. $complaint_unread = Complaint::where('status', 2)
  7830. ->whereJsonContains('re_user_ids', $user_id)
  7831. //未读消息
  7832. ->where(function ($query) use ($user_id) {
  7833. $query->whereJsonDoesntContain('read_id', $user_id)
  7834. ->orWhereNull('read_id');
  7835. })
  7836. ->orderBy('updated_at', 'desc')
  7837. ->get();
  7838. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7839. $complany = Company::where('status', 1)
  7840. ->where('user_id', $user_id)
  7841. ->orderBy('updated_at', 'desc')
  7842. // ->limit(5)
  7843. ->get();
  7844. //获取5条单聊未读聊天消息
  7845. // $chat = ChatRecords::where('is_read', 0)
  7846. // ->where('user_id', $user_id)
  7847. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7848. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7849. // ->where('action', 'recieved')
  7850. // ->where('talk_type', 1)
  7851. // ->orderBy('created_at', 'desc')
  7852. // // ->limit(5)
  7853. // ->get();
  7854. //获取5条未读群聊信息
  7855. // $chat_group = ChatRecords::where('is_read', 0)
  7856. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7857. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7858. // ->where('user_id', $user_id)
  7859. // ->where('talk_type', 2)
  7860. // ->orderBy('created_at', 'desc')
  7861. // // ->limit(5)
  7862. // ->get();
  7863. //获取5条用户的待审核项目
  7864. $project = Project::where('status', 1)
  7865. ->where('user_id', $user_id)
  7866. ->orderBy('updated_at', 'desc')
  7867. // ->limit(5)
  7868. ->get();
  7869. // count($chat) + count($chat_group) +
  7870. $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)
  7871. + count($complany)
  7872. + count($project)
  7873. + count($notice_unread)
  7874. + count($complaint_unread)
  7875. // + count($chat) + count($chat_group)
  7876. ;
  7877. $result = [
  7878. 'apply_articale' => $apply_articale,
  7879. // 'chat' => $chat,
  7880. // 'chat_group' => $chat_group,
  7881. 'good' => $good,
  7882. 'notice' => $notice,
  7883. 'complaint' => $complaint,
  7884. 'book' => $book,
  7885. 'job_hunting' => $job_hunting,
  7886. 'job_recruiting' => $job_recruiting,
  7887. 'job_apply' => $job_apply,
  7888. 'job_resume' => $job_resume,
  7889. 'complaint_deal' => $complaint_deal,
  7890. 'complany' => $complany,
  7891. 'project' => $project,
  7892. 'notice_unread' => $notice_unread,
  7893. 'complaint_unread' => $complaint_unread,
  7894. 'count' => $count,
  7895. ];
  7896. } elseif ($type_id == 12) {
  7897. //最近的5篇已审的文章
  7898. $apply_articale = Article::where('status', 1)
  7899. ->where('admin_user_id', $user_id)
  7900. ->limit(5)->get();
  7901. //获取5条单聊未读聊天消息
  7902. $chat = ChatRecords::where('is_read', 0)
  7903. ->where('user_id', $user_id)
  7904. ->where('talk_type', 1)
  7905. ->orderBy('created_at', 'desc')
  7906. ->limit(5)->get();
  7907. //获取5条未读群聊信息
  7908. $chat_group = ChatRecords::where('is_read', 0)
  7909. ->where('user_id', $user_id)
  7910. ->where('talk_type', 2)
  7911. ->orderBy('created_at', 'desc')
  7912. ->limit(5)->get();
  7913. //获取5条用户的已审核商品
  7914. $good = Good::where('status', 2)
  7915. ->where('user_id', $user_id)
  7916. ->orderBy('updated_at', 'desc')
  7917. ->limit(5)->get();
  7918. //获取5条用户的book
  7919. $book = Book::where('status', 2)
  7920. ->where('user_id', $user_id)
  7921. ->orderBy('updated_at', 'desc')
  7922. ->limit(5)->get();
  7923. //获取5条用户的求职
  7924. //获取5条用户的求职 1
  7925. //count($chat) + count($chat_group)
  7926. $count = count($apply_articale) + count($good);
  7927. $result = [
  7928. 'apply_articale' => $apply_articale,
  7929. 'chat' => $chat,
  7930. 'chat_group' => $chat_group,
  7931. 'good' => $good,
  7932. 'book' => $book,
  7933. 'count' => $count,
  7934. ];
  7935. } elseif ($type_id == 13) {
  7936. //最近的5篇已审的文章
  7937. $apply_articale = Article::where('status', 1)
  7938. ->where('admin_user_id', $user_id)
  7939. ->limit(5)->get();
  7940. //获取5条单聊未读聊天消息
  7941. $chat = ChatRecords::where('is_read', 0)
  7942. ->where('user_id', $user_id)
  7943. ->where('talk_type', 1)
  7944. ->orderBy('created_at', 'desc')
  7945. ->limit(5)->get();
  7946. //获取5条未读群聊信息
  7947. $chat_group = ChatRecords::where('is_read', 0)
  7948. ->where('user_id', $user_id)
  7949. ->where('talk_type', 2)
  7950. ->orderBy('created_at', 'desc')
  7951. ->limit(5)->get();
  7952. //获取5条用户的已审核商品
  7953. $good = Good::where('status', 2)
  7954. ->where('user_id', $user_id)
  7955. ->orderBy('updated_at', 'desc')
  7956. ->limit(5)->get();
  7957. //count($chat) + count($chat_group) +
  7958. $count = count($apply_articale) + count($good);
  7959. $result = [
  7960. 'apply_articale' => $apply_articale,
  7961. 'chat' => $chat,
  7962. 'chat_group' => $chat_group,
  7963. 'good' => $good,
  7964. 'count' => $count,
  7965. ];
  7966. } elseif ($type_id == 14) {
  7967. //最近的5篇已审的文章
  7968. $apply_articale = Article::where('status', 1)
  7969. ->where('admin_user_id', $user_id)
  7970. // ->limit(5)
  7971. ->get();
  7972. //获取5条用户的已审核商品
  7973. $good = Good::where('status', 2)
  7974. ->where('user_id', $user_id)
  7975. ->orderBy('updated_at', 'desc')
  7976. // ->limit(5)
  7977. ->get();
  7978. $count = count($apply_articale) + count($good);
  7979. $result = [
  7980. 'apply_articale' => $apply_articale,
  7981. 'chat' => '',
  7982. 'chat_group' => '',
  7983. 'good' => $good,
  7984. 'count' => $count,
  7985. ];
  7986. } elseif ($type_id == 10000) {
  7987. //获取未审核的5篇文章
  7988. $apply_articale = Article::where('status', 0)
  7989. ->orderBy('updated_at', 'desc')
  7990. // ->limit(5)
  7991. ->get();
  7992. //获取5条单聊未读聊天消息
  7993. //获取5条单聊未读聊天消息
  7994. // $chat = ChatRecords::where('is_read', 0)
  7995. // ->where('user_id', $user_id)
  7996. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7997. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7998. // ->where('action', 'recieved')
  7999. // ->where('talk_type', 1)
  8000. // ->orderBy('created_at', 'desc')
  8001. // // ->limit(5)
  8002. // ->get();
  8003. // //获取5条未读群聊信息
  8004. // $chat_group = ChatRecords::where('is_read', 0)
  8005. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8006. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8007. // ->where('user_id', $user_id)
  8008. // ->where('talk_type', 2)
  8009. // ->orderBy('created_at', 'desc')
  8010. // // ->limit(5)
  8011. // ->get();
  8012. //获取5条用户的已审核商品
  8013. $good = Good::where('status', 1)
  8014. // ->where('user_id', $user_id)
  8015. ->orderBy('updated_at', 'desc')
  8016. // ->limit(5)
  8017. ->get();
  8018. //获取5条用户待审核的公告
  8019. $notice = Notice::where('status', 1)
  8020. ->orderBy('updated_at', 'desc')
  8021. // ->limit(5)
  8022. ->get();
  8023. //获取5条用户的待审核投诉
  8024. $complaint = Complaint::where('status', 1)
  8025. ->orderBy('updated_at', 'desc')
  8026. // ->limit(5)
  8027. ->get();
  8028. //获取5条用户的book
  8029. $book = Book::where('status', 1)
  8030. ->orderBy('updated_at', 'desc')
  8031. // ->limit(5)
  8032. ->get();
  8033. //获取5条用户的求职 1
  8034. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8035. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8036. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8037. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8038. ->orderBy('updated_at', 'desc')
  8039. // ->limit(5)
  8040. ->get();
  8041. //获取5条用户的求职 2
  8042. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8043. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8044. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8045. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8046. ->orderBy('updated_at', 'desc')
  8047. // ->limit(5)
  8048. ->get();
  8049. //人才库 1
  8050. $job_apply = JobApply::where('job_apply.status', 1)
  8051. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8052. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8053. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8054. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8055. ->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')
  8056. ->orderBy('updated_at', 'desc')
  8057. // ->limit(5)
  8058. ->get();
  8059. // 职场机会 2
  8060. $job_resume = JobResume::where('job_resume.status', 1)
  8061. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8062. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8063. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8064. ->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')
  8065. ->orderBy('updated_at', 'desc')
  8066. // ->limit(5)
  8067. ->get();
  8068. //待审核数据com pro
  8069. $complany = Company::where('status', 0)
  8070. ->orderBy('updated_at', 'desc')
  8071. // ->limit(5)
  8072. ->get();
  8073. $project = Project::where('status', 0)
  8074. ->orderBy('updated_at', 'desc')
  8075. // ->limit(5)
  8076. ->get();
  8077. $count =
  8078. // count($chat) +
  8079. // count($chat_group) +
  8080. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8081. // + count($job_apply)
  8082. // + count($job_resume)
  8083. + count($complany)
  8084. + count($project);
  8085. $result = [
  8086. 'apply_articale' => $apply_articale,
  8087. // 'chat' => $chat,
  8088. // 'chat_group' => $chat_group,
  8089. 'good' => $good,
  8090. 'notice' => $notice,
  8091. 'complaint' => $complaint,
  8092. 'book' => $book,
  8093. 'job_hunting' => $job_hunting,
  8094. 'job_recruiting' => $job_recruiting,
  8095. // 'job_apply' => $job_apply,
  8096. // 'job_resume' => $job_resume,
  8097. 'complany' => $complany,
  8098. 'project' => $project,
  8099. 'count' => $count,
  8100. ];
  8101. } elseif ($type_id == 20000) {
  8102. }
  8103. var_dump($type_id, '-----------------test---------');
  8104. return Result::success($result);
  8105. }
  8106. /**
  8107. * @param array $data
  8108. * @return array
  8109. */
  8110. public function getWebsiteProject(array $data): array
  8111. {
  8112. $categorys = json_decode($data['id'], true);
  8113. if (!empty($categorys)) {
  8114. $category_arr = $this->processArticlePro($data['website_id']);
  8115. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8116. $catiall = $category_arr['catiall'];
  8117. // return Result::success($catiall);
  8118. foreach ($categorys as $key => $val) {
  8119. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8120. $level = explode(',', $val['level'])[0];
  8121. $imgnum = explode(',', $val['level'])[1] ?? null;
  8122. $textnum = explode(',', $val['level'])[2] ?? null;
  8123. if ($level == 1) {
  8124. if (!empty($textnum) && $textnum > 0) {
  8125. $text_num = Project::where('level', $level)
  8126. ->where('website_id', $data['website_id'])
  8127. ->where('status', 1)
  8128. ->select(
  8129. 'project.id',
  8130. 'project.title',
  8131. 'project.description',
  8132. 'project.updated_at',
  8133. 'project.category_id',
  8134. 'project.cat_arr_id'
  8135. )
  8136. ->orderBy('updated_at', 'desc')
  8137. ->limit($textnum)
  8138. ->get()->all();
  8139. }
  8140. if (!empty($imgnum) && $imgnum > 0) {
  8141. $img_num = Project::where('level', $level)
  8142. ->where('website_id', $data['website_id'])
  8143. ->where('status', 1)
  8144. ->where('imgurl', '!=', '')
  8145. ->whereNotNull('imgurl')
  8146. ->select(
  8147. 'project.id',
  8148. 'project.title',
  8149. 'project.description',
  8150. 'project.updated_at',
  8151. 'project.imgurl as imgs',
  8152. 'project.category_id',
  8153. 'project.cat_arr_id'
  8154. )
  8155. ->orderBy('updated_at', 'desc')
  8156. ->limit($imgnum)
  8157. ->get()->all();
  8158. }
  8159. } else {
  8160. if (!empty($textnum) && $textnum > 0) {
  8161. $text_num = Project::where('website_id', $data['website_id'])
  8162. ->where('status', 1)
  8163. ->select(
  8164. 'project.id',
  8165. 'project.title',
  8166. 'project.description',
  8167. 'project.updated_at',
  8168. 'project.category_id',
  8169. 'project.cat_arr_id',
  8170. 'project.website_id',
  8171. 'project.updated_at',
  8172. 'project.created_at'
  8173. )
  8174. ->orderBy('updated_at', 'desc')
  8175. ->limit($textnum)
  8176. ->get()->all();
  8177. }
  8178. if (!empty($imgnum) && $imgnum > 0) {
  8179. $img_num = Project::where('website_id', $data['website_id'])
  8180. ->where('status', 1)
  8181. ->where('imgurl', '!=', '')
  8182. ->whereNotNull('imgurl')
  8183. ->select(
  8184. 'project.id',
  8185. 'project.title',
  8186. 'project.description',
  8187. 'project.updated_at',
  8188. 'project.imgurl as imgs',
  8189. 'project.category_id',
  8190. 'project.cat_arr_id'
  8191. )
  8192. ->orderBy('updated_at', 'desc')
  8193. ->limit($imgnum)
  8194. ->get()->all();
  8195. }
  8196. }
  8197. }
  8198. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8199. $category_ids = explode(',', $val['id'])[0];
  8200. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8201. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8202. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8203. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8204. $text_num = Project::whereIn('category_id', $category_arr)
  8205. ->where('website_id', $data['website_id'])
  8206. ->where('status', 1)
  8207. ->select(
  8208. 'project.id',
  8209. 'project.title',
  8210. 'project.description',
  8211. 'project.updated_at',
  8212. 'project.category_id',
  8213. 'project.cat_arr_id'
  8214. )
  8215. ->orderBy('updated_at', 'desc')
  8216. ->limit($cat_textnum)
  8217. ->get()->all();
  8218. }
  8219. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8220. $img_num = Project::whereIn('category_id', $category_arr)
  8221. ->where('website_id', $data['website_id'])
  8222. ->where('status', 1)
  8223. ->where('imgurl', '!=', '')
  8224. ->whereNotNull('imgurl')
  8225. ->select(
  8226. 'project.id',
  8227. 'project.title',
  8228. 'project.description',
  8229. 'project.updated_at',
  8230. 'project.imgurl as imgs',
  8231. 'project.category_id',
  8232. 'project.cat_arr_id'
  8233. )
  8234. ->orderBy('updated_at', 'desc')
  8235. ->limit($cat_imgnum)
  8236. ->get()->all();
  8237. }
  8238. }
  8239. if (!empty($img_num)) {
  8240. foreach ($img_num as $k => $v) {
  8241. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8242. $imgurl = json_decode($v['imgs'], true);
  8243. if (!empty($imgurl)) {
  8244. $img_num[$k]->imgurl = $imgurl[0];
  8245. }
  8246. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8247. }
  8248. }
  8249. if (!empty($text_num)) {
  8250. foreach ($text_num as $k => $v) {
  8251. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8252. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8253. }
  8254. }
  8255. $project[$key]['img_num'] = $img_num ?? [];
  8256. $project[$key]['text_num'] = $text_num ?? [];
  8257. }
  8258. }
  8259. if (empty($project)) {
  8260. return Result::error("暂无相关项目信息", 0);
  8261. }
  8262. return Result::success($project);
  8263. }
  8264. /**
  8265. * @param array $data
  8266. * @return array
  8267. */
  8268. public function getWebsiteProjectInfo(array $data): array
  8269. {
  8270. $project = Project::where('id', $data['id'])
  8271. ->where('status', 1)
  8272. ->where('website_id', $data['website_id'])
  8273. ->select('project.*')
  8274. ->first();
  8275. if (empty($project)) {
  8276. return Result::error("暂无相关项目信息", 0);
  8277. }
  8278. return Result::success($project);
  8279. }
  8280. /**
  8281. * @param array $data
  8282. * @return array
  8283. */
  8284. public function getWebsiteProjectList(array $data): array
  8285. {
  8286. $where = [];
  8287. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8288. $where['category_id'] = $data['category_id'];
  8289. }
  8290. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8291. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8292. }
  8293. $query = Project::where($where)
  8294. ->where('status', 1)
  8295. ->where('website_id', $data['website_id'])
  8296. ->select(
  8297. 'project.id',
  8298. 'project.title',
  8299. 'project.description',
  8300. 'project.imgurl as imgs',
  8301. 'project.category_id',
  8302. 'project.cat_arr_id'
  8303. )
  8304. ->orderBy('updated_at', 'desc');
  8305. $count = $query->count();
  8306. $project = $query->clone()
  8307. ->offset(($data['page'] - 1) * $data['pageSize'])
  8308. ->limit($data['pageSize'])
  8309. ->get()->all();
  8310. if (empty($project)) {
  8311. return Result::error("暂无相关项目信息", 0);
  8312. }
  8313. $categorys = $this->processArticlePro($data['website_id']);
  8314. $catiall = $categorys['catiall'];
  8315. foreach ($project as $key => $val) {
  8316. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8317. if (!empty($val['imgs'])) {
  8318. $imgurl = json_decode($val['imgs'], true);
  8319. if (!empty($imgurl)) {
  8320. $project[$key]->imgurl = $imgurl[0];
  8321. }
  8322. } else {
  8323. $project[$key]->imgurl = '';
  8324. }
  8325. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8326. }
  8327. $result = [
  8328. 'rows' => $project,
  8329. 'count' => $count,
  8330. ];
  8331. return Result::success($result);
  8332. }
  8333. /**
  8334. * @param array $data
  8335. * @return array
  8336. */
  8337. public function getWebsiteCategoryJob(array $data): array
  8338. {
  8339. $categorys = json_decode($data['id'], true);
  8340. if (!empty($categorys)) {
  8341. $category_arr = $this->processArticlePro($data['website_id']);
  8342. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8343. $catiall = $category_arr['catiall'];
  8344. foreach ($categorys as $key => $val) {
  8345. if (isset($val['id']) && !empty($val['id'])) {
  8346. $catid = explode(',', $val['id'])[0] ?? null;
  8347. $type = explode(',', $val['id'])[1] ?? null;
  8348. $textnum = explode(',', $val['id'])[2] ?? null;
  8349. }
  8350. // 4:招聘;5:求职;
  8351. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8352. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8353. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8354. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8355. ->where('job_recruiting.status', 1)
  8356. ->where('job_recruiting.website_id', $data['website_id'])
  8357. ->select(
  8358. 'job_recruiting.id',
  8359. 'job_recruiting.title',
  8360. 'job_company.business_name',
  8361. 'job_recruiting.updated_at',
  8362. 'job_recruiting.cat_arr_id',
  8363. 'job_recruiting.keyword',
  8364. 'job_recruiting.description'
  8365. )
  8366. ->orderBy('job_recruiting.updated_at', 'desc')
  8367. ->limit($textnum)
  8368. ->get()->all();
  8369. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8370. // 状态 审核状态,1待审核2已审核3已拒绝
  8371. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8372. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8373. ->where('job_hunting.status', 2)
  8374. ->where('job_hunting.website_id', $data['website_id'])
  8375. ->select(
  8376. 'job_hunting.id',
  8377. 'job_hunting.name',
  8378. 'job_hunting.cat_arr_id',
  8379. 'job_position.zwname as job_name',
  8380. 'job_hunting.updated_at',
  8381. // 'job_hunting.keyword',
  8382. 'job_hunting.slelf_evaluation'
  8383. )
  8384. ->orderBy('updated_at', 'desc')
  8385. ->limit($textnum)
  8386. ->get()->all();
  8387. } else {
  8388. $job = [];
  8389. }
  8390. // var_dump($catid.'222uuuuuuu'.$key);
  8391. if (!empty($job)) {
  8392. foreach ($job as $k => $value) {
  8393. if (isset($value->cat_arr_id)) {
  8394. $catArr = json_decode($value->cat_arr_id, true);
  8395. $catId = end($catArr);
  8396. } else {
  8397. continue;
  8398. }
  8399. if (isset($catiall[$catId])) {
  8400. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8401. }
  8402. }
  8403. }
  8404. // var_dump($catid.'xxxxx'.$key);
  8405. $result[$key] = $job ?? [];
  8406. }
  8407. }
  8408. if (empty($result)) {
  8409. return Result::error("暂无相关分类信息", 0);
  8410. }
  8411. return Result::success($result);
  8412. }
  8413. /**
  8414. * 发送消息
  8415. * @param array $messageData
  8416. * @return void
  8417. */
  8418. public function sendMessage($messageData)
  8419. {
  8420. $msg = [
  8421. 'talk_type' => $messageData['talk_type'],
  8422. 'title' => $messageData['title'],
  8423. 'content' => $messageData['content'],
  8424. 'messageType' => $messageData['messageType'],
  8425. 'user_id' => $messageData['user_id'] ?? '',
  8426. 'time' => microtime(),
  8427. ];
  8428. $message = new MqProducer($msg);
  8429. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8430. $producer->produce($message);
  8431. }
  8432. /**
  8433. * 行业分类管理 ------1121
  8434. * @param array $data
  8435. * @return array
  8436. */
  8437. public function getJobIndustryList(array $data): array
  8438. {
  8439. $page = $data['page'] ?? 1;
  8440. $page_size = $data['page_size'] ?? 10;
  8441. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8442. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8443. } else {
  8444. $where = [];
  8445. }
  8446. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8447. $query->where([$where]); // 修复:将条件包装成二维数组
  8448. })
  8449. ->orderBy('updated_at', 'desc');
  8450. $count = $rs_query->count();
  8451. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8452. $result = [
  8453. 'count' => $count,
  8454. 'list' => $hy,
  8455. ];
  8456. if (empty($hy)) {
  8457. return Result::success('暂无数据');
  8458. }
  8459. return Result::success($result);
  8460. }
  8461. /**
  8462. * 添加行业分类
  8463. * @param array $data
  8464. * @return array
  8465. */
  8466. public function addJobIndustry(array $data): array
  8467. {
  8468. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8469. if (!empty($hy_name)) {
  8470. return Result::error('行业分类已存在');
  8471. }
  8472. $hy = JobIndustry::insertGetId($data);
  8473. if (empty($hy)) {
  8474. return Result::error('添加失败');
  8475. }
  8476. return Result::success($hy);
  8477. }
  8478. /**
  8479. * 更新行业分类
  8480. * @param array $data
  8481. * @return array
  8482. */
  8483. public function upJobIndustry(array $data): array
  8484. {
  8485. $hy_query = JobIndustry::get();
  8486. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8487. $hy_names = $hy_query->pluck('hyname')->toArray();
  8488. if (!in_array($data['hyid'], $hy_ids)) {
  8489. return Result::error('行业分类不存在');
  8490. }
  8491. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8492. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8493. // return Result::success($other_key_hy);
  8494. unset($hy_names[$other_key_hy]);
  8495. if (in_array($data['hyname'], $hy_names)) {
  8496. return Result::error('行业分类名称已存在');
  8497. }
  8498. }
  8499. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8500. if (empty($hy)) {
  8501. return Result::error('更新失败');
  8502. }
  8503. return Result::success($hy);
  8504. }
  8505. /**
  8506. * 删除行业分类
  8507. * @param array $data
  8508. * @return array
  8509. */
  8510. public function delJobIndustry(array $data): array
  8511. {
  8512. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8513. if (empty($hy_id)) {
  8514. return Result::error('行业分类不存在');
  8515. }
  8516. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8517. if (empty($hy)) {
  8518. return Result::error('删除失败');
  8519. }
  8520. return Result::success($hy);
  8521. }
  8522. /**
  8523. * 职位分类-列表
  8524. * @param array $data
  8525. * @return array
  8526. */
  8527. public function getJobPositionList(array $data): array
  8528. {
  8529. $page = $data['page'] ?? 1;
  8530. $page_size = $data['page_size'] ?? 10;
  8531. $where = [];
  8532. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8533. $zwids = JobPosition::where('zwpid', 0)
  8534. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8535. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8536. })
  8537. ->orderBy('updated_at', 'desc')
  8538. ->pluck('zwid')
  8539. // ->get()
  8540. ->toArray();
  8541. }
  8542. if (isset($data['childname']) && !empty($data['childname'])) {
  8543. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8544. ->when(!empty($data['childname']), function ($query) use ($data) {
  8545. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8546. })
  8547. ->orderBy('updated_at', 'desc')
  8548. ->pluck('zwpid')
  8549. // ->get()
  8550. ->toArray();
  8551. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8552. $child_zwids = array_intersect($zwids, $child_zwids);
  8553. }
  8554. $zwids = array_values(array_unique($child_zwids));
  8555. }
  8556. $zwids = $zwids ?? null;
  8557. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8558. $query->whereIn('zwid', $zwids);
  8559. })
  8560. ->where('zwpid', 0)
  8561. ->count();
  8562. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8563. $query->whereIn('zwid', $zwids);
  8564. })
  8565. ->where('zwpid', 0)
  8566. ->orderBy('updated_at', 'desc')
  8567. ->offset(($page - 1) * $page_size)
  8568. ->limit($page_size)->get()
  8569. ->map(function ($item) use ($data) {
  8570. $item->children = $item->where('zwpid', $item->zwid)
  8571. ->when(!empty($data['childname']), function ($query) use ($data) {
  8572. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8573. })
  8574. ->orderBy('updated_at', 'desc')
  8575. ->get();
  8576. return $item;
  8577. })
  8578. ->all();
  8579. $result = [
  8580. 'count' => $count,
  8581. 'list' => $position,
  8582. ];
  8583. if (empty($result)) {
  8584. return Result::success('暂无数据');
  8585. }
  8586. return Result::success($result);
  8587. }
  8588. /**
  8589. * 职位分类-添加
  8590. * @param array $data
  8591. * @return array
  8592. */
  8593. public function addJobPosition(array $data): array
  8594. {
  8595. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8596. ->where('zwname', $data['zwname'])->first(['zwid']);
  8597. if (!empty($zw_name)) {
  8598. return Result::error('职位分类已存在');
  8599. }
  8600. $zw = JobPosition::insertGetId($data);
  8601. if(empty($zw)){
  8602. return Result::error('添加失败');
  8603. }
  8604. return Result::success($zw);
  8605. }
  8606. /**
  8607. * 更新职位分类
  8608. * @param array $data
  8609. * @return array
  8610. */
  8611. public function upJobPosition(array $data): array
  8612. {
  8613. $zw_position = JobPosition::get();
  8614. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8615. return Result::error('职位分类不存在');
  8616. }
  8617. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8618. ->where('zwpid', $data['zwpid'])
  8619. ->where('zwname', $data['zwname'])->first();
  8620. if (!empty($zw_name)) {
  8621. return Result::error('职位分类已存在');
  8622. }
  8623. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8624. if (empty($result)) {
  8625. return Result::error('更新失败');
  8626. }
  8627. return Result::success($result);
  8628. }
  8629. /**
  8630. * 删除职位分类
  8631. * @param array $data
  8632. * @return array
  8633. */
  8634. public function delJobPosition(array $data): array
  8635. {
  8636. $zw_jobposition = JobPosition::get();
  8637. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8638. if (empty($zw_id)) {
  8639. return Result::error('职位分类不存在');
  8640. }
  8641. if($zw_id->zwpid == 0){
  8642. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8643. if(!empty($zw_job)){
  8644. return Result::error('请先删除子分类');
  8645. }
  8646. }
  8647. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8648. if (empty($result)) {
  8649. return Result::error('删除失败');
  8650. }
  8651. return Result::success($result);
  8652. }
  8653. }