NewsService.php 327 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896
  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. $id = Article::insertGetId($articleData);
  574. if (!$id) {
  575. throw new \Exception('文章插入失败');
  576. }
  577. $articleDataContent = [
  578. 'article_id' => $id,
  579. 'content' => $data['content'],
  580. ];
  581. // 采集器中的文章内容,在添加时,去掉div标签
  582. if ($is_collect == 1) {
  583. // 采集来的文章,content中可能包含div标签,需要先移除
  584. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  585. $article_data = preg_replace($pattern, '', $data['content']);
  586. $$articleDataContent['content'] = $article_data;
  587. }
  588. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  589. if (!$contentInsertId) {
  590. throw new \Exception('文章内容插入失败');
  591. }
  592. // ------c_show_time********add***2****
  593. // 直接使用当前系统时间,不再强制添加8小时
  594. $now = date('Y-m-d H:i:s');
  595. if ($user_type == 10000 || $is_collect == 1) {
  596. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  597. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  598. if (!isset($data['catid'])) {
  599. throw new \Exception('缺少必要字段:catid');
  600. }
  601. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  602. $web = WebsiteCategory::where('category_id', $data['catid'])
  603. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  604. ->select(
  605. 'website_id',
  606. 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')
  607. )
  608. ->get();
  609. // $id = 225; -----测试开启
  610. // 采集来的文章,错开时间在两小时之内发布
  611. if ($user_type == 10000 && $is_collect == 1) {
  612. $web_num = $web->where('is_core', '!=', 2)->count();
  613. $waiting_interval = 10;
  614. if ($web_num > 12) {
  615. // 若网站数量大于12个,则每个网站间隔时间取均值
  616. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  617. $waiting_interval = 120 / max(1, $web_num);
  618. }
  619. $time = 0;
  620. } else {
  621. // 非核心站与核心站----显示时间-----间隔
  622. $time = 20;
  623. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  624. $waiting_interval = 5;
  625. }
  626. // 将 Hyperf\Database\Model\Collection 转换为数组
  627. $webArray = $web->toArray();
  628. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  629. // 检查 $item 对象是否有 is_core 属性
  630. if (!isset($item['is_core'])) {
  631. throw new \Exception('$item 对象缺少 is_core 属性');
  632. }
  633. // 当 is_core 为 2 时,则表示此网站不存在
  634. if ($item['is_core'] == 2) {
  635. return null;
  636. }
  637. if ($is_collect == 1) {
  638. // 采集来的文章,错开时间在两小时之内发布
  639. // $time = 0;
  640. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  641. $time += $waiting_interval;
  642. } else if ($item['is_core'] == 1) {
  643. // 当 is_core 为 1 时,则表示此网站是核心站
  644. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  645. } else {
  646. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  647. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  648. if ($item['is_core'] == 0) {
  649. $time += $waiting_interval;
  650. }
  651. }
  652. return [
  653. 'article_id' => $id,
  654. 'website_id' => $item['website_id'],
  655. 'c_show_time' => $c_show_time,
  656. // 'is_core' => $item['is_core'],
  657. // 'time' => $time
  658. ];
  659. }, array_keys($webArray), $webArray)));
  660. // Db::commit();
  661. // return Result::success($article_ignore);
  662. if (!empty($article_ignore)) {
  663. $article_ignores = ArticleIgnore::insert($article_ignore);
  664. if (!$article_ignores) {
  665. throw new \Exception('c端展示时间插入失败');
  666. }
  667. }
  668. }
  669. // ------c_show_time********add***2****
  670. //处理投票
  671. if ($is_survey == 1) {
  672. //生成年月日时分秒+8位随机数
  673. $uuid = date('YmdHis') . rand(10000000, 99999999);
  674. var_dump($suvey_array, 'suvey_array________');
  675. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  676. var_dump($suveys_array, '---------------------1');
  677. var_dump($suvey_array, '---------------------2');
  678. $suvey_data = [];
  679. foreach ($suveys_array as $key => $value) {
  680. if ($value == '') {
  681. continue;
  682. }
  683. if (is_array($value)) {
  684. $suvey_data[] = [
  685. 'sur_id' => $uuid,
  686. 'art_id' => $id,
  687. 'website_id' => $website_id ?? 2,
  688. 'survey_name' => $survey_name,
  689. 'choice_name' => $value[1],
  690. 'is_other' => 1,
  691. 'other_id' => 0,
  692. 'results' => 0,
  693. ];
  694. } else {
  695. $suvey_data[] = [
  696. 'sur_id' => $uuid,
  697. 'art_id' => $id,
  698. 'website_id' => $website_id ?? 2,
  699. 'survey_name' => $survey_name,
  700. 'choice_name' => $value,
  701. 'is_other' => 0,
  702. 'other_id' => 0,
  703. 'results' => 0,
  704. ];
  705. }
  706. if (empty($suvey_data)) {
  707. throw new \Exception("投票数据为空");
  708. }
  709. }
  710. $result = ArticleSurvey::insert($suvey_data);
  711. if (!$result) {
  712. throw new \Exception("投票失败,ArticleSurvey插入失败");
  713. }
  714. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  715. if (!$result) {
  716. throw new \Exception("投票失败,更新主表失败");
  717. }
  718. }
  719. Db::commit();
  720. return Result::success(['id' => $id]);
  721. } catch (\Throwable $ex) {
  722. Db::rollBack();
  723. var_dump($ex->getMessage());
  724. return Result::error("创建失败", 0);
  725. }
  726. }
  727. /**
  728. * @param array $data
  729. * @return array
  730. */
  731. public function delArticle(array $data): array
  732. {
  733. // ------c_show_time********del*******
  734. Db::beginTransaction();
  735. try {
  736. $article = Article::where(['id' => $data['id']])->delete();
  737. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  738. if (!$article) {
  739. throw new \Exception("删除失败,文章删除失败");
  740. }
  741. //survey投票删除
  742. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  743. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  744. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  745. // 若文章详情删除失败,抛出异常
  746. if (!$article_data) {
  747. throw new \Exception("删除失败,文章详情删除失败");
  748. }
  749. Db::commit(); // 所有操作成功,提交事务
  750. } catch (\Throwable $ex) {
  751. Db::rollBack();
  752. var_dump($ex->getMessage());
  753. return Result::error("删除失败: " . $ex->getMessage(), 0);
  754. }
  755. // ------c_show_time********del*******
  756. if (!$article) {
  757. return Result::error("删除失败");
  758. }
  759. return Result::success($article);
  760. }
  761. /**
  762. * @param array $data
  763. * @return array
  764. */
  765. public function updateArticle(array $data): array
  766. {
  767. var_dump($data, '----------12-----------1');
  768. Db::beginTransaction();
  769. // ------c_show_time********up*******
  770. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  771. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  772. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  773. $web = WebsiteCategory::where('category_id', $data['catid'])
  774. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  775. ->select(
  776. 'website_id',
  777. 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')
  778. )
  779. ->get();
  780. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  781. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  782. $websiteIds = $web->pluck('website_id')->toArray();
  783. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  784. if ($user_type == 0) {
  785. throw new \Exception("用户类型不能为空");
  786. }
  787. if ($user_type == 10000) {
  788. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  789. $web = WebsiteCategory::where('category_id', $data['catid'])
  790. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  791. ->select(
  792. 'website_id',
  793. 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')
  794. )
  795. ->get();
  796. // 非核心站与核心站----显示时间-----间隔
  797. $time = 20;
  798. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  799. $waiting_interval = 5;
  800. $webArray = $web->toArray();
  801. if (empty($webArray)) {
  802. throw new \Exception('网站分类不存在');
  803. }
  804. // 直接使用当前系统时间,不再强制添加8小时
  805. $now = date('Y-m-d H:i:s');
  806. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  807. // 检查 $item 对象是否有 is_core 属性
  808. if (!isset($item['is_core'])) {
  809. throw new \Exception('$item 对象缺少 is_core 属性');
  810. }
  811. // 当 is_core 为 2 时,则表示此网站不存在
  812. if ($item['is_core'] == 2) {
  813. return null;
  814. } else if ($item['is_core'] == 1) {
  815. // 当 is_core 为 1 时,则表示此网站是核心站
  816. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  817. } else {
  818. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  819. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  820. if ($item['is_core'] == 0) {
  821. $time += $waiting_interval;
  822. }
  823. }
  824. return [
  825. 'article_id' => $data['id'],
  826. 'website_id' => $item['website_id'],
  827. 'c_show_time' => $c_show_time,
  828. ];
  829. }, array_keys($webArray), $webArray)));
  830. if (!empty($article_ignore)) {
  831. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  832. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  833. $article_ignores = ArticleIgnore::upsert(
  834. $article_ignore,
  835. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  836. ['c_show_time'] // 需要更新的字段
  837. );
  838. if (!$article_ignores) {
  839. throw new \Exception('c端展示时间插入失败');
  840. }
  841. }
  842. // Db::commit();
  843. // return Result::success($article_ignore);
  844. }
  845. // ------c_show_time********up*******
  846. unset($data['user_type']);
  847. // unset($data['web_site_id']);
  848. unset($data['nav_add_pool_id']);
  849. try {
  850. //处理投票
  851. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  852. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  853. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  854. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  855. unset($data['is_survey']);
  856. unset($data['survey_name']);
  857. unset($data['suvey_array']);
  858. unset($data['website_id']);
  859. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  860. if ($data['hits'] == '') {
  861. $data['hits'] = 0;
  862. }
  863. if ($data['is_original'] == '') {
  864. $data['is_original'] = 0;
  865. }
  866. if ($data['status'] == '') {
  867. $data['status'] = 0;
  868. }
  869. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  870. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  871. $articleData = $data;
  872. unset($articleData['content']);
  873. unset($articleData['status_name']);
  874. unset($articleData['name']);
  875. unset($articleData['content']);
  876. unset($articleData['pid_arr']);
  877. unset($articleData['pid']);
  878. //自动处理缩略图、关键字、描述
  879. if ($articleData['imgurl'] == '') {
  880. //如果没有图,设置level=0
  881. $levelArr = json_decode($articleData['level'], true);
  882. var_dump($levelArr, '----------levelArr-----------1');
  883. //content中提取图片第一个图,正则提取
  884. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  885. preg_match_all($reg, $data['content'], $matches);
  886. if (isset($matches[1][0])) {
  887. //截取varchar240
  888. // 截取到第一个<
  889. $articleData['imgurl'] = $matches[1][0];
  890. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  891. $pos = strpos($articleData['imgurl'], '"');
  892. if ($pos !== false) {
  893. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  894. }
  895. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  896. //如果有图,设置level=3
  897. if (!in_array(3, $levelArr)) {
  898. $levelArr[] = 3;
  899. }
  900. $articleData['level'] = json_encode($levelArr);
  901. } else {
  902. if (!in_array(0, $levelArr)) {
  903. $levelArr[] = 0;
  904. }
  905. $articleData['level'] = json_encode($levelArr);
  906. }
  907. }
  908. var_dump($articleData['level'], '----------$articleData[level]----------1');
  909. if ($articleData['keyword'] == '') {
  910. //提取标题+内容中的关键词
  911. $articleData['keyword'] = $data['title'];
  912. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  913. Jieba::init(); // 初始化 jieba-php
  914. Finalseg::init();
  915. $segList = Jieba::cut($articleData['keyword']);
  916. $segList1 = array_slice($segList, 0, 8);
  917. $articleData['keyword'] = implode(',', $segList1);
  918. }
  919. if ($articleData['introduce'] == '') {
  920. //提取内容中的描述
  921. $content = $data['content'];
  922. // 去除 <style> 和 <script> 标签及其内容
  923. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  924. // 去除所有 HTML 标签
  925. $content = strip_tags($content);
  926. // 去除 HTML 实体
  927. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  928. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  929. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  930. // 去除多余空白
  931. $content = preg_replace('/\s+/u', '', $content);
  932. // 截取 100 个字符
  933. $articleData['introduce'] = mb_substr($content, 0, 100);
  934. }
  935. if ($articleData['status'] == 0) {
  936. $this->sendMessage([
  937. 'talk_type' => 100,
  938. 'title' => $articleData['title'],
  939. 'content' => '提交了审核',
  940. 'messageType' => 2,
  941. ]);
  942. }
  943. $id = Article::where(['id' => $data['id']])->update($articleData);
  944. // $articleDataContent = [
  945. // 'content' => $data['content'],
  946. // ];
  947. // 采集来的文章,content中可能包含div标签,需要先移除
  948. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  949. $article_data = preg_replace($pattern, '', $data['content']);
  950. $articleDataContent['content'] = $article_data;
  951. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  952. //处理投票
  953. $id = $data['id'];
  954. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  955. var_dump($suvey_array, 'suvey_array________delete');
  956. //处理投票
  957. if ($is_survey == 1) {
  958. //生成年月日时分秒+8位随机数
  959. $uuid = date('YmdHis') . rand(10000000, 99999999);
  960. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  961. var_dump($suveys_array, '---------------------1');
  962. $suvey_data = [];
  963. if (is_array($suveys_array)) {
  964. foreach ($suveys_array as $key => $value) {
  965. if ($value == '') {
  966. continue;
  967. }
  968. if (is_array($value)) {
  969. $suvey_data[] = [
  970. 'sur_id' => $uuid,
  971. 'art_id' => $id,
  972. 'website_id' => $website_id ?? 2,
  973. 'survey_name' => $survey_name,
  974. 'choice_name' => $value[1],
  975. 'is_other' => 1,
  976. 'other_id' => 0,
  977. 'results' => 0,
  978. ];
  979. } else {
  980. $suvey_data[] = [
  981. 'sur_id' => $uuid,
  982. 'art_id' => $id,
  983. 'website_id' => $website_id ?? 2,
  984. 'survey_name' => $survey_name,
  985. 'choice_name' => $value,
  986. 'is_other' => 0,
  987. 'other_id' => 0,
  988. 'results' => 0,
  989. ];
  990. }
  991. if (empty($suvey_data)) {
  992. throw new \Exception("投票数据为空");
  993. }
  994. }
  995. }
  996. $result = ArticleSurvey::insert($suvey_data);
  997. if (!$result) {
  998. throw new \Exception("投票失败");
  999. }
  1000. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1001. if (!$result) {
  1002. throw new \Exception("投票失败");
  1003. }
  1004. } else {
  1005. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1006. }
  1007. Db::commit();
  1008. return Result::success([]);
  1009. } catch (\Throwable $ex) {
  1010. Db::rollBack();
  1011. var_dump($ex->getMessage());
  1012. return Result::error("更新失败" . $ex->getMessage(), 0);
  1013. }
  1014. }
  1015. /**
  1016. * 更新资讯状态
  1017. * @param array $data
  1018. * @return array
  1019. */
  1020. public function upArticleStatus(array $data): array
  1021. {
  1022. $articleData = Article::where(['id' => $data['id']])->first();
  1023. //发送10次
  1024. // for ($i = 0; $i < 10; $i++) {
  1025. // $this->sendMessage([
  1026. // 'talk_type' => 100,
  1027. // 'title' => $i . $articleData['title'],
  1028. // 'content' => '审核通过',
  1029. // 'messageType' => 2,
  1030. // 'user_id' => $articleData['admin_user_id'],
  1031. // ]);
  1032. // }
  1033. // var_dump($data['status'], 'status');
  1034. // return Result::success();
  1035. if ($data['status'] == 1) {
  1036. $this->sendMessage([
  1037. 'talk_type' => 101,
  1038. 'title' => $articleData['title'],
  1039. 'content' => '审核通过',
  1040. 'messageType' => 2,
  1041. 'user_id' => $articleData['admin_user_id'],
  1042. ]);
  1043. }
  1044. if ($data['status'] == 2) {
  1045. $this->sendMessage([
  1046. 'talk_type' => 101,
  1047. 'title' => $articleData['title'],
  1048. 'content' => '审核拒绝',
  1049. 'messageType' => 2,
  1050. 'user_id' => $articleData['admin_user_id'],
  1051. ]);
  1052. }
  1053. if ($data['status'] == 0) {
  1054. $this->sendMessage([
  1055. 'talk_type' => 100,
  1056. 'title' => $articleData['title'],
  1057. 'content' => '提交了审核',
  1058. 'messageType' => 2,
  1059. ]);
  1060. }
  1061. $result = Article::where(['id' => $data['id']])->update($data);
  1062. // ------c_show_time********up_status*******
  1063. // 若是审核通过 则更新c_show_time
  1064. if ($data['status'] == 1) {
  1065. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1066. $web = Article::where('article.id', $data['id'])
  1067. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1068. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1069. ->select(
  1070. 'website_id',
  1071. 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')
  1072. )
  1073. ->get();
  1074. // 非核心站与核心站----显示时间-----间隔
  1075. $time = 20;
  1076. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1077. $waiting_interval = 5;
  1078. $webArray = $web->toArray();
  1079. if (empty($webArray)) {
  1080. throw new \Exception('网站分类不存在');
  1081. }
  1082. // 直接使用当前系统时间,不再强制添加8小时
  1083. $now = date('Y-m-d H:i:s');
  1084. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1085. if (isset($data['ignore_ids'])) {
  1086. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1087. if (in_array($item['website_id'], $ignore_website_ids)) {
  1088. $is_ignore = 1;
  1089. } else {
  1090. $is_ignore = 0;
  1091. }
  1092. return [
  1093. 'article_id' => $data['id'],
  1094. 'website_id' => $item['website_id'],
  1095. 'is_ignore' => $is_ignore,
  1096. ];
  1097. } else {
  1098. // 检查 $item 对象是否有 is_core 属性
  1099. if (!isset($item['is_core'])) {
  1100. throw new \Exception('$item 对象缺少 is_core 属性');
  1101. }
  1102. // 当 is_core 为 2 时,则表示此网站不存在
  1103. if ($item['is_core'] == 2) {
  1104. return null;
  1105. } else if ($item['is_core'] == 1) {
  1106. // 当 is_core 为 1 时,则表示此网站是核心站
  1107. $c_show_time = $now;
  1108. } else {
  1109. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1110. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1111. if ($item['is_core'] == 0) {
  1112. $time += $waiting_interval;
  1113. }
  1114. }
  1115. return [
  1116. 'article_id' => $data['id'],
  1117. 'website_id' => $item['website_id'],
  1118. 'c_show_time' => $c_show_time,
  1119. ];
  1120. }
  1121. }, array_keys($webArray), $webArray)));
  1122. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1123. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1124. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1125. $websiteIds = $web->pluck('website_id')->toArray();
  1126. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1127. $article_ignores = ArticleIgnore::upsert(
  1128. $article_ignore,
  1129. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1130. ['c_show_time'] // 需要更新的字段
  1131. );
  1132. if (!$article_ignores) {
  1133. throw new \Exception('c端展示时间插入失败');
  1134. }
  1135. }
  1136. if (!empty($data['ignore_ids'])) {
  1137. // return Result::success($article_ignore);
  1138. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1139. if (!empty($article_ignore)) {
  1140. $article_ignores = ArticleIgnore::upsert(
  1141. $article_ignore,
  1142. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1143. ['is_ignore'] // 需要更新的字段
  1144. );
  1145. // if(!$article_ignores){
  1146. // throw new \Exception('屏蔽网站更新失败');
  1147. // }
  1148. }
  1149. }
  1150. }
  1151. // ------c_show_time********up_status*******
  1152. if ($result) {
  1153. return Result::success();
  1154. } else {
  1155. return Result::error("更新状态失败", 0);
  1156. }
  1157. }
  1158. /**
  1159. * 获取新闻详情
  1160. * @param array $data
  1161. * @return array
  1162. */
  1163. public function getArticleInfo(array $data): array
  1164. {
  1165. $where = [
  1166. 'article.id' => $data['id'],
  1167. // 'article.status' => 1,
  1168. ];
  1169. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1170. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1171. $info = $result;
  1172. // var_dump($info, 'info');
  1173. $info['survey_array'] = $articleSurvey;
  1174. if ($result) {
  1175. return Result::success($info);
  1176. } else {
  1177. return Result::error("查询失败", 0);
  1178. }
  1179. }
  1180. /**
  1181. * 获取头条新闻
  1182. * @param array $data
  1183. * @return array
  1184. */
  1185. public function getWebsiteArticlett(array $data): array
  1186. {
  1187. $website_id = $data['website_id'];
  1188. $website = Website::where('id', $data['website_id'])->first();
  1189. if (empty($website)) {
  1190. return Result::error("网站不存在", 0);
  1191. }
  1192. $categorys = $this->processArticlePro($website_id);
  1193. $catiall = $categorys['catiall'];
  1194. $categoryIds = $categorys['categoryIds'];
  1195. $where = [
  1196. 'status' => 1
  1197. ];
  1198. // $website_column = $website['column'];
  1199. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1200. $website_column = json_decode($website['website_column_arr_id'], true);
  1201. }
  1202. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1203. // return Result::success($diff_pid_categoryIds);
  1204. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1205. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1206. }
  1207. // $website_id = $data['website_id'];
  1208. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1209. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1210. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1211. switch ($data['level']) {
  1212. case 1:
  1213. case 2:
  1214. case 3:
  1215. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1216. $query = Article::where($where)
  1217. ->where('level', 'like', '%' . $data['level'] . '%')
  1218. ->orderBy('updated_at', 'desc');
  1219. break;
  1220. case 4: //最新资讯
  1221. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1222. break;
  1223. case 5: //资讯推荐
  1224. $query = Article::where($where)
  1225. ->where('updated_at', '>', $month);
  1226. break;
  1227. case 7: //资讯分类
  1228. if (isset($data['id']) && !empty($data['id'])) {
  1229. $keyword = Article::where('id', $data['id'])->value('keyword');
  1230. $keywordArray = explode(',', $keyword);
  1231. $whereL7 = [];
  1232. foreach ($keywordArray as $k => $v) {
  1233. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1234. }
  1235. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1236. break;
  1237. } else {
  1238. return Result::error("请输入资讯ID", 0);
  1239. break;
  1240. }
  1241. default:
  1242. break;
  1243. }
  1244. // $whereL7 = [];
  1245. // if(isset($data['id']) && !empty($data['id'])){
  1246. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1247. // $keywordArray = explode(',', $keyword);
  1248. // foreach ($keywordArray as $k => $v) {
  1249. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1250. // }
  1251. // }
  1252. // $query = Article::where($where)
  1253. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1254. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1255. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1256. // }
  1257. // if($data['level'] == 7){
  1258. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1259. // }
  1260. // if($data['level'] == 4){
  1261. // $query = $query->inRandomOrder()
  1262. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1263. // }
  1264. // if($data['level'] == 5){
  1265. // $query = $query->orderBy('updated_at','desc');
  1266. // }
  1267. // });
  1268. if ($data['textnum'] > 0) {
  1269. $query = clone $query;
  1270. $result['text'] = $query
  1271. ->whereIn('catid', $categoryIds)
  1272. ->leftJoinSub(function ($query) use ($website_id) {
  1273. $query->from('article_ignore')
  1274. ->where('website_id', $website_id);
  1275. }, 'article_ignore', function ($join) {
  1276. $join->on('article_ignore.article_id', '=', 'article.id');
  1277. })
  1278. ->where(function ($query) {
  1279. $query->whereNull('article_ignore.article_id')
  1280. ->orWhere(function ($subQuery) {
  1281. $subQuery->whereNotNull('article_ignore.article_id')
  1282. ->where('article_ignore.is_ignore', 0)
  1283. ->where(function ($subSubQuery) {
  1284. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1285. ->orWhereNull('article_ignore.c_show_time');
  1286. });
  1287. });
  1288. })
  1289. // ->where(function ($query) use ($website_id) {
  1290. // $query->whereNull('article_ignore.article_id')
  1291. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1292. // })
  1293. ->select(
  1294. 'article.id',
  1295. 'article.title',
  1296. 'article.author',
  1297. 'article.updated_at',
  1298. 'article.introduce',
  1299. 'article.islink',
  1300. 'article.linkurl',
  1301. 'article.copyfrom',
  1302. 'article.cat_arr_id',
  1303. 'article.catid',
  1304. 'article.level',
  1305. // 'article_ignore.is_ignore',
  1306. // 'article_ignore.c_show_time',
  1307. )
  1308. ->offset($data['placeid'])
  1309. ->limit($data['textnum'])
  1310. ->get()->all();
  1311. foreach ($result['text'] as $k => $v) {
  1312. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1313. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1314. }
  1315. }
  1316. if ($data['imgnum'] > 0) {
  1317. $query = clone $query;
  1318. if ($data['textnum'] == 0) {
  1319. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1320. $query->from('article_ignore')
  1321. ->where('website_id', $website_id);
  1322. }, 'article_ignore', function ($join) {
  1323. $join->on('article_ignore.article_id', '=', 'article.id');
  1324. })
  1325. ->where(function ($query) {
  1326. $query->whereNull('article_ignore.article_id')
  1327. ->orWhere(function ($subQuery) {
  1328. $subQuery->whereNotNull('article_ignore.article_id')
  1329. ->where('article_ignore.is_ignore', 0)
  1330. ->where(function ($subSubQuery) {
  1331. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1332. ->orWhereNull('article_ignore.c_show_time');
  1333. });
  1334. });
  1335. });
  1336. }
  1337. $result['img'] = $query
  1338. ->whereIn('catid', $categoryIds)
  1339. ->where('article.imgurl', '!=', '')
  1340. ->select(
  1341. 'article.id',
  1342. 'article.title',
  1343. 'article.imgurl',
  1344. 'article.author',
  1345. 'article.updated_at',
  1346. 'article.introduce',
  1347. 'article.islink',
  1348. 'article.linkurl',
  1349. 'article.copyfrom',
  1350. 'article.cat_arr_id',
  1351. 'article.catid',
  1352. 'article.level',
  1353. // 'article_ignore.is_ignore',
  1354. // 'article_ignore.c_show_time',
  1355. )
  1356. ->offset($data['placeid'])
  1357. ->limit($data['imgnum'])
  1358. ->get()->all();
  1359. foreach ($result['img'] as $k => $v) {
  1360. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1361. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1362. }
  1363. }
  1364. if (empty($result)) {
  1365. return Result::error("暂无相关资讯", 0);
  1366. }
  1367. return Result::success($result);
  1368. }
  1369. /**
  1370. * 获取模块新闻
  1371. * @param array $data
  1372. * @return array
  1373. */
  1374. public function getWebsiteModelArticles(array $data): array
  1375. {
  1376. $catid = $data['catid'];
  1377. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1378. $category = $category->toArray();
  1379. if (!empty($category)) {
  1380. $where = [
  1381. 'status' => 1,
  1382. 'catid' => $catid,
  1383. ];
  1384. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1385. // 1:文字新闻;2:轮播图;3:图文;
  1386. // 级别:0:未分类
  1387. // 3:推荐图片
  1388. if ($data['level'] == 1) {
  1389. $data['level'] = 0;
  1390. }
  1391. $result = Article::where($where)
  1392. ->where(function ($query) use ($data) {
  1393. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1394. ->orWhereNull("level")
  1395. ->orWhereRaw("level = '[]'");
  1396. })
  1397. ->leftJoinSub(function ($query) use ($data) {
  1398. $query->from('article_ignore')
  1399. ->where('website_id', $data['website_id']);
  1400. }, 'article_ignore', function ($join) {
  1401. $join->on('article_ignore.article_id', '=', 'article.id');
  1402. })
  1403. ->where(function ($query) {
  1404. $query->whereNull('article_ignore.article_id')
  1405. ->orWhere(function ($subQuery) {
  1406. $subQuery->whereNotNull('article_ignore.article_id')
  1407. ->where('article_ignore.is_ignore', 0)
  1408. ->where(function ($subSubQuery) {
  1409. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1410. ->orWhereNull('article_ignore.c_show_time');
  1411. });
  1412. });
  1413. })
  1414. // ->where(function ($query) use ($data) {
  1415. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1416. // ->orWhereNull("ignore_ids");
  1417. // })
  1418. ->orderBy("updated_at", "desc")
  1419. ->offset($placeid)
  1420. ->limit($data['pagesize'])
  1421. ->get();
  1422. if (empty($result)) {
  1423. return Result::error("此栏目暂无相关新闻", 0);
  1424. }
  1425. } else {
  1426. return Result::error("此网站暂无此栏目", 0);
  1427. }
  1428. return Result::success($result);
  1429. }
  1430. /**
  1431. *获取新闻列表
  1432. * @param array $data
  1433. * @return array
  1434. */
  1435. public function getWebsiteArticleList(array $data): array
  1436. {
  1437. // return Result::success($data);
  1438. $where[] = ['status', '=', 1];
  1439. $website_id = $data['website_id'];
  1440. $website = Website::where('id', $data['website_id'])->first();
  1441. if (empty($website)) {
  1442. return Result::error("网站不存在", 0);
  1443. }
  1444. // $website_column = $website['column'];
  1445. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1446. $website_column = json_decode($website['website_column_arr_id'], true);
  1447. }
  1448. $categorys = $this->processArticlePro($website_id);
  1449. $cat_1st_arr = $categorys['cat_1st_arr'];
  1450. $catiall = $categorys['catiall'];
  1451. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1452. // return Result::success($diff_pid_categoryIds);
  1453. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1454. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1455. }
  1456. if (isset($data['catid']) && !empty($data['catid'])) {
  1457. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1458. if (empty($category)) {
  1459. return Result::error("此网站暂无此栏目", 0);
  1460. }
  1461. array_push($where, ['catid', '=', $data['catid']]);
  1462. }
  1463. // return Result::success($where);
  1464. $query = Article::where($where)
  1465. ->leftJoinSub(function ($query) use ($website_id) {
  1466. $query->from('article_ignore')
  1467. ->where('website_id', $website_id);
  1468. }, 'article_ignore', function ($join) {
  1469. $join->on('article_ignore.article_id', '=', 'article.id');
  1470. })
  1471. ->where(function ($query) {
  1472. $query->whereNull('article_ignore.article_id')
  1473. ->orWhere(function ($subQuery) {
  1474. $subQuery->whereNotNull('article_ignore.article_id')
  1475. ->where('article_ignore.is_ignore', 0)
  1476. ->where(function ($subSubQuery) {
  1477. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1478. ->orWhereNull('article_ignore.c_show_time');
  1479. });
  1480. });
  1481. })
  1482. ->select(
  1483. 'article.id',
  1484. 'article.title',
  1485. 'article.imgurl',
  1486. 'article.author',
  1487. 'article.updated_at',
  1488. 'article.introduce',
  1489. 'article.islink',
  1490. 'article.linkurl',
  1491. 'article.copyfrom',
  1492. 'article.cat_arr_id',
  1493. 'article.catid'
  1494. );
  1495. $count = $query->count();
  1496. $rep = $query->orderBy("updated_at", "desc")
  1497. ->offset(($data['page'] - 1) * $data['pageSize'])
  1498. ->limit($data['pageSize'])
  1499. ->get()->all();
  1500. $categorys = $this->processArticlePro($website_id);
  1501. $cat_1st_arr = $categorys['cat_1st_arr'];
  1502. $catiall = $categorys['catiall'];
  1503. // $web['website_id'] = $data['website_id'];
  1504. foreach ($rep as $k => $v) {
  1505. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1506. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1507. }
  1508. // $rep = $this->processArticles($rep,$web);
  1509. $data = [
  1510. 'rows' => $rep,
  1511. 'count' => $count,
  1512. ];
  1513. if (empty($rep)) {
  1514. return Result::error("没有信息数据");
  1515. }
  1516. return Result::success($data);
  1517. }
  1518. /**
  1519. * 前端-获取新闻详情
  1520. * @param array $data
  1521. * @return array
  1522. */
  1523. public function selectWebsiteArticleInfo(array $data): array
  1524. {
  1525. $where = [
  1526. 'article.id' => $data['id'],
  1527. 'article.status' => 1,
  1528. ];
  1529. $result = Article::where($where)
  1530. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1531. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1532. // ->where(function ($query) use ($data) {
  1533. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1534. // ->orWhereNull("ignore_ids");
  1535. // })
  1536. ->leftJoinSub(function ($query) use ($data) {
  1537. $query->from('article_ignore')
  1538. ->where('website_id', $data['website_id']);
  1539. }, 'article_ignore', function ($join) {
  1540. $join->on('article_ignore.article_id', '=', 'article.id');
  1541. })
  1542. ->where(function ($query) {
  1543. $query->whereNull('article_ignore.article_id')
  1544. ->orWhere(function ($subQuery) {
  1545. $subQuery->whereNotNull('article_ignore.article_id')
  1546. ->where('article_ignore.is_ignore', 0)
  1547. ->where(function ($subSubQuery) {
  1548. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1549. ->orWhereNull('article_ignore.c_show_time');
  1550. });
  1551. });
  1552. })
  1553. ->select(
  1554. 'article.*',
  1555. 'article_data.content',
  1556. 'article_data.article_id',
  1557. 'article_extend.website_url',
  1558. 'article_extend.email',
  1559. 'article_extend.contacts',
  1560. 'article_extend.contacts_mobile',
  1561. 'article_extend.contacts_address',
  1562. 'article_extend.zip_code',
  1563. 'article_extend.enterprise_name'
  1564. )
  1565. ->first();
  1566. if (empty($result)) {
  1567. return Result::error("暂无此新闻!", 0);
  1568. }
  1569. if (!empty($result['publiced_at'])) {
  1570. $result['updated_at'] = $result['publiced_at'];
  1571. }
  1572. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1573. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1574. ->where('website_category.website_id', $data['website_id'])
  1575. ->where(['website_category.category_id' => $result['catid']])
  1576. ->first();
  1577. if (empty($category)) {
  1578. return Result::error("查询失败", 0);
  1579. }
  1580. //手动推荐文章
  1581. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1582. if (empty($commend_ids)) {
  1583. $commendArticle = [];
  1584. } else {
  1585. //去除不存在的文章ID
  1586. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1587. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1588. ->leftJoinSub(function ($query) use ($data) {
  1589. $query->from('article_ignore')
  1590. ->where('website_id', $data['website_id']);
  1591. }, 'article_ignore', function ($join) {
  1592. $join->on('article_ignore.article_id', '=', 'article.id');
  1593. })
  1594. ->where(function ($query) {
  1595. $query->whereNull('article_ignore.article_id')
  1596. ->orWhere(function ($subQuery) {
  1597. $subQuery->whereNotNull('article_ignore.article_id')
  1598. ->where('article_ignore.is_ignore', 0)
  1599. ->where(function ($subSubQuery) {
  1600. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1601. ->orWhereNull('article_ignore.c_show_time');
  1602. });
  1603. });
  1604. })
  1605. ->where('article.status', 1)
  1606. ->where('website_category.website_id', $data['website_id'])
  1607. ->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')
  1608. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1609. // ->orderBy('article.updated_at', 'desc')
  1610. ->limit(5)
  1611. ->get();
  1612. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1613. foreach ($commendArticle as $k => $v) {
  1614. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1615. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1616. $cat_arr_id = array_unique($cat_arr_id);
  1617. // 从website_category取出alias_pinyin
  1618. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1619. ->whereIn('category_id', $cat_arr_id)
  1620. ->pluck('alias_pinyin', 'category_id')
  1621. ->toArray();
  1622. // 将cat_arr_id的json转成路径/隔开
  1623. $path_parts = [];
  1624. foreach ($cat_arr_id as $cat_id) {
  1625. if (isset($cat_arr[$cat_id])) {
  1626. $path_parts[] = $cat_arr[$cat_id];
  1627. }
  1628. }
  1629. $v->alias_pinyin = implode('/', $path_parts);
  1630. } else {
  1631. $v->alias_pinyin = '';
  1632. }
  1633. }
  1634. }
  1635. $result['category_id'] = $category['category_id'];
  1636. $result['cat_name'] = $category['alias'];
  1637. $result['website_name'] = $category['website_name'] ?? "";
  1638. $result['suffix'] = $category['suffix'] ?? "";
  1639. $result['commendArticle'] = $commendArticle;
  1640. $result['commend_ids'] = $commend_ids;
  1641. return Result::success($result);
  1642. }
  1643. /**
  1644. * 前端-获取网站调查问卷
  1645. * @param array $data
  1646. * @return array
  1647. */
  1648. public function getWebsiteSurvey(array $data): array
  1649. {
  1650. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1651. $website = Website::where('id', $data['website_id'])->first();
  1652. if (empty($website)) {
  1653. return Result::error("暂无此网站", 0);
  1654. }
  1655. }
  1656. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1657. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1658. if (empty($article)) {
  1659. return Result::error("暂无此文章", 0);
  1660. }
  1661. // return Result::error($data,0);
  1662. $where['art_id'] = $data['art_id'];
  1663. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1664. } else {
  1665. $survey = Article::where(function ($query) {
  1666. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1667. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1668. })
  1669. ->where('status', 1)
  1670. ->where('is_survey', 1)
  1671. ->select('survey_id')
  1672. ->orderBy('updated_at', 'desc')
  1673. ->first();
  1674. if (empty($survey)) {
  1675. return Result::error("暂无调查问卷", 0);
  1676. }
  1677. $where['sur_id'] = $survey['survey_id'];
  1678. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1679. }
  1680. // return Result::success($where);
  1681. $result = ArticleSurvey::where($where)
  1682. ->where(function ($query) {
  1683. $query->where('is_other', 0)
  1684. ->orWhere(function ($subQuery) {
  1685. $subQuery->where('is_other', 1)
  1686. ->where('other_id', 0);
  1687. });
  1688. })
  1689. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1690. ->select('article_survey.*', 'article.survey_type')
  1691. ->get()->all();
  1692. if (empty($result)) {
  1693. return Result::error("此文章暂无调查问卷", 0);
  1694. }
  1695. return Result::success($result);
  1696. }
  1697. /**
  1698. * 前端-添加网站调查问卷选项
  1699. * @param array $data
  1700. * @return array
  1701. */
  1702. public function addWebsiteSurveyOption(array $data): array
  1703. {
  1704. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1705. $website = Website::where('id', $data['website_id'])->first();
  1706. if (empty($website)) {
  1707. return Result::error("暂无此网站", 0);
  1708. }
  1709. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1710. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1711. if (empty($survey)) {
  1712. return Result::error("此调查问卷不可添加选项", 0);
  1713. }
  1714. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1715. $choice = [
  1716. 'art_id' => $survey['art_id'],
  1717. 'website_id' => $data['website_id'],
  1718. 'survey_name' => $survey['survey_name'],
  1719. 'choice_name' => $data['choice_name'],
  1720. 'sur_id' => $survey['sur_id'],
  1721. 'is_other' => 1,
  1722. 'other_id' => $survey['id'],
  1723. ];
  1724. $result = ArticleSurvey::insertGetId($choice);
  1725. if (empty($result)) {
  1726. return Result::error("添加失败", 0);
  1727. }
  1728. return Result::success($result);
  1729. }
  1730. }
  1731. return Result::error("添加失败", 0);
  1732. }
  1733. return Result::error("添加失败", 0);
  1734. }
  1735. /**
  1736. * 前端-调查问卷投票
  1737. * @param array $data
  1738. * @return array
  1739. */
  1740. public function addWebsiteSurveyVote(array $data): array
  1741. {
  1742. // return Result::success($data);
  1743. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1744. $website = Website::where('id', $data['website_id'])->first();
  1745. if (empty($website)) {
  1746. return Result::error("暂无此网站", 0);
  1747. }
  1748. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1749. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1750. // return Result::success($survey);
  1751. if (empty($is_survey)) {
  1752. return Result::error("此调查问卷不存在", 0);
  1753. }
  1754. // return Result::success($survey);
  1755. // 调查问卷类型
  1756. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1757. //多选 若是json型则转化成数组类型
  1758. if (strpos($data['choice_id'], '[') === 0) {
  1759. $data['choice_id'] = json_decode($data['choice_id'], true);
  1760. } else {
  1761. // 单选 也转换成数组
  1762. $data['choice_id'] = [$data['choice_id']];
  1763. }
  1764. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1765. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1766. // ->where('website_id',$data['website_id'])
  1767. ->where('is_other', 1)
  1768. ->where('other_id', 0)
  1769. ->first();
  1770. if (!empty($other)) {
  1771. return Result::error("请选择已有的选项!", 0);
  1772. }
  1773. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1774. // ->where('website_id',$data['website_id'])
  1775. ->where('is_other', 1)
  1776. ->where('other_id', '!=', 0)
  1777. ->first();
  1778. // return Result::success($choice['other']);
  1779. $choice_id = $data['choice_id'];
  1780. if (!empty($choice['other'])) {
  1781. // array_push($data['choice_id'],$choice['other']['other_id']);
  1782. if (!empty($choice_id)) {
  1783. $key = array_search($choice['other']['id'], $choice_id);
  1784. if ($key !== false) {
  1785. unset($choice_id[$key]);
  1786. $choice_id = array_values($choice_id);
  1787. }
  1788. array_push($choice_id, $choice['other']['other_id']);
  1789. } else {
  1790. $choice_id[0] = $choice['other']['other_id'];
  1791. }
  1792. array_push($data['choice_id'], $choice['other']['other_id']);
  1793. }
  1794. // return Result::success($data);
  1795. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1796. // ->where('website_id',$data['website_id'])
  1797. ->increment('results', 1);
  1798. if (empty($choice)) {
  1799. return Result::error("请选择已有的选项!", 0);
  1800. }
  1801. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1802. // ->where('website_id',$data['website_id'])
  1803. ->where('other_id', 0)
  1804. ->get();
  1805. $survey['choice'] = $choice_id;
  1806. return Result::success($survey);
  1807. }
  1808. return Result::error("参数必填!");
  1809. }
  1810. return Result::error("此调查问卷不存在", 0);
  1811. }
  1812. return Result::error("参数必填!");
  1813. }
  1814. /**
  1815. * 后端-获取网站调查问卷列表
  1816. * @param array $data
  1817. * @return array
  1818. */
  1819. public function getSurveyList(array $data): array
  1820. {
  1821. $where = [];
  1822. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1823. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1824. }
  1825. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1826. if (!empty($where)) {
  1827. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1828. $query = ArticleSurvey::select(
  1829. 'art_id as id',
  1830. Db::raw('MAX(id) as surid'),
  1831. Db::raw('MAX(survey_name) as survey_name'),
  1832. Db::raw('MAX(sur_id) as survey_id')
  1833. )
  1834. ->groupBy('art_id')
  1835. ->where($where)
  1836. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1837. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1838. $sub->select('id')
  1839. ->from('article')
  1840. ->where('survey_type', $survey_type);
  1841. });
  1842. })
  1843. ->with(['article' => function ($query) {
  1844. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1845. }]);
  1846. ;
  1847. }else{
  1848. $query = ArticleSurvey::select(
  1849. 'art_id as id',
  1850. Db::raw('MAX(id) as surid'),
  1851. Db::raw('MAX(survey_name) as survey_name'),
  1852. Db::raw('MAX(sur_id) as survey_id'),
  1853. )
  1854. ->groupBy('art_id')
  1855. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1856. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1857. $sub->select('id')
  1858. ->from('article')
  1859. ->where('survey_type', $survey_type);
  1860. });
  1861. })
  1862. ->with(['article' => function ($query) {
  1863. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1864. }]);
  1865. }
  1866. $count = $query->get()->count();
  1867. // 简单写法:直接统计分组后的 art_id 数量
  1868. $survey = $query->orderBy('id', 'desc')
  1869. ->limit($data['pageSize'])
  1870. ->offset(($data['page'] - 1) * $data['pageSize'])
  1871. ->get();
  1872. if (empty($survey->toArray())) {
  1873. return Result::error("暂无调查问卷!", 0);
  1874. }
  1875. $survey = array_map(function ($item) {
  1876. $item['survey_type'] = $item['article']['survey_type'];
  1877. $item['created_at'] = $item['article']['created_at'];
  1878. $item['updated_at'] = $item['article']['updated_at'];
  1879. unset($item['article']);
  1880. return $item;
  1881. }, $survey->toArray());
  1882. $result = [
  1883. 'rows' => $survey,
  1884. 'count' => $count,
  1885. ];
  1886. return Result::success($result);
  1887. }
  1888. /**
  1889. * 后端-获取网站调查问卷详情
  1890. * @param array $data
  1891. * @return array
  1892. */
  1893. public function getSurveyInfo(array $data): array
  1894. {
  1895. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1896. $where = ['sur_id' => $data['sur_id']];
  1897. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1898. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1899. ->select('article_survey.*', 'article.survey_type')
  1900. ->get()->all();
  1901. if (empty($choose)) {
  1902. return Result::error("此调查问卷不存在", 0);
  1903. }
  1904. $resultsArray = array_column($choose, 'results');
  1905. $total = array_sum($resultsArray);
  1906. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1907. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1908. // $total = 0;
  1909. if (!empty($other)) {
  1910. $total = $total + $other['results'];
  1911. $other['choice_name'] = '(其他)';
  1912. if (!empty($others)) {
  1913. $other['hasChildren'] = true;
  1914. // array_push($other,['hasChildren','=',true]);
  1915. $other['children'] = $others;
  1916. $other_choices = [$other->toArray()];
  1917. $mer_choice = array_merge($choose, $other_choices);
  1918. $value_choice = array_values($mer_choice);
  1919. } else {
  1920. // return Result::error('1111');
  1921. $other_choices = [$other->toArray()];
  1922. $other_choices = array_merge($choose, $other_choices);
  1923. $value_choice = array_values($other_choices);
  1924. // return Result::success($result);
  1925. }
  1926. } else {
  1927. $value_choice = $choose;
  1928. }
  1929. $result = [
  1930. 'choose' => $value_choice,
  1931. 'total' => $total,
  1932. ];
  1933. }
  1934. return Result::success($result);
  1935. }
  1936. /**
  1937. * 前端-搜索新闻列表
  1938. * @param array $data
  1939. * @return array
  1940. */
  1941. public function selectWebsiteArticle(array $data): array
  1942. {
  1943. $website = Website::where('id', $data['website_id'])->first();
  1944. if (empty($website)) {
  1945. return Result::error("网站不存在", 0);
  1946. }
  1947. // $website_column = $website['column'];
  1948. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1949. $website_column = json_decode($website['website_column_arr_id'], true);
  1950. }
  1951. $website_id = $data['website_id'];
  1952. $categorys = $this->processArticlePro($website_id);
  1953. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1954. // return Result::success($diff_pid_categoryIds);
  1955. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1956. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1957. }
  1958. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1959. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1960. $catiall = $categorys['catiall'];
  1961. $categoryIds = $categorys['categoryIds'];
  1962. // return Result::success($categoryIds);
  1963. $query = Article::where('status', 1)
  1964. ->whereIn('catid', $categoryIds)
  1965. ->leftJoinSub(function ($query) use ($website_id) {
  1966. $query->from('article_ignore')
  1967. ->where('website_id', $website_id);
  1968. }, 'article_ignore', function ($join) {
  1969. $join->on('article_ignore.article_id', '=', 'article.id');
  1970. })
  1971. ->where(function ($query) {
  1972. $query->whereNull('article_ignore.article_id')
  1973. ->orWhere(function ($subQuery) {
  1974. $subQuery->whereNotNull('article_ignore.article_id')
  1975. ->where('article_ignore.is_ignore', 0)
  1976. ->where(function ($subSubQuery) {
  1977. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1978. ->orWhereNull('article_ignore.c_show_time');
  1979. });
  1980. });
  1981. });
  1982. // ->get()->all();
  1983. // return Result::success($query);
  1984. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1985. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1986. }
  1987. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1988. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1989. }
  1990. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1991. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1992. }
  1993. // 计算总数
  1994. $count = $query->count();
  1995. // return Result::success($count);
  1996. // 分页查询
  1997. $articles = $query
  1998. ->select(
  1999. 'article.id',
  2000. 'article.title',
  2001. 'article.imgurl',
  2002. 'article.author',
  2003. 'article.updated_at',
  2004. 'article.introduce',
  2005. 'article.islink',
  2006. 'article.linkurl',
  2007. 'article.copyfrom',
  2008. 'article.cat_arr_id',
  2009. 'article.catid',
  2010. 'article.department_arr_id',
  2011. 'article.city_arr_id',
  2012. // 'article_ignore.c_show_time',
  2013. // 'article_ignore.is_ignore'
  2014. )
  2015. ->orderBy("updated_at", "desc")
  2016. ->offset(($data['page'] - 1) * $data['pageSize'])
  2017. ->limit($data['pageSize'])
  2018. ->get();
  2019. // return Result::success($articles);
  2020. foreach ($articles as $k => $v) {
  2021. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2022. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2023. }
  2024. if (empty($articles)) {
  2025. return Result::error("没有符合条件的资讯数据");
  2026. }
  2027. $result = [
  2028. 'rows' => $articles,
  2029. 'count' => $count,
  2030. ];
  2031. return Result::success($result);
  2032. }
  2033. /**
  2034. * 模块新闻加强版
  2035. * @param array $data
  2036. * @return array
  2037. */
  2038. public function getWebsiteCatidArticle(array $data): array
  2039. {
  2040. $where = [
  2041. 'website_category.category_id' => $data['catid'],
  2042. 'website_category.website_id' => $data['website_id'],
  2043. ];
  2044. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2045. $child_catnum = $data['child_catnum'] ?? 1;
  2046. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2047. $childCategoryIds = array_column($category['child'], 'category_id');
  2048. if (empty($childCategoryIds)) {
  2049. return Result::error("暂无子栏目", 0);
  2050. }
  2051. $imgArticles = [];
  2052. $textArticles = [];
  2053. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2054. // 初始化子分类图片新闻和文字新闻数组
  2055. // 查询所有子级栏目的图文新闻
  2056. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2057. ->where(function ($query) use ($data) {
  2058. $query->where(function ($subQuery) use ($data) {
  2059. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2060. })->orWhereNull("ignore_ids");
  2061. })
  2062. ->where('status', 1)
  2063. ->where('imgurl', '!=', '')
  2064. ->select('*')
  2065. ->orderBy('updated_at', 'desc')
  2066. ->limit($data['child_imgnum'])
  2067. ->get();
  2068. }
  2069. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2070. // 查询所有子级栏目的文字新闻
  2071. $textArticles = Article::where('catid', $childCategoryIds[0])
  2072. ->where('status', 1)
  2073. ->where(function ($query) use ($data) {
  2074. $query->where(function ($subQuery) use ($data) {
  2075. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2076. })->orWhereNull("ignore_ids");
  2077. })
  2078. ->select('*')
  2079. ->orderBy('updated_at', 'desc')
  2080. ->limit($data['child_textnum'])
  2081. ->get();
  2082. }
  2083. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2084. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2085. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2086. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2087. return $child;
  2088. }, $category['child']);
  2089. }
  2090. // }
  2091. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2092. $category['img'] = WebsiteCategory::where($where)
  2093. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2094. ->where('article.status', 1)
  2095. ->where('article.imgurl', '!=', '')
  2096. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2097. ->orderBy('article.updated_at', 'desc')
  2098. ->limit($data['img_num'])
  2099. ->get();
  2100. }
  2101. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2102. $category['text'] = WebsiteCategory::where($where)
  2103. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2104. ->where('article.status', 1)
  2105. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2106. ->orderBy('article.updated_at', 'desc')
  2107. ->limit($data['text_num'])
  2108. ->get();
  2109. }
  2110. // $category = $category->get();
  2111. if (empty($category)) {
  2112. return Result::error("查询失败", 0);
  2113. }
  2114. return Result::success($category);
  2115. }
  2116. /**
  2117. * 模块新闻加强plus版
  2118. * @param array $data
  2119. * @return array
  2120. */
  2121. public function getWebsiteAllArticle(array $data): array
  2122. {
  2123. // return Result::success($data);
  2124. $time1 = microtime(true);
  2125. $wetbsite_id = $data['website_id'] ?? 2;
  2126. $data = json_decode($data['id'], true);
  2127. $website = Website::where('id', $wetbsite_id)->first();
  2128. if (empty($website)) {
  2129. return Result::error("网站不存在", 0);
  2130. }
  2131. // return Result::success($website);
  2132. $website_column = $website['website_column_arr_id'] ?? '[]';
  2133. $website_column = json_decode($website_column, true);
  2134. $categorys = $this->processArticlePro($wetbsite_id);
  2135. $cat_1st_arr = $categorys['cat_1st_arr'];
  2136. $catiall = $categorys['catiall'];
  2137. // return Result::success($catiall);
  2138. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2139. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2140. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2141. }
  2142. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2143. // return Result::success($categorys);
  2144. $parent_category = array_column($data, 'parent');
  2145. $parent_cat = [];
  2146. $child_category = array_column($data, 'child');
  2147. if (!empty($parent_category)) {
  2148. foreach ($parent_category as $key => $value) {
  2149. $arr = array_map('intval', explode(',', $value));
  2150. $parent_cat[$key] = $arr[0] ?? 0;
  2151. $parent_category = $arr[0] ?? 0;
  2152. $article_imgnum = $arr[1] ?? 0;
  2153. $article_textnum = $arr[2] ?? 0;
  2154. if ($parent_category != 0) {
  2155. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2156. // return Result::success($category_arr);
  2157. if ($article_imgnum != 0) {
  2158. $img_article = Article::whereIn('catid', $category_arr)
  2159. ->where('status', 1)
  2160. ->where('imgurl', '!=', '')
  2161. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2162. $query->from('article_ignore')
  2163. ->where('website_id', $wetbsite_id);
  2164. }, 'article_ignore', function ($join) {
  2165. $join->on('article_ignore.article_id', '=', 'article.id');
  2166. })
  2167. ->where(function ($query) {
  2168. $query->whereNull('article_ignore.article_id')
  2169. ->orWhere(function ($subQuery) {
  2170. $subQuery->whereNotNull('article_ignore.article_id')
  2171. ->where('article_ignore.is_ignore', 0)
  2172. ->where(function ($subSubQuery) {
  2173. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2174. ->orWhereNull('article_ignore.c_show_time');
  2175. });
  2176. });
  2177. })
  2178. ->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')
  2179. ->orderBy('updated_at', 'desc')
  2180. ->limit($article_imgnum)
  2181. ->get()->all();
  2182. foreach ($img_article as $k => $v) {
  2183. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2184. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2185. }
  2186. } else {
  2187. $img_article = [];
  2188. }
  2189. if ($article_textnum != 0) {
  2190. $text_article = Article::whereIn('catid', $category_arr)
  2191. ->where('status', 1)
  2192. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2193. $query->from('article_ignore')
  2194. ->where('website_id', $wetbsite_id);
  2195. }, 'article_ignore', function ($join) {
  2196. $join->on('article_ignore.article_id', '=', 'article.id');
  2197. })
  2198. ->where(function ($query) {
  2199. $query->whereNull('article_ignore.article_id')
  2200. ->orWhere(function ($subQuery) {
  2201. $subQuery->whereNotNull('article_ignore.article_id')
  2202. ->where('article_ignore.is_ignore', 0)
  2203. ->where(function ($subSubQuery) {
  2204. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2205. ->orWhereNull('article_ignore.c_show_time');
  2206. });
  2207. });
  2208. })
  2209. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2210. ->orderBy('updated_at', 'desc')
  2211. ->limit($article_textnum)
  2212. ->get()->all();
  2213. foreach ($text_article as $k => $v) {
  2214. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2215. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2216. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2217. }
  2218. } else {
  2219. $text_article = [];
  2220. }
  2221. $catiall[$parent_category]['imgnum'] = $img_article;
  2222. $catiall[$parent_category]['textnum'] = $text_article;
  2223. $parent[$key] = $catiall[$parent_category];
  2224. } else {
  2225. $parent[$key] = '';
  2226. }
  2227. }
  2228. }
  2229. if (!empty($child_category)) {
  2230. foreach ($child_category as $key => $value) {
  2231. $arr = array_map('intval', explode(',', $value));
  2232. $parent_category = $parent_cat[$key];
  2233. $child_category = $arr[0] ?? 0;
  2234. $article_imgnum = $arr[1] ?? 0;
  2235. $article_textnum = $arr[2] ?? 0;
  2236. if ($child_category != 0) {
  2237. $all_childcat = $cat_1st_arr[$parent_category];
  2238. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2239. // 从 $websiteInfoIndexed 中获取对应的数据
  2240. $info = $websiteInfoIndexed[$v];
  2241. // 返回一个包含所需信息的数组
  2242. return [
  2243. 'alias' => $info->alias,
  2244. 'category_id' => $info->category_id,
  2245. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2246. 'pid' => $info->pid,
  2247. 'type' => $info->type,
  2248. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2249. 'pinyin' => $info->pinyin,
  2250. ];
  2251. }, $all_childcat);
  2252. if ($article_imgnum != 0) {
  2253. $img_article = Article::where('catid', $child_category)
  2254. ->where('status', 1)
  2255. ->where('imgurl', '!=', '')
  2256. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2257. $query->from('article_ignore')
  2258. ->where('website_id', $wetbsite_id);
  2259. }, 'article_ignore', function ($join) {
  2260. $join->on('article_ignore.article_id', '=', 'article.id');
  2261. })
  2262. ->where(function ($query) {
  2263. $query->whereNull('article_ignore.article_id')
  2264. ->orWhere(function ($subQuery) {
  2265. $subQuery->whereNotNull('article_ignore.article_id')
  2266. ->where('article_ignore.is_ignore', 0)
  2267. ->where(function ($subSubQuery) {
  2268. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2269. ->orWhereNull('article_ignore.c_show_time');
  2270. });
  2271. });
  2272. })
  2273. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2274. ->orderBy('updated_at', 'desc')
  2275. ->limit($article_imgnum)
  2276. ->get()->all();
  2277. foreach ($img_article as $k => $v) {
  2278. // var_dump($v);
  2279. // var_dump($k);
  2280. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2281. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2282. }
  2283. } else {
  2284. $img_article = [];
  2285. }
  2286. if ($article_textnum != 0) {
  2287. $text_article = Article::where('catid', $child_category)
  2288. ->where('status', 1)
  2289. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2290. $query->from('article_ignore')
  2291. ->where('website_id', $wetbsite_id);
  2292. }, 'article_ignore', function ($join) {
  2293. $join->on('article_ignore.article_id', '=', 'article.id');
  2294. })
  2295. ->where(function ($query) {
  2296. $query->whereNull('article_ignore.article_id')
  2297. ->orWhere(function ($subQuery) {
  2298. $subQuery->whereNotNull('article_ignore.article_id')
  2299. ->where('article_ignore.is_ignore', 0)
  2300. ->where(function ($subSubQuery) {
  2301. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2302. ->orWhereNull('article_ignore.c_show_time');
  2303. });
  2304. });
  2305. })
  2306. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2307. ->orderBy('updated_at', 'desc')
  2308. ->limit($article_textnum)
  2309. ->get()->all();
  2310. foreach ($text_article as $k => $v) {
  2311. // var_dump($v);
  2312. // var_dump($k);
  2313. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2314. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2315. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2316. }
  2317. } else {
  2318. $text_article = [];
  2319. }
  2320. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2321. $catiall[$child_category]['imgnum'] = $img_article;
  2322. $catiall[$child_category]['textnum'] = $text_article;
  2323. $child[$key] = $catiall[$child_category];
  2324. // var_dump($pids);
  2325. } else {
  2326. $child[$key] = '';
  2327. }
  2328. }
  2329. }
  2330. foreach ($parent as $key => $value) {
  2331. $result[$key] = $value;
  2332. if (!empty($child[$key])) {
  2333. // var_dump($child[$key]);
  2334. $result[$key]['child'] = $child[$key];
  2335. // $value[$key]['child'] = $child[$key];
  2336. } else {
  2337. $result[$key]['child'] = [
  2338. "alias" => null,
  2339. "category_id" => null,
  2340. "type" => null,
  2341. "pinyin" => null,
  2342. "all_childcat" => [],
  2343. "imgnum" => [],
  2344. "textnum" => []
  2345. ];
  2346. }
  2347. }
  2348. return Result::success($result);
  2349. }
  2350. /**
  2351. * 辅助方法:获取文章列表
  2352. */
  2353. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2354. {
  2355. sleep(1);
  2356. $query = Article::where('article.status', 1)
  2357. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2358. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2359. ->where(function ($query) use ($website) {
  2360. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2361. })
  2362. ->leftJoin('website_category', function ($join) use ($website) {
  2363. $join->on('article.catid', '=', 'website_category.category_id')
  2364. ->where('website_category.website_id', '=', $website['website_id']);
  2365. })
  2366. ->select(
  2367. 'article.id',
  2368. 'article.title',
  2369. 'article.imgurl',
  2370. 'article.author',
  2371. 'article.updated_at',
  2372. 'article.introduce',
  2373. 'article.islink',
  2374. 'article.linkurl',
  2375. 'article.copyfrom',
  2376. 'article.cat_arr_id',
  2377. 'article.catid',
  2378. 'website_category.alias as category_name'
  2379. )
  2380. ->orderBy('updated_at', 'desc')
  2381. ->limit($limit);
  2382. // 如果是图片文章,添加图片URL条件
  2383. if ($isImageArticle) {
  2384. $query->where('imgurl', '!=', '');
  2385. } else {
  2386. // 文字文章不需要imgurl字段
  2387. $query->addSelect('article.introduce');
  2388. }
  2389. $articles = $query->get();
  2390. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2391. }
  2392. /**
  2393. * 乡村网-获取特殊新闻模块
  2394. * @param array $data
  2395. * @return array
  2396. */
  2397. public function getWebsiteArticles(array $data): array
  2398. {
  2399. $website_id = $data['website_id'];
  2400. $website = Website::where('id', $website_id)->first();
  2401. if (empty($website)) {
  2402. return Result::error("网站不存在", 0);
  2403. }
  2404. // return Result::success($website);
  2405. $website_column = $website['website_column_arr_id'] ?? '[]';
  2406. $website_column = json_decode($website_column, true);
  2407. $catids = json_decode($data['id'], true);
  2408. $parent_category = array_column($catids, 'parent');
  2409. if (!empty($parent_category) && is_array($parent_category)) {
  2410. $categorys = $this->processArticlePro($website_id);
  2411. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2412. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2413. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2414. }
  2415. $catiall = $categorys['catiall'];
  2416. $cat_1st_arr = $categorys['cat_1st_arr'];
  2417. // return Result::success($categorys);
  2418. foreach ($parent_category as $key => $value) {
  2419. $arr = array_map('intval', explode(',', $value));
  2420. $parent_category = $arr[0] ?? 0;
  2421. $article_imgnum = $arr[1] ?? 0;
  2422. $article_textnum = $arr[2] ?? 0;
  2423. if ($parent_category != 0) {
  2424. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2425. // return Result::success($category_arr);
  2426. if ($article_imgnum != 0) {
  2427. $img_article = Article::whereIn('article.catid', $category_arr)
  2428. ->where('article.status', 1)
  2429. ->where('article.imgurl', '!=', '')
  2430. ->leftJoinSub(function ($query) use ($website_id) {
  2431. $query->from('article_ignore')
  2432. ->where('website_id', $website_id);
  2433. }, 'article_ignore', function ($join) {
  2434. $join->on('article_ignore.article_id', '=', 'article.id');
  2435. })
  2436. ->where(function ($query) {
  2437. $query->whereNull('article_ignore.article_id')
  2438. ->orWhere(function ($subQuery) {
  2439. $subQuery->whereNotNull('article_ignore.article_id')
  2440. ->where('article_ignore.is_ignore', 0)
  2441. ->where(function ($subSubQuery) {
  2442. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2443. ->orWhereNull('article_ignore.c_show_time');
  2444. });
  2445. });
  2446. })
  2447. ->select(
  2448. 'article.id',
  2449. 'article.title',
  2450. 'article.imgurl',
  2451. 'article.author',
  2452. 'article.updated_at',
  2453. 'article.introduce',
  2454. 'article.islink',
  2455. 'article.linkurl',
  2456. 'article.copyfrom',
  2457. 'article.cat_arr_id',
  2458. 'article.catid as category_id'
  2459. )
  2460. ->orderBy('updated_at', 'desc')
  2461. ->limit($article_imgnum)
  2462. ->get()->all();
  2463. foreach ($img_article as $k => $v) {
  2464. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2465. // return Result::success($v);
  2466. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2467. }
  2468. } else {
  2469. $img_article = [];
  2470. }
  2471. if ($article_textnum != 0) {
  2472. $text_article = Article::whereIn('article.catid', $category_arr)
  2473. ->where('article.status', 1)
  2474. ->leftJoinSub(function ($query) use ($website_id) {
  2475. $query->from('article_ignore')
  2476. ->where('website_id', $website_id);
  2477. }, 'article_ignore', function ($join) {
  2478. $join->on('article_ignore.article_id', '=', 'article.id');
  2479. })
  2480. ->where(function ($query) {
  2481. $query->whereNull('article_ignore.article_id')
  2482. ->orWhere(function ($subQuery) {
  2483. $subQuery->whereNotNull('article_ignore.article_id')
  2484. ->where('article_ignore.is_ignore', 0)
  2485. ->where(function ($subSubQuery) {
  2486. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2487. ->orWhereNull('article_ignore.c_show_time');
  2488. });
  2489. });
  2490. })
  2491. ->select(
  2492. 'article.id',
  2493. 'article.title',
  2494. 'article.author',
  2495. 'article.updated_at',
  2496. 'article.introduce',
  2497. 'article.islink',
  2498. 'article.linkurl',
  2499. 'article.copyfrom',
  2500. 'article.cat_arr_id',
  2501. 'article.catid as category_id'
  2502. )
  2503. ->orderBy('updated_at', 'desc')
  2504. ->limit($article_textnum)
  2505. ->get()->all();
  2506. foreach ($text_article as $k => $v) {
  2507. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2508. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2509. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2510. }
  2511. } else {
  2512. $text_article = [];
  2513. }
  2514. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2515. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2516. $parent[$key] = $catiall[$parent_category];
  2517. } else {
  2518. $parent[$key] = [];
  2519. }
  2520. }
  2521. }
  2522. return Result::success($parent);
  2523. }
  2524. // 封装处理商品的路由问题
  2525. function processGoods($goods, $data)
  2526. {
  2527. return $goods->map(function ($good) use ($data) {
  2528. $catid = $good->catid ?? 0;
  2529. // $pinyin = '';
  2530. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2531. if (!empty($category->pid) && $category->pid != 0) {
  2532. $level = json_decode($category->category_arr_id, true);
  2533. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2534. ->whereIn('category_id', $level)
  2535. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2536. ->get(['aLIas_pinyin'])
  2537. ->pluck('aLIas_pinyin')
  2538. ->implode('/');
  2539. } else {
  2540. $pinyin = $category->aLIas_pinyin ?? '';
  2541. }
  2542. if (isset($good->city_id) && !empty($good->city_id)) {
  2543. $city = District::where('id', $good->city_id)->first(['name']);
  2544. $good->city_name = $city->name ?? '';
  2545. }
  2546. // 解析imgurl JSON并取第一条数据
  2547. $imgUrls = json_decode($good->imgurl, true);
  2548. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2549. $good->pinyin = $pinyin;
  2550. return $good;
  2551. });
  2552. }
  2553. /**
  2554. * 获取商城首页-根据栏目id
  2555. * @param array $data
  2556. * @return array
  2557. * */
  2558. function getWebsiteCatidshop(array $data): array
  2559. {
  2560. $input['catid'] = $data['catid'];
  2561. $input['website_id'] = $data['website_id'];
  2562. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2563. $result = array_map(function ($item) use ($input) {
  2564. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2565. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2566. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2567. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2568. if (empty($category) || $category->type != 2) {
  2569. return Result::error("暂无此栏目", 0);
  2570. } else {
  2571. $website['website_id'] = $input['website_id'];
  2572. $goods = Good::where('good.status', 2)
  2573. ->where('good.website_id', $website['website_id'])
  2574. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2575. ->select(
  2576. 'good.id',
  2577. 'good.name',
  2578. 'good.imgurl',
  2579. 'good.description',
  2580. 'good.updated_at',
  2581. 'good.catid',
  2582. 'good.type_id',
  2583. 'good.price',
  2584. 'good.com',
  2585. 'good.level',
  2586. 'good.unit'
  2587. )
  2588. ->orderBy('updated_at', 'desc')
  2589. ->offset($goodStart)
  2590. ->limit($goodNum);
  2591. $all_goods = $goods->get();
  2592. $all_goods = $this->processGoods($all_goods, $website);
  2593. }
  2594. return $all_goods ?? [];
  2595. }
  2596. }, $data);
  2597. return Result::success($result);
  2598. }
  2599. /**
  2600. * 获取商品模块
  2601. * @param array $data
  2602. * @return array
  2603. * */
  2604. public function getWebsiteshop(array $data): array
  2605. {
  2606. $input['id'] = $data['id'];
  2607. $input['website_id'] = $data['website_id'];
  2608. $catid = $data['catid'];
  2609. $data = json_decode($input['id'] ?? '', true) ?? [];
  2610. $result['goods'] = array_map(function ($item) use ($input) {
  2611. // 检查parent元素是否存在且不是undefined
  2612. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2613. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2614. $website = $input['website_id'];
  2615. $query = Good::where('good.status', 2)
  2616. ->where('good.website_id', $website);
  2617. switch ($Levelid) {
  2618. case 1:
  2619. case 2:
  2620. case 3:
  2621. $goods = $query->where(function ($q) use ($Levelid) {
  2622. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2623. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2624. });
  2625. break;
  2626. case 4:
  2627. $goods = $query;
  2628. break;
  2629. case 5:
  2630. $goods = $query->where('type_id', 1);
  2631. break;
  2632. case 6:
  2633. $goods = $query->where('type_id', 2);
  2634. break;
  2635. default:
  2636. return [];
  2637. }
  2638. $all_goods = $goods
  2639. ->select(
  2640. 'good.id',
  2641. 'good.name',
  2642. 'good.imgurl',
  2643. 'good.description',
  2644. 'good.updated_at',
  2645. 'good.catid',
  2646. 'good.type_id',
  2647. 'good.price',
  2648. 'good.level',
  2649. 'good.website_id'
  2650. )
  2651. ->orderBy('updated_at', 'desc')
  2652. ->offset($goodStart)
  2653. ->limit($goodNum)
  2654. ->get();
  2655. $web['website_id'] = $website;
  2656. $all_goods = $this->processGoods($all_goods, $web);
  2657. }
  2658. return $all_goods;
  2659. }, $data);
  2660. $website = $input['website_id'];
  2661. $result['article'] = Article::where(function ($query) use ($website) {
  2662. $query->where(function ($subQuery) use ($website) {
  2663. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2664. })->orWhereNull("ignore_ids");
  2665. })
  2666. ->where('catid', $catid)
  2667. ->where('article.status', 1)
  2668. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2669. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2670. ->orderBy('article.updated_at', 'desc')
  2671. ->first();
  2672. return Result::success($result);
  2673. }
  2674. /**
  2675. * 获取商品分类
  2676. * @param array $data
  2677. * @return array
  2678. * */
  2679. public function getWebsiteshopCat(array $data): array
  2680. {
  2681. $website = $data['website_id'];
  2682. $category = WebsiteCategory::where('website_id', $website)
  2683. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2684. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2685. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2686. ->orderBy('sort')
  2687. ->get();
  2688. $cat = $category->map(function ($item) use ($website) {
  2689. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2690. $pid = $item->pid ?? 0;
  2691. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2692. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2693. ->where('website_id', $website)
  2694. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2695. ->get(['aLIas_pinyin'])
  2696. ->pluck('aLIas_pinyin')
  2697. ->implode('/');
  2698. } else {
  2699. $pinyin = $item->aLIas_pinyin ?? '';
  2700. }
  2701. $item->pinyin = $pinyin;
  2702. });
  2703. if (empty($category)) {
  2704. return Result::error("栏目查询失败", 0);
  2705. }
  2706. $cat_tree = Result::buildMenuTree($category);
  2707. $web['website_id'] = $website;
  2708. $goods = Good::where('website_id', $website)
  2709. ->where('status', 2)
  2710. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2711. ->latest('updated_at')
  2712. ->offset(($data['page'] - 1) * $data['pageSize'])
  2713. ->limit($data['pageSize'])
  2714. ->get();
  2715. if (!empty($goods)) {
  2716. if ($goods->count() > 1 && !empty($goods)) {
  2717. $goods = $this->processGoods($goods, $web);
  2718. }
  2719. } else {
  2720. $goods = [];
  2721. }
  2722. $result = [
  2723. 'category' => $cat_tree,
  2724. 'goods' => $goods,
  2725. ];
  2726. // $resul['goods'] = $goods;
  2727. if (empty($result)) {
  2728. return Result::error("查询失败", 0);
  2729. }
  2730. return Result::success($result);
  2731. }
  2732. /*
  2733. * 获取商品列表
  2734. * @param array $data
  2735. * @return array
  2736. * */
  2737. public function getWebsiteshopList(array $data): array
  2738. {
  2739. // return Result::success($data);
  2740. $where = [
  2741. 'status' => 2,
  2742. 'website_id' => $data['website_id'],
  2743. ];
  2744. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2745. // return Result::error("查询失败", 0);
  2746. // }
  2747. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2748. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2749. $data['catid'] = $category->category_id ?? 0;
  2750. }
  2751. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2752. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2753. }
  2754. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2755. array_push($where, ['type_id', $data['type_id']]);
  2756. }
  2757. $query = Good::where($where)
  2758. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2759. $query->where(function ($q) use ($data) {
  2760. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2761. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2762. });
  2763. })
  2764. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2765. $query->where(function ($q) use ($data) {
  2766. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2767. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2768. });
  2769. })
  2770. ->select(
  2771. 'good.id',
  2772. 'good.name',
  2773. 'good.imgurl',
  2774. 'good.description',
  2775. 'good.updated_at',
  2776. 'good.com',
  2777. 'good.catid',
  2778. 'good.type_id',
  2779. 'good.website_id',
  2780. 'good.cat_arr_id',
  2781. 'good.created_at',
  2782. 'good.city_id'
  2783. )
  2784. ->latest('updated_at');
  2785. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2786. $result['count'] = $query->clone()->count();
  2787. $result['goods'] = $this->processGoods(
  2788. $query->clone()
  2789. ->offset(($data['page'] - 1) * $data['pageSize'])
  2790. ->limit($data['pageSize'])
  2791. ->get(),
  2792. $data
  2793. );
  2794. } else {
  2795. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2796. // 获取 type_id 为 1 的数据
  2797. $result['type1'] = $this->processGoods(
  2798. $query->clone()
  2799. ->where('type_id', 1)
  2800. ->offset(($data['page'] - 1) * $data['pageSize'])
  2801. ->limit($data['pageSize'])
  2802. ->get(),
  2803. $data
  2804. );
  2805. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2806. // 获取 type_id 为 2 的数据
  2807. $result['type2'] = $this->processGoods(
  2808. $query->clone()
  2809. ->where('type_id', 2)
  2810. ->offset(($data['page'] - 1) * $data['pageSize'])
  2811. ->limit($data['pageSize'])
  2812. ->get(),
  2813. $data
  2814. );
  2815. }
  2816. if (empty($result)) {
  2817. return Result::error("查询失败", 0);
  2818. }
  2819. return Result::success($result);
  2820. }
  2821. /**
  2822. * 获取商品详情
  2823. * @param array $data
  2824. * @return array
  2825. * */
  2826. public function getWebsiteshopInfo(array $data): array
  2827. {
  2828. $where = [
  2829. 'good.status' => 2,
  2830. 'good.website_id' => $data['website_id'],
  2831. 'good.id' => $data['id'],
  2832. ];
  2833. $goods = Good::where($where)
  2834. ->where('good.id', $data['id'])
  2835. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2836. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2837. ->first();
  2838. if (empty($goods)) {
  2839. return Result::error("查询失败", 0);
  2840. }
  2841. $goods->imgurl = json_decode($goods->imgurl, true);
  2842. return Result::success($goods);
  2843. }
  2844. /**
  2845. * plus pro 处理文章路由问题
  2846. */
  2847. function processArticlePro($website_id)
  2848. {
  2849. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2850. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2851. // // 取出category_id 对应的aLIas_pinyin
  2852. // $categoryIds = array_column($categorys, 'category_id');
  2853. // $categoryPIds = array_column($categorys, 'pid');
  2854. // $aliasPinyins = array_column($categorys, 'path');
  2855. // $alias = array_column($categorys, 'alias');
  2856. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2857. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2858. // // return Result::success($cat_arr);
  2859. // // $catiall = [];
  2860. // //一级所有子级的记录
  2861. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2862. // return [
  2863. // 'cat_1st_arr' => $cat_alias_arr,
  2864. // 'catiall' => $cat_arr,
  2865. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2866. // 'categoryIds' => $categoryIds,
  2867. // ];
  2868. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2869. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2870. // 取出category_id 对应的aLIas_pinyin
  2871. $categoryIds = array_column($categorys, 'category_id');
  2872. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2873. return $pid != 0;
  2874. })));
  2875. $category_path = array_column($categorys, 'path');
  2876. $cat_arr = array_combine($categoryIds, $category_path);
  2877. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2878. $catiall = [];
  2879. //一级所有子级的记录
  2880. $cat_1st_arr = [];
  2881. foreach ($categorys as $key => $value) {
  2882. // $category_arr_id = json_decode($value->category_arr_id);
  2883. // $pinyin_str = '';
  2884. // // 算出一级 并且算出子级
  2885. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2886. $cat_1st_arr[$value->pid][] = $value->category_id;
  2887. }
  2888. // foreach ($category_arr_id as $k => $v) {
  2889. // $pinyin_str .= $cat_arr[$v] . '/';
  2890. // }
  2891. // $pinyin_str = rtrim($pinyin_str, '/');
  2892. $catiall[$value->category_id]['alias'] = $value->alias;
  2893. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2894. $catiall[$value->category_id]['type'] = $value->type;
  2895. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2896. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2897. }
  2898. return [
  2899. 'cat_1st_arr' => $cat_1st_arr,
  2900. 'catiall' => $catiall,
  2901. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2902. 'categoryIds' => $categoryIds,
  2903. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2904. 'categoryPIds' => $categoryPIds,
  2905. ];
  2906. }
  2907. /**
  2908. * 封装处理文章的路由问题
  2909. * */
  2910. function processArticles($articles, $data)
  2911. {
  2912. // 检查 $articles 是否为数组或可迭代对象
  2913. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2914. return $articles->map(function ($article) use ($data) {
  2915. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2916. $catid = $article->cat_arr_id ?? '';
  2917. }
  2918. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2919. $catid = $article->category_arr_id ?? '';
  2920. }
  2921. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2922. $level = json_decode($catid, true);
  2923. if (!is_array($level)) {
  2924. return $article;
  2925. } else {
  2926. $level = array_map('intval', $level);
  2927. }
  2928. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2929. ->where($data)
  2930. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2931. ->pluck('aLIas_pinyin')
  2932. ->implode('/');
  2933. $article->pinyin = $pinyin ?? '';
  2934. return $article;
  2935. });
  2936. } else {
  2937. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2938. $catid = $articles->cat_arr_id ?? '';
  2939. $level = json_decode($catid, true);
  2940. if (!is_array($level)) {
  2941. return $articles;
  2942. } else {
  2943. $level = array_map('intval', $level);
  2944. }
  2945. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2946. ->where($data)
  2947. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2948. ->pluck('aLIas_pinyin')
  2949. ->implode('/');
  2950. $articles->pinyin = $pinyin ?? '';
  2951. return $articles;
  2952. }
  2953. }
  2954. // 封装处理由问题
  2955. function processJob($job, $data)
  2956. {
  2957. return $job->map(function ($job) use ($data) {
  2958. $category = $job->cat_arr_id ?? '';
  2959. $cityid = $job->city_arr_id ?? '';
  2960. $city = json_decode($cityid, true);
  2961. $pinyin = '';
  2962. $level = json_decode($category, true);
  2963. // 路由
  2964. if (!empty($level) && is_array($level)) {
  2965. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2966. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2967. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2968. ->get(['aLIas_pinyin'])
  2969. ->pluck('aLIas_pinyin')
  2970. ->implode('/');
  2971. if (empty($pinyin)) {
  2972. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2973. }
  2974. $job->pinyin = $pinyin;
  2975. }
  2976. // 取职位-城市 市??省
  2977. if (!empty($city) && is_array($city)) {
  2978. if (isset($city[1]) && !empty($city[1])) {
  2979. $city = District::where('id', $city[1])->first(['name']);
  2980. $job->city_name = $city->name ?? '';
  2981. } else if (isset($city[0]) && !empty($city[0])) {
  2982. $city = District::where('id', $city[0])->first(['name']);
  2983. $job->city_name = $city->name ?? '';
  2984. } else {
  2985. $job->city_name = '全国';
  2986. }
  2987. }
  2988. // 获取简历最后一级地区
  2989. if (isset($job->city_id) && !empty($job->city_id)) {
  2990. $city = District::where('id', $job->city_id)->first(['name']);
  2991. $job->hunt_cityname = $city->name ?? '';
  2992. }
  2993. // 组合详细地址
  2994. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2995. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2996. if (is_array($address_id) && !empty($address_id)) {
  2997. $address = District::whereIn('id', $address_id)
  2998. ->orderBy('level', 'asc')
  2999. ->get(['name'])
  3000. ->pluck('name')
  3001. ->implode('');
  3002. // $job->address_name = $address ?? '';
  3003. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3004. }
  3005. }
  3006. // 取行业
  3007. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3008. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3009. if (!empty($job->industry)) {
  3010. $query->where('hyid', $job->industry);
  3011. } else if (!empty($job->hy_id)) {
  3012. $query->where('hyid', $job->hy_id);
  3013. } else if (!empty($job->company_hy_id)) {
  3014. $query->where('hyid', $job->company_hy_id);
  3015. } else {
  3016. $query->where('hyid', $job->job_industry);
  3017. }
  3018. })->first(['hyname']);
  3019. $job->hy_name = $hy_name->hyname ?? '';
  3020. }
  3021. // 取职位类别
  3022. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3023. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3024. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3025. $job->zw_name = $zw_name->zwname ?? '';
  3026. }
  3027. // 取具体职位
  3028. 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))) {
  3029. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3030. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3031. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3032. }
  3033. // 取工作经验
  3034. if (isset($job->experience) && !empty($job->experience)) {
  3035. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3036. $job->experience_name = $experience->ename ?? '';
  3037. }
  3038. // 取学历
  3039. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3040. $education = $job->educational ?? $job->school_education;
  3041. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3042. $job->education_name = $education->ename ?? '';
  3043. }
  3044. // 语言
  3045. if (isset($job->language) && !empty($job->language)) {
  3046. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3047. $job->language_name = $language->ename ?? '';
  3048. }
  3049. // 薪资
  3050. if (isset($job->salary) && !empty($job->salary)) {
  3051. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3052. $job->salary_name = $salary->ename ?? '';
  3053. }
  3054. // 职位性质
  3055. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3056. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3057. $job->job_nature_name = $job_nature->ename ?? '';
  3058. }
  3059. // 公司规模
  3060. if (isset($job->company_size) && !empty($job->company_size)) {
  3061. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3062. $job->company_size_name = $company_size->ename ?? '';
  3063. }
  3064. // 公司性质
  3065. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3066. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3067. $job->company_nature_name = $company_nature->nature_name ?? '';
  3068. }
  3069. // $job->pinyin = $pinyin;
  3070. return $job;
  3071. });
  3072. }
  3073. /**
  3074. * 获取书籍模块
  3075. * @param array $data
  3076. * @return array
  3077. * */
  3078. public function getWebsiteBook(array $data): array
  3079. {
  3080. $input['id'] = $data['id'];
  3081. $input['website_id'] = $data['website_id'];
  3082. // 将 JSON 字符串转换为 PHP 数组
  3083. $data = json_decode($input['id'], true);
  3084. // 使用 array_map 处理每个元素
  3085. $result = array_map(function ($item) use ($input) {
  3086. // 检查parent元素是否存在且不是undefined
  3087. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3088. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3089. $website = [
  3090. 'website_id' => $input['website_id'],
  3091. ];
  3092. // 查询栏目名称
  3093. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3094. if (empty($category)) {
  3095. $parent_alias = '';
  3096. $parent_pinyin = null;
  3097. $imgBooks = [];
  3098. $textBooks = [];
  3099. } else {
  3100. $parent_alias = $category->alias ?? '';
  3101. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3102. // 查找子分类ID数组
  3103. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3104. array_push($childCategoryIds, $parentCatId);
  3105. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3106. if ($parentImgNum != 0) {
  3107. // 查询图片新闻
  3108. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3109. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3110. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3111. })
  3112. ->where('book.status', 2)
  3113. ->where('book.img_url', '!=', '')
  3114. ->where('book.website_id', $website['website_id'])
  3115. ->leftJoin('website_category', function ($join) use ($website) {
  3116. $join->on('book.cat_id', '=', 'website_category.category_id')
  3117. ->where('website_category.website_id', '=', $website['website_id']);
  3118. })
  3119. ->select(
  3120. 'book.id',
  3121. 'book.title',
  3122. 'book.img_url',
  3123. 'book.price',
  3124. 'book.market_price',
  3125. 'book.description',
  3126. 'book.cat_id',
  3127. 'book.description',
  3128. 'book.updated_at',
  3129. 'website_category.alias as category_name',
  3130. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3131. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3132. )
  3133. ->orderBy('updated_at', 'desc')
  3134. ->limit($parentImgNum)
  3135. ->get()->all();
  3136. // 查询文字新闻
  3137. }
  3138. if ($parentTextNum != 0) {
  3139. $textBooks = [];
  3140. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3141. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3142. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3143. })
  3144. ->where('book.status', 2)
  3145. ->where('book.website_id', $website['website_id'])
  3146. ->leftJoin('website_category', function ($join) use ($website) {
  3147. $join->on('book.cat_id', '=', 'website_category.category_id')
  3148. ->where('website_category.website_id', '=', $website['website_id']);
  3149. })
  3150. ->select(
  3151. 'book.id',
  3152. 'book.title',
  3153. 'book.img_url',
  3154. 'book.price',
  3155. 'book.market_price',
  3156. 'book.description',
  3157. 'book.cat_id',
  3158. 'book.description',
  3159. 'book.updated_at',
  3160. 'website_category.alias as category_name',
  3161. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3162. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3163. )
  3164. ->orderBy('updated_at', 'desc')
  3165. ->limit($parentTextNum)
  3166. ->get()->all();
  3167. }
  3168. }
  3169. }
  3170. $resultItem = [
  3171. 'alias' => $parent_alias ?? '',
  3172. 'category_id' => $parentCatId ?? 0,
  3173. 'pinyin' => $parent_pinyin ?? null,
  3174. 'imgnum' => $imgBooks ?? [],
  3175. 'textnum' => $textBooks ?? [],
  3176. ];
  3177. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3178. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3179. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3180. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3181. ->get()->all();
  3182. if (!empty($childCategory)) {
  3183. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3184. // 查询子栏目名称
  3185. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3186. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3187. ->first();
  3188. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3189. $childImgArticles = [];
  3190. $childTextArticles = [];
  3191. $resultItem['child'] = [];
  3192. } else {
  3193. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3194. // 查询子栏目图片新闻
  3195. $childImgArticles = Book::where('cat_id', $childCatId)
  3196. ->where('status', 2)
  3197. ->where('img_url', '!=', '')
  3198. ->where('book.website_id', $website['website_id'])
  3199. ->leftJoin('website_category', function ($join) use ($website) {
  3200. $join->on('book.cat_id', '=', 'website_category.category_id')
  3201. ->where('website_category.website_id', '=', $website['website_id']);
  3202. })
  3203. ->select(
  3204. 'book.id',
  3205. 'book.title',
  3206. 'book.img_url',
  3207. 'book.price',
  3208. 'book.market_price',
  3209. 'book.description',
  3210. 'book.cat_id',
  3211. 'book.description',
  3212. 'book.updated_at',
  3213. DB::raw("'$child_pinyin' as pinyin")
  3214. )
  3215. ->orderBy('updated_at', 'desc')
  3216. ->limit($childImgNum)
  3217. ->get()->all();
  3218. // 查询子栏目文字新闻
  3219. $childTextArticles = Book::where('cat_id', $childCatId)
  3220. ->where('status', 2)
  3221. ->where('book.website_id', $website['website_id'])
  3222. ->leftJoin('website_category', function ($join) use ($website) {
  3223. $join->on('book.cat_id', '=', 'website_category.category_id')
  3224. ->where('website_category.website_id', '=', $website['website_id']);
  3225. })
  3226. ->select(
  3227. 'book.id',
  3228. 'book.title',
  3229. 'book.img_url',
  3230. 'book.price',
  3231. 'book.market_price',
  3232. 'book.description',
  3233. 'book.cat_id',
  3234. 'book.description',
  3235. 'book.updated_at',
  3236. DB::raw("'$child_pinyin' as pinyin")
  3237. )
  3238. ->orderBy('updated_at', 'desc')
  3239. ->limit($childTextNum)
  3240. ->get()->all();
  3241. $resultItem['child'] = [
  3242. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3243. 'category_id' => $childCatId,
  3244. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3245. 'all_childcat' => $childCategory,
  3246. 'imgnum' => $childImgArticles,
  3247. 'textnum' => $childTextArticles,
  3248. ];
  3249. }
  3250. }
  3251. } else {
  3252. $resultItem['child'] = [];
  3253. }
  3254. return $resultItem;
  3255. }, $data);
  3256. return Result::success($result);
  3257. }
  3258. /**
  3259. * 获取书刊列表
  3260. * @param array $data
  3261. * @return array
  3262. * */
  3263. public function getWebsiteBookList(array $data): array
  3264. {
  3265. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3266. if (empty($web)) {
  3267. return Result::error("查询失败", 0);
  3268. }
  3269. $catid = $data['id'];
  3270. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3271. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3272. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3273. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3274. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3275. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3276. ->where('pid', $category['pid'])
  3277. ->select(
  3278. 'category_id',
  3279. 'alias',
  3280. 'aLIas_pinyin',
  3281. 'pid',
  3282. 'sort',
  3283. 'is_url',
  3284. 'web_url',
  3285. 'seo_title',
  3286. 'seo_keywords',
  3287. 'seo_description',
  3288. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3289. )
  3290. ->orderBy('sort')
  3291. ->get()->all();
  3292. if (empty($category)) {
  3293. return Result::error("查询失败", 0);
  3294. }
  3295. $query = Book::where('book.status', 2)
  3296. ->where('book.website_id', $data['website_id'])
  3297. ->where('book.cat_id', $catid)
  3298. ->select(
  3299. 'book.id',
  3300. 'book.title',
  3301. 'book.img_url',
  3302. 'book.description',
  3303. 'book.updated_at',
  3304. 'book.cat_id',
  3305. DB::raw("'$pinyin' as pinyin")
  3306. )
  3307. ->orderBy('book.updated_at', 'desc');
  3308. $count = $query->count();
  3309. $query = clone $query;
  3310. $Book = $query
  3311. ->limit($data['pageSize'])
  3312. ->offset(($data['page'] - 1) * $data['pageSize'])
  3313. ->get()->all();
  3314. $result = [
  3315. 'category' => $categorys,
  3316. 'books' => $Book,
  3317. 'count' => $count,
  3318. ];
  3319. // if(empty($result)){
  3320. // return Result::error("查询失败", 0);
  3321. // }
  3322. return Result::success($result);
  3323. }
  3324. /**
  3325. * 获取书刊详情
  3326. * @param array $data
  3327. * @return array
  3328. * */
  3329. public function getWebsiteBookInfo(array $data): array
  3330. {
  3331. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3332. if (empty($web)) {
  3333. return Result::error("查询失败", 0);
  3334. }
  3335. $book = Book::where('status', 2)
  3336. ->where('website_id', $data['website_id'])
  3337. ->where('id', $data['id'])
  3338. ->select(
  3339. 'book.*',
  3340. )
  3341. ->orderBy('updated_at', 'desc')
  3342. ->first();
  3343. if (empty($book)) {
  3344. return Result::error("查询失败", 0);
  3345. }
  3346. // 先查询当前分类的 pid
  3347. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3348. ->where('category_id', $book['cat_id'])
  3349. ->first(['pid', 'category_id']);
  3350. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3351. if (!empty($carpid)) {
  3352. if ($carpid->pid != 0) {
  3353. $pid = $carpid['pid'];
  3354. // $parent_pinyin = '';
  3355. } else {
  3356. $pid = $carpid['category_id'];
  3357. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3358. }
  3359. }
  3360. $categorys = $query->where('pid', $pid)
  3361. ->select(
  3362. 'category_id',
  3363. 'alias',
  3364. 'aLIas_pinyin',
  3365. 'pid',
  3366. 'sort',
  3367. 'is_url',
  3368. 'web_url',
  3369. 'category_arr_id as cat_arr_id',
  3370. )
  3371. ->orderBy('sort')
  3372. ->get();
  3373. $category = $this->processArticle($categorys, $data);
  3374. $result = [
  3375. 'category' => $category,
  3376. 'books' => $book,
  3377. ];
  3378. return Result::success($result);
  3379. }
  3380. /**
  3381. * 尝试
  3382. * @param array $data
  3383. * @return array
  3384. * */
  3385. public function test(array $data): array
  3386. {
  3387. $input['id'] = $data['id'];
  3388. $input['website_id'] = $data['website_id'];
  3389. // 将 JSON 字符串转换为 PHP 数组
  3390. $data = json_decode($input['id'], true);
  3391. $result = [];
  3392. $article = $data;
  3393. $result = array_map(function ($item) use ($input) {
  3394. $website = [
  3395. 'website_id' => $input['website_id'],
  3396. ];
  3397. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3398. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3399. $parent = [
  3400. 0 => $category['category_id'] ?? [],
  3401. 1 => $parentImgNum ?? [],
  3402. 2 => $parentTextNum ?? [],
  3403. ];
  3404. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3405. $child = [];
  3406. $resultItem = [
  3407. // 'alias' => $parent_alias ?? '',
  3408. 'category_id' => $parentCatId ?? 0,
  3409. 'pinyin' => $parentImgNum ?? null,
  3410. 'imgnum' => $parentTextNum ?? [],
  3411. // 'textnum' => $textArticles ?? [],
  3412. ];
  3413. return $parent;
  3414. }, $data);
  3415. return Result::success($result);
  3416. // });
  3417. }
  3418. /**
  3419. * 封装处理文章的路由问题
  3420. * */
  3421. function processArticle($article, $data)
  3422. {
  3423. return $article->map(function ($article) use ($data) {
  3424. $catid = $article->cat_arr_id ?? '';
  3425. $level = json_decode($catid, true);
  3426. $pinyin = '';
  3427. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3428. if (!empty($level) && is_array($level)) {
  3429. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3430. ->where('website_id', $data['website_id'])
  3431. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3432. ->get(['aLIas_pinyin'])
  3433. ->pluck('aLIas_pinyin')
  3434. ->implode('/');
  3435. } else {
  3436. $pinyin = '';
  3437. }
  3438. $article->pinyin = $pinyin;
  3439. return $article;
  3440. });
  3441. }
  3442. /**
  3443. * c端-获取招工招聘下拉选框
  3444. * @param array $data
  3445. * @return array
  3446. * */
  3447. public function getWebsiteJobSelect(array $data): array
  3448. {
  3449. $web = Website::where('id', $data['website_id'])->first();
  3450. if (empty($web)) {
  3451. return Result::error("该网站不存在", 0);
  3452. }
  3453. $hy = JobIndustry::get()->all();
  3454. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3455. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3456. $result = [
  3457. 'hy' => $hy,
  3458. 'zw' => $zw,
  3459. 'jtzw' => $jtzw,
  3460. ];
  3461. if (empty($result)) {
  3462. return Result::error("查询失败", 0);
  3463. }
  3464. return Result::success($result);
  3465. }
  3466. /**
  3467. * c端-获取招工招聘
  3468. * @param array $data
  3469. * @return array
  3470. * */
  3471. public function getWebsiteJob(array $data): array
  3472. {
  3473. $web = Website::where('id', $data['website_id'])->first();
  3474. if (empty($web)) {
  3475. return Result::error("该网站不存在", 0);
  3476. }
  3477. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3478. ->where('job_hunting.website_id', $data['website_id'])
  3479. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3480. $query->where(function ($q) use ($data) {
  3481. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3482. });
  3483. })
  3484. ->select(
  3485. 'job_hunting.id',
  3486. 'job_hunting.catid',
  3487. 'job_hunting.cat_arr_id',
  3488. 'job_hunting.job_name_get',
  3489. 'job_hunting.industry',
  3490. 'job_hunting.name',
  3491. 'job_hunting.sexy',
  3492. 'job_hunting.origin',
  3493. 'job_hunting.city_arr_id',
  3494. 'job_hunting.experience',
  3495. 'job_hunting.updated_at',
  3496. 'job_hunting.salary',
  3497. 'job_hunting.skillList',
  3498. 'job_hunting.slelf_evaluation',
  3499. )
  3500. ->orderBy('updated_at', 'desc')
  3501. ->limit($data['job1_num'])
  3502. ->get();
  3503. $web['website_id'] = $data['website_id'];
  3504. if (empty($job_hunting)) {
  3505. $job_huntings = "未查询到相关简历信息";
  3506. } else {
  3507. $job_huntings = $this->processJob($job_hunting, $web);
  3508. }
  3509. // 0:待审核 1:已通过 2:已拒绝
  3510. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3511. ->where('job_recruiting.website_id', $data['website_id'])
  3512. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3513. $query->where(function ($q) use ($data) {
  3514. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3515. });
  3516. })
  3517. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3518. ->select(
  3519. 'job_recruiting.id',
  3520. 'job_recruiting.catid',
  3521. 'job_recruiting.cat_arr_id',
  3522. 'job_recruiting.title',
  3523. 'job_recruiting.jtzw_id',
  3524. 'job_recruiting.hy_id',
  3525. 'job_recruiting.city_arr_id',
  3526. 'job_recruiting.due_data',
  3527. 'job_recruiting.updated_at',
  3528. 'job_recruiting.experience',
  3529. 'job_recruiting.educational',
  3530. 'job_recruiting.salary',
  3531. 'job_recruiting.zw_id',
  3532. 'job_company.business_name',
  3533. 'job_recruiting.keyword',
  3534. 'job_recruiting.description',
  3535. )
  3536. ->orderBy('updated_at', 'desc')
  3537. ->limit($data['job2_num'])
  3538. ->get();
  3539. if (empty($job_recruiting->toArray())) {
  3540. $job_recruitings = "未查询到相关职位信息";
  3541. } else {
  3542. $job_recruitings = $this->processJob($job_recruiting, $web);
  3543. }
  3544. $result = [
  3545. 'job_hunting' => $job_huntings,
  3546. 'job_recuiting' => $job_recruitings,
  3547. ];
  3548. return Result::success($result);
  3549. }
  3550. /**
  3551. * c端-获取招工招聘列表
  3552. * @param array $data
  3553. * @return array
  3554. * */
  3555. public function getWebsiteJobList(array $data): array
  3556. {
  3557. $recruit_where = [];
  3558. $hunt_where = [];
  3559. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3560. if (empty($web)) {
  3561. return Result::error("此网站不存在", 0);
  3562. }
  3563. $website_id['website_id'] = $data['website_id'];
  3564. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3565. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3566. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3567. }
  3568. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3569. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3570. }
  3571. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3572. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3573. }
  3574. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3575. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3576. }
  3577. $query = JobRecruiting::where('job_recruiting.status', 1)
  3578. ->where('job_recruiting.website_id', $data['website_id'])
  3579. ->where($recruit_where)
  3580. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3581. $query->where(function ($q) use ($data) {
  3582. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3583. });
  3584. })
  3585. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3586. $query->where(function ($q) use ($data) {
  3587. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3588. });
  3589. })
  3590. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3591. ->select(
  3592. 'job_recruiting.id',
  3593. 'job_recruiting.catid',
  3594. 'job_recruiting.hy_id',
  3595. 'job_recruiting.title',
  3596. 'job_recruiting.zw_id',
  3597. 'job_recruiting.educational',
  3598. 'job_recruiting.jtzw_id',
  3599. 'job_recruiting.city_arr_id',
  3600. 'job_recruiting.due_data',
  3601. 'job_recruiting.experience',
  3602. 'job_recruiting.cat_arr_id',
  3603. 'job_recruiting.updated_at',
  3604. 'job_company.business_name',
  3605. 'job_recruiting.keyword',
  3606. 'job_recruiting.description',
  3607. )
  3608. ->orderBy('job_recruiting.updated_at', 'desc');
  3609. $recruit_count = $query->count();
  3610. $query = clone $query;
  3611. $JobRecruiting = $query
  3612. ->offset(($data['page'] - 1) * $data['pageSize'])
  3613. ->limit($data['pageSize'])
  3614. ->get();
  3615. if (empty($JobRecruiting)) {
  3616. $JobRecruiting = "暂无相关职位信息";
  3617. } else {
  3618. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3619. }
  3620. }
  3621. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3622. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3623. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3624. }
  3625. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3626. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3627. }
  3628. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3629. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3630. }
  3631. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3632. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3633. }
  3634. $query = JobHunting::where('job_hunting.status', 2)
  3635. ->where('job_hunting.website_id', $data['website_id'])
  3636. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3637. ->where($hunt_where)
  3638. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3639. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3640. // })
  3641. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3642. $query->where(function ($q) use ($data) {
  3643. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3644. });
  3645. })
  3646. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3647. $query->where(function ($q) use ($data) {
  3648. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3649. });
  3650. })
  3651. ->select(
  3652. 'job_hunting.id',
  3653. 'job_hunting.catid',
  3654. 'job_hunting.sexy',
  3655. 'job_hunting.experience',
  3656. 'job_hunting.origin',
  3657. 'job_hunting.industry',
  3658. 'job_hunting.name',
  3659. 'job_hunting.job',
  3660. 'job_hunting.job_name_get',
  3661. 'job_hunting.city_arr_id',
  3662. 'job_hunting.cat_arr_id',
  3663. 'job_hunting.created_at',
  3664. 'job_hunting.updated_at',
  3665. 'job_position.zwname as job_name',
  3666. 'job_hunting.skillList',
  3667. 'job_hunting.slelf_evaluation',
  3668. )
  3669. ->orderBy('job_hunting.updated_at', 'desc');
  3670. $hunt_count = $query->count();
  3671. $query = clone $query;
  3672. $JobHunting = $query
  3673. ->offset(($data['page'] - 1) * $data['pageSize'])
  3674. ->limit($data['pageSize'])
  3675. ->get();
  3676. if (empty($JobHunting)) {
  3677. $JobRecruiting = "暂无相关简历信息";
  3678. } else {
  3679. $JobHunting = $this->processJob($JobHunting, $website_id);
  3680. }
  3681. }
  3682. $result = [
  3683. 'JobRecruiting' => $JobRecruiting ?? [],
  3684. 'recruit_count' => $recruit_count ?? 0,
  3685. 'JobHunting' => $JobHunting ?? [],
  3686. 'hunt_count' => $hunt_count ?? 0,
  3687. ];
  3688. return Result::success($result);
  3689. }
  3690. /**
  3691. * c端-获取招工招聘详情
  3692. * @param array $data
  3693. * @return array
  3694. * */
  3695. public function getWebsiteJobInfo(array $data): array
  3696. {
  3697. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3698. if (empty($web)) {
  3699. return Result::error("该网站不存在", 0);
  3700. }
  3701. $webid = [
  3702. 'website_id' => $data['website_id'],
  3703. ];
  3704. // 职位相关信息
  3705. if ($data['type'] == 1) {
  3706. $query = JobRecruiting::where('status', 1)
  3707. ->where('website_id', $data['website_id'])
  3708. ->select('*');
  3709. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3710. $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();
  3711. if (!empty($company)) {
  3712. $result['company'] = $this->processJob($company, $webid);
  3713. }
  3714. $other_job = JobRecruiting::where('status', 1)
  3715. ->where('website_id', $data['website_id'])
  3716. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3717. ->where('id', '!=', $data['id'])
  3718. ->where('user_id', '=', $job[0]['user_id'])
  3719. ->limit($data['pageSize'])
  3720. ->get();
  3721. if (!empty($other_job)) {
  3722. $result['other_job'] = $this->processJob($other_job, $webid);
  3723. }
  3724. } else {
  3725. // 简历相关信息
  3726. $job = JobHunting::where('job_hunting.status', 2)
  3727. ->where('job_hunting.website_id', $data['website_id'])
  3728. ->where('job_hunting.id', $data['id'])
  3729. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3730. ->select('job_hunting.*', 'user_name')
  3731. ->get();
  3732. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3733. if (!empty($resume->toArray())) {
  3734. $result['resume'] = 1;
  3735. } else {
  3736. $result['resume'] = 0;
  3737. }
  3738. }
  3739. if (empty($job->toArray())) {
  3740. return Result::error("id参数错误", 0);
  3741. }
  3742. if (!empty($job[0]['job_experience'])) {
  3743. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3744. if (!empty($job_experience)) {
  3745. // $hy = [];
  3746. foreach ($job_experience as $key => $value) {
  3747. // $id = $value['id'];
  3748. $hy[$key] = $value['job_industry'];
  3749. $zw_id[$key] = $value['job_typename'];
  3750. $jtzw_id[$key] = $value['job_name'];
  3751. }
  3752. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3753. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3754. // 先将关联表转换为索引数组,提高查找效率
  3755. $hyLookup = [];
  3756. foreach ($hy_table as $item) {
  3757. $hyLookup[$item['hyid']] = $item['hyname'];
  3758. }
  3759. $zwLookup = [];
  3760. foreach ($zw_table as $item) {
  3761. $zwLookup[$item['zwid']] = $item['zwname'];
  3762. }
  3763. foreach ($job_experience as $key => &$value) {
  3764. // 处理行业名称
  3765. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3766. $value['hy_name'] = $hyLookup[$hy[$key]];
  3767. }
  3768. // 处理职位名称
  3769. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3770. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3771. }
  3772. // 处理具体职位名称
  3773. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3774. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3775. }
  3776. }
  3777. // 释放引用,防止意外修改后续代码
  3778. unset($value);
  3779. }
  3780. $result['job_experience'] = $job_experience ?? [];
  3781. }
  3782. if (!empty($job[0]['education_experience'])) {
  3783. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3784. if (!empty($education_experience)) {
  3785. foreach ($education_experience as $key => $value) {
  3786. // $id = $value['id'];
  3787. $education[$key] = $value['school_education'];
  3788. }
  3789. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3790. // // 先将关联表转换为索引数组,提高查找效率
  3791. $educationLookup = [];
  3792. foreach ($education_table as $item) {
  3793. $educationLookup[$item['evalue']] = $item['ename'];
  3794. }
  3795. foreach ($education_experience as $key => &$value) {
  3796. // 处理学历名称
  3797. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3798. $value['education_name'] = $educationLookup[$education[$key]];
  3799. }
  3800. }
  3801. }
  3802. $result['education_experience'] = $job_experience ?? [];
  3803. }
  3804. $result['job'] = $this->processJob($job, $webid);
  3805. // // 返现对应的栏目
  3806. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3807. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3808. ->whereIn('category_id', $catid)
  3809. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3810. ->orderBy('pid')->get()->all();
  3811. if (!empty($category)) {
  3812. $result['category'] = $category;
  3813. }
  3814. $result['job'] = $job;
  3815. $result['job_experience'] = $job_experience ?? [];
  3816. $result['education_experience'] = $education_experience ?? [];
  3817. if (empty($result)) {
  3818. return Result::error("参数错误", 0);
  3819. }
  3820. return Result::success($result);
  3821. }
  3822. /**
  3823. * c端-申请职位
  3824. * @param array $data
  3825. * @return array
  3826. * */
  3827. public function getWebsiteJobApply(array $data): array
  3828. {
  3829. // 首先验证网站是否存在
  3830. // return Result::success($data);
  3831. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3832. if (empty($web)) {
  3833. return Result::error("该网站不存在", 0);
  3834. }
  3835. // 验证用户是否存在且为个人会员/管理员
  3836. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3837. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3838. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3839. return Result::error("用户不存在", 0);
  3840. }
  3841. // 去除重复元素和空元素,并保持原始顺序
  3842. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3843. return !empty($value);
  3844. }));
  3845. // 验证职位是否存在 1:审核通过
  3846. $recruiting = JobRecruiting::where('status', 1)
  3847. ->where('website_id', $data['website_id'])
  3848. ->whereIn('id', $data['recruit_id'])
  3849. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3850. if (empty($recruiting)) {
  3851. return Result::error("该职位不存在", 0);
  3852. }
  3853. // 简历是否存在
  3854. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3855. if (empty($hunt_id)) {
  3856. return Result::error("该简历不存在", 0);
  3857. }
  3858. $data['hunt_id'] = $hunt_id['hunt_id'];
  3859. // // 验证是否已投递过该职位
  3860. $apply = JobApply::where('user_id', $data['user_id'])
  3861. ->where('hunt_id', $data['hunt_id'])
  3862. ->where('website_id', $data['website_id'])
  3863. ->whereIn('recruit_id', $data['recruit_id'])
  3864. ->get(['recruit_id']);
  3865. if (!empty($apply->toArray())) {
  3866. return Result::error("您已投递过该职位!");
  3867. }
  3868. $insertData = array_map(function ($recruiting) use ($data) {
  3869. return [
  3870. 'user_id' => $data['user_id'],
  3871. 'hunt_id' => $data['hunt_id'],
  3872. 'website_id' => $data['website_id'],
  3873. 'recruit_id' => $recruiting['recruit_id'],
  3874. 'receiver_id' => $recruiting['receiver_id'],
  3875. 'status' => 1,
  3876. ];
  3877. }, $recruiting);
  3878. // 批量插入数据
  3879. $result = JobApply::insert($insertData);
  3880. if (empty($result)) {
  3881. return Result::error("投递失败", 0);
  3882. }
  3883. return Result::success($result);
  3884. }
  3885. /**
  3886. * 招工招聘-沟通简历
  3887. * @param array $data
  3888. * @return array
  3889. * */
  3890. public function getWebsiteJobResume(array $data): array
  3891. {
  3892. // 首先验证网站是否存在
  3893. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3894. if (empty($web)) {
  3895. return Result::error("该网站不存在", 0);
  3896. }
  3897. // return Result::success($data);
  3898. // 验证用户是否存在且为企业会员/管理员
  3899. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3900. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3901. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3902. return Result::error("用户不存在", 0);
  3903. }
  3904. // 去除重复元素和空元素,并保持原始顺序
  3905. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3906. return !empty($value);
  3907. }));
  3908. // 验证简历是否存在
  3909. $hunting = JobHunting::where('status', 2)
  3910. ->where('website_id', $data['website_id'])
  3911. ->whereIn('id', $data['hunt_id'])
  3912. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3913. if (empty($hunting)) {
  3914. return Result::error("该简历不存在", 0);
  3915. }
  3916. // 验证是否已沟通过该简历
  3917. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3918. ->where('recruit_id', $data['recruit_id'])
  3919. ->where('website_id', $data['website_id'])
  3920. ->whereIn('hunt_id', $data['hunt_id'])
  3921. ->get(['hunt_id']);
  3922. if (!empty($remuse->toArray())) {
  3923. return Result::error("您已沟通过该简历!");
  3924. }
  3925. // 准备要插入的数据数组
  3926. $insertData = array_map(function ($hunting) use ($data) {
  3927. return [
  3928. 'user_id' => $data['user_id'],
  3929. 'recruit_id' => $data['recruit_id'],
  3930. 'website_id' => $data['website_id'],
  3931. 'hunt_id' => $hunting['hunt_id'],
  3932. 'receiver_id' => $hunting['receiver_id'],
  3933. 'status' => 1,
  3934. ];
  3935. }, $hunting);
  3936. // 批量插入数据
  3937. $result = JobRemuse::insert($insertData);
  3938. if (empty($result)) {
  3939. return Result::error("沟通失败", 0);
  3940. }
  3941. return Result::success($result);
  3942. }
  3943. /**
  3944. * 招工招聘 -我的职位(企业会员)
  3945. * @param array $data
  3946. * @return array
  3947. */
  3948. public function getWebsiteJobRecruiting(array $data): array
  3949. {
  3950. $web = Website::where('id', $data['website_id'])->first('id');
  3951. if (empty($web)) {
  3952. return Result::error("该网站不存在", 0);
  3953. }
  3954. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3955. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3956. return Result::error("用户暂无权限!", 0);
  3957. }
  3958. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3959. $result = JobRecruiting::where('website_id', $data['website_id'])
  3960. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3961. $query->where('user_id', $user['id']);
  3962. })
  3963. ->where('status', 1)
  3964. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3965. ->orderBy('updated_at', 'desc')
  3966. ->limit($data['pageSize'])
  3967. ->get();
  3968. if (empty($result)) {
  3969. return Result::error("暂无相关职位信息", 0);
  3970. }
  3971. return Result::success($result);
  3972. }
  3973. /**
  3974. * c端 - 验证路由
  3975. * @param array $data
  3976. * @return array
  3977. */
  3978. /**
  3979. * c端 - 验证路由
  3980. * @param array $data
  3981. * @return array
  3982. */
  3983. public function checkWebsiteRoute(array $data): array
  3984. {
  3985. // 测试001111111222
  3986. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3987. if (empty($web)) {
  3988. return Result::error("该网站不存在", 0);
  3989. } elseif ($web['status'] != 1) {
  3990. return Result::error("网站已经关闭", 0);
  3991. }
  3992. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3993. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3994. // 验证路由是否存在
  3995. if (empty($whiteRouterInfo)) {
  3996. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3997. }
  3998. if (!empty($whiteRouterInfo)) {
  3999. return Result::success($whiteRouterInfo->toArray());
  4000. }
  4001. }
  4002. // 验证栏目路由
  4003. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4004. ->where('path', $data['all_route'])
  4005. ->get()->all();
  4006. if (count($last_category) == 0) {
  4007. return Result::error("该栏目不存在", 0);
  4008. }
  4009. if (count($last_category) > 1) {
  4010. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4011. }
  4012. if (count($last_category) == 1) {
  4013. $last_category = $last_category[0];
  4014. }
  4015. // return Result::success($last_category);
  4016. if (isset($data['id']) && !empty($data['id'])) {
  4017. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4018. switch ($last_category['type']) {
  4019. case 1:
  4020. // 文章
  4021. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4022. $article = Article::where('status', 1)
  4023. ->where('id', $data['id'])
  4024. ->where(function ($query) use ($data) {
  4025. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4026. ->orWhereNull("ignore_ids");
  4027. })
  4028. ->first(['catid']);
  4029. if (empty($article)) {
  4030. return Result::error("该文章不存在", 0);
  4031. }
  4032. // return Result::success($article);
  4033. break;
  4034. case 2:
  4035. // 商品
  4036. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4037. $article = Good::where('website_id', $data['website_id'])
  4038. ->where('status', 2)
  4039. ->where('id', $data['id'])
  4040. ->first(['cat_arr_id']);
  4041. if (empty($article)) {
  4042. return Result::error("该商品不存在", 0);
  4043. }
  4044. break;
  4045. case 3:
  4046. // 书刊信息
  4047. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4048. $article = Book::where('website_id', $data['website_id'])
  4049. ->where('status', 2)
  4050. ->where('id', $data['id'])
  4051. ->first(['id', 'cat_arr_id']);
  4052. if (empty($article)) {
  4053. return Result::error("该书刊不存在", 0);
  4054. }
  4055. break;
  4056. case 4:
  4057. // 招聘
  4058. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4059. $article = JobRecruiting::where('website_id', $data['website_id'])
  4060. ->where('status', 1)
  4061. ->where('id', $data['id'])
  4062. ->first(['cat_arr_id']);
  4063. if (empty($article)) {
  4064. return Result::error("该招聘不存在", 0);
  4065. }
  4066. break;
  4067. case 5:
  4068. // 求职
  4069. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4070. $article = JobHunting::where('website_id', $data['website_id'])
  4071. ->where('status', 2)
  4072. ->where('id', $data['id'])
  4073. ->first(['cat_arr_id']);
  4074. if (empty($article)) {
  4075. return Result::error("该求职不存在", 0);
  4076. }
  4077. break;
  4078. case 6:
  4079. // 企业
  4080. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4081. $article = Company::
  4082. // where('website_id', $data['website_id'])
  4083. // ->
  4084. where('status', 1)
  4085. ->where('id', $data['id'])
  4086. ->first(['cat_arr_id']);
  4087. if (empty($article)) {
  4088. return Result::error("该企业不存在", 0);
  4089. }
  4090. break;
  4091. case 7:
  4092. // 项目
  4093. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4094. $article = Project::where('website_id', $data['website_id'])
  4095. ->where('status', 1)
  4096. ->where('id', $data['id'])
  4097. ->first(['cat_arr_id']);
  4098. if (empty($article)) {
  4099. return Result::error("该项目不存在", 0);
  4100. }
  4101. break;
  4102. default:
  4103. return Result::error("该数据不存在", 0);
  4104. break;
  4105. }
  4106. // return Result::success($article);
  4107. // $catid =0 ;
  4108. if (!isset($article['cat_arr_id'])) {
  4109. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4110. } else {
  4111. $catidArray = json_decode($article['cat_arr_id'], true);
  4112. $catid = !empty($catidArray) ? end($catidArray) : null;
  4113. }
  4114. // return Result::success($catid);
  4115. // // return Result::success($article['cat_arr_id']);
  4116. if (empty($catid)) {
  4117. return Result::error("该栏目路径不存在", 0);
  4118. }
  4119. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4120. ->where('category_id', $catid)
  4121. ->first('path');
  4122. }
  4123. // else{
  4124. // // if ($last_category['pid'] != 0) {
  4125. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4126. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4127. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4128. // ->where('category_id',$catid)
  4129. // ->where('path',$data['all_route'])
  4130. // ->first('path');
  4131. // // } else {
  4132. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4133. // // }
  4134. // }
  4135. // return Result::success($path);
  4136. if (!empty($path) && $path['path'] != $data['all_route']) {
  4137. return Result::error('非法路径!');
  4138. } else {
  4139. return Result::success($last_category['path']);
  4140. }
  4141. }
  4142. /**
  4143. * 招工招聘 - 获取推荐职位
  4144. * @param array $data
  4145. * @return array
  4146. */
  4147. public function getWebsiteLevelJob(array $data): array
  4148. {
  4149. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4150. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4151. ->where('job_recruiting.status', 1)
  4152. ->where('job_level', $data['job_level'])
  4153. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4154. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4155. ->orderBy('job_recruiting.updated_at', 'desc')
  4156. ->limit($data['pageSize'])
  4157. ->get();
  4158. $web = ['website_id' => $data['website_id']];
  4159. if (!empty($job)) {
  4160. $result = $this->processJob($job, $web);
  4161. }
  4162. if (empty($result)) {
  4163. return Result::error("暂无相关职位信息", 0);
  4164. }
  4165. return Result::success($result);
  4166. }
  4167. /**
  4168. * 验证导航名称是否重复
  4169. * @return void
  4170. */
  4171. //20250226 产品列表
  4172. public function getGoodList(array $data): array
  4173. {
  4174. var_dump($data, '---------1-2--');
  4175. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4176. unset($data['user_type_id']);
  4177. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4178. $where = [];
  4179. if ($type_id != '10000') {
  4180. $where = [
  4181. 'good.user_id' => $user_id,
  4182. ];
  4183. }
  4184. //类型
  4185. if (isset($data['type_id']) && $data['type_id']) {
  4186. $where['good.type_id'] = $data['type_id'];
  4187. }
  4188. //名称
  4189. if (isset($data['name']) && $data['name']) {
  4190. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4191. }
  4192. //status
  4193. if (isset($data['status']) && $data['status'] != '') {
  4194. $where['good.status'] = $data['status'];
  4195. }
  4196. //status1
  4197. // if (isset($data['status1']) && $data['status1'] == 1) {
  4198. // $status1 = 1;
  4199. // }
  4200. $where1 = [];
  4201. //website_id
  4202. // if (isset($data['website_id']) && $data['website_id']) {
  4203. // $where1 = [
  4204. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4205. // ];
  4206. // }
  4207. // website_name
  4208. if (isset($data['website_name']) && $data['website_name']) {
  4209. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4210. }
  4211. // catid
  4212. if (isset($data['category_name']) && $data['category_name']) {
  4213. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4214. }
  4215. // $result = Good::where($where)
  4216. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4217. var_dump($where, '---------1---');
  4218. $result = Good::where($where)
  4219. ->when(!empty($where1), function ($query) use ($where1) {
  4220. return $query->where($where1);
  4221. })
  4222. //status 1待审核2已审核3已拒绝
  4223. ->when(isset($data['status1']), function ($query) {
  4224. return $query->whereIn('good.status', [1, 3]);
  4225. })
  4226. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4227. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4228. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4229. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4230. ->orderBy("updated_at", "desc")
  4231. ->limit($data['page_size'])
  4232. ->offset(($data['page'] - 1) * $data['page_size'])
  4233. ->get();
  4234. $count = Good::where($where)
  4235. ->when(!empty($where1), function ($query) use ($where1) {
  4236. return $query->where($where1);
  4237. })
  4238. //status 1待审核2已审核3已拒绝
  4239. ->when(isset($data['status1']), function ($query) {
  4240. return $query->whereIn('good.status', [1, 3]);
  4241. })
  4242. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4243. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4244. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4245. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4246. ->orderBy("updated_at", "desc")->count();
  4247. $data = [
  4248. 'rows' => $result->toArray(),
  4249. 'count' => $count,
  4250. ];
  4251. if (empty($result)) {
  4252. return Result::error("此栏目暂无相关产品", 0);
  4253. }
  4254. return Result::success($data);
  4255. }
  4256. public function getGoodInfo(array $data): array
  4257. {
  4258. $result = Good::where('id', $data['id'])->first();
  4259. if (empty($result)) {
  4260. return Result::error("此产品不存在", 0);
  4261. }
  4262. return Result::success($result);
  4263. }
  4264. public function addGood(array $data): array
  4265. {
  4266. // unset($data['city_arr_id']);
  4267. // unset($data['cat_arr_id']);
  4268. $data['city_id'] = end($data['city_arr_id']);
  4269. $data['catid'] = end($data['cat_arr_id']);
  4270. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4271. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4272. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4273. unset($data['imgUrl']); //大小写
  4274. if (isset($data['price']) && $data['price'] == '') {
  4275. $data['price'] = 0;
  4276. }
  4277. if ($data['imgurl'] == '') {
  4278. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4279. preg_match_all($reg, $data['detail'], $matches);
  4280. if (isset($matches[1][0])) {
  4281. //截取varchar240
  4282. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4283. }
  4284. }
  4285. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4286. //提取标题+内容中的关键词
  4287. $data['keyword'] = $data['name'];
  4288. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4289. Jieba::init(); // 初始化 jieba-php
  4290. Finalseg::init();
  4291. $segList = Jieba::cut($data['keyword']);
  4292. $segList1 = array_slice($segList, 0, 8);
  4293. $data['keyword'] = implode(',', $segList1);
  4294. }
  4295. if ($data['description'] == '') {
  4296. //提取内容中的描述
  4297. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4298. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4299. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4300. }
  4301. if ($data['status'] == 1) {
  4302. $this->sendMessage([
  4303. 'talk_type' => 200,
  4304. 'title' => $data['name'],
  4305. 'content' => '提交了审核',
  4306. 'messageType' => 3,
  4307. ]);
  4308. }
  4309. $result = Good::insert($data);
  4310. if (empty($result)) {
  4311. return Result::error("添加失败", 0);
  4312. }
  4313. return Result::success($result);
  4314. }
  4315. public function updateGood(array $data): array
  4316. {
  4317. $data['city_id'] = end($data['city_arr_id']);
  4318. $data['catid'] = end($data['cat_arr_id']);
  4319. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4320. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4321. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4322. //设置东八区
  4323. date_default_timezone_set('Asia/Shanghai');
  4324. $data['updated_at'] = date('Y-m-d H:i:s');
  4325. if (isset($data['price']) && $data['price'] == '') {
  4326. $data['price'] = 0;
  4327. }
  4328. if ($data['imgurl'] == '') {
  4329. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4330. preg_match_all($reg, $data['detail'], $matches);
  4331. if (isset($matches[1][0])) {
  4332. //截取varchar240
  4333. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4334. }
  4335. }
  4336. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4337. //提取标题+内容中的关键词
  4338. $data['keyword'] = $data['name'];
  4339. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4340. Jieba::init(); // 初始化 jieba-php
  4341. Finalseg::init();
  4342. $segList = Jieba::cut($data['keyword']);
  4343. $segList1 = array_slice($segList, 0, 8);
  4344. $data['keyword'] = implode(',', $segList1);
  4345. }
  4346. if ($data['description'] == '') {
  4347. //提取内容中的描述
  4348. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4349. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4350. }
  4351. if ($data['status'] == 1) {
  4352. $this->sendMessage([
  4353. 'talk_type' => 200,
  4354. 'title' => $data['name'],
  4355. 'content' => '提交了审核',
  4356. 'messageType' => 3,
  4357. ]);
  4358. }
  4359. $result = Good::where('id', $data['id'])->update($data);
  4360. if (empty($result)) {
  4361. return Result::error("更新失败", 0);
  4362. }
  4363. return Result::success($result);
  4364. }
  4365. public function delGood(array $data): array
  4366. {
  4367. $result = Good::where('id', $data['id'])->delete();
  4368. if (empty($result)) {
  4369. return Result::error("删除失败", 0);
  4370. }
  4371. return Result::success($result);
  4372. }
  4373. //20250226 产品列表
  4374. //20250306 求职信息
  4375. public function getJobHuntingList(array $data): array
  4376. {
  4377. $where = [];
  4378. if (isset($data['username']) && !empty($data['username'])) {
  4379. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4380. }
  4381. //status 1待审核2已审核3已拒绝
  4382. if (isset($data['status']) && $data['status'] != '') {
  4383. $where = [
  4384. 'job_hunting.status' => $data['status'],
  4385. ];
  4386. }
  4387. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4388. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4389. unset($data['type_id']);
  4390. if ($type_id != '10000') {
  4391. $where[] = ['job_hunting.user_id', '=', $user_id];
  4392. }
  4393. $result = JobHunting::where($where)
  4394. ->when(!empty($data['status1']), function ($query) use ($data) {
  4395. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4396. })
  4397. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4398. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4399. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4400. ->orderBy("updated_at", "desc")
  4401. ->limit($data['page_size'])
  4402. ->offset(($data['page'] - 1) * $data['page_size'])
  4403. ->get();
  4404. if (empty($result)) {
  4405. return Result::error("查询失败", 0);
  4406. }
  4407. $count = JobHunting::where($where)
  4408. ->when(!empty($data['status1']), function ($query) use ($data) {
  4409. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4410. })
  4411. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4412. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4413. ->count();
  4414. $data = [
  4415. 'rows' => $result->toArray(),
  4416. 'count' => $count,
  4417. ];
  4418. return Result::success($data);
  4419. }
  4420. public function getJobHuntingApply(array $data): array
  4421. {
  4422. var_dump($data, '-----------------test--------1-');
  4423. $where = [];
  4424. if (isset($data['username']) && !empty($data['username'])) {
  4425. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4426. }
  4427. if (isset($data['salary']) && !empty($data['salary'])) {
  4428. $where[] = [
  4429. 'job_hunting.salary',
  4430. '=',
  4431. $data['salary'],
  4432. ];
  4433. }
  4434. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4435. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4436. unset($data['type_id']);
  4437. if ($type_id != '10000') {
  4438. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4439. }
  4440. var_dump($where, '-----------------test---------');
  4441. $result = jobApply::where($where)
  4442. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4443. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4444. // })
  4445. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4446. ->where('job_enum.egroup', '=', 'income')
  4447. ->where('job_hunting.status', 2) //已审核
  4448. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4449. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4450. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4451. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4452. //职位----是申请职位
  4453. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4454. ->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')
  4455. ->orderBy("job_hunting.updated_at", "desc")
  4456. ->limit($data['page_size'])
  4457. ->offset(($data['page'] - 1) * $data['page_size'])
  4458. ->get();
  4459. if (empty($result)) {
  4460. return Result::error("查询失败", 0);
  4461. }
  4462. $count = jobApply::where($where)
  4463. ->where('job_enum.egroup', '=', 'income')
  4464. ->where('job_hunting.status', 2) //已审核
  4465. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4466. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4467. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4468. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4469. //职位----是申请职位
  4470. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4471. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  4472. ->count();
  4473. $data = [
  4474. 'rows' => $result->toArray(),
  4475. 'count' => $count,
  4476. ];
  4477. return Result::success($data);
  4478. }
  4479. public function addJobHunting(array $data): array
  4480. {
  4481. date_default_timezone_set('Asia/Shanghai');
  4482. unset($data['company_name']);
  4483. unset($data['job_industry']);
  4484. unset($data['job_name']);
  4485. unset($data['department']);
  4486. unset($data['job_timeList']);
  4487. unset($data['job_content']);
  4488. unset($data['job_typename']); //不知道这是啥,
  4489. $data['created_at'] = date('Y-m-d H:i:s');
  4490. $data['updated_at'] = date('Y-m-d H:i:s');
  4491. //根据用户 user_id 只能添加一次
  4492. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4493. if (!empty($result)) {
  4494. return Result::error("您已添加过求职信息", 0);
  4495. }
  4496. var_dump($result, '-----------------test---------');
  4497. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4498. if (is_string($data['city_arr_id'])) {
  4499. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4500. $cityArr = json_decode($data['city_arr_id'], true);
  4501. // 确保 $cityArr 是数组
  4502. if (is_array($cityArr)) {
  4503. $data['city_id'] = end($cityArr);
  4504. }
  4505. } else {
  4506. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4507. if (is_array($data['city_arr_id'])) {
  4508. $data['city_id'] = end($data['city_arr_id']);
  4509. }
  4510. }
  4511. }
  4512. // 处理求职所绑定栏目
  4513. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4514. if (is_string($data['cat_arr_id'])) {
  4515. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4516. // 先清理可能存在的无效 JSON 字符
  4517. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4518. $catArr = json_decode($cleanedCatArrStr, true);
  4519. // 检查 JSON 解码是否成功且结果是数组
  4520. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4521. $data['catid'] = end($catArr);
  4522. }
  4523. } else {
  4524. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4525. if (is_array($data['cat_arr_id'])) {
  4526. $data['catid'] = end($data['cat_arr_id']);
  4527. }
  4528. }
  4529. }
  4530. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4531. $this->sendMessage([
  4532. 'talk_type' => 600,
  4533. 'title' => $data['name'],
  4534. 'content' => '提交了审核',
  4535. 'messageType' => 11,
  4536. ]);
  4537. }
  4538. $result = JobHunting::create($data);
  4539. if (empty($result)) {
  4540. return Result::error("添加失败", 0);
  4541. }
  4542. return Result::success($result);
  4543. }
  4544. public function delJobHunting(array $data): array
  4545. {
  4546. $result = JobHunting::where('id', $data['id'])->delete();
  4547. if (empty($result)) {
  4548. return Result::error("删除失败", 0);
  4549. }
  4550. return Result::success($result);
  4551. }
  4552. public function updateJobHunting(array $data): array
  4553. {
  4554. //设置东八区
  4555. date_default_timezone_set('Asia/Shanghai');
  4556. unset($data['company_name']);
  4557. unset($data['job_industry']);
  4558. unset($data['job_name']);
  4559. unset($data['department']);
  4560. unset($data['job_timeList']);
  4561. unset($data['job_content']);
  4562. unset($data['job_typename']); //不知道这是啥,
  4563. $data['created_at'] = date('Y-m-d H:i:s');
  4564. $data['updated_at'] = date('Y-m-d H:i:s');
  4565. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4566. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4567. $cityArr = json_decode($data['city_arr_id'], true);
  4568. $data['city_id'] = end($cityArr);
  4569. } else {
  4570. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4571. $data['city_id'] = end($data['city_arr_id']);
  4572. }
  4573. // 处理求职所绑定栏目
  4574. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4575. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4576. $catArr = json_decode($data['cat_arr_id'], true);
  4577. $data['catid'] = end($catArr);
  4578. } else {
  4579. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4580. $data['catid'] = end($data['cat_arr_id']);
  4581. }
  4582. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4583. $this->sendMessage([
  4584. 'talk_type' => 600,
  4585. 'title' => $data['name'],
  4586. 'content' => '提交了审核',
  4587. 'messageType' => 11,
  4588. ]);
  4589. }
  4590. $result = JobHunting::where('id', $data['id'])->update($data);
  4591. if (empty($result)) {
  4592. return Result::error("更新失败", 0);
  4593. }
  4594. return Result::success($result);
  4595. }
  4596. public function getJobHuntingInfo(array $data): array
  4597. {
  4598. $result = JobHunting::where('id', $data['id'])->first();
  4599. if (empty($result)) {
  4600. return Result::error("查询失败", 0);
  4601. }
  4602. return Result::success($result);
  4603. }
  4604. public function getJobHuntingData(array $data): array
  4605. {
  4606. $jobEnum = JobEnum::get();
  4607. $jobIndustry = JobIndustry::get();
  4608. $jobNature = JobNature::get();
  4609. $jobPosition = JobPosition::get();
  4610. $data = [
  4611. 'jobEnum' => $jobEnum,
  4612. 'jobIndustry' => $jobIndustry,
  4613. 'jobNature' => $jobNature,
  4614. 'jobPosition' => $jobPosition,
  4615. ];
  4616. return Result::success($data);
  4617. }
  4618. public function delJobHuntingInfo(array $data): array
  4619. {
  4620. $result = JobHunting::where('id', $data['id'])->delete();
  4621. return Result::success();
  4622. }
  4623. //20250324 通知,公告,消息
  4624. public function delNotice(array $data): array
  4625. {
  4626. $result = Notice::where('id', $data['id'])->delete();
  4627. if ($result) {
  4628. return Result::success();
  4629. } else {
  4630. return Result::error("删除失败", 0);
  4631. }
  4632. }
  4633. public function getNoticeInfo(array $data): array
  4634. {
  4635. $result = Notice::where('id', $data['id'])->first();
  4636. // var_dump($result['re_user_ids'], '--------------------');
  4637. if (empty($result)) {
  4638. return Result::error("查询失败", 0);
  4639. }
  4640. return Result::success($result);
  4641. }
  4642. public function readNotice(array $data): array
  4643. {
  4644. $result = Notice::where('id', $data['id'])->first();
  4645. // var_dump($result['re_user_ids'], '--------------------');
  4646. if (empty($result)) {
  4647. return Result::error("查询失败", 0);
  4648. }
  4649. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4650. $re_user_ids = json_decode($result['re_user_ids'], true);
  4651. var_dump($re_user_ids, '--------------1---test---------');
  4652. var_dump($data, '--------------1---test---------');
  4653. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4654. //如果已经存在,就不再添加
  4655. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4656. $read_id = json_decode($result['read_id'], true);
  4657. if (!is_array($read_id)) {
  4658. $read_id = [];
  4659. }
  4660. if (!in_array($data['user_id'], $read_id)) {
  4661. $read_id[] = $data['user_id'];
  4662. $result['read_id'] = json_encode($read_id);
  4663. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4664. }
  4665. } else {
  4666. //如果不存在,就添加
  4667. $result['read_id'] = json_encode([$data['user_id']]);
  4668. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4669. }
  4670. }
  4671. return Result::success($result);
  4672. }
  4673. public function addNotice(array $data): array
  4674. {
  4675. date_default_timezone_set('Asia/Shanghai');
  4676. $data['created_at'] = date('Y-m-d H:i:s');
  4677. $data['updated_at'] = date('Y-m-d H:i:s');
  4678. // $data['level'] = "1,2,3,4,5";
  4679. $level = json_decode($data['level'], true);
  4680. $user_id = UserInfo::
  4681. //city_id不是null
  4682. whereNotNull('city_id')
  4683. ->whereNotNull('department_id')
  4684. ->where(function ($query) use ($data) {
  4685. $query->where(function ($subQuery) use ($data) {
  4686. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4687. });
  4688. })
  4689. ->where(function ($query) use ($data) {
  4690. $query->where(function ($subQuery) use ($data) {
  4691. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4692. });
  4693. })
  4694. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4695. $query->whereIn('level', $level);
  4696. })
  4697. ->pluck('user_id')->toArray();
  4698. $user_id = array_unique($user_id);
  4699. $chat_ids = $user_id;
  4700. $user_id = json_encode($user_id);
  4701. $data['re_user_ids'] = $user_id;
  4702. $this->sendMessage([
  4703. 'talk_type' => 700,
  4704. 'title' => $data['title'],
  4705. 'content' => '提交了审核',
  4706. 'messageType' => 5,
  4707. ]);
  4708. $result = Notice::insertGetId($data);
  4709. if (empty($result)) {
  4710. return Result::error("添加失败", 0);
  4711. }
  4712. return Result::success($result);
  4713. }
  4714. public function updateNotice(array $data): array
  4715. {
  4716. date_default_timezone_set('Asia/Shanghai');
  4717. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4718. $user_id = UserInfo::
  4719. //city_id不是null
  4720. whereNotNull('city_id')
  4721. ->whereNotNull('department_id')
  4722. ->where(function ($query) use ($data) {
  4723. $query->where(function ($subQuery) use ($data) {
  4724. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4725. });
  4726. })
  4727. ->where(function ($query) use ($data) {
  4728. $query->where(function ($subQuery) use ($data) {
  4729. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4730. });
  4731. })
  4732. ->pluck('user_id')->toArray();
  4733. $user_id = array_unique($user_id);
  4734. $user_id = json_encode($user_id);
  4735. $data['re_user_ids'] = $user_id;
  4736. $data['updated_at'] = date('Y-m-d H:i:s');
  4737. $this->sendMessage([
  4738. 'talk_type' => 700,
  4739. 'title' => $data['title'],
  4740. 'content' => '提交了审核',
  4741. 'messageType' => 5,
  4742. ]);
  4743. $result = Notice::where('id', $data['id'])->update($data);
  4744. return Result::success($result);
  4745. }
  4746. public function getNoticeList(array $data): array
  4747. {
  4748. $where = [];
  4749. //title
  4750. if (isset($data['title']) && !empty($data['title'])) {
  4751. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4752. }
  4753. //level
  4754. if (isset($data['level']) && !empty($data['level'])) {
  4755. $where[] = ['notice.level', '=', $data['level']];
  4756. }
  4757. //status
  4758. if (isset($data['status']) && !empty($data['status'])) {
  4759. $where[] = ['notice.status', '=', $data['status']];
  4760. }
  4761. //type
  4762. if (isset($data['type']) && !empty($data['type'])) {
  4763. $where[] = ['notice.type', '=', $data['type']];
  4764. }
  4765. var_dump($data, '------------11111-2----test---------');
  4766. if ($data['type_id'] == 10000) {
  4767. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4768. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4769. })
  4770. ->where($where)
  4771. ->orderBy('updated_at', 'desc')
  4772. ->limit($data['page_size'])
  4773. ->offset(($data['page'] - 1) * $data['page_size'])
  4774. ->get();
  4775. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4776. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4777. })
  4778. ->where($where)
  4779. ->orderBy('updated_at', 'desc')
  4780. ->count();
  4781. } else {
  4782. $result = Notice::where($where)
  4783. // ->where('user_id', $data['user_id'])
  4784. ->Where(function ($query) use ($data) {
  4785. $query->Where(function ($q) use ($data) {
  4786. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4787. ->orWhere('notice.user_id', $data['user_id']);
  4788. });
  4789. })
  4790. ->when(!empty($data['status1']), function ($query) use ($data) {
  4791. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4792. })
  4793. ->orderBy('updated_at', 'desc')
  4794. ->limit($data['page_size'])
  4795. ->offset(($data['page'] - 1) * $data['page_size'])
  4796. ->get();
  4797. $total = Notice::where($where)
  4798. ->when(!empty($data['status1']), function ($query) use ($data) {
  4799. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4800. })
  4801. // ->where('user_id', $data['user_id'])
  4802. ->Where(function ($query) use ($data) {
  4803. $query->Where(function ($q) use ($data) {
  4804. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4805. ->orWhere('notice.user_id', $data['user_id']);
  4806. });
  4807. })
  4808. ->count();
  4809. }
  4810. if (empty($result)) {
  4811. return Result::error("查询失败", 0);
  4812. }
  4813. $data = [
  4814. 'rows' => $result,
  4815. 'count' => $total,
  4816. ];
  4817. return Result::success($data);
  4818. }
  4819. public function noticeList(array $data): array
  4820. {
  4821. $where = [];
  4822. //title
  4823. if (isset($data['title']) && !empty($data['title'])) {
  4824. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4825. }
  4826. //level
  4827. if (isset($data['level']) && !empty($data['level'])) {
  4828. $where[] = ['notice.level', '=', $data['level']];
  4829. }
  4830. //status
  4831. if (isset($data['status']) && !empty($data['status'])) {
  4832. $where[] = ['notice.status', '=', $data['status']];
  4833. }
  4834. //type
  4835. if (isset($data['type']) && !empty($data['type'])) {
  4836. $where[] = ['notice.type', '=', $data['type']];
  4837. }
  4838. var_dump($data, '------------11111-2----test---------');
  4839. if ($data['type_id'] == 10000) {
  4840. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4841. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4842. })
  4843. ->where($where)
  4844. ->orderBy('updated_at', 'desc')
  4845. ->limit($data['page_size'])
  4846. ->offset(($data['page'] - 1) * $data['page_size'])
  4847. ->get();
  4848. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4849. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4850. })
  4851. ->where($where)
  4852. ->orderBy('updated_at', 'desc')
  4853. ->count();
  4854. } else {
  4855. $result = Notice::where($where)
  4856. // ->where('user_id', $data['user_id'])
  4857. ->Where(function ($query) use ($data) {
  4858. $query->Where(function ($q) use ($data) {
  4859. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4860. ->orWhere('notice.user_id', $data['user_id']);
  4861. });
  4862. })
  4863. ->when(!empty($data['status1']), function ($query) use ($data) {
  4864. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4865. })
  4866. ->orderBy('updated_at', 'desc')
  4867. ->limit($data['page_size'])
  4868. ->offset(($data['page'] - 1) * $data['page_size'])
  4869. ->get();
  4870. $total = Notice::where($where)
  4871. ->when(!empty($data['status1']), function ($query) use ($data) {
  4872. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4873. })
  4874. // ->where('user_id', $data['user_id'])
  4875. ->Where(function ($query) use ($data) {
  4876. $query->Where(function ($q) use ($data) {
  4877. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4878. ->orWhere('notice.user_id', $data['user_id']);
  4879. });
  4880. })
  4881. ->count();
  4882. }
  4883. if (empty($result)) {
  4884. return Result::error("查询失败", 0);
  4885. }
  4886. $data = [
  4887. 'rows' => $result,
  4888. 'count' => $total,
  4889. ];
  4890. return Result::success($data);
  4891. }
  4892. public function getNoticeDetail(array $data): array
  4893. {
  4894. $result = Notice::where('id', $data['id'])->first();
  4895. if (empty($result)) {
  4896. return Result::error("查询失败", 0);
  4897. }
  4898. return Result::success($result);
  4899. }
  4900. public function deleteNotice(array $data): array
  4901. {
  4902. $notice = Notice::where('id', $data['id'])->first();
  4903. if (empty($notice)) {
  4904. return Result::error("删除失败", 0);
  4905. }
  4906. $chat_group_id = $notice->group_id;
  4907. if ($chat_group_id) {
  4908. //删除群聊
  4909. ChatGroups::where('id', $chat_group_id)->delete();
  4910. //删除群成员
  4911. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4912. //删除群聊记录
  4913. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4914. }
  4915. $result = Notice::where('id', $data['id'])->delete();
  4916. return Result::success($result);
  4917. }
  4918. public function complaintList(array $data): array
  4919. {
  4920. var_dump($data, '---------1---------');
  4921. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4922. unset($data['type_id']);
  4923. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4924. $where = [];
  4925. if ($type_id != 10000 && empty($data['deal_user'])) {
  4926. // $where['complaint.user_id'] = $user_id;
  4927. }
  4928. if (!empty($data['title'])) {
  4929. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4930. }
  4931. if (!empty($data['department_id'])) {
  4932. $where['complaint.department_id'] = $data['department_id'];
  4933. }
  4934. if (!empty($data['deal'])) {
  4935. $where['complaint.deal'] = $data['deal'];
  4936. }
  4937. if (!empty($data['status'])) {
  4938. $where['complaint.status'] = $data['status'];
  4939. }
  4940. var_dump(!empty($data['deal_user']), '----------1');
  4941. var_dump($where, '----------2');
  4942. $result = Complaint::where($where)
  4943. ->when(!empty($data['status1']), function ($query) use ($data) {
  4944. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4945. })
  4946. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4947. //json re_user_ids data[user_id]是不是在里面
  4948. $query->Where(function ($q) use ($data) {
  4949. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4950. ->where('complaint.status', 2);
  4951. });
  4952. })
  4953. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4954. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4955. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4956. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4957. ->orderBy('updated_at', 'desc')
  4958. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4959. //sql输出
  4960. if (empty($result)) {
  4961. return Result::error("暂无投诉信息", 0);
  4962. }
  4963. // 取出数据
  4964. $rows = $result->items();
  4965. $count = $result->total();
  4966. $responseData = [
  4967. 'rows' => $rows,
  4968. 'count' => $count,
  4969. ];
  4970. return Result::success($responseData);
  4971. }
  4972. public function getComplaintList(array $data): array
  4973. {
  4974. var_dump($data, '00000001000000000000');
  4975. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4976. unset($data['type_id']);
  4977. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4978. $where = [];
  4979. if ($type_id != 10000 && empty($data['deal_user'])) {
  4980. $where['complaint.user_id'] = $user_id;
  4981. }
  4982. if (!empty($data['title'])) {
  4983. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4984. }
  4985. if (!empty($data['department_id'])) {
  4986. $where['complaint.department_id'] = $data['department_id'];
  4987. }
  4988. if (!empty($data['deal'])) {
  4989. $where['complaint.deal'] = $data['deal'];
  4990. }
  4991. if (!empty($data['status'])) {
  4992. $where['complaint.status'] = $data['status'];
  4993. }
  4994. var_dump(!empty($data['deal_user']), '----------1');
  4995. var_dump($where, '----------2');
  4996. $result = Complaint::where($where)
  4997. ->when(!empty($data['status1']), function ($query) use ($data) {
  4998. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4999. })
  5000. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5001. // //json re_user_ids data[user_id]是不是在里面
  5002. // $query->Where(function ($q) use ($data) {
  5003. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5004. // ->where('complaint.status', 2);
  5005. // });
  5006. // })
  5007. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5008. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5009. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5010. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5011. ->orderBy('updated_at', 'desc')
  5012. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5013. //sql输出
  5014. if (empty($result)) {
  5015. return Result::error("暂无投诉信息", 0);
  5016. }
  5017. // 取出数据
  5018. $rows = $result->items();
  5019. $count = $result->total();
  5020. $responseData = [
  5021. 'rows' => $rows,
  5022. 'count' => $count,
  5023. ];
  5024. return Result::success($responseData);
  5025. }
  5026. public function getComplaintInfo(array $data): array
  5027. {
  5028. $result = Complaint::where('id', $data['id'])->first();
  5029. if (empty($result)) {
  5030. return Result::error("查询失败", 0);
  5031. }
  5032. return Result::success($result);
  5033. }
  5034. public function readComplaint(array $data): array
  5035. {
  5036. $result = Complaint::where('id', $data['id'])->first();
  5037. if (empty($result)) {
  5038. return Result::error("查询失败", 0);
  5039. }
  5040. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5041. $re_user_ids = json_decode($result['re_user_ids'], true);
  5042. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5043. //如果已经存在,就不再添加
  5044. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5045. $read_id = json_decode($result['read_id'], true);
  5046. if (!is_array($read_id)) {
  5047. $read_id = [];
  5048. }
  5049. if (!in_array($data['user_id'], $read_id)) {
  5050. $read_id[] = $data['user_id'];
  5051. $result['read_id'] = json_encode($read_id);
  5052. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5053. }
  5054. } else {
  5055. //如果不存在,就添加
  5056. $result['read_id'] = json_encode([$data['user_id']]);
  5057. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5058. }
  5059. }
  5060. return Result::success($result);
  5061. }
  5062. public function addComplaint(array $data): array
  5063. {
  5064. date_default_timezone_set('Asia/Shanghai');
  5065. $data['created_at'] = date('Y-m-d H:i:s');
  5066. $data['updated_at'] = date('Y-m-d H:i:s');
  5067. $this->sendMessage([
  5068. 'talk_type' => 800,
  5069. 'title' => $data['title'],
  5070. 'content' => '提交了审核',
  5071. 'messageType' => 6,
  5072. ]);
  5073. $result = Complaint::create($data);
  5074. return Result::success($result);
  5075. }
  5076. public function updateComplaint(array $data): array
  5077. {
  5078. date_default_timezone_set('Asia/Shanghai');
  5079. $data['updated_at'] = date('Y-m-d H:i:s');
  5080. $user_id = $data['user_id'] ?? 0;
  5081. $type_id = $data['type_id'] ?? 0;
  5082. unset($data['user_id']);
  5083. unset($data['type_id']);
  5084. $this->sendMessage([
  5085. 'talk_type' => 800,
  5086. 'title' => $data['title'],
  5087. 'content' => '提交了审核',
  5088. 'messageType' => 6,
  5089. ]);
  5090. $result = Complaint::where('id', $data['id'])->update($data);
  5091. return Result::success($result);
  5092. }
  5093. public function deleteComplaint(array $data): array
  5094. {
  5095. $result = Complaint::where('id', $data['id'])->delete();
  5096. return Result::success($result);
  5097. }
  5098. public function getComplainInfo(array $data): array
  5099. {
  5100. $result = Complaint::where('id', $data['id'])->first();
  5101. if (empty($result)) {
  5102. return Result::error("查询失败", 0);
  5103. }
  5104. return Result::success($result);
  5105. }
  5106. public function updateComplaintStatus(array $data): array
  5107. {
  5108. date_default_timezone_set('Asia/Shanghai');
  5109. $data['updated_at'] = date('Y-m-d H:i:s');
  5110. $user_id = $data['user_id'] ?? 0;
  5111. $type_id = $data['type_id'] ?? 0;
  5112. unset($data['user_id']);
  5113. unset($data['type_id']);
  5114. //处理, 写入处理人
  5115. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5116. $data['real_deal_user'] = $user_id;
  5117. }
  5118. //如果是deal 23,则判断是不是处理人
  5119. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5120. $complaintInof = Complaint::where('id', $data['id'])
  5121. ->where('real_deal_user', $user_id)
  5122. ->first();
  5123. if (empty($complaintInof)) {
  5124. return Result::error("处理人错误", 0);
  5125. }
  5126. }
  5127. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5128. if ($data['status'] == 1) {
  5129. $this->sendMessage([
  5130. 'talk_type' => 800,
  5131. 'title' => $complaintInfo['title'],
  5132. 'content' => '提交了审核',
  5133. 'messageType' => 6,
  5134. ]);
  5135. }
  5136. if ($data['status'] == 2 && !isset($data['deal'])) {
  5137. $this->sendMessage([
  5138. 'talk_type' => 801,
  5139. 'title' => $complaintInfo['title'],
  5140. 'content' => '审核通过',
  5141. 'messageType' => 6,
  5142. 'user_id' => $complaintInfo['user_id'],
  5143. ]);
  5144. $this->sendMessage([
  5145. 'talk_type' => 802,
  5146. 'title' => $complaintInfo['title'],
  5147. 'content' => '待处理',
  5148. 'messageType' => 6,
  5149. 'user_id' => $complaintInfo['re_user_ids'],
  5150. ]);
  5151. }
  5152. if ($data['status'] == 3 && !isset($data['deal'])) {
  5153. $this->sendMessage([
  5154. 'talk_type' => 801,
  5155. 'title' => $complaintInfo['title'],
  5156. 'content' => '审核拒绝',
  5157. 'messageType' => 6,
  5158. 'user_id' => $complaintInfo['user_id'],
  5159. ]);
  5160. }
  5161. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5162. $this->sendMessage([
  5163. 'talk_type' => 802,
  5164. 'title' => $complaintInfo['title'],
  5165. 'content' => '处理中',
  5166. 'messageType' => 6,
  5167. 'user_id' => $complaintInfo['re_user_ids'],
  5168. ]);
  5169. }
  5170. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5171. $this->sendMessage([
  5172. 'talk_type' => 802,
  5173. 'title' => $complaintInfo['title'],
  5174. 'content' => '不予处理',
  5175. 'messageType' => 6,
  5176. 'user_id' => $complaintInfo['re_user_ids'],
  5177. ]);
  5178. }
  5179. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5180. $this->sendMessage([
  5181. 'talk_type' => 802,
  5182. 'title' => $complaintInfo['title'],
  5183. 'content' => '已完结',
  5184. 'messageType' => 6,
  5185. 'user_id' => $complaintInfo['re_user_ids'],
  5186. ]);
  5187. }
  5188. $result = complaint::where('id', $data['id'])->update($data);
  5189. return Result::success($result);
  5190. }
  5191. public function updateGoodStatus(array $data): array
  5192. {
  5193. $user_id = $data['user_id'] ?? 0;
  5194. $type_id = $data['type_id'] ?? 0;
  5195. unset($data['user_id']);
  5196. unset($data['type_id']);
  5197. $goodInfo = Good::where('id', $data['id'])->first();
  5198. if ($data['status'] == 2) {
  5199. $this->sendMessage([
  5200. 'talk_type' => 201,
  5201. 'title' => $goodInfo['name'],
  5202. 'content' => '审核通过',
  5203. 'messageType' => 3,
  5204. 'user_id' => $goodInfo['user_id'],
  5205. ]);
  5206. }
  5207. if ($data['status'] == 3) {
  5208. $this->sendMessage([
  5209. 'talk_type' => 201,
  5210. 'title' => $goodInfo['name'],
  5211. 'content' => '审核拒绝',
  5212. 'messageType' => 3,
  5213. 'user_id' => $goodInfo['user_id'],
  5214. ]);
  5215. }
  5216. if ($data['status'] == 1) {
  5217. $this->sendMessage([
  5218. 'talk_type' => 200,
  5219. 'title' => $goodInfo['name'],
  5220. 'content' => '提交了审核',
  5221. 'messageType' => 3,
  5222. ]);
  5223. }
  5224. $result = Good::where('id', $data['id'])->update($data);
  5225. return Result::success($result);
  5226. }
  5227. public function updateJobHuntingStatus(array $data): array
  5228. {
  5229. $user_id = $data['user_id'] ?? 0;
  5230. $type_id = $data['type_id'] ?? 0;
  5231. unset($data['user_id']);
  5232. unset($data['type_id']);
  5233. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5234. if ($data['status'] == 2) {
  5235. $this->sendMessage([
  5236. 'talk_type' => 601,
  5237. 'title' => $jogHuntingInfo['name'],
  5238. 'content' => '审核通过',
  5239. 'messageType' => 11,
  5240. 'user_id' => $jogHuntingInfo['user_id'],
  5241. ]);
  5242. }
  5243. if ($data['status'] == 3) {
  5244. $this->sendMessage([
  5245. 'talk_type' => 601,
  5246. 'title' => $jogHuntingInfo['name'],
  5247. 'content' => '审核拒绝',
  5248. 'messageType' => 11,
  5249. 'user_id' => $jogHuntingInfo['user_id'],
  5250. ]);
  5251. }
  5252. if ($data['status'] == 1) {
  5253. $this->sendMessage([
  5254. 'talk_type' => 600,
  5255. 'title' => $jogHuntingInfo['name'],
  5256. 'content' => '提交了审核',
  5257. 'messageType' => 11,
  5258. ]);
  5259. }
  5260. $result = JobHunting::where('id', $data['id'])->update($data);
  5261. return Result::success($result);
  5262. }
  5263. public function updateNoticeStatus(array $data): array
  5264. {
  5265. $user_id = $data['user_id'] ?? 0;
  5266. $type_id = $data['type_id'] ?? 0;
  5267. unset($data['user_id']);
  5268. unset($data['type_id']);
  5269. //查询公告
  5270. $notice = Notice::where('id', $data['id'])->first();
  5271. if (empty($notice)) {
  5272. return Result::error("公告不存在", 0);
  5273. }
  5274. //$chat_ids 去除掉$data['user_id']
  5275. $chat_ids = json_decode($notice['re_user_ids'], true);
  5276. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5277. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5278. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5279. //chat_group
  5280. $group_id = PublicData::uuid();
  5281. $groupData = [
  5282. 'id' => $group_id,
  5283. 'creator_id' => $notice['user_id'],
  5284. 'group_name' => $notice['group_name'] ?? '',
  5285. 'profile' => $notice['profile'] ?? 0,
  5286. ];
  5287. var_dump($groupData, '-----------------groupData-------');
  5288. $groupResult = ChatGroups::insertGetId($groupData);
  5289. var_dump($groupResult, '-----------------groupid-------');
  5290. $groupMemberData = [
  5291. 'id' => PublicData::uuid(),
  5292. 'user_id' => $notice['user_id'],
  5293. 'group_id' => $group_id,
  5294. 'leader' => 2,
  5295. ];
  5296. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5297. //插入群成员表
  5298. $groupMemberDataUser = [];
  5299. $chatData = [];
  5300. foreach ($chat_ids as $key => $value) {
  5301. $groupMemberDataUser[] = [
  5302. 'id' => PublicData::uuid(),
  5303. 'user_id' => $value,
  5304. 'group_id' => $group_id,
  5305. 'leader' => 1,
  5306. ];
  5307. $chatData[] = [
  5308. 'user_id' => $value,
  5309. 'msg_type' => 1,
  5310. 'receiver_id' => $group_id,
  5311. 'content' => '通过通知创建群聊',
  5312. 'group_receiver_id' => $notice['user_id'],
  5313. 'action' => 'recieved',
  5314. 'created_at' => date('Y-m-d H:i:s'),
  5315. ];
  5316. }
  5317. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5318. ChatGroupsMember::insert($groupMemberDataUser);
  5319. //插入一条管理员聊天记录
  5320. $chatData[] = [
  5321. 'user_id' => $notice['user_id'],
  5322. 'msg_type' => 1,
  5323. 'receiver_id' => $group_id,
  5324. 'content' => '通过通知创建群聊',
  5325. 'group_receiver_id' => $notice['user_id'],
  5326. 'action' => 'said',
  5327. 'created_at' => date('Y-m-d H:i:s'),
  5328. ];
  5329. var_dump($chatData, '-----------------chatData-------');
  5330. $chatResult = ChatRecords::insert($chatData);
  5331. //处理imp
  5332. $group = [
  5333. 'type' => 1,
  5334. 'name' => $notice['group_name'] ?? '',
  5335. 'profile' => '',
  5336. 'avatar' => '',
  5337. 'creator_id' => $notice['user_id'],
  5338. ];
  5339. $groupResult = GroupImp::insertGetId($group);
  5340. var_dump($groupResult, '获取imp group_id');
  5341. $groupMember = [
  5342. 'user_id' => $notice['user_id'],
  5343. 'group_id' => $groupResult,
  5344. 'leader' => 1,
  5345. 'join_time' => Date('Y-m-d H:i:s')
  5346. ];
  5347. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5348. $talk_session = [
  5349. 'user_id' => $notice['user_id'],
  5350. 'to_from_id' => $groupResult,
  5351. 'talk_mode' => 2,
  5352. 'created_at' => Date('Y-m-d H:i:s'),
  5353. 'updated_at' => Date('Y-m-d H:i:s'),
  5354. ];
  5355. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5356. //被通知人员处理
  5357. foreach ($chat_ids as $key => $value) {
  5358. $groupMemberdata[] = [
  5359. 'user_id' => $value,
  5360. 'group_id' => $groupResult,
  5361. 'leader' => 3,
  5362. 'join_time' => Date('Y-m-d H:i:s')
  5363. ];
  5364. $talk_sessionData[] = [
  5365. 'user_id' => $value,
  5366. 'to_from_id' => $groupResult,
  5367. 'talk_mode' => 2,
  5368. 'created_at' => Date('Y-m-d H:i:s'),
  5369. 'updated_at' => Date('Y-m-d H:i:s'),
  5370. ];
  5371. }
  5372. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5373. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5374. $group_id = $groupResult;
  5375. //更新result的 group_id
  5376. $data['group_id'] = $group_id;
  5377. Notice::where(['id' => $data['id']])->update($data);
  5378. }
  5379. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5380. //删除掉信息
  5381. GroupImp::where('id', $notice['group_id'])->delete();
  5382. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5383. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5384. foreach ($chat_ids as $key => $value) {
  5385. }
  5386. //聊天记录删除
  5387. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5388. $data['group_id'] = null;
  5389. Notice::where(['id' => $data['id']])->update($data);
  5390. }
  5391. $result = Notice::where('id', $data['id'])->update($data);
  5392. $noticeInfo = Notice::where('id', $data['id'])->first();
  5393. if ($data['status'] == 2) {
  5394. $this->sendMessage([
  5395. 'talk_type' => 701,
  5396. 'title' => $noticeInfo['title'],
  5397. 'content' => '审核通过',
  5398. 'messageType' => 3,
  5399. 'user_id' => $noticeInfo['user_id'],
  5400. ]);
  5401. }
  5402. if ($data['status'] == 3) {
  5403. $this->sendMessage([
  5404. 'talk_type' => 701,
  5405. 'title' => $noticeInfo['title'],
  5406. 'content' => '审核拒绝',
  5407. 'messageType' => 3,
  5408. 'user_id' => $noticeInfo['user_id'],
  5409. ]);
  5410. }
  5411. if ($data['status'] == 1) {
  5412. $this->sendMessage([
  5413. 'talk_type' => 700,
  5414. 'title' => $noticeInfo['title'],
  5415. 'content' => '提交了审核',
  5416. 'messageType' => 3,
  5417. ]);
  5418. }
  5419. return Result::success($result);
  5420. }
  5421. public function getDUser(array $data): array
  5422. {
  5423. if (!empty($data['ids'])) {
  5424. $user = User::whereIn('id', $data['ids'])->getall();
  5425. if (empty($user)) {
  5426. return Result::error('无数据', 0);
  5427. }
  5428. return Result::success($user);
  5429. }
  5430. $where = [];
  5431. if (!empty($data['department_id'])) {
  5432. $where['department_id'] = $data['department_id'];
  5433. }
  5434. if (!empty($data['city_id'])) {
  5435. $where['city_id'] = $data['city_id'];
  5436. }
  5437. $result = User::where('type_id', 2)
  5438. ->where('status', 1)
  5439. ->where($where)
  5440. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5441. ->get();
  5442. if (empty($result)) {
  5443. return Result::error("查询失败", 0);
  5444. }
  5445. return Result::success($result);
  5446. }
  5447. /**
  5448. * 验证导航名称是否重复
  5449. * @return void
  5450. */
  5451. public function checkCategoryName(array $data): array
  5452. {
  5453. $result = Category::when($data, function ($query) use ($data) {
  5454. if (isset($data['name']) && $data['name']) {
  5455. $query->where("name", $data['name']);
  5456. }
  5457. if (isset($data['id']) && $data['id']) {
  5458. $query->where("id", "!=", $data['id']);
  5459. }
  5460. })->first();
  5461. if ($result) {
  5462. return Result::error("已存在");
  5463. } else {
  5464. return Result::success();
  5465. }
  5466. }
  5467. //20250226 产品列表
  5468. // 20250306 -------招聘--------fr
  5469. /*
  5470. * 招聘列表
  5471. * */
  5472. public function getJobRecruitingList(array $data): array
  5473. {
  5474. $where = [];
  5475. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5476. if ($data['checkout'] == 0) {
  5477. $job_status = [0, 2];
  5478. } else {
  5479. $job_status = [1];
  5480. }
  5481. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5482. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5483. }
  5484. $user = User::where('id', $data['user_id'])->first();
  5485. if (empty($user)) {
  5486. return Result::error("用户不存在", 0);
  5487. }
  5488. // 3:企业会员
  5489. if ($user['type_id'] == 3) {
  5490. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5491. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5492. }
  5493. // 如果 $where 为空,则不添加 where 条件
  5494. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5495. return $query->where($where);
  5496. })
  5497. ->whereIn('job_recruiting.status', $job_status)
  5498. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5499. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5500. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5501. ->orderBy("updated_at", "desc")
  5502. ->offset(($data['page'] - 1) * $data['page_size'])
  5503. ->limit($data['page_size'])
  5504. ->get()
  5505. ->all();
  5506. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5507. return $query->where($where);
  5508. })
  5509. ->whereIn('job_recruiting.status', $job_status)
  5510. ->count();
  5511. if (empty($result)) {
  5512. return Result::error("暂无招聘信息", 0);
  5513. }
  5514. return Result::success($result);
  5515. }
  5516. /*
  5517. * 招聘信息添加
  5518. * */
  5519. public function addJobRecruiting(array $data): array
  5520. {
  5521. // var_dump('添加招聘进入news------data',$data);
  5522. // return Result::success($data);
  5523. $user = User::where('user.id', $data['user_id'])
  5524. ->where('user.status', 1)
  5525. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5526. ->select(
  5527. 'user.type_id',
  5528. 'user.mobile',
  5529. 'user.email',
  5530. 'user_info.business_name',
  5531. 'user_info.company_hy_id',
  5532. 'user_info.company_nature',
  5533. 'user_info.company_size',
  5534. 'user_info.introduction',
  5535. 'user_info.real_name',
  5536. 'user_info.company_url',
  5537. 'user_info.address_arr_id',
  5538. 'user_info.address'
  5539. )
  5540. ->first();
  5541. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5542. return Result::error("用户不存在", 0);
  5543. }
  5544. $web = Website::where('id', $data['website_id'])->first();
  5545. if (empty($web)) {
  5546. return Result::error("网站不存在", 0);
  5547. }
  5548. // var_dump('添加招聘进入news---user---user',$user);
  5549. // 处理招聘关键词
  5550. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5551. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5552. } else {
  5553. Jieba::init(); // 初始化 jieba-php
  5554. Finalseg::init();
  5555. $segList = Jieba::cut($data['title']);
  5556. $segList1 = array_slice($segList, 0, 8);
  5557. $data['keyword'] = implode(',', $segList1);
  5558. }
  5559. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5560. $content = $data['description'];
  5561. // 去除 <style> 和 <script> 标签及其内容
  5562. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5563. // 去除所有 HTML 标签
  5564. $content = strip_tags($content);
  5565. // 去除 HTML 实体
  5566. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5567. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5568. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5569. // 去除多余空白
  5570. $content = preg_replace('/\s+/u', '', $content);
  5571. // 截取 100 个字符
  5572. $data['seo_description'] = mb_substr($content, 0, 100);
  5573. }
  5574. // return Result::success($user);
  5575. $data['action_id'] = $data['user_id'] ?? null;
  5576. $data['user_type'] = $user['type_id'] ?? null;
  5577. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5578. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5579. $data['catid'] = end($data['cat_arr_id']);
  5580. } else {
  5581. $data['catid'] = 0;
  5582. }
  5583. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5584. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5585. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5586. // 公司地址 管理员必填
  5587. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5588. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5589. // 管理员-企业相关信息
  5590. $company = [
  5591. // 'user_id' => $data['user_id']?? null,
  5592. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5593. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5594. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5595. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5596. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5597. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5598. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5599. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5600. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5601. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5602. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5603. ];
  5604. //去掉相关企业信息
  5605. $job = array_diff_key($data, array_flip(array_keys($company)));
  5606. // var_dump('添加招聘进入news---job---user',$job);
  5607. Db::beginTransaction();
  5608. try {
  5609. // // 先添加职位相关信息
  5610. if ($user['type_id'] == 10000) {
  5611. $job['status'] = 1;
  5612. }
  5613. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5614. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5615. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5616. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5617. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5618. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5619. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5620. // return Result::success($job);
  5621. $jobId = JobRecruiting::insertGetId($job);
  5622. if (empty($jobId)) {
  5623. Db::rollBack();
  5624. return Result::error("添加失败");
  5625. }
  5626. // 添加公司信息
  5627. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5628. $company['job_id'] = $jobId;
  5629. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5630. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5631. if ($user['type_id'] == 10000) {
  5632. // 管理员添加企业信息
  5633. $companyId = JobCompany::insertGetId($company);
  5634. if (empty($companyId)) {
  5635. Db::rollBack();
  5636. return Result::error("添加失败");
  5637. }
  5638. } else {
  5639. // 企业会员添加企业信息
  5640. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5641. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5642. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5643. $company['job_id'] = $jobId;
  5644. $companyId = JobCompany::insertGetId($company);
  5645. if (empty($companyId)) {
  5646. Db::rollBack();
  5647. return Result::error("添加失败");
  5648. }
  5649. }
  5650. Db::commit();
  5651. $result = [
  5652. 'job_id' => $jobId,
  5653. 'company_id' => $companyId,
  5654. ];
  5655. return Result::success($result);
  5656. } catch (\Exception $e) {
  5657. Db::rollBack();
  5658. return Result::error($e->getMessage(), 0);
  5659. }
  5660. // return Result::success($result);
  5661. }
  5662. /*
  5663. * 获取招聘信息详情
  5664. * */
  5665. public function getJobRecruitingInfo(array $data): array
  5666. {
  5667. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5668. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5669. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5670. ->select(
  5671. 'job_recruiting.*',
  5672. 'website.website_name as website_name',
  5673. 'job_company.business_name',
  5674. 'job_company.company_hy_id',
  5675. 'job_company.company_size',
  5676. 'job_company.company_nature',
  5677. 'job_company.introduction',
  5678. 'job_company.real_name',
  5679. 'job_company.mobile',
  5680. 'job_company.company_url',
  5681. 'job_company.address_arr_id',
  5682. 'job_company.address',
  5683. 'job_company.email'
  5684. )
  5685. ->first();
  5686. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5687. if (!empty($cityId)) {
  5688. if (isset($cityId[1]) && $cityId[1] != null) {
  5689. $city = District::where('id', $cityId[1])->first(['name']);
  5690. } else {
  5691. $city = District::where('id', $cityId[0])->first(['name']);
  5692. }
  5693. $result['city'] = $city['name'] ?? '';
  5694. }
  5695. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5696. if (is_array($addressId) && !empty($addressId)) {
  5697. $address = District::whereIn('id', $addressId)
  5698. ->orderBy('level', 'asc')
  5699. ->get(['name'])
  5700. ->pluck('name')
  5701. ->implode('');
  5702. // $job->address_name = $address ?? '';
  5703. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5704. }
  5705. if (empty($result)) {
  5706. return Result::error("招聘信息不存在", 0);
  5707. }
  5708. // return Result::success($job);
  5709. return Result::success($result);
  5710. }
  5711. /*
  5712. * 修改招聘信息
  5713. * */
  5714. public function upJobRecruiting(array $data): array
  5715. {
  5716. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5717. // return Result::success($job);
  5718. if (empty($job)) {
  5719. return Result::error("招聘信息不存在", 0);
  5720. }
  5721. $user = User::where('id', $data['user_id'])->first();
  5722. // return Result::success($user);
  5723. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5724. return Result::error("用户不存在", 0);
  5725. }
  5726. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5727. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5728. }
  5729. // 处理招聘关键词
  5730. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5731. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5732. } else {
  5733. Jieba::init(); // 初始化 jieba-php
  5734. Finalseg::init();
  5735. $segList = Jieba::cut($data['title']);
  5736. $segList1 = array_slice($segList, 0, 8);
  5737. $data['keyword'] = implode(',', $segList1);
  5738. }
  5739. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5740. $content = $data['description'];
  5741. // 去除 <style> 和 <script> 标签及其内容
  5742. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5743. // 去除所有 HTML 标签
  5744. $content = strip_tags($content);
  5745. // 去除 HTML 实体
  5746. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5747. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5748. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5749. // 去除多余空白
  5750. $content = preg_replace('/\s+/u', '', $content);
  5751. // 截取 100 个字符
  5752. $data['seo_description'] = mb_substr($content, 0, 100);
  5753. }
  5754. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5755. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5756. $data['catid'] = end($data['cat_arr_id']);
  5757. } else {
  5758. }
  5759. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5760. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5761. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5762. // 公司地址 管理员必填
  5763. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5764. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5765. // 管理员-企业相关信息
  5766. $company = [
  5767. // 'user_id' => $data['user_id']?? null,
  5768. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5769. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5770. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5771. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5772. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5773. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5774. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5775. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5776. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5777. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5778. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5779. ];
  5780. //去掉相关企业信息
  5781. $data = array_diff_key($data, array_flip(array_keys($company)));
  5782. $jobId = $data['id'];
  5783. $web = $data['website_id'];
  5784. $data['action_id'] = $data['user_id'];
  5785. unset($data['user_id']);
  5786. unset($data['user_type']);
  5787. unset($data['id']);
  5788. unset($data['website_id']);
  5789. // return Result::success($data);
  5790. Db::beginTransaction();
  5791. try {
  5792. // 管理员修改招聘信息
  5793. if ($user['type_id'] == 10000) {
  5794. $data['website_id'] = $web;
  5795. $company['website_id'] = $data['website_id'];
  5796. $data['status'] = 1;
  5797. } else {
  5798. $data['status'] = 0;
  5799. }
  5800. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5801. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5802. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5803. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5804. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5805. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5806. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5807. // return Result::success($job);
  5808. // Db::rollBack();
  5809. // return Result::success($company);
  5810. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5811. $this->sendMessage([
  5812. 'talk_type' => 500,
  5813. 'title' => $data['title'],
  5814. 'content' => '提交了审核',
  5815. 'messageType' => 10,
  5816. ]);
  5817. }
  5818. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5819. if (empty($result['job'])) {
  5820. Db::rollBack();
  5821. return Result::error("修改招聘信息失败");
  5822. }
  5823. // 管理员修改企业相关信息
  5824. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5825. if (empty($result['company'])) {
  5826. Db::rollBack();
  5827. return Result::error("修改企业相关信息失败");
  5828. }
  5829. Db::commit();
  5830. // return Result::success($result);
  5831. } catch (\Exception $e) {
  5832. Db::rollBack();
  5833. return Result::error($e->getMessage(), 0);
  5834. }
  5835. return Result::success($result);
  5836. }
  5837. /*
  5838. * 招聘信息删除
  5839. * */
  5840. public function delJobRecruiting(array $data): array
  5841. {
  5842. $user = User::where('id', $data['user_id'])->first();
  5843. if (empty($user)) {
  5844. return Result::error("用户不存在", 0);
  5845. }
  5846. $job = JobRecruiting::where('id', $data['id'])->first();
  5847. if (empty($job)) {
  5848. return Result::error("招聘信息不存在", 0);
  5849. }
  5850. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5851. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5852. }
  5853. Db::beginTransaction();
  5854. try {
  5855. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5856. if (empty($result['job'])) {
  5857. Db::rollBack();
  5858. return Result::error("删除招聘信息失败");
  5859. }
  5860. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5861. if (empty($result['company'])) {
  5862. Db::rollBack();
  5863. return Result::error("删除企业相关信息失败");
  5864. }
  5865. Db::commit();
  5866. } catch (\Exception $e) {
  5867. Db::rollBack();
  5868. return Result::error($e->getMessage(), 0);
  5869. }
  5870. return Result::success($result);
  5871. }
  5872. /*
  5873. * 获取公司信息
  5874. * */
  5875. public function getJobCompany(array $data): array
  5876. {
  5877. $user = User::where('user.id', $data['user_id'])
  5878. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5879. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5880. ->first();
  5881. // return Result::success($user);
  5882. if (empty($user)) {
  5883. return Result::error("用户不存在", 0);
  5884. }
  5885. if ($user['type_id'] == 3) {
  5886. $result = [
  5887. // 'id' => 0,
  5888. 'user_id' => $data['user_id'],
  5889. 'website_id' => $data['website_id'],
  5890. 'business_name' => $user['business_name'], // 企业名称
  5891. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5892. 'company_nature' => $user['company_nature'], // 公司性质
  5893. 'company_size' => $user['company_size'], // 公司规模
  5894. 'introduction' => $user['introduction'], // 公司简介
  5895. 'real_name' => $user['real_name'], // 企业联系人
  5896. 'mobile' => $user['mobile'], // 企业联系电话
  5897. 'company_url' => $user['company_url'], // 企业网址
  5898. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5899. 'address' => $user['address'], // 企业地址
  5900. 'email' => $user['email'], // 企业邮箱
  5901. ];
  5902. } else {
  5903. return Result::error("用户类型错误", 0);
  5904. }
  5905. if (empty($result)) {
  5906. return Result::error("公司信息不存在", 0);
  5907. }
  5908. return Result::success($result);
  5909. }
  5910. /*
  5911. * 修改公司信息
  5912. * */
  5913. public function upJobCompany(array $data): array
  5914. {
  5915. // return Result::success($data);
  5916. $user = User::where('user.id', $data['user_id'])
  5917. ->where('user.status', 1)
  5918. ->select('user.user_name', 'user.type_id')
  5919. ->first();
  5920. if (empty($user)) {
  5921. return Result::error("用户不存在", 0);
  5922. }
  5923. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5924. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5925. $company = [
  5926. 'business_name' => $data['business_name'], // 企业名称
  5927. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5928. 'company_nature' => $data['company_nature'], // 公司性质
  5929. 'company_size' => $data['company_size'], // 公司规模
  5930. 'introduction' => $data['introduction'], // 公司简介
  5931. // 'real_name' => $data['real_name'], // 企业联系人
  5932. 'company_url' => $data['company_url'], // 企业网址
  5933. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5934. 'address' => $data['address'], // 企业详细地址
  5935. // 'email' => $data['email'], // 企业邮箱
  5936. ];
  5937. if ($user['type_id'] == 3) {
  5938. Db::beginTransaction();
  5939. try {
  5940. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5941. 'business_name' => $data['business_name'], // 企业名称
  5942. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5943. 'company_nature' => $data['company_nature'], // 公司性质
  5944. 'company_size' => $data['company_size'], // 公司规模
  5945. 'introduction' => $data['introduction'], // 公司简介
  5946. // 'real_name' => $data['real_name'], // 企业联系人
  5947. 'company_url' => $data['company_url'], // 企业网址
  5948. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5949. 'address' => $data['address'], // 企业详细地址
  5950. ]);
  5951. if (empty($result['userinfo'])) {
  5952. Db::rollBack();
  5953. return Result::error('修改企业会员信息失败!');
  5954. }
  5955. $result['user'] = User::where('id', $data['user_id'])->update([
  5956. 'email' => $data['email'], // 企业邮箱
  5957. ]);
  5958. if (empty($result['user'])) {
  5959. Db::rollBack();
  5960. return Result::error('修改个人中心信息失败!');
  5961. }
  5962. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5963. if (!empty($job_company)) {
  5964. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5965. if (empty($result['job_company'])) {
  5966. Db::rollBack();
  5967. return Result::error('修改企业会员信息失败!');
  5968. }
  5969. }
  5970. Db::commit();
  5971. return Result::success($result);
  5972. } catch (\Exception $e) {
  5973. Db::rollBack();
  5974. return Result::error($e->getMessage(), 0);
  5975. }
  5976. } else {
  5977. return Result::error("用户类型错误", 0);
  5978. }
  5979. }
  5980. /*
  5981. * 获取省-市
  5982. * */
  5983. public function getJobRecruitingArea(array $data): array
  5984. {
  5985. if (isset($data['pid']) && $data['pid'] != null) {
  5986. $result = District::where('pid', $data['pid'])->get()->all();
  5987. } else {
  5988. $result = District::where('level', 1)->get()->all();
  5989. }
  5990. if (empty($result)) {
  5991. return Result::error("暂无此省市", 0);
  5992. }
  5993. return Result::success($result);
  5994. }
  5995. /*
  5996. * 获取行业分类
  5997. * */
  5998. public function getIndustry(array $data): array
  5999. {
  6000. $result = JobIndustry::get()->all();
  6001. if (empty($result)) {
  6002. return Result::error("暂无行业分类", 0);
  6003. }
  6004. return Result::success($result);
  6005. }
  6006. /*
  6007. * 获取职位
  6008. * */
  6009. public function getPositionList(array $data): array
  6010. {
  6011. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6012. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6013. } else {
  6014. $result = JobPosition::where('zwpid', 0)->get()->all();
  6015. }
  6016. if (empty($result)) {
  6017. return Result::error("暂无此职位", 0);
  6018. }
  6019. return Result::success($result);
  6020. }
  6021. /*
  6022. * 获取工作性质-菜单
  6023. * */
  6024. public function getJobNature(array $data): array
  6025. {
  6026. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6027. if (empty($result)) {
  6028. return Result::error("暂无工作性质", 0);
  6029. }
  6030. return Result::success($result);
  6031. }
  6032. /*
  6033. * 获取工作经验-菜单
  6034. * */
  6035. public function getExperience(array $data): array
  6036. {
  6037. $result = JobEnum::where('egroup', 'years')->get()->all();
  6038. if (empty($result)) {
  6039. return Result::error("暂无工作经验", 0);
  6040. }
  6041. return Result::success($result);
  6042. }
  6043. /*
  6044. * 获取学历-菜单
  6045. * */
  6046. public function getEducation(array $data): array
  6047. {
  6048. $result = JobEnum::where('egroup', 'education')->get()->all();
  6049. if (empty($result)) {
  6050. return Result::error("暂无学历", 0);
  6051. }
  6052. return Result::success($result);
  6053. }
  6054. /*
  6055. * 获取薪资-菜单
  6056. * */
  6057. public function getSalary(array $data): array
  6058. {
  6059. $result = JobEnum::where('egroup', 'income')->get()->all();
  6060. if (empty($result)) {
  6061. return Result::error("暂无薪资", 0);
  6062. }
  6063. return Result::success($result);
  6064. }
  6065. /*
  6066. * 获取语言-菜单
  6067. * */
  6068. public function getLanguage(array $data): array
  6069. {
  6070. $result = JobEnum::where('egroup', 'language')->get()->all();
  6071. if (empty($result)) {
  6072. return Result::error("暂无语言", 0);
  6073. }
  6074. return Result::success($result);
  6075. }
  6076. /*
  6077. * 获取掌握程度-菜单
  6078. * */
  6079. public function getLevel(array $data): array
  6080. {
  6081. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6082. if (empty($result)) {
  6083. return Result::error("暂无工作性质", 0);
  6084. }
  6085. return Result::success($result);
  6086. }
  6087. // 公司信息
  6088. /*
  6089. * 获取公司性质-菜单
  6090. * */
  6091. public function getCompanyNature(array $data): array
  6092. {
  6093. $result = JobNature::get()->all();
  6094. if (empty($result)) {
  6095. return Result::error("暂无公司性质", 0);
  6096. }
  6097. return Result::success($result);
  6098. }
  6099. /*
  6100. * 获取公司规模-菜单
  6101. * */
  6102. public function getCompanySize(array $data): array
  6103. {
  6104. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6105. if (empty($result)) {
  6106. return Result::error("暂无公司规模", 0);
  6107. }
  6108. return Result::success($result);
  6109. }
  6110. /*
  6111. * 招聘信息审核
  6112. * */
  6113. public function checkJobRecruiting(array $data): array
  6114. {
  6115. $user = User::where('id', $data['user_id'])->first();
  6116. if (empty($user)) {
  6117. return Result::error("用户不存在", 0);
  6118. }
  6119. $job = JobRecruiting::where('id', $data['id'])->first();
  6120. if (empty($job)) {
  6121. return Result::error("招聘信息不存在", 0);
  6122. }
  6123. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6124. if ($user['type_id'] != 10000) {
  6125. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6126. }
  6127. // 驳回原因
  6128. if ($data['status'] == 2) {
  6129. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6130. }
  6131. $data['action_id'] = $data['user_id'];
  6132. unset($data['user_id']);
  6133. if ($data['status'] == 1) {
  6134. $this->sendMessage([
  6135. 'talk_type' => 501,
  6136. 'title' => $job['title'],
  6137. 'content' => '审核通过',
  6138. 'messageType' => 10,
  6139. 'user_id' => $job['user_id'],
  6140. ]);
  6141. }
  6142. if ($data['status'] == 2) {
  6143. $this->sendMessage([
  6144. 'talk_type' => 501,
  6145. 'title' => $job['title'],
  6146. 'content' => '审核拒绝',
  6147. 'messageType' => 10,
  6148. 'user_id' => $job['user_id'],
  6149. ]);
  6150. }
  6151. if ($data['status'] == 0) {
  6152. $this->sendMessage([
  6153. 'talk_type' => 500,
  6154. 'title' => $job['title'],
  6155. 'content' => '提交了审核',
  6156. 'messageType' => 10,
  6157. ]);
  6158. }
  6159. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6160. if (empty($result)) {
  6161. return Result::error("审核失败", 0);
  6162. }
  6163. return Result::success($result);
  6164. }
  6165. public function myApplyList(array $data): array
  6166. {
  6167. var_dump($data, '------参数');
  6168. $user = User::where('id', $data['user_id'])->first();
  6169. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6170. return Result::error("用户不存在", 0);
  6171. }
  6172. // 1:个人会员 职场机会
  6173. if ($user['type_id'] == 1) {
  6174. $where['user_id'] = $user['id'];
  6175. }
  6176. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6177. $query->where('user_id', $user['id']);
  6178. })
  6179. ->pluck('recruit_id');
  6180. $where = [];
  6181. if (isset($data['salary']) && $data['salary'] != null) {
  6182. $where['job_recruiting.salary'] = $data['salary'];
  6183. }
  6184. if (isset($data['experience']) && $data['experience'] != null) {
  6185. $where['job_recruiting.experience'] = $data['experience'];
  6186. }
  6187. if (isset($data['business_name']) && $data['business_name'] != null) {
  6188. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6189. }
  6190. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6191. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6192. ->where($where);
  6193. // ->count();
  6194. $count = $query->count();
  6195. $query = clone $query;
  6196. $job = $query
  6197. ->leftJoin('job_enum as income_enum', function ($join) {
  6198. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6199. ->where('income_enum.egroup', 'income');
  6200. })
  6201. ->leftJoin('job_enum as years_enum', function ($join) {
  6202. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6203. ->where('years_enum.egroup', 'years');
  6204. })
  6205. // ->where($where)
  6206. ->orderBy('job_recruiting.updated_at', 'desc')
  6207. ->select(
  6208. 'job_recruiting.id',
  6209. 'job_recruiting.title',
  6210. 'job_company.business_name',
  6211. 'income_enum.evalue as salary_evalue',
  6212. 'income_enum.ename as salary_ename',
  6213. 'years_enum.evalue as experience_evalue',
  6214. 'years_enum.ename as experience_ename',
  6215. 'job_recruiting.updated_at'
  6216. )
  6217. ->offset(($data['page'] - 1) * $data['pageSize'])
  6218. ->limit($data['pageSize'])
  6219. ->get()
  6220. ->all();
  6221. if (empty($job)) {
  6222. return Result::error("暂无招聘信息", 0);
  6223. }
  6224. $result = [
  6225. 'row' => $job,
  6226. 'count' => $count,
  6227. ];
  6228. return Result::success($result);
  6229. }
  6230. public function readJobApply(array $data): array
  6231. {
  6232. $result = JobApply::where('id', $data['id'])->first();
  6233. if (empty($result)) {
  6234. return Result::error("查询失败", 0);
  6235. }
  6236. $result = JobApply::where('id', $data['id'])->update([
  6237. 'status' => 2,
  6238. ]);
  6239. return Result::success($result);
  6240. }
  6241. /*
  6242. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6243. * */
  6244. public function getRecruitingList(array $data): array
  6245. {
  6246. $user = User::where('id', $data['user_id'])->first();
  6247. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6248. return Result::error("用户不存在", 0);
  6249. }
  6250. // 1:个人会员 职场机会
  6251. if ($user['type_id'] == 1) {
  6252. $where['user_id'] = $user['id'];
  6253. }
  6254. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6255. $query->where('receiver_id', $user['id']);
  6256. })
  6257. ->pluck('recruit_id');
  6258. // return Result::success($recruitingId);
  6259. $where = [];
  6260. if (isset($data['salary']) && $data['salary'] != null) {
  6261. $where['job_recruiting.salary'] = $data['salary'];
  6262. }
  6263. if (isset($data['experience']) && $data['experience'] != null) {
  6264. $where['job_recruiting.experience'] = $data['experience'];
  6265. }
  6266. if (isset($data['business_name']) && $data['business_name'] != null) {
  6267. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6268. }
  6269. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6270. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6271. ->where($where);
  6272. // ->count();
  6273. $count = $query->count();
  6274. $query = clone $query;
  6275. $job = $query
  6276. ->leftJoin('job_enum as income_enum', function ($join) {
  6277. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6278. ->where('income_enum.egroup', 'income');
  6279. })
  6280. ->leftJoin('job_enum as years_enum', function ($join) {
  6281. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6282. ->where('years_enum.egroup', 'years');
  6283. })
  6284. // ->where($where)
  6285. ->orderBy('job_recruiting.updated_at', 'desc')
  6286. ->select(
  6287. 'job_recruiting.id',
  6288. 'job_recruiting.title',
  6289. 'job_company.business_name',
  6290. 'income_enum.evalue as salary_evalue',
  6291. 'income_enum.ename as salary_ename',
  6292. 'years_enum.evalue as experience_evalue',
  6293. 'years_enum.ename as experience_ename',
  6294. 'job_recruiting.updated_at'
  6295. )
  6296. ->offset(($data['page'] - 1) * $data['pageSize'])
  6297. ->limit($data['pageSize'])
  6298. ->get()
  6299. ->all();
  6300. if (empty($job)) {
  6301. return Result::error("暂无招聘信息", 0);
  6302. }
  6303. $result = [
  6304. 'row' => $job,
  6305. 'count' => $count,
  6306. ];
  6307. return Result::success($result);
  6308. }
  6309. /*
  6310. * 获取企业会员-招聘信息列表
  6311. * */
  6312. public function getRecruitingInfo(array $data): array
  6313. {
  6314. $user = User::where('id', $data['user_id'])->first();
  6315. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6316. return Result::error("用户不存在", 0);
  6317. }
  6318. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6319. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6320. ->select(
  6321. 'job_recruiting.*',
  6322. 'job_company.business_name',
  6323. 'job_company.company_hy_id',
  6324. 'job_company.company_size',
  6325. 'job_company.company_nature',
  6326. 'job_company.introduction',
  6327. 'job_company.real_name',
  6328. 'job_company.mobile',
  6329. 'job_company.company_url',
  6330. 'job_company.address_arr_id',
  6331. 'job_company.address',
  6332. 'job_company.email'
  6333. )
  6334. ->get();
  6335. if (empty($recruiting)) {
  6336. return Result::error("暂无招聘信息", 0);
  6337. }
  6338. return Result::success($recruiting);
  6339. }
  6340. /*
  6341. * 获取企业会员-我的沟通
  6342. * */
  6343. public function getJobResumeList(array $data): array
  6344. {
  6345. $user = User::where('id', $data['user_id'])->first();
  6346. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6347. return Result::error("用户不存在", 0);
  6348. }
  6349. $where = [];
  6350. if (isset($data['salary']) && $data['salary'] != null) {
  6351. $where['job_hunting.salary'] = $data['salary'];
  6352. }
  6353. if (isset($data['user_name']) && $data['user_name'] != null) {
  6354. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6355. }
  6356. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6357. $query->where('job_resume.user_id', $user['id']);
  6358. })
  6359. ->when(!empty($where), function ($query) use ($where) {
  6360. $query->where($where);
  6361. })
  6362. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6363. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6364. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6365. ->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');
  6366. $count = $job->count();
  6367. if ($count == 0) {
  6368. return Result::error("暂无沟通记录", 0);
  6369. }
  6370. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6371. ->offset(($data['page'] - 1) * $data['pageSize'])
  6372. ->limit($data['pageSize'])
  6373. ->get();
  6374. if (empty($jobs)) {
  6375. return Result::error("暂无沟通记录", 0);
  6376. }
  6377. $result['row'] = $this->processJob($jobs, '');
  6378. $result['count'] = $count;
  6379. return Result::success($result);
  6380. }
  6381. public function readJobResume(array $data): array
  6382. {
  6383. $result = JobResume::where('id', $data['id'])->first();
  6384. if (empty($result)) {
  6385. return Result::error("查询失败", 0);
  6386. }
  6387. $result = JobResume::where('id', $data['id'])->update([
  6388. 'status' => 2,
  6389. ]);
  6390. return Result::success($result);
  6391. }
  6392. // 20250306 招聘
  6393. //20250422 书刊音像
  6394. public function addBook(array $data): array
  6395. {
  6396. $user_id = $data['user_id'] ?? 0;
  6397. $type_id = $data['type_id'] ?? 0;
  6398. // $website_id = $data['website_id'] ?? 0;
  6399. // unset($data['user_id']);
  6400. unset($data['type_id']);
  6401. // unset($data['website_id']);
  6402. //处理数组
  6403. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6404. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6405. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6406. if ($data['img_url'] == '') {
  6407. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6408. preg_match_all($reg, $data['detail'], $matches);
  6409. if (isset($matches[1][0])) {
  6410. //截取varchar240
  6411. $data['img_url'] = substr($matches[1][0], 0, 240);
  6412. }
  6413. }
  6414. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6415. //提取标题+内容中的关键词
  6416. $data['keyword'] = $data['title'];
  6417. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6418. Jieba::init(); // 初始化 jieba-php
  6419. Finalseg::init();
  6420. $segList = Jieba::cut($data['keyword']);
  6421. $segList1 = array_slice($segList, 0, 8);
  6422. $data['keyword'] = implode(',', $segList1);
  6423. }
  6424. if ($data['description'] == '') {
  6425. //提取内容中的描述
  6426. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6427. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6428. }
  6429. var_dump($data, '--');
  6430. if ($data['status'] == 1) {
  6431. $this->sendMessage([
  6432. 'talk_type' => 400,
  6433. 'title' => $data['title'],
  6434. 'content' => '提交了审核',
  6435. 'messageType' => 7,
  6436. ]);
  6437. }
  6438. $result = Book::insertGetId($data);
  6439. if (empty($result)) {
  6440. return Result::error("添加失败", 0);
  6441. }
  6442. return Result::success($result);
  6443. }
  6444. public function getBookList(array $data): array
  6445. {
  6446. $where = [];
  6447. if (!empty($data["title"])) {
  6448. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6449. }
  6450. if (!empty($data['website_name'])) {
  6451. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6452. }
  6453. if (!empty($data['status'])) {
  6454. $where[] = ['book.status', '=', $data['status']];
  6455. }
  6456. $user_id = $data['user_id'];
  6457. $type_id = $data['type_id'];
  6458. // $type_id = 4;
  6459. var_dump($type_id, '------1--------');
  6460. if ($type_id != 10000) {
  6461. $where[] = ['book.user_id', '=', $user_id];
  6462. }
  6463. var_dump(!empty($data['status1']), '=-===1');
  6464. $result = Book::where($where)
  6465. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6466. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6467. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6468. ->when(isset($data['status1']), function ($query) use ($data) {
  6469. $query->whereIn('book.status', [1, 3]);
  6470. })
  6471. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6472. ->orderBy("updated_at", "desc")
  6473. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6474. if (empty($result)) {
  6475. return Result::error("暂无数据", 0);
  6476. }
  6477. // 取出数据
  6478. $rows = $result->items();
  6479. $count = $result->total();
  6480. $responseData = [
  6481. 'rows' => $rows,
  6482. 'count' => $count,
  6483. ];
  6484. return Result::success($responseData);
  6485. }
  6486. public function deleteBook(array $data): array
  6487. {
  6488. $result = Book::where('id', $data['id'])->delete();
  6489. if (empty($result)) {
  6490. return Result::error("删除失败", 0);
  6491. }
  6492. return Result::success($result);
  6493. }
  6494. public function updateBook(array $data): array
  6495. {
  6496. // $user_id = $data['user_id'] ?? 0;
  6497. $type_id = $data['type_id'] ?? 0;
  6498. // $website_id = $data['website_id'] ?? 0;
  6499. unset($data['user_id']);
  6500. unset($data['type_id']);
  6501. // unset($data['website_id']);
  6502. //处理数组
  6503. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6504. if ($data['img_url'] == '') {
  6505. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6506. preg_match_all($reg, $data['detail'], $matches);
  6507. if (isset($matches[1][0])) {
  6508. //截取varchar240
  6509. $data['img_url'] = substr($matches[1][0], 0, 240);
  6510. }
  6511. }
  6512. if ($data['keyword'] == '') {
  6513. //提取标题+内容中的关键词
  6514. $data['keyword'] = $data['title'];
  6515. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6516. Jieba::init(); // 初始化 jieba-php
  6517. Finalseg::init();
  6518. $segList = Jieba::cut($data['keyword']);
  6519. $segList1 = array_slice($segList, 0, 8);
  6520. $data['keyword'] = implode(',', $segList1);
  6521. }
  6522. if ($data['description'] == '') {
  6523. //提取内容中的描述
  6524. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6525. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6526. }
  6527. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6528. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6529. if ($data['status'] == 1) {
  6530. $this->sendMessage([
  6531. 'talk_type' => 400,
  6532. 'title' => $data['title'],
  6533. 'content' => '提交了审核',
  6534. 'messageType' => 7,
  6535. ]);
  6536. }
  6537. $result = Book::where("id", $data["id"])->update($data);
  6538. if (empty($result)) {
  6539. return Result::error("更新失败", 0);
  6540. }
  6541. return Result::success($result);
  6542. }
  6543. public function getBookInfo(array $data): array
  6544. {
  6545. $result = Book::where("id", $data["id"])->first();
  6546. if (empty($result)) {
  6547. return Result::error("获取失败", 0);
  6548. }
  6549. return Result::success($result);
  6550. }
  6551. public function updateBookStatus(array $data): array
  6552. {
  6553. //审核
  6554. unset($data['user_id']);
  6555. $bookInfo = Book::where("id", $data["id"])->first();
  6556. var_dump($bookInfo, '----');
  6557. if ($data['status'] == 2) {
  6558. $this->sendMessage([
  6559. 'talk_type' => 401,
  6560. 'title' => $bookInfo['title'],
  6561. 'content' => '审核通过',
  6562. 'messageType' => 7,
  6563. 'user_id' => $bookInfo['user_id'],
  6564. ]);
  6565. }
  6566. if ($data['status'] == 3) {
  6567. $this->sendMessage([
  6568. 'talk_type' => 401,
  6569. 'title' => $bookInfo['title'],
  6570. 'content' => '审核拒绝',
  6571. 'messageType' => 7,
  6572. 'user_id' => $bookInfo['user_id'],
  6573. ]);
  6574. }
  6575. if ($data['status'] == 1) {
  6576. $this->sendMessage([
  6577. 'talk_type' => 400,
  6578. 'title' => $bookInfo['title'],
  6579. 'content' => '提交了审核',
  6580. 'messageType' => 7,
  6581. // 'user_id'=>$bookInfo['user_id'],
  6582. ]);
  6583. }
  6584. $result = Book::where("id", $data["id"])->update($data);
  6585. if (empty($result)) {
  6586. return Result::error("更新失败", 0);
  6587. }
  6588. return Result::success($result);
  6589. }
  6590. //20250422 书刊音像
  6591. /**
  6592. * 贴身宝贝
  6593. * @param array $data
  6594. * @return array
  6595. */
  6596. public function getWebsiteTsbb(array $data): array
  6597. {
  6598. $month = $data['month'] ?? date('m');
  6599. $day = $data['day'] ?? date('d');
  6600. // 使用缓存键
  6601. $cacheKey = "tsbb_data_{$month}_{$day}";
  6602. // 尝试从缓存获取数据
  6603. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6604. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6605. if ($cachedData = $cache->get($cacheKey)) {
  6606. return Result::success(unserialize($cachedData));
  6607. }
  6608. //查询老黄历
  6609. try {
  6610. $date = date('Y-m-d');
  6611. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6612. // 使用 curl 替代 file_get_contents
  6613. $ch = curl_init();
  6614. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6615. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6616. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6617. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6618. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6619. 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');
  6620. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6621. 'Accept: application/json',
  6622. 'Content-Type: application/json',
  6623. 'Referer: https://www.36jxs.com/'
  6624. ]);
  6625. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6626. curl_setopt($ch, CURLOPT_ENCODING, '');
  6627. $almanacResponse = curl_exec($ch);
  6628. var_dump("====:", $almanacResponse);
  6629. if (curl_errno($ch)) {
  6630. var_dump('Curl error:', curl_error($ch));
  6631. throw new \Exception('Curl error: ' . curl_error($ch));
  6632. }
  6633. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6634. curl_close($ch);
  6635. if ($almanacResponse === false) {
  6636. throw new \Exception('Failed to fetch almanac data');
  6637. }
  6638. $almanacData = json_decode($almanacResponse, true);
  6639. if (json_last_error() !== JSON_ERROR_NONE) {
  6640. throw new \Exception('Failed to parse almanac data');
  6641. }
  6642. $almanacInfo = $almanacData['data'] ?? [];
  6643. } catch (\Exception $e) {
  6644. var_dump('Exception:', $e->getMessage());
  6645. $almanacInfo = [];
  6646. }
  6647. // 获取历史上的今天数据
  6648. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6649. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6650. ->orderBy('year', 'asc')
  6651. ->select("title", "id", "year", DB::raw('1 as type'))
  6652. ->limit(16)
  6653. ->get();
  6654. // 获取节日数据 - 从今天开始获取未来4条
  6655. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6656. ->orderBy('showtime', 'asc')
  6657. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6658. ->limit(16)
  6659. ->get();
  6660. //说文解字
  6661. $chartacterList = Character::orderBy('updated_at', 'desc')
  6662. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6663. ->limit(6)
  6664. ->get();
  6665. //谜语沙龙
  6666. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6667. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6668. ->limit(4)
  6669. ->get();
  6670. //成语欣赏
  6671. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6672. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6673. ->limit(32)
  6674. ->get();
  6675. //名联赏析
  6676. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6677. ->select("id", "first", "second", DB::raw('6 as type'))
  6678. ->limit(6)
  6679. ->get();
  6680. // 获取分类文章数据
  6681. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6682. ->pluck('category_id')
  6683. ->toArray();
  6684. $articlesList = [];
  6685. foreach ($categoryIds as $catid) {
  6686. // 先查有图片的
  6687. $withImg = DB::table('article')
  6688. ->where('status', 1)
  6689. ->where('catid', $catid)
  6690. ->whereNotNull('imgurl')
  6691. ->where('imgurl', '!=', '')
  6692. ->orderBy('updated_at', 'desc')
  6693. ->limit(6)
  6694. ->get();
  6695. $count = $withImg->count();
  6696. if ($count < 6) {
  6697. // 不足6条再查无图片的补足
  6698. $withoutImg = DB::table('article')
  6699. ->where('status', 1)
  6700. ->where('catid', $catid)
  6701. ->where(function ($q) {
  6702. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6703. })
  6704. ->orderBy('updated_at', 'desc')
  6705. ->limit(6 - $count)
  6706. ->get();
  6707. $articles = $withImg->concat($withoutImg);
  6708. } else {
  6709. $articles = $withImg;
  6710. }
  6711. // 组装
  6712. $category = \App\Model\Category::find($catid);
  6713. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6714. $articlesList[] = [
  6715. 'category_name' => $category ? $category->name : '',
  6716. 'catid' => $catid,
  6717. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6718. 'type' => 100,
  6719. 'list' => $articles->map(function ($item) {
  6720. return [
  6721. 'id' => $item->id,
  6722. 'title' => $item->title,
  6723. 'imgurl' => $item->imgurl,
  6724. 'created_at' => $item->created_at
  6725. ];
  6726. })->values()
  6727. ];
  6728. }
  6729. $result = [
  6730. 'almanac' => $almanacInfo,
  6731. 'historyTodayList' => [
  6732. 'category_name' => '历史上的今天',
  6733. 'list' => $historyTodayList,
  6734. 'type' => 1
  6735. ],
  6736. 'festivalList' => [
  6737. 'category_name' => '节日预告',
  6738. 'list' => $festivalList,
  6739. 'type' => 2
  6740. ],
  6741. 'chartacterList' => [
  6742. 'category_name' => '说文解字',
  6743. 'list' => $chartacterList,
  6744. 'type' => 3
  6745. ],
  6746. 'coupletList' => [
  6747. 'category_name' => '名联赏析',
  6748. 'list' => $coupletList,
  6749. 'type' => 6
  6750. ],
  6751. 'riddletList' => [
  6752. 'category_name' => '谜语沙龙',
  6753. 'list' => $riddletList,
  6754. 'type' => 4
  6755. ],
  6756. 'idiomList' => [
  6757. 'category_name' => '成语欣赏',
  6758. 'list' => $idiomList,
  6759. 'type' => 5
  6760. ],
  6761. 'articlesList' => $articlesList
  6762. ];
  6763. // 缓存结果,设置1小时过期
  6764. $cache->set($cacheKey, serialize($result), 3600);
  6765. return Result::success($result);
  6766. }
  6767. /**
  6768. * 获取资讯列表
  6769. */
  6770. public function getWebsiteTsbbList(array $data): array
  6771. {
  6772. $page = $data['page'] ?? 1;
  6773. $pageSize = $data['pageSize'] ?? 10;
  6774. // 如果没有传入月份和日期,则使用今天的日期
  6775. $month = $data['month'] ?? date('m');
  6776. $day = $data['day'] ?? date('d');
  6777. $total = 0;
  6778. $result = [];
  6779. $data['type'] = intval($data['type']);
  6780. var_dump("接收参数:", $data);
  6781. switch ($data['type']) {
  6782. case 1:
  6783. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6784. // 当前月份之后的数据
  6785. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6786. // 或者当前月份且日期大于等于当前日期的数据
  6787. ->orWhere(function ($q) use ($month, $day) {
  6788. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6789. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6790. });
  6791. })
  6792. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6793. $total = $query->count();
  6794. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6795. ->offset(($page - 1) * $pageSize)
  6796. ->limit($pageSize)
  6797. ->get();
  6798. break;
  6799. case 2:
  6800. $query = Festival::where(function ($q) use ($month, $day) {
  6801. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6802. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6803. ->orWhere(function ($q) use ($month, $day) {
  6804. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6805. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6806. });
  6807. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6808. $total = $query->count();
  6809. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6810. ->offset(($page - 1) * $pageSize)
  6811. ->limit($pageSize)
  6812. ->get();
  6813. break;
  6814. case 3:
  6815. $query = Character::orderBy("updated_at", "desc");
  6816. $total = $query->count();
  6817. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6818. ->offset(($page - 1) * $pageSize)
  6819. ->limit($pageSize)
  6820. ->get();
  6821. break;
  6822. case 4:
  6823. $query = Riddle::orderBy("updated_at", "desc");
  6824. $total = $query->count();
  6825. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6826. ->offset(($page - 1) * $pageSize)
  6827. ->limit($pageSize)
  6828. ->get();
  6829. break;
  6830. case 5:
  6831. $query = Idiom::orderBy("updated_at", "desc");
  6832. $total = $query->count();
  6833. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6834. ->offset(($page - 1) * $pageSize)
  6835. ->limit($pageSize)
  6836. ->get();
  6837. break;
  6838. case 6:
  6839. $query = Couplet::orderBy("updated_at", "desc");
  6840. $total = $query->count();
  6841. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6842. ->offset(($page - 1) * $pageSize)
  6843. ->limit($pageSize)
  6844. ->get();
  6845. break;
  6846. default:
  6847. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6848. $total = $query->count();
  6849. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6850. ->offset(($page - 1) * $pageSize)
  6851. ->limit($pageSize)
  6852. ->get();
  6853. }
  6854. return Result::success([
  6855. 'list' => $result,
  6856. 'total' => $total,
  6857. 'page' => (int)$page,
  6858. 'pageSize' => (int)$pageSize,
  6859. 'month' => $month,
  6860. 'day' => $day
  6861. ]);
  6862. }
  6863. /**
  6864. * 1:历史上的今天
  6865. * 2:节日
  6866. * 3:文章
  6867. *
  6868. * 资讯详情信息
  6869. */
  6870. public function getWebsiteTsbbDetail(array $data): array
  6871. {
  6872. $data['type'] = intval($data['type']);
  6873. switch ($data['type']) {
  6874. case 1:
  6875. $result = HistoryToday::where("id", $data['id'])->first();
  6876. break;
  6877. case 2:
  6878. $result = Festival::where("id", $data['id'])->first();
  6879. break;
  6880. case 3:
  6881. $result = Character::where("id", $data['id'])->first();
  6882. break;
  6883. case 4:
  6884. $result = Riddle::where("id", $data['id'])->first();
  6885. break;
  6886. case 5:
  6887. $result = Idiom::where("id", $data['id'])->first();
  6888. break;
  6889. case 6:
  6890. $result = Couplet::where("id", $data['id'])->first();
  6891. break;
  6892. default:
  6893. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6894. break;
  6895. }
  6896. return Result::success($result);
  6897. }
  6898. /**
  6899. * 农网导航首页数据
  6900. */
  6901. public function getWebsiteNwHomeList(array $data): array
  6902. {
  6903. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6904. ->pluck('category_id')
  6905. ->toArray();
  6906. // 使用子查询优化
  6907. $articlesList = DB::table('article')
  6908. ->select([
  6909. 'article.id',
  6910. 'article.title',
  6911. 'article.imgurl',
  6912. 'article.created_at',
  6913. 'category.name as category_name',
  6914. 'category.id as category_id',
  6915. 'website_category.aLIas_pinyin as pinyin',
  6916. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6917. DB::raw('100 as type')
  6918. ])
  6919. ->join('category', 'article.catid', '=', 'category.id')
  6920. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6921. ->leftJoin('website_category as parent_wc', function ($join) {
  6922. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6923. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6924. })
  6925. ->where('website_category.website_id', $data['website_id'])
  6926. ->where('article.status', 1)
  6927. ->whereIn('category.id', $categoryIds)
  6928. ->orderBy('article.created_at', 'desc')
  6929. ->get()
  6930. ->groupBy('category_id')
  6931. ->map(function ($group) {
  6932. // 确保第一条数据有图片
  6933. $firstWithImage = $group->first(function ($item) {
  6934. return !empty($item->imgurl);
  6935. });
  6936. if ($firstWithImage) {
  6937. // 如果有带图片的文章,将其放在第一位
  6938. $group = $group->filter(function ($item) use ($firstWithImage) {
  6939. return $item->id !== $firstWithImage->id;
  6940. })->prepend($firstWithImage);
  6941. }
  6942. return [
  6943. 'category_name' => $group->first()->category_name,
  6944. 'catid' => $group->first()->category_id,
  6945. 'pinyin' => $group->first()->pinyin,
  6946. 'parent_pinyin' => $group->first()->parent_pinyin,
  6947. 'list' => $group->take(4)->map(function ($item) {
  6948. return [
  6949. 'id' => $item->id,
  6950. 'title' => $item->title,
  6951. ];
  6952. })->values()
  6953. ];
  6954. })
  6955. ->values()
  6956. ->toArray();
  6957. return Result::success($articlesList);
  6958. }
  6959. /**
  6960. * 企业管理
  6961. * @param array $data
  6962. * @return array
  6963. */
  6964. public function getCompanyList(array $data): array
  6965. {
  6966. // return Result::success($data);
  6967. $where = [];
  6968. $user = User::where('id', $data['user_id'])->first();
  6969. if (empty($user)) {
  6970. return Result::error('用户不存在!');
  6971. }
  6972. if ($user['type_id'] != 10000) {
  6973. $where['user_id'] = $data['user_id'];
  6974. }
  6975. if (isset($data['title']) && !empty($data['title'])) {
  6976. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6977. }
  6978. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6979. array_push($where, ['website.id', $data['website_id']]);
  6980. }
  6981. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6982. if ($data['ischeck'] == 1) {
  6983. if (isset($data['status']) && $data['status'] != '') {
  6984. array_push($where, ['company.status', $data['status']]);
  6985. $query = Company::where($where);
  6986. } else {
  6987. $query = Company::whereIn('company.status', [0, 2]);
  6988. }
  6989. } else {
  6990. $query = Company::where('company.status', 1);
  6991. }
  6992. }
  6993. $result = $query->where($where)
  6994. ->leftJoin('website_category', function ($query) {
  6995. $query->on('website_category.category_id', '=', 'company.category_id')
  6996. ->on('website_category.website_id', '=', 'company.website_id');
  6997. })
  6998. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6999. ->select(
  7000. 'company.id',
  7001. 'company.title',
  7002. 'company.website_id',
  7003. 'company.category_id',
  7004. 'website.website_name',
  7005. 'website_category.alias as category_name',
  7006. 'company.status',
  7007. 'company.updated_at',
  7008. 'company.user_id'
  7009. )
  7010. ->orderBy('company.updated_at', 'desc')
  7011. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7012. if ($result->isEmpty()) {
  7013. return Result::error("暂无企业", 0);
  7014. }
  7015. return Result::success($result);
  7016. }
  7017. /**
  7018. * 添加企业
  7019. * @param array $data
  7020. * @return array
  7021. */
  7022. public function addCompany(array $data): array
  7023. {
  7024. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7025. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7026. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7027. $data['cat_arr_id'] = json_encode($car_arr_id);
  7028. } else {
  7029. $data['cat_arr_id'] = '';
  7030. }
  7031. if ($data['imgurl'] == '') {
  7032. //content中提取图片第一个图,正则提取
  7033. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7034. preg_match_all($reg, $data['content'], $matches);
  7035. if (isset($matches[1][0])) {
  7036. //截取varchar240
  7037. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7038. }
  7039. }
  7040. if ($data['keyword'] == '') {
  7041. //提取标题+内容中的关键词
  7042. $data['keyword'] = $data['title'];
  7043. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7044. Jieba::init(); // 初始化 jieba-php
  7045. Finalseg::init();
  7046. $segList = Jieba::cut($data['keyword']);
  7047. $segList1 = array_slice($segList, 0, 8);
  7048. $data['keyword'] = implode(',', $segList1);
  7049. }
  7050. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7051. //提取内容中的描述
  7052. $content = $data['content'];
  7053. // 去除 <style> 和 <script> 标签及其内容
  7054. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7055. // 去除所有 HTML 标签
  7056. $content = strip_tags($content);
  7057. // 去除 HTML 实体
  7058. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7059. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7060. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7061. // 去除多余空白
  7062. $content = preg_replace('/\s+/u', '', $content);
  7063. // 截取 100 个字符
  7064. $data['introduce'] = mb_substr($content, 0, 100);
  7065. }
  7066. $user = User::where('id', $data['user_id'])->first();
  7067. if (empty($user)) {
  7068. return Result::error('用户不存在!');
  7069. }
  7070. if ($user['type_id'] == 10000) {
  7071. $data['status'] = 1;
  7072. }
  7073. if (isset($data['level']) && $data['level'] != null) {
  7074. $data['level'] = intval($data['level']);
  7075. } else {
  7076. $data['level'] = null;
  7077. }
  7078. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7079. $this->sendMessage([
  7080. 'talk_type' => 900,
  7081. 'title' => $data['title'],
  7082. 'content' => '提交了审核',
  7083. 'messageType' => 8,
  7084. ]);
  7085. }
  7086. $result = Company::insertGetId($data);
  7087. if ($result) {
  7088. return Result::success($result);
  7089. } else {
  7090. return Result::error('添加失败');
  7091. }
  7092. }
  7093. /**
  7094. * 更新企业
  7095. * @param array $data
  7096. * @return array
  7097. */
  7098. public function upCompany(array $data): array
  7099. {
  7100. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7101. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7102. $data['cat_arr_id'] = json_encode($car_arr_id);
  7103. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7104. } else {
  7105. $data['cat_arr_id'] = '';
  7106. }
  7107. if ($data['imgurl'] == '') {
  7108. //content中提取图片第一个图,正则提取
  7109. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7110. preg_match_all($reg, $data['content'], $matches);
  7111. if (isset($matches[1][0])) {
  7112. //截取varchar
  7113. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7114. }
  7115. }
  7116. if ($data['keyword'] == '') {
  7117. //提取标题+内容中的关键词
  7118. $data['keyword'] = $data['title'];
  7119. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7120. Jieba::init(); // 初始化 jieba-php
  7121. Finalseg::init();
  7122. $segList = Jieba::cut($data['keyword']);
  7123. $segList1 = array_slice($segList, 0, 8);
  7124. $data['keyword'] = implode(',', $segList1);
  7125. }
  7126. if ($data['introduce'] == '') {
  7127. //提取内容中的描述
  7128. $content = $data['content'];
  7129. // 去除 <style> 和 <script> 标签及其内容
  7130. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7131. // 去除所有 HTML 标签
  7132. $content = strip_tags($content);
  7133. // 去除 HTML 实体
  7134. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7135. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7136. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7137. // 去除多余空白
  7138. $content = preg_replace('/\s+/u', '', $content);
  7139. // 截取 100 个字符
  7140. $data['introduce'] = mb_substr($content, 0, 100);
  7141. }
  7142. if (isset($data['level']) && $data['level'] != null) {
  7143. $data['level'] = intval($data['level']);
  7144. } else {
  7145. $data['level'] = null;
  7146. }
  7147. $user = User::where('id', $data['user_id'])->first();
  7148. if (empty($user)) {
  7149. return Result::error('用户不存在!');
  7150. }
  7151. if ($user['type_id'] == 10000) {
  7152. $data['status'] = 1;
  7153. } else {
  7154. $data['status'] = 0;
  7155. }
  7156. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7157. $this->sendMessage([
  7158. 'talk_type' => 900,
  7159. 'title' => $data['title'],
  7160. 'content' => '提交了审核',
  7161. 'messageType' => 8,
  7162. ]);
  7163. }
  7164. $result = Company::where('id', $data['id'])->update($data);
  7165. if ($result) {
  7166. return Result::success($result);
  7167. } else {
  7168. return Result::error('修改失败');
  7169. }
  7170. }
  7171. /**
  7172. * 删除企业
  7173. * @param array $data
  7174. * @return array
  7175. */
  7176. public function delCompany(array $data): array
  7177. {
  7178. $result = Company::where('id', $data['id'])->delete();
  7179. if ($result) {
  7180. return Result::success($result);
  7181. } else {
  7182. return Result::error('删除失败');
  7183. }
  7184. }
  7185. /**
  7186. * 审核企业
  7187. * @param array $data
  7188. * @return array
  7189. */
  7190. public function checkCompany(array $data): array
  7191. {
  7192. $user = User::where('id', $data['user_id'])->first();
  7193. if (empty($user)) {
  7194. return Result::error('用户不存在!');
  7195. }
  7196. $company = Company::where('id', $data['id'])->first();
  7197. if (empty($company)) {
  7198. return Result::error('企业不存在!');
  7199. }
  7200. // 状态:0:未审核 1:已审核 2:已拒绝
  7201. if ($data['status'] == 2 || $data['status'] == '2') {
  7202. $this->sendMessage([
  7203. 'talk_type' => 901,
  7204. 'title' => $company['title'],
  7205. 'content' => '审核拒绝',
  7206. 'messageType' => 8,
  7207. 'user_id' => $company['user_id'],
  7208. ]);
  7209. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7210. } else {
  7211. if ($data['status'] == 1) {
  7212. $this->sendMessage([
  7213. 'talk_type' => 901,
  7214. 'title' => $company['title'],
  7215. 'content' => '审核通过',
  7216. 'messageType' => 8,
  7217. 'user_id' => $company['user_id'],
  7218. ]);
  7219. } else if ($data['status'] == 0) {
  7220. $this->sendMessage([
  7221. 'talk_type' => 900,
  7222. 'title' => $company['title'],
  7223. 'content' => '提交了审核',
  7224. 'messageType' => 8,
  7225. ]);
  7226. }
  7227. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7228. }
  7229. if (empty($result)) {
  7230. return Result::error('审核失败!');
  7231. } else {
  7232. return Result::success($result);
  7233. }
  7234. }
  7235. /**
  7236. * 获取企业信息
  7237. * @param array $data
  7238. * @return array
  7239. */
  7240. public function getCompanyInfo(array $data): array
  7241. {
  7242. $result = Company::where('id', $data['id'])->first();
  7243. $city_arr = json_decode($result['city_arr_id']);
  7244. $result['city_name'] = District::whereIn('id', $city_arr)
  7245. ->pluck('name')
  7246. ->implode('-');
  7247. if (empty($result)) {
  7248. return Result::error('企业不存在!');
  7249. } else {
  7250. return Result::success($result);
  7251. }
  7252. }
  7253. /**
  7254. * @param array $data
  7255. * @return array
  7256. */
  7257. public function getWebsiteCompany(array $data): array
  7258. {
  7259. $categorys = json_decode($data['id'], true);
  7260. $category_arr = $this->processArticlePro($data['website_id']);
  7261. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7262. $catiall = $category_arr['catiall'];
  7263. $categoryIds = $category_arr['categoryIds'];
  7264. // return Result::success($category_arr);
  7265. foreach ($categorys as $key => $value) {
  7266. if (array_key_exists('level', $value)) {
  7267. $parts = explode(',', $value['level']);
  7268. $level = $parts[0] ?? null;
  7269. $imgnum = $parts[1] ?? null;
  7270. $textnum = $parts[2] ?? null;
  7271. if (!empty($textnum) && $textnum > 0) {
  7272. $text_num = Company::where('level', $level)
  7273. ->whereIn('category_id', $categoryIds)
  7274. ->where('status', 1)
  7275. ->select(
  7276. 'company.id',
  7277. 'company.title',
  7278. 'company.description',
  7279. 'company.updated_at',
  7280. 'company.category_id',
  7281. 'company.cat_arr_id'
  7282. )
  7283. ->orderBy('updated_at', 'desc')
  7284. ->limit($textnum)
  7285. ->get()->all();
  7286. }
  7287. if (!empty($imgnum) && $imgnum > 0) {
  7288. $img_num = Company::where('level', $level)
  7289. ->whereIn('category_id', $categoryIds)
  7290. ->where('status', 1)
  7291. ->where('imgurl', '!=', '')
  7292. ->whereNotNull('imgurl')
  7293. ->select(
  7294. 'company.id',
  7295. 'company.title',
  7296. 'company.description',
  7297. 'company.updated_at',
  7298. 'company.imgurl as imgs',
  7299. 'company.category_id',
  7300. 'company.cat_arr_id'
  7301. )
  7302. ->orderBy('updated_at', 'desc')
  7303. ->limit($imgnum)
  7304. ->get()->all();
  7305. }
  7306. }
  7307. if (array_key_exists('id', $value)) {
  7308. $parts = explode(',', $value['id']);
  7309. $category_id = $parts[0] ?? null;
  7310. $imgnum = $parts[1] ?? null;
  7311. $textnum = $parts[2] ?? null;
  7312. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7313. if (!empty($textnum) && $textnum > 0) {
  7314. $text_num = Company::whereIn('category_id', $category_arr)
  7315. // ->where('website_id', $data['website_id'])
  7316. ->where('status', 1)
  7317. ->select(
  7318. 'company.id',
  7319. 'company.title',
  7320. 'company.description',
  7321. 'company.updated_at',
  7322. 'company.category_id',
  7323. 'company.cat_arr_id'
  7324. )
  7325. ->orderBy('updated_at', 'desc')
  7326. ->limit($textnum)
  7327. ->get()->all();
  7328. }
  7329. if (!empty($imgnum) && $imgnum > 0) {
  7330. $img_num = Company::whereIn('category_id', $category_arr)
  7331. // ->where('website_id', $data['website_id'])
  7332. ->where('status', 1)
  7333. ->where('imgurl', '!=', '')
  7334. ->whereNotNull('imgurl')
  7335. ->select(
  7336. 'company.id',
  7337. 'company.title',
  7338. 'company.description',
  7339. 'company.updated_at',
  7340. 'company.imgurl as imgs',
  7341. 'company.category_id',
  7342. 'company.cat_arr_id'
  7343. )
  7344. ->orderBy('updated_at', 'desc')
  7345. ->limit($imgnum)
  7346. ->get()->all();
  7347. }
  7348. }
  7349. if (!empty($text_num)) {
  7350. foreach ($text_num as $k => $v) {
  7351. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7352. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7353. }
  7354. }
  7355. if (!empty($img_num)) {
  7356. foreach ($img_num as $k => $v) {
  7357. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7358. $imgurl = json_decode($v['imgs'], true);
  7359. if (!empty($imgurl)) {
  7360. $img_num[$k]->imgurl = $imgurl[0];
  7361. }
  7362. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7363. }
  7364. }
  7365. $company[$key]['img_num'] = $img_num ?? [];
  7366. $company[$key]['text_num'] = $text_num ?? [];
  7367. }
  7368. if (empty($company)) {
  7369. return Result::error("暂无相关企业信息", 0);
  7370. }
  7371. return Result::success($company);
  7372. }
  7373. /**
  7374. * @param array $data
  7375. * @return array
  7376. */
  7377. public function getWebsiteCompanyList(array $data): array
  7378. {
  7379. $where['website_id'] = $data['website_id'];
  7380. $where['status'] = 1;
  7381. $categoryIds = [];
  7382. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7383. $category_id = $data['category_id'];
  7384. }
  7385. $category_arr = $this->processArticlePro($data['website_id']);
  7386. $categoryIds = $category_arr['categoryIds'];
  7387. // return Result::success($cat_1st_arr);
  7388. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7389. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7390. })
  7391. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7392. $query->whereIn('category_id', $categoryIds);
  7393. })
  7394. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7395. $query->where('category_id', $category_id);
  7396. })
  7397. ->where('status',1)
  7398. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7399. ->orderBy('updated_at', 'desc')
  7400. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7401. if (empty($company)) {
  7402. return Result::error("暂无相关公司信息", 0);
  7403. }
  7404. $result = [
  7405. 'count' => $company->total(),
  7406. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7407. ];
  7408. return Result::success($result);
  7409. }
  7410. /**
  7411. * 获取项目列表
  7412. * @param array $data
  7413. * @return array
  7414. */
  7415. public function getProjectList(array $data): array
  7416. {
  7417. $where = [];
  7418. $user = User::where('id', $data['user_id'])->first();
  7419. if (empty($user)) {
  7420. return Result::error('用户不存在!');
  7421. }
  7422. if ($user->type_id != 10000) {
  7423. array_push($where, ['project.user_id', $data['user_id']]);
  7424. }
  7425. $query = Project::query();
  7426. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7427. array_push($where, ['project.website_id', $data['website_id']]);
  7428. }
  7429. if (isset($data['title']) && !empty($data['title'])) {
  7430. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7431. }
  7432. if ($data['status'] != 3) {
  7433. array_push($where, ['project.status', $data['status']]);
  7434. }
  7435. $query = Project::where($where)
  7436. ->when($data['status'] == 3, function ($query) {
  7437. $query->whereIn('project.status', [0, 2]);
  7438. });
  7439. $count = $query->clone()
  7440. ->count();
  7441. $rows = $query->clone()
  7442. ->leftJoin('website', 'project.website_id', 'website.id')
  7443. ->leftJoin('website_category', function ($join) {
  7444. $join->on('project.website_id', '=', 'website_category.website_id')
  7445. ->on('project.category_id', '=', 'website_category.category_id');
  7446. })
  7447. ->select(
  7448. 'project.id',
  7449. 'project.title',
  7450. 'project.updated_at',
  7451. 'project.status',
  7452. 'website.website_name',
  7453. 'website_category.alias as category_name',
  7454. 'project.website_id',
  7455. 'project.user_id'
  7456. )
  7457. ->orderBy('project.updated_at', 'desc')
  7458. ->offset(($data['page'] - 1) * $data['pageSize'])
  7459. ->limit($data['pageSize'])
  7460. ->get();
  7461. if ($rows->isEmpty()) {
  7462. return Result::error("暂无相关项目信息", 0);
  7463. }
  7464. $result = [
  7465. 'count' => $count,
  7466. 'rows' => $rows,
  7467. ];
  7468. return Result::success($result);
  7469. }
  7470. /**
  7471. * 添加项目
  7472. * @param array $data
  7473. * @return array
  7474. */
  7475. public function addProject(array $data): array
  7476. {
  7477. $user = User::where('id', $data['user_id'])->first();
  7478. if (empty($user)) {
  7479. return Result::error("暂无相关用户信息", 0);
  7480. }
  7481. if ($user->type_id == 10000) {
  7482. $data['status'] = 1;
  7483. } else {
  7484. $data['status'] = 0;
  7485. }
  7486. if ($data['keyword'] == '') {
  7487. //提取标题+内容中的关键词
  7488. $data['keyword'] = $data['title'];
  7489. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7490. Jieba::init(); // 初始化 jieba-php
  7491. Finalseg::init();
  7492. $segList = Jieba::cut($data['keyword']);
  7493. $segList1 = array_slice($segList, 0, 8);
  7494. $data['keyword'] = implode(',', $segList1);
  7495. }
  7496. if ($data['description'] == '') {
  7497. //提取内容中的描述
  7498. // var_dump(11111);
  7499. //提取内容中的描述
  7500. $content = $data['introduce'];
  7501. // 去除 <style> 和 <script> 标签及其内容
  7502. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7503. // 去除所有 HTML 标签
  7504. $content = strip_tags($content);
  7505. // 去除 HTML 实体
  7506. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7507. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7508. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7509. // 去除多余空白
  7510. $content = preg_replace('/\s+/u', '', $content);
  7511. // 截取 100 个字符
  7512. $data['description'] = mb_substr($content, 0, 100);
  7513. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7514. }
  7515. if ($data['status'] == 0) {
  7516. $this->sendMessage([
  7517. 'talk_type' => 1000,
  7518. 'title' => $data['title'],
  7519. 'content' => '提交了审核',
  7520. 'messageType' => 9,
  7521. ]);
  7522. }
  7523. $project = Project::insertGetId($data);
  7524. if (empty($project)) {
  7525. return Result::error("暂无相关项目信息", 0);
  7526. }
  7527. return Result::success($project);
  7528. }
  7529. /**
  7530. * 更新项目
  7531. * @param array $data
  7532. * @return array
  7533. */
  7534. public function upProject(array $data): array
  7535. {
  7536. $project = Project::where('id', $data['id'])->first();
  7537. if (empty($project)) {
  7538. return Result::error("暂无相关项目信息", 0);
  7539. }
  7540. $id = $data['id'];
  7541. unset($data['id']);
  7542. $user = User::where('id', $data['user_id'])->first();
  7543. if (empty($user)) {
  7544. return Result::error("暂无相关用户信息", 0);
  7545. }
  7546. if ($user->type_id == 10000) {
  7547. $data['status'] = 1;
  7548. } else {
  7549. $data['status'] = 0;
  7550. }
  7551. unset($data['user_id']);
  7552. if ($data['keyword'] == '') {
  7553. //提取标题+内容中的关键词
  7554. $data['keyword'] = $data['title'];
  7555. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7556. Jieba::init(); // 初始化 jieba-php
  7557. Finalseg::init();
  7558. $segList = Jieba::cut($data['keyword']);
  7559. $segList1 = array_slice($segList, 0, 8);
  7560. $data['keyword'] = implode(',', $segList1);
  7561. }
  7562. if ($data['description'] == '') {
  7563. //提取内容中的描述
  7564. // var_dump(11111);
  7565. //提取内容中的描述
  7566. $content = $data['introduce'];
  7567. // 去除 <style> 和 <script> 标签及其内容
  7568. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7569. // 去除所有 HTML 标签
  7570. $content = strip_tags($content);
  7571. // 去除 HTML 实体
  7572. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7573. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7574. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7575. // 去除多余空白
  7576. $content = preg_replace('/\s+/u', '', $content);
  7577. // 截取 100 个字符
  7578. $data['description'] = mb_substr($content, 0, 100);
  7579. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7580. }
  7581. if ($data['status'] == 0) {
  7582. $this->sendMessage([
  7583. 'talk_type' => 1000,
  7584. 'title' => $data['title'],
  7585. 'content' => '提交了审核',
  7586. 'messageType' => 9,
  7587. ]);
  7588. }
  7589. $result = Project::where('id', $id)->update($data);
  7590. if (empty($result)) {
  7591. return Result::error("更新失败", 0);
  7592. }
  7593. return Result::success($result);
  7594. }
  7595. /**
  7596. * 删除项目
  7597. * @param array $data
  7598. * @return array
  7599. */
  7600. public function delProject(array $data): array
  7601. {
  7602. $user = User::where('id', $data['user_id'])->first();
  7603. if (empty($user)) {
  7604. return Result::error("暂无相关用户信息", 0);
  7605. }
  7606. $project = Project::where('id', $data['id'])->first();
  7607. if (empty($project)) {
  7608. return Result::error("暂无相关项目信息", 0);
  7609. }
  7610. $result = Project::where('id', $data['id'])->delete();
  7611. if (empty($result)) {
  7612. return Result::error("删除失败", 0);
  7613. }
  7614. return Result::success($result);
  7615. }
  7616. /**
  7617. * 审核项目
  7618. * @param array $data
  7619. * @return array
  7620. */
  7621. public function checkProject(array $data): array
  7622. {
  7623. $user = User::where('id', $data['user_id'])->first();
  7624. if (empty($user)) {
  7625. return Result::error("暂无相关用户信息", 0);
  7626. }
  7627. // 0:未审核; 1:已审核; 2:已拒绝;
  7628. if ($user->type_id != 10000) {
  7629. if ($data['status'] == 1 || $data['status'] == 2) {
  7630. return Result::error("此用户权限不足", 0);
  7631. }
  7632. }
  7633. $project = Project::where('id', $data['id'])->first();
  7634. if (empty($project)) {
  7635. return Result::error("暂无相关项目信息", 0);
  7636. }
  7637. if ($data['status'] == 2) {
  7638. $this->sendMessage([
  7639. 'talk_type' => 1001,
  7640. 'title' => $project['title'],
  7641. 'content' => '审核拒绝',
  7642. 'messageType' => 9,
  7643. 'user_id' => $project['user_id'],
  7644. ]);
  7645. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7646. } else {
  7647. if ($data['status'] == 1) {
  7648. $this->sendMessage([
  7649. 'talk_type' => 1001,
  7650. 'title' => $project['title'],
  7651. 'content' => '审核通过',
  7652. 'messageType' => 9,
  7653. 'user_id' => $project['user_id'],
  7654. ]);
  7655. } else if ($data['status'] == 0) {
  7656. $this->sendMessage([
  7657. 'talk_type' => 1000,
  7658. 'title' => $project['title'],
  7659. 'content' => '提交了审核',
  7660. 'messageType' => 9,
  7661. ]);
  7662. }
  7663. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7664. }
  7665. if (empty($result)) {
  7666. return Result::error("审核失败", 0);
  7667. }
  7668. return Result::success($result);
  7669. }
  7670. /**
  7671. * 获取项目详情
  7672. * @param array $data
  7673. * @return array
  7674. */
  7675. public function getProjectInfo(array $data): array
  7676. {
  7677. $project = Project::where('id', $data['id'])->first();
  7678. if (empty($project)) {
  7679. return Result::error("暂无相关项目信息", 0);
  7680. }
  7681. return Result::success($project);
  7682. }
  7683. public function getWebsiteCompanyInfo(array $data): array
  7684. {
  7685. $company = Company::where('id', $data['id'])
  7686. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7687. ->where('status', 1)
  7688. // ->where('website_id', $data['website_id'])
  7689. ->select('company.*', 'job_industry.hyname as hy_name')
  7690. ->first();
  7691. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7692. $jobnature_id = $company['jobnature_id'] ?? null;
  7693. if ($jobnature_id !== null) {
  7694. switch ($jobnature_id) {
  7695. case 0:
  7696. $company->jobnature_name = '市场监督';
  7697. break;
  7698. case 1:
  7699. $company->jobnature_name = '信访纪检';
  7700. break;
  7701. case 2:
  7702. $company->jobnature_name = '公检法司';
  7703. break;
  7704. case 3:
  7705. $company->jobnature_name = '高关注机构';
  7706. break;
  7707. default:
  7708. $company->jobnature_name = '';
  7709. break;
  7710. }
  7711. } else {
  7712. $company->jobnature_name = '';
  7713. }
  7714. $city_arr = $company->city_arr_id;
  7715. if (!empty($city_arr)) {
  7716. $city_arr = json_decode($city_arr, true);
  7717. $cityNames = District::whereIn('id', $city_arr)
  7718. ->pluck('name')
  7719. ->implode('-');
  7720. $company->city_name = $cityNames;
  7721. } else {
  7722. $company->city_name = '';
  7723. }
  7724. if (empty($company)) {
  7725. return Result::error("暂无相关公司信息", 0);
  7726. }
  7727. return Result::success($company);
  7728. }
  7729. public function getMSG(array $data): array
  7730. {
  7731. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7732. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7733. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7734. $result = [];
  7735. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7736. //最近的5篇已审的文章
  7737. $apply_articale = Article::where('status', 1)
  7738. ->where('admin_user_id', $user_id)
  7739. ->orderBy('updated_at', 'desc')
  7740. // ->limit(5)
  7741. ->get();
  7742. //获取5条用户的已审核商品
  7743. $good = Good::where('status', 2)
  7744. ->where('user_id', $user_id)
  7745. ->orderBy('updated_at', 'desc')
  7746. // ->limit(5)
  7747. ->get();
  7748. //获取5条用户待审核的公告
  7749. $notice = Notice::where('status', 2)
  7750. ->where('user_id', $user_id)
  7751. ->orderBy('updated_at', 'desc')
  7752. ->limit(5)->get();
  7753. //获取5条用户的待审核投诉
  7754. $complaint = Complaint::where('status', 2)
  7755. ->where('user_id', $user_id)
  7756. ->orderBy('updated_at', 'desc')
  7757. // ->limit(5)
  7758. ->get();
  7759. //获取5条用户的book
  7760. $book = Book::where('status', 2)
  7761. ->where('user_id', $user_id)
  7762. ->orderBy('updated_at', 'desc')
  7763. // ->limit(5)
  7764. ->get();
  7765. //获取5条用户的求职
  7766. //获取5条用户的求职 1
  7767. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7768. ->where('job_hunting.user_id', $user_id)
  7769. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7770. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7771. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7772. ->orderBy('updated_at', 'desc')
  7773. // ->limit(5)
  7774. ->get();
  7775. //获取5条用户的求职 2
  7776. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7777. ->where('job_recruiting.user_id', $user_id)
  7778. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7779. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7780. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7781. ->orderBy('updated_at', 'desc')
  7782. // ->limit(5)
  7783. ->get();
  7784. //人才库 1
  7785. $job_apply = JobApply::where('job_apply.status', 1)
  7786. ->where('job_apply.receiver_id', $user_id)
  7787. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7788. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7789. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7790. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7791. ->select('job_recruiting', 'job_recruiting.', '', '')
  7792. ->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')
  7793. ->orderBy('updated_at', 'desc')
  7794. // ->limit(5)
  7795. ->get();
  7796. // 职场机会 2
  7797. $job_resume = JobResume::where('job_resume.status', 1)
  7798. ->where('job_resume.receiver_id', $user_id)
  7799. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7800. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7801. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7802. ->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')
  7803. ->orderBy('updated_at', 'desc')
  7804. // ->limit(5)
  7805. ->get();
  7806. //获取5条用户待处理的投诉
  7807. $complaint_deal = Complaint::where('status', 2)
  7808. ->where('deal', 1)
  7809. ->whereJsonContains('re_user_ids', $user_id)
  7810. ->orderBy('updated_at', 'desc')
  7811. // ->limit(5)
  7812. ->get();
  7813. //获取 被通知者未读信息
  7814. $notice_unread = Notice::where('status', 2)
  7815. ->whereJsonContains('re_user_ids', $user_id)
  7816. //未读消息
  7817. ->where(function ($query) use ($user_id) {
  7818. $query->whereJsonDoesntContain('read_id', $user_id)
  7819. ->orWhereNull('read_id');
  7820. })
  7821. ->orderBy('updated_at', 'desc')
  7822. ->get();
  7823. $complaint_unread = Complaint::where('status', 2)
  7824. ->whereJsonContains('re_user_ids', $user_id)
  7825. //未读消息
  7826. ->where(function ($query) use ($user_id) {
  7827. $query->whereJsonDoesntContain('read_id', $user_id)
  7828. ->orWhereNull('read_id');
  7829. })
  7830. ->orderBy('updated_at', 'desc')
  7831. ->get();
  7832. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7833. $complany = Company::where('status', 1)
  7834. ->where('user_id', $user_id)
  7835. ->orderBy('updated_at', 'desc')
  7836. // ->limit(5)
  7837. ->get();
  7838. //获取5条单聊未读聊天消息
  7839. // $chat = ChatRecords::where('is_read', 0)
  7840. // ->where('user_id', $user_id)
  7841. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7842. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7843. // ->where('action', 'recieved')
  7844. // ->where('talk_type', 1)
  7845. // ->orderBy('created_at', 'desc')
  7846. // // ->limit(5)
  7847. // ->get();
  7848. //获取5条未读群聊信息
  7849. // $chat_group = ChatRecords::where('is_read', 0)
  7850. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7851. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7852. // ->where('user_id', $user_id)
  7853. // ->where('talk_type', 2)
  7854. // ->orderBy('created_at', 'desc')
  7855. // // ->limit(5)
  7856. // ->get();
  7857. //获取5条用户的待审核项目
  7858. $project = Project::where('status', 1)
  7859. ->where('user_id', $user_id)
  7860. ->orderBy('updated_at', 'desc')
  7861. // ->limit(5)
  7862. ->get();
  7863. // count($chat) + count($chat_group) +
  7864. $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)
  7865. + count($complany)
  7866. + count($project)
  7867. + count($notice_unread)
  7868. + count($complaint_unread)
  7869. // + count($chat) + count($chat_group)
  7870. ;
  7871. $result = [
  7872. 'apply_articale' => $apply_articale,
  7873. // 'chat' => $chat,
  7874. // 'chat_group' => $chat_group,
  7875. 'good' => $good,
  7876. 'notice' => $notice,
  7877. 'complaint' => $complaint,
  7878. 'book' => $book,
  7879. 'job_hunting' => $job_hunting,
  7880. 'job_recruiting' => $job_recruiting,
  7881. 'job_apply' => $job_apply,
  7882. 'job_resume' => $job_resume,
  7883. 'complaint_deal' => $complaint_deal,
  7884. 'complany' => $complany,
  7885. 'project' => $project,
  7886. 'notice_unread' => $notice_unread,
  7887. 'complaint_unread' => $complaint_unread,
  7888. 'count' => $count,
  7889. ];
  7890. } elseif ($type_id == 12) {
  7891. //最近的5篇已审的文章
  7892. $apply_articale = Article::where('status', 1)
  7893. ->where('admin_user_id', $user_id)
  7894. ->limit(5)->get();
  7895. //获取5条单聊未读聊天消息
  7896. $chat = ChatRecords::where('is_read', 0)
  7897. ->where('user_id', $user_id)
  7898. ->where('talk_type', 1)
  7899. ->orderBy('created_at', 'desc')
  7900. ->limit(5)->get();
  7901. //获取5条未读群聊信息
  7902. $chat_group = ChatRecords::where('is_read', 0)
  7903. ->where('user_id', $user_id)
  7904. ->where('talk_type', 2)
  7905. ->orderBy('created_at', 'desc')
  7906. ->limit(5)->get();
  7907. //获取5条用户的已审核商品
  7908. $good = Good::where('status', 2)
  7909. ->where('user_id', $user_id)
  7910. ->orderBy('updated_at', 'desc')
  7911. ->limit(5)->get();
  7912. //获取5条用户的book
  7913. $book = Book::where('status', 2)
  7914. ->where('user_id', $user_id)
  7915. ->orderBy('updated_at', 'desc')
  7916. ->limit(5)->get();
  7917. //获取5条用户的求职
  7918. //获取5条用户的求职 1
  7919. //count($chat) + count($chat_group)
  7920. $count = count($apply_articale) + count($good);
  7921. $result = [
  7922. 'apply_articale' => $apply_articale,
  7923. 'chat' => $chat,
  7924. 'chat_group' => $chat_group,
  7925. 'good' => $good,
  7926. 'book' => $book,
  7927. 'count' => $count,
  7928. ];
  7929. } elseif ($type_id == 13) {
  7930. //最近的5篇已审的文章
  7931. $apply_articale = Article::where('status', 1)
  7932. ->where('admin_user_id', $user_id)
  7933. ->limit(5)->get();
  7934. //获取5条单聊未读聊天消息
  7935. $chat = ChatRecords::where('is_read', 0)
  7936. ->where('user_id', $user_id)
  7937. ->where('talk_type', 1)
  7938. ->orderBy('created_at', 'desc')
  7939. ->limit(5)->get();
  7940. //获取5条未读群聊信息
  7941. $chat_group = ChatRecords::where('is_read', 0)
  7942. ->where('user_id', $user_id)
  7943. ->where('talk_type', 2)
  7944. ->orderBy('created_at', 'desc')
  7945. ->limit(5)->get();
  7946. //获取5条用户的已审核商品
  7947. $good = Good::where('status', 2)
  7948. ->where('user_id', $user_id)
  7949. ->orderBy('updated_at', 'desc')
  7950. ->limit(5)->get();
  7951. //count($chat) + count($chat_group) +
  7952. $count = count($apply_articale) + count($good);
  7953. $result = [
  7954. 'apply_articale' => $apply_articale,
  7955. 'chat' => $chat,
  7956. 'chat_group' => $chat_group,
  7957. 'good' => $good,
  7958. 'count' => $count,
  7959. ];
  7960. } elseif ($type_id == 14) {
  7961. //最近的5篇已审的文章
  7962. $apply_articale = Article::where('status', 1)
  7963. ->where('admin_user_id', $user_id)
  7964. // ->limit(5)
  7965. ->get();
  7966. //获取5条用户的已审核商品
  7967. $good = Good::where('status', 2)
  7968. ->where('user_id', $user_id)
  7969. ->orderBy('updated_at', 'desc')
  7970. // ->limit(5)
  7971. ->get();
  7972. $count = count($apply_articale) + count($good);
  7973. $result = [
  7974. 'apply_articale' => $apply_articale,
  7975. 'chat' => '',
  7976. 'chat_group' => '',
  7977. 'good' => $good,
  7978. 'count' => $count,
  7979. ];
  7980. } elseif ($type_id == 10000) {
  7981. //获取未审核的5篇文章
  7982. $apply_articale = Article::where('status', 0)
  7983. ->orderBy('updated_at', 'desc')
  7984. // ->limit(5)
  7985. ->get();
  7986. //获取5条单聊未读聊天消息
  7987. //获取5条单聊未读聊天消息
  7988. // $chat = ChatRecords::where('is_read', 0)
  7989. // ->where('user_id', $user_id)
  7990. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7991. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7992. // ->where('action', 'recieved')
  7993. // ->where('talk_type', 1)
  7994. // ->orderBy('created_at', 'desc')
  7995. // // ->limit(5)
  7996. // ->get();
  7997. // //获取5条未读群聊信息
  7998. // $chat_group = ChatRecords::where('is_read', 0)
  7999. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8000. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8001. // ->where('user_id', $user_id)
  8002. // ->where('talk_type', 2)
  8003. // ->orderBy('created_at', 'desc')
  8004. // // ->limit(5)
  8005. // ->get();
  8006. //获取5条用户的已审核商品
  8007. $good = Good::where('status', 1)
  8008. // ->where('user_id', $user_id)
  8009. ->orderBy('updated_at', 'desc')
  8010. // ->limit(5)
  8011. ->get();
  8012. //获取5条用户待审核的公告
  8013. $notice = Notice::where('status', 1)
  8014. ->orderBy('updated_at', 'desc')
  8015. // ->limit(5)
  8016. ->get();
  8017. //获取5条用户的待审核投诉
  8018. $complaint = Complaint::where('status', 1)
  8019. ->orderBy('updated_at', 'desc')
  8020. // ->limit(5)
  8021. ->get();
  8022. //获取5条用户的book
  8023. $book = Book::where('status', 1)
  8024. ->orderBy('updated_at', 'desc')
  8025. // ->limit(5)
  8026. ->get();
  8027. //获取5条用户的求职 1
  8028. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8029. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8030. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8031. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8032. ->orderBy('updated_at', 'desc')
  8033. // ->limit(5)
  8034. ->get();
  8035. //获取5条用户的求职 2
  8036. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8037. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8038. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8039. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8040. ->orderBy('updated_at', 'desc')
  8041. // ->limit(5)
  8042. ->get();
  8043. //人才库 1
  8044. $job_apply = JobApply::where('job_apply.status', 1)
  8045. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8046. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8047. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8048. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8049. ->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')
  8050. ->orderBy('updated_at', 'desc')
  8051. // ->limit(5)
  8052. ->get();
  8053. // 职场机会 2
  8054. $job_resume = JobResume::where('job_resume.status', 1)
  8055. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8056. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8057. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8058. ->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')
  8059. ->orderBy('updated_at', 'desc')
  8060. // ->limit(5)
  8061. ->get();
  8062. //待审核数据com pro
  8063. $complany = Company::where('status', 0)
  8064. ->orderBy('updated_at', 'desc')
  8065. // ->limit(5)
  8066. ->get();
  8067. $project = Project::where('status', 0)
  8068. ->orderBy('updated_at', 'desc')
  8069. // ->limit(5)
  8070. ->get();
  8071. $count =
  8072. // count($chat) +
  8073. // count($chat_group) +
  8074. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8075. // + count($job_apply)
  8076. // + count($job_resume)
  8077. + count($complany)
  8078. + count($project);
  8079. $result = [
  8080. 'apply_articale' => $apply_articale,
  8081. // 'chat' => $chat,
  8082. // 'chat_group' => $chat_group,
  8083. 'good' => $good,
  8084. 'notice' => $notice,
  8085. 'complaint' => $complaint,
  8086. 'book' => $book,
  8087. 'job_hunting' => $job_hunting,
  8088. 'job_recruiting' => $job_recruiting,
  8089. // 'job_apply' => $job_apply,
  8090. // 'job_resume' => $job_resume,
  8091. 'complany' => $complany,
  8092. 'project' => $project,
  8093. 'count' => $count,
  8094. ];
  8095. } elseif ($type_id == 20000) {
  8096. }
  8097. var_dump($type_id, '-----------------test---------');
  8098. return Result::success($result);
  8099. }
  8100. /**
  8101. * @param array $data
  8102. * @return array
  8103. */
  8104. public function getWebsiteProject(array $data): array
  8105. {
  8106. $categorys = json_decode($data['id'], true);
  8107. if (!empty($categorys)) {
  8108. $category_arr = $this->processArticlePro($data['website_id']);
  8109. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8110. $catiall = $category_arr['catiall'];
  8111. // return Result::success($catiall);
  8112. foreach ($categorys as $key => $val) {
  8113. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8114. $level = explode(',', $val['level'])[0];
  8115. $imgnum = explode(',', $val['level'])[1] ?? null;
  8116. $textnum = explode(',', $val['level'])[2] ?? null;
  8117. if ($level == 1) {
  8118. if (!empty($textnum) && $textnum > 0) {
  8119. $text_num = Project::where('level', $level)
  8120. ->where('website_id', $data['website_id'])
  8121. ->where('status', 1)
  8122. ->select(
  8123. 'project.id',
  8124. 'project.title',
  8125. 'project.description',
  8126. 'project.updated_at',
  8127. 'project.category_id',
  8128. 'project.cat_arr_id'
  8129. )
  8130. ->orderBy('updated_at', 'desc')
  8131. ->limit($textnum)
  8132. ->get()->all();
  8133. }
  8134. if (!empty($imgnum) && $imgnum > 0) {
  8135. $img_num = Project::where('level', $level)
  8136. ->where('website_id', $data['website_id'])
  8137. ->where('status', 1)
  8138. ->where('imgurl', '!=', '')
  8139. ->whereNotNull('imgurl')
  8140. ->select(
  8141. 'project.id',
  8142. 'project.title',
  8143. 'project.description',
  8144. 'project.updated_at',
  8145. 'project.imgurl as imgs',
  8146. 'project.category_id',
  8147. 'project.cat_arr_id'
  8148. )
  8149. ->orderBy('updated_at', 'desc')
  8150. ->limit($imgnum)
  8151. ->get()->all();
  8152. }
  8153. } else {
  8154. if (!empty($textnum) && $textnum > 0) {
  8155. $text_num = Project::where('website_id', $data['website_id'])
  8156. ->where('status', 1)
  8157. ->select(
  8158. 'project.id',
  8159. 'project.title',
  8160. 'project.description',
  8161. 'project.updated_at',
  8162. 'project.category_id',
  8163. 'project.cat_arr_id',
  8164. 'project.website_id',
  8165. 'project.updated_at',
  8166. 'project.created_at'
  8167. )
  8168. ->orderBy('updated_at', 'desc')
  8169. ->limit($textnum)
  8170. ->get()->all();
  8171. }
  8172. if (!empty($imgnum) && $imgnum > 0) {
  8173. $img_num = Project::where('website_id', $data['website_id'])
  8174. ->where('status', 1)
  8175. ->where('imgurl', '!=', '')
  8176. ->whereNotNull('imgurl')
  8177. ->select(
  8178. 'project.id',
  8179. 'project.title',
  8180. 'project.description',
  8181. 'project.updated_at',
  8182. 'project.imgurl as imgs',
  8183. 'project.category_id',
  8184. 'project.cat_arr_id'
  8185. )
  8186. ->orderBy('updated_at', 'desc')
  8187. ->limit($imgnum)
  8188. ->get()->all();
  8189. }
  8190. }
  8191. }
  8192. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8193. $category_ids = explode(',', $val['id'])[0];
  8194. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8195. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8196. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8197. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8198. $text_num = Project::whereIn('category_id', $category_arr)
  8199. ->where('website_id', $data['website_id'])
  8200. ->where('status', 1)
  8201. ->select(
  8202. 'project.id',
  8203. 'project.title',
  8204. 'project.description',
  8205. 'project.updated_at',
  8206. 'project.category_id',
  8207. 'project.cat_arr_id'
  8208. )
  8209. ->orderBy('updated_at', 'desc')
  8210. ->limit($cat_textnum)
  8211. ->get()->all();
  8212. }
  8213. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8214. $img_num = Project::whereIn('category_id', $category_arr)
  8215. ->where('website_id', $data['website_id'])
  8216. ->where('status', 1)
  8217. ->where('imgurl', '!=', '')
  8218. ->whereNotNull('imgurl')
  8219. ->select(
  8220. 'project.id',
  8221. 'project.title',
  8222. 'project.description',
  8223. 'project.updated_at',
  8224. 'project.imgurl as imgs',
  8225. 'project.category_id',
  8226. 'project.cat_arr_id'
  8227. )
  8228. ->orderBy('updated_at', 'desc')
  8229. ->limit($cat_imgnum)
  8230. ->get()->all();
  8231. }
  8232. }
  8233. if (!empty($img_num)) {
  8234. foreach ($img_num as $k => $v) {
  8235. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8236. $imgurl = json_decode($v['imgs'], true);
  8237. if (!empty($imgurl)) {
  8238. $img_num[$k]->imgurl = $imgurl[0];
  8239. }
  8240. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8241. }
  8242. }
  8243. if (!empty($text_num)) {
  8244. foreach ($text_num as $k => $v) {
  8245. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8246. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8247. }
  8248. }
  8249. $project[$key]['img_num'] = $img_num ?? [];
  8250. $project[$key]['text_num'] = $text_num ?? [];
  8251. }
  8252. }
  8253. if (empty($project)) {
  8254. return Result::error("暂无相关项目信息", 0);
  8255. }
  8256. return Result::success($project);
  8257. }
  8258. /**
  8259. * @param array $data
  8260. * @return array
  8261. */
  8262. public function getWebsiteProjectInfo(array $data): array
  8263. {
  8264. $project = Project::where('id', $data['id'])
  8265. ->where('status', 1)
  8266. ->where('website_id', $data['website_id'])
  8267. ->select('project.*')
  8268. ->first();
  8269. if (empty($project)) {
  8270. return Result::error("暂无相关项目信息", 0);
  8271. }
  8272. return Result::success($project);
  8273. }
  8274. /**
  8275. * @param array $data
  8276. * @return array
  8277. */
  8278. public function getWebsiteProjectList(array $data): array
  8279. {
  8280. $where = [];
  8281. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8282. $where['category_id'] = $data['category_id'];
  8283. }
  8284. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8285. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8286. }
  8287. $query = Project::where($where)
  8288. ->where('status', 1)
  8289. ->where('website_id', $data['website_id'])
  8290. ->select(
  8291. 'project.id',
  8292. 'project.title',
  8293. 'project.description',
  8294. 'project.imgurl as imgs',
  8295. 'project.category_id',
  8296. 'project.cat_arr_id'
  8297. )
  8298. ->orderBy('updated_at', 'desc');
  8299. $count = $query->count();
  8300. $project = $query->clone()
  8301. ->offset(($data['page'] - 1) * $data['pageSize'])
  8302. ->limit($data['pageSize'])
  8303. ->get()->all();
  8304. if (empty($project)) {
  8305. return Result::error("暂无相关项目信息", 0);
  8306. }
  8307. $categorys = $this->processArticlePro($data['website_id']);
  8308. $catiall = $categorys['catiall'];
  8309. foreach ($project as $key => $val) {
  8310. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8311. if (!empty($val['imgs'])) {
  8312. $imgurl = json_decode($val['imgs'], true);
  8313. if (!empty($imgurl)) {
  8314. $project[$key]->imgurl = $imgurl[0];
  8315. }
  8316. } else {
  8317. $project[$key]->imgurl = '';
  8318. }
  8319. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8320. }
  8321. $result = [
  8322. 'rows' => $project,
  8323. 'count' => $count,
  8324. ];
  8325. return Result::success($result);
  8326. }
  8327. /**
  8328. * @param array $data
  8329. * @return array
  8330. */
  8331. public function getWebsiteCategoryJob(array $data): array
  8332. {
  8333. $categorys = json_decode($data['id'], true);
  8334. if (!empty($categorys)) {
  8335. $category_arr = $this->processArticlePro($data['website_id']);
  8336. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8337. $catiall = $category_arr['catiall'];
  8338. foreach ($categorys as $key => $val) {
  8339. if (isset($val['id']) && !empty($val['id'])) {
  8340. $catid = explode(',', $val['id'])[0] ?? null;
  8341. $type = explode(',', $val['id'])[1] ?? null;
  8342. $textnum = explode(',', $val['id'])[2] ?? null;
  8343. }
  8344. // 4:招聘;5:求职;
  8345. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8346. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8347. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8348. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8349. ->where('job_recruiting.status', 1)
  8350. ->where('job_recruiting.website_id', $data['website_id'])
  8351. ->select(
  8352. 'job_recruiting.id',
  8353. 'job_recruiting.title',
  8354. 'job_company.business_name',
  8355. 'job_recruiting.updated_at',
  8356. 'job_recruiting.cat_arr_id',
  8357. 'job_recruiting.keyword',
  8358. 'job_recruiting.description'
  8359. )
  8360. ->orderBy('job_recruiting.updated_at', 'desc')
  8361. ->limit($textnum)
  8362. ->get()->all();
  8363. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8364. // 状态 审核状态,1待审核2已审核3已拒绝
  8365. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8366. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8367. ->where('job_hunting.status', 2)
  8368. ->where('job_hunting.website_id', $data['website_id'])
  8369. ->select(
  8370. 'job_hunting.id',
  8371. 'job_hunting.name',
  8372. 'job_hunting.cat_arr_id',
  8373. 'job_position.zwname as job_name',
  8374. 'job_hunting.updated_at',
  8375. // 'job_hunting.keyword',
  8376. 'job_hunting.slelf_evaluation'
  8377. )
  8378. ->orderBy('updated_at', 'desc')
  8379. ->limit($textnum)
  8380. ->get()->all();
  8381. } else {
  8382. $job = [];
  8383. }
  8384. // var_dump($catid.'222uuuuuuu'.$key);
  8385. if (!empty($job)) {
  8386. foreach ($job as $k => $value) {
  8387. if (isset($value->cat_arr_id)) {
  8388. $catArr = json_decode($value->cat_arr_id, true);
  8389. $catId = end($catArr);
  8390. } else {
  8391. continue;
  8392. }
  8393. if (isset($catiall[$catId])) {
  8394. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8395. }
  8396. }
  8397. }
  8398. // var_dump($catid.'xxxxx'.$key);
  8399. $result[$key] = $job ?? [];
  8400. }
  8401. }
  8402. if (empty($result)) {
  8403. return Result::error("暂无相关分类信息", 0);
  8404. }
  8405. return Result::success($result);
  8406. }
  8407. /**
  8408. * 发送消息
  8409. * @param array $messageData
  8410. * @return void
  8411. */
  8412. public function sendMessage($messageData)
  8413. {
  8414. $msg = [
  8415. 'talk_type' => $messageData['talk_type'],
  8416. 'title' => $messageData['title'],
  8417. 'content' => $messageData['content'],
  8418. 'messageType' => $messageData['messageType'],
  8419. 'user_id' => $messageData['user_id'] ?? '',
  8420. 'time' => microtime(),
  8421. ];
  8422. $message = new MqProducer($msg);
  8423. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8424. $producer->produce($message);
  8425. }
  8426. /**
  8427. * 行业分类管理 ------1121
  8428. * @param array $data
  8429. * @return array
  8430. */
  8431. public function getJobIndustryList(array $data): array
  8432. {
  8433. $page = $data['page'] ?? 1;
  8434. $page_size = $data['page_size'] ?? 10;
  8435. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8436. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8437. } else {
  8438. $where = [];
  8439. }
  8440. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8441. $query->where([$where]); // 修复:将条件包装成二维数组
  8442. })
  8443. ->orderBy('updated_at', 'desc');
  8444. $count = $rs_query->count();
  8445. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8446. $result = [
  8447. 'count' => $count,
  8448. 'list' => $hy,
  8449. ];
  8450. if (empty($hy)) {
  8451. return Result::success('暂无数据');
  8452. }
  8453. return Result::success($result);
  8454. }
  8455. /**
  8456. * 添加行业分类
  8457. * @param array $data
  8458. * @return array
  8459. */
  8460. public function addJobIndustry(array $data): array
  8461. {
  8462. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8463. if (!empty($hy_name)) {
  8464. return Result::error('行业分类已存在');
  8465. }
  8466. $hy = JobIndustry::insertGetId($data);
  8467. if (empty($hy)) {
  8468. return Result::error('添加失败');
  8469. }
  8470. return Result::success($hy);
  8471. }
  8472. /**
  8473. * 更新行业分类
  8474. * @param array $data
  8475. * @return array
  8476. */
  8477. public function upJobIndustry(array $data): array
  8478. {
  8479. $hy_query = JobIndustry::get();
  8480. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8481. $hy_names = $hy_query->pluck('hyname')->toArray();
  8482. if (!in_array($data['hyid'], $hy_ids)) {
  8483. return Result::error('行业分类不存在');
  8484. }
  8485. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8486. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8487. // return Result::success($other_key_hy);
  8488. unset($hy_names[$other_key_hy]);
  8489. if (in_array($data['hyname'], $hy_names)) {
  8490. return Result::error('行业分类名称已存在');
  8491. }
  8492. }
  8493. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8494. if (empty($hy)) {
  8495. return Result::error('更新失败');
  8496. }
  8497. return Result::success($hy);
  8498. }
  8499. /**
  8500. * 删除行业分类
  8501. * @param array $data
  8502. * @return array
  8503. */
  8504. public function delJobIndustry(array $data): array
  8505. {
  8506. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8507. if (empty($hy_id)) {
  8508. return Result::error('行业分类不存在');
  8509. }
  8510. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8511. if (empty($hy)) {
  8512. return Result::error('删除失败');
  8513. }
  8514. return Result::success($hy);
  8515. }
  8516. /**
  8517. * 职位分类-列表
  8518. * @param array $data
  8519. * @return array
  8520. */
  8521. public function getJobPositionList(array $data): array
  8522. {
  8523. $page = $data['page'] ?? 1;
  8524. $page_size = $data['page_size'] ?? 10;
  8525. $where = [];
  8526. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8527. $zwids = JobPosition::where('zwpid', 0)
  8528. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8529. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8530. })
  8531. ->orderBy('updated_at', 'desc')
  8532. ->pluck('zwid')
  8533. // ->get()
  8534. ->toArray();
  8535. }
  8536. if (isset($data['childname']) && !empty($data['childname'])) {
  8537. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8538. ->when(!empty($data['childname']), function ($query) use ($data) {
  8539. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8540. })
  8541. ->orderBy('updated_at', 'desc')
  8542. ->pluck('zwpid')
  8543. // ->get()
  8544. ->toArray();
  8545. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8546. $child_zwids = array_intersect($zwids, $child_zwids);
  8547. }
  8548. $zwids = array_values(array_unique($child_zwids));
  8549. }
  8550. $zwids = $zwids ?? null;
  8551. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8552. $query->whereIn('zwid', $zwids);
  8553. })
  8554. ->where('zwpid', 0)
  8555. ->count();
  8556. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8557. $query->whereIn('zwid', $zwids);
  8558. })
  8559. ->where('zwpid', 0)
  8560. ->orderBy('updated_at', 'desc')
  8561. ->offset(($page - 1) * $page_size)
  8562. ->limit($page_size)->get()
  8563. ->map(function ($item) use ($data) {
  8564. $item->children = $item->where('zwpid', $item->zwid)
  8565. ->when(!empty($data['childname']), function ($query) use ($data) {
  8566. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8567. })
  8568. ->orderBy('updated_at', 'desc')
  8569. ->get();
  8570. return $item;
  8571. })
  8572. ->all();
  8573. $result = [
  8574. 'count' => $count,
  8575. 'list' => $position,
  8576. ];
  8577. if (empty($result)) {
  8578. return Result::success('暂无数据');
  8579. }
  8580. return Result::success($result);
  8581. }
  8582. /**
  8583. * 职位分类-添加
  8584. * @param array $data
  8585. * @return array
  8586. */
  8587. public function addJobPosition(array $data): array
  8588. {
  8589. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8590. ->where('zwname', $data['zwname'])->first(['zwid']);
  8591. if (!empty($zw_name)) {
  8592. return Result::error('职位分类已存在');
  8593. }
  8594. $zw = JobPosition::insertGetId($data);
  8595. if(empty($zw)){
  8596. return Result::error('添加失败');
  8597. }
  8598. return Result::success($zw);
  8599. }
  8600. /**
  8601. * 更新职位分类
  8602. * @param array $data
  8603. * @return array
  8604. */
  8605. public function upJobPosition(array $data): array
  8606. {
  8607. $zw_position = JobPosition::get();
  8608. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8609. return Result::error('职位分类不存在');
  8610. }
  8611. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8612. ->where('zwpid', $data['zwpid'])
  8613. ->where('zwname', $data['zwname'])->first();
  8614. if (!empty($zw_name)) {
  8615. return Result::error('职位分类已存在');
  8616. }
  8617. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8618. if (empty($result)) {
  8619. return Result::error('更新失败');
  8620. }
  8621. return Result::success($result);
  8622. }
  8623. /**
  8624. * 删除职位分类
  8625. * @param array $data
  8626. * @return array
  8627. */
  8628. public function delJobPosition(array $data): array
  8629. {
  8630. $zw_jobposition = JobPosition::get();
  8631. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8632. if (empty($zw_id)) {
  8633. return Result::error('职位分类不存在');
  8634. }
  8635. if($zw_id->zwpid == 0){
  8636. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8637. if(!empty($zw_job)){
  8638. return Result::error('请先删除子分类');
  8639. }
  8640. }
  8641. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8642. if (empty($result)) {
  8643. return Result::error('删除失败');
  8644. }
  8645. return Result::success($result);
  8646. }
  8647. }