NewsService.php 310 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. $rep = Article::where($where)
  396. ->whereNotIn('article.status', [404])
  397. ->when($status1, function ($query) use ($status1) {
  398. if (isset($status1) && $status1) {
  399. $query->whereIn('article.status', $status1);
  400. }
  401. })
  402. ->leftJoin('category', 'article.catid', 'category.id')
  403. ->leftJoin('website_category', function ($join) {
  404. $join->on('article.web_site_id', '=', 'website_category.website_id')
  405. ->on('article.catid', '=', 'website_category.category_id');
  406. })
  407. ->when($type_id != 10000 && !empty($data['website_id']), function ($query) use ($data) {
  408. $query->leftJoin('article_ignore', function ($join) use ($data) {
  409. $join->on('article.id', '=', 'article_ignore.article_id')
  410. ->where('article_ignore.website_id', $data['website_id']);
  411. });
  412. })
  413. ->select("article.*", "category.name as category_name", "website_category.alias",'article_ignore.c_show_time')
  414. ->orderBy("article.updated_at", "desc")
  415. ->limit($data['pageSize'])
  416. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  417. $count = Article::where($where)->whereNotIn('article.status', [404])
  418. ->when($status1, function ($query) use ($status1) {
  419. if (isset($status1) && $status1) {
  420. $query->whereIn('article.status', $status1);
  421. }
  422. })
  423. ->leftJoin('category', 'article.catid', 'category.id')->count();
  424. $data = [
  425. 'rows' => $rep->toArray(),
  426. 'count' => $count,
  427. ];
  428. if (empty($rep)) {
  429. return Result::error("没有信息数据");
  430. }
  431. return Result::success($data);
  432. }
  433. /**
  434. * @param array $data
  435. * @return array
  436. */
  437. public function addArticle(array $data): array
  438. {
  439. var_dump($data, '----------12-----------1');
  440. // ------c_show_time********add***1****
  441. $is_collect = $data['is_collect'] ?? 0;
  442. $user_type = $data['user_type'];
  443. unset($data['is_collect']);
  444. unset($data['user_type']);
  445. // ------c_show_time********add***1****
  446. unset($data['nav_add_pool_id']);
  447. // unset($data['commend_id']);
  448. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  449. Db::beginTransaction();
  450. try {
  451. //处理投票
  452. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  453. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  454. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  455. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  456. unset($data['is_survey']);
  457. unset($data['survey_name']);
  458. unset($data['suvey_array']);
  459. unset($data['website_id']);
  460. unset($data['web_site_id']);
  461. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  462. if ($data['hits'] == '') {
  463. $data['hits'] = 0;
  464. }
  465. if ($data['is_original'] == '') {
  466. $data['is_original'] = 0;
  467. }
  468. if ($data['status'] == '') {
  469. $data['status'] = 0;
  470. }
  471. $articleData = $data;
  472. unset($articleData['content']);
  473. //自动处理缩略图、关键字、描述
  474. if ($articleData['imgurl'] == '') {
  475. //如果没有图,设置level=0
  476. $levelArr = json_decode($articleData['level'], true);
  477. var_dump($levelArr, '----------levelArr-----------1');
  478. //content中提取图片第一个图,正则提取
  479. // -------采集器相关优化-----
  480. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  481. if($is_collect == 1){
  482. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  483. }else{
  484. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  485. }
  486. // -------采集器相关优化-----
  487. preg_match_all($reg, $data['content'], $matches);
  488. if (isset($matches[1][0])) {
  489. //截取varchar240
  490. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  491. //如果有图,设置level=3
  492. if (!in_array(3, $levelArr)) {
  493. $levelArr[] = 3;
  494. }
  495. $articleData['level'] = json_encode($levelArr);
  496. } else {
  497. if (!in_array(0, $levelArr)) {
  498. $levelArr[] = 0;
  499. }
  500. $articleData['level'] = json_encode($levelArr);
  501. }
  502. }
  503. var_dump($articleData['level'], '----------$articleData[level]----------1');
  504. if ($articleData['keyword'] == '') {
  505. //提取标题+内容中的关键词
  506. $articleData['keyword'] = $data['title'];
  507. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  508. Jieba::init(); // 初始化 jieba-php
  509. Finalseg::init();
  510. $segList = Jieba::cut($articleData['keyword']);
  511. $segList1 = array_slice($segList, 0, 8);
  512. $articleData['keyword'] = implode(',', $segList1);
  513. }
  514. if ($articleData['introduce'] == '') {
  515. //提取内容中的描述
  516. $content = $data['content'];
  517. // 去除 <style> 和 <script> 标签及其内容
  518. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  519. // 去除所有 HTML 标签
  520. $content = strip_tags($content);
  521. // 去除 HTML 实体
  522. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  523. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  524. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  525. // 去除多余空白
  526. $content = preg_replace('/\s+/u', '', $content);
  527. // 截取 100 个字符
  528. $articleData['introduce'] = mb_substr($content, 0, 100);
  529. }
  530. if ($articleData['status'] == 0) {
  531. $this->sendMessage([
  532. 'talk_type' => 100,
  533. 'title' => $articleData['title'],
  534. 'content' => '提交了审核',
  535. 'messageType' => 2,
  536. ]);
  537. }
  538. $id = Article::insertGetId($articleData);
  539. if (!$id) {
  540. throw new \Exception('文章插入失败');
  541. }
  542. $articleDataContent = [
  543. 'article_id' => $id,
  544. 'content' => $data['content'],
  545. ];
  546. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  547. if (!$contentInsertId) {
  548. throw new \Exception('文章内容插入失败');
  549. }
  550. // ------c_show_time********add***2****
  551. // 直接使用当前系统时间,不再强制添加8小时
  552. $now = date('Y-m-d H:i:s');
  553. if($user_type == 10000 || $is_collect == 1){
  554. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  555. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  556. if (!isset($data['catid'])) {
  557. throw new \Exception('缺少必要字段:catid');
  558. }
  559. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  560. $web = WebsiteCategory::where('category_id', $data['catid'])
  561. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  562. ->select('website_id',
  563. 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'))
  564. ->get();
  565. // $id = 225; -----测试开启
  566. // 采集来的文章,错开时间在两小时之内发布
  567. if($user_type == 10000 && $is_collect == 1){
  568. $web_num = $web->where('is_core', '!=', 2)->count();
  569. $waiting_interval = 10;
  570. if($web_num > 12){
  571. // 若网站数量大于12个,则每个网站间隔时间取均值
  572. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  573. $waiting_interval = 120 / max(1, $web_num);
  574. }
  575. $time = 0;
  576. }else{
  577. // 非核心站与核心站----显示时间-----间隔
  578. $time = 20;
  579. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  580. $waiting_interval = 5;
  581. }
  582. // 将 Hyperf\Database\Model\Collection 转换为数组
  583. $webArray = $web->toArray();
  584. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  585. // 检查 $item 对象是否有 is_core 属性
  586. if (!isset($item['is_core'])) {
  587. throw new \Exception('$item 对象缺少 is_core 属性');
  588. }
  589. // 当 is_core 为 2 时,则表示此网站不存在
  590. if ($item['is_core'] == 2) {
  591. return null;
  592. }
  593. if($is_collect == 1){
  594. // 采集来的文章,错开时间在两小时之内发布
  595. // $time = 0;
  596. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  597. $time += $waiting_interval;
  598. }else if($item['is_core'] == 1){
  599. // 当 is_core 为 1 时,则表示此网站是核心站
  600. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  601. }else{
  602. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  603. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  604. if ($item['is_core'] == 0) {
  605. $time += $waiting_interval;
  606. }
  607. }
  608. return [
  609. 'article_id' => $id,
  610. 'website_id' => $item['website_id'],
  611. 'c_show_time' => $c_show_time,
  612. // 'is_core' => $item['is_core'],
  613. // 'time' => $time
  614. ];
  615. }, array_keys($webArray), $webArray)));
  616. // Db::commit();
  617. // return Result::success($article_ignore);
  618. if(!empty($article_ignore)){
  619. $article_ignores = ArticleIgnore::insert($article_ignore);
  620. if(!$article_ignores){
  621. throw new \Exception('c端展示时间插入失败');
  622. }
  623. }
  624. }
  625. // ------c_show_time********add***2****
  626. //处理投票
  627. if ($is_survey == 1) {
  628. //生成年月日时分秒+8位随机数
  629. $uuid = date('YmdHis') . rand(10000000, 99999999);
  630. var_dump($suvey_array, 'suvey_array________');
  631. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  632. var_dump($suveys_array, '---------------------1');
  633. var_dump($suvey_array, '---------------------2');
  634. $suvey_data = [];
  635. foreach ($suveys_array as $key => $value) {
  636. if ($value == '') {
  637. continue;
  638. }
  639. if (is_array($value)) {
  640. $suvey_data[] = [
  641. 'sur_id' => $uuid,
  642. 'art_id' => $id,
  643. 'website_id' => $website_id ?? 2,
  644. 'survey_name' => $survey_name,
  645. 'choice_name' => $value[1],
  646. 'is_other' => 1,
  647. 'other_id' => 0,
  648. 'results' => 0,
  649. ];
  650. } else {
  651. $suvey_data[] = [
  652. 'sur_id' => $uuid,
  653. 'art_id' => $id,
  654. 'website_id' => $website_id ?? 2,
  655. 'survey_name' => $survey_name,
  656. 'choice_name' => $value,
  657. 'is_other' => 0,
  658. 'other_id' => 0,
  659. 'results' => 0,
  660. ];
  661. }
  662. if (empty($suvey_data)) {
  663. throw new \Exception("投票数据为空");
  664. }
  665. }
  666. $result = ArticleSurvey::insert($suvey_data);
  667. if (!$result) {
  668. throw new \Exception("投票失败,ArticleSurvey插入失败");
  669. }
  670. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  671. if (!$result) {
  672. throw new \Exception("投票失败,更新主表失败");
  673. }
  674. }
  675. Db::commit();
  676. return Result::success(['id' => $id]);
  677. } catch (\Throwable $ex) {
  678. Db::rollBack();
  679. var_dump($ex->getMessage());
  680. return Result::error("创建失败", 0);
  681. }
  682. }
  683. /**
  684. * @param array $data
  685. * @return array
  686. */
  687. public function delArticle(array $data): array
  688. {
  689. // ------c_show_time********del*******
  690. Db::beginTransaction();
  691. try{
  692. $article = Article::where(['id' => $data['id']])->delete();
  693. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  694. if (!$article) {
  695. throw new \Exception("删除失败,文章删除失败");
  696. }
  697. //survey投票删除
  698. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  699. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  700. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  701. // 若文章详情删除失败,抛出异常
  702. if (!$article_data) {
  703. throw new \Exception("删除失败,文章详情删除失败");
  704. }
  705. Db::commit(); // 所有操作成功,提交事务
  706. }catch (\Throwable $ex) {
  707. Db::rollBack();
  708. var_dump($ex->getMessage());
  709. return Result::error("删除失败: " . $ex->getMessage(), 0);
  710. }
  711. // ------c_show_time********del*******
  712. if (!$article) {
  713. return Result::error("删除失败");
  714. }
  715. return Result::success($article);
  716. }
  717. /**
  718. * @param array $data
  719. * @return array
  720. */
  721. public function updateArticle(array $data): array
  722. {
  723. var_dump($data, '----------12-----------1');
  724. Db::beginTransaction();
  725. // ------c_show_time********up*******
  726. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  727. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  728. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  729. $web = WebsiteCategory::where('category_id', $data['catid'])
  730. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  731. ->select('website_id',
  732. 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'))
  733. ->get();
  734. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  735. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  736. $websiteIds = $web->pluck('website_id')->toArray();
  737. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  738. if($user_type == 0){
  739. throw new \Exception("用户类型不能为空");
  740. }
  741. if($user_type == 10000 ){
  742. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  743. $web = WebsiteCategory::where('category_id', $data['catid'])
  744. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  745. ->select('website_id',
  746. 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'))
  747. ->get();
  748. // 非核心站与核心站----显示时间-----间隔
  749. $time = 20;
  750. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  751. $waiting_interval = 5;
  752. $webArray = $web->toArray();
  753. if(empty($webArray)){
  754. throw new \Exception('网站分类不存在');
  755. }
  756. // 直接使用当前系统时间,不再强制添加8小时
  757. $now = date('Y-m-d H:i:s');
  758. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  759. // 检查 $item 对象是否有 is_core 属性
  760. if (!isset($item['is_core'])) {
  761. throw new \Exception('$item 对象缺少 is_core 属性');
  762. }
  763. // 当 is_core 为 2 时,则表示此网站不存在
  764. if ($item['is_core'] == 2) {
  765. return null;
  766. }else if($item['is_core'] == 1){
  767. // 当 is_core 为 1 时,则表示此网站是核心站
  768. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  769. }else{
  770. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  771. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  772. if ($item['is_core'] == 0) {
  773. $time += $waiting_interval;
  774. }
  775. }
  776. return [
  777. 'article_id' => $data['id'],
  778. 'website_id' => $item['website_id'],
  779. 'c_show_time' => $c_show_time,
  780. ];
  781. }, array_keys($webArray), $webArray)));
  782. if(!empty($article_ignore)){
  783. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  784. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  785. $article_ignores = ArticleIgnore::upsert(
  786. $article_ignore,
  787. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  788. ['c_show_time'] // 需要更新的字段
  789. );
  790. if(!$article_ignores){
  791. throw new \Exception('c端展示时间插入失败');
  792. }
  793. }
  794. // Db::commit();
  795. // return Result::success($article_ignore);
  796. }
  797. // ------c_show_time********up*******
  798. unset($data['user_type']);
  799. // unset($data['web_site_id']);
  800. unset($data['nav_add_pool_id']);
  801. try {
  802. //处理投票
  803. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  804. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  805. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  806. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  807. unset($data['is_survey']);
  808. unset($data['survey_name']);
  809. unset($data['suvey_array']);
  810. unset($data['website_id']);
  811. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  812. if ($data['hits'] == '') {
  813. $data['hits'] = 0;
  814. }
  815. if ($data['is_original'] == '') {
  816. $data['is_original'] = 0;
  817. }
  818. if ($data['status'] == '') {
  819. $data['status'] = 0;
  820. }
  821. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  822. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  823. $articleData = $data;
  824. unset($articleData['content']);
  825. unset($articleData['status_name']);
  826. unset($articleData['name']);
  827. unset($articleData['content']);
  828. unset($articleData['pid_arr']);
  829. unset($articleData['pid']);
  830. //自动处理缩略图、关键字、描述
  831. if ($articleData['imgurl'] == '') {
  832. //如果没有图,设置level=0
  833. $levelArr = json_decode($articleData['level'], true);
  834. var_dump($levelArr, '----------levelArr-----------1');
  835. //content中提取图片第一个图,正则提取
  836. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  837. preg_match_all($reg, $data['content'], $matches);
  838. if (isset($matches[1][0])) {
  839. //截取varchar240
  840. // 截取到第一个<
  841. $articleData['imgurl'] = $matches[1][0];
  842. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  843. $pos = strpos($articleData['imgurl'], '"');
  844. if ($pos !== false) {
  845. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  846. }
  847. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  848. //如果有图,设置level=3
  849. if (!in_array(3, $levelArr)) {
  850. $levelArr[] = 3;
  851. }
  852. $articleData['level'] = json_encode($levelArr);
  853. } else {
  854. if (!in_array(0, $levelArr)) {
  855. $levelArr[] = 0;
  856. }
  857. $articleData['level'] = json_encode($levelArr);
  858. }
  859. }
  860. var_dump($articleData['level'], '----------$articleData[level]----------1');
  861. if ($articleData['keyword'] == '') {
  862. //提取标题+内容中的关键词
  863. $articleData['keyword'] = $data['title'];
  864. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  865. Jieba::init(); // 初始化 jieba-php
  866. Finalseg::init();
  867. $segList = Jieba::cut($articleData['keyword']);
  868. $segList1 = array_slice($segList, 0, 8);
  869. $articleData['keyword'] = implode(',', $segList1);
  870. }
  871. if ($articleData['introduce'] == '') {
  872. //提取内容中的描述
  873. $content = $data['content'];
  874. // 去除 <style> 和 <script> 标签及其内容
  875. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  876. // 去除所有 HTML 标签
  877. $content = strip_tags($content);
  878. // 去除 HTML 实体
  879. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  880. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  881. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  882. // 去除多余空白
  883. $content = preg_replace('/\s+/u', '', $content);
  884. // 截取 100 个字符
  885. $articleData['introduce'] = mb_substr($content, 0, 100);
  886. }
  887. if ($articleData['status'] == 0) {
  888. $this->sendMessage([
  889. 'talk_type' => 100,
  890. 'title' => $articleData['title'],
  891. 'content' => '提交了审核',
  892. 'messageType' => 2,
  893. ]);
  894. }
  895. $id = Article::where(['id' => $data['id']])->update($articleData);
  896. $articleDataContent = [
  897. 'content' => $data['content'],
  898. ];
  899. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  900. //处理投票
  901. $id = $data['id'];
  902. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  903. var_dump($suvey_array, 'suvey_array________delete');
  904. //处理投票
  905. if ($is_survey == 1) {
  906. //生成年月日时分秒+8位随机数
  907. $uuid = date('YmdHis') . rand(10000000, 99999999);
  908. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  909. var_dump($suveys_array, '---------------------1');
  910. $suvey_data = [];
  911. if (is_array($suveys_array)) {
  912. foreach ($suveys_array as $key => $value) {
  913. if ($value == '') {
  914. continue;
  915. }
  916. if (is_array($value)) {
  917. $suvey_data[] = [
  918. 'sur_id' => $uuid,
  919. 'art_id' => $id,
  920. 'website_id' => $website_id ?? 2,
  921. 'survey_name' => $survey_name,
  922. 'choice_name' => $value[1],
  923. 'is_other' => 1,
  924. 'other_id' => 0,
  925. 'results' => 0,
  926. ];
  927. } else {
  928. $suvey_data[] = [
  929. 'sur_id' => $uuid,
  930. 'art_id' => $id,
  931. 'website_id' => $website_id ?? 2,
  932. 'survey_name' => $survey_name,
  933. 'choice_name' => $value,
  934. 'is_other' => 0,
  935. 'other_id' => 0,
  936. 'results' => 0,
  937. ];
  938. }
  939. if (empty($suvey_data)) {
  940. throw new \Exception("投票数据为空");
  941. }
  942. }
  943. }
  944. $result = ArticleSurvey::insert($suvey_data);
  945. if (!$result) {
  946. throw new \Exception("投票失败");
  947. }
  948. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  949. if (!$result) {
  950. throw new \Exception("投票失败");
  951. }
  952. } else {
  953. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  954. }
  955. Db::commit();
  956. return Result::success([]);
  957. } catch (\Throwable $ex) {
  958. Db::rollBack();
  959. var_dump($ex->getMessage());
  960. return Result::error("更新失败" . $ex->getMessage(), 0);
  961. }
  962. }
  963. /**
  964. * 更新资讯状态
  965. * @param array $data
  966. * @return array
  967. */
  968. public function upArticleStatus(array $data): array
  969. {
  970. $articleData = Article::where(['id' => $data['id']])->first();
  971. //发送10次
  972. // for ($i = 0; $i < 10; $i++) {
  973. // $this->sendMessage([
  974. // 'talk_type' => 100,
  975. // 'title' => $i . $articleData['title'],
  976. // 'content' => '审核通过',
  977. // 'messageType' => 2,
  978. // 'user_id' => $articleData['admin_user_id'],
  979. // ]);
  980. // }
  981. // var_dump($data['status'], 'status');
  982. // return Result::success();
  983. if ($data['status'] == 1) {
  984. $this->sendMessage([
  985. 'talk_type' => 101,
  986. 'title' => $articleData['title'],
  987. 'content' => '审核通过',
  988. 'messageType' => 2,
  989. 'user_id' => $articleData['admin_user_id'],
  990. ]);
  991. }
  992. if ($data['status'] == 2) {
  993. $this->sendMessage([
  994. 'talk_type' => 101,
  995. 'title' => $articleData['title'],
  996. 'content' => '审核拒绝',
  997. 'messageType' => 2,
  998. 'user_id' => $articleData['admin_user_id'],
  999. ]);
  1000. }
  1001. if ($data['status'] == 0) {
  1002. $this->sendMessage([
  1003. 'talk_type' => 100,
  1004. 'title' => $articleData['title'],
  1005. 'content' => '提交了审核',
  1006. 'messageType' => 2,
  1007. ]);
  1008. }
  1009. $result = Article::where(['id' => $data['id']])->update($data);
  1010. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  1011. //article_ignore 表插入数据 db操作
  1012. //转成数组
  1013. //删掉数据重新写入
  1014. // DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  1015. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1016. // $insert_data = [];
  1017. // foreach ($website_ids as $key => $value) {
  1018. // $insert_data[] = [
  1019. // 'article_id' => $data['id'],
  1020. // 'website_id' => $value,
  1021. // 'is_ignore' => 1
  1022. // ];
  1023. // }
  1024. DB::table('article_ignore')->where('article_id', $data['id'])->whereIn('website_id',$website_ids)->update(['is_ignore' => 1]);
  1025. }else{
  1026. // ------c_show_time********up_status*******
  1027. // 若是审核通过 则更新c_show_time
  1028. if($data['status'] == 1){
  1029. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1030. $web = Article::where('article.id',$data['id'])
  1031. ->leftJoin('website_category','article.catid','website_category.category_id')
  1032. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1033. ->select('website_id',
  1034. 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'))
  1035. ->get();
  1036. // 非核心站与核心站----显示时间-----间隔
  1037. $time = 20;
  1038. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1039. $waiting_interval = 5;
  1040. $webArray = $web->toArray();
  1041. if(empty($webArray)){
  1042. throw new \Exception('网站分类不存在');
  1043. }
  1044. // 直接使用当前系统时间,不再强制添加8小时
  1045. $now = date('Y-m-d H:i:s');
  1046. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1047. // 检查 $item 对象是否有 is_core 属性
  1048. if (!isset($item['is_core'])) {
  1049. throw new \Exception('$item 对象缺少 is_core 属性');
  1050. }
  1051. // 当 is_core 为 2 时,则表示此网站不存在
  1052. if ($item['is_core'] == 2) {
  1053. return null;
  1054. }else if($item['is_core'] == 1){
  1055. // 当 is_core 为 1 时,则表示此网站是核心站
  1056. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  1057. }else{
  1058. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1059. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1060. if ($item['is_core'] == 0) {
  1061. $time += $waiting_interval;
  1062. }
  1063. }
  1064. return [
  1065. 'article_id' => $data['id'],
  1066. 'website_id' => $item['website_id'],
  1067. 'c_show_time' => $c_show_time,
  1068. ];
  1069. }, array_keys($webArray), $webArray)));
  1070. if(!empty($article_ignore)){
  1071. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1072. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1073. $article_ignores = ArticleIgnore::upsert(
  1074. $article_ignore,
  1075. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1076. ['c_show_time'] // 需要更新的字段
  1077. );
  1078. if(!$article_ignores){
  1079. throw new \Exception('c端展示时间插入失败');
  1080. }
  1081. }
  1082. }
  1083. // ------c_show_time********up_status*******
  1084. }
  1085. if ($result) {
  1086. return Result::success();
  1087. } else {
  1088. return Result::error("更新状态失败", 0);
  1089. }
  1090. }
  1091. /**
  1092. * 获取新闻详情
  1093. * @param array $data
  1094. * @return array
  1095. */
  1096. public function getArticleInfo(array $data): array
  1097. {
  1098. $where = [
  1099. 'article.id' => $data['id'],
  1100. // 'article.status' => 1,
  1101. ];
  1102. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1103. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1104. $info = $result;
  1105. // var_dump($info, 'info');
  1106. $info['survey_array'] = $articleSurvey;
  1107. if ($result) {
  1108. return Result::success($info);
  1109. } else {
  1110. return Result::error("查询失败", 0);
  1111. }
  1112. }
  1113. /**
  1114. * 获取头条新闻
  1115. * @param array $data
  1116. * @return array
  1117. */
  1118. public function getWebsiteArticlett(array $data): array
  1119. {
  1120. $website_id = $data['website_id'];
  1121. $website = Website::where('id', $data['website_id'])->first();
  1122. if (empty($website)) {
  1123. return Result::error("网站不存在", 0);
  1124. }
  1125. $categorys = $this->processArticlePro($website_id);
  1126. $catiall = $categorys['catiall'];
  1127. $categoryIds = $categorys['categoryIds'];
  1128. $where = [
  1129. 'status' => 1
  1130. ];
  1131. // $website_column = $website['column'];
  1132. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1133. $website_column = json_decode($website['website_column_arr_id'], true);
  1134. }
  1135. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1136. // return Result::success($diff_pid_categoryIds);
  1137. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1138. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1139. }
  1140. // $website_id = $data['website_id'];
  1141. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1142. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1143. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1144. switch ($data['level']) {
  1145. case 1:
  1146. case 2:
  1147. case 3:
  1148. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1149. $query = Article::where($where)
  1150. ->where('level', 'like', '%' . $data['level'] . '%')
  1151. ->orderBy('updated_at', 'desc');
  1152. break;
  1153. case 4: //最新资讯
  1154. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1155. break;
  1156. case 5: //资讯推荐
  1157. $query = Article::where($where)
  1158. ->where('updated_at', '>', $month);
  1159. break;
  1160. case 7: //资讯分类
  1161. if (isset($data['id']) && !empty($data['id'])) {
  1162. $keyword = Article::where('id', $data['id'])->value('keyword');
  1163. $keywordArray = explode(',', $keyword);
  1164. $whereL7 = [];
  1165. foreach ($keywordArray as $k => $v) {
  1166. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1167. }
  1168. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1169. break;
  1170. } else {
  1171. return Result::error("请输入资讯ID", 0);
  1172. break;
  1173. }
  1174. default:
  1175. break;
  1176. }
  1177. // $whereL7 = [];
  1178. // if(isset($data['id']) && !empty($data['id'])){
  1179. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1180. // $keywordArray = explode(',', $keyword);
  1181. // foreach ($keywordArray as $k => $v) {
  1182. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1183. // }
  1184. // }
  1185. // $query = Article::where($where)
  1186. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1187. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1188. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1189. // }
  1190. // if($data['level'] == 7){
  1191. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1192. // }
  1193. // if($data['level'] == 4){
  1194. // $query = $query->inRandomOrder()
  1195. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1196. // }
  1197. // if($data['level'] == 5){
  1198. // $query = $query->orderBy('updated_at','desc');
  1199. // }
  1200. // });
  1201. if ($data['textnum'] > 0) {
  1202. $query = clone $query;
  1203. $result['text'] = $query
  1204. ->whereIn('catid', $categoryIds)
  1205. ->leftJoinSub(function ($query) use ($website_id) {
  1206. $query->from('article_ignore')
  1207. ->where('website_id', $website_id);
  1208. }, 'article_ignore', function ($join) {
  1209. $join->on('article_ignore.article_id', '=', 'article.id');
  1210. })
  1211. ->where(function ($query) {
  1212. $query->whereNull('article_ignore.article_id')
  1213. ->orWhere(function ($subQuery) {
  1214. $subQuery->whereNotNull('article_ignore.article_id')
  1215. ->where('article_ignore.is_ignore', 0)
  1216. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1217. });
  1218. })
  1219. // ->where(function ($query) use ($website_id) {
  1220. // $query->whereNull('article_ignore.article_id')
  1221. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1222. // })
  1223. ->select(
  1224. 'article.id',
  1225. 'article.title',
  1226. 'article.author',
  1227. 'article.updated_at',
  1228. 'article.introduce',
  1229. 'article.islink',
  1230. 'article.linkurl',
  1231. 'article.copyfrom',
  1232. 'article.cat_arr_id',
  1233. 'article.catid',
  1234. 'article.level',
  1235. // 'article_ignore.is_ignore',
  1236. // 'article_ignore.c_show_time',
  1237. )
  1238. ->offset($data['placeid'])
  1239. ->limit($data['textnum'])
  1240. ->get()->all();
  1241. foreach ($result['text'] as $k => $v) {
  1242. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1243. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1244. }
  1245. }
  1246. if ($data['imgnum'] > 0) {
  1247. $query = clone $query;
  1248. $result['img'] = $query
  1249. ->whereIn('catid', $categoryIds)
  1250. ->where('article.imgurl', '!=', '')
  1251. ->select(
  1252. 'article.id',
  1253. 'article.title',
  1254. 'article.imgurl',
  1255. 'article.author',
  1256. 'article.updated_at',
  1257. 'article.introduce',
  1258. 'article.islink',
  1259. 'article.linkurl',
  1260. 'article.copyfrom',
  1261. 'article.cat_arr_id',
  1262. 'article.catid',
  1263. 'article.level',
  1264. // 'article_ignore.is_ignore',
  1265. // 'article_ignore.c_show_time',
  1266. )
  1267. ->offset($data['placeid'])
  1268. ->limit($data['imgnum'])
  1269. ->get()->all();
  1270. foreach ($result['img'] as $k => $v) {
  1271. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1272. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1273. }
  1274. }
  1275. if (empty($result)) {
  1276. return Result::error("暂无相关资讯", 0);
  1277. }
  1278. return Result::success($result);
  1279. }
  1280. /**
  1281. * 获取模块新闻
  1282. * @param array $data
  1283. * @return array
  1284. */
  1285. public function getWebsiteModelArticles(array $data): array
  1286. {
  1287. $catid = $data['catid'];
  1288. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1289. $category = $category->toArray();
  1290. if (!empty($category)) {
  1291. $where = [
  1292. 'status' => 1,
  1293. 'catid' => $catid,
  1294. ];
  1295. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1296. // 1:文字新闻;2:轮播图;3:图文;
  1297. // 级别:0:未分类
  1298. // 3:推荐图片
  1299. if ($data['level'] == 1) {
  1300. $data['level'] = 0;
  1301. }
  1302. $result = Article::where($where)
  1303. ->where(function ($query) use ($data) {
  1304. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1305. ->orWhereNull("level")
  1306. ->orWhereRaw("level = '[]'");
  1307. })
  1308. ->leftJoinSub(function ($query) use ($data) {
  1309. $query->from('article_ignore')
  1310. ->where('website_id', $data['website_id']);
  1311. }, 'article_ignore', function ($join) {
  1312. $join->on('article_ignore.article_id', '=', 'article.id');
  1313. })
  1314. ->where(function ($query) {
  1315. $query->whereNull('article_ignore.article_id')
  1316. ->orWhere(function ($subQuery) {
  1317. $subQuery->whereNotNull('article_ignore.article_id')
  1318. ->where('article_ignore.is_ignore', 0)
  1319. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1320. });
  1321. })
  1322. // ->where(function ($query) use ($data) {
  1323. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1324. // ->orWhereNull("ignore_ids");
  1325. // })
  1326. ->orderBy("updated_at", "desc")
  1327. ->offset($placeid)
  1328. ->limit($data['pagesize'])
  1329. ->get();
  1330. if (empty($result)) {
  1331. return Result::error("此栏目暂无相关新闻", 0);
  1332. }
  1333. } else {
  1334. return Result::error("此网站暂无此栏目", 0);
  1335. }
  1336. return Result::success($result);
  1337. }
  1338. /**
  1339. *获取新闻列表
  1340. * @param array $data
  1341. * @return array
  1342. */
  1343. public function getWebsiteArticleList(array $data): array
  1344. {
  1345. // return Result::success($data);
  1346. $where[] = ['status', '=', 1];
  1347. $website_id = $data['website_id'];
  1348. $website = Website::where('id', $data['website_id'])->first();
  1349. if (empty($website)) {
  1350. return Result::error("网站不存在", 0);
  1351. }
  1352. // $website_column = $website['column'];
  1353. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1354. $website_column = json_decode($website['website_column_arr_id'], true);
  1355. }
  1356. $categorys = $this->processArticlePro($website_id);
  1357. $cat_1st_arr = $categorys['cat_1st_arr'];
  1358. $catiall = $categorys['catiall'];
  1359. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1360. // return Result::success($diff_pid_categoryIds);
  1361. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1362. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1363. }
  1364. if (isset($data['catid']) && !empty($data['catid'])) {
  1365. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1366. if (empty($category)) {
  1367. return Result::error("此网站暂无此栏目", 0);
  1368. }
  1369. array_push($where, ['catid', '=', $data['catid']]);
  1370. }
  1371. // return Result::success($where);
  1372. $query = Article::where($where)
  1373. ->leftJoinSub(function ($query) use ($website_id) {
  1374. $query->from('article_ignore')
  1375. ->where('website_id', $website_id);
  1376. }, 'article_ignore', function ($join) {
  1377. $join->on('article_ignore.article_id', '=', 'article.id');
  1378. })
  1379. ->where(function ($query) {
  1380. $query->whereNull('article_ignore.article_id')
  1381. ->orWhere(function ($subQuery) {
  1382. $subQuery->whereNotNull('article_ignore.article_id')
  1383. ->where('article_ignore.is_ignore', 0)
  1384. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1385. });
  1386. })
  1387. ->select(
  1388. 'article.id',
  1389. 'article.title',
  1390. 'article.imgurl',
  1391. 'article.author',
  1392. 'article.updated_at',
  1393. 'article.introduce',
  1394. 'article.islink',
  1395. 'article.linkurl',
  1396. 'article.copyfrom',
  1397. 'article.cat_arr_id',
  1398. 'article.catid'
  1399. );
  1400. $count = $query->count();
  1401. $rep = $query->orderBy("updated_at", "desc")
  1402. ->offset(($data['page'] - 1) * $data['pageSize'])
  1403. ->limit($data['pageSize'])
  1404. ->get()->all();
  1405. $categorys = $this->processArticlePro($website_id);
  1406. $cat_1st_arr = $categorys['cat_1st_arr'];
  1407. $catiall = $categorys['catiall'];
  1408. // $web['website_id'] = $data['website_id'];
  1409. foreach ($rep as $k => $v) {
  1410. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1411. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1412. }
  1413. // $rep = $this->processArticles($rep,$web);
  1414. $data = [
  1415. 'rows' => $rep,
  1416. 'count' => $count,
  1417. ];
  1418. if (empty($rep)) {
  1419. return Result::error("没有信息数据");
  1420. }
  1421. return Result::success($data);
  1422. }
  1423. /**
  1424. * 前端-获取新闻详情
  1425. * @param array $data
  1426. * @return array
  1427. */
  1428. public function selectWebsiteArticleInfo(array $data): array
  1429. {
  1430. $where = [
  1431. 'article.id' => $data['id'],
  1432. 'article.status' => 1,
  1433. ];
  1434. $result = Article::where($where)
  1435. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1436. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1437. ->where(function ($query) use ($data) {
  1438. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1439. ->orWhereNull("ignore_ids");
  1440. })
  1441. ->select(
  1442. 'article.*',
  1443. 'article_data.content',
  1444. 'article_data.article_id',
  1445. 'article_extend.website_url',
  1446. 'article_extend.email',
  1447. 'article_extend.contacts',
  1448. 'article_extend.contacts_mobile',
  1449. 'article_extend.contacts_address',
  1450. 'article_extend.zip_code',
  1451. 'article_extend.enterprise_name'
  1452. )
  1453. ->first();
  1454. if (empty($result)) {
  1455. return Result::error("暂无此新闻!", 0);
  1456. }
  1457. if (!empty($result['publiced_at'])) {
  1458. $result['updated_at'] = $result['publiced_at'];
  1459. }
  1460. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1461. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1462. ->where('website_category.website_id', $data['website_id'])
  1463. ->where(['website_category.category_id' => $result['catid']])
  1464. ->first();
  1465. if (empty($category)) {
  1466. return Result::error("查询失败", 0);
  1467. }
  1468. //手动推荐文章
  1469. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1470. if (empty($commend_ids)) {
  1471. $commendArticle = [];
  1472. } else {
  1473. //去除不存在的文章ID
  1474. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1475. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1476. ->where('article.status', 1)
  1477. ->where('website_category.website_id', $data['website_id'])
  1478. ->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')
  1479. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1480. // ->orderBy('article.updated_at', 'desc')
  1481. ->limit(5)
  1482. ->get();
  1483. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1484. foreach ($commendArticle as $k => $v) {
  1485. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1486. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1487. $cat_arr_id = array_unique($cat_arr_id);
  1488. // 从website_category取出alias_pinyin
  1489. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1490. ->whereIn('category_id', $cat_arr_id)
  1491. ->pluck('alias_pinyin', 'category_id')
  1492. ->toArray();
  1493. // 将cat_arr_id的json转成路径/隔开
  1494. $path_parts = [];
  1495. foreach ($cat_arr_id as $cat_id) {
  1496. if (isset($cat_arr[$cat_id])) {
  1497. $path_parts[] = $cat_arr[$cat_id];
  1498. }
  1499. }
  1500. $v->alias_pinyin = implode('/', $path_parts);
  1501. } else {
  1502. $v->alias_pinyin = '';
  1503. }
  1504. }
  1505. }
  1506. $result['category_id'] = $category['category_id'];
  1507. $result['cat_name'] = $category['alias'];
  1508. $result['website_name'] = $category['website_name'] ?? "";
  1509. $result['suffix'] = $category['suffix'] ?? "";
  1510. $result['commendArticle'] = $commendArticle;
  1511. $result['commend_ids'] = $commend_ids;
  1512. return Result::success($result);
  1513. }
  1514. /**
  1515. * 前端-获取网站调查问卷
  1516. * @param array $data
  1517. * @return array
  1518. */
  1519. public function getWebsiteSurvey(array $data): array
  1520. {
  1521. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1522. $website = Website::where('id', $data['website_id'])->first();
  1523. if (empty($website)) {
  1524. return Result::error("暂无此网站", 0);
  1525. }
  1526. }
  1527. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1528. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1529. if (empty($article)) {
  1530. return Result::error("暂无此文章", 0);
  1531. }
  1532. // return Result::error($data,0);
  1533. $where['art_id'] = $data['art_id'];
  1534. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1535. } else {
  1536. $survey = Article::where(function ($query) {
  1537. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1538. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1539. })
  1540. ->where('status', 1)
  1541. ->where('is_survey', 1)
  1542. ->select('survey_id')
  1543. ->orderBy('updated_at', 'desc')
  1544. ->first();
  1545. if (empty($survey)) {
  1546. return Result::error("暂无调查问卷", 0);
  1547. }
  1548. $where['sur_id'] = $survey['survey_id'];
  1549. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1550. }
  1551. // return Result::success($where);
  1552. $result = ArticleSurvey::where($where)
  1553. ->where(function ($query) {
  1554. $query->where('is_other', 0)
  1555. ->orWhere(function ($subQuery) {
  1556. $subQuery->where('is_other', 1)
  1557. ->where('other_id', 0);
  1558. });
  1559. })
  1560. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1561. ->select('article_survey.*', 'article.survey_type')
  1562. ->get()->all();
  1563. if (empty($result)) {
  1564. return Result::error("此文章暂无调查问卷", 0);
  1565. }
  1566. return Result::success($result);
  1567. }
  1568. /**
  1569. * 前端-添加网站调查问卷选项
  1570. * @param array $data
  1571. * @return array
  1572. */
  1573. public function addWebsiteSurveyOption(array $data): array
  1574. {
  1575. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1576. $website = Website::where('id', $data['website_id'])->first();
  1577. if (empty($website)) {
  1578. return Result::error("暂无此网站", 0);
  1579. }
  1580. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1581. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1582. if (empty($survey)) {
  1583. return Result::error("此调查问卷不可添加选项", 0);
  1584. }
  1585. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1586. $choice = [
  1587. 'art_id' => $survey['art_id'],
  1588. 'website_id' => $data['website_id'],
  1589. 'survey_name' => $survey['survey_name'],
  1590. 'choice_name' => $data['choice_name'],
  1591. 'sur_id' => $survey['sur_id'],
  1592. 'is_other' => 1,
  1593. 'other_id' => $survey['id'],
  1594. ];
  1595. $result = ArticleSurvey::insertGetId($choice);
  1596. if (empty($result)) {
  1597. return Result::error("添加失败", 0);
  1598. }
  1599. return Result::success($result);
  1600. }
  1601. }
  1602. return Result::error("添加失败", 0);
  1603. }
  1604. return Result::error("添加失败", 0);
  1605. }
  1606. /**
  1607. * 前端-调查问卷投票
  1608. * @param array $data
  1609. * @return array
  1610. */
  1611. public function addWebsiteSurveyVote(array $data): array
  1612. {
  1613. // return Result::success($data);
  1614. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1615. $website = Website::where('id', $data['website_id'])->first();
  1616. if (empty($website)) {
  1617. return Result::error("暂无此网站", 0);
  1618. }
  1619. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1620. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1621. // return Result::success($survey);
  1622. if (empty($is_survey)) {
  1623. return Result::error("此调查问卷不存在", 0);
  1624. }
  1625. // return Result::success($survey);
  1626. // 调查问卷类型
  1627. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1628. //多选 若是json型则转化成数组类型
  1629. if (strpos($data['choice_id'], '[') === 0) {
  1630. $data['choice_id'] = json_decode($data['choice_id'], true);
  1631. } else {
  1632. // 单选 也转换成数组
  1633. $data['choice_id'] = [$data['choice_id']];
  1634. }
  1635. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1636. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1637. // ->where('website_id',$data['website_id'])
  1638. ->where('is_other', 1)
  1639. ->where('other_id', 0)
  1640. ->first();
  1641. if (!empty($other)) {
  1642. return Result::error("请选择已有的选项!", 0);
  1643. }
  1644. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1645. // ->where('website_id',$data['website_id'])
  1646. ->where('is_other', 1)
  1647. ->where('other_id', '!=', 0)
  1648. ->first();
  1649. // return Result::success($choice['other']);
  1650. $choice_id = $data['choice_id'];
  1651. if (!empty($choice['other'])) {
  1652. // array_push($data['choice_id'],$choice['other']['other_id']);
  1653. if (!empty($choice_id)) {
  1654. $key = array_search($choice['other']['id'], $choice_id);
  1655. if ($key !== false) {
  1656. unset($choice_id[$key]);
  1657. $choice_id = array_values($choice_id);
  1658. }
  1659. array_push($choice_id, $choice['other']['other_id']);
  1660. } else {
  1661. $choice_id[0] = $choice['other']['other_id'];
  1662. }
  1663. array_push($data['choice_id'], $choice['other']['other_id']);
  1664. }
  1665. // return Result::success($data);
  1666. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1667. // ->where('website_id',$data['website_id'])
  1668. ->increment('results', 1);
  1669. if (empty($choice)) {
  1670. return Result::error("请选择已有的选项!", 0);
  1671. }
  1672. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1673. // ->where('website_id',$data['website_id'])
  1674. ->where('other_id', 0)
  1675. ->get();
  1676. $survey['choice'] = $choice_id;
  1677. return Result::success($survey);
  1678. }
  1679. return Result::error("参数必填!");
  1680. }
  1681. return Result::error("此调查问卷不存在", 0);
  1682. }
  1683. return Result::error("参数必填!");
  1684. }
  1685. /**
  1686. * 后端-获取网站调查问卷列表
  1687. * @param array $data
  1688. * @return array
  1689. */
  1690. public function getSurveyList(array $data): array
  1691. {
  1692. $where = [];
  1693. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1694. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1695. }
  1696. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1697. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1698. }
  1699. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1700. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1701. }
  1702. // return Result::success($where);
  1703. if (!empty($where)) {
  1704. $query = Article::where($where)->where(function ($q) {
  1705. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1706. });
  1707. } else {
  1708. $query = Article::where(function ($q) {
  1709. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1710. });
  1711. }
  1712. $count = $query->count();
  1713. $survey = $query->orderByDesc('id')
  1714. ->limit($data['pageSize'])
  1715. ->offset(($data['page'] - 1) * $data['pageSize'])
  1716. ->get();
  1717. if (empty($survey->toArray())) {
  1718. return Result::error("暂无调查问卷!", 0);
  1719. }
  1720. $result = [
  1721. 'rows' => $survey,
  1722. 'count' => $count,
  1723. ];
  1724. return Result::success($result);
  1725. }
  1726. /**
  1727. * 后端-获取网站调查问卷详情
  1728. * @param array $data
  1729. * @return array
  1730. */
  1731. public function getSurveyInfo(array $data): array
  1732. {
  1733. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1734. $where = ['sur_id' => $data['sur_id']];
  1735. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1736. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1737. ->select('article_survey.*', 'article.survey_type')
  1738. ->get()->all();
  1739. if (empty($choose)) {
  1740. return Result::error("此调查问卷不存在", 0);
  1741. }
  1742. $resultsArray = array_column($choose, 'results');
  1743. $total = array_sum($resultsArray);
  1744. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1745. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1746. // $total = 0;
  1747. if (!empty($other)) {
  1748. $total = $total + $other['results'];
  1749. $other['choice_name'] = '(其他)';
  1750. if (!empty($others)) {
  1751. $other['hasChildren'] = true;
  1752. // array_push($other,['hasChildren','=',true]);
  1753. $other['children'] = $others;
  1754. $other_choices = [$other->toArray()];
  1755. $mer_choice = array_merge($choose, $other_choices);
  1756. $value_choice = array_values($mer_choice);
  1757. } else {
  1758. // return Result::error('1111');
  1759. $other_choices = [$other->toArray()];
  1760. $other_choices = array_merge($choose, $other_choices);
  1761. $value_choice = array_values($other_choices);
  1762. // return Result::success($result);
  1763. }
  1764. } else {
  1765. $value_choice = $choose;
  1766. }
  1767. $result = [
  1768. 'choose' => $value_choice,
  1769. 'total' => $total,
  1770. ];
  1771. }
  1772. return Result::success($result);
  1773. }
  1774. /**
  1775. * 前端-搜索新闻列表
  1776. * @param array $data
  1777. * @return array
  1778. */
  1779. public function selectWebsiteArticle(array $data): array
  1780. {
  1781. $website = Website::where('id', $data['website_id'])->first();
  1782. if (empty($website)) {
  1783. return Result::error("网站不存在", 0);
  1784. }
  1785. // $website_column = $website['column'];
  1786. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1787. $website_column = json_decode($website['website_column_arr_id'], true);
  1788. }
  1789. $website_id = $data['website_id'];
  1790. $categorys = $this->processArticlePro($website_id);
  1791. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1792. // return Result::success($diff_pid_categoryIds);
  1793. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1794. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1795. }
  1796. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1797. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1798. $catiall = $categorys['catiall'];
  1799. $categoryIds = $categorys['categoryIds'];
  1800. // return Result::success($categoryIds);
  1801. $query = Article::where('status', 1)
  1802. ->whereIn('catid', $categoryIds)
  1803. ->leftJoinSub(function ($query) use ($website_id) {
  1804. $query->from('article_ignore')
  1805. ->where('website_id', $website_id);
  1806. }, 'article_ignore', function ($join) {
  1807. $join->on('article_ignore.article_id', '=', 'article.id');
  1808. })
  1809. ->where(function ($query) {
  1810. $query->whereNull('article_ignore.article_id')
  1811. ->orWhere(function ($subQuery) {
  1812. $subQuery->whereNotNull('article_ignore.article_id')
  1813. ->where('article_ignore.is_ignore', 0)
  1814. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1815. });
  1816. });
  1817. // ->get()->all();
  1818. // return Result::success($query);
  1819. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1820. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1821. }
  1822. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1823. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1824. }
  1825. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1826. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1827. }
  1828. // 计算总数
  1829. $count = $query->count();
  1830. // return Result::success($count);
  1831. // 分页查询
  1832. $articles = $query
  1833. ->select(
  1834. 'article.id',
  1835. 'article.title',
  1836. 'article.imgurl',
  1837. 'article.author',
  1838. 'article.updated_at',
  1839. 'article.introduce',
  1840. 'article.islink',
  1841. 'article.linkurl',
  1842. 'article.copyfrom',
  1843. 'article.cat_arr_id',
  1844. 'article.catid',
  1845. 'article.department_arr_id',
  1846. 'article.city_arr_id',
  1847. // 'article_ignore.c_show_time',
  1848. // 'article_ignore.is_ignore'
  1849. )
  1850. ->orderBy("updated_at", "desc")
  1851. ->offset(($data['page'] - 1) * $data['pageSize'])
  1852. ->limit($data['pageSize'])
  1853. ->get();
  1854. // return Result::success($articles);
  1855. foreach ($articles as $k => $v) {
  1856. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1857. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1858. }
  1859. if (empty($articles)) {
  1860. return Result::error("没有符合条件的资讯数据");
  1861. }
  1862. $result = [
  1863. 'rows' => $articles,
  1864. 'count' => $count,
  1865. ];
  1866. return Result::success($result);
  1867. }
  1868. /**
  1869. * 模块新闻加强版
  1870. * @param array $data
  1871. * @return array
  1872. */
  1873. public function getWebsiteCatidArticle(array $data): array
  1874. {
  1875. $where = [
  1876. 'website_category.category_id' => $data['catid'],
  1877. 'website_category.website_id' => $data['website_id'],
  1878. ];
  1879. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1880. $child_catnum = $data['child_catnum'] ?? 1;
  1881. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1882. $childCategoryIds = array_column($category['child'], 'category_id');
  1883. if (empty($childCategoryIds)) {
  1884. return Result::error("暂无子栏目", 0);
  1885. }
  1886. $imgArticles = [];
  1887. $textArticles = [];
  1888. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1889. // 初始化子分类图片新闻和文字新闻数组
  1890. // 查询所有子级栏目的图文新闻
  1891. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1892. ->where(function ($query) use ($data) {
  1893. $query->where(function ($subQuery) use ($data) {
  1894. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1895. })->orWhereNull("ignore_ids");
  1896. })
  1897. ->where('status', 1)
  1898. ->where('imgurl', '!=', '')
  1899. ->select('*')
  1900. ->orderBy('updated_at', 'desc')
  1901. ->limit($data['child_imgnum'])
  1902. ->get();
  1903. }
  1904. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1905. // 查询所有子级栏目的文字新闻
  1906. $textArticles = Article::where('catid', $childCategoryIds[0])
  1907. ->where('status', 1)
  1908. ->where(function ($query) use ($data) {
  1909. $query->where(function ($subQuery) use ($data) {
  1910. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1911. })->orWhereNull("ignore_ids");
  1912. })
  1913. ->select('*')
  1914. ->orderBy('updated_at', 'desc')
  1915. ->limit($data['child_textnum'])
  1916. ->get();
  1917. }
  1918. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1919. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1920. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1921. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1922. return $child;
  1923. }, $category['child']);
  1924. }
  1925. // }
  1926. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1927. $category['img'] = WebsiteCategory::where($where)
  1928. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1929. ->where('article.status', 1)
  1930. ->where('article.imgurl', '!=', '')
  1931. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1932. ->orderBy('article.updated_at', 'desc')
  1933. ->limit($data['img_num'])
  1934. ->get();
  1935. }
  1936. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1937. $category['text'] = WebsiteCategory::where($where)
  1938. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1939. ->where('article.status', 1)
  1940. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1941. ->orderBy('article.updated_at', 'desc')
  1942. ->limit($data['text_num'])
  1943. ->get();
  1944. }
  1945. // $category = $category->get();
  1946. if (empty($category)) {
  1947. return Result::error("查询失败", 0);
  1948. }
  1949. return Result::success($category);
  1950. }
  1951. /**
  1952. * 模块新闻加强plus版
  1953. * @param array $data
  1954. * @return array
  1955. */
  1956. public function getWebsiteAllArticle(array $data): array
  1957. {
  1958. // return Result::success($data);
  1959. $time1 = microtime(true);
  1960. $wetbsite_id = $data['website_id'] ?? 2;
  1961. $data = json_decode($data['id'], true);
  1962. $website = Website::where('id', $wetbsite_id)->first();
  1963. if (empty($website)) {
  1964. return Result::error("网站不存在", 0);
  1965. }
  1966. // return Result::success($website);
  1967. $website_column = $website['website_column_arr_id'] ?? '[]';
  1968. $website_column = json_decode($website_column, true);
  1969. $categorys = $this->processArticlePro($wetbsite_id);
  1970. $cat_1st_arr = $categorys['cat_1st_arr'];
  1971. $catiall = $categorys['catiall'];
  1972. // return Result::success($catiall);
  1973. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1974. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1975. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1976. }
  1977. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1978. // return Result::success($categorys);
  1979. $parent_category = array_column($data, 'parent');
  1980. $parent_cat = [];
  1981. $child_category = array_column($data, 'child');
  1982. if (!empty($parent_category)) {
  1983. foreach ($parent_category as $key => $value) {
  1984. $arr = array_map('intval', explode(',', $value));
  1985. $parent_cat[$key] = $arr[0] ?? 0;
  1986. $parent_category = $arr[0] ?? 0;
  1987. $article_imgnum = $arr[1] ?? 0;
  1988. $article_textnum = $arr[2] ?? 0;
  1989. if ($parent_category != 0) {
  1990. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1991. // return Result::success($category_arr);
  1992. if ($article_imgnum != 0) {
  1993. $img_article = Article::whereIn('catid', $category_arr)
  1994. ->where('status', 1)
  1995. ->where('imgurl', '!=', '')
  1996. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1997. $query->from('article_ignore')
  1998. ->where('website_id', $wetbsite_id);
  1999. }, 'article_ignore', function ($join) {
  2000. $join->on('article_ignore.article_id', '=', 'article.id');
  2001. })
  2002. ->where(function ($query) {
  2003. $query->whereNull('article_ignore.article_id')
  2004. ->orWhere(function ($subQuery) {
  2005. $subQuery->whereNotNull('article_ignore.article_id')
  2006. ->where('article_ignore.is_ignore', 0)
  2007. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2008. });
  2009. })
  2010. ->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')
  2011. ->orderBy('updated_at', 'desc')
  2012. ->limit($article_imgnum)
  2013. ->get()->all();
  2014. foreach ($img_article as $k => $v) {
  2015. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2016. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2017. }
  2018. } else {
  2019. $img_article = [];
  2020. }
  2021. if ($article_textnum != 0) {
  2022. $text_article = Article::whereIn('catid', $category_arr)
  2023. ->where('status', 1)
  2024. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2025. $query->from('article_ignore')
  2026. ->where('website_id', $wetbsite_id);
  2027. }, 'article_ignore', function ($join) {
  2028. $join->on('article_ignore.article_id', '=', 'article.id');
  2029. })
  2030. ->where(function ($query) {
  2031. $query->whereNull('article_ignore.article_id')
  2032. ->orWhere(function ($subQuery) {
  2033. $subQuery->whereNotNull('article_ignore.article_id')
  2034. ->where('article_ignore.is_ignore', 0)
  2035. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2036. });
  2037. })
  2038. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2039. ->orderBy('updated_at', 'desc')
  2040. ->limit($article_textnum)
  2041. ->get()->all();
  2042. foreach ($text_article as $k => $v) {
  2043. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2044. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2045. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2046. }
  2047. } else {
  2048. $text_article = [];
  2049. }
  2050. $catiall[$parent_category]['imgnum'] = $img_article;
  2051. $catiall[$parent_category]['textnum'] = $text_article;
  2052. $parent[$key] = $catiall[$parent_category];
  2053. } else {
  2054. $parent[$key] = '';
  2055. }
  2056. }
  2057. }
  2058. if (!empty($child_category)) {
  2059. foreach ($child_category as $key => $value) {
  2060. $arr = array_map('intval', explode(',', $value));
  2061. $parent_category = $parent_cat[$key];
  2062. $child_category = $arr[0] ?? 0;
  2063. $article_imgnum = $arr[1] ?? 0;
  2064. $article_textnum = $arr[2] ?? 0;
  2065. if ($child_category != 0) {
  2066. $all_childcat = $cat_1st_arr[$parent_category];
  2067. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2068. // 从 $websiteInfoIndexed 中获取对应的数据
  2069. $info = $websiteInfoIndexed[$v];
  2070. // 返回一个包含所需信息的数组
  2071. return [
  2072. 'alias' => $info->alias,
  2073. 'category_id' => $info->category_id,
  2074. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2075. 'pid' => $info->pid,
  2076. 'type' => $info->type,
  2077. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2078. 'pinyin' => $info->pinyin,
  2079. ];
  2080. }, $all_childcat);
  2081. if ($article_imgnum != 0) {
  2082. $img_article = Article::where('catid', $child_category)
  2083. ->where('status', 1)
  2084. ->where('imgurl', '!=', '')
  2085. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2086. $query->from('article_ignore')
  2087. ->where('website_id', $wetbsite_id);
  2088. }, 'article_ignore', function ($join) {
  2089. $join->on('article_ignore.article_id', '=', 'article.id');
  2090. })
  2091. ->where(function ($query) {
  2092. $query->whereNull('article_ignore.article_id')
  2093. ->orWhere(function ($subQuery) {
  2094. $subQuery->whereNotNull('article_ignore.article_id')
  2095. ->where('article_ignore.is_ignore', 0)
  2096. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2097. });
  2098. })
  2099. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2100. ->orderBy('updated_at', 'desc')
  2101. ->limit($article_imgnum)
  2102. ->get()->all();
  2103. foreach ($img_article as $k => $v) {
  2104. // var_dump($v);
  2105. // var_dump($k);
  2106. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2107. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2108. }
  2109. } else {
  2110. $img_article = [];
  2111. }
  2112. if ($article_textnum != 0) {
  2113. $text_article = Article::where('catid', $child_category)
  2114. ->where('status', 1)
  2115. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2116. $query->from('article_ignore')
  2117. ->where('website_id', $wetbsite_id);
  2118. }, 'article_ignore', function ($join) {
  2119. $join->on('article_ignore.article_id', '=', 'article.id');
  2120. })
  2121. ->where(function ($query) {
  2122. $query->whereNull('article_ignore.article_id')
  2123. ->orWhere(function ($subQuery) {
  2124. $subQuery->whereNotNull('article_ignore.article_id')
  2125. ->where('article_ignore.is_ignore', 0)
  2126. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2127. });
  2128. })
  2129. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2130. ->orderBy('updated_at', 'desc')
  2131. ->limit($article_textnum)
  2132. ->get()->all();
  2133. foreach ($text_article as $k => $v) {
  2134. // var_dump($v);
  2135. // var_dump($k);
  2136. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2137. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2138. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2139. }
  2140. } else {
  2141. $text_article = [];
  2142. }
  2143. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2144. $catiall[$child_category]['imgnum'] = $img_article;
  2145. $catiall[$child_category]['textnum'] = $text_article;
  2146. $child[$key] = $catiall[$child_category];
  2147. // var_dump($pids);
  2148. } else {
  2149. $child[$key] = '';
  2150. }
  2151. }
  2152. }
  2153. foreach ($parent as $key => $value) {
  2154. $result[$key] = $value;
  2155. if (!empty($child[$key])) {
  2156. // var_dump($child[$key]);
  2157. $result[$key]['child'] = $child[$key];
  2158. // $value[$key]['child'] = $child[$key];
  2159. } else {
  2160. $result[$key]['child'] = [
  2161. "alias" => null,
  2162. "category_id" => null,
  2163. "type" => null,
  2164. "pinyin" => null,
  2165. "all_childcat" => [],
  2166. "imgnum" => [],
  2167. "textnum" => []
  2168. ];
  2169. }
  2170. }
  2171. return Result::success($result);
  2172. }
  2173. /**
  2174. * 辅助方法:获取文章列表
  2175. */
  2176. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2177. {
  2178. sleep(1);
  2179. $query = Article::where('article.status', 1)
  2180. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2181. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2182. ->where(function ($query) use ($website) {
  2183. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2184. })
  2185. ->leftJoin('website_category', function ($join) use ($website) {
  2186. $join->on('article.catid', '=', 'website_category.category_id')
  2187. ->where('website_category.website_id', '=', $website['website_id']);
  2188. })
  2189. ->select(
  2190. 'article.id',
  2191. 'article.title',
  2192. 'article.imgurl',
  2193. 'article.author',
  2194. 'article.updated_at',
  2195. 'article.introduce',
  2196. 'article.islink',
  2197. 'article.linkurl',
  2198. 'article.copyfrom',
  2199. 'article.cat_arr_id',
  2200. 'article.catid',
  2201. 'website_category.alias as category_name'
  2202. )
  2203. ->orderBy('updated_at', 'desc')
  2204. ->limit($limit);
  2205. // 如果是图片文章,添加图片URL条件
  2206. if ($isImageArticle) {
  2207. $query->where('imgurl', '!=', '');
  2208. } else {
  2209. // 文字文章不需要imgurl字段
  2210. $query->addSelect('article.introduce');
  2211. }
  2212. $articles = $query->get();
  2213. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2214. }
  2215. /**
  2216. * 乡村网-获取特殊新闻模块
  2217. * @param array $data
  2218. * @return array
  2219. */
  2220. public function getWebsiteArticles(array $data): array
  2221. {
  2222. $website_id = $data['website_id'];
  2223. $website = Website::where('id', $website_id)->first();
  2224. if (empty($website)) {
  2225. return Result::error("网站不存在", 0);
  2226. }
  2227. // return Result::success($website);
  2228. $website_column = $website['website_column_arr_id'] ?? '[]';
  2229. $website_column = json_decode($website_column, true);
  2230. $catids = json_decode($data['id'], true);
  2231. $parent_category = array_column($catids, 'parent');
  2232. if (!empty($parent_category) && is_array($parent_category)) {
  2233. $categorys = $this->processArticlePro($website_id);
  2234. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2235. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2236. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2237. }
  2238. $catiall = $categorys['catiall'];
  2239. $cat_1st_arr = $categorys['cat_1st_arr'];
  2240. // return Result::success($categorys);
  2241. foreach ($parent_category as $key => $value) {
  2242. $arr = array_map('intval', explode(',', $value));
  2243. $parent_category = $arr[0] ?? 0;
  2244. $article_imgnum = $arr[1] ?? 0;
  2245. $article_textnum = $arr[2] ?? 0;
  2246. if ($parent_category != 0) {
  2247. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2248. // return Result::success($category_arr);
  2249. if ($article_imgnum != 0) {
  2250. $img_article = Article::whereIn('article.catid', $category_arr)
  2251. ->where('article.status', 1)
  2252. ->where('article.imgurl', '!=', '')
  2253. ->leftJoinSub(function ($query) use ($website_id) {
  2254. $query->from('article_ignore')
  2255. ->where('website_id', $website_id);
  2256. }, 'article_ignore', function ($join) {
  2257. $join->on('article_ignore.article_id', '=', 'article.id');
  2258. })
  2259. ->where(function ($query) {
  2260. $query->whereNull('article_ignore.article_id')
  2261. ->orWhere(function ($subQuery) {
  2262. $subQuery->whereNotNull('article_ignore.article_id')
  2263. ->where('article_ignore.is_ignore', 0)
  2264. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2265. });
  2266. })
  2267. ->select(
  2268. 'article.id',
  2269. 'article.title',
  2270. 'article.imgurl',
  2271. 'article.author',
  2272. 'article.updated_at',
  2273. 'article.introduce',
  2274. 'article.islink',
  2275. 'article.linkurl',
  2276. 'article.copyfrom',
  2277. 'article.cat_arr_id',
  2278. 'article.catid as category_id'
  2279. )
  2280. ->orderBy('updated_at', 'desc')
  2281. ->limit($article_imgnum)
  2282. ->get()->all();
  2283. foreach ($img_article as $k => $v) {
  2284. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2285. // return Result::success($v);
  2286. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2287. }
  2288. } else {
  2289. $img_article = [];
  2290. }
  2291. if ($article_textnum != 0) {
  2292. $text_article = Article::whereIn('article.catid', $category_arr)
  2293. ->where('article.status', 1)
  2294. ->leftJoinSub(function ($query) use ($website_id) {
  2295. $query->from('article_ignore')
  2296. ->where('website_id', $website_id);
  2297. }, 'article_ignore', function ($join) {
  2298. $join->on('article_ignore.article_id', '=', 'article.id');
  2299. })
  2300. ->where(function ($query) {
  2301. $query->whereNull('article_ignore.article_id')
  2302. ->orWhere(function ($subQuery) {
  2303. $subQuery->whereNotNull('article_ignore.article_id')
  2304. ->where('article_ignore.is_ignore', 0)
  2305. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2306. });
  2307. })
  2308. ->select(
  2309. 'article.id',
  2310. 'article.title',
  2311. 'article.author',
  2312. 'article.updated_at',
  2313. 'article.introduce',
  2314. 'article.islink',
  2315. 'article.linkurl',
  2316. 'article.copyfrom',
  2317. 'article.cat_arr_id',
  2318. 'article.catid as category_id'
  2319. )
  2320. ->orderBy('updated_at', 'desc')
  2321. ->limit($article_textnum)
  2322. ->get()->all();
  2323. foreach ($text_article as $k => $v) {
  2324. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2325. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2326. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2327. }
  2328. } else {
  2329. $text_article = [];
  2330. }
  2331. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2332. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2333. $parent[$key] = $catiall[$parent_category];
  2334. } else {
  2335. $parent[$key] = [];
  2336. }
  2337. }
  2338. }
  2339. return Result::success($parent);
  2340. }
  2341. // 封装处理商品的路由问题
  2342. function processGoods($goods, $data)
  2343. {
  2344. return $goods->map(function ($good) use ($data) {
  2345. $catid = $good->catid ?? 0;
  2346. // $pinyin = '';
  2347. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2348. if (!empty($category->pid) && $category->pid != 0) {
  2349. $level = json_decode($category->category_arr_id, true);
  2350. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2351. ->whereIn('category_id', $level)
  2352. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2353. ->get(['aLIas_pinyin'])
  2354. ->pluck('aLIas_pinyin')
  2355. ->implode('/');
  2356. } else {
  2357. $pinyin = $category->aLIas_pinyin ?? '';
  2358. }
  2359. if (isset($good->city_id) && !empty($good->city_id)) {
  2360. $city = District::where('id', $good->city_id)->first(['name']);
  2361. $good->city_name = $city->name ?? '';
  2362. }
  2363. // 解析imgurl JSON并取第一条数据
  2364. $imgUrls = json_decode($good->imgurl, true);
  2365. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2366. $good->pinyin = $pinyin;
  2367. return $good;
  2368. });
  2369. }
  2370. /**
  2371. * 获取商城首页-根据栏目id
  2372. * @param array $data
  2373. * @return array
  2374. * */
  2375. function getWebsiteCatidshop(array $data): array
  2376. {
  2377. $input['catid'] = $data['catid'];
  2378. $input['website_id'] = $data['website_id'];
  2379. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2380. $result = array_map(function ($item) use ($input) {
  2381. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2382. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2383. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2384. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2385. if (empty($category) || $category->type != 2) {
  2386. return Result::error("暂无此栏目", 0);
  2387. } else {
  2388. $website['website_id'] = $input['website_id'];
  2389. $goods = Good::where('good.status', 2)
  2390. ->where('good.website_id', $website['website_id'])
  2391. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2392. ->select(
  2393. 'good.id',
  2394. 'good.name',
  2395. 'good.imgurl',
  2396. 'good.description',
  2397. 'good.updated_at',
  2398. 'good.catid',
  2399. 'good.type_id',
  2400. 'good.price',
  2401. 'good.com',
  2402. 'good.level',
  2403. 'good.unit'
  2404. )
  2405. ->orderBy('updated_at', 'desc')
  2406. ->offset($goodStart)
  2407. ->limit($goodNum);
  2408. $all_goods = $goods->get();
  2409. $all_goods = $this->processGoods($all_goods, $website);
  2410. }
  2411. return $all_goods ?? [];
  2412. }
  2413. }, $data);
  2414. return Result::success($result);
  2415. }
  2416. /**
  2417. * 获取商品模块
  2418. * @param array $data
  2419. * @return array
  2420. * */
  2421. public function getWebsiteshop(array $data): array
  2422. {
  2423. $input['id'] = $data['id'];
  2424. $input['website_id'] = $data['website_id'];
  2425. $catid = $data['catid'];
  2426. $data = json_decode($input['id'] ?? '', true) ?? [];
  2427. $result['goods'] = array_map(function ($item) use ($input) {
  2428. // 检查parent元素是否存在且不是undefined
  2429. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2430. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2431. $website = $input['website_id'];
  2432. $query = Good::where('good.status', 2)
  2433. ->where('good.website_id', $website);
  2434. switch ($Levelid) {
  2435. case 1:
  2436. case 2:
  2437. case 3:
  2438. $goods = $query->where(function ($q) use ($Levelid) {
  2439. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2440. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2441. });
  2442. break;
  2443. case 4:
  2444. $goods = $query;
  2445. break;
  2446. case 5:
  2447. $goods = $query->where('type_id', 1);
  2448. break;
  2449. case 6:
  2450. $goods = $query->where('type_id', 2);
  2451. break;
  2452. default:
  2453. return [];
  2454. }
  2455. $all_goods = $goods
  2456. ->select(
  2457. 'good.id',
  2458. 'good.name',
  2459. 'good.imgurl',
  2460. 'good.description',
  2461. 'good.updated_at',
  2462. 'good.catid',
  2463. 'good.type_id',
  2464. 'good.price',
  2465. 'good.level',
  2466. 'good.website_id'
  2467. )
  2468. ->orderBy('updated_at', 'desc')
  2469. ->offset($goodStart)
  2470. ->limit($goodNum)
  2471. ->get();
  2472. $web['website_id'] = $website;
  2473. $all_goods = $this->processGoods($all_goods, $web);
  2474. }
  2475. return $all_goods;
  2476. }, $data);
  2477. $website = $input['website_id'];
  2478. $result['article'] = Article::where(function ($query) use ($website) {
  2479. $query->where(function ($subQuery) use ($website) {
  2480. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2481. })->orWhereNull("ignore_ids");
  2482. })
  2483. ->where('catid', $catid)
  2484. ->where('article.status', 1)
  2485. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2486. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2487. ->orderBy('article.updated_at', 'desc')
  2488. ->first();
  2489. return Result::success($result);
  2490. }
  2491. /**
  2492. * 获取商品分类
  2493. * @param array $data
  2494. * @return array
  2495. * */
  2496. public function getWebsiteshopCat(array $data): array
  2497. {
  2498. $website = $data['website_id'];
  2499. $category = WebsiteCategory::where('website_id', $website)
  2500. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2501. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2502. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2503. ->orderBy('sort')
  2504. ->get();
  2505. $cat = $category->map(function ($item) use ($website) {
  2506. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2507. $pid = $item->pid ?? 0;
  2508. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2509. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2510. ->where('website_id', $website)
  2511. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2512. ->get(['aLIas_pinyin'])
  2513. ->pluck('aLIas_pinyin')
  2514. ->implode('/');
  2515. } else {
  2516. $pinyin = $item->aLIas_pinyin ?? '';
  2517. }
  2518. $item->pinyin = $pinyin;
  2519. });
  2520. if (empty($category)) {
  2521. return Result::error("栏目查询失败", 0);
  2522. }
  2523. $cat_tree = Result::buildMenuTree($category);
  2524. $web['website_id'] = $website;
  2525. $goods = Good::where('website_id', $website)
  2526. ->where('status', 2)
  2527. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2528. ->latest('updated_at')
  2529. ->offset(($data['page'] - 1) * $data['pageSize'])
  2530. ->limit($data['pageSize'])
  2531. ->get();
  2532. if (!empty($goods)) {
  2533. if ($goods->count() > 1 && !empty($goods)) {
  2534. $goods = $this->processGoods($goods, $web);
  2535. }
  2536. } else {
  2537. $goods = [];
  2538. }
  2539. $result = [
  2540. 'category' => $cat_tree,
  2541. 'goods' => $goods,
  2542. ];
  2543. // $resul['goods'] = $goods;
  2544. if (empty($result)) {
  2545. return Result::error("查询失败", 0);
  2546. }
  2547. return Result::success($result);
  2548. }
  2549. /*
  2550. * 获取商品列表
  2551. * @param array $data
  2552. * @return array
  2553. * */
  2554. public function getWebsiteshopList(array $data): array
  2555. {
  2556. // return Result::success($data);
  2557. $where = [
  2558. 'status' => 2,
  2559. 'website_id' => $data['website_id'],
  2560. ];
  2561. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2562. // return Result::error("查询失败", 0);
  2563. // }
  2564. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2565. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2566. $data['catid'] = $category->category_id ?? 0;
  2567. }
  2568. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2569. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2570. }
  2571. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2572. array_push($where, ['type_id', $data['type_id']]);
  2573. }
  2574. $query = Good::where($where)
  2575. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2576. $query->where(function ($q) use ($data) {
  2577. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2578. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2579. });
  2580. })
  2581. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2582. $query->where(function ($q) use ($data) {
  2583. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2584. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2585. });
  2586. })
  2587. ->select(
  2588. 'good.id',
  2589. 'good.name',
  2590. 'good.imgurl',
  2591. 'good.description',
  2592. 'good.updated_at',
  2593. 'good.com',
  2594. 'good.catid',
  2595. 'good.type_id',
  2596. 'good.website_id',
  2597. 'good.cat_arr_id',
  2598. 'good.created_at',
  2599. 'good.city_id'
  2600. )
  2601. ->latest('updated_at');
  2602. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2603. $result['count'] = $query->clone()->count();
  2604. $result['goods'] = $this->processGoods(
  2605. $query->clone()
  2606. ->offset(($data['page'] - 1) * $data['pageSize'])
  2607. ->limit($data['pageSize'])
  2608. ->get(),
  2609. $data
  2610. );
  2611. } else {
  2612. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2613. // 获取 type_id 为 1 的数据
  2614. $result['type1'] = $this->processGoods(
  2615. $query->clone()
  2616. ->where('type_id', 1)
  2617. ->offset(($data['page'] - 1) * $data['pageSize'])
  2618. ->limit($data['pageSize'])
  2619. ->get(),
  2620. $data
  2621. );
  2622. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2623. // 获取 type_id 为 2 的数据
  2624. $result['type2'] = $this->processGoods(
  2625. $query->clone()
  2626. ->where('type_id', 2)
  2627. ->offset(($data['page'] - 1) * $data['pageSize'])
  2628. ->limit($data['pageSize'])
  2629. ->get(),
  2630. $data
  2631. );
  2632. }
  2633. if (empty($result)) {
  2634. return Result::error("查询失败", 0);
  2635. }
  2636. return Result::success($result);
  2637. }
  2638. /**
  2639. * 获取商品详情
  2640. * @param array $data
  2641. * @return array
  2642. * */
  2643. public function getWebsiteshopInfo(array $data): array
  2644. {
  2645. $where = [
  2646. 'good.status' => 2,
  2647. 'good.website_id' => $data['website_id'],
  2648. 'good.id' => $data['id'],
  2649. ];
  2650. $goods = Good::where($where)
  2651. ->where('good.id', $data['id'])
  2652. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2653. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2654. ->first();
  2655. if (empty($goods)) {
  2656. return Result::error("查询失败", 0);
  2657. }
  2658. $goods->imgurl = json_decode($goods->imgurl, true);
  2659. return Result::success($goods);
  2660. }
  2661. /**
  2662. * plus pro 处理文章路由问题
  2663. */
  2664. function processArticlePro($website_id)
  2665. {
  2666. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2667. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2668. // // 取出category_id 对应的aLIas_pinyin
  2669. // $categoryIds = array_column($categorys, 'category_id');
  2670. // $categoryPIds = array_column($categorys, 'pid');
  2671. // $aliasPinyins = array_column($categorys, 'path');
  2672. // $alias = array_column($categorys, 'alias');
  2673. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2674. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2675. // // return Result::success($cat_arr);
  2676. // // $catiall = [];
  2677. // //一级所有子级的记录
  2678. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2679. // return [
  2680. // 'cat_1st_arr' => $cat_alias_arr,
  2681. // 'catiall' => $cat_arr,
  2682. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2683. // 'categoryIds' => $categoryIds,
  2684. // ];
  2685. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2686. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2687. // 取出category_id 对应的aLIas_pinyin
  2688. $categoryIds = array_column($categorys, 'category_id');
  2689. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2690. return $pid != 0;
  2691. })));
  2692. $category_path = array_column($categorys, 'path');
  2693. $cat_arr = array_combine($categoryIds, $category_path);
  2694. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2695. $catiall = [];
  2696. //一级所有子级的记录
  2697. $cat_1st_arr = [];
  2698. foreach ($categorys as $key => $value) {
  2699. // $category_arr_id = json_decode($value->category_arr_id);
  2700. // $pinyin_str = '';
  2701. // // 算出一级 并且算出子级
  2702. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2703. $cat_1st_arr[$value->pid][] = $value->category_id;
  2704. }
  2705. // foreach ($category_arr_id as $k => $v) {
  2706. // $pinyin_str .= $cat_arr[$v] . '/';
  2707. // }
  2708. // $pinyin_str = rtrim($pinyin_str, '/');
  2709. $catiall[$value->category_id]['alias'] = $value->alias;
  2710. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2711. $catiall[$value->category_id]['type'] = $value->type;
  2712. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2713. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2714. }
  2715. return [
  2716. 'cat_1st_arr' => $cat_1st_arr,
  2717. 'catiall' => $catiall,
  2718. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2719. 'categoryIds' => $categoryIds,
  2720. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2721. 'categoryPIds' => $categoryPIds,
  2722. ];
  2723. }
  2724. /**
  2725. * 封装处理文章的路由问题
  2726. * */
  2727. function processArticles($articles, $data)
  2728. {
  2729. // 检查 $articles 是否为数组或可迭代对象
  2730. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2731. return $articles->map(function ($article) use ($data) {
  2732. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2733. $catid = $article->cat_arr_id ?? '';
  2734. }
  2735. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2736. $catid = $article->category_arr_id ?? '';
  2737. }
  2738. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2739. $level = json_decode($catid, true);
  2740. if (!is_array($level)) {
  2741. return $article;
  2742. } else {
  2743. $level = array_map('intval', $level);
  2744. }
  2745. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2746. ->where($data)
  2747. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2748. ->pluck('aLIas_pinyin')
  2749. ->implode('/');
  2750. $article->pinyin = $pinyin ?? '';
  2751. return $article;
  2752. });
  2753. } else {
  2754. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2755. $catid = $articles->cat_arr_id ?? '';
  2756. $level = json_decode($catid, true);
  2757. if (!is_array($level)) {
  2758. return $articles;
  2759. } else {
  2760. $level = array_map('intval', $level);
  2761. }
  2762. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2763. ->where($data)
  2764. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2765. ->pluck('aLIas_pinyin')
  2766. ->implode('/');
  2767. $articles->pinyin = $pinyin ?? '';
  2768. return $articles;
  2769. }
  2770. }
  2771. // 封装处理由问题
  2772. function processJob($job, $data)
  2773. {
  2774. return $job->map(function ($job) use ($data) {
  2775. $category = $job->cat_arr_id ?? '';
  2776. $cityid = $job->city_arr_id ?? '';
  2777. $city = json_decode($cityid, true);
  2778. $pinyin = '';
  2779. $level = json_decode($category, true);
  2780. // 路由
  2781. if (!empty($level) && is_array($level)) {
  2782. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2783. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2784. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2785. ->get(['aLIas_pinyin'])
  2786. ->pluck('aLIas_pinyin')
  2787. ->implode('/');
  2788. if (empty($pinyin)) {
  2789. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2790. }
  2791. $job->pinyin = $pinyin;
  2792. }
  2793. // 取职位-城市 市??省
  2794. if (!empty($city) && is_array($city)) {
  2795. if (isset($city[1]) && !empty($city[1])) {
  2796. $city = District::where('id', $city[1])->first(['name']);
  2797. $job->city_name = $city->name ?? '';
  2798. } else if (isset($city[0]) && !empty($city[0])) {
  2799. $city = District::where('id', $city[0])->first(['name']);
  2800. $job->city_name = $city->name ?? '';
  2801. } else {
  2802. $job->city_name = '全国';
  2803. }
  2804. }
  2805. // 获取简历最后一级地区
  2806. if (isset($job->city_id) && !empty($job->city_id)) {
  2807. $city = District::where('id', $job->city_id)->first(['name']);
  2808. $job->hunt_cityname = $city->name ?? '';
  2809. }
  2810. // 组合详细地址
  2811. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2812. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2813. if (is_array($address_id) && !empty($address_id)) {
  2814. $address = District::whereIn('id', $address_id)
  2815. ->orderBy('level', 'asc')
  2816. ->get(['name'])
  2817. ->pluck('name')
  2818. ->implode('');
  2819. // $job->address_name = $address ?? '';
  2820. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2821. }
  2822. }
  2823. // 取行业
  2824. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2825. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2826. if (!empty($job->industry)) {
  2827. $query->where('hyid', $job->industry);
  2828. } else if (!empty($job->hy_id)) {
  2829. $query->where('hyid', $job->hy_id);
  2830. } else if (!empty($job->company_hy_id)) {
  2831. $query->where('hyid', $job->company_hy_id);
  2832. } else {
  2833. $query->where('hyid', $job->job_industry);
  2834. }
  2835. })->first(['hyname']);
  2836. $job->hy_name = $hy_name->hyname ?? '';
  2837. }
  2838. // 取职位类别
  2839. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2840. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2841. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2842. $job->zw_name = $zw_name->zwname ?? '';
  2843. }
  2844. // 取具体职位
  2845. 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))) {
  2846. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2847. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2848. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2849. }
  2850. // 取工作经验
  2851. if (isset($job->experience) && !empty($job->experience)) {
  2852. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2853. $job->experience_name = $experience->ename ?? '';
  2854. }
  2855. // 取学历
  2856. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2857. $education = $job->educational ?? $job->school_education;
  2858. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2859. $job->education_name = $education->ename ?? '';
  2860. }
  2861. // 语言
  2862. if (isset($job->language) && !empty($job->language)) {
  2863. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2864. $job->language_name = $language->ename ?? '';
  2865. }
  2866. // 薪资
  2867. if (isset($job->salary) && !empty($job->salary)) {
  2868. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2869. $job->salary_name = $salary->ename ?? '';
  2870. }
  2871. // 职位性质
  2872. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2873. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2874. $job->job_nature_name = $job_nature->ename ?? '';
  2875. }
  2876. // 公司规模
  2877. if (isset($job->company_size) && !empty($job->company_size)) {
  2878. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2879. $job->company_size_name = $company_size->ename ?? '';
  2880. }
  2881. // 公司性质
  2882. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2883. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2884. $job->company_nature_name = $company_nature->nature_name ?? '';
  2885. }
  2886. // $job->pinyin = $pinyin;
  2887. return $job;
  2888. });
  2889. }
  2890. /**
  2891. * 获取书籍模块
  2892. * @param array $data
  2893. * @return array
  2894. * */
  2895. public function getWebsiteBook(array $data): array
  2896. {
  2897. $input['id'] = $data['id'];
  2898. $input['website_id'] = $data['website_id'];
  2899. // 将 JSON 字符串转换为 PHP 数组
  2900. $data = json_decode($input['id'], true);
  2901. // 使用 array_map 处理每个元素
  2902. $result = array_map(function ($item) use ($input) {
  2903. // 检查parent元素是否存在且不是undefined
  2904. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2905. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2906. $website = [
  2907. 'website_id' => $input['website_id'],
  2908. ];
  2909. // 查询栏目名称
  2910. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2911. if (empty($category)) {
  2912. $parent_alias = '';
  2913. $parent_pinyin = null;
  2914. $imgBooks = [];
  2915. $textBooks = [];
  2916. } else {
  2917. $parent_alias = $category->alias ?? '';
  2918. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2919. // 查找子分类ID数组
  2920. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2921. array_push($childCategoryIds, $parentCatId);
  2922. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2923. if ($parentImgNum != 0) {
  2924. // 查询图片新闻
  2925. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2926. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2927. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2928. })
  2929. ->where('book.status', 2)
  2930. ->where('book.img_url', '!=', '')
  2931. ->where('book.website_id', $website['website_id'])
  2932. ->leftJoin('website_category', function ($join) use ($website) {
  2933. $join->on('book.cat_id', '=', 'website_category.category_id')
  2934. ->where('website_category.website_id', '=', $website['website_id']);
  2935. })
  2936. ->select(
  2937. 'book.id',
  2938. 'book.title',
  2939. 'book.img_url',
  2940. 'book.price',
  2941. 'book.market_price',
  2942. 'book.description',
  2943. 'book.cat_id',
  2944. 'book.description',
  2945. 'book.updated_at',
  2946. 'website_category.alias as category_name',
  2947. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2948. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2949. )
  2950. ->orderBy('updated_at', 'desc')
  2951. ->limit($parentImgNum)
  2952. ->get()->all();
  2953. // 查询文字新闻
  2954. }
  2955. if ($parentTextNum != 0) {
  2956. $textBooks = [];
  2957. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2958. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2959. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2960. })
  2961. ->where('book.status', 2)
  2962. ->where('book.website_id', $website['website_id'])
  2963. ->leftJoin('website_category', function ($join) use ($website) {
  2964. $join->on('book.cat_id', '=', 'website_category.category_id')
  2965. ->where('website_category.website_id', '=', $website['website_id']);
  2966. })
  2967. ->select(
  2968. 'book.id',
  2969. 'book.title',
  2970. 'book.img_url',
  2971. 'book.price',
  2972. 'book.market_price',
  2973. 'book.description',
  2974. 'book.cat_id',
  2975. 'book.description',
  2976. 'book.updated_at',
  2977. 'website_category.alias as category_name',
  2978. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2979. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2980. )
  2981. ->orderBy('updated_at', 'desc')
  2982. ->limit($parentTextNum)
  2983. ->get()->all();
  2984. }
  2985. }
  2986. }
  2987. $resultItem = [
  2988. 'alias' => $parent_alias ?? '',
  2989. 'category_id' => $parentCatId ?? 0,
  2990. 'pinyin' => $parent_pinyin ?? null,
  2991. 'imgnum' => $imgBooks ?? [],
  2992. 'textnum' => $textBooks ?? [],
  2993. ];
  2994. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2995. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2996. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2997. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2998. ->get()->all();
  2999. if (!empty($childCategory)) {
  3000. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3001. // 查询子栏目名称
  3002. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3003. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3004. ->first();
  3005. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3006. $childImgArticles = [];
  3007. $childTextArticles = [];
  3008. $resultItem['child'] = [];
  3009. } else {
  3010. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3011. // 查询子栏目图片新闻
  3012. $childImgArticles = Book::where('cat_id', $childCatId)
  3013. ->where('status', 2)
  3014. ->where('img_url', '!=', '')
  3015. ->where('book.website_id', $website['website_id'])
  3016. ->leftJoin('website_category', function ($join) use ($website) {
  3017. $join->on('book.cat_id', '=', 'website_category.category_id')
  3018. ->where('website_category.website_id', '=', $website['website_id']);
  3019. })
  3020. ->select(
  3021. 'book.id',
  3022. 'book.title',
  3023. 'book.img_url',
  3024. 'book.price',
  3025. 'book.market_price',
  3026. 'book.description',
  3027. 'book.cat_id',
  3028. 'book.description',
  3029. 'book.updated_at',
  3030. DB::raw("'$child_pinyin' as pinyin")
  3031. )
  3032. ->orderBy('updated_at', 'desc')
  3033. ->limit($childImgNum)
  3034. ->get()->all();
  3035. // 查询子栏目文字新闻
  3036. $childTextArticles = Book::where('cat_id', $childCatId)
  3037. ->where('status', 2)
  3038. ->where('book.website_id', $website['website_id'])
  3039. ->leftJoin('website_category', function ($join) use ($website) {
  3040. $join->on('book.cat_id', '=', 'website_category.category_id')
  3041. ->where('website_category.website_id', '=', $website['website_id']);
  3042. })
  3043. ->select(
  3044. 'book.id',
  3045. 'book.title',
  3046. 'book.img_url',
  3047. 'book.price',
  3048. 'book.market_price',
  3049. 'book.description',
  3050. 'book.cat_id',
  3051. 'book.description',
  3052. 'book.updated_at',
  3053. DB::raw("'$child_pinyin' as pinyin")
  3054. )
  3055. ->orderBy('updated_at', 'desc')
  3056. ->limit($childTextNum)
  3057. ->get()->all();
  3058. $resultItem['child'] = [
  3059. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3060. 'category_id' => $childCatId,
  3061. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3062. 'all_childcat' => $childCategory,
  3063. 'imgnum' => $childImgArticles,
  3064. 'textnum' => $childTextArticles,
  3065. ];
  3066. }
  3067. }
  3068. } else {
  3069. $resultItem['child'] = [];
  3070. }
  3071. return $resultItem;
  3072. }, $data);
  3073. return Result::success($result);
  3074. }
  3075. /**
  3076. * 获取书刊列表
  3077. * @param array $data
  3078. * @return array
  3079. * */
  3080. public function getWebsiteBookList(array $data): array
  3081. {
  3082. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3083. if (empty($web)) {
  3084. return Result::error("查询失败", 0);
  3085. }
  3086. $catid = $data['id'];
  3087. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3088. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3089. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3090. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3091. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3092. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3093. ->where('pid', $category['pid'])
  3094. ->select(
  3095. 'category_id',
  3096. 'alias',
  3097. 'aLIas_pinyin',
  3098. 'pid',
  3099. 'sort',
  3100. 'is_url',
  3101. 'web_url',
  3102. 'seo_title',
  3103. 'seo_keywords',
  3104. 'seo_description',
  3105. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3106. )
  3107. ->orderBy('sort')
  3108. ->get()->all();
  3109. if (empty($category)) {
  3110. return Result::error("查询失败", 0);
  3111. }
  3112. $query = Book::where('book.status', 2)
  3113. ->where('book.website_id', $data['website_id'])
  3114. ->where('book.cat_id', $catid)
  3115. ->select(
  3116. 'book.id',
  3117. 'book.title',
  3118. 'book.img_url',
  3119. 'book.description',
  3120. 'book.updated_at',
  3121. 'book.cat_id',
  3122. DB::raw("'$pinyin' as pinyin")
  3123. )
  3124. ->orderBy('book.updated_at', 'desc');
  3125. $count = $query->count();
  3126. $query = clone $query;
  3127. $Book = $query
  3128. ->limit($data['pageSize'])
  3129. ->offset(($data['page'] - 1) * $data['pageSize'])
  3130. ->get()->all();
  3131. $result = [
  3132. 'category' => $categorys,
  3133. 'books' => $Book,
  3134. 'count' => $count,
  3135. ];
  3136. // if(empty($result)){
  3137. // return Result::error("查询失败", 0);
  3138. // }
  3139. return Result::success($result);
  3140. }
  3141. /**
  3142. * 获取书刊详情
  3143. * @param array $data
  3144. * @return array
  3145. * */
  3146. public function getWebsiteBookInfo(array $data): array
  3147. {
  3148. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3149. if (empty($web)) {
  3150. return Result::error("查询失败", 0);
  3151. }
  3152. $book = Book::where('status', 2)
  3153. ->where('website_id', $data['website_id'])
  3154. ->where('id', $data['id'])
  3155. ->select(
  3156. 'book.*',
  3157. )
  3158. ->orderBy('updated_at', 'desc')
  3159. ->first();
  3160. if (empty($book)) {
  3161. return Result::error("查询失败", 0);
  3162. }
  3163. // 先查询当前分类的 pid
  3164. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3165. ->where('category_id', $book['cat_id'])
  3166. ->first(['pid', 'category_id']);
  3167. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3168. if (!empty($carpid)) {
  3169. if ($carpid->pid != 0) {
  3170. $pid = $carpid['pid'];
  3171. // $parent_pinyin = '';
  3172. } else {
  3173. $pid = $carpid['category_id'];
  3174. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3175. }
  3176. }
  3177. $categorys = $query->where('pid', $pid)
  3178. ->select(
  3179. 'category_id',
  3180. 'alias',
  3181. 'aLIas_pinyin',
  3182. 'pid',
  3183. 'sort',
  3184. 'is_url',
  3185. 'web_url',
  3186. 'category_arr_id as cat_arr_id',
  3187. )
  3188. ->orderBy('sort')
  3189. ->get();
  3190. $category = $this->processArticle($categorys, $data);
  3191. $result = [
  3192. 'category' => $category,
  3193. 'books' => $book,
  3194. ];
  3195. return Result::success($result);
  3196. }
  3197. /**
  3198. * 尝试
  3199. * @param array $data
  3200. * @return array
  3201. * */
  3202. public function test(array $data): array
  3203. {
  3204. $input['id'] = $data['id'];
  3205. $input['website_id'] = $data['website_id'];
  3206. // 将 JSON 字符串转换为 PHP 数组
  3207. $data = json_decode($input['id'], true);
  3208. $result = [];
  3209. $article = $data;
  3210. $result = array_map(function ($item) use ($input) {
  3211. $website = [
  3212. 'website_id' => $input['website_id'],
  3213. ];
  3214. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3215. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3216. $parent = [
  3217. 0 => $category['category_id'] ?? [],
  3218. 1 => $parentImgNum ?? [],
  3219. 2 => $parentTextNum ?? [],
  3220. ];
  3221. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3222. $child = [];
  3223. $resultItem = [
  3224. // 'alias' => $parent_alias ?? '',
  3225. 'category_id' => $parentCatId ?? 0,
  3226. 'pinyin' => $parentImgNum ?? null,
  3227. 'imgnum' => $parentTextNum ?? [],
  3228. // 'textnum' => $textArticles ?? [],
  3229. ];
  3230. return $parent;
  3231. }, $data);
  3232. return Result::success($result);
  3233. // });
  3234. }
  3235. /**
  3236. * 封装处理文章的路由问题
  3237. * */
  3238. function processArticle($article, $data)
  3239. {
  3240. return $article->map(function ($article) use ($data) {
  3241. $catid = $article->cat_arr_id ?? '';
  3242. $level = json_decode($catid, true);
  3243. $pinyin = '';
  3244. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3245. if (!empty($level) && is_array($level)) {
  3246. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3247. ->where('website_id', $data['website_id'])
  3248. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3249. ->get(['aLIas_pinyin'])
  3250. ->pluck('aLIas_pinyin')
  3251. ->implode('/');
  3252. } else {
  3253. $pinyin = '';
  3254. }
  3255. $article->pinyin = $pinyin;
  3256. return $article;
  3257. });
  3258. }
  3259. /**
  3260. * c端-获取招工招聘下拉选框
  3261. * @param array $data
  3262. * @return array
  3263. * */
  3264. public function getWebsiteJobSelect(array $data): array
  3265. {
  3266. $web = Website::where('id', $data['website_id'])->first();
  3267. if (empty($web)) {
  3268. return Result::error("该网站不存在", 0);
  3269. }
  3270. $hy = JobIndustry::get()->all();
  3271. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3272. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3273. $result = [
  3274. 'hy' => $hy,
  3275. 'zw' => $zw,
  3276. 'jtzw' => $jtzw,
  3277. ];
  3278. if (empty($result)) {
  3279. return Result::error("查询失败", 0);
  3280. }
  3281. return Result::success($result);
  3282. }
  3283. /**
  3284. * c端-获取招工招聘
  3285. * @param array $data
  3286. * @return array
  3287. * */
  3288. public function getWebsiteJob(array $data): array
  3289. {
  3290. $web = Website::where('id', $data['website_id'])->first();
  3291. if (empty($web)) {
  3292. return Result::error("该网站不存在", 0);
  3293. }
  3294. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3295. ->where('job_hunting.website_id', $data['website_id'])
  3296. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3297. $query->where(function ($q) use ($data) {
  3298. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3299. });
  3300. })
  3301. ->select(
  3302. 'job_hunting.id',
  3303. 'job_hunting.catid',
  3304. 'job_hunting.cat_arr_id',
  3305. 'job_hunting.job_name_get',
  3306. 'job_hunting.industry',
  3307. 'job_hunting.name',
  3308. 'job_hunting.sexy',
  3309. 'job_hunting.origin',
  3310. 'job_hunting.city_arr_id',
  3311. 'job_hunting.experience',
  3312. 'job_hunting.updated_at',
  3313. 'job_hunting.salary',
  3314. 'job_hunting.skillList',
  3315. 'job_hunting.slelf_evaluation',
  3316. )
  3317. ->orderBy('updated_at', 'desc')
  3318. ->limit($data['job1_num'])
  3319. ->get();
  3320. $web['website_id'] = $data['website_id'];
  3321. if (empty($job_hunting)) {
  3322. $job_huntings = "未查询到相关简历信息";
  3323. } else {
  3324. $job_huntings = $this->processJob($job_hunting, $web);
  3325. }
  3326. // 0:待审核 1:已通过 2:已拒绝
  3327. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3328. ->where('job_recruiting.website_id', $data['website_id'])
  3329. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3330. $query->where(function ($q) use ($data) {
  3331. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3332. });
  3333. })
  3334. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3335. ->select(
  3336. 'job_recruiting.id',
  3337. 'job_recruiting.catid',
  3338. 'job_recruiting.cat_arr_id',
  3339. 'job_recruiting.title',
  3340. 'job_recruiting.jtzw_id',
  3341. 'job_recruiting.hy_id',
  3342. 'job_recruiting.city_arr_id',
  3343. 'job_recruiting.due_data',
  3344. 'job_recruiting.updated_at',
  3345. 'job_recruiting.experience',
  3346. 'job_recruiting.educational',
  3347. 'job_recruiting.salary',
  3348. 'job_recruiting.zw_id',
  3349. 'job_company.business_name',
  3350. 'job_recruiting.keyword',
  3351. 'job_recruiting.description',
  3352. )
  3353. ->orderBy('updated_at', 'desc')
  3354. ->limit($data['job2_num'])
  3355. ->get();
  3356. if (empty($job_recruiting->toArray())) {
  3357. $job_recruitings = "未查询到相关职位信息";
  3358. } else {
  3359. $job_recruitings = $this->processJob($job_recruiting, $web);
  3360. }
  3361. $result = [
  3362. 'job_hunting' => $job_huntings,
  3363. 'job_recuiting' => $job_recruitings,
  3364. ];
  3365. return Result::success($result);
  3366. }
  3367. /**
  3368. * c端-获取招工招聘列表
  3369. * @param array $data
  3370. * @return array
  3371. * */
  3372. public function getWebsiteJobList(array $data): array
  3373. {
  3374. $recruit_where = [];
  3375. $hunt_where = [];
  3376. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3377. if (empty($web)) {
  3378. return Result::error("此网站不存在", 0);
  3379. }
  3380. $website_id['website_id'] = $data['website_id'];
  3381. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3382. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3383. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3384. }
  3385. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3386. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3387. }
  3388. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3389. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3390. }
  3391. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3392. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3393. }
  3394. $query = JobRecruiting::where('job_recruiting.status', 1)
  3395. ->where('job_recruiting.website_id', $data['website_id'])
  3396. ->where($recruit_where)
  3397. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3398. $query->where(function ($q) use ($data) {
  3399. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3400. });
  3401. })
  3402. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3403. $query->where(function ($q) use ($data) {
  3404. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3405. });
  3406. })
  3407. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3408. ->select(
  3409. 'job_recruiting.id',
  3410. 'job_recruiting.catid',
  3411. 'job_recruiting.hy_id',
  3412. 'job_recruiting.title',
  3413. 'job_recruiting.zw_id',
  3414. 'job_recruiting.educational',
  3415. 'job_recruiting.jtzw_id',
  3416. 'job_recruiting.city_arr_id',
  3417. 'job_recruiting.due_data',
  3418. 'job_recruiting.experience',
  3419. 'job_recruiting.cat_arr_id',
  3420. 'job_recruiting.updated_at',
  3421. 'job_company.business_name',
  3422. 'job_recruiting.keyword',
  3423. 'job_recruiting.description',
  3424. )
  3425. ->orderBy('job_recruiting.updated_at', 'desc');
  3426. $recruit_count = $query->count();
  3427. $query = clone $query;
  3428. $JobRecruiting = $query
  3429. ->offset(($data['page'] - 1) * $data['pageSize'])
  3430. ->limit($data['pageSize'])
  3431. ->get();
  3432. if (empty($JobRecruiting)) {
  3433. $JobRecruiting = "暂无相关职位信息";
  3434. } else {
  3435. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3436. }
  3437. }
  3438. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3439. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3440. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3441. }
  3442. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3443. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3444. }
  3445. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3446. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3447. }
  3448. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3449. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3450. }
  3451. $query = JobHunting::where('job_hunting.status', 2)
  3452. ->where('job_hunting.website_id', $data['website_id'])
  3453. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3454. ->where($hunt_where)
  3455. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3456. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3457. // })
  3458. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3459. $query->where(function ($q) use ($data) {
  3460. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3461. });
  3462. })
  3463. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3464. $query->where(function ($q) use ($data) {
  3465. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3466. });
  3467. })
  3468. ->select(
  3469. 'job_hunting.id',
  3470. 'job_hunting.catid',
  3471. 'job_hunting.sexy',
  3472. 'job_hunting.experience',
  3473. 'job_hunting.origin',
  3474. 'job_hunting.industry',
  3475. 'job_hunting.name',
  3476. 'job_hunting.job',
  3477. 'job_hunting.job_name_get',
  3478. 'job_hunting.city_arr_id',
  3479. 'job_hunting.cat_arr_id',
  3480. 'job_hunting.created_at',
  3481. 'job_hunting.updated_at',
  3482. 'job_position.zwname as job_name',
  3483. 'job_hunting.skillList',
  3484. 'job_hunting.slelf_evaluation',
  3485. )
  3486. ->orderBy('job_hunting.updated_at', 'desc');
  3487. $hunt_count = $query->count();
  3488. $query = clone $query;
  3489. $JobHunting = $query
  3490. ->offset(($data['page'] - 1) * $data['pageSize'])
  3491. ->limit($data['pageSize'])
  3492. ->get();
  3493. if (empty($JobHunting)) {
  3494. $JobRecruiting = "暂无相关简历信息";
  3495. } else {
  3496. $JobHunting = $this->processJob($JobHunting, $website_id);
  3497. }
  3498. }
  3499. $result = [
  3500. 'JobRecruiting' => $JobRecruiting ?? [],
  3501. 'recruit_count' => $recruit_count ?? 0,
  3502. 'JobHunting' => $JobHunting ?? [],
  3503. 'hunt_count' => $hunt_count ?? 0,
  3504. ];
  3505. return Result::success($result);
  3506. }
  3507. /**
  3508. * c端-获取招工招聘详情
  3509. * @param array $data
  3510. * @return array
  3511. * */
  3512. public function getWebsiteJobInfo(array $data): array
  3513. {
  3514. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3515. if (empty($web)) {
  3516. return Result::error("该网站不存在", 0);
  3517. }
  3518. $webid = [
  3519. 'website_id' => $data['website_id'],
  3520. ];
  3521. // 职位相关信息
  3522. if ($data['type'] == 1) {
  3523. $query = JobRecruiting::where('status', 1)
  3524. ->where('website_id', $data['website_id'])
  3525. ->select('*');
  3526. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3527. $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();
  3528. if (!empty($company)) {
  3529. $result['company'] = $this->processJob($company, $webid);
  3530. }
  3531. $other_job = JobRecruiting::where('status', 1)
  3532. ->where('website_id', $data['website_id'])
  3533. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3534. ->where('id', '!=', $data['id'])
  3535. ->where('user_id', '=', $job[0]['user_id'])
  3536. ->limit($data['pageSize'])
  3537. ->get();
  3538. if (!empty($other_job)) {
  3539. $result['other_job'] = $this->processJob($other_job, $webid);
  3540. }
  3541. } else {
  3542. // 简历相关信息
  3543. $job = JobHunting::where('job_hunting.status', 2)
  3544. ->where('job_hunting.website_id', $data['website_id'])
  3545. ->where('job_hunting.id', $data['id'])
  3546. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3547. ->select('job_hunting.*', 'user_name')
  3548. ->get();
  3549. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3550. if (!empty($resume->toArray())) {
  3551. $result['resume'] = 1;
  3552. } else {
  3553. $result['resume'] = 0;
  3554. }
  3555. }
  3556. if (empty($job->toArray())) {
  3557. return Result::error("id参数错误", 0);
  3558. }
  3559. if (!empty($job[0]['job_experience'])) {
  3560. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3561. if (!empty($job_experience)) {
  3562. // $hy = [];
  3563. foreach ($job_experience as $key => $value) {
  3564. // $id = $value['id'];
  3565. $hy[$key] = $value['job_industry'];
  3566. $zw_id[$key] = $value['job_typename'];
  3567. $jtzw_id[$key] = $value['job_name'];
  3568. }
  3569. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3570. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3571. // 先将关联表转换为索引数组,提高查找效率
  3572. $hyLookup = [];
  3573. foreach ($hy_table as $item) {
  3574. $hyLookup[$item['hyid']] = $item['hyname'];
  3575. }
  3576. $zwLookup = [];
  3577. foreach ($zw_table as $item) {
  3578. $zwLookup[$item['zwid']] = $item['zwname'];
  3579. }
  3580. foreach ($job_experience as $key => &$value) {
  3581. // 处理行业名称
  3582. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3583. $value['hy_name'] = $hyLookup[$hy[$key]];
  3584. }
  3585. // 处理职位名称
  3586. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3587. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3588. }
  3589. // 处理具体职位名称
  3590. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3591. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3592. }
  3593. }
  3594. // 释放引用,防止意外修改后续代码
  3595. unset($value);
  3596. }
  3597. $result['job_experience'] = $job_experience ?? [];
  3598. }
  3599. if (!empty($job[0]['education_experience'])) {
  3600. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3601. if (!empty($education_experience)) {
  3602. foreach ($education_experience as $key => $value) {
  3603. // $id = $value['id'];
  3604. $education[$key] = $value['school_education'];
  3605. }
  3606. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3607. // // 先将关联表转换为索引数组,提高查找效率
  3608. $educationLookup = [];
  3609. foreach ($education_table as $item) {
  3610. $educationLookup[$item['evalue']] = $item['ename'];
  3611. }
  3612. foreach ($education_experience as $key => &$value) {
  3613. // 处理学历名称
  3614. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3615. $value['education_name'] = $educationLookup[$education[$key]];
  3616. }
  3617. }
  3618. }
  3619. $result['education_experience'] = $job_experience ?? [];
  3620. }
  3621. $result['job'] = $this->processJob($job, $webid);
  3622. // // 返现对应的栏目
  3623. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3624. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3625. ->whereIn('category_id', $catid)
  3626. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3627. ->orderBy('pid')->get()->all();
  3628. if (!empty($category)) {
  3629. $result['category'] = $category;
  3630. }
  3631. $result['job'] = $job;
  3632. $result['job_experience'] = $job_experience ?? [];
  3633. $result['education_experience'] = $education_experience ?? [];
  3634. if (empty($result)) {
  3635. return Result::error("参数错误", 0);
  3636. }
  3637. return Result::success($result);
  3638. }
  3639. /**
  3640. * c端-申请职位
  3641. * @param array $data
  3642. * @return array
  3643. * */
  3644. public function getWebsiteJobApply(array $data): array
  3645. {
  3646. // 首先验证网站是否存在
  3647. // return Result::success($data);
  3648. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3649. if (empty($web)) {
  3650. return Result::error("该网站不存在", 0);
  3651. }
  3652. // 验证用户是否存在且为个人会员/管理员
  3653. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3654. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3655. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3656. return Result::error("用户不存在", 0);
  3657. }
  3658. // 去除重复元素和空元素,并保持原始顺序
  3659. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3660. return !empty($value);
  3661. }));
  3662. // 验证职位是否存在 1:审核通过
  3663. $recruiting = JobRecruiting::where('status', 1)
  3664. ->where('website_id', $data['website_id'])
  3665. ->whereIn('id', $data['recruit_id'])
  3666. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3667. if (empty($recruiting)) {
  3668. return Result::error("该职位不存在", 0);
  3669. }
  3670. // 简历是否存在
  3671. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3672. if (empty($hunt_id)) {
  3673. return Result::error("该简历不存在", 0);
  3674. }
  3675. $data['hunt_id'] = $hunt_id['hunt_id'];
  3676. // // 验证是否已投递过该职位
  3677. $apply = JobApply::where('user_id', $data['user_id'])
  3678. ->where('hunt_id', $data['hunt_id'])
  3679. ->where('website_id', $data['website_id'])
  3680. ->whereIn('recruit_id', $data['recruit_id'])
  3681. ->get(['recruit_id']);
  3682. if (!empty($apply->toArray())) {
  3683. return Result::error("您已投递过该职位!");
  3684. }
  3685. $insertData = array_map(function ($recruiting) use ($data) {
  3686. return [
  3687. 'user_id' => $data['user_id'],
  3688. 'hunt_id' => $data['hunt_id'],
  3689. 'website_id' => $data['website_id'],
  3690. 'recruit_id' => $recruiting['recruit_id'],
  3691. 'receiver_id' => $recruiting['receiver_id'],
  3692. 'status' => 1,
  3693. ];
  3694. }, $recruiting);
  3695. // 批量插入数据
  3696. $result = JobApply::insert($insertData);
  3697. if (empty($result)) {
  3698. return Result::error("投递失败", 0);
  3699. }
  3700. return Result::success($result);
  3701. }
  3702. /**
  3703. * 招工招聘-沟通简历
  3704. * @param array $data
  3705. * @return array
  3706. * */
  3707. public function getWebsiteJobResume(array $data): array
  3708. {
  3709. // 首先验证网站是否存在
  3710. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3711. if (empty($web)) {
  3712. return Result::error("该网站不存在", 0);
  3713. }
  3714. // return Result::success($data);
  3715. // 验证用户是否存在且为企业会员/管理员
  3716. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3717. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3718. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3719. return Result::error("用户不存在", 0);
  3720. }
  3721. // 去除重复元素和空元素,并保持原始顺序
  3722. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3723. return !empty($value);
  3724. }));
  3725. // 验证简历是否存在
  3726. $hunting = JobHunting::where('status', 2)
  3727. ->where('website_id', $data['website_id'])
  3728. ->whereIn('id', $data['hunt_id'])
  3729. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3730. if (empty($hunting)) {
  3731. return Result::error("该简历不存在", 0);
  3732. }
  3733. // 验证是否已沟通过该简历
  3734. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3735. ->where('recruit_id', $data['recruit_id'])
  3736. ->where('website_id', $data['website_id'])
  3737. ->whereIn('hunt_id', $data['hunt_id'])
  3738. ->get(['hunt_id']);
  3739. if (!empty($remuse->toArray())) {
  3740. return Result::error("您已沟通过该简历!");
  3741. }
  3742. // 准备要插入的数据数组
  3743. $insertData = array_map(function ($hunting) use ($data) {
  3744. return [
  3745. 'user_id' => $data['user_id'],
  3746. 'recruit_id' => $data['recruit_id'],
  3747. 'website_id' => $data['website_id'],
  3748. 'hunt_id' => $hunting['hunt_id'],
  3749. 'receiver_id' => $hunting['receiver_id'],
  3750. 'status' => 1,
  3751. ];
  3752. }, $hunting);
  3753. // 批量插入数据
  3754. $result = JobRemuse::insert($insertData);
  3755. if (empty($result)) {
  3756. return Result::error("沟通失败", 0);
  3757. }
  3758. return Result::success($result);
  3759. }
  3760. /**
  3761. * 招工招聘 -我的职位(企业会员)
  3762. * @param array $data
  3763. * @return array
  3764. */
  3765. public function getWebsiteJobRecruiting(array $data): array
  3766. {
  3767. $web = Website::where('id', $data['website_id'])->first('id');
  3768. if (empty($web)) {
  3769. return Result::error("该网站不存在", 0);
  3770. }
  3771. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3772. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3773. return Result::error("用户暂无权限!", 0);
  3774. }
  3775. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3776. $result = JobRecruiting::where('website_id', $data['website_id'])
  3777. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3778. $query->where('user_id', $user['id']);
  3779. })
  3780. ->where('status', 1)
  3781. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3782. ->orderBy('updated_at', 'desc')
  3783. ->limit($data['pageSize'])
  3784. ->get();
  3785. if (empty($result)) {
  3786. return Result::error("暂无相关职位信息", 0);
  3787. }
  3788. return Result::success($result);
  3789. }
  3790. /**
  3791. * c端 - 验证路由
  3792. * @param array $data
  3793. * @return array
  3794. */
  3795. /**
  3796. * c端 - 验证路由
  3797. * @param array $data
  3798. * @return array
  3799. */
  3800. public function checkWebsiteRoute(array $data): array
  3801. {
  3802. // 测试001111111222
  3803. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3804. if (empty($web)) {
  3805. return Result::error("该网站不存在", 0);
  3806. } elseif ($web['status'] != 1) {
  3807. return Result::error("网站已经关闭", 0);
  3808. }
  3809. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3810. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3811. // 验证路由是否存在
  3812. if (empty($whiteRouterInfo)) {
  3813. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3814. }
  3815. if (!empty($whiteRouterInfo)) {
  3816. return Result::success($whiteRouterInfo->toArray());
  3817. }
  3818. }
  3819. // 验证栏目路由
  3820. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3821. ->where('path', $data['all_route'])
  3822. ->get()->all();
  3823. if (count($last_category) == 0) {
  3824. return Result::error("该栏目不存在", 0);
  3825. }
  3826. if (count($last_category) > 1) {
  3827. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3828. }
  3829. if (count($last_category) == 1) {
  3830. $last_category = $last_category[0];
  3831. }
  3832. // return Result::success($last_category);
  3833. if (isset($data['id']) && !empty($data['id'])) {
  3834. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3835. switch ($last_category['type']) {
  3836. case 1:
  3837. // 文章
  3838. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3839. $article = Article::where('status', 1)
  3840. ->where('id', $data['id'])
  3841. ->where(function ($query) use ($data) {
  3842. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3843. ->orWhereNull("ignore_ids");
  3844. })
  3845. ->first(['catid']);
  3846. if (empty($article)) {
  3847. return Result::error("该文章不存在", 0);
  3848. }
  3849. // return Result::success($article);
  3850. break;
  3851. case 2:
  3852. // 商品
  3853. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3854. $article = Good::where('website_id', $data['website_id'])
  3855. ->where('status', 2)
  3856. ->where('id', $data['id'])
  3857. ->first(['cat_arr_id']);
  3858. if (empty($article)) {
  3859. return Result::error("该商品不存在", 0);
  3860. }
  3861. break;
  3862. case 3:
  3863. // 书刊信息
  3864. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3865. $article = Book::where('website_id', $data['website_id'])
  3866. ->where('status', 2)
  3867. ->where('id', $data['id'])
  3868. ->first(['id', 'cat_arr_id']);
  3869. if (empty($article)) {
  3870. return Result::error("该书刊不存在", 0);
  3871. }
  3872. break;
  3873. case 4:
  3874. // 招聘
  3875. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3876. $article = JobRecruiting::where('website_id', $data['website_id'])
  3877. ->where('status', 1)
  3878. ->where('id', $data['id'])
  3879. ->first(['cat_arr_id']);
  3880. if (empty($article)) {
  3881. return Result::error("该招聘不存在", 0);
  3882. }
  3883. break;
  3884. case 5:
  3885. // 求职
  3886. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3887. $article = JobHunting::where('website_id', $data['website_id'])
  3888. ->where('status', 2)
  3889. ->where('id', $data['id'])
  3890. ->first(['cat_arr_id']);
  3891. if (empty($article)) {
  3892. return Result::error("该求职不存在", 0);
  3893. }
  3894. break;
  3895. case 6:
  3896. // 企业
  3897. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3898. $article = Company::
  3899. // where('website_id', $data['website_id'])
  3900. // ->
  3901. where('status', 1)
  3902. ->where('id', $data['id'])
  3903. ->first(['cat_arr_id']);
  3904. if (empty($article)) {
  3905. return Result::error("该企业不存在", 0);
  3906. }
  3907. break;
  3908. case 7:
  3909. // 项目
  3910. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3911. $article = Project::where('website_id', $data['website_id'])
  3912. ->where('status', 1)
  3913. ->where('id', $data['id'])
  3914. ->first(['cat_arr_id']);
  3915. if (empty($article)) {
  3916. return Result::error("该项目不存在", 0);
  3917. }
  3918. break;
  3919. default:
  3920. return Result::error("该数据不存在", 0);
  3921. break;
  3922. }
  3923. // return Result::success($article);
  3924. // $catid =0 ;
  3925. if (!isset($article['cat_arr_id'])) {
  3926. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3927. } else {
  3928. $catidArray = json_decode($article['cat_arr_id'], true);
  3929. $catid = !empty($catidArray) ? end($catidArray) : null;
  3930. }
  3931. // return Result::success($catid);
  3932. // // return Result::success($article['cat_arr_id']);
  3933. if (empty($catid)) {
  3934. return Result::error("该栏目路径不存在", 0);
  3935. }
  3936. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3937. ->where('category_id', $catid)
  3938. ->first('path');
  3939. }
  3940. // else{
  3941. // // if ($last_category['pid'] != 0) {
  3942. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3943. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3944. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3945. // ->where('category_id',$catid)
  3946. // ->where('path',$data['all_route'])
  3947. // ->first('path');
  3948. // // } else {
  3949. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3950. // // }
  3951. // }
  3952. // return Result::success($path);
  3953. if (!empty($path) && $path['path'] != $data['all_route']) {
  3954. return Result::error('非法路径!');
  3955. } else {
  3956. return Result::success($last_category['path']);
  3957. }
  3958. }
  3959. /**
  3960. * 招工招聘 - 获取推荐职位
  3961. * @param array $data
  3962. * @return array
  3963. */
  3964. public function getWebsiteLevelJob(array $data): array
  3965. {
  3966. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3967. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3968. ->where('job_recruiting.status', 1)
  3969. ->where('job_level', $data['job_level'])
  3970. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3971. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3972. ->orderBy('job_recruiting.updated_at', 'desc')
  3973. ->limit($data['pageSize'])
  3974. ->get();
  3975. $web = ['website_id' => $data['website_id']];
  3976. if (!empty($job)) {
  3977. $result = $this->processJob($job, $web);
  3978. }
  3979. if (empty($result)) {
  3980. return Result::error("暂无相关职位信息", 0);
  3981. }
  3982. return Result::success($result);
  3983. }
  3984. /**
  3985. * 验证导航名称是否重复
  3986. * @return void
  3987. */
  3988. //20250226 产品列表
  3989. public function getGoodList(array $data): array
  3990. {
  3991. var_dump($data, '---------1-2--');
  3992. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3993. unset($data['user_type_id']);
  3994. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3995. $where = [];
  3996. if ($type_id != '10000') {
  3997. $where = [
  3998. 'good.user_id' => $user_id,
  3999. ];
  4000. }
  4001. //类型
  4002. if (isset($data['type_id']) && $data['type_id']) {
  4003. $where['good.type_id'] = $data['type_id'];
  4004. }
  4005. //名称
  4006. if (isset($data['name']) && $data['name']) {
  4007. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4008. }
  4009. //status
  4010. if (isset($data['status']) && $data['status'] != '') {
  4011. $where['good.status'] = $data['status'];
  4012. }
  4013. //status1
  4014. // if (isset($data['status1']) && $data['status1'] == 1) {
  4015. // $status1 = 1;
  4016. // }
  4017. $where1 = [];
  4018. //website_id
  4019. // if (isset($data['website_id']) && $data['website_id']) {
  4020. // $where1 = [
  4021. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4022. // ];
  4023. // }
  4024. // website_name
  4025. if (isset($data['website_name']) && $data['website_name']) {
  4026. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4027. }
  4028. // catid
  4029. if (isset($data['category_name']) && $data['category_name']) {
  4030. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4031. }
  4032. // $result = Good::where($where)
  4033. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4034. var_dump($where, '---------1---');
  4035. $result = Good::where($where)
  4036. ->when(!empty($where1), function ($query) use ($where1) {
  4037. return $query->where($where1);
  4038. })
  4039. //status 1待审核2已审核3已拒绝
  4040. ->when(isset($data['status1']), function ($query) {
  4041. return $query->whereIn('good.status', [1, 3]);
  4042. })
  4043. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4044. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4045. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4046. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4047. ->orderBy("updated_at", "desc")
  4048. ->limit($data['page_size'])
  4049. ->offset(($data['page'] - 1) * $data['page_size'])
  4050. ->get();
  4051. $count = Good::where($where)
  4052. ->when(!empty($where1), function ($query) use ($where1) {
  4053. return $query->where($where1);
  4054. })
  4055. //status 1待审核2已审核3已拒绝
  4056. ->when(isset($data['status1']), function ($query) {
  4057. return $query->whereIn('good.status', [1, 3]);
  4058. })
  4059. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4060. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4061. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4062. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4063. ->orderBy("updated_at", "desc")->count();
  4064. $data = [
  4065. 'rows' => $result->toArray(),
  4066. 'count' => $count,
  4067. ];
  4068. if (empty($result)) {
  4069. return Result::error("此栏目暂无相关产品", 0);
  4070. }
  4071. return Result::success($data);
  4072. }
  4073. public function getGoodInfo(array $data): array
  4074. {
  4075. $result = Good::where('id', $data['id'])->first();
  4076. if (empty($result)) {
  4077. return Result::error("此产品不存在", 0);
  4078. }
  4079. return Result::success($result);
  4080. }
  4081. public function addGood(array $data): array
  4082. {
  4083. // unset($data['city_arr_id']);
  4084. // unset($data['cat_arr_id']);
  4085. $data['city_id'] = end($data['city_arr_id']);
  4086. $data['catid'] = end($data['cat_arr_id']);
  4087. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4088. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4089. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4090. unset($data['imgUrl']); //大小写
  4091. if (isset($data['price']) && $data['price'] == '') {
  4092. $data['price'] = 0;
  4093. }
  4094. if ($data['imgurl'] == '') {
  4095. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4096. preg_match_all($reg, $data['detail'], $matches);
  4097. if (isset($matches[1][0])) {
  4098. //截取varchar240
  4099. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4100. }
  4101. }
  4102. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4103. //提取标题+内容中的关键词
  4104. $data['keyword'] = $data['name'];
  4105. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4106. Jieba::init(); // 初始化 jieba-php
  4107. Finalseg::init();
  4108. $segList = Jieba::cut($data['keyword']);
  4109. $segList1 = array_slice($segList, 0, 8);
  4110. $data['keyword'] = implode(',', $segList1);
  4111. }
  4112. if ($data['description'] == '') {
  4113. //提取内容中的描述
  4114. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4115. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4116. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4117. }
  4118. if ($data['status'] == 1) {
  4119. $this->sendMessage([
  4120. 'talk_type' => 200,
  4121. 'title' => $data['name'],
  4122. 'content' => '提交了审核',
  4123. 'messageType' => 3,
  4124. ]);
  4125. }
  4126. $result = Good::insert($data);
  4127. if (empty($result)) {
  4128. return Result::error("添加失败", 0);
  4129. }
  4130. return Result::success($result);
  4131. }
  4132. public function updateGood(array $data): array
  4133. {
  4134. $data['city_id'] = end($data['city_arr_id']);
  4135. $data['catid'] = end($data['cat_arr_id']);
  4136. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4137. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4138. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4139. //设置东八区
  4140. date_default_timezone_set('Asia/Shanghai');
  4141. $data['updated_at'] = date('Y-m-d H:i:s');
  4142. if (isset($data['price']) && $data['price'] == '') {
  4143. $data['price'] = 0;
  4144. }
  4145. if ($data['imgurl'] == '') {
  4146. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4147. preg_match_all($reg, $data['detail'], $matches);
  4148. if (isset($matches[1][0])) {
  4149. //截取varchar240
  4150. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4151. }
  4152. }
  4153. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4154. //提取标题+内容中的关键词
  4155. $data['keyword'] = $data['name'];
  4156. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4157. Jieba::init(); // 初始化 jieba-php
  4158. Finalseg::init();
  4159. $segList = Jieba::cut($data['keyword']);
  4160. $segList1 = array_slice($segList, 0, 8);
  4161. $data['keyword'] = implode(',', $segList1);
  4162. }
  4163. if ($data['description'] == '') {
  4164. //提取内容中的描述
  4165. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4166. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4167. }
  4168. if ($data['status'] == 1) {
  4169. $this->sendMessage([
  4170. 'talk_type' => 200,
  4171. 'title' => $data['name'],
  4172. 'content' => '提交了审核',
  4173. 'messageType' => 3,
  4174. ]);
  4175. }
  4176. $result = Good::where('id', $data['id'])->update($data);
  4177. if (empty($result)) {
  4178. return Result::error("更新失败", 0);
  4179. }
  4180. return Result::success($result);
  4181. }
  4182. public function delGood(array $data): array
  4183. {
  4184. $result = Good::where('id', $data['id'])->delete();
  4185. if (empty($result)) {
  4186. return Result::error("删除失败", 0);
  4187. }
  4188. return Result::success($result);
  4189. }
  4190. //20250226 产品列表
  4191. //20250306 求职信息
  4192. public function getJobHuntingList(array $data): array
  4193. {
  4194. $where = [];
  4195. if (isset($data['username']) && !empty($data['username'])) {
  4196. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4197. }
  4198. //status 1待审核2已审核3已拒绝
  4199. if (isset($data['status']) && $data['status'] != '') {
  4200. $where = [
  4201. 'job_hunting.status' => $data['status'],
  4202. ];
  4203. }
  4204. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4205. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4206. unset($data['type_id']);
  4207. if ($type_id != '10000') {
  4208. $where[] = ['job_hunting.user_id', '=', $user_id];
  4209. }
  4210. $result = JobHunting::where($where)
  4211. ->when(!empty($data['status1']), function ($query) use ($data) {
  4212. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4213. })
  4214. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4215. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4216. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4217. ->orderBy("updated_at", "desc")
  4218. ->limit($data['page_size'])
  4219. ->offset(($data['page'] - 1) * $data['page_size'])
  4220. ->get();
  4221. if (empty($result)) {
  4222. return Result::error("查询失败", 0);
  4223. }
  4224. $count = JobHunting::where($where)
  4225. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4226. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4227. ->count();
  4228. $data = [
  4229. 'rows' => $result->toArray(),
  4230. 'count' => $count,
  4231. ];
  4232. return Result::success($data);
  4233. }
  4234. public function getJobHuntingApply(array $data): array
  4235. {
  4236. var_dump($data, '-----------------test--------1-');
  4237. $where = [];
  4238. if (isset($data['username']) && !empty($data['username'])) {
  4239. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4240. }
  4241. if (isset($data['salary']) && !empty($data['salary'])) {
  4242. $where[] = [
  4243. 'job_hunting.salary',
  4244. '=',
  4245. $data['salary'],
  4246. ];
  4247. }
  4248. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4249. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4250. unset($data['type_id']);
  4251. if ($type_id != '10000') {
  4252. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4253. }
  4254. var_dump($where, '-----------------test---------');
  4255. $result = jobApply::where($where)
  4256. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4257. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4258. // })
  4259. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4260. ->where('job_enum.egroup', '=', 'income')
  4261. ->where('job_hunting.status', 2) //已审核
  4262. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4263. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4264. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4265. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4266. //职位----是申请职位
  4267. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4268. ->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')
  4269. ->orderBy("job_hunting.updated_at", "desc")
  4270. ->limit($data['page_size'])
  4271. ->offset(($data['page'] - 1) * $data['page_size'])
  4272. ->get();
  4273. if (empty($result)) {
  4274. return Result::error("查询失败", 0);
  4275. }
  4276. $count = jobApply::where($where)
  4277. ->where('job_enum.egroup', '=', 'income')
  4278. ->where('job_hunting.status', 2) //已审核
  4279. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4280. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4281. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4282. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4283. //职位----是申请职位
  4284. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4285. ->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')
  4286. ->count();
  4287. $data = [
  4288. 'rows' => $result->toArray(),
  4289. 'count' => $count,
  4290. ];
  4291. return Result::success($data);
  4292. }
  4293. public function addJobHunting(array $data): array
  4294. {
  4295. date_default_timezone_set('Asia/Shanghai');
  4296. unset($data['company_name']);
  4297. unset($data['job_industry']);
  4298. unset($data['job_name']);
  4299. unset($data['department']);
  4300. unset($data['job_timeList']);
  4301. unset($data['job_content']);
  4302. unset($data['job_typename']); //不知道这是啥,
  4303. $data['created_at'] = date('Y-m-d H:i:s');
  4304. $data['updated_at'] = date('Y-m-d H:i:s');
  4305. //根据用户 user_id 只能添加一次
  4306. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4307. if (!empty($result)) {
  4308. return Result::error("您已添加过求职信息", 0);
  4309. }
  4310. var_dump($result, '-----------------test---------');
  4311. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4312. if (is_string($data['city_arr_id'])) {
  4313. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4314. $cityArr = json_decode($data['city_arr_id'], true);
  4315. // 确保 $cityArr 是数组
  4316. if (is_array($cityArr)) {
  4317. $data['city_id'] = end($cityArr);
  4318. }
  4319. } else {
  4320. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4321. if (is_array($data['city_arr_id'])) {
  4322. $data['city_id'] = end($data['city_arr_id']);
  4323. }
  4324. }
  4325. }
  4326. // 处理求职所绑定栏目
  4327. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4328. if (is_string($data['cat_arr_id'])) {
  4329. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4330. // 先清理可能存在的无效 JSON 字符
  4331. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4332. $catArr = json_decode($cleanedCatArrStr, true);
  4333. // 检查 JSON 解码是否成功且结果是数组
  4334. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4335. $data['catid'] = end($catArr);
  4336. }
  4337. } else {
  4338. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4339. if (is_array($data['cat_arr_id'])) {
  4340. $data['catid'] = end($data['cat_arr_id']);
  4341. }
  4342. }
  4343. }
  4344. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4345. $this->sendMessage([
  4346. 'talk_type' => 600,
  4347. 'title' => $data['name'],
  4348. 'content' => '提交了审核',
  4349. 'messageType' => 11,
  4350. ]);
  4351. }
  4352. $result = JobHunting::create($data);
  4353. if (empty($result)) {
  4354. return Result::error("添加失败", 0);
  4355. }
  4356. return Result::success($result);
  4357. }
  4358. public function delJobHunting(array $data): array
  4359. {
  4360. $result = JobHunting::where('id', $data['id'])->delete();
  4361. if (empty($result)) {
  4362. return Result::error("删除失败", 0);
  4363. }
  4364. return Result::success($result);
  4365. }
  4366. public function updateJobHunting(array $data): array
  4367. {
  4368. //设置东八区
  4369. date_default_timezone_set('Asia/Shanghai');
  4370. unset($data['company_name']);
  4371. unset($data['job_industry']);
  4372. unset($data['job_name']);
  4373. unset($data['department']);
  4374. unset($data['job_timeList']);
  4375. unset($data['job_content']);
  4376. unset($data['job_typename']); //不知道这是啥,
  4377. $data['created_at'] = date('Y-m-d H:i:s');
  4378. $data['updated_at'] = date('Y-m-d H:i:s');
  4379. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4380. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4381. $cityArr = json_decode($data['city_arr_id'], true);
  4382. $data['city_id'] = end($cityArr);
  4383. } else {
  4384. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4385. $data['city_id'] = end($data['city_arr_id']);
  4386. }
  4387. // 处理求职所绑定栏目
  4388. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4389. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4390. $catArr = json_decode($data['cat_arr_id'], true);
  4391. $data['catid'] = end($catArr);
  4392. } else {
  4393. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4394. $data['catid'] = end($data['cat_arr_id']);
  4395. }
  4396. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4397. $this->sendMessage([
  4398. 'talk_type' => 600,
  4399. 'title' => $data['name'],
  4400. 'content' => '提交了审核',
  4401. 'messageType' => 11,
  4402. ]);
  4403. }
  4404. $result = JobHunting::where('id', $data['id'])->update($data);
  4405. if (empty($result)) {
  4406. return Result::error("更新失败", 0);
  4407. }
  4408. return Result::success($result);
  4409. }
  4410. public function getJobHuntingInfo(array $data): array
  4411. {
  4412. $result = JobHunting::where('id', $data['id'])->first();
  4413. if (empty($result)) {
  4414. return Result::error("查询失败", 0);
  4415. }
  4416. return Result::success($result);
  4417. }
  4418. public function getJobHuntingData(array $data): array
  4419. {
  4420. $jobEnum = JobEnum::get();
  4421. $jobIndustry = JobIndustry::get();
  4422. $jobNature = JobNature::get();
  4423. $jobPosition = JobPosition::get();
  4424. $data = [
  4425. 'jobEnum' => $jobEnum,
  4426. 'jobIndustry' => $jobIndustry,
  4427. 'jobNature' => $jobNature,
  4428. 'jobPosition' => $jobPosition,
  4429. ];
  4430. return Result::success($data);
  4431. }
  4432. public function delJobHuntingInfo(array $data): array
  4433. {
  4434. $result = JobHunting::where('id', $data['id'])->delete();
  4435. return Result::success();
  4436. }
  4437. //20250324 通知,公告,消息
  4438. public function delNotice(array $data): array
  4439. {
  4440. $result = Notice::where('id', $data['id'])->delete();
  4441. if ($result) {
  4442. return Result::success();
  4443. } else {
  4444. return Result::error("删除失败", 0);
  4445. }
  4446. }
  4447. public function getNoticeInfo(array $data): array
  4448. {
  4449. $result = Notice::where('id', $data['id'])->first();
  4450. // var_dump($result['re_user_ids'], '--------------------');
  4451. if (empty($result)) {
  4452. return Result::error("查询失败", 0);
  4453. }
  4454. return Result::success($result);
  4455. }
  4456. public function readNotice(array $data): array
  4457. {
  4458. $result = Notice::where('id', $data['id'])->first();
  4459. // var_dump($result['re_user_ids'], '--------------------');
  4460. if (empty($result)) {
  4461. return Result::error("查询失败", 0);
  4462. }
  4463. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4464. $re_user_ids = json_decode($result['re_user_ids'], true);
  4465. var_dump($re_user_ids, '--------------1---test---------');
  4466. var_dump($data, '--------------1---test---------');
  4467. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4468. //如果已经存在,就不再添加
  4469. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4470. $read_id = json_decode($result['read_id'], true);
  4471. if (!is_array($read_id)) {
  4472. $read_id = [];
  4473. }
  4474. if (!in_array($data['user_id'], $read_id)) {
  4475. $read_id[] = $data['user_id'];
  4476. $result['read_id'] = json_encode($read_id);
  4477. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4478. }
  4479. } else {
  4480. //如果不存在,就添加
  4481. $result['read_id'] = json_encode([$data['user_id']]);
  4482. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4483. }
  4484. }
  4485. return Result::success($result);
  4486. }
  4487. public function addNotice(array $data): array
  4488. {
  4489. date_default_timezone_set('Asia/Shanghai');
  4490. $data['created_at'] = date('Y-m-d H:i:s');
  4491. $data['updated_at'] = date('Y-m-d H:i:s');
  4492. $user_id = UserInfo::
  4493. //city_id不是null
  4494. whereNotNull('city_id')
  4495. ->whereNotNull('department_id')
  4496. ->where(function ($query) use ($data) {
  4497. $query->where(function ($subQuery) use ($data) {
  4498. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4499. });
  4500. })
  4501. ->where(function ($query) use ($data) {
  4502. $query->where(function ($subQuery) use ($data) {
  4503. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4504. });
  4505. })
  4506. ->pluck('user_id')->toArray();
  4507. $user_id = array_unique($user_id);
  4508. $chat_ids = $user_id;
  4509. $user_id = json_encode($user_id);
  4510. $data['re_user_ids'] = $user_id;
  4511. $this->sendMessage([
  4512. 'talk_type' => 700,
  4513. 'title' => $data['title'],
  4514. 'content' => '提交了审核',
  4515. 'messageType' => 5,
  4516. ]);
  4517. $result = Notice::insertGetId($data);
  4518. if (empty($result)) {
  4519. return Result::error("添加失败", 0);
  4520. }
  4521. return Result::success($result);
  4522. }
  4523. public function updateNotice(array $data): array
  4524. {
  4525. date_default_timezone_set('Asia/Shanghai');
  4526. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4527. $user_id = UserInfo::
  4528. //city_id不是null
  4529. whereNotNull('city_id')
  4530. ->whereNotNull('department_id')
  4531. ->where(function ($query) use ($data) {
  4532. $query->where(function ($subQuery) use ($data) {
  4533. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4534. });
  4535. })
  4536. ->where(function ($query) use ($data) {
  4537. $query->where(function ($subQuery) use ($data) {
  4538. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4539. });
  4540. })
  4541. ->pluck('user_id')->toArray();
  4542. $user_id = array_unique($user_id);
  4543. $user_id = json_encode($user_id);
  4544. $data['re_user_ids'] = $user_id;
  4545. $data['updated_at'] = date('Y-m-d H:i:s');
  4546. $this->sendMessage([
  4547. 'talk_type' => 700,
  4548. 'title' => $data['title'],
  4549. 'content' => '提交了审核',
  4550. 'messageType' => 5,
  4551. ]);
  4552. $result = Notice::where('id', $data['id'])->update($data);
  4553. return Result::success($result);
  4554. }
  4555. public function getNoticeList(array $data): array
  4556. {
  4557. $where = [];
  4558. //title
  4559. if (isset($data['title']) && !empty($data['title'])) {
  4560. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4561. }
  4562. //level
  4563. if (isset($data['level']) && !empty($data['level'])) {
  4564. $where[] = ['notice.level', '=', $data['level']];
  4565. }
  4566. //status
  4567. if (isset($data['status']) && !empty($data['status'])) {
  4568. $where[] = ['notice.status', '=', $data['status']];
  4569. }
  4570. //type
  4571. if (isset($data['type']) && !empty($data['type'])) {
  4572. $where[] = ['notice.type', '=', $data['type']];
  4573. }
  4574. var_dump($data, '------------11111-2----test---------');
  4575. if ($data['type_id'] == 10000) {
  4576. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4577. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4578. })
  4579. ->where($where)
  4580. ->orderBy('updated_at', 'desc')
  4581. ->limit($data['page_size'])
  4582. ->offset(($data['page'] - 1) * $data['page_size'])
  4583. ->get();
  4584. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4585. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4586. })
  4587. ->where($where)
  4588. ->orderBy('updated_at', 'desc')
  4589. ->count();
  4590. } else {
  4591. $result = Notice::where($where)
  4592. // ->where('user_id', $data['user_id'])
  4593. ->Where(function ($query) use ($data) {
  4594. $query->Where(function ($q) use ($data) {
  4595. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4596. ->orWhere('notice.user_id', $data['user_id']);
  4597. });
  4598. })
  4599. ->when(!empty($data['status1']), function ($query) use ($data) {
  4600. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4601. })
  4602. ->orderBy('updated_at', 'desc')
  4603. ->limit($data['page_size'])
  4604. ->offset(($data['page'] - 1) * $data['page_size'])
  4605. ->get();
  4606. $total = Notice::where($where)
  4607. ->when(!empty($data['status1']), function ($query) use ($data) {
  4608. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4609. })
  4610. // ->where('user_id', $data['user_id'])
  4611. ->Where(function ($query) use ($data) {
  4612. $query->Where(function ($q) use ($data) {
  4613. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4614. ->orWhere('notice.user_id', $data['user_id']);
  4615. });
  4616. })
  4617. ->count();
  4618. }
  4619. if (empty($result)) {
  4620. return Result::error("查询失败", 0);
  4621. }
  4622. $data = [
  4623. 'rows' => $result,
  4624. 'count' => $total,
  4625. ];
  4626. return Result::success($data);
  4627. }
  4628. public function noticeList(array $data): array
  4629. {
  4630. $where = [];
  4631. //title
  4632. if (isset($data['title']) && !empty($data['title'])) {
  4633. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4634. }
  4635. //level
  4636. if (isset($data['level']) && !empty($data['level'])) {
  4637. $where[] = ['notice.level', '=', $data['level']];
  4638. }
  4639. //status
  4640. if (isset($data['status']) && !empty($data['status'])) {
  4641. $where[] = ['notice.status', '=', $data['status']];
  4642. }
  4643. //type
  4644. if (isset($data['type']) && !empty($data['type'])) {
  4645. $where[] = ['notice.type', '=', $data['type']];
  4646. }
  4647. var_dump($data, '------------11111-2----test---------');
  4648. if ($data['type_id'] == 10000) {
  4649. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4650. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4651. })
  4652. ->where($where)
  4653. ->orderBy('updated_at', 'desc')
  4654. ->limit($data['page_size'])
  4655. ->offset(($data['page'] - 1) * $data['page_size'])
  4656. ->get();
  4657. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4658. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4659. })
  4660. ->where($where)
  4661. ->orderBy('updated_at', 'desc')
  4662. ->count();
  4663. } else {
  4664. $result = Notice::where($where)
  4665. // ->where('user_id', $data['user_id'])
  4666. ->Where(function ($query) use ($data) {
  4667. $query->Where(function ($q) use ($data) {
  4668. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4669. ->orWhere('notice.user_id', $data['user_id']);
  4670. });
  4671. })
  4672. ->when(!empty($data['status1']), function ($query) use ($data) {
  4673. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4674. })
  4675. ->orderBy('updated_at', 'desc')
  4676. ->limit($data['page_size'])
  4677. ->offset(($data['page'] - 1) * $data['page_size'])
  4678. ->get();
  4679. $total = Notice::where($where)
  4680. ->when(!empty($data['status1']), function ($query) use ($data) {
  4681. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4682. })
  4683. // ->where('user_id', $data['user_id'])
  4684. ->Where(function ($query) use ($data) {
  4685. $query->Where(function ($q) use ($data) {
  4686. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4687. ->orWhere('notice.user_id', $data['user_id']);
  4688. });
  4689. })
  4690. ->count();
  4691. }
  4692. if (empty($result)) {
  4693. return Result::error("查询失败", 0);
  4694. }
  4695. $data = [
  4696. 'rows' => $result,
  4697. 'count' => $total,
  4698. ];
  4699. return Result::success($data);
  4700. }
  4701. public function getNoticeDetail(array $data): array
  4702. {
  4703. $result = Notice::where('id', $data['id'])->first();
  4704. if (empty($result)) {
  4705. return Result::error("查询失败", 0);
  4706. }
  4707. return Result::success($result);
  4708. }
  4709. public function deleteNotice(array $data): array
  4710. {
  4711. $notice = Notice::where('id', $data['id'])->first();
  4712. if (empty($notice)) {
  4713. return Result::error("删除失败", 0);
  4714. }
  4715. $chat_group_id = $notice->group_id;
  4716. if ($chat_group_id) {
  4717. //删除群聊
  4718. ChatGroups::where('id', $chat_group_id)->delete();
  4719. //删除群成员
  4720. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4721. //删除群聊记录
  4722. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4723. }
  4724. $result = Notice::where('id', $data['id'])->delete();
  4725. return Result::success($result);
  4726. }
  4727. public function complaintList(array $data): array
  4728. {
  4729. var_dump($data, '---------1---------');
  4730. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4731. unset($data['type_id']);
  4732. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4733. $where = [];
  4734. if ($type_id != 10000 && empty($data['deal_user'])) {
  4735. // $where['complaint.user_id'] = $user_id;
  4736. }
  4737. if (!empty($data['title'])) {
  4738. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4739. }
  4740. if (!empty($data['department_id'])) {
  4741. $where['complaint.department_id'] = $data['department_id'];
  4742. }
  4743. if (!empty($data['deal'])) {
  4744. $where['complaint.deal'] = $data['deal'];
  4745. }
  4746. if (!empty($data['status'])) {
  4747. $where['complaint.status'] = $data['status'];
  4748. }
  4749. var_dump(!empty($data['deal_user']), '----------1');
  4750. var_dump($where, '----------2');
  4751. $result = Complaint::where($where)
  4752. ->when(!empty($data['status1']), function ($query) use ($data) {
  4753. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4754. })
  4755. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4756. //json re_user_ids data[user_id]是不是在里面
  4757. $query->Where(function ($q) use ($data) {
  4758. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4759. ->where('complaint.status', 2);
  4760. });
  4761. })
  4762. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4763. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4764. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4765. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4766. ->orderBy('updated_at', 'desc')
  4767. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4768. //sql输出
  4769. if (empty($result)) {
  4770. return Result::error("暂无投诉信息", 0);
  4771. }
  4772. // 取出数据
  4773. $rows = $result->items();
  4774. $count = $result->total();
  4775. $responseData = [
  4776. 'rows' => $rows,
  4777. 'count' => $count,
  4778. ];
  4779. return Result::success($responseData);
  4780. }
  4781. public function getComplaintList(array $data): array
  4782. {
  4783. var_dump($data, '00000001000000000000');
  4784. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4785. unset($data['type_id']);
  4786. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4787. $where = [];
  4788. if ($type_id != 10000 && empty($data['deal_user'])) {
  4789. $where['complaint.user_id'] = $user_id;
  4790. }
  4791. if (!empty($data['title'])) {
  4792. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4793. }
  4794. if (!empty($data['department_id'])) {
  4795. $where['complaint.department_id'] = $data['department_id'];
  4796. }
  4797. if (!empty($data['deal'])) {
  4798. $where['complaint.deal'] = $data['deal'];
  4799. }
  4800. if (!empty($data['status'])) {
  4801. $where['complaint.status'] = $data['status'];
  4802. }
  4803. var_dump(!empty($data['deal_user']), '----------1');
  4804. var_dump($where, '----------2');
  4805. $result = Complaint::where($where)
  4806. ->when(!empty($data['status1']), function ($query) use ($data) {
  4807. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4808. })
  4809. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4810. // //json re_user_ids data[user_id]是不是在里面
  4811. // $query->Where(function ($q) use ($data) {
  4812. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4813. // ->where('complaint.status', 2);
  4814. // });
  4815. // })
  4816. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4817. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4818. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4819. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4820. ->orderBy('updated_at', 'desc')
  4821. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4822. //sql输出
  4823. if (empty($result)) {
  4824. return Result::error("暂无投诉信息", 0);
  4825. }
  4826. // 取出数据
  4827. $rows = $result->items();
  4828. $count = $result->total();
  4829. $responseData = [
  4830. 'rows' => $rows,
  4831. 'count' => $count,
  4832. ];
  4833. return Result::success($responseData);
  4834. }
  4835. public function getComplaintInfo(array $data): array
  4836. {
  4837. $result = Complaint::where('id', $data['id'])->first();
  4838. if (empty($result)) {
  4839. return Result::error("查询失败", 0);
  4840. }
  4841. return Result::success($result);
  4842. }
  4843. public function readComplaint(array $data): array
  4844. {
  4845. $result = Complaint::where('id', $data['id'])->first();
  4846. if (empty($result)) {
  4847. return Result::error("查询失败", 0);
  4848. }
  4849. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4850. $re_user_ids = json_decode($result['re_user_ids'], true);
  4851. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4852. //如果已经存在,就不再添加
  4853. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4854. $read_id = json_decode($result['read_id'], true);
  4855. if (!is_array($read_id)) {
  4856. $read_id = [];
  4857. }
  4858. if (!in_array($data['user_id'], $read_id)) {
  4859. $read_id[] = $data['user_id'];
  4860. $result['read_id'] = json_encode($read_id);
  4861. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4862. }
  4863. } else {
  4864. //如果不存在,就添加
  4865. $result['read_id'] = json_encode([$data['user_id']]);
  4866. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4867. }
  4868. }
  4869. return Result::success($result);
  4870. }
  4871. public function addComplaint(array $data): array
  4872. {
  4873. date_default_timezone_set('Asia/Shanghai');
  4874. $data['created_at'] = date('Y-m-d H:i:s');
  4875. $data['updated_at'] = date('Y-m-d H:i:s');
  4876. $this->sendMessage([
  4877. 'talk_type' => 800,
  4878. 'title' => $data['title'],
  4879. 'content' => '提交了审核',
  4880. 'messageType' => 6,
  4881. ]);
  4882. $result = Complaint::create($data);
  4883. return Result::success($result);
  4884. }
  4885. public function updateComplaint(array $data): array
  4886. {
  4887. date_default_timezone_set('Asia/Shanghai');
  4888. $data['updated_at'] = date('Y-m-d H:i:s');
  4889. $user_id = $data['user_id'] ?? 0;
  4890. $type_id = $data['type_id'] ?? 0;
  4891. unset($data['user_id']);
  4892. unset($data['type_id']);
  4893. $this->sendMessage([
  4894. 'talk_type' => 800,
  4895. 'title' => $data['title'],
  4896. 'content' => '提交了审核',
  4897. 'messageType' => 6,
  4898. ]);
  4899. $result = Complaint::where('id', $data['id'])->update($data);
  4900. return Result::success($result);
  4901. }
  4902. public function deleteComplaint(array $data): array
  4903. {
  4904. $result = Complaint::where('id', $data['id'])->delete();
  4905. return Result::success($result);
  4906. }
  4907. public function getComplainInfo(array $data): array
  4908. {
  4909. $result = Complaint::where('id', $data['id'])->first();
  4910. if (empty($result)) {
  4911. return Result::error("查询失败", 0);
  4912. }
  4913. return Result::success($result);
  4914. }
  4915. public function updateComplaintStatus(array $data): array
  4916. {
  4917. date_default_timezone_set('Asia/Shanghai');
  4918. $data['updated_at'] = date('Y-m-d H:i:s');
  4919. $user_id = $data['user_id'] ?? 0;
  4920. $type_id = $data['type_id'] ?? 0;
  4921. unset($data['user_id']);
  4922. unset($data['type_id']);
  4923. //处理, 写入处理人
  4924. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4925. $data['real_deal_user'] = $user_id;
  4926. }
  4927. //如果是deal 23,则判断是不是处理人
  4928. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4929. $complaintInof = Complaint::where('id', $data['id'])
  4930. ->where('real_deal_user', $user_id)
  4931. ->first();
  4932. if (empty($complaintInof)) {
  4933. return Result::error("处理人错误", 0);
  4934. }
  4935. }
  4936. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4937. if ($data['status'] == 1) {
  4938. $this->sendMessage([
  4939. 'talk_type' => 800,
  4940. 'title' => $complaintInfo['title'],
  4941. 'content' => '提交了审核',
  4942. 'messageType' => 6,
  4943. ]);
  4944. }
  4945. if ($data['status'] == 2 && !isset($data['deal'])) {
  4946. $this->sendMessage([
  4947. 'talk_type' => 801,
  4948. 'title' => $complaintInfo['title'],
  4949. 'content' => '审核通过',
  4950. 'messageType' => 6,
  4951. 'user_id' => $complaintInfo['user_id'],
  4952. ]);
  4953. $this->sendMessage([
  4954. 'talk_type' => 802,
  4955. 'title' => $complaintInfo['title'],
  4956. 'content' => '待处理',
  4957. 'messageType' => 6,
  4958. 'user_id' => $complaintInfo['re_user_ids'],
  4959. ]);
  4960. }
  4961. if ($data['status'] == 3 && !isset($data['deal'])) {
  4962. $this->sendMessage([
  4963. 'talk_type' => 801,
  4964. 'title' => $complaintInfo['title'],
  4965. 'content' => '审核拒绝',
  4966. 'messageType' => 6,
  4967. 'user_id' => $complaintInfo['user_id'],
  4968. ]);
  4969. }
  4970. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4971. $this->sendMessage([
  4972. 'talk_type' => 802,
  4973. 'title' => $complaintInfo['title'],
  4974. 'content' => '处理中',
  4975. 'messageType' => 6,
  4976. 'user_id' => $complaintInfo['re_user_ids'],
  4977. ]);
  4978. }
  4979. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4980. $this->sendMessage([
  4981. 'talk_type' => 802,
  4982. 'title' => $complaintInfo['title'],
  4983. 'content' => '不予处理',
  4984. 'messageType' => 6,
  4985. 'user_id' => $complaintInfo['re_user_ids'],
  4986. ]);
  4987. }
  4988. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4989. $this->sendMessage([
  4990. 'talk_type' => 802,
  4991. 'title' => $complaintInfo['title'],
  4992. 'content' => '已完结',
  4993. 'messageType' => 6,
  4994. 'user_id' => $complaintInfo['re_user_ids'],
  4995. ]);
  4996. }
  4997. $result = complaint::where('id', $data['id'])->update($data);
  4998. return Result::success($result);
  4999. }
  5000. public function updateGoodStatus(array $data): array
  5001. {
  5002. $user_id = $data['user_id'] ?? 0;
  5003. $type_id = $data['type_id'] ?? 0;
  5004. unset($data['user_id']);
  5005. unset($data['type_id']);
  5006. $goodInfo = Good::where('id', $data['id'])->first();
  5007. if ($data['status'] == 2) {
  5008. $this->sendMessage([
  5009. 'talk_type' => 201,
  5010. 'title' => $goodInfo['name'],
  5011. 'content' => '审核通过',
  5012. 'messageType' => 3,
  5013. 'user_id' => $goodInfo['user_id'],
  5014. ]);
  5015. }
  5016. if ($data['status'] == 3) {
  5017. $this->sendMessage([
  5018. 'talk_type' => 201,
  5019. 'title' => $goodInfo['name'],
  5020. 'content' => '审核拒绝',
  5021. 'messageType' => 3,
  5022. 'user_id' => $goodInfo['user_id'],
  5023. ]);
  5024. }
  5025. if ($data['status'] == 1) {
  5026. $this->sendMessage([
  5027. 'talk_type' => 200,
  5028. 'title' => $goodInfo['name'],
  5029. 'content' => '提交了审核',
  5030. 'messageType' => 3,
  5031. ]);
  5032. }
  5033. $result = Good::where('id', $data['id'])->update($data);
  5034. return Result::success($result);
  5035. }
  5036. public function updateJobHuntingStatus(array $data): array
  5037. {
  5038. $user_id = $data['user_id'] ?? 0;
  5039. $type_id = $data['type_id'] ?? 0;
  5040. unset($data['user_id']);
  5041. unset($data['type_id']);
  5042. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5043. if ($data['status'] == 2) {
  5044. $this->sendMessage([
  5045. 'talk_type' => 601,
  5046. 'title' => $jogHuntingInfo['name'],
  5047. 'content' => '审核通过',
  5048. 'messageType' => 11,
  5049. 'user_id' => $jogHuntingInfo['user_id'],
  5050. ]);
  5051. }
  5052. if ($data['status'] == 3) {
  5053. $this->sendMessage([
  5054. 'talk_type' => 601,
  5055. 'title' => $jogHuntingInfo['name'],
  5056. 'content' => '审核拒绝',
  5057. 'messageType' => 11,
  5058. 'user_id' => $jogHuntingInfo['user_id'],
  5059. ]);
  5060. }
  5061. if ($data['status'] == 1) {
  5062. $this->sendMessage([
  5063. 'talk_type' => 600,
  5064. 'title' => $jogHuntingInfo['name'],
  5065. 'content' => '提交了审核',
  5066. 'messageType' => 11,
  5067. ]);
  5068. }
  5069. $result = JobHunting::where('id', $data['id'])->update($data);
  5070. return Result::success($result);
  5071. }
  5072. public function updateNoticeStatus(array $data): array
  5073. {
  5074. $user_id = $data['user_id'] ?? 0;
  5075. $type_id = $data['type_id'] ?? 0;
  5076. unset($data['user_id']);
  5077. unset($data['type_id']);
  5078. //查询公告
  5079. $notice = Notice::where('id', $data['id'])->first();
  5080. if (empty($notice)) {
  5081. return Result::error("公告不存在", 0);
  5082. }
  5083. //$chat_ids 去除掉$data['user_id']
  5084. $chat_ids = json_decode($notice['re_user_ids'], true);
  5085. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5086. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5087. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5088. //chat_group
  5089. $group_id = PublicData::uuid();
  5090. $groupData = [
  5091. 'id' => $group_id,
  5092. 'creator_id' => $notice['user_id'],
  5093. 'group_name' => $notice['group_name'] ?? '',
  5094. 'profile' => $notice['profile'] ?? 0,
  5095. ];
  5096. var_dump($groupData, '-----------------groupData-------');
  5097. $groupResult = ChatGroups::insertGetId($groupData);
  5098. var_dump($groupResult, '-----------------groupid-------');
  5099. $groupMemberData = [
  5100. 'id' => PublicData::uuid(),
  5101. 'user_id' => $notice['user_id'],
  5102. 'group_id' => $group_id,
  5103. 'leader' => 2,
  5104. ];
  5105. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5106. //插入群成员表
  5107. $groupMemberDataUser = [];
  5108. $chatData = [];
  5109. foreach ($chat_ids as $key => $value) {
  5110. $groupMemberDataUser[] = [
  5111. 'id' => PublicData::uuid(),
  5112. 'user_id' => $value,
  5113. 'group_id' => $group_id,
  5114. 'leader' => 1,
  5115. ];
  5116. $chatData[] = [
  5117. 'user_id' => $value,
  5118. 'msg_type' => 1,
  5119. 'receiver_id' => $group_id,
  5120. 'content' => '通过通知创建群聊',
  5121. 'group_receiver_id' => $notice['user_id'],
  5122. 'action' => 'recieved',
  5123. 'created_at' => date('Y-m-d H:i:s'),
  5124. ];
  5125. }
  5126. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5127. ChatGroupsMember::insert($groupMemberDataUser);
  5128. //插入一条管理员聊天记录
  5129. $chatData[] = [
  5130. 'user_id' => $notice['user_id'],
  5131. 'msg_type' => 1,
  5132. 'receiver_id' => $group_id,
  5133. 'content' => '通过通知创建群聊',
  5134. 'group_receiver_id' => $notice['user_id'],
  5135. 'action' => 'said',
  5136. 'created_at' => date('Y-m-d H:i:s'),
  5137. ];
  5138. var_dump($chatData, '-----------------chatData-------');
  5139. $chatResult = ChatRecords::insert($chatData);
  5140. //处理imp
  5141. $group = [
  5142. 'type' => 1,
  5143. 'name' => $notice['group_name'] ?? '',
  5144. 'profile' => '',
  5145. 'avatar' => '',
  5146. 'creator_id' => $notice['user_id'],
  5147. ];
  5148. $groupResult = GroupImp::insertGetId($group);
  5149. var_dump($groupResult, '获取imp group_id');
  5150. $groupMember = [
  5151. 'user_id' => $notice['user_id'],
  5152. 'group_id' => $groupResult,
  5153. 'leader' => 1,
  5154. 'join_time' => Date('Y-m-d H:i:s')
  5155. ];
  5156. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5157. $talk_session = [
  5158. 'user_id' => $notice['user_id'],
  5159. 'to_from_id' => $groupResult,
  5160. 'talk_mode' => 2,
  5161. 'created_at' => Date('Y-m-d H:i:s'),
  5162. 'updated_at' => Date('Y-m-d H:i:s'),
  5163. ];
  5164. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5165. //被通知人员处理
  5166. foreach ($chat_ids as $key => $value) {
  5167. $groupMemberdata[] = [
  5168. 'user_id' => $value,
  5169. 'group_id' => $groupResult,
  5170. 'leader' => 3,
  5171. 'join_time' => Date('Y-m-d H:i:s')
  5172. ];
  5173. $talk_sessionData[] = [
  5174. 'user_id' => $value,
  5175. 'to_from_id' => $groupResult,
  5176. 'talk_mode' => 2,
  5177. 'created_at' => Date('Y-m-d H:i:s'),
  5178. 'updated_at' => Date('Y-m-d H:i:s'),
  5179. ];
  5180. }
  5181. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5182. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5183. $group_id = $groupResult;
  5184. //更新result的 group_id
  5185. $data['group_id'] = $group_id;
  5186. Notice::where(['id' => $data['id']])->update($data);
  5187. }
  5188. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5189. //删除掉信息
  5190. GroupImp::where('id', $notice['group_id'])->delete();
  5191. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5192. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5193. foreach ($chat_ids as $key => $value) {
  5194. }
  5195. //聊天记录删除
  5196. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5197. $data['group_id'] = null;
  5198. Notice::where(['id' => $data['id']])->update($data);
  5199. }
  5200. $result = Notice::where('id', $data['id'])->update($data);
  5201. $noticeInfo = Notice::where('id', $data['id'])->first();
  5202. if ($data['status'] == 2) {
  5203. $this->sendMessage([
  5204. 'talk_type' => 701,
  5205. 'title' => $noticeInfo['title'],
  5206. 'content' => '审核通过',
  5207. 'messageType' => 3,
  5208. 'user_id' => $noticeInfo['user_id'],
  5209. ]);
  5210. }
  5211. if ($data['status'] == 3) {
  5212. $this->sendMessage([
  5213. 'talk_type' => 701,
  5214. 'title' => $noticeInfo['title'],
  5215. 'content' => '审核拒绝',
  5216. 'messageType' => 3,
  5217. 'user_id' => $noticeInfo['user_id'],
  5218. ]);
  5219. }
  5220. if ($data['status'] == 1) {
  5221. $this->sendMessage([
  5222. 'talk_type' => 700,
  5223. 'title' => $noticeInfo['title'],
  5224. 'content' => '提交了审核',
  5225. 'messageType' => 3,
  5226. ]);
  5227. }
  5228. return Result::success($result);
  5229. }
  5230. public function getDUser(array $data): array
  5231. {
  5232. if (!empty($data['ids'])) {
  5233. $user = User::whereIn('id', $data['ids'])->getall();
  5234. if (empty($user)) {
  5235. return Result::error('无数据', 0);
  5236. }
  5237. return Result::success($user);
  5238. }
  5239. $where = [];
  5240. if (!empty($data['department_id'])) {
  5241. $where['department_id'] = $data['department_id'];
  5242. }
  5243. if (!empty($data['city_id'])) {
  5244. $where['city_id'] = $data['city_id'];
  5245. }
  5246. $result = User::where('type_id', 2)
  5247. ->where('status', 1)
  5248. ->where($where)
  5249. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5250. ->get();
  5251. if (empty($result)) {
  5252. return Result::error("查询失败", 0);
  5253. }
  5254. return Result::success($result);
  5255. }
  5256. /**
  5257. * 验证导航名称是否重复
  5258. * @return void
  5259. */
  5260. public function checkCategoryName(array $data): array
  5261. {
  5262. $result = Category::when($data, function ($query) use ($data) {
  5263. if (isset($data['name']) && $data['name']) {
  5264. $query->where("name", $data['name']);
  5265. }
  5266. if (isset($data['id']) && $data['id']) {
  5267. $query->where("id", "!=", $data['id']);
  5268. }
  5269. })->first();
  5270. if ($result) {
  5271. return Result::error("已存在");
  5272. } else {
  5273. return Result::success();
  5274. }
  5275. }
  5276. //20250226 产品列表
  5277. // 20250306 -------招聘--------fr
  5278. /*
  5279. * 招聘列表
  5280. * */
  5281. public function getJobRecruitingList(array $data): array
  5282. {
  5283. $where = [];
  5284. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5285. if ($data['checkout'] == 0) {
  5286. $job_status = [0, 2];
  5287. } else {
  5288. $job_status = [1];
  5289. }
  5290. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5291. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5292. }
  5293. $user = User::where('id', $data['user_id'])->first();
  5294. if (empty($user)) {
  5295. return Result::error("用户不存在", 0);
  5296. }
  5297. // 3:企业会员
  5298. if ($user['type_id'] == 3) {
  5299. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5300. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5301. }
  5302. // 如果 $where 为空,则不添加 where 条件
  5303. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5304. return $query->where($where);
  5305. })
  5306. ->whereIn('job_recruiting.status', $job_status)
  5307. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5308. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5309. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5310. ->orderBy("updated_at", "desc")
  5311. ->offset(($data['page'] - 1) * $data['page_size'])
  5312. ->limit($data['page_size'])
  5313. ->get()
  5314. ->all();
  5315. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5316. return $query->where($where);
  5317. })
  5318. ->whereIn('job_recruiting.status', $job_status)
  5319. ->count();
  5320. if (empty($result)) {
  5321. return Result::error("暂无招聘信息", 0);
  5322. }
  5323. return Result::success($result);
  5324. }
  5325. /*
  5326. * 招聘信息添加
  5327. * */
  5328. public function addJobRecruiting(array $data): array
  5329. {
  5330. // var_dump('添加招聘进入news------data',$data);
  5331. // return Result::success($data);
  5332. $user = User::where('user.id', $data['user_id'])
  5333. ->where('user.status', 1)
  5334. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5335. ->select(
  5336. 'user.type_id',
  5337. 'user.mobile',
  5338. 'user.email',
  5339. 'user_info.business_name',
  5340. 'user_info.company_hy_id',
  5341. 'user_info.company_nature',
  5342. 'user_info.company_size',
  5343. 'user_info.introduction',
  5344. 'user_info.real_name',
  5345. 'user_info.company_url',
  5346. 'user_info.address_arr_id',
  5347. 'user_info.address'
  5348. )
  5349. ->first();
  5350. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5351. return Result::error("用户不存在", 0);
  5352. }
  5353. $web = Website::where('id', $data['website_id'])->first();
  5354. if (empty($web)) {
  5355. return Result::error("网站不存在", 0);
  5356. }
  5357. // var_dump('添加招聘进入news---user---user',$user);
  5358. // 处理招聘关键词
  5359. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5360. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5361. } else {
  5362. Jieba::init(); // 初始化 jieba-php
  5363. Finalseg::init();
  5364. $segList = Jieba::cut($data['title']);
  5365. $segList1 = array_slice($segList, 0, 8);
  5366. $data['keyword'] = implode(',', $segList1);
  5367. }
  5368. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5369. $content = $data['description'];
  5370. // 去除 <style> 和 <script> 标签及其内容
  5371. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5372. // 去除所有 HTML 标签
  5373. $content = strip_tags($content);
  5374. // 去除 HTML 实体
  5375. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5376. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5377. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5378. // 去除多余空白
  5379. $content = preg_replace('/\s+/u', '', $content);
  5380. // 截取 100 个字符
  5381. $data['seo_description'] = mb_substr($content, 0, 100);
  5382. }
  5383. // return Result::success($user);
  5384. $data['action_id'] = $data['user_id'] ?? null;
  5385. $data['user_type'] = $user['type_id'] ?? null;
  5386. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5387. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5388. $data['catid'] = end($data['cat_arr_id']);
  5389. } else {
  5390. $data['catid'] = 0;
  5391. }
  5392. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5393. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5394. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5395. // 公司地址 管理员必填
  5396. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5397. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5398. // 管理员-企业相关信息
  5399. $company = [
  5400. // 'user_id' => $data['user_id']?? null,
  5401. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5402. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5403. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5404. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5405. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5406. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5407. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5408. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5409. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5410. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5411. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5412. ];
  5413. //去掉相关企业信息
  5414. $job = array_diff_key($data, array_flip(array_keys($company)));
  5415. // var_dump('添加招聘进入news---job---user',$job);
  5416. Db::beginTransaction();
  5417. try {
  5418. // // 先添加职位相关信息
  5419. if ($user['type_id'] == 10000) {
  5420. $job['status'] = 1;
  5421. }
  5422. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5423. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5424. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5425. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5426. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5427. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5428. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5429. // return Result::success($job);
  5430. $jobId = JobRecruiting::insertGetId($job);
  5431. if (empty($jobId)) {
  5432. Db::rollBack();
  5433. return Result::error("添加失败");
  5434. }
  5435. // 添加公司信息
  5436. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5437. $company['job_id'] = $jobId;
  5438. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5439. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5440. if ($user['type_id'] == 10000) {
  5441. // 管理员添加企业信息
  5442. $companyId = JobCompany::insertGetId($company);
  5443. if (empty($companyId)) {
  5444. Db::rollBack();
  5445. return Result::error("添加失败");
  5446. }
  5447. } else {
  5448. // 企业会员添加企业信息
  5449. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5450. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5451. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5452. $company['job_id'] = $jobId;
  5453. $companyId = JobCompany::insertGetId($company);
  5454. if (empty($companyId)) {
  5455. Db::rollBack();
  5456. return Result::error("添加失败");
  5457. }
  5458. }
  5459. Db::commit();
  5460. $result = [
  5461. 'job_id' => $jobId,
  5462. 'company_id' => $companyId,
  5463. ];
  5464. return Result::success($result);
  5465. } catch (\Exception $e) {
  5466. Db::rollBack();
  5467. return Result::error($e->getMessage(), 0);
  5468. }
  5469. // return Result::success($result);
  5470. }
  5471. /*
  5472. * 获取招聘信息详情
  5473. * */
  5474. public function getJobRecruitingInfo(array $data): array
  5475. {
  5476. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5477. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5478. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5479. ->select(
  5480. 'job_recruiting.*',
  5481. 'website.website_name as website_name',
  5482. 'job_company.business_name',
  5483. 'job_company.company_hy_id',
  5484. 'job_company.company_size',
  5485. 'job_company.company_nature',
  5486. 'job_company.introduction',
  5487. 'job_company.real_name',
  5488. 'job_company.mobile',
  5489. 'job_company.company_url',
  5490. 'job_company.address_arr_id',
  5491. 'job_company.address',
  5492. 'job_company.email'
  5493. )
  5494. ->first();
  5495. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5496. if (!empty($cityId)) {
  5497. if (isset($cityId[1]) && $cityId[1] != null) {
  5498. $city = District::where('id', $cityId[1])->first(['name']);
  5499. } else {
  5500. $city = District::where('id', $cityId[0])->first(['name']);
  5501. }
  5502. $result['city'] = $city['name'] ?? '';
  5503. }
  5504. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5505. if (is_array($addressId) && !empty($addressId)) {
  5506. $address = District::whereIn('id', $addressId)
  5507. ->orderBy('level', 'asc')
  5508. ->get(['name'])
  5509. ->pluck('name')
  5510. ->implode('');
  5511. // $job->address_name = $address ?? '';
  5512. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5513. }
  5514. if (empty($result)) {
  5515. return Result::error("招聘信息不存在", 0);
  5516. }
  5517. // return Result::success($job);
  5518. return Result::success($result);
  5519. }
  5520. /*
  5521. * 修改招聘信息
  5522. * */
  5523. public function upJobRecruiting(array $data): array
  5524. {
  5525. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5526. // return Result::success($job);
  5527. if (empty($job)) {
  5528. return Result::error("招聘信息不存在", 0);
  5529. }
  5530. $user = User::where('id', $data['user_id'])->first();
  5531. // return Result::success($user);
  5532. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5533. return Result::error("用户不存在", 0);
  5534. }
  5535. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5536. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5537. }
  5538. // 处理招聘关键词
  5539. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5540. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5541. } else {
  5542. Jieba::init(); // 初始化 jieba-php
  5543. Finalseg::init();
  5544. $segList = Jieba::cut($data['title']);
  5545. $segList1 = array_slice($segList, 0, 8);
  5546. $data['keyword'] = implode(',', $segList1);
  5547. }
  5548. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5549. $content = $data['description'];
  5550. // 去除 <style> 和 <script> 标签及其内容
  5551. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5552. // 去除所有 HTML 标签
  5553. $content = strip_tags($content);
  5554. // 去除 HTML 实体
  5555. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5556. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5557. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5558. // 去除多余空白
  5559. $content = preg_replace('/\s+/u', '', $content);
  5560. // 截取 100 个字符
  5561. $data['seo_description'] = mb_substr($content, 0, 100);
  5562. }
  5563. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5564. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5565. $data['catid'] = end($data['cat_arr_id']);
  5566. } else {
  5567. }
  5568. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5569. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5570. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5571. // 公司地址 管理员必填
  5572. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5573. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5574. // 管理员-企业相关信息
  5575. $company = [
  5576. // 'user_id' => $data['user_id']?? null,
  5577. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5578. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5579. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5580. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5581. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5582. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5583. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5584. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5585. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5586. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5587. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5588. ];
  5589. //去掉相关企业信息
  5590. $data = array_diff_key($data, array_flip(array_keys($company)));
  5591. $jobId = $data['id'];
  5592. $web = $data['website_id'];
  5593. $data['action_id'] = $data['user_id'];
  5594. unset($data['user_id']);
  5595. unset($data['user_type']);
  5596. unset($data['id']);
  5597. unset($data['website_id']);
  5598. // return Result::success($data);
  5599. Db::beginTransaction();
  5600. try {
  5601. // 管理员修改招聘信息
  5602. if ($user['type_id'] == 10000) {
  5603. $data['website_id'] = $web;
  5604. $company['website_id'] = $data['website_id'];
  5605. $data['status'] = 1;
  5606. } else {
  5607. $data['status'] = 0;
  5608. }
  5609. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5610. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5611. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5612. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5613. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5614. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5615. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5616. // return Result::success($job);
  5617. // Db::rollBack();
  5618. // return Result::success($company);
  5619. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5620. $this->sendMessage([
  5621. 'talk_type' => 500,
  5622. 'title' => $data['title'],
  5623. 'content' => '提交了审核',
  5624. 'messageType' => 10,
  5625. ]);
  5626. }
  5627. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5628. if (empty($result['job'])) {
  5629. Db::rollBack();
  5630. return Result::error("修改招聘信息失败");
  5631. }
  5632. // 管理员修改企业相关信息
  5633. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5634. if (empty($result['company'])) {
  5635. Db::rollBack();
  5636. return Result::error("修改企业相关信息失败");
  5637. }
  5638. Db::commit();
  5639. // return Result::success($result);
  5640. } catch (\Exception $e) {
  5641. Db::rollBack();
  5642. return Result::error($e->getMessage(), 0);
  5643. }
  5644. return Result::success($result);
  5645. }
  5646. /*
  5647. * 招聘信息删除
  5648. * */
  5649. public function delJobRecruiting(array $data): array
  5650. {
  5651. $user = User::where('id', $data['user_id'])->first();
  5652. if (empty($user)) {
  5653. return Result::error("用户不存在", 0);
  5654. }
  5655. $job = JobRecruiting::where('id', $data['id'])->first();
  5656. if (empty($job)) {
  5657. return Result::error("招聘信息不存在", 0);
  5658. }
  5659. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5660. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5661. }
  5662. Db::beginTransaction();
  5663. try {
  5664. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5665. if (empty($result['job'])) {
  5666. Db::rollBack();
  5667. return Result::error("删除招聘信息失败");
  5668. }
  5669. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5670. if (empty($result['company'])) {
  5671. Db::rollBack();
  5672. return Result::error("删除企业相关信息失败");
  5673. }
  5674. Db::commit();
  5675. } catch (\Exception $e) {
  5676. Db::rollBack();
  5677. return Result::error($e->getMessage(), 0);
  5678. }
  5679. return Result::success($result);
  5680. }
  5681. /*
  5682. * 获取公司信息
  5683. * */
  5684. public function getJobCompany(array $data): array
  5685. {
  5686. $user = User::where('user.id', $data['user_id'])
  5687. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5688. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5689. ->first();
  5690. // return Result::success($user);
  5691. if (empty($user)) {
  5692. return Result::error("用户不存在", 0);
  5693. }
  5694. if ($user['type_id'] == 3) {
  5695. $result = [
  5696. // 'id' => 0,
  5697. 'user_id' => $data['user_id'],
  5698. 'website_id' => $data['website_id'],
  5699. 'business_name' => $user['business_name'], // 企业名称
  5700. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5701. 'company_nature' => $user['company_nature'], // 公司性质
  5702. 'company_size' => $user['company_size'], // 公司规模
  5703. 'introduction' => $user['introduction'], // 公司简介
  5704. 'real_name' => $user['real_name'], // 企业联系人
  5705. 'mobile' => $user['mobile'], // 企业联系电话
  5706. 'company_url' => $user['company_url'], // 企业网址
  5707. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5708. 'address' => $user['address'], // 企业地址
  5709. 'email' => $user['email'], // 企业邮箱
  5710. ];
  5711. } else {
  5712. return Result::error("用户类型错误", 0);
  5713. }
  5714. if (empty($result)) {
  5715. return Result::error("公司信息不存在", 0);
  5716. }
  5717. return Result::success($result);
  5718. }
  5719. /*
  5720. * 修改公司信息
  5721. * */
  5722. public function upJobCompany(array $data): array
  5723. {
  5724. // return Result::success($data);
  5725. $user = User::where('user.id', $data['user_id'])
  5726. ->where('user.status', 1)
  5727. ->select('user.user_name', 'user.type_id')
  5728. ->first();
  5729. if (empty($user)) {
  5730. return Result::error("用户不存在", 0);
  5731. }
  5732. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5733. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5734. $company = [
  5735. 'business_name' => $data['business_name'], // 企业名称
  5736. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5737. 'company_nature' => $data['company_nature'], // 公司性质
  5738. 'company_size' => $data['company_size'], // 公司规模
  5739. 'introduction' => $data['introduction'], // 公司简介
  5740. // 'real_name' => $data['real_name'], // 企业联系人
  5741. 'company_url' => $data['company_url'], // 企业网址
  5742. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5743. 'address' => $data['address'], // 企业详细地址
  5744. // 'email' => $data['email'], // 企业邮箱
  5745. ];
  5746. if ($user['type_id'] == 3) {
  5747. Db::beginTransaction();
  5748. try {
  5749. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5750. 'business_name' => $data['business_name'], // 企业名称
  5751. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5752. 'company_nature' => $data['company_nature'], // 公司性质
  5753. 'company_size' => $data['company_size'], // 公司规模
  5754. 'introduction' => $data['introduction'], // 公司简介
  5755. // 'real_name' => $data['real_name'], // 企业联系人
  5756. 'company_url' => $data['company_url'], // 企业网址
  5757. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5758. 'address' => $data['address'], // 企业详细地址
  5759. ]);
  5760. if (empty($result['userinfo'])) {
  5761. Db::rollBack();
  5762. return Result::error('修改企业会员信息失败!');
  5763. }
  5764. $result['user'] = User::where('id', $data['user_id'])->update([
  5765. 'email' => $data['email'], // 企业邮箱
  5766. ]);
  5767. if (empty($result['user'])) {
  5768. Db::rollBack();
  5769. return Result::error('修改个人中心信息失败!');
  5770. }
  5771. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5772. if (!empty($job_company)) {
  5773. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5774. if (empty($result['job_company'])) {
  5775. Db::rollBack();
  5776. return Result::error('修改企业会员信息失败!');
  5777. }
  5778. }
  5779. Db::commit();
  5780. return Result::success($result);
  5781. } catch (\Exception $e) {
  5782. Db::rollBack();
  5783. return Result::error($e->getMessage(), 0);
  5784. }
  5785. } else {
  5786. return Result::error("用户类型错误", 0);
  5787. }
  5788. }
  5789. /*
  5790. * 获取省-市
  5791. * */
  5792. public function getJobRecruitingArea(array $data): array
  5793. {
  5794. if (isset($data['pid']) && $data['pid'] != null) {
  5795. $result = District::where('pid', $data['pid'])->get()->all();
  5796. } else {
  5797. $result = District::where('level', 1)->get()->all();
  5798. }
  5799. if (empty($result)) {
  5800. return Result::error("暂无此省市", 0);
  5801. }
  5802. return Result::success($result);
  5803. }
  5804. /*
  5805. * 获取行业分类
  5806. * */
  5807. public function getIndustry(array $data): array
  5808. {
  5809. $result = JobIndustry::get()->all();
  5810. if (empty($result)) {
  5811. return Result::error("暂无行业分类", 0);
  5812. }
  5813. return Result::success($result);
  5814. }
  5815. /*
  5816. * 获取职位
  5817. * */
  5818. public function getPositionList(array $data): array
  5819. {
  5820. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5821. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5822. } else {
  5823. $result = JobPosition::where('zwpid', 0)->get()->all();
  5824. }
  5825. if (empty($result)) {
  5826. return Result::error("暂无此职位", 0);
  5827. }
  5828. return Result::success($result);
  5829. }
  5830. /*
  5831. * 获取工作性质-菜单
  5832. * */
  5833. public function getJobNature(array $data): array
  5834. {
  5835. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5836. if (empty($result)) {
  5837. return Result::error("暂无工作性质", 0);
  5838. }
  5839. return Result::success($result);
  5840. }
  5841. /*
  5842. * 获取工作经验-菜单
  5843. * */
  5844. public function getExperience(array $data): array
  5845. {
  5846. $result = JobEnum::where('egroup', 'years')->get()->all();
  5847. if (empty($result)) {
  5848. return Result::error("暂无工作经验", 0);
  5849. }
  5850. return Result::success($result);
  5851. }
  5852. /*
  5853. * 获取学历-菜单
  5854. * */
  5855. public function getEducation(array $data): array
  5856. {
  5857. $result = JobEnum::where('egroup', 'education')->get()->all();
  5858. if (empty($result)) {
  5859. return Result::error("暂无学历", 0);
  5860. }
  5861. return Result::success($result);
  5862. }
  5863. /*
  5864. * 获取薪资-菜单
  5865. * */
  5866. public function getSalary(array $data): array
  5867. {
  5868. $result = JobEnum::where('egroup', 'income')->get()->all();
  5869. if (empty($result)) {
  5870. return Result::error("暂无薪资", 0);
  5871. }
  5872. return Result::success($result);
  5873. }
  5874. /*
  5875. * 获取语言-菜单
  5876. * */
  5877. public function getLanguage(array $data): array
  5878. {
  5879. $result = JobEnum::where('egroup', 'language')->get()->all();
  5880. if (empty($result)) {
  5881. return Result::error("暂无语言", 0);
  5882. }
  5883. return Result::success($result);
  5884. }
  5885. /*
  5886. * 获取掌握程度-菜单
  5887. * */
  5888. public function getLevel(array $data): array
  5889. {
  5890. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5891. if (empty($result)) {
  5892. return Result::error("暂无工作性质", 0);
  5893. }
  5894. return Result::success($result);
  5895. }
  5896. // 公司信息
  5897. /*
  5898. * 获取公司性质-菜单
  5899. * */
  5900. public function getCompanyNature(array $data): array
  5901. {
  5902. $result = JobNature::get()->all();
  5903. if (empty($result)) {
  5904. return Result::error("暂无公司性质", 0);
  5905. }
  5906. return Result::success($result);
  5907. }
  5908. /*
  5909. * 获取公司规模-菜单
  5910. * */
  5911. public function getCompanySize(array $data): array
  5912. {
  5913. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5914. if (empty($result)) {
  5915. return Result::error("暂无公司规模", 0);
  5916. }
  5917. return Result::success($result);
  5918. }
  5919. /*
  5920. * 招聘信息审核
  5921. * */
  5922. public function checkJobRecruiting(array $data): array
  5923. {
  5924. $user = User::where('id', $data['user_id'])->first();
  5925. if (empty($user)) {
  5926. return Result::error("用户不存在", 0);
  5927. }
  5928. $job = JobRecruiting::where('id', $data['id'])->first();
  5929. if (empty($job)) {
  5930. return Result::error("招聘信息不存在", 0);
  5931. }
  5932. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5933. if ($user['type_id'] != 10000) {
  5934. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5935. }
  5936. // 驳回原因
  5937. if ($data['status'] == 2) {
  5938. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5939. }
  5940. $data['action_id'] = $data['user_id'];
  5941. unset($data['user_id']);
  5942. if ($data['status'] == 1) {
  5943. $this->sendMessage([
  5944. 'talk_type' => 501,
  5945. 'title' => $job['title'],
  5946. 'content' => '审核通过',
  5947. 'messageType' => 10,
  5948. 'user_id' => $job['user_id'],
  5949. ]);
  5950. }
  5951. if ($data['status'] == 2) {
  5952. $this->sendMessage([
  5953. 'talk_type' => 501,
  5954. 'title' => $job['title'],
  5955. 'content' => '审核拒绝',
  5956. 'messageType' => 10,
  5957. 'user_id' => $job['user_id'],
  5958. ]);
  5959. }
  5960. if ($data['status'] == 0) {
  5961. $this->sendMessage([
  5962. 'talk_type' => 500,
  5963. 'title' => $job['title'],
  5964. 'content' => '提交了审核',
  5965. 'messageType' => 10,
  5966. ]);
  5967. }
  5968. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5969. if (empty($result)) {
  5970. return Result::error("审核失败", 0);
  5971. }
  5972. return Result::success($result);
  5973. }
  5974. public function myApplyList(array $data): array
  5975. {
  5976. var_dump($data, '------参数');
  5977. $user = User::where('id', $data['user_id'])->first();
  5978. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5979. return Result::error("用户不存在", 0);
  5980. }
  5981. // 1:个人会员 职场机会
  5982. if ($user['type_id'] == 1) {
  5983. $where['user_id'] = $user['id'];
  5984. }
  5985. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5986. $query->where('user_id', $user['id']);
  5987. })
  5988. ->pluck('recruit_id');
  5989. $where = [];
  5990. if (isset($data['salary']) && $data['salary'] != null) {
  5991. $where['job_recruiting.salary'] = $data['salary'];
  5992. }
  5993. if (isset($data['experience']) && $data['experience'] != null) {
  5994. $where['job_recruiting.experience'] = $data['experience'];
  5995. }
  5996. if (isset($data['business_name']) && $data['business_name'] != null) {
  5997. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5998. }
  5999. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6000. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6001. ->where($where);
  6002. // ->count();
  6003. $count = $query->count();
  6004. $query = clone $query;
  6005. $job = $query
  6006. ->leftJoin('job_enum as income_enum', function ($join) {
  6007. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6008. ->where('income_enum.egroup', 'income');
  6009. })
  6010. ->leftJoin('job_enum as years_enum', function ($join) {
  6011. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6012. ->where('years_enum.egroup', 'years');
  6013. })
  6014. // ->where($where)
  6015. ->orderBy('job_recruiting.updated_at', 'desc')
  6016. ->select(
  6017. 'job_recruiting.id',
  6018. 'job_recruiting.title',
  6019. 'job_company.business_name',
  6020. 'income_enum.evalue as salary_evalue',
  6021. 'income_enum.ename as salary_ename',
  6022. 'years_enum.evalue as experience_evalue',
  6023. 'years_enum.ename as experience_ename',
  6024. 'job_recruiting.updated_at'
  6025. )
  6026. ->offset(($data['page'] - 1) * $data['pageSize'])
  6027. ->limit($data['pageSize'])
  6028. ->get()
  6029. ->all();
  6030. if (empty($job)) {
  6031. return Result::error("暂无招聘信息", 0);
  6032. }
  6033. $result = [
  6034. 'row' => $job,
  6035. 'count' => $count,
  6036. ];
  6037. return Result::success($result);
  6038. }
  6039. public function readJobApply(array $data): array
  6040. {
  6041. $result = JobApply::where('id', $data['id'])->first();
  6042. if (empty($result)) {
  6043. return Result::error("查询失败", 0);
  6044. }
  6045. $result = JobApply::where('id', $data['id'])->update([
  6046. 'status' => 2,
  6047. ]);
  6048. return Result::success($result);
  6049. }
  6050. /*
  6051. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6052. * */
  6053. public function getRecruitingList(array $data): array
  6054. {
  6055. $user = User::where('id', $data['user_id'])->first();
  6056. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6057. return Result::error("用户不存在", 0);
  6058. }
  6059. // 1:个人会员 职场机会
  6060. if ($user['type_id'] == 1) {
  6061. $where['user_id'] = $user['id'];
  6062. }
  6063. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6064. $query->where('receiver_id', $user['id']);
  6065. })
  6066. ->pluck('recruit_id');
  6067. // return Result::success($recruitingId);
  6068. $where = [];
  6069. if (isset($data['salary']) && $data['salary'] != null) {
  6070. $where['job_recruiting.salary'] = $data['salary'];
  6071. }
  6072. if (isset($data['experience']) && $data['experience'] != null) {
  6073. $where['job_recruiting.experience'] = $data['experience'];
  6074. }
  6075. if (isset($data['business_name']) && $data['business_name'] != null) {
  6076. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6077. }
  6078. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6079. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6080. ->where($where);
  6081. // ->count();
  6082. $count = $query->count();
  6083. $query = clone $query;
  6084. $job = $query
  6085. ->leftJoin('job_enum as income_enum', function ($join) {
  6086. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6087. ->where('income_enum.egroup', 'income');
  6088. })
  6089. ->leftJoin('job_enum as years_enum', function ($join) {
  6090. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6091. ->where('years_enum.egroup', 'years');
  6092. })
  6093. // ->where($where)
  6094. ->orderBy('job_recruiting.updated_at', 'desc')
  6095. ->select(
  6096. 'job_recruiting.id',
  6097. 'job_recruiting.title',
  6098. 'job_company.business_name',
  6099. 'income_enum.evalue as salary_evalue',
  6100. 'income_enum.ename as salary_ename',
  6101. 'years_enum.evalue as experience_evalue',
  6102. 'years_enum.ename as experience_ename',
  6103. 'job_recruiting.updated_at'
  6104. )
  6105. ->offset(($data['page'] - 1) * $data['pageSize'])
  6106. ->limit($data['pageSize'])
  6107. ->get()
  6108. ->all();
  6109. if (empty($job)) {
  6110. return Result::error("暂无招聘信息", 0);
  6111. }
  6112. $result = [
  6113. 'row' => $job,
  6114. 'count' => $count,
  6115. ];
  6116. return Result::success($result);
  6117. }
  6118. /*
  6119. * 获取企业会员-招聘信息列表
  6120. * */
  6121. public function getRecruitingInfo(array $data): array
  6122. {
  6123. $user = User::where('id', $data['user_id'])->first();
  6124. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6125. return Result::error("用户不存在", 0);
  6126. }
  6127. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6128. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6129. ->select(
  6130. 'job_recruiting.*',
  6131. 'job_company.business_name',
  6132. 'job_company.company_hy_id',
  6133. 'job_company.company_size',
  6134. 'job_company.company_nature',
  6135. 'job_company.introduction',
  6136. 'job_company.real_name',
  6137. 'job_company.mobile',
  6138. 'job_company.company_url',
  6139. 'job_company.address_arr_id',
  6140. 'job_company.address',
  6141. 'job_company.email'
  6142. )
  6143. ->get();
  6144. if (empty($recruiting)) {
  6145. return Result::error("暂无招聘信息", 0);
  6146. }
  6147. return Result::success($recruiting);
  6148. }
  6149. /*
  6150. * 获取企业会员-我的沟通
  6151. * */
  6152. public function getJobResumeList(array $data): array
  6153. {
  6154. $user = User::where('id', $data['user_id'])->first();
  6155. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6156. return Result::error("用户不存在", 0);
  6157. }
  6158. $where = [];
  6159. if (isset($data['salary']) && $data['salary'] != null) {
  6160. $where['job_hunting.salary'] = $data['salary'];
  6161. }
  6162. if (isset($data['user_name']) && $data['user_name'] != null) {
  6163. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6164. }
  6165. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6166. $query->where('job_resume.user_id', $user['id']);
  6167. })
  6168. ->when(!empty($where), function ($query) use ($where) {
  6169. $query->where($where);
  6170. })
  6171. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6172. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6173. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6174. ->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');
  6175. $count = $job->count();
  6176. if ($count == 0) {
  6177. return Result::error("暂无沟通记录", 0);
  6178. }
  6179. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6180. ->offset(($data['page'] - 1) * $data['pageSize'])
  6181. ->limit($data['pageSize'])
  6182. ->get();
  6183. if (empty($jobs)) {
  6184. return Result::error("暂无沟通记录", 0);
  6185. }
  6186. $result['row'] = $this->processJob($jobs, '');
  6187. $result['count'] = $count;
  6188. return Result::success($result);
  6189. }
  6190. public function readJobResume(array $data): array
  6191. {
  6192. $result = JobResume::where('id', $data['id'])->first();
  6193. if (empty($result)) {
  6194. return Result::error("查询失败", 0);
  6195. }
  6196. $result = JobResume::where('id', $data['id'])->update([
  6197. 'status' => 2,
  6198. ]);
  6199. return Result::success($result);
  6200. }
  6201. // 20250306 招聘
  6202. //20250422 书刊音像
  6203. public function addBook(array $data): array
  6204. {
  6205. $user_id = $data['user_id'] ?? 0;
  6206. $type_id = $data['type_id'] ?? 0;
  6207. // $website_id = $data['website_id'] ?? 0;
  6208. // unset($data['user_id']);
  6209. unset($data['type_id']);
  6210. // unset($data['website_id']);
  6211. //处理数组
  6212. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6213. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6214. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6215. if ($data['img_url'] == '') {
  6216. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6217. preg_match_all($reg, $data['detail'], $matches);
  6218. if (isset($matches[1][0])) {
  6219. //截取varchar240
  6220. $data['img_url'] = substr($matches[1][0], 0, 240);
  6221. }
  6222. }
  6223. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6224. //提取标题+内容中的关键词
  6225. $data['keyword'] = $data['title'];
  6226. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6227. Jieba::init(); // 初始化 jieba-php
  6228. Finalseg::init();
  6229. $segList = Jieba::cut($data['keyword']);
  6230. $segList1 = array_slice($segList, 0, 8);
  6231. $data['keyword'] = implode(',', $segList1);
  6232. }
  6233. if ($data['description'] == '') {
  6234. //提取内容中的描述
  6235. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6236. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6237. }
  6238. var_dump($data, '--');
  6239. if ($data['status'] == 1) {
  6240. $this->sendMessage([
  6241. 'talk_type' => 400,
  6242. 'title' => $data['title'],
  6243. 'content' => '提交了审核',
  6244. 'messageType' => 7,
  6245. ]);
  6246. }
  6247. $result = Book::insertGetId($data);
  6248. if (empty($result)) {
  6249. return Result::error("添加失败", 0);
  6250. }
  6251. return Result::success($result);
  6252. }
  6253. public function getBookList(array $data): array
  6254. {
  6255. $where = [];
  6256. if (!empty($data["title"])) {
  6257. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6258. }
  6259. if (!empty($data['website_name'])) {
  6260. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6261. }
  6262. if (!empty($data['status'])) {
  6263. $where[] = ['book.status', '=', $data['status']];
  6264. }
  6265. $user_id = $data['user_id'];
  6266. $type_id = $data['type_id'];
  6267. // $type_id = 4;
  6268. var_dump($type_id, '------1--------');
  6269. if ($type_id != 10000) {
  6270. $where[] = ['book.user_id', '=', $user_id];
  6271. }
  6272. var_dump(!empty($data['status1']), '=-===1');
  6273. $result = Book::where($where)
  6274. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6275. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6276. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6277. ->when(isset($data['status1']), function ($query) use ($data) {
  6278. $query->whereIn('book.status', [1, 3]);
  6279. })
  6280. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6281. ->orderBy("updated_at", "desc")
  6282. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6283. if (empty($result)) {
  6284. return Result::error("暂无数据", 0);
  6285. }
  6286. // 取出数据
  6287. $rows = $result->items();
  6288. $count = $result->total();
  6289. $responseData = [
  6290. 'rows' => $rows,
  6291. 'count' => $count,
  6292. ];
  6293. return Result::success($responseData);
  6294. }
  6295. public function deleteBook(array $data): array
  6296. {
  6297. $result = Book::where('id', $data['id'])->delete();
  6298. if (empty($result)) {
  6299. return Result::error("删除失败", 0);
  6300. }
  6301. return Result::success($result);
  6302. }
  6303. public function updateBook(array $data): array
  6304. {
  6305. // $user_id = $data['user_id'] ?? 0;
  6306. $type_id = $data['type_id'] ?? 0;
  6307. // $website_id = $data['website_id'] ?? 0;
  6308. unset($data['user_id']);
  6309. unset($data['type_id']);
  6310. // unset($data['website_id']);
  6311. //处理数组
  6312. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6313. if ($data['img_url'] == '') {
  6314. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6315. preg_match_all($reg, $data['detail'], $matches);
  6316. if (isset($matches[1][0])) {
  6317. //截取varchar240
  6318. $data['img_url'] = substr($matches[1][0], 0, 240);
  6319. }
  6320. }
  6321. if ($data['keyword'] == '') {
  6322. //提取标题+内容中的关键词
  6323. $data['keyword'] = $data['title'];
  6324. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6325. Jieba::init(); // 初始化 jieba-php
  6326. Finalseg::init();
  6327. $segList = Jieba::cut($data['keyword']);
  6328. $segList1 = array_slice($segList, 0, 8);
  6329. $data['keyword'] = implode(',', $segList1);
  6330. }
  6331. if ($data['description'] == '') {
  6332. //提取内容中的描述
  6333. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6334. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6335. }
  6336. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6337. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6338. if ($data['status'] == 1) {
  6339. $this->sendMessage([
  6340. 'talk_type' => 400,
  6341. 'title' => $data['title'],
  6342. 'content' => '提交了审核',
  6343. 'messageType' => 7,
  6344. ]);
  6345. }
  6346. $result = Book::where("id", $data["id"])->update($data);
  6347. if (empty($result)) {
  6348. return Result::error("更新失败", 0);
  6349. }
  6350. return Result::success($result);
  6351. }
  6352. public function getBookInfo(array $data): array
  6353. {
  6354. $result = Book::where("id", $data["id"])->first();
  6355. if (empty($result)) {
  6356. return Result::error("获取失败", 0);
  6357. }
  6358. return Result::success($result);
  6359. }
  6360. public function updateBookStatus(array $data): array
  6361. {
  6362. //审核
  6363. unset($data['user_id']);
  6364. $bookInfo = Book::where("id", $data["id"])->first();
  6365. var_dump($bookInfo, '----');
  6366. if ($data['status'] == 2) {
  6367. $this->sendMessage([
  6368. 'talk_type' => 401,
  6369. 'title' => $bookInfo['title'],
  6370. 'content' => '审核通过',
  6371. 'messageType' => 7,
  6372. 'user_id' => $bookInfo['user_id'],
  6373. ]);
  6374. }
  6375. if ($data['status'] == 3) {
  6376. $this->sendMessage([
  6377. 'talk_type' => 401,
  6378. 'title' => $bookInfo['title'],
  6379. 'content' => '审核拒绝',
  6380. 'messageType' => 7,
  6381. 'user_id' => $bookInfo['user_id'],
  6382. ]);
  6383. }
  6384. if ($data['status'] == 1) {
  6385. $this->sendMessage([
  6386. 'talk_type' => 400,
  6387. 'title' => $bookInfo['title'],
  6388. 'content' => '提交了审核',
  6389. 'messageType' => 7,
  6390. // 'user_id'=>$bookInfo['user_id'],
  6391. ]);
  6392. }
  6393. $result = Book::where("id", $data["id"])->update($data);
  6394. if (empty($result)) {
  6395. return Result::error("更新失败", 0);
  6396. }
  6397. return Result::success($result);
  6398. }
  6399. //20250422 书刊音像
  6400. /**
  6401. * 贴身宝贝
  6402. * @param array $data
  6403. * @return array
  6404. */
  6405. public function getWebsiteTsbb(array $data): array
  6406. {
  6407. $month = $data['month'] ?? date('m');
  6408. $day = $data['day'] ?? date('d');
  6409. // 使用缓存键
  6410. $cacheKey = "tsbb_data_{$month}_{$day}";
  6411. // 尝试从缓存获取数据
  6412. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6413. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6414. if ($cachedData = $cache->get($cacheKey)) {
  6415. return Result::success(unserialize($cachedData));
  6416. }
  6417. //查询老黄历
  6418. try {
  6419. $date = date('Y-m-d');
  6420. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6421. // 使用 curl 替代 file_get_contents
  6422. $ch = curl_init();
  6423. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6424. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6425. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6426. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6427. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6428. 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');
  6429. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6430. 'Accept: application/json',
  6431. 'Content-Type: application/json',
  6432. 'Referer: https://www.36jxs.com/'
  6433. ]);
  6434. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6435. curl_setopt($ch, CURLOPT_ENCODING, '');
  6436. $almanacResponse = curl_exec($ch);
  6437. var_dump("====:", $almanacResponse);
  6438. if (curl_errno($ch)) {
  6439. var_dump('Curl error:', curl_error($ch));
  6440. throw new \Exception('Curl error: ' . curl_error($ch));
  6441. }
  6442. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6443. curl_close($ch);
  6444. if ($almanacResponse === false) {
  6445. throw new \Exception('Failed to fetch almanac data');
  6446. }
  6447. $almanacData = json_decode($almanacResponse, true);
  6448. if (json_last_error() !== JSON_ERROR_NONE) {
  6449. throw new \Exception('Failed to parse almanac data');
  6450. }
  6451. $almanacInfo = $almanacData['data'] ?? [];
  6452. } catch (\Exception $e) {
  6453. var_dump('Exception:', $e->getMessage());
  6454. $almanacInfo = [];
  6455. }
  6456. // 获取历史上的今天数据
  6457. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6458. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6459. ->orderBy('year', 'asc')
  6460. ->select("title", "id", "year", DB::raw('1 as type'))
  6461. ->limit(16)
  6462. ->get();
  6463. // 获取节日数据 - 从今天开始获取未来4条
  6464. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6465. ->orderBy('showtime', 'asc')
  6466. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6467. ->limit(16)
  6468. ->get();
  6469. //说文解字
  6470. $chartacterList = Character::orderBy('updated_at', 'desc')
  6471. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6472. ->limit(6)
  6473. ->get();
  6474. //谜语沙龙
  6475. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6476. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6477. ->limit(4)
  6478. ->get();
  6479. //成语欣赏
  6480. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6481. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6482. ->limit(32)
  6483. ->get();
  6484. //名联赏析
  6485. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6486. ->select("id", "first", "second", DB::raw('6 as type'))
  6487. ->limit(6)
  6488. ->get();
  6489. // 获取分类文章数据
  6490. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6491. ->pluck('category_id')
  6492. ->toArray();
  6493. $articlesList = [];
  6494. foreach ($categoryIds as $catid) {
  6495. // 先查有图片的
  6496. $withImg = DB::table('article')
  6497. ->where('status', 1)
  6498. ->where('catid', $catid)
  6499. ->whereNotNull('imgurl')
  6500. ->where('imgurl', '!=', '')
  6501. ->orderBy('updated_at', 'desc')
  6502. ->limit(6)
  6503. ->get();
  6504. $count = $withImg->count();
  6505. if ($count < 6) {
  6506. // 不足6条再查无图片的补足
  6507. $withoutImg = DB::table('article')
  6508. ->where('status', 1)
  6509. ->where('catid', $catid)
  6510. ->where(function ($q) {
  6511. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6512. })
  6513. ->orderBy('updated_at', 'desc')
  6514. ->limit(6 - $count)
  6515. ->get();
  6516. $articles = $withImg->concat($withoutImg);
  6517. } else {
  6518. $articles = $withImg;
  6519. }
  6520. // 组装
  6521. $category = \App\Model\Category::find($catid);
  6522. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6523. $articlesList[] = [
  6524. 'category_name' => $category ? $category->name : '',
  6525. 'catid' => $catid,
  6526. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6527. 'type' => 100,
  6528. 'list' => $articles->map(function ($item) {
  6529. return [
  6530. 'id' => $item->id,
  6531. 'title' => $item->title,
  6532. 'imgurl' => $item->imgurl,
  6533. 'created_at' => $item->created_at
  6534. ];
  6535. })->values()
  6536. ];
  6537. }
  6538. $result = [
  6539. 'almanac' => $almanacInfo,
  6540. 'historyTodayList' => [
  6541. 'category_name' => '历史上的今天',
  6542. 'list' => $historyTodayList,
  6543. 'type' => 1
  6544. ],
  6545. 'festivalList' => [
  6546. 'category_name' => '节日预告',
  6547. 'list' => $festivalList,
  6548. 'type' => 2
  6549. ],
  6550. 'chartacterList' => [
  6551. 'category_name' => '说文解字',
  6552. 'list' => $chartacterList,
  6553. 'type' => 3
  6554. ],
  6555. 'coupletList' => [
  6556. 'category_name' => '名联赏析',
  6557. 'list' => $coupletList,
  6558. 'type' => 6
  6559. ],
  6560. 'riddletList' => [
  6561. 'category_name' => '谜语沙龙',
  6562. 'list' => $riddletList,
  6563. 'type' => 4
  6564. ],
  6565. 'idiomList' => [
  6566. 'category_name' => '成语欣赏',
  6567. 'list' => $idiomList,
  6568. 'type' => 5
  6569. ],
  6570. 'articlesList' => $articlesList
  6571. ];
  6572. // 缓存结果,设置1小时过期
  6573. $cache->set($cacheKey, serialize($result), 3600);
  6574. return Result::success($result);
  6575. }
  6576. /**
  6577. * 获取资讯列表
  6578. */
  6579. public function getWebsiteTsbbList(array $data): array
  6580. {
  6581. $page = $data['page'] ?? 1;
  6582. $pageSize = $data['pageSize'] ?? 10;
  6583. // 如果没有传入月份和日期,则使用今天的日期
  6584. $month = $data['month'] ?? date('m');
  6585. $day = $data['day'] ?? date('d');
  6586. $total = 0;
  6587. $result = [];
  6588. $data['type'] = intval($data['type']);
  6589. var_dump("接收参数:", $data);
  6590. switch ($data['type']) {
  6591. case 1:
  6592. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6593. // 当前月份之后的数据
  6594. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6595. // 或者当前月份且日期大于等于当前日期的数据
  6596. ->orWhere(function ($q) use ($month, $day) {
  6597. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6598. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6599. });
  6600. })
  6601. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6602. $total = $query->count();
  6603. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6604. ->offset(($page - 1) * $pageSize)
  6605. ->limit($pageSize)
  6606. ->get();
  6607. break;
  6608. case 2:
  6609. $query = Festival::where(function ($q) use ($month, $day) {
  6610. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6611. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6612. ->orWhere(function ($q) use ($month, $day) {
  6613. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6614. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6615. });
  6616. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6617. $total = $query->count();
  6618. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6619. ->offset(($page - 1) * $pageSize)
  6620. ->limit($pageSize)
  6621. ->get();
  6622. break;
  6623. case 3:
  6624. $query = Character::orderBy("updated_at", "desc");
  6625. $total = $query->count();
  6626. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6627. ->offset(($page - 1) * $pageSize)
  6628. ->limit($pageSize)
  6629. ->get();
  6630. break;
  6631. case 4:
  6632. $query = Riddle::orderBy("updated_at", "desc");
  6633. $total = $query->count();
  6634. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6635. ->offset(($page - 1) * $pageSize)
  6636. ->limit($pageSize)
  6637. ->get();
  6638. break;
  6639. case 5:
  6640. $query = Idiom::orderBy("updated_at", "desc");
  6641. $total = $query->count();
  6642. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6643. ->offset(($page - 1) * $pageSize)
  6644. ->limit($pageSize)
  6645. ->get();
  6646. break;
  6647. case 6:
  6648. $query = Couplet::orderBy("updated_at", "desc");
  6649. $total = $query->count();
  6650. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6651. ->offset(($page - 1) * $pageSize)
  6652. ->limit($pageSize)
  6653. ->get();
  6654. break;
  6655. default:
  6656. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6657. $total = $query->count();
  6658. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6659. ->offset(($page - 1) * $pageSize)
  6660. ->limit($pageSize)
  6661. ->get();
  6662. }
  6663. return Result::success([
  6664. 'list' => $result,
  6665. 'total' => $total,
  6666. 'page' => (int)$page,
  6667. 'pageSize' => (int)$pageSize,
  6668. 'month' => $month,
  6669. 'day' => $day
  6670. ]);
  6671. }
  6672. /**
  6673. * 1:历史上的今天
  6674. * 2:节日
  6675. * 3:文章
  6676. *
  6677. * 资讯详情信息
  6678. */
  6679. public function getWebsiteTsbbDetail(array $data): array
  6680. {
  6681. $data['type'] = intval($data['type']);
  6682. switch ($data['type']) {
  6683. case 1:
  6684. $result = HistoryToday::where("id", $data['id'])->first();
  6685. break;
  6686. case 2:
  6687. $result = Festival::where("id", $data['id'])->first();
  6688. break;
  6689. case 3:
  6690. $result = Character::where("id", $data['id'])->first();
  6691. break;
  6692. case 4:
  6693. $result = Riddle::where("id", $data['id'])->first();
  6694. break;
  6695. case 5:
  6696. $result = Idiom::where("id", $data['id'])->first();
  6697. break;
  6698. case 6:
  6699. $result = Couplet::where("id", $data['id'])->first();
  6700. break;
  6701. default:
  6702. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6703. break;
  6704. }
  6705. return Result::success($result);
  6706. }
  6707. /**
  6708. * 农网导航首页数据
  6709. */
  6710. public function getWebsiteNwHomeList(array $data): array
  6711. {
  6712. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6713. ->pluck('category_id')
  6714. ->toArray();
  6715. // 使用子查询优化
  6716. $articlesList = DB::table('article')
  6717. ->select([
  6718. 'article.id',
  6719. 'article.title',
  6720. 'article.imgurl',
  6721. 'article.created_at',
  6722. 'category.name as category_name',
  6723. 'category.id as category_id',
  6724. 'website_category.aLIas_pinyin as pinyin',
  6725. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6726. DB::raw('100 as type')
  6727. ])
  6728. ->join('category', 'article.catid', '=', 'category.id')
  6729. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6730. ->leftJoin('website_category as parent_wc', function ($join) {
  6731. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6732. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6733. })
  6734. ->where('website_category.website_id', $data['website_id'])
  6735. ->where('article.status', 1)
  6736. ->whereIn('category.id', $categoryIds)
  6737. ->orderBy('article.created_at', 'desc')
  6738. ->get()
  6739. ->groupBy('category_id')
  6740. ->map(function ($group) {
  6741. // 确保第一条数据有图片
  6742. $firstWithImage = $group->first(function ($item) {
  6743. return !empty($item->imgurl);
  6744. });
  6745. if ($firstWithImage) {
  6746. // 如果有带图片的文章,将其放在第一位
  6747. $group = $group->filter(function ($item) use ($firstWithImage) {
  6748. return $item->id !== $firstWithImage->id;
  6749. })->prepend($firstWithImage);
  6750. }
  6751. return [
  6752. 'category_name' => $group->first()->category_name,
  6753. 'catid' => $group->first()->category_id,
  6754. 'pinyin' => $group->first()->pinyin,
  6755. 'parent_pinyin' => $group->first()->parent_pinyin,
  6756. 'list' => $group->take(4)->map(function ($item) {
  6757. return [
  6758. 'id' => $item->id,
  6759. 'title' => $item->title,
  6760. ];
  6761. })->values()
  6762. ];
  6763. })
  6764. ->values()
  6765. ->toArray();
  6766. return Result::success($articlesList);
  6767. }
  6768. /**
  6769. * 企业管理
  6770. * @param array $data
  6771. * @return array
  6772. */
  6773. public function getCompanyList(array $data): array
  6774. {
  6775. // return Result::success($data);
  6776. $where = [];
  6777. $user = User::where('id', $data['user_id'])->first();
  6778. if (empty($user)) {
  6779. return Result::error('用户不存在!');
  6780. }
  6781. if ($user['type_id'] != 10000) {
  6782. $where['user_id'] = $data['user_id'];
  6783. }
  6784. if (isset($data['title']) && !empty($data['title'])) {
  6785. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6786. }
  6787. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6788. array_push($where, ['website.id', $data['website_id']]);
  6789. }
  6790. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6791. if ($data['ischeck'] == 1) {
  6792. if (isset($data['status']) && $data['status'] != '') {
  6793. array_push($where, ['company.status', $data['status']]);
  6794. $query = Company::where($where);
  6795. } else {
  6796. $query = Company::whereIn('company.status', [0, 2]);
  6797. }
  6798. } else {
  6799. $query = Company::where('company.status', 1);
  6800. }
  6801. }
  6802. $result = $query->where($where)
  6803. ->leftJoin('website_category', function ($query) {
  6804. $query->on('website_category.category_id', '=', 'company.category_id')
  6805. ->on('website_category.website_id', '=', 'company.website_id');
  6806. })
  6807. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6808. ->select(
  6809. 'company.id',
  6810. 'company.title',
  6811. 'company.website_id',
  6812. 'company.category_id',
  6813. 'website.website_name',
  6814. 'website_category.alias as category_name',
  6815. 'company.status',
  6816. 'company.updated_at',
  6817. 'company.user_id'
  6818. )
  6819. ->orderBy('company.updated_at', 'desc')
  6820. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6821. if ($result->isEmpty()) {
  6822. return Result::error("暂无企业", 0);
  6823. }
  6824. return Result::success($result);
  6825. }
  6826. /**
  6827. * 添加企业
  6828. * @param array $data
  6829. * @return array
  6830. */
  6831. public function addCompany(array $data): array
  6832. {
  6833. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6834. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6835. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6836. $data['cat_arr_id'] = json_encode($car_arr_id);
  6837. } else {
  6838. $data['cat_arr_id'] = '';
  6839. }
  6840. if ($data['imgurl'] == '') {
  6841. //content中提取图片第一个图,正则提取
  6842. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6843. preg_match_all($reg, $data['content'], $matches);
  6844. if (isset($matches[1][0])) {
  6845. //截取varchar240
  6846. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6847. }
  6848. }
  6849. if ($data['keyword'] == '') {
  6850. //提取标题+内容中的关键词
  6851. $data['keyword'] = $data['title'];
  6852. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6853. Jieba::init(); // 初始化 jieba-php
  6854. Finalseg::init();
  6855. $segList = Jieba::cut($data['keyword']);
  6856. $segList1 = array_slice($segList, 0, 8);
  6857. $data['keyword'] = implode(',', $segList1);
  6858. }
  6859. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6860. //提取内容中的描述
  6861. $content = $data['content'];
  6862. // 去除 <style> 和 <script> 标签及其内容
  6863. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6864. // 去除所有 HTML 标签
  6865. $content = strip_tags($content);
  6866. // 去除 HTML 实体
  6867. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6868. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6869. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6870. // 去除多余空白
  6871. $content = preg_replace('/\s+/u', '', $content);
  6872. // 截取 100 个字符
  6873. $data['introduce'] = mb_substr($content, 0, 100);
  6874. }
  6875. $user = User::where('id', $data['user_id'])->first();
  6876. if (empty($user)) {
  6877. return Result::error('用户不存在!');
  6878. }
  6879. if ($user['type_id'] == 10000) {
  6880. $data['status'] = 1;
  6881. }
  6882. if (isset($data['level']) && $data['level'] != null) {
  6883. $data['level'] = intval($data['level']);
  6884. } else {
  6885. $data['level'] = null;
  6886. }
  6887. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6888. $this->sendMessage([
  6889. 'talk_type' => 900,
  6890. 'title' => $data['title'],
  6891. 'content' => '提交了审核',
  6892. 'messageType' => 8,
  6893. ]);
  6894. }
  6895. $result = Company::insertGetId($data);
  6896. if ($result) {
  6897. return Result::success($result);
  6898. } else {
  6899. return Result::error('添加失败');
  6900. }
  6901. }
  6902. /**
  6903. * 更新企业
  6904. * @param array $data
  6905. * @return array
  6906. */
  6907. public function upCompany(array $data): array
  6908. {
  6909. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6910. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6911. $data['cat_arr_id'] = json_encode($car_arr_id);
  6912. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6913. } else {
  6914. $data['cat_arr_id'] = '';
  6915. }
  6916. if ($data['imgurl'] == '') {
  6917. //content中提取图片第一个图,正则提取
  6918. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6919. preg_match_all($reg, $data['content'], $matches);
  6920. if (isset($matches[1][0])) {
  6921. //截取varchar
  6922. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6923. }
  6924. }
  6925. if ($data['keyword'] == '') {
  6926. //提取标题+内容中的关键词
  6927. $data['keyword'] = $data['title'];
  6928. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6929. Jieba::init(); // 初始化 jieba-php
  6930. Finalseg::init();
  6931. $segList = Jieba::cut($data['keyword']);
  6932. $segList1 = array_slice($segList, 0, 8);
  6933. $data['keyword'] = implode(',', $segList1);
  6934. }
  6935. if ($data['introduce'] == '') {
  6936. //提取内容中的描述
  6937. $content = $data['content'];
  6938. // 去除 <style> 和 <script> 标签及其内容
  6939. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6940. // 去除所有 HTML 标签
  6941. $content = strip_tags($content);
  6942. // 去除 HTML 实体
  6943. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6944. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6945. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6946. // 去除多余空白
  6947. $content = preg_replace('/\s+/u', '', $content);
  6948. // 截取 100 个字符
  6949. $data['introduce'] = mb_substr($content, 0, 100);
  6950. }
  6951. if (isset($data['level']) && $data['level'] != null) {
  6952. $data['level'] = intval($data['level']);
  6953. } else {
  6954. $data['level'] = null;
  6955. }
  6956. $user = User::where('id', $data['user_id'])->first();
  6957. if (empty($user)) {
  6958. return Result::error('用户不存在!');
  6959. }
  6960. if ($user['type_id'] == 10000) {
  6961. $data['status'] = 1;
  6962. } else {
  6963. $data['status'] = 0;
  6964. }
  6965. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6966. $this->sendMessage([
  6967. 'talk_type' => 900,
  6968. 'title' => $data['title'],
  6969. 'content' => '提交了审核',
  6970. 'messageType' => 8,
  6971. ]);
  6972. }
  6973. $result = Company::where('id', $data['id'])->update($data);
  6974. if ($result) {
  6975. return Result::success($result);
  6976. } else {
  6977. return Result::error('修改失败');
  6978. }
  6979. }
  6980. /**
  6981. * 删除企业
  6982. * @param array $data
  6983. * @return array
  6984. */
  6985. public function delCompany(array $data): array
  6986. {
  6987. $result = Company::where('id', $data['id'])->delete();
  6988. if ($result) {
  6989. return Result::success($result);
  6990. } else {
  6991. return Result::error('删除失败');
  6992. }
  6993. }
  6994. /**
  6995. * 审核企业
  6996. * @param array $data
  6997. * @return array
  6998. */
  6999. public function checkCompany(array $data): array
  7000. {
  7001. $user = User::where('id', $data['user_id'])->first();
  7002. if (empty($user)) {
  7003. return Result::error('用户不存在!');
  7004. }
  7005. $company = Company::where('id', $data['id'])->first();
  7006. if (empty($company)) {
  7007. return Result::error('企业不存在!');
  7008. }
  7009. // 状态:0:未审核 1:已审核 2:已拒绝
  7010. if ($data['status'] == 2 || $data['status'] == '2') {
  7011. $this->sendMessage([
  7012. 'talk_type' => 901,
  7013. 'title' => $company['title'],
  7014. 'content' => '审核拒绝',
  7015. 'messageType' => 8,
  7016. 'user_id' => $company['user_id'],
  7017. ]);
  7018. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7019. } else {
  7020. if ($data['status'] == 1) {
  7021. $this->sendMessage([
  7022. 'talk_type' => 901,
  7023. 'title' => $company['title'],
  7024. 'content' => '审核通过',
  7025. 'messageType' => 8,
  7026. 'user_id' => $company['user_id'],
  7027. ]);
  7028. } else if ($data['status'] == 0) {
  7029. $this->sendMessage([
  7030. 'talk_type' => 900,
  7031. 'title' => $company['title'],
  7032. 'content' => '提交了审核',
  7033. 'messageType' => 8,
  7034. ]);
  7035. }
  7036. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7037. }
  7038. if (empty($result)) {
  7039. return Result::error('审核失败!');
  7040. } else {
  7041. return Result::success($result);
  7042. }
  7043. }
  7044. /**
  7045. * 获取企业信息
  7046. * @param array $data
  7047. * @return array
  7048. */
  7049. public function getCompanyInfo(array $data): array
  7050. {
  7051. $result = Company::where('id', $data['id'])->first();
  7052. $city_arr = json_decode($result['city_arr_id']);
  7053. $result['city_name'] = District::whereIn('id', $city_arr)
  7054. ->pluck('name')
  7055. ->implode('-');
  7056. if (empty($result)) {
  7057. return Result::error('企业不存在!');
  7058. } else {
  7059. return Result::success($result);
  7060. }
  7061. }
  7062. /**
  7063. * @param array $data
  7064. * @return array
  7065. */
  7066. public function getWebsiteCompany(array $data): array
  7067. {
  7068. $categorys = json_decode($data['id'], true);
  7069. $category_arr = $this->processArticlePro($data['website_id']);
  7070. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7071. $catiall = $category_arr['catiall'];
  7072. $categoryIds = $category_arr['categoryIds'];
  7073. // return Result::success($category_arr);
  7074. foreach ($categorys as $key => $value) {
  7075. if (array_key_exists('level', $value)) {
  7076. $parts = explode(',', $value['level']);
  7077. $level = $parts[0] ?? null;
  7078. $imgnum = $parts[1] ?? null;
  7079. $textnum = $parts[2] ?? null;
  7080. if (!empty($textnum) && $textnum > 0) {
  7081. $text_num = Company::where('level', $level)
  7082. ->whereIn('category_id', $categoryIds)
  7083. ->where('status', 1)
  7084. ->select(
  7085. 'company.id',
  7086. 'company.title',
  7087. 'company.description',
  7088. 'company.updated_at',
  7089. 'company.category_id',
  7090. 'company.cat_arr_id'
  7091. )
  7092. ->orderBy('updated_at', 'desc')
  7093. ->limit($textnum)
  7094. ->get()->all();
  7095. }
  7096. if (!empty($imgnum) && $imgnum > 0) {
  7097. $img_num = Company::where('level', $level)
  7098. ->whereIn('category_id', $categoryIds)
  7099. ->where('status', 1)
  7100. ->where('imgurl', '!=', '')
  7101. ->whereNotNull('imgurl')
  7102. ->select(
  7103. 'company.id',
  7104. 'company.title',
  7105. 'company.description',
  7106. 'company.updated_at',
  7107. 'company.imgurl as imgs',
  7108. 'company.category_id',
  7109. 'company.cat_arr_id'
  7110. )
  7111. ->orderBy('updated_at', 'desc')
  7112. ->limit($imgnum)
  7113. ->get()->all();
  7114. }
  7115. }
  7116. if (array_key_exists('id', $value)) {
  7117. $parts = explode(',', $value['id']);
  7118. $category_id = $parts[0] ?? null;
  7119. $imgnum = $parts[1] ?? null;
  7120. $textnum = $parts[2] ?? null;
  7121. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7122. if (!empty($textnum) && $textnum > 0) {
  7123. $text_num = Company::whereIn('category_id', $category_arr)
  7124. // ->where('website_id', $data['website_id'])
  7125. ->where('status', 1)
  7126. ->select(
  7127. 'company.id',
  7128. 'company.title',
  7129. 'company.description',
  7130. 'company.updated_at',
  7131. 'company.category_id',
  7132. 'company.cat_arr_id'
  7133. )
  7134. ->orderBy('updated_at', 'desc')
  7135. ->limit($textnum)
  7136. ->get()->all();
  7137. }
  7138. if (!empty($imgnum) && $imgnum > 0) {
  7139. $img_num = Company::whereIn('category_id', $category_arr)
  7140. // ->where('website_id', $data['website_id'])
  7141. ->where('status', 1)
  7142. ->where('imgurl', '!=', '')
  7143. ->whereNotNull('imgurl')
  7144. ->select(
  7145. 'company.id',
  7146. 'company.title',
  7147. 'company.description',
  7148. 'company.updated_at',
  7149. 'company.imgurl as imgs',
  7150. 'company.category_id',
  7151. 'company.cat_arr_id'
  7152. )
  7153. ->orderBy('updated_at', 'desc')
  7154. ->limit($imgnum)
  7155. ->get()->all();
  7156. }
  7157. }
  7158. if (!empty($text_num)) {
  7159. foreach ($text_num as $k => $v) {
  7160. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7161. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7162. }
  7163. }
  7164. if (!empty($img_num)) {
  7165. foreach ($img_num as $k => $v) {
  7166. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7167. $imgurl = json_decode($v['imgs'], true);
  7168. if (!empty($imgurl)) {
  7169. $img_num[$k]->imgurl = $imgurl[0];
  7170. }
  7171. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7172. }
  7173. }
  7174. $company[$key]['img_num'] = $img_num ?? [];
  7175. $company[$key]['text_num'] = $text_num ?? [];
  7176. }
  7177. if (empty($company)) {
  7178. return Result::error("暂无相关企业信息", 0);
  7179. }
  7180. return Result::success($company);
  7181. }
  7182. /**
  7183. * @param array $data
  7184. * @return array
  7185. */
  7186. public function getWebsiteCompanyList(array $data): array
  7187. {
  7188. $where['website_id'] = $data['website_id'];
  7189. $where['status'] = 1;
  7190. $categoryIds = [];
  7191. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7192. $category_id = $data['category_id'];
  7193. }
  7194. $category_arr = $this->processArticlePro($data['website_id']);
  7195. $categoryIds = $category_arr['categoryIds'];
  7196. // return Result::success($cat_1st_arr);
  7197. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7198. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7199. })
  7200. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7201. $query->whereIn('category_id', $categoryIds);
  7202. })
  7203. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7204. $query->where('category_id', $category_id);
  7205. })
  7206. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7207. ->orderBy('updated_at', 'desc')
  7208. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7209. if (empty($company)) {
  7210. return Result::error("暂无相关公司信息", 0);
  7211. }
  7212. $result = [
  7213. 'count' => $company->total(),
  7214. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7215. ];
  7216. return Result::success($result);
  7217. }
  7218. /**
  7219. * 获取项目列表
  7220. * @param array $data
  7221. * @return array
  7222. */
  7223. public function getProjectList(array $data): array
  7224. {
  7225. $where = [];
  7226. $user = User::where('id', $data['user_id'])->first();
  7227. if (empty($user)) {
  7228. return Result::error('用户不存在!');
  7229. }
  7230. if ($user->type_id != 10000) {
  7231. array_push($where, ['project.user_id', $data['user_id']]);
  7232. }
  7233. $query = Project::query();
  7234. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7235. array_push($where, ['project.website_id', $data['website_id']]);
  7236. }
  7237. if (isset($data['title']) && !empty($data['title'])) {
  7238. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7239. }
  7240. if ($data['status'] != 3) {
  7241. array_push($where, ['project.status', $data['status']]);
  7242. }
  7243. $query = Project::where($where)
  7244. ->when($data['status'] == 3, function ($query) {
  7245. $query->whereIn('project.status', [0, 2]);
  7246. });
  7247. $count = $query->clone()
  7248. ->count();
  7249. $rows = $query->clone()
  7250. ->leftJoin('website', 'project.website_id', 'website.id')
  7251. ->leftJoin('website_category', function ($join) {
  7252. $join->on('project.website_id', '=', 'website_category.website_id')
  7253. ->on('project.category_id', '=', 'website_category.category_id');
  7254. })
  7255. ->select(
  7256. 'project.id',
  7257. 'project.title',
  7258. 'project.updated_at',
  7259. 'project.status',
  7260. 'website.website_name',
  7261. 'website_category.alias as category_name',
  7262. 'project.website_id',
  7263. 'project.user_id'
  7264. )
  7265. ->orderBy('project.updated_at', 'desc')
  7266. ->offset(($data['page'] - 1) * $data['pageSize'])
  7267. ->limit($data['pageSize'])
  7268. ->get();
  7269. if ($rows->isEmpty()) {
  7270. return Result::error("暂无相关项目信息", 0);
  7271. }
  7272. $result = [
  7273. 'count' => $count,
  7274. 'rows' => $rows,
  7275. ];
  7276. return Result::success($result);
  7277. }
  7278. /**
  7279. * 添加项目
  7280. * @param array $data
  7281. * @return array
  7282. */
  7283. public function addProject(array $data): array
  7284. {
  7285. $user = User::where('id', $data['user_id'])->first();
  7286. if (empty($user)) {
  7287. return Result::error("暂无相关用户信息", 0);
  7288. }
  7289. if ($user->type_id == 10000) {
  7290. $data['status'] = 1;
  7291. } else {
  7292. $data['status'] = 0;
  7293. }
  7294. if ($data['keyword'] == '') {
  7295. //提取标题+内容中的关键词
  7296. $data['keyword'] = $data['title'];
  7297. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7298. Jieba::init(); // 初始化 jieba-php
  7299. Finalseg::init();
  7300. $segList = Jieba::cut($data['keyword']);
  7301. $segList1 = array_slice($segList, 0, 8);
  7302. $data['keyword'] = implode(',', $segList1);
  7303. }
  7304. if ($data['description'] == '') {
  7305. //提取内容中的描述
  7306. // var_dump(11111);
  7307. //提取内容中的描述
  7308. $content = $data['introduce'];
  7309. // 去除 <style> 和 <script> 标签及其内容
  7310. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7311. // 去除所有 HTML 标签
  7312. $content = strip_tags($content);
  7313. // 去除 HTML 实体
  7314. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7315. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7316. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7317. // 去除多余空白
  7318. $content = preg_replace('/\s+/u', '', $content);
  7319. // 截取 100 个字符
  7320. $data['description'] = mb_substr($content, 0, 100);
  7321. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7322. }
  7323. if ($data['status'] == 0) {
  7324. $this->sendMessage([
  7325. 'talk_type' => 1000,
  7326. 'title' => $data['title'],
  7327. 'content' => '提交了审核',
  7328. 'messageType' => 9,
  7329. ]);
  7330. }
  7331. $project = Project::insertGetId($data);
  7332. if (empty($project)) {
  7333. return Result::error("暂无相关项目信息", 0);
  7334. }
  7335. return Result::success($project);
  7336. }
  7337. /**
  7338. * 更新项目
  7339. * @param array $data
  7340. * @return array
  7341. */
  7342. public function upProject(array $data): array
  7343. {
  7344. $project = Project::where('id', $data['id'])->first();
  7345. if (empty($project)) {
  7346. return Result::error("暂无相关项目信息", 0);
  7347. }
  7348. $id = $data['id'];
  7349. unset($data['id']);
  7350. $user = User::where('id', $data['user_id'])->first();
  7351. if (empty($user)) {
  7352. return Result::error("暂无相关用户信息", 0);
  7353. }
  7354. if ($user->type_id == 10000) {
  7355. $data['status'] = 1;
  7356. } else {
  7357. $data['status'] = 0;
  7358. }
  7359. unset($data['user_id']);
  7360. if ($data['keyword'] == '') {
  7361. //提取标题+内容中的关键词
  7362. $data['keyword'] = $data['title'];
  7363. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7364. Jieba::init(); // 初始化 jieba-php
  7365. Finalseg::init();
  7366. $segList = Jieba::cut($data['keyword']);
  7367. $segList1 = array_slice($segList, 0, 8);
  7368. $data['keyword'] = implode(',', $segList1);
  7369. }
  7370. if ($data['description'] == '') {
  7371. //提取内容中的描述
  7372. // var_dump(11111);
  7373. //提取内容中的描述
  7374. $content = $data['introduce'];
  7375. // 去除 <style> 和 <script> 标签及其内容
  7376. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7377. // 去除所有 HTML 标签
  7378. $content = strip_tags($content);
  7379. // 去除 HTML 实体
  7380. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7381. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7382. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7383. // 去除多余空白
  7384. $content = preg_replace('/\s+/u', '', $content);
  7385. // 截取 100 个字符
  7386. $data['description'] = mb_substr($content, 0, 100);
  7387. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7388. }
  7389. if ($data['status'] == 0) {
  7390. $this->sendMessage([
  7391. 'talk_type' => 1000,
  7392. 'title' => $data['title'],
  7393. 'content' => '提交了审核',
  7394. 'messageType' => 9,
  7395. ]);
  7396. }
  7397. $result = Project::where('id', $id)->update($data);
  7398. if (empty($result)) {
  7399. return Result::error("更新失败", 0);
  7400. }
  7401. return Result::success($result);
  7402. }
  7403. /**
  7404. * 删除项目
  7405. * @param array $data
  7406. * @return array
  7407. */
  7408. public function delProject(array $data): array
  7409. {
  7410. $user = User::where('id', $data['user_id'])->first();
  7411. if (empty($user)) {
  7412. return Result::error("暂无相关用户信息", 0);
  7413. }
  7414. $project = Project::where('id', $data['id'])->first();
  7415. if (empty($project)) {
  7416. return Result::error("暂无相关项目信息", 0);
  7417. }
  7418. $result = Project::where('id', $data['id'])->delete();
  7419. if (empty($result)) {
  7420. return Result::error("删除失败", 0);
  7421. }
  7422. return Result::success($result);
  7423. }
  7424. /**
  7425. * 审核项目
  7426. * @param array $data
  7427. * @return array
  7428. */
  7429. public function checkProject(array $data): array
  7430. {
  7431. $user = User::where('id', $data['user_id'])->first();
  7432. if (empty($user)) {
  7433. return Result::error("暂无相关用户信息", 0);
  7434. }
  7435. // 0:未审核; 1:已审核; 2:已拒绝;
  7436. if ($user->type_id != 10000) {
  7437. if ($data['status'] == 1 || $data['status'] == 2) {
  7438. return Result::error("此用户权限不足", 0);
  7439. }
  7440. }
  7441. $project = Project::where('id', $data['id'])->first();
  7442. if (empty($project)) {
  7443. return Result::error("暂无相关项目信息", 0);
  7444. }
  7445. if ($data['status'] == 2) {
  7446. $this->sendMessage([
  7447. 'talk_type' => 1001,
  7448. 'title' => $project['title'],
  7449. 'content' => '审核拒绝',
  7450. 'messageType' => 9,
  7451. 'user_id' => $project['user_id'],
  7452. ]);
  7453. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7454. } else {
  7455. if ($data['status'] == 1) {
  7456. $this->sendMessage([
  7457. 'talk_type' => 1001,
  7458. 'title' => $project['title'],
  7459. 'content' => '审核通过',
  7460. 'messageType' => 9,
  7461. 'user_id' => $project['user_id'],
  7462. ]);
  7463. } else if ($data['status'] == 0) {
  7464. $this->sendMessage([
  7465. 'talk_type' => 1000,
  7466. 'title' => $project['title'],
  7467. 'content' => '提交了审核',
  7468. 'messageType' => 9,
  7469. ]);
  7470. }
  7471. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7472. }
  7473. if (empty($result)) {
  7474. return Result::error("审核失败", 0);
  7475. }
  7476. return Result::success($result);
  7477. }
  7478. /**
  7479. * 获取项目详情
  7480. * @param array $data
  7481. * @return array
  7482. */
  7483. public function getProjectInfo(array $data): array
  7484. {
  7485. $project = Project::where('id', $data['id'])->first();
  7486. if (empty($project)) {
  7487. return Result::error("暂无相关项目信息", 0);
  7488. }
  7489. return Result::success($project);
  7490. }
  7491. public function getWebsiteCompanyInfo(array $data): array
  7492. {
  7493. $company = Company::where('id', $data['id'])
  7494. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7495. ->where('status', 1)
  7496. // ->where('website_id', $data['website_id'])
  7497. ->select('company.*', 'job_industry.hyname as hy_name')
  7498. ->first();
  7499. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7500. switch ($company->jobnature_id) {
  7501. case null:
  7502. $company->jobnature_name = '';
  7503. break;
  7504. case 0:
  7505. $company->jobnature_name = '市场监督';
  7506. break;
  7507. case 1:
  7508. $company->jobnature_name = '信访纪检';
  7509. break;
  7510. case 2:
  7511. $company->jobnature_name = '公检法司';
  7512. break;
  7513. case 3:
  7514. $company->jobnature_name = '高关注机构';
  7515. break;
  7516. default:
  7517. $company->jobnature_name = '';
  7518. break;
  7519. }
  7520. $city_arr = $company->city_arr_id;
  7521. if (!empty($city_arr)) {
  7522. $city_arr = json_decode($city_arr, true);
  7523. $cityNames = District::whereIn('id', $city_arr)
  7524. ->pluck('name')
  7525. ->implode('-');
  7526. $company->city_name = $cityNames;
  7527. } else {
  7528. $company->city_name = '';
  7529. }
  7530. if (empty($company)) {
  7531. return Result::error("暂无相关公司信息", 0);
  7532. }
  7533. return Result::success($company);
  7534. }
  7535. public function getMSG(array $data): array
  7536. {
  7537. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7538. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7539. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7540. $result = [];
  7541. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7542. //最近的5篇已审的文章
  7543. $apply_articale = Article::where('status', 1)
  7544. ->where('admin_user_id', $user_id)
  7545. ->orderBy('updated_at', 'desc')
  7546. // ->limit(5)
  7547. ->get();
  7548. //获取5条用户的已审核商品
  7549. $good = Good::where('status', 2)
  7550. ->where('user_id', $user_id)
  7551. ->orderBy('updated_at', 'desc')
  7552. // ->limit(5)
  7553. ->get();
  7554. //获取5条用户待审核的公告
  7555. $notice = Notice::where('status', 2)
  7556. ->where('user_id', $user_id)
  7557. ->orderBy('updated_at', 'desc')
  7558. ->limit(5)->get();
  7559. //获取5条用户的待审核投诉
  7560. $complaint = Complaint::where('status', 2)
  7561. ->where('user_id', $user_id)
  7562. ->orderBy('updated_at', 'desc')
  7563. // ->limit(5)
  7564. ->get();
  7565. //获取5条用户的book
  7566. $book = Book::where('status', 2)
  7567. ->where('user_id', $user_id)
  7568. ->orderBy('updated_at', 'desc')
  7569. // ->limit(5)
  7570. ->get();
  7571. //获取5条用户的求职
  7572. //获取5条用户的求职 1
  7573. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7574. ->where('job_hunting.user_id', $user_id)
  7575. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7576. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7577. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7578. ->orderBy('updated_at', 'desc')
  7579. // ->limit(5)
  7580. ->get();
  7581. //获取5条用户的求职 2
  7582. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7583. ->where('job_recruiting.user_id', $user_id)
  7584. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7585. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7586. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7587. ->orderBy('updated_at', 'desc')
  7588. // ->limit(5)
  7589. ->get();
  7590. //人才库 1
  7591. $job_apply = JobApply::where('job_apply.status', 1)
  7592. ->where('job_apply.receiver_id', $user_id)
  7593. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7594. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7595. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7596. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7597. ->select('job_recruiting', 'job_recruiting.', '', '')
  7598. ->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')
  7599. ->orderBy('updated_at', 'desc')
  7600. // ->limit(5)
  7601. ->get();
  7602. // 职场机会 2
  7603. $job_resume = JobResume::where('job_resume.status', 1)
  7604. ->where('job_resume.receiver_id', $user_id)
  7605. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7606. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7607. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7608. ->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')
  7609. ->orderBy('updated_at', 'desc')
  7610. // ->limit(5)
  7611. ->get();
  7612. //获取5条用户待处理的投诉
  7613. $complaint_deal = Complaint::where('status', 2)
  7614. ->where('deal', 1)
  7615. ->whereJsonContains('re_user_ids', $user_id)
  7616. ->orderBy('updated_at', 'desc')
  7617. // ->limit(5)
  7618. ->get();
  7619. //获取 被通知者未读信息
  7620. $notice_unread = Notice::where('status', 2)
  7621. ->whereJsonContains('re_user_ids', $user_id)
  7622. //未读消息
  7623. ->where(function ($query) use ($user_id) {
  7624. $query->whereJsonDoesntContain('read_id', $user_id)
  7625. ->orWhereNull('read_id');
  7626. })
  7627. ->orderBy('updated_at', 'desc')
  7628. ->get();
  7629. $complaint_unread = Complaint::where('status', 2)
  7630. ->whereJsonContains('re_user_ids', $user_id)
  7631. //未读消息
  7632. ->where(function ($query) use ($user_id) {
  7633. $query->whereJsonDoesntContain('read_id', $user_id)
  7634. ->orWhereNull('read_id');
  7635. })
  7636. ->orderBy('updated_at', 'desc')
  7637. ->get();
  7638. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7639. $complany = Company::where('status', 1)
  7640. ->where('user_id', $user_id)
  7641. ->orderBy('updated_at', 'desc')
  7642. // ->limit(5)
  7643. ->get();
  7644. //获取5条单聊未读聊天消息
  7645. // $chat = ChatRecords::where('is_read', 0)
  7646. // ->where('user_id', $user_id)
  7647. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7648. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7649. // ->where('action', 'recieved')
  7650. // ->where('talk_type', 1)
  7651. // ->orderBy('created_at', 'desc')
  7652. // // ->limit(5)
  7653. // ->get();
  7654. //获取5条未读群聊信息
  7655. // $chat_group = ChatRecords::where('is_read', 0)
  7656. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7657. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7658. // ->where('user_id', $user_id)
  7659. // ->where('talk_type', 2)
  7660. // ->orderBy('created_at', 'desc')
  7661. // // ->limit(5)
  7662. // ->get();
  7663. //获取5条用户的待审核项目
  7664. $project = Project::where('status', 1)
  7665. ->where('user_id', $user_id)
  7666. ->orderBy('updated_at', 'desc')
  7667. // ->limit(5)
  7668. ->get();
  7669. // count($chat) + count($chat_group) +
  7670. $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)
  7671. + count($complany)
  7672. + count($project)
  7673. + count($notice_unread)
  7674. + count($complaint_unread)
  7675. // + count($chat) + count($chat_group)
  7676. ;
  7677. $result = [
  7678. 'apply_articale' => $apply_articale,
  7679. // 'chat' => $chat,
  7680. // 'chat_group' => $chat_group,
  7681. 'good' => $good,
  7682. 'notice' => $notice,
  7683. 'complaint' => $complaint,
  7684. 'book' => $book,
  7685. 'job_hunting' => $job_hunting,
  7686. 'job_recruiting' => $job_recruiting,
  7687. 'job_apply' => $job_apply,
  7688. 'job_resume' => $job_resume,
  7689. 'complaint_deal' => $complaint_deal,
  7690. 'complany' => $complany,
  7691. 'project' => $project,
  7692. 'notice_unread' => $notice_unread,
  7693. 'complaint_unread' => $complaint_unread,
  7694. 'count' => $count,
  7695. ];
  7696. } elseif ($type_id == 12) {
  7697. //最近的5篇已审的文章
  7698. $apply_articale = Article::where('status', 1)
  7699. ->where('admin_user_id', $user_id)
  7700. ->limit(5)->get();
  7701. //获取5条单聊未读聊天消息
  7702. $chat = ChatRecords::where('is_read', 0)
  7703. ->where('user_id', $user_id)
  7704. ->where('talk_type', 1)
  7705. ->orderBy('created_at', 'desc')
  7706. ->limit(5)->get();
  7707. //获取5条未读群聊信息
  7708. $chat_group = ChatRecords::where('is_read', 0)
  7709. ->where('user_id', $user_id)
  7710. ->where('talk_type', 2)
  7711. ->orderBy('created_at', 'desc')
  7712. ->limit(5)->get();
  7713. //获取5条用户的已审核商品
  7714. $good = Good::where('status', 2)
  7715. ->where('user_id', $user_id)
  7716. ->orderBy('updated_at', 'desc')
  7717. ->limit(5)->get();
  7718. //获取5条用户的book
  7719. $book = Book::where('status', 2)
  7720. ->where('user_id', $user_id)
  7721. ->orderBy('updated_at', 'desc')
  7722. ->limit(5)->get();
  7723. //获取5条用户的求职
  7724. //获取5条用户的求职 1
  7725. //count($chat) + count($chat_group)
  7726. $count = count($apply_articale) + count($good);
  7727. $result = [
  7728. 'apply_articale' => $apply_articale,
  7729. 'chat' => $chat,
  7730. 'chat_group' => $chat_group,
  7731. 'good' => $good,
  7732. 'book' => $book,
  7733. 'count' => $count,
  7734. ];
  7735. } elseif ($type_id == 13) {
  7736. //最近的5篇已审的文章
  7737. $apply_articale = Article::where('status', 1)
  7738. ->where('admin_user_id', $user_id)
  7739. ->limit(5)->get();
  7740. //获取5条单聊未读聊天消息
  7741. $chat = ChatRecords::where('is_read', 0)
  7742. ->where('user_id', $user_id)
  7743. ->where('talk_type', 1)
  7744. ->orderBy('created_at', 'desc')
  7745. ->limit(5)->get();
  7746. //获取5条未读群聊信息
  7747. $chat_group = ChatRecords::where('is_read', 0)
  7748. ->where('user_id', $user_id)
  7749. ->where('talk_type', 2)
  7750. ->orderBy('created_at', 'desc')
  7751. ->limit(5)->get();
  7752. //获取5条用户的已审核商品
  7753. $good = Good::where('status', 2)
  7754. ->where('user_id', $user_id)
  7755. ->orderBy('updated_at', 'desc')
  7756. ->limit(5)->get();
  7757. //count($chat) + count($chat_group) +
  7758. $count = count($apply_articale) + count($good);
  7759. $result = [
  7760. 'apply_articale' => $apply_articale,
  7761. 'chat' => $chat,
  7762. 'chat_group' => $chat_group,
  7763. 'good' => $good,
  7764. 'count' => $count,
  7765. ];
  7766. } elseif ($type_id == 14) {
  7767. //最近的5篇已审的文章
  7768. $apply_articale = Article::where('status', 1)
  7769. ->where('admin_user_id', $user_id)
  7770. // ->limit(5)
  7771. ->get();
  7772. //获取5条用户的已审核商品
  7773. $good = Good::where('status', 2)
  7774. ->where('user_id', $user_id)
  7775. ->orderBy('updated_at', 'desc')
  7776. // ->limit(5)
  7777. ->get();
  7778. $count = count($apply_articale) + count($good);
  7779. $result = [
  7780. 'apply_articale' => $apply_articale,
  7781. 'chat' => '',
  7782. 'chat_group' => '',
  7783. 'good' => $good,
  7784. 'count' => $count,
  7785. ];
  7786. } elseif ($type_id == 10000) {
  7787. //获取未审核的5篇文章
  7788. $apply_articale = Article::where('status', 0)
  7789. ->orderBy('updated_at', 'desc')
  7790. // ->limit(5)
  7791. ->get();
  7792. //获取5条单聊未读聊天消息
  7793. //获取5条单聊未读聊天消息
  7794. // $chat = ChatRecords::where('is_read', 0)
  7795. // ->where('user_id', $user_id)
  7796. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7797. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7798. // ->where('action', 'recieved')
  7799. // ->where('talk_type', 1)
  7800. // ->orderBy('created_at', 'desc')
  7801. // // ->limit(5)
  7802. // ->get();
  7803. // //获取5条未读群聊信息
  7804. // $chat_group = ChatRecords::where('is_read', 0)
  7805. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7806. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7807. // ->where('user_id', $user_id)
  7808. // ->where('talk_type', 2)
  7809. // ->orderBy('created_at', 'desc')
  7810. // // ->limit(5)
  7811. // ->get();
  7812. //获取5条用户的已审核商品
  7813. $good = Good::where('status', 1)
  7814. // ->where('user_id', $user_id)
  7815. ->orderBy('updated_at', 'desc')
  7816. // ->limit(5)
  7817. ->get();
  7818. //获取5条用户待审核的公告
  7819. $notice = Notice::where('status', 1)
  7820. ->orderBy('updated_at', 'desc')
  7821. // ->limit(5)
  7822. ->get();
  7823. //获取5条用户的待审核投诉
  7824. $complaint = Complaint::where('status', 1)
  7825. ->orderBy('updated_at', 'desc')
  7826. // ->limit(5)
  7827. ->get();
  7828. //获取5条用户的book
  7829. $book = Book::where('status', 1)
  7830. ->orderBy('updated_at', 'desc')
  7831. // ->limit(5)
  7832. ->get();
  7833. //获取5条用户的求职 1
  7834. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7835. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7836. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7837. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7838. ->orderBy('updated_at', 'desc')
  7839. // ->limit(5)
  7840. ->get();
  7841. //获取5条用户的求职 2
  7842. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7843. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7844. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7845. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7846. ->orderBy('updated_at', 'desc')
  7847. // ->limit(5)
  7848. ->get();
  7849. //人才库 1
  7850. $job_apply = JobApply::where('job_apply.status', 1)
  7851. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7852. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7853. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7854. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7855. ->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')
  7856. ->orderBy('updated_at', 'desc')
  7857. // ->limit(5)
  7858. ->get();
  7859. // 职场机会 2
  7860. $job_resume = JobResume::where('job_resume.status', 1)
  7861. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7862. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7863. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7864. ->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')
  7865. ->orderBy('updated_at', 'desc')
  7866. // ->limit(5)
  7867. ->get();
  7868. //待审核数据com pro
  7869. $complany = Company::where('status', 0)
  7870. ->orderBy('updated_at', 'desc')
  7871. // ->limit(5)
  7872. ->get();
  7873. $project = Project::where('status', 0)
  7874. ->orderBy('updated_at', 'desc')
  7875. // ->limit(5)
  7876. ->get();
  7877. $count =
  7878. // count($chat) +
  7879. // count($chat_group) +
  7880. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7881. // + count($job_apply)
  7882. // + count($job_resume)
  7883. + count($complany)
  7884. + count($project);
  7885. $result = [
  7886. 'apply_articale' => $apply_articale,
  7887. // 'chat' => $chat,
  7888. // 'chat_group' => $chat_group,
  7889. 'good' => $good,
  7890. 'notice' => $notice,
  7891. 'complaint' => $complaint,
  7892. 'book' => $book,
  7893. 'job_hunting' => $job_hunting,
  7894. 'job_recruiting' => $job_recruiting,
  7895. // 'job_apply' => $job_apply,
  7896. // 'job_resume' => $job_resume,
  7897. 'complany' => $complany,
  7898. 'project' => $project,
  7899. 'count' => $count,
  7900. ];
  7901. } elseif ($type_id == 20000) {
  7902. }
  7903. var_dump($type_id, '-----------------test---------');
  7904. return Result::success($result);
  7905. }
  7906. /**
  7907. * @param array $data
  7908. * @return array
  7909. */
  7910. public function getWebsiteProject(array $data): array
  7911. {
  7912. $categorys = json_decode($data['id'], true);
  7913. if (!empty($categorys)) {
  7914. $category_arr = $this->processArticlePro($data['website_id']);
  7915. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7916. $catiall = $category_arr['catiall'];
  7917. // return Result::success($catiall);
  7918. foreach ($categorys as $key => $val) {
  7919. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7920. $level = explode(',', $val['level'])[0];
  7921. $imgnum = explode(',', $val['level'])[1] ?? null;
  7922. $textnum = explode(',', $val['level'])[2] ?? null;
  7923. if ($level == 1) {
  7924. if (!empty($textnum) && $textnum > 0) {
  7925. $text_num = Project::where('level', $level)
  7926. ->where('website_id', $data['website_id'])
  7927. ->where('status', 1)
  7928. ->select(
  7929. 'project.id',
  7930. 'project.title',
  7931. 'project.description',
  7932. 'project.updated_at',
  7933. 'project.category_id',
  7934. 'project.cat_arr_id'
  7935. )
  7936. ->orderBy('updated_at', 'desc')
  7937. ->limit($textnum)
  7938. ->get()->all();
  7939. }
  7940. if (!empty($imgnum) && $imgnum > 0) {
  7941. $img_num = Project::where('level', $level)
  7942. ->where('website_id', $data['website_id'])
  7943. ->where('status', 1)
  7944. ->where('imgurl', '!=', '')
  7945. ->whereNotNull('imgurl')
  7946. ->select(
  7947. 'project.id',
  7948. 'project.title',
  7949. 'project.description',
  7950. 'project.updated_at',
  7951. 'project.imgurl as imgs',
  7952. 'project.category_id',
  7953. 'project.cat_arr_id'
  7954. )
  7955. ->orderBy('updated_at', 'desc')
  7956. ->limit($imgnum)
  7957. ->get()->all();
  7958. }
  7959. } else {
  7960. if (!empty($textnum) && $textnum > 0) {
  7961. $text_num = Project::where('website_id', $data['website_id'])
  7962. ->where('status', 1)
  7963. ->select(
  7964. 'project.id',
  7965. 'project.title',
  7966. 'project.description',
  7967. 'project.updated_at',
  7968. 'project.category_id',
  7969. 'project.cat_arr_id',
  7970. 'project.website_id',
  7971. 'project.updated_at',
  7972. 'project.created_at'
  7973. )
  7974. ->orderBy('updated_at', 'desc')
  7975. ->limit($textnum)
  7976. ->get()->all();
  7977. }
  7978. if (!empty($imgnum) && $imgnum > 0) {
  7979. $img_num = Project::where('website_id', $data['website_id'])
  7980. ->where('status', 1)
  7981. ->where('imgurl', '!=', '')
  7982. ->whereNotNull('imgurl')
  7983. ->select(
  7984. 'project.id',
  7985. 'project.title',
  7986. 'project.description',
  7987. 'project.updated_at',
  7988. 'project.imgurl as imgs',
  7989. 'project.category_id',
  7990. 'project.cat_arr_id'
  7991. )
  7992. ->orderBy('updated_at', 'desc')
  7993. ->limit($imgnum)
  7994. ->get()->all();
  7995. }
  7996. }
  7997. }
  7998. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7999. $category_ids = explode(',', $val['id'])[0];
  8000. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8001. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8002. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8003. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8004. $text_num = Project::whereIn('category_id', $category_arr)
  8005. ->where('website_id', $data['website_id'])
  8006. ->where('status', 1)
  8007. ->select(
  8008. 'project.id',
  8009. 'project.title',
  8010. 'project.description',
  8011. 'project.updated_at',
  8012. 'project.category_id',
  8013. 'project.cat_arr_id'
  8014. )
  8015. ->orderBy('updated_at', 'desc')
  8016. ->limit($cat_textnum)
  8017. ->get()->all();
  8018. }
  8019. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8020. $img_num = Project::whereIn('category_id', $category_arr)
  8021. ->where('website_id', $data['website_id'])
  8022. ->where('status', 1)
  8023. ->where('imgurl', '!=', '')
  8024. ->whereNotNull('imgurl')
  8025. ->select(
  8026. 'project.id',
  8027. 'project.title',
  8028. 'project.description',
  8029. 'project.updated_at',
  8030. 'project.imgurl as imgs',
  8031. 'project.category_id',
  8032. 'project.cat_arr_id'
  8033. )
  8034. ->orderBy('updated_at', 'desc')
  8035. ->limit($cat_imgnum)
  8036. ->get()->all();
  8037. }
  8038. }
  8039. if (!empty($img_num)) {
  8040. foreach ($img_num as $k => $v) {
  8041. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8042. $imgurl = json_decode($v['imgs'], true);
  8043. if (!empty($imgurl)) {
  8044. $img_num[$k]->imgurl = $imgurl[0];
  8045. }
  8046. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8047. }
  8048. }
  8049. if (!empty($text_num)) {
  8050. foreach ($text_num as $k => $v) {
  8051. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8052. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8053. }
  8054. }
  8055. $project[$key]['img_num'] = $img_num ?? [];
  8056. $project[$key]['text_num'] = $text_num ?? [];
  8057. }
  8058. }
  8059. if (empty($project)) {
  8060. return Result::error("暂无相关项目信息", 0);
  8061. }
  8062. return Result::success($project);
  8063. }
  8064. /**
  8065. * @param array $data
  8066. * @return array
  8067. */
  8068. public function getWebsiteProjectInfo(array $data): array
  8069. {
  8070. $project = Project::where('id', $data['id'])
  8071. ->where('status', 1)
  8072. ->where('website_id', $data['website_id'])
  8073. ->select('project.*')
  8074. ->first();
  8075. if (empty($project)) {
  8076. return Result::error("暂无相关项目信息", 0);
  8077. }
  8078. return Result::success($project);
  8079. }
  8080. /**
  8081. * @param array $data
  8082. * @return array
  8083. */
  8084. public function getWebsiteProjectList(array $data): array
  8085. {
  8086. $where = [];
  8087. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8088. $where['category_id'] = $data['category_id'];
  8089. }
  8090. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8091. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8092. }
  8093. $query = Project::where($where)
  8094. ->where('status', 1)
  8095. ->where('website_id', $data['website_id'])
  8096. ->select(
  8097. 'project.id',
  8098. 'project.title',
  8099. 'project.description',
  8100. 'project.imgurl as imgs',
  8101. 'project.category_id',
  8102. 'project.cat_arr_id'
  8103. )
  8104. ->orderBy('updated_at', 'desc');
  8105. $count = $query->count();
  8106. $project = $query->clone()
  8107. ->offset(($data['page'] - 1) * $data['pageSize'])
  8108. ->limit($data['pageSize'])
  8109. ->get()->all();
  8110. if (empty($project)) {
  8111. return Result::error("暂无相关项目信息", 0);
  8112. }
  8113. $categorys = $this->processArticlePro($data['website_id']);
  8114. $catiall = $categorys['catiall'];
  8115. foreach ($project as $key => $val) {
  8116. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8117. if (!empty($val['imgs'])) {
  8118. $imgurl = json_decode($val['imgs'], true);
  8119. if (!empty($imgurl)) {
  8120. $project[$key]->imgurl = $imgurl[0];
  8121. }
  8122. } else {
  8123. $project[$key]->imgurl = '';
  8124. }
  8125. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8126. }
  8127. $result = [
  8128. 'rows' => $project,
  8129. 'count' => $count,
  8130. ];
  8131. return Result::success($result);
  8132. }
  8133. /**
  8134. * @param array $data
  8135. * @return array
  8136. */
  8137. public function getWebsiteCategoryJob(array $data): array
  8138. {
  8139. $categorys = json_decode($data['id'], true);
  8140. if (!empty($categorys)) {
  8141. $category_arr = $this->processArticlePro($data['website_id']);
  8142. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8143. $catiall = $category_arr['catiall'];
  8144. foreach ($categorys as $key => $val) {
  8145. if (isset($val['id']) && !empty($val['id'])) {
  8146. $catid = explode(',', $val['id'])[0] ?? null;
  8147. $type = explode(',', $val['id'])[1] ?? null;
  8148. $textnum = explode(',', $val['id'])[2] ?? null;
  8149. }
  8150. // 4:招聘;5:求职;
  8151. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8152. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8153. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8154. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8155. ->where('job_recruiting.status', 1)
  8156. ->where('job_recruiting.website_id', $data['website_id'])
  8157. ->select(
  8158. 'job_recruiting.id',
  8159. 'job_recruiting.title',
  8160. 'job_company.business_name',
  8161. 'job_recruiting.updated_at',
  8162. 'job_recruiting.cat_arr_id',
  8163. 'job_recruiting.keyword',
  8164. 'job_recruiting.description'
  8165. )
  8166. ->orderBy('job_recruiting.updated_at', 'desc')
  8167. ->limit($textnum)
  8168. ->get()->all();
  8169. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8170. // 状态 审核状态,1待审核2已审核3已拒绝
  8171. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8172. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8173. ->where('job_hunting.status', 2)
  8174. ->where('job_hunting.website_id', $data['website_id'])
  8175. ->select(
  8176. 'job_hunting.id',
  8177. 'job_hunting.name',
  8178. 'job_hunting.cat_arr_id',
  8179. 'job_position.zwname as job_name',
  8180. 'job_hunting.updated_at',
  8181. 'job_hunting.keyword',
  8182. 'job_hunting.slelf_evaluation'
  8183. )
  8184. ->orderBy('updated_at', 'desc')
  8185. ->limit($textnum)
  8186. ->get()->all();
  8187. } else {
  8188. $job = [];
  8189. }
  8190. // var_dump($catid.'222uuuuuuu'.$key);
  8191. if (!empty($job)) {
  8192. foreach ($job as $k => $value) {
  8193. if (isset($value->cat_arr_id)) {
  8194. $catArr = json_decode($value->cat_arr_id, true);
  8195. $catId = end($catArr);
  8196. } else {
  8197. continue;
  8198. }
  8199. if (isset($catiall[$catId])) {
  8200. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8201. }
  8202. }
  8203. }
  8204. // var_dump($catid.'xxxxx'.$key);
  8205. $result[$key] = $job ?? [];
  8206. }
  8207. }
  8208. if (empty($result)) {
  8209. return Result::error("暂无相关分类信息", 0);
  8210. }
  8211. return Result::success($result);
  8212. }
  8213. /**
  8214. * 发送消息
  8215. * @param array $messageData
  8216. * @return void
  8217. */
  8218. public function sendMessage($messageData)
  8219. {
  8220. $msg = [
  8221. 'talk_type' => $messageData['talk_type'],
  8222. 'title' => $messageData['title'],
  8223. 'content' => $messageData['content'],
  8224. 'messageType' => $messageData['messageType'],
  8225. 'user_id' => $messageData['user_id'] ?? '',
  8226. 'time' => microtime(),
  8227. ];
  8228. $message = new MqProducer($msg);
  8229. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8230. $producer->produce($message);
  8231. }
  8232. }