NewsService.php 313 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. // $rep = Article::where($where)
  396. // ->whereNotIn('article.status', [404])
  397. // ->when($status1, function ($query) use ($status1) {
  398. // if (isset($status1) && $status1) {
  399. // $query->whereIn('article.status', $status1);
  400. // }
  401. // })
  402. // ->leftJoin('category', 'article.catid', 'category.id')
  403. // ->leftJoin('website_category', function ($join) {
  404. // $join->on('article.web_site_id', '=', 'website_category.website_id')
  405. // ->on('article.catid', '=', 'website_category.category_id');
  406. // })
  407. // ->when($type_id != 10000 && !empty($data['website_id']), function ($query) use ($data) {
  408. // $query->leftJoin('article_ignore', function ($join) use ($data) {
  409. // $join->on('article.id', '=', 'article_ignore.article_id')
  410. // ->where('article_ignore.website_id', $data['website_id']);
  411. // });
  412. // })
  413. // ->select("article.*", "category.name as category_name", "website_category.alias",
  414. // Db::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time'))
  415. // ->orderBy("article.updated_at", "desc")
  416. // ->limit($data['pageSize'])
  417. // ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  418. //
  419. $query = Article::where($where)
  420. ->whereNotIn('article.status', [404])
  421. ->when($status1, function ($query) use ($status1) {
  422. if (isset($status1) && $status1) {
  423. $query->whereIn('article.status', $status1);
  424. }
  425. })
  426. ->leftJoin('category', 'article.catid', 'category.id')
  427. ->leftJoin('website_category', function ($join) {
  428. $join->on('article.web_site_id', '=', 'website_category.website_id')
  429. ->on('article.catid', '=', 'website_category.category_id');
  430. });
  431. if ($type_id != 10000 && !empty($data['website_id'])) {
  432. $query = $query
  433. ->leftJoin('article_ignore', function ($join) use ($data) {
  434. $join->on('article.id', '=', 'article_ignore.article_id')
  435. ->where('article_ignore.website_id', $data['website_id']);
  436. })
  437. ->select("article.*", "category.name as category_name", "website_category.alias",'article_ignore.c_show_time');
  438. } else {
  439. $query = $query
  440. ->select("article.*", "category.name as category_name", "website_category.alias");
  441. }
  442. $rep = $query
  443. ->orderBy("article.updated_at", "desc")
  444. ->limit($data['pageSize'])
  445. ->offset(($data['page'] - 1) * $data['pageSize'])
  446. ->get();
  447. $count = $query->count();
  448. $data = [
  449. 'rows' => $rep->toArray(),
  450. 'count' => $count,
  451. ];
  452. if (empty($rep)) {
  453. return Result::error("没有信息数据");
  454. }
  455. return Result::success($data);
  456. }
  457. /**
  458. * @param array $data
  459. * @return array
  460. */
  461. public function addArticle(array $data): array
  462. {
  463. var_dump($data, '----------12-----------1');
  464. // ------c_show_time********add***1****
  465. $is_collect = $data['is_collect'] ?? 0;
  466. $user_type = $data['user_type'];
  467. unset($data['is_collect']);
  468. unset($data['user_type']);
  469. // ------c_show_time********add***1****
  470. unset($data['nav_add_pool_id']);
  471. // unset($data['commend_id']);
  472. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  473. Db::beginTransaction();
  474. try {
  475. //处理投票
  476. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  477. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  478. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  479. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  480. unset($data['is_survey']);
  481. unset($data['survey_name']);
  482. unset($data['suvey_array']);
  483. unset($data['website_id']);
  484. unset($data['web_site_id']);
  485. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  486. if ($data['hits'] == '') {
  487. $data['hits'] = 0;
  488. }
  489. if ($data['is_original'] == '') {
  490. $data['is_original'] = 0;
  491. }
  492. if ($data['status'] == '') {
  493. $data['status'] = 0;
  494. }
  495. $articleData = $data;
  496. unset($articleData['content']);
  497. //自动处理缩略图、关键字、描述
  498. if ($articleData['imgurl'] == '') {
  499. //如果没有图,设置level=0
  500. $levelArr = json_decode($articleData['level'], true);
  501. var_dump($levelArr, '----------levelArr-----------1');
  502. //content中提取图片第一个图,正则提取
  503. // -------采集器相关优化-----
  504. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  505. if($is_collect == 1){
  506. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  507. }else{
  508. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  509. }
  510. // -------采集器相关优化-----
  511. preg_match_all($reg, $data['content'], $matches);
  512. if (isset($matches[1][0])) {
  513. //截取varchar240
  514. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  515. //如果有图,设置level=3
  516. if (!in_array(3, $levelArr)) {
  517. $levelArr[] = 3;
  518. }
  519. $articleData['level'] = json_encode($levelArr);
  520. } else {
  521. if (!in_array(0, $levelArr)) {
  522. $levelArr[] = 0;
  523. }
  524. $articleData['level'] = json_encode($levelArr);
  525. }
  526. }
  527. var_dump($articleData['level'], '----------$articleData[level]----------1');
  528. if ($articleData['keyword'] == '') {
  529. //提取标题+内容中的关键词
  530. $articleData['keyword'] = $data['title'];
  531. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  532. Jieba::init(); // 初始化 jieba-php
  533. Finalseg::init();
  534. $segList = Jieba::cut($articleData['keyword']);
  535. $segList1 = array_slice($segList, 0, 8);
  536. $articleData['keyword'] = implode(',', $segList1);
  537. }
  538. if ($articleData['introduce'] == '') {
  539. //提取内容中的描述
  540. $content = $data['content'];
  541. // 去除 <style> 和 <script> 标签及其内容
  542. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  543. // 去除所有 HTML 标签
  544. $content = strip_tags($content);
  545. // 去除 HTML 实体
  546. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  547. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  548. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  549. // 去除多余空白
  550. $content = preg_replace('/\s+/u', '', $content);
  551. // 截取 100 个字符
  552. $articleData['introduce'] = mb_substr($content, 0, 100);
  553. }
  554. if ($articleData['status'] == 0) {
  555. $this->sendMessage([
  556. 'talk_type' => 100,
  557. 'title' => $articleData['title'],
  558. 'content' => '提交了审核',
  559. 'messageType' => 2,
  560. ]);
  561. }
  562. $id = Article::insertGetId($articleData);
  563. if (!$id) {
  564. throw new \Exception('文章插入失败');
  565. }
  566. $articleDataContent = [
  567. 'article_id' => $id,
  568. 'content' => $data['content'],
  569. ];
  570. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  571. if (!$contentInsertId) {
  572. throw new \Exception('文章内容插入失败');
  573. }
  574. // ------c_show_time********add***2****
  575. // 直接使用当前系统时间,不再强制添加8小时
  576. $now = date('Y-m-d H:i:s');
  577. if($user_type == 10000 || $is_collect == 1){
  578. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  579. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  580. if (!isset($data['catid'])) {
  581. throw new \Exception('缺少必要字段:catid');
  582. }
  583. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  584. $web = WebsiteCategory::where('category_id', $data['catid'])
  585. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  586. ->select('website_id',
  587. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  588. ->get();
  589. // $id = 225; -----测试开启
  590. // 采集来的文章,错开时间在两小时之内发布
  591. if($user_type == 10000 && $is_collect == 1){
  592. $web_num = $web->where('is_core', '!=', 2)->count();
  593. $waiting_interval = 10;
  594. if($web_num > 12){
  595. // 若网站数量大于12个,则每个网站间隔时间取均值
  596. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  597. $waiting_interval = 120 / max(1, $web_num);
  598. }
  599. $time = 0;
  600. }else{
  601. // 非核心站与核心站----显示时间-----间隔
  602. $time = 20;
  603. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  604. $waiting_interval = 5;
  605. }
  606. // 将 Hyperf\Database\Model\Collection 转换为数组
  607. $webArray = $web->toArray();
  608. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  609. // 检查 $item 对象是否有 is_core 属性
  610. if (!isset($item['is_core'])) {
  611. throw new \Exception('$item 对象缺少 is_core 属性');
  612. }
  613. // 当 is_core 为 2 时,则表示此网站不存在
  614. if ($item['is_core'] == 2) {
  615. return null;
  616. }
  617. if($is_collect == 1){
  618. // 采集来的文章,错开时间在两小时之内发布
  619. // $time = 0;
  620. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  621. $time += $waiting_interval;
  622. }else if($item['is_core'] == 1){
  623. // 当 is_core 为 1 时,则表示此网站是核心站
  624. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  625. }else{
  626. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  627. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  628. if ($item['is_core'] == 0) {
  629. $time += $waiting_interval;
  630. }
  631. }
  632. return [
  633. 'article_id' => $id,
  634. 'website_id' => $item['website_id'],
  635. 'c_show_time' => $c_show_time,
  636. // 'is_core' => $item['is_core'],
  637. // 'time' => $time
  638. ];
  639. }, array_keys($webArray), $webArray)));
  640. // Db::commit();
  641. // return Result::success($article_ignore);
  642. if(!empty($article_ignore)){
  643. $article_ignores = ArticleIgnore::insert($article_ignore);
  644. if(!$article_ignores){
  645. throw new \Exception('c端展示时间插入失败');
  646. }
  647. }
  648. }
  649. // ------c_show_time********add***2****
  650. //处理投票
  651. if ($is_survey == 1) {
  652. //生成年月日时分秒+8位随机数
  653. $uuid = date('YmdHis') . rand(10000000, 99999999);
  654. var_dump($suvey_array, 'suvey_array________');
  655. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  656. var_dump($suveys_array, '---------------------1');
  657. var_dump($suvey_array, '---------------------2');
  658. $suvey_data = [];
  659. foreach ($suveys_array as $key => $value) {
  660. if ($value == '') {
  661. continue;
  662. }
  663. if (is_array($value)) {
  664. $suvey_data[] = [
  665. 'sur_id' => $uuid,
  666. 'art_id' => $id,
  667. 'website_id' => $website_id ?? 2,
  668. 'survey_name' => $survey_name,
  669. 'choice_name' => $value[1],
  670. 'is_other' => 1,
  671. 'other_id' => 0,
  672. 'results' => 0,
  673. ];
  674. } else {
  675. $suvey_data[] = [
  676. 'sur_id' => $uuid,
  677. 'art_id' => $id,
  678. 'website_id' => $website_id ?? 2,
  679. 'survey_name' => $survey_name,
  680. 'choice_name' => $value,
  681. 'is_other' => 0,
  682. 'other_id' => 0,
  683. 'results' => 0,
  684. ];
  685. }
  686. if (empty($suvey_data)) {
  687. throw new \Exception("投票数据为空");
  688. }
  689. }
  690. $result = ArticleSurvey::insert($suvey_data);
  691. if (!$result) {
  692. throw new \Exception("投票失败,ArticleSurvey插入失败");
  693. }
  694. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  695. if (!$result) {
  696. throw new \Exception("投票失败,更新主表失败");
  697. }
  698. }
  699. Db::commit();
  700. return Result::success(['id' => $id]);
  701. } catch (\Throwable $ex) {
  702. Db::rollBack();
  703. var_dump($ex->getMessage());
  704. return Result::error("创建失败", 0);
  705. }
  706. }
  707. /**
  708. * @param array $data
  709. * @return array
  710. */
  711. public function delArticle(array $data): array
  712. {
  713. // ------c_show_time********del*******
  714. Db::beginTransaction();
  715. try{
  716. $article = Article::where(['id' => $data['id']])->delete();
  717. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  718. if (!$article) {
  719. throw new \Exception("删除失败,文章删除失败");
  720. }
  721. //survey投票删除
  722. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  723. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  724. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  725. // 若文章详情删除失败,抛出异常
  726. if (!$article_data) {
  727. throw new \Exception("删除失败,文章详情删除失败");
  728. }
  729. Db::commit(); // 所有操作成功,提交事务
  730. }catch (\Throwable $ex) {
  731. Db::rollBack();
  732. var_dump($ex->getMessage());
  733. return Result::error("删除失败: " . $ex->getMessage(), 0);
  734. }
  735. // ------c_show_time********del*******
  736. if (!$article) {
  737. return Result::error("删除失败");
  738. }
  739. return Result::success($article);
  740. }
  741. /**
  742. * @param array $data
  743. * @return array
  744. */
  745. public function updateArticle(array $data): array
  746. {
  747. var_dump($data, '----------12-----------1');
  748. Db::beginTransaction();
  749. // ------c_show_time********up*******
  750. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  751. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  752. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  753. $web = WebsiteCategory::where('category_id', $data['catid'])
  754. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  755. ->select('website_id',
  756. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  757. ->get();
  758. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  759. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  760. $websiteIds = $web->pluck('website_id')->toArray();
  761. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  762. if($user_type == 0){
  763. throw new \Exception("用户类型不能为空");
  764. }
  765. if($user_type == 10000 ){
  766. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  767. $web = WebsiteCategory::where('category_id', $data['catid'])
  768. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  769. ->select('website_id',
  770. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  771. ->get();
  772. // 非核心站与核心站----显示时间-----间隔
  773. $time = 20;
  774. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  775. $waiting_interval = 5;
  776. $webArray = $web->toArray();
  777. if(empty($webArray)){
  778. throw new \Exception('网站分类不存在');
  779. }
  780. // 直接使用当前系统时间,不再强制添加8小时
  781. $now = date('Y-m-d H:i:s');
  782. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  783. // 检查 $item 对象是否有 is_core 属性
  784. if (!isset($item['is_core'])) {
  785. throw new \Exception('$item 对象缺少 is_core 属性');
  786. }
  787. // 当 is_core 为 2 时,则表示此网站不存在
  788. if ($item['is_core'] == 2) {
  789. return null;
  790. }else if($item['is_core'] == 1){
  791. // 当 is_core 为 1 时,则表示此网站是核心站
  792. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  793. }else{
  794. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  795. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  796. if ($item['is_core'] == 0) {
  797. $time += $waiting_interval;
  798. }
  799. }
  800. return [
  801. 'article_id' => $data['id'],
  802. 'website_id' => $item['website_id'],
  803. 'c_show_time' => $c_show_time,
  804. ];
  805. }, array_keys($webArray), $webArray)));
  806. if(!empty($article_ignore)){
  807. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  808. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  809. $article_ignores = ArticleIgnore::upsert(
  810. $article_ignore,
  811. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  812. ['c_show_time'] // 需要更新的字段
  813. );
  814. if(!$article_ignores){
  815. throw new \Exception('c端展示时间插入失败');
  816. }
  817. }
  818. // Db::commit();
  819. // return Result::success($article_ignore);
  820. }
  821. // ------c_show_time********up*******
  822. unset($data['user_type']);
  823. // unset($data['web_site_id']);
  824. unset($data['nav_add_pool_id']);
  825. try {
  826. //处理投票
  827. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  828. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  829. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  830. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  831. unset($data['is_survey']);
  832. unset($data['survey_name']);
  833. unset($data['suvey_array']);
  834. unset($data['website_id']);
  835. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  836. if ($data['hits'] == '') {
  837. $data['hits'] = 0;
  838. }
  839. if ($data['is_original'] == '') {
  840. $data['is_original'] = 0;
  841. }
  842. if ($data['status'] == '') {
  843. $data['status'] = 0;
  844. }
  845. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  846. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  847. $articleData = $data;
  848. unset($articleData['content']);
  849. unset($articleData['status_name']);
  850. unset($articleData['name']);
  851. unset($articleData['content']);
  852. unset($articleData['pid_arr']);
  853. unset($articleData['pid']);
  854. //自动处理缩略图、关键字、描述
  855. if ($articleData['imgurl'] == '') {
  856. //如果没有图,设置level=0
  857. $levelArr = json_decode($articleData['level'], true);
  858. var_dump($levelArr, '----------levelArr-----------1');
  859. //content中提取图片第一个图,正则提取
  860. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  861. preg_match_all($reg, $data['content'], $matches);
  862. if (isset($matches[1][0])) {
  863. //截取varchar240
  864. // 截取到第一个<
  865. $articleData['imgurl'] = $matches[1][0];
  866. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  867. $pos = strpos($articleData['imgurl'], '"');
  868. if ($pos !== false) {
  869. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  870. }
  871. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  872. //如果有图,设置level=3
  873. if (!in_array(3, $levelArr)) {
  874. $levelArr[] = 3;
  875. }
  876. $articleData['level'] = json_encode($levelArr);
  877. } else {
  878. if (!in_array(0, $levelArr)) {
  879. $levelArr[] = 0;
  880. }
  881. $articleData['level'] = json_encode($levelArr);
  882. }
  883. }
  884. var_dump($articleData['level'], '----------$articleData[level]----------1');
  885. if ($articleData['keyword'] == '') {
  886. //提取标题+内容中的关键词
  887. $articleData['keyword'] = $data['title'];
  888. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  889. Jieba::init(); // 初始化 jieba-php
  890. Finalseg::init();
  891. $segList = Jieba::cut($articleData['keyword']);
  892. $segList1 = array_slice($segList, 0, 8);
  893. $articleData['keyword'] = implode(',', $segList1);
  894. }
  895. if ($articleData['introduce'] == '') {
  896. //提取内容中的描述
  897. $content = $data['content'];
  898. // 去除 <style> 和 <script> 标签及其内容
  899. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  900. // 去除所有 HTML 标签
  901. $content = strip_tags($content);
  902. // 去除 HTML 实体
  903. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  904. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  905. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  906. // 去除多余空白
  907. $content = preg_replace('/\s+/u', '', $content);
  908. // 截取 100 个字符
  909. $articleData['introduce'] = mb_substr($content, 0, 100);
  910. }
  911. if ($articleData['status'] == 0) {
  912. $this->sendMessage([
  913. 'talk_type' => 100,
  914. 'title' => $articleData['title'],
  915. 'content' => '提交了审核',
  916. 'messageType' => 2,
  917. ]);
  918. }
  919. $id = Article::where(['id' => $data['id']])->update($articleData);
  920. $articleDataContent = [
  921. 'content' => $data['content'],
  922. ];
  923. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  924. //处理投票
  925. $id = $data['id'];
  926. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  927. var_dump($suvey_array, 'suvey_array________delete');
  928. //处理投票
  929. if ($is_survey == 1) {
  930. //生成年月日时分秒+8位随机数
  931. $uuid = date('YmdHis') . rand(10000000, 99999999);
  932. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  933. var_dump($suveys_array, '---------------------1');
  934. $suvey_data = [];
  935. if (is_array($suveys_array)) {
  936. foreach ($suveys_array as $key => $value) {
  937. if ($value == '') {
  938. continue;
  939. }
  940. if (is_array($value)) {
  941. $suvey_data[] = [
  942. 'sur_id' => $uuid,
  943. 'art_id' => $id,
  944. 'website_id' => $website_id ?? 2,
  945. 'survey_name' => $survey_name,
  946. 'choice_name' => $value[1],
  947. 'is_other' => 1,
  948. 'other_id' => 0,
  949. 'results' => 0,
  950. ];
  951. } else {
  952. $suvey_data[] = [
  953. 'sur_id' => $uuid,
  954. 'art_id' => $id,
  955. 'website_id' => $website_id ?? 2,
  956. 'survey_name' => $survey_name,
  957. 'choice_name' => $value,
  958. 'is_other' => 0,
  959. 'other_id' => 0,
  960. 'results' => 0,
  961. ];
  962. }
  963. if (empty($suvey_data)) {
  964. throw new \Exception("投票数据为空");
  965. }
  966. }
  967. }
  968. $result = ArticleSurvey::insert($suvey_data);
  969. if (!$result) {
  970. throw new \Exception("投票失败");
  971. }
  972. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  973. if (!$result) {
  974. throw new \Exception("投票失败");
  975. }
  976. } else {
  977. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  978. }
  979. Db::commit();
  980. return Result::success([]);
  981. } catch (\Throwable $ex) {
  982. Db::rollBack();
  983. var_dump($ex->getMessage());
  984. return Result::error("更新失败" . $ex->getMessage(), 0);
  985. }
  986. }
  987. /**
  988. * 更新资讯状态
  989. * @param array $data
  990. * @return array
  991. */
  992. public function upArticleStatus(array $data): array
  993. {
  994. $articleData = Article::where(['id' => $data['id']])->first();
  995. //发送10次
  996. // for ($i = 0; $i < 10; $i++) {
  997. // $this->sendMessage([
  998. // 'talk_type' => 100,
  999. // 'title' => $i . $articleData['title'],
  1000. // 'content' => '审核通过',
  1001. // 'messageType' => 2,
  1002. // 'user_id' => $articleData['admin_user_id'],
  1003. // ]);
  1004. // }
  1005. // var_dump($data['status'], 'status');
  1006. // return Result::success();
  1007. if ($data['status'] == 1) {
  1008. $this->sendMessage([
  1009. 'talk_type' => 101,
  1010. 'title' => $articleData['title'],
  1011. 'content' => '审核通过',
  1012. 'messageType' => 2,
  1013. 'user_id' => $articleData['admin_user_id'],
  1014. ]);
  1015. }
  1016. if ($data['status'] == 2) {
  1017. $this->sendMessage([
  1018. 'talk_type' => 101,
  1019. 'title' => $articleData['title'],
  1020. 'content' => '审核拒绝',
  1021. 'messageType' => 2,
  1022. 'user_id' => $articleData['admin_user_id'],
  1023. ]);
  1024. }
  1025. if ($data['status'] == 0) {
  1026. $this->sendMessage([
  1027. 'talk_type' => 100,
  1028. 'title' => $articleData['title'],
  1029. 'content' => '提交了审核',
  1030. 'messageType' => 2,
  1031. ]);
  1032. }
  1033. $result = Article::where(['id' => $data['id']])->update($data);
  1034. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  1035. //article_ignore 表插入数据 db操作
  1036. //转成数组
  1037. //删掉数据重新写入
  1038. // DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  1039. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1040. // $insert_data = [];
  1041. // foreach ($website_ids as $key => $value) {
  1042. // $insert_data[] = [
  1043. // 'article_id' => $data['id'],
  1044. // 'website_id' => $value,
  1045. // 'is_ignore' => 1
  1046. // ];
  1047. // }
  1048. DB::table('article_ignore')->where('article_id', $data['id'])
  1049. ->when(!empty($website_ids), function ($query) use ($website_ids) {
  1050. $query->whereIn('website_id', $website_ids);
  1051. })
  1052. ->update(['is_ignore' => !empty($website_ids) ? 1 : 0]);
  1053. // ------c_show_time********up_status*******
  1054. // 若是审核通过 则更新c_show_time
  1055. if($data['status'] == 1){
  1056. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1057. $web = Article::where('article.id',$data['id'])
  1058. ->leftJoin('website_category','article.catid','website_category.category_id')
  1059. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1060. ->select('website_id',
  1061. 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'))
  1062. ->get();
  1063. // 非核心站与核心站----显示时间-----间隔
  1064. $time = 20;
  1065. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1066. $waiting_interval = 5;
  1067. $webArray = $web->toArray();
  1068. if(empty($webArray)){
  1069. throw new \Exception('网站分类不存在');
  1070. }
  1071. // 直接使用当前系统时间,不再强制添加8小时
  1072. $now = date('Y-m-d H:i:s');
  1073. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1074. // 检查 $item 对象是否有 is_core 属性
  1075. if (!isset($item['is_core'])) {
  1076. throw new \Exception('$item 对象缺少 is_core 属性');
  1077. }
  1078. // 当 is_core 为 2 时,则表示此网站不存在
  1079. if ($item['is_core'] == 2) {
  1080. return null;
  1081. }else if($item['is_core'] == 1){
  1082. // 当 is_core 为 1 时,则表示此网站是核心站
  1083. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  1084. }else{
  1085. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1086. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1087. if ($item['is_core'] == 0) {
  1088. $time += $waiting_interval;
  1089. }
  1090. }
  1091. return [
  1092. 'article_id' => $data['id'],
  1093. 'website_id' => $item['website_id'],
  1094. 'c_show_time' => $c_show_time,
  1095. ];
  1096. }, array_keys($webArray), $webArray)));
  1097. if(!empty($article_ignore)){
  1098. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1099. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1100. $article_ignores = ArticleIgnore::upsert(
  1101. $article_ignore,
  1102. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1103. ['c_show_time'] // 需要更新的字段
  1104. );
  1105. if(!$article_ignores){
  1106. throw new \Exception('c端展示时间插入失败');
  1107. }
  1108. }
  1109. }
  1110. // ------c_show_time********up_status*******
  1111. }
  1112. if ($result) {
  1113. return Result::success();
  1114. } else {
  1115. return Result::error("更新状态失败", 0);
  1116. }
  1117. }
  1118. /**
  1119. * 获取新闻详情
  1120. * @param array $data
  1121. * @return array
  1122. */
  1123. public function getArticleInfo(array $data): array
  1124. {
  1125. $where = [
  1126. 'article.id' => $data['id'],
  1127. // 'article.status' => 1,
  1128. ];
  1129. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1130. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1131. $info = $result;
  1132. // var_dump($info, 'info');
  1133. $info['survey_array'] = $articleSurvey;
  1134. if ($result) {
  1135. return Result::success($info);
  1136. } else {
  1137. return Result::error("查询失败", 0);
  1138. }
  1139. }
  1140. /**
  1141. * 获取头条新闻
  1142. * @param array $data
  1143. * @return array
  1144. */
  1145. public function getWebsiteArticlett(array $data): array
  1146. {
  1147. $website_id = $data['website_id'];
  1148. $website = Website::where('id', $data['website_id'])->first();
  1149. if (empty($website)) {
  1150. return Result::error("网站不存在", 0);
  1151. }
  1152. $categorys = $this->processArticlePro($website_id);
  1153. $catiall = $categorys['catiall'];
  1154. $categoryIds = $categorys['categoryIds'];
  1155. $where = [
  1156. 'status' => 1
  1157. ];
  1158. // $website_column = $website['column'];
  1159. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1160. $website_column = json_decode($website['website_column_arr_id'], true);
  1161. }
  1162. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1163. // return Result::success($diff_pid_categoryIds);
  1164. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1165. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1166. }
  1167. // $website_id = $data['website_id'];
  1168. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1169. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1170. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1171. switch ($data['level']) {
  1172. case 1:
  1173. case 2:
  1174. case 3:
  1175. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1176. $query = Article::where($where)
  1177. ->where('level', 'like', '%' . $data['level'] . '%')
  1178. ->orderBy('updated_at', 'desc');
  1179. break;
  1180. case 4: //最新资讯
  1181. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1182. break;
  1183. case 5: //资讯推荐
  1184. $query = Article::where($where)
  1185. ->where('updated_at', '>', $month);
  1186. break;
  1187. case 7: //资讯分类
  1188. if (isset($data['id']) && !empty($data['id'])) {
  1189. $keyword = Article::where('id', $data['id'])->value('keyword');
  1190. $keywordArray = explode(',', $keyword);
  1191. $whereL7 = [];
  1192. foreach ($keywordArray as $k => $v) {
  1193. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1194. }
  1195. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1196. break;
  1197. } else {
  1198. return Result::error("请输入资讯ID", 0);
  1199. break;
  1200. }
  1201. default:
  1202. break;
  1203. }
  1204. // $whereL7 = [];
  1205. // if(isset($data['id']) && !empty($data['id'])){
  1206. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1207. // $keywordArray = explode(',', $keyword);
  1208. // foreach ($keywordArray as $k => $v) {
  1209. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1210. // }
  1211. // }
  1212. // $query = Article::where($where)
  1213. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1214. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1215. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1216. // }
  1217. // if($data['level'] == 7){
  1218. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1219. // }
  1220. // if($data['level'] == 4){
  1221. // $query = $query->inRandomOrder()
  1222. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1223. // }
  1224. // if($data['level'] == 5){
  1225. // $query = $query->orderBy('updated_at','desc');
  1226. // }
  1227. // });
  1228. if ($data['textnum'] > 0) {
  1229. $query = clone $query;
  1230. $result['text'] = $query
  1231. ->whereIn('catid', $categoryIds)
  1232. ->leftJoinSub(function ($query) use ($website_id) {
  1233. $query->from('article_ignore')
  1234. ->where('website_id', $website_id);
  1235. }, 'article_ignore', function ($join) {
  1236. $join->on('article_ignore.article_id', '=', 'article.id');
  1237. })
  1238. ->where(function ($query) {
  1239. $query->whereNull('article_ignore.article_id')
  1240. ->orWhere(function ($subQuery) {
  1241. $subQuery->whereNotNull('article_ignore.article_id')
  1242. ->where('article_ignore.is_ignore', 0)
  1243. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1244. });
  1245. })
  1246. // ->where(function ($query) use ($website_id) {
  1247. // $query->whereNull('article_ignore.article_id')
  1248. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1249. // })
  1250. ->select(
  1251. 'article.id',
  1252. 'article.title',
  1253. 'article.author',
  1254. 'article.updated_at',
  1255. 'article.introduce',
  1256. 'article.islink',
  1257. 'article.linkurl',
  1258. 'article.copyfrom',
  1259. 'article.cat_arr_id',
  1260. 'article.catid',
  1261. 'article.level',
  1262. // 'article_ignore.is_ignore',
  1263. // 'article_ignore.c_show_time',
  1264. )
  1265. ->offset($data['placeid'])
  1266. ->limit($data['textnum'])
  1267. ->get()->all();
  1268. foreach ($result['text'] as $k => $v) {
  1269. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1270. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1271. }
  1272. }
  1273. if ($data['imgnum'] > 0) {
  1274. $query = clone $query;
  1275. $result['img'] = $query
  1276. ->whereIn('catid', $categoryIds)
  1277. ->where('article.imgurl', '!=', '')
  1278. ->select(
  1279. 'article.id',
  1280. 'article.title',
  1281. 'article.imgurl',
  1282. 'article.author',
  1283. 'article.updated_at',
  1284. 'article.introduce',
  1285. 'article.islink',
  1286. 'article.linkurl',
  1287. 'article.copyfrom',
  1288. 'article.cat_arr_id',
  1289. 'article.catid',
  1290. 'article.level',
  1291. // 'article_ignore.is_ignore',
  1292. // 'article_ignore.c_show_time',
  1293. )
  1294. ->offset($data['placeid'])
  1295. ->limit($data['imgnum'])
  1296. ->get()->all();
  1297. foreach ($result['img'] as $k => $v) {
  1298. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1299. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1300. }
  1301. }
  1302. if (empty($result)) {
  1303. return Result::error("暂无相关资讯", 0);
  1304. }
  1305. return Result::success($result);
  1306. }
  1307. /**
  1308. * 获取模块新闻
  1309. * @param array $data
  1310. * @return array
  1311. */
  1312. public function getWebsiteModelArticles(array $data): array
  1313. {
  1314. $catid = $data['catid'];
  1315. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1316. $category = $category->toArray();
  1317. if (!empty($category)) {
  1318. $where = [
  1319. 'status' => 1,
  1320. 'catid' => $catid,
  1321. ];
  1322. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1323. // 1:文字新闻;2:轮播图;3:图文;
  1324. // 级别:0:未分类
  1325. // 3:推荐图片
  1326. if ($data['level'] == 1) {
  1327. $data['level'] = 0;
  1328. }
  1329. $result = Article::where($where)
  1330. ->where(function ($query) use ($data) {
  1331. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1332. ->orWhereNull("level")
  1333. ->orWhereRaw("level = '[]'");
  1334. })
  1335. ->leftJoinSub(function ($query) use ($data) {
  1336. $query->from('article_ignore')
  1337. ->where('website_id', $data['website_id']);
  1338. }, 'article_ignore', function ($join) {
  1339. $join->on('article_ignore.article_id', '=', 'article.id');
  1340. })
  1341. ->where(function ($query) {
  1342. $query->whereNull('article_ignore.article_id')
  1343. ->orWhere(function ($subQuery) {
  1344. $subQuery->whereNotNull('article_ignore.article_id')
  1345. ->where('article_ignore.is_ignore', 0)
  1346. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1347. });
  1348. })
  1349. // ->where(function ($query) use ($data) {
  1350. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1351. // ->orWhereNull("ignore_ids");
  1352. // })
  1353. ->orderBy("updated_at", "desc")
  1354. ->offset($placeid)
  1355. ->limit($data['pagesize'])
  1356. ->get();
  1357. if (empty($result)) {
  1358. return Result::error("此栏目暂无相关新闻", 0);
  1359. }
  1360. } else {
  1361. return Result::error("此网站暂无此栏目", 0);
  1362. }
  1363. return Result::success($result);
  1364. }
  1365. /**
  1366. *获取新闻列表
  1367. * @param array $data
  1368. * @return array
  1369. */
  1370. public function getWebsiteArticleList(array $data): array
  1371. {
  1372. // return Result::success($data);
  1373. $where[] = ['status', '=', 1];
  1374. $website_id = $data['website_id'];
  1375. $website = Website::where('id', $data['website_id'])->first();
  1376. if (empty($website)) {
  1377. return Result::error("网站不存在", 0);
  1378. }
  1379. // $website_column = $website['column'];
  1380. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1381. $website_column = json_decode($website['website_column_arr_id'], true);
  1382. }
  1383. $categorys = $this->processArticlePro($website_id);
  1384. $cat_1st_arr = $categorys['cat_1st_arr'];
  1385. $catiall = $categorys['catiall'];
  1386. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1387. // return Result::success($diff_pid_categoryIds);
  1388. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1389. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1390. }
  1391. if (isset($data['catid']) && !empty($data['catid'])) {
  1392. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1393. if (empty($category)) {
  1394. return Result::error("此网站暂无此栏目", 0);
  1395. }
  1396. array_push($where, ['catid', '=', $data['catid']]);
  1397. }
  1398. // return Result::success($where);
  1399. $query = Article::where($where)
  1400. ->leftJoinSub(function ($query) use ($website_id) {
  1401. $query->from('article_ignore')
  1402. ->where('website_id', $website_id);
  1403. }, 'article_ignore', function ($join) {
  1404. $join->on('article_ignore.article_id', '=', 'article.id');
  1405. })
  1406. ->where(function ($query) {
  1407. $query->whereNull('article_ignore.article_id')
  1408. ->orWhere(function ($subQuery) {
  1409. $subQuery->whereNotNull('article_ignore.article_id')
  1410. ->where('article_ignore.is_ignore', 0)
  1411. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1412. });
  1413. })
  1414. ->select(
  1415. 'article.id',
  1416. 'article.title',
  1417. 'article.imgurl',
  1418. 'article.author',
  1419. 'article.updated_at',
  1420. 'article.introduce',
  1421. 'article.islink',
  1422. 'article.linkurl',
  1423. 'article.copyfrom',
  1424. 'article.cat_arr_id',
  1425. 'article.catid'
  1426. );
  1427. $count = $query->count();
  1428. $rep = $query->orderBy("updated_at", "desc")
  1429. ->offset(($data['page'] - 1) * $data['pageSize'])
  1430. ->limit($data['pageSize'])
  1431. ->get()->all();
  1432. $categorys = $this->processArticlePro($website_id);
  1433. $cat_1st_arr = $categorys['cat_1st_arr'];
  1434. $catiall = $categorys['catiall'];
  1435. // $web['website_id'] = $data['website_id'];
  1436. foreach ($rep as $k => $v) {
  1437. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1438. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1439. }
  1440. // $rep = $this->processArticles($rep,$web);
  1441. $data = [
  1442. 'rows' => $rep,
  1443. 'count' => $count,
  1444. ];
  1445. if (empty($rep)) {
  1446. return Result::error("没有信息数据");
  1447. }
  1448. return Result::success($data);
  1449. }
  1450. /**
  1451. * 前端-获取新闻详情
  1452. * @param array $data
  1453. * @return array
  1454. */
  1455. public function selectWebsiteArticleInfo(array $data): array
  1456. {
  1457. $where = [
  1458. 'article.id' => $data['id'],
  1459. 'article.status' => 1,
  1460. ];
  1461. $result = Article::where($where)
  1462. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1463. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1464. // ->where(function ($query) use ($data) {
  1465. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1466. // ->orWhereNull("ignore_ids");
  1467. // })
  1468. ->leftJoinSub(function ($query) use ($data) {
  1469. $query->from('article_ignore')
  1470. ->where('website_id', $data['website_id']);
  1471. }, 'article_ignore', function ($join) {
  1472. $join->on('article_ignore.article_id', '=', 'article.id');
  1473. })
  1474. ->where(function ($query) {
  1475. $query->whereNull('article_ignore.article_id')
  1476. ->orWhere(function ($subQuery) {
  1477. $subQuery->whereNotNull('article_ignore.article_id')
  1478. ->where('article_ignore.is_ignore', 0)
  1479. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1480. });
  1481. })
  1482. ->select(
  1483. 'article.*',
  1484. 'article_data.content',
  1485. 'article_data.article_id',
  1486. 'article_extend.website_url',
  1487. 'article_extend.email',
  1488. 'article_extend.contacts',
  1489. 'article_extend.contacts_mobile',
  1490. 'article_extend.contacts_address',
  1491. 'article_extend.zip_code',
  1492. 'article_extend.enterprise_name'
  1493. )
  1494. ->first();
  1495. if (empty($result)) {
  1496. return Result::error("暂无此新闻!", 0);
  1497. }
  1498. if (!empty($result['publiced_at'])) {
  1499. $result['updated_at'] = $result['publiced_at'];
  1500. }
  1501. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1502. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1503. ->where('website_category.website_id', $data['website_id'])
  1504. ->where(['website_category.category_id' => $result['catid']])
  1505. ->first();
  1506. if (empty($category)) {
  1507. return Result::error("查询失败", 0);
  1508. }
  1509. //手动推荐文章
  1510. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1511. if (empty($commend_ids)) {
  1512. $commendArticle = [];
  1513. } else {
  1514. //去除不存在的文章ID
  1515. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1516. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1517. ->leftJoinSub(function ($query) use ($data) {
  1518. $query->from('article_ignore')
  1519. ->where('website_id', $data['website_id']);
  1520. }, 'article_ignore', function ($join) {
  1521. $join->on('article_ignore.article_id', '=', 'article.id');
  1522. })
  1523. ->where(function ($query) {
  1524. $query->whereNull('article_ignore.article_id')
  1525. ->orWhere(function ($subQuery) {
  1526. $subQuery->whereNotNull('article_ignore.article_id')
  1527. ->where('article_ignore.is_ignore', 0)
  1528. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1529. });
  1530. })
  1531. ->where('article.status', 1)
  1532. ->where('website_category.website_id', $data['website_id'])
  1533. ->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')
  1534. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1535. // ->orderBy('article.updated_at', 'desc')
  1536. ->limit(5)
  1537. ->get();
  1538. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1539. foreach ($commendArticle as $k => $v) {
  1540. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1541. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1542. $cat_arr_id = array_unique($cat_arr_id);
  1543. // 从website_category取出alias_pinyin
  1544. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1545. ->whereIn('category_id', $cat_arr_id)
  1546. ->pluck('alias_pinyin', 'category_id')
  1547. ->toArray();
  1548. // 将cat_arr_id的json转成路径/隔开
  1549. $path_parts = [];
  1550. foreach ($cat_arr_id as $cat_id) {
  1551. if (isset($cat_arr[$cat_id])) {
  1552. $path_parts[] = $cat_arr[$cat_id];
  1553. }
  1554. }
  1555. $v->alias_pinyin = implode('/', $path_parts);
  1556. } else {
  1557. $v->alias_pinyin = '';
  1558. }
  1559. }
  1560. }
  1561. $result['category_id'] = $category['category_id'];
  1562. $result['cat_name'] = $category['alias'];
  1563. $result['website_name'] = $category['website_name'] ?? "";
  1564. $result['suffix'] = $category['suffix'] ?? "";
  1565. $result['commendArticle'] = $commendArticle;
  1566. $result['commend_ids'] = $commend_ids;
  1567. return Result::success($result);
  1568. }
  1569. /**
  1570. * 前端-获取网站调查问卷
  1571. * @param array $data
  1572. * @return array
  1573. */
  1574. public function getWebsiteSurvey(array $data): array
  1575. {
  1576. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1577. $website = Website::where('id', $data['website_id'])->first();
  1578. if (empty($website)) {
  1579. return Result::error("暂无此网站", 0);
  1580. }
  1581. }
  1582. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1583. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1584. if (empty($article)) {
  1585. return Result::error("暂无此文章", 0);
  1586. }
  1587. // return Result::error($data,0);
  1588. $where['art_id'] = $data['art_id'];
  1589. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1590. } else {
  1591. $survey = Article::where(function ($query) {
  1592. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1593. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1594. })
  1595. ->where('status', 1)
  1596. ->where('is_survey', 1)
  1597. ->select('survey_id')
  1598. ->orderBy('updated_at', 'desc')
  1599. ->first();
  1600. if (empty($survey)) {
  1601. return Result::error("暂无调查问卷", 0);
  1602. }
  1603. $where['sur_id'] = $survey['survey_id'];
  1604. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1605. }
  1606. // return Result::success($where);
  1607. $result = ArticleSurvey::where($where)
  1608. ->where(function ($query) {
  1609. $query->where('is_other', 0)
  1610. ->orWhere(function ($subQuery) {
  1611. $subQuery->where('is_other', 1)
  1612. ->where('other_id', 0);
  1613. });
  1614. })
  1615. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1616. ->select('article_survey.*', 'article.survey_type')
  1617. ->get()->all();
  1618. if (empty($result)) {
  1619. return Result::error("此文章暂无调查问卷", 0);
  1620. }
  1621. return Result::success($result);
  1622. }
  1623. /**
  1624. * 前端-添加网站调查问卷选项
  1625. * @param array $data
  1626. * @return array
  1627. */
  1628. public function addWebsiteSurveyOption(array $data): array
  1629. {
  1630. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1631. $website = Website::where('id', $data['website_id'])->first();
  1632. if (empty($website)) {
  1633. return Result::error("暂无此网站", 0);
  1634. }
  1635. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1636. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1637. if (empty($survey)) {
  1638. return Result::error("此调查问卷不可添加选项", 0);
  1639. }
  1640. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1641. $choice = [
  1642. 'art_id' => $survey['art_id'],
  1643. 'website_id' => $data['website_id'],
  1644. 'survey_name' => $survey['survey_name'],
  1645. 'choice_name' => $data['choice_name'],
  1646. 'sur_id' => $survey['sur_id'],
  1647. 'is_other' => 1,
  1648. 'other_id' => $survey['id'],
  1649. ];
  1650. $result = ArticleSurvey::insertGetId($choice);
  1651. if (empty($result)) {
  1652. return Result::error("添加失败", 0);
  1653. }
  1654. return Result::success($result);
  1655. }
  1656. }
  1657. return Result::error("添加失败", 0);
  1658. }
  1659. return Result::error("添加失败", 0);
  1660. }
  1661. /**
  1662. * 前端-调查问卷投票
  1663. * @param array $data
  1664. * @return array
  1665. */
  1666. public function addWebsiteSurveyVote(array $data): array
  1667. {
  1668. // return Result::success($data);
  1669. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1670. $website = Website::where('id', $data['website_id'])->first();
  1671. if (empty($website)) {
  1672. return Result::error("暂无此网站", 0);
  1673. }
  1674. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1675. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1676. // return Result::success($survey);
  1677. if (empty($is_survey)) {
  1678. return Result::error("此调查问卷不存在", 0);
  1679. }
  1680. // return Result::success($survey);
  1681. // 调查问卷类型
  1682. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1683. //多选 若是json型则转化成数组类型
  1684. if (strpos($data['choice_id'], '[') === 0) {
  1685. $data['choice_id'] = json_decode($data['choice_id'], true);
  1686. } else {
  1687. // 单选 也转换成数组
  1688. $data['choice_id'] = [$data['choice_id']];
  1689. }
  1690. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1691. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1692. // ->where('website_id',$data['website_id'])
  1693. ->where('is_other', 1)
  1694. ->where('other_id', 0)
  1695. ->first();
  1696. if (!empty($other)) {
  1697. return Result::error("请选择已有的选项!", 0);
  1698. }
  1699. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1700. // ->where('website_id',$data['website_id'])
  1701. ->where('is_other', 1)
  1702. ->where('other_id', '!=', 0)
  1703. ->first();
  1704. // return Result::success($choice['other']);
  1705. $choice_id = $data['choice_id'];
  1706. if (!empty($choice['other'])) {
  1707. // array_push($data['choice_id'],$choice['other']['other_id']);
  1708. if (!empty($choice_id)) {
  1709. $key = array_search($choice['other']['id'], $choice_id);
  1710. if ($key !== false) {
  1711. unset($choice_id[$key]);
  1712. $choice_id = array_values($choice_id);
  1713. }
  1714. array_push($choice_id, $choice['other']['other_id']);
  1715. } else {
  1716. $choice_id[0] = $choice['other']['other_id'];
  1717. }
  1718. array_push($data['choice_id'], $choice['other']['other_id']);
  1719. }
  1720. // return Result::success($data);
  1721. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1722. // ->where('website_id',$data['website_id'])
  1723. ->increment('results', 1);
  1724. if (empty($choice)) {
  1725. return Result::error("请选择已有的选项!", 0);
  1726. }
  1727. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1728. // ->where('website_id',$data['website_id'])
  1729. ->where('other_id', 0)
  1730. ->get();
  1731. $survey['choice'] = $choice_id;
  1732. return Result::success($survey);
  1733. }
  1734. return Result::error("参数必填!");
  1735. }
  1736. return Result::error("此调查问卷不存在", 0);
  1737. }
  1738. return Result::error("参数必填!");
  1739. }
  1740. /**
  1741. * 后端-获取网站调查问卷列表
  1742. * @param array $data
  1743. * @return array
  1744. */
  1745. public function getSurveyList(array $data): array
  1746. {
  1747. $where = [];
  1748. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1749. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1750. }
  1751. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1752. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1753. }
  1754. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1755. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1756. }
  1757. // return Result::success($where);
  1758. if (!empty($where)) {
  1759. $query = Article::where($where)->where(function ($q) {
  1760. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1761. });
  1762. } else {
  1763. $query = Article::where(function ($q) {
  1764. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1765. });
  1766. }
  1767. $count = $query->count();
  1768. $survey = $query->orderByDesc('id')
  1769. ->limit($data['pageSize'])
  1770. ->offset(($data['page'] - 1) * $data['pageSize'])
  1771. ->get();
  1772. if (empty($survey->toArray())) {
  1773. return Result::error("暂无调查问卷!", 0);
  1774. }
  1775. $result = [
  1776. 'rows' => $survey,
  1777. 'count' => $count,
  1778. ];
  1779. return Result::success($result);
  1780. }
  1781. /**
  1782. * 后端-获取网站调查问卷详情
  1783. * @param array $data
  1784. * @return array
  1785. */
  1786. public function getSurveyInfo(array $data): array
  1787. {
  1788. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1789. $where = ['sur_id' => $data['sur_id']];
  1790. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1791. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1792. ->select('article_survey.*', 'article.survey_type')
  1793. ->get()->all();
  1794. if (empty($choose)) {
  1795. return Result::error("此调查问卷不存在", 0);
  1796. }
  1797. $resultsArray = array_column($choose, 'results');
  1798. $total = array_sum($resultsArray);
  1799. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1800. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1801. // $total = 0;
  1802. if (!empty($other)) {
  1803. $total = $total + $other['results'];
  1804. $other['choice_name'] = '(其他)';
  1805. if (!empty($others)) {
  1806. $other['hasChildren'] = true;
  1807. // array_push($other,['hasChildren','=',true]);
  1808. $other['children'] = $others;
  1809. $other_choices = [$other->toArray()];
  1810. $mer_choice = array_merge($choose, $other_choices);
  1811. $value_choice = array_values($mer_choice);
  1812. } else {
  1813. // return Result::error('1111');
  1814. $other_choices = [$other->toArray()];
  1815. $other_choices = array_merge($choose, $other_choices);
  1816. $value_choice = array_values($other_choices);
  1817. // return Result::success($result);
  1818. }
  1819. } else {
  1820. $value_choice = $choose;
  1821. }
  1822. $result = [
  1823. 'choose' => $value_choice,
  1824. 'total' => $total,
  1825. ];
  1826. }
  1827. return Result::success($result);
  1828. }
  1829. /**
  1830. * 前端-搜索新闻列表
  1831. * @param array $data
  1832. * @return array
  1833. */
  1834. public function selectWebsiteArticle(array $data): array
  1835. {
  1836. $website = Website::where('id', $data['website_id'])->first();
  1837. if (empty($website)) {
  1838. return Result::error("网站不存在", 0);
  1839. }
  1840. // $website_column = $website['column'];
  1841. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1842. $website_column = json_decode($website['website_column_arr_id'], true);
  1843. }
  1844. $website_id = $data['website_id'];
  1845. $categorys = $this->processArticlePro($website_id);
  1846. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1847. // return Result::success($diff_pid_categoryIds);
  1848. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1849. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1850. }
  1851. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1852. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1853. $catiall = $categorys['catiall'];
  1854. $categoryIds = $categorys['categoryIds'];
  1855. // return Result::success($categoryIds);
  1856. $query = Article::where('status', 1)
  1857. ->whereIn('catid', $categoryIds)
  1858. ->leftJoinSub(function ($query) use ($website_id) {
  1859. $query->from('article_ignore')
  1860. ->where('website_id', $website_id);
  1861. }, 'article_ignore', function ($join) {
  1862. $join->on('article_ignore.article_id', '=', 'article.id');
  1863. })
  1864. ->where(function ($query) {
  1865. $query->whereNull('article_ignore.article_id')
  1866. ->orWhere(function ($subQuery) {
  1867. $subQuery->whereNotNull('article_ignore.article_id')
  1868. ->where('article_ignore.is_ignore', 0)
  1869. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1870. });
  1871. });
  1872. // ->get()->all();
  1873. // return Result::success($query);
  1874. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1875. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1876. }
  1877. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1878. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1879. }
  1880. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1881. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1882. }
  1883. // 计算总数
  1884. $count = $query->count();
  1885. // return Result::success($count);
  1886. // 分页查询
  1887. $articles = $query
  1888. ->select(
  1889. 'article.id',
  1890. 'article.title',
  1891. 'article.imgurl',
  1892. 'article.author',
  1893. 'article.updated_at',
  1894. 'article.introduce',
  1895. 'article.islink',
  1896. 'article.linkurl',
  1897. 'article.copyfrom',
  1898. 'article.cat_arr_id',
  1899. 'article.catid',
  1900. 'article.department_arr_id',
  1901. 'article.city_arr_id',
  1902. // 'article_ignore.c_show_time',
  1903. // 'article_ignore.is_ignore'
  1904. )
  1905. ->orderBy("updated_at", "desc")
  1906. ->offset(($data['page'] - 1) * $data['pageSize'])
  1907. ->limit($data['pageSize'])
  1908. ->get();
  1909. // return Result::success($articles);
  1910. foreach ($articles as $k => $v) {
  1911. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1912. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1913. }
  1914. if (empty($articles)) {
  1915. return Result::error("没有符合条件的资讯数据");
  1916. }
  1917. $result = [
  1918. 'rows' => $articles,
  1919. 'count' => $count,
  1920. ];
  1921. return Result::success($result);
  1922. }
  1923. /**
  1924. * 模块新闻加强版
  1925. * @param array $data
  1926. * @return array
  1927. */
  1928. public function getWebsiteCatidArticle(array $data): array
  1929. {
  1930. $where = [
  1931. 'website_category.category_id' => $data['catid'],
  1932. 'website_category.website_id' => $data['website_id'],
  1933. ];
  1934. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1935. $child_catnum = $data['child_catnum'] ?? 1;
  1936. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1937. $childCategoryIds = array_column($category['child'], 'category_id');
  1938. if (empty($childCategoryIds)) {
  1939. return Result::error("暂无子栏目", 0);
  1940. }
  1941. $imgArticles = [];
  1942. $textArticles = [];
  1943. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1944. // 初始化子分类图片新闻和文字新闻数组
  1945. // 查询所有子级栏目的图文新闻
  1946. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1947. ->where(function ($query) use ($data) {
  1948. $query->where(function ($subQuery) use ($data) {
  1949. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1950. })->orWhereNull("ignore_ids");
  1951. })
  1952. ->where('status', 1)
  1953. ->where('imgurl', '!=', '')
  1954. ->select('*')
  1955. ->orderBy('updated_at', 'desc')
  1956. ->limit($data['child_imgnum'])
  1957. ->get();
  1958. }
  1959. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1960. // 查询所有子级栏目的文字新闻
  1961. $textArticles = Article::where('catid', $childCategoryIds[0])
  1962. ->where('status', 1)
  1963. ->where(function ($query) use ($data) {
  1964. $query->where(function ($subQuery) use ($data) {
  1965. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1966. })->orWhereNull("ignore_ids");
  1967. })
  1968. ->select('*')
  1969. ->orderBy('updated_at', 'desc')
  1970. ->limit($data['child_textnum'])
  1971. ->get();
  1972. }
  1973. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1974. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1975. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1976. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1977. return $child;
  1978. }, $category['child']);
  1979. }
  1980. // }
  1981. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1982. $category['img'] = WebsiteCategory::where($where)
  1983. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1984. ->where('article.status', 1)
  1985. ->where('article.imgurl', '!=', '')
  1986. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1987. ->orderBy('article.updated_at', 'desc')
  1988. ->limit($data['img_num'])
  1989. ->get();
  1990. }
  1991. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1992. $category['text'] = WebsiteCategory::where($where)
  1993. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1994. ->where('article.status', 1)
  1995. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1996. ->orderBy('article.updated_at', 'desc')
  1997. ->limit($data['text_num'])
  1998. ->get();
  1999. }
  2000. // $category = $category->get();
  2001. if (empty($category)) {
  2002. return Result::error("查询失败", 0);
  2003. }
  2004. return Result::success($category);
  2005. }
  2006. /**
  2007. * 模块新闻加强plus版
  2008. * @param array $data
  2009. * @return array
  2010. */
  2011. public function getWebsiteAllArticle(array $data): array
  2012. {
  2013. // return Result::success($data);
  2014. $time1 = microtime(true);
  2015. $wetbsite_id = $data['website_id'] ?? 2;
  2016. $data = json_decode($data['id'], true);
  2017. $website = Website::where('id', $wetbsite_id)->first();
  2018. if (empty($website)) {
  2019. return Result::error("网站不存在", 0);
  2020. }
  2021. // return Result::success($website);
  2022. $website_column = $website['website_column_arr_id'] ?? '[]';
  2023. $website_column = json_decode($website_column, true);
  2024. $categorys = $this->processArticlePro($wetbsite_id);
  2025. $cat_1st_arr = $categorys['cat_1st_arr'];
  2026. $catiall = $categorys['catiall'];
  2027. // return Result::success($catiall);
  2028. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2029. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2030. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2031. }
  2032. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2033. // return Result::success($categorys);
  2034. $parent_category = array_column($data, 'parent');
  2035. $parent_cat = [];
  2036. $child_category = array_column($data, 'child');
  2037. if (!empty($parent_category)) {
  2038. foreach ($parent_category as $key => $value) {
  2039. $arr = array_map('intval', explode(',', $value));
  2040. $parent_cat[$key] = $arr[0] ?? 0;
  2041. $parent_category = $arr[0] ?? 0;
  2042. $article_imgnum = $arr[1] ?? 0;
  2043. $article_textnum = $arr[2] ?? 0;
  2044. if ($parent_category != 0) {
  2045. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2046. // return Result::success($category_arr);
  2047. if ($article_imgnum != 0) {
  2048. $img_article = Article::whereIn('catid', $category_arr)
  2049. ->where('status', 1)
  2050. ->where('imgurl', '!=', '')
  2051. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2052. $query->from('article_ignore')
  2053. ->where('website_id', $wetbsite_id);
  2054. }, 'article_ignore', function ($join) {
  2055. $join->on('article_ignore.article_id', '=', 'article.id');
  2056. })
  2057. ->where(function ($query) {
  2058. $query->whereNull('article_ignore.article_id')
  2059. ->orWhere(function ($subQuery) {
  2060. $subQuery->whereNotNull('article_ignore.article_id')
  2061. ->where('article_ignore.is_ignore', 0)
  2062. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2063. });
  2064. })
  2065. ->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')
  2066. ->orderBy('updated_at', 'desc')
  2067. ->limit($article_imgnum)
  2068. ->get()->all();
  2069. foreach ($img_article as $k => $v) {
  2070. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2071. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2072. }
  2073. } else {
  2074. $img_article = [];
  2075. }
  2076. if ($article_textnum != 0) {
  2077. $text_article = Article::whereIn('catid', $category_arr)
  2078. ->where('status', 1)
  2079. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2080. $query->from('article_ignore')
  2081. ->where('website_id', $wetbsite_id);
  2082. }, 'article_ignore', function ($join) {
  2083. $join->on('article_ignore.article_id', '=', 'article.id');
  2084. })
  2085. ->where(function ($query) {
  2086. $query->whereNull('article_ignore.article_id')
  2087. ->orWhere(function ($subQuery) {
  2088. $subQuery->whereNotNull('article_ignore.article_id')
  2089. ->where('article_ignore.is_ignore', 0)
  2090. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2091. });
  2092. })
  2093. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2094. ->orderBy('updated_at', 'desc')
  2095. ->limit($article_textnum)
  2096. ->get()->all();
  2097. foreach ($text_article as $k => $v) {
  2098. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2099. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2100. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2101. }
  2102. } else {
  2103. $text_article = [];
  2104. }
  2105. $catiall[$parent_category]['imgnum'] = $img_article;
  2106. $catiall[$parent_category]['textnum'] = $text_article;
  2107. $parent[$key] = $catiall[$parent_category];
  2108. } else {
  2109. $parent[$key] = '';
  2110. }
  2111. }
  2112. }
  2113. if (!empty($child_category)) {
  2114. foreach ($child_category as $key => $value) {
  2115. $arr = array_map('intval', explode(',', $value));
  2116. $parent_category = $parent_cat[$key];
  2117. $child_category = $arr[0] ?? 0;
  2118. $article_imgnum = $arr[1] ?? 0;
  2119. $article_textnum = $arr[2] ?? 0;
  2120. if ($child_category != 0) {
  2121. $all_childcat = $cat_1st_arr[$parent_category];
  2122. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2123. // 从 $websiteInfoIndexed 中获取对应的数据
  2124. $info = $websiteInfoIndexed[$v];
  2125. // 返回一个包含所需信息的数组
  2126. return [
  2127. 'alias' => $info->alias,
  2128. 'category_id' => $info->category_id,
  2129. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2130. 'pid' => $info->pid,
  2131. 'type' => $info->type,
  2132. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2133. 'pinyin' => $info->pinyin,
  2134. ];
  2135. }, $all_childcat);
  2136. if ($article_imgnum != 0) {
  2137. $img_article = Article::where('catid', $child_category)
  2138. ->where('status', 1)
  2139. ->where('imgurl', '!=', '')
  2140. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2141. $query->from('article_ignore')
  2142. ->where('website_id', $wetbsite_id);
  2143. }, 'article_ignore', function ($join) {
  2144. $join->on('article_ignore.article_id', '=', 'article.id');
  2145. })
  2146. ->where(function ($query) {
  2147. $query->whereNull('article_ignore.article_id')
  2148. ->orWhere(function ($subQuery) {
  2149. $subQuery->whereNotNull('article_ignore.article_id')
  2150. ->where('article_ignore.is_ignore', 0)
  2151. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2152. });
  2153. })
  2154. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2155. ->orderBy('updated_at', 'desc')
  2156. ->limit($article_imgnum)
  2157. ->get()->all();
  2158. foreach ($img_article as $k => $v) {
  2159. // var_dump($v);
  2160. // var_dump($k);
  2161. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2162. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2163. }
  2164. } else {
  2165. $img_article = [];
  2166. }
  2167. if ($article_textnum != 0) {
  2168. $text_article = Article::where('catid', $child_category)
  2169. ->where('status', 1)
  2170. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2171. $query->from('article_ignore')
  2172. ->where('website_id', $wetbsite_id);
  2173. }, 'article_ignore', function ($join) {
  2174. $join->on('article_ignore.article_id', '=', 'article.id');
  2175. })
  2176. ->where(function ($query) {
  2177. $query->whereNull('article_ignore.article_id')
  2178. ->orWhere(function ($subQuery) {
  2179. $subQuery->whereNotNull('article_ignore.article_id')
  2180. ->where('article_ignore.is_ignore', 0)
  2181. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2182. });
  2183. })
  2184. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2185. ->orderBy('updated_at', 'desc')
  2186. ->limit($article_textnum)
  2187. ->get()->all();
  2188. foreach ($text_article as $k => $v) {
  2189. // var_dump($v);
  2190. // var_dump($k);
  2191. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2192. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2193. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2194. }
  2195. } else {
  2196. $text_article = [];
  2197. }
  2198. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2199. $catiall[$child_category]['imgnum'] = $img_article;
  2200. $catiall[$child_category]['textnum'] = $text_article;
  2201. $child[$key] = $catiall[$child_category];
  2202. // var_dump($pids);
  2203. } else {
  2204. $child[$key] = '';
  2205. }
  2206. }
  2207. }
  2208. foreach ($parent as $key => $value) {
  2209. $result[$key] = $value;
  2210. if (!empty($child[$key])) {
  2211. // var_dump($child[$key]);
  2212. $result[$key]['child'] = $child[$key];
  2213. // $value[$key]['child'] = $child[$key];
  2214. } else {
  2215. $result[$key]['child'] = [
  2216. "alias" => null,
  2217. "category_id" => null,
  2218. "type" => null,
  2219. "pinyin" => null,
  2220. "all_childcat" => [],
  2221. "imgnum" => [],
  2222. "textnum" => []
  2223. ];
  2224. }
  2225. }
  2226. return Result::success($result);
  2227. }
  2228. /**
  2229. * 辅助方法:获取文章列表
  2230. */
  2231. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2232. {
  2233. sleep(1);
  2234. $query = Article::where('article.status', 1)
  2235. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2236. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2237. ->where(function ($query) use ($website) {
  2238. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2239. })
  2240. ->leftJoin('website_category', function ($join) use ($website) {
  2241. $join->on('article.catid', '=', 'website_category.category_id')
  2242. ->where('website_category.website_id', '=', $website['website_id']);
  2243. })
  2244. ->select(
  2245. 'article.id',
  2246. 'article.title',
  2247. 'article.imgurl',
  2248. 'article.author',
  2249. 'article.updated_at',
  2250. 'article.introduce',
  2251. 'article.islink',
  2252. 'article.linkurl',
  2253. 'article.copyfrom',
  2254. 'article.cat_arr_id',
  2255. 'article.catid',
  2256. 'website_category.alias as category_name'
  2257. )
  2258. ->orderBy('updated_at', 'desc')
  2259. ->limit($limit);
  2260. // 如果是图片文章,添加图片URL条件
  2261. if ($isImageArticle) {
  2262. $query->where('imgurl', '!=', '');
  2263. } else {
  2264. // 文字文章不需要imgurl字段
  2265. $query->addSelect('article.introduce');
  2266. }
  2267. $articles = $query->get();
  2268. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2269. }
  2270. /**
  2271. * 乡村网-获取特殊新闻模块
  2272. * @param array $data
  2273. * @return array
  2274. */
  2275. public function getWebsiteArticles(array $data): array
  2276. {
  2277. $website_id = $data['website_id'];
  2278. $website = Website::where('id', $website_id)->first();
  2279. if (empty($website)) {
  2280. return Result::error("网站不存在", 0);
  2281. }
  2282. // return Result::success($website);
  2283. $website_column = $website['website_column_arr_id'] ?? '[]';
  2284. $website_column = json_decode($website_column, true);
  2285. $catids = json_decode($data['id'], true);
  2286. $parent_category = array_column($catids, 'parent');
  2287. if (!empty($parent_category) && is_array($parent_category)) {
  2288. $categorys = $this->processArticlePro($website_id);
  2289. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2290. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2291. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2292. }
  2293. $catiall = $categorys['catiall'];
  2294. $cat_1st_arr = $categorys['cat_1st_arr'];
  2295. // return Result::success($categorys);
  2296. foreach ($parent_category as $key => $value) {
  2297. $arr = array_map('intval', explode(',', $value));
  2298. $parent_category = $arr[0] ?? 0;
  2299. $article_imgnum = $arr[1] ?? 0;
  2300. $article_textnum = $arr[2] ?? 0;
  2301. if ($parent_category != 0) {
  2302. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2303. // return Result::success($category_arr);
  2304. if ($article_imgnum != 0) {
  2305. $img_article = Article::whereIn('article.catid', $category_arr)
  2306. ->where('article.status', 1)
  2307. ->where('article.imgurl', '!=', '')
  2308. ->leftJoinSub(function ($query) use ($website_id) {
  2309. $query->from('article_ignore')
  2310. ->where('website_id', $website_id);
  2311. }, 'article_ignore', function ($join) {
  2312. $join->on('article_ignore.article_id', '=', 'article.id');
  2313. })
  2314. ->where(function ($query) {
  2315. $query->whereNull('article_ignore.article_id')
  2316. ->orWhere(function ($subQuery) {
  2317. $subQuery->whereNotNull('article_ignore.article_id')
  2318. ->where('article_ignore.is_ignore', 0)
  2319. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2320. });
  2321. })
  2322. ->select(
  2323. 'article.id',
  2324. 'article.title',
  2325. 'article.imgurl',
  2326. 'article.author',
  2327. 'article.updated_at',
  2328. 'article.introduce',
  2329. 'article.islink',
  2330. 'article.linkurl',
  2331. 'article.copyfrom',
  2332. 'article.cat_arr_id',
  2333. 'article.catid as category_id'
  2334. )
  2335. ->orderBy('updated_at', 'desc')
  2336. ->limit($article_imgnum)
  2337. ->get()->all();
  2338. foreach ($img_article as $k => $v) {
  2339. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2340. // return Result::success($v);
  2341. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2342. }
  2343. } else {
  2344. $img_article = [];
  2345. }
  2346. if ($article_textnum != 0) {
  2347. $text_article = Article::whereIn('article.catid', $category_arr)
  2348. ->where('article.status', 1)
  2349. ->leftJoinSub(function ($query) use ($website_id) {
  2350. $query->from('article_ignore')
  2351. ->where('website_id', $website_id);
  2352. }, 'article_ignore', function ($join) {
  2353. $join->on('article_ignore.article_id', '=', 'article.id');
  2354. })
  2355. ->where(function ($query) {
  2356. $query->whereNull('article_ignore.article_id')
  2357. ->orWhere(function ($subQuery) {
  2358. $subQuery->whereNotNull('article_ignore.article_id')
  2359. ->where('article_ignore.is_ignore', 0)
  2360. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2361. });
  2362. })
  2363. ->select(
  2364. 'article.id',
  2365. 'article.title',
  2366. 'article.author',
  2367. 'article.updated_at',
  2368. 'article.introduce',
  2369. 'article.islink',
  2370. 'article.linkurl',
  2371. 'article.copyfrom',
  2372. 'article.cat_arr_id',
  2373. 'article.catid as category_id'
  2374. )
  2375. ->orderBy('updated_at', 'desc')
  2376. ->limit($article_textnum)
  2377. ->get()->all();
  2378. foreach ($text_article as $k => $v) {
  2379. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2380. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2381. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2382. }
  2383. } else {
  2384. $text_article = [];
  2385. }
  2386. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2387. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2388. $parent[$key] = $catiall[$parent_category];
  2389. } else {
  2390. $parent[$key] = [];
  2391. }
  2392. }
  2393. }
  2394. return Result::success($parent);
  2395. }
  2396. // 封装处理商品的路由问题
  2397. function processGoods($goods, $data)
  2398. {
  2399. return $goods->map(function ($good) use ($data) {
  2400. $catid = $good->catid ?? 0;
  2401. // $pinyin = '';
  2402. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2403. if (!empty($category->pid) && $category->pid != 0) {
  2404. $level = json_decode($category->category_arr_id, true);
  2405. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2406. ->whereIn('category_id', $level)
  2407. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2408. ->get(['aLIas_pinyin'])
  2409. ->pluck('aLIas_pinyin')
  2410. ->implode('/');
  2411. } else {
  2412. $pinyin = $category->aLIas_pinyin ?? '';
  2413. }
  2414. if (isset($good->city_id) && !empty($good->city_id)) {
  2415. $city = District::where('id', $good->city_id)->first(['name']);
  2416. $good->city_name = $city->name ?? '';
  2417. }
  2418. // 解析imgurl JSON并取第一条数据
  2419. $imgUrls = json_decode($good->imgurl, true);
  2420. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2421. $good->pinyin = $pinyin;
  2422. return $good;
  2423. });
  2424. }
  2425. /**
  2426. * 获取商城首页-根据栏目id
  2427. * @param array $data
  2428. * @return array
  2429. * */
  2430. function getWebsiteCatidshop(array $data): array
  2431. {
  2432. $input['catid'] = $data['catid'];
  2433. $input['website_id'] = $data['website_id'];
  2434. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2435. $result = array_map(function ($item) use ($input) {
  2436. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2437. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2438. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2439. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2440. if (empty($category) || $category->type != 2) {
  2441. return Result::error("暂无此栏目", 0);
  2442. } else {
  2443. $website['website_id'] = $input['website_id'];
  2444. $goods = Good::where('good.status', 2)
  2445. ->where('good.website_id', $website['website_id'])
  2446. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2447. ->select(
  2448. 'good.id',
  2449. 'good.name',
  2450. 'good.imgurl',
  2451. 'good.description',
  2452. 'good.updated_at',
  2453. 'good.catid',
  2454. 'good.type_id',
  2455. 'good.price',
  2456. 'good.com',
  2457. 'good.level',
  2458. 'good.unit'
  2459. )
  2460. ->orderBy('updated_at', 'desc')
  2461. ->offset($goodStart)
  2462. ->limit($goodNum);
  2463. $all_goods = $goods->get();
  2464. $all_goods = $this->processGoods($all_goods, $website);
  2465. }
  2466. return $all_goods ?? [];
  2467. }
  2468. }, $data);
  2469. return Result::success($result);
  2470. }
  2471. /**
  2472. * 获取商品模块
  2473. * @param array $data
  2474. * @return array
  2475. * */
  2476. public function getWebsiteshop(array $data): array
  2477. {
  2478. $input['id'] = $data['id'];
  2479. $input['website_id'] = $data['website_id'];
  2480. $catid = $data['catid'];
  2481. $data = json_decode($input['id'] ?? '', true) ?? [];
  2482. $result['goods'] = array_map(function ($item) use ($input) {
  2483. // 检查parent元素是否存在且不是undefined
  2484. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2485. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2486. $website = $input['website_id'];
  2487. $query = Good::where('good.status', 2)
  2488. ->where('good.website_id', $website);
  2489. switch ($Levelid) {
  2490. case 1:
  2491. case 2:
  2492. case 3:
  2493. $goods = $query->where(function ($q) use ($Levelid) {
  2494. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2495. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2496. });
  2497. break;
  2498. case 4:
  2499. $goods = $query;
  2500. break;
  2501. case 5:
  2502. $goods = $query->where('type_id', 1);
  2503. break;
  2504. case 6:
  2505. $goods = $query->where('type_id', 2);
  2506. break;
  2507. default:
  2508. return [];
  2509. }
  2510. $all_goods = $goods
  2511. ->select(
  2512. 'good.id',
  2513. 'good.name',
  2514. 'good.imgurl',
  2515. 'good.description',
  2516. 'good.updated_at',
  2517. 'good.catid',
  2518. 'good.type_id',
  2519. 'good.price',
  2520. 'good.level',
  2521. 'good.website_id'
  2522. )
  2523. ->orderBy('updated_at', 'desc')
  2524. ->offset($goodStart)
  2525. ->limit($goodNum)
  2526. ->get();
  2527. $web['website_id'] = $website;
  2528. $all_goods = $this->processGoods($all_goods, $web);
  2529. }
  2530. return $all_goods;
  2531. }, $data);
  2532. $website = $input['website_id'];
  2533. $result['article'] = Article::where(function ($query) use ($website) {
  2534. $query->where(function ($subQuery) use ($website) {
  2535. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2536. })->orWhereNull("ignore_ids");
  2537. })
  2538. ->where('catid', $catid)
  2539. ->where('article.status', 1)
  2540. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2541. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2542. ->orderBy('article.updated_at', 'desc')
  2543. ->first();
  2544. return Result::success($result);
  2545. }
  2546. /**
  2547. * 获取商品分类
  2548. * @param array $data
  2549. * @return array
  2550. * */
  2551. public function getWebsiteshopCat(array $data): array
  2552. {
  2553. $website = $data['website_id'];
  2554. $category = WebsiteCategory::where('website_id', $website)
  2555. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2556. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2557. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2558. ->orderBy('sort')
  2559. ->get();
  2560. $cat = $category->map(function ($item) use ($website) {
  2561. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2562. $pid = $item->pid ?? 0;
  2563. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2564. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2565. ->where('website_id', $website)
  2566. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2567. ->get(['aLIas_pinyin'])
  2568. ->pluck('aLIas_pinyin')
  2569. ->implode('/');
  2570. } else {
  2571. $pinyin = $item->aLIas_pinyin ?? '';
  2572. }
  2573. $item->pinyin = $pinyin;
  2574. });
  2575. if (empty($category)) {
  2576. return Result::error("栏目查询失败", 0);
  2577. }
  2578. $cat_tree = Result::buildMenuTree($category);
  2579. $web['website_id'] = $website;
  2580. $goods = Good::where('website_id', $website)
  2581. ->where('status', 2)
  2582. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2583. ->latest('updated_at')
  2584. ->offset(($data['page'] - 1) * $data['pageSize'])
  2585. ->limit($data['pageSize'])
  2586. ->get();
  2587. if (!empty($goods)) {
  2588. if ($goods->count() > 1 && !empty($goods)) {
  2589. $goods = $this->processGoods($goods, $web);
  2590. }
  2591. } else {
  2592. $goods = [];
  2593. }
  2594. $result = [
  2595. 'category' => $cat_tree,
  2596. 'goods' => $goods,
  2597. ];
  2598. // $resul['goods'] = $goods;
  2599. if (empty($result)) {
  2600. return Result::error("查询失败", 0);
  2601. }
  2602. return Result::success($result);
  2603. }
  2604. /*
  2605. * 获取商品列表
  2606. * @param array $data
  2607. * @return array
  2608. * */
  2609. public function getWebsiteshopList(array $data): array
  2610. {
  2611. // return Result::success($data);
  2612. $where = [
  2613. 'status' => 2,
  2614. 'website_id' => $data['website_id'],
  2615. ];
  2616. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2617. // return Result::error("查询失败", 0);
  2618. // }
  2619. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2620. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2621. $data['catid'] = $category->category_id ?? 0;
  2622. }
  2623. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2624. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2625. }
  2626. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2627. array_push($where, ['type_id', $data['type_id']]);
  2628. }
  2629. $query = Good::where($where)
  2630. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2631. $query->where(function ($q) use ($data) {
  2632. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2633. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2634. });
  2635. })
  2636. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2637. $query->where(function ($q) use ($data) {
  2638. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2639. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2640. });
  2641. })
  2642. ->select(
  2643. 'good.id',
  2644. 'good.name',
  2645. 'good.imgurl',
  2646. 'good.description',
  2647. 'good.updated_at',
  2648. 'good.com',
  2649. 'good.catid',
  2650. 'good.type_id',
  2651. 'good.website_id',
  2652. 'good.cat_arr_id',
  2653. 'good.created_at',
  2654. 'good.city_id'
  2655. )
  2656. ->latest('updated_at');
  2657. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2658. $result['count'] = $query->clone()->count();
  2659. $result['goods'] = $this->processGoods(
  2660. $query->clone()
  2661. ->offset(($data['page'] - 1) * $data['pageSize'])
  2662. ->limit($data['pageSize'])
  2663. ->get(),
  2664. $data
  2665. );
  2666. } else {
  2667. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2668. // 获取 type_id 为 1 的数据
  2669. $result['type1'] = $this->processGoods(
  2670. $query->clone()
  2671. ->where('type_id', 1)
  2672. ->offset(($data['page'] - 1) * $data['pageSize'])
  2673. ->limit($data['pageSize'])
  2674. ->get(),
  2675. $data
  2676. );
  2677. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2678. // 获取 type_id 为 2 的数据
  2679. $result['type2'] = $this->processGoods(
  2680. $query->clone()
  2681. ->where('type_id', 2)
  2682. ->offset(($data['page'] - 1) * $data['pageSize'])
  2683. ->limit($data['pageSize'])
  2684. ->get(),
  2685. $data
  2686. );
  2687. }
  2688. if (empty($result)) {
  2689. return Result::error("查询失败", 0);
  2690. }
  2691. return Result::success($result);
  2692. }
  2693. /**
  2694. * 获取商品详情
  2695. * @param array $data
  2696. * @return array
  2697. * */
  2698. public function getWebsiteshopInfo(array $data): array
  2699. {
  2700. $where = [
  2701. 'good.status' => 2,
  2702. 'good.website_id' => $data['website_id'],
  2703. 'good.id' => $data['id'],
  2704. ];
  2705. $goods = Good::where($where)
  2706. ->where('good.id', $data['id'])
  2707. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2708. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2709. ->first();
  2710. if (empty($goods)) {
  2711. return Result::error("查询失败", 0);
  2712. }
  2713. $goods->imgurl = json_decode($goods->imgurl, true);
  2714. return Result::success($goods);
  2715. }
  2716. /**
  2717. * plus pro 处理文章路由问题
  2718. */
  2719. function processArticlePro($website_id)
  2720. {
  2721. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2722. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2723. // // 取出category_id 对应的aLIas_pinyin
  2724. // $categoryIds = array_column($categorys, 'category_id');
  2725. // $categoryPIds = array_column($categorys, 'pid');
  2726. // $aliasPinyins = array_column($categorys, 'path');
  2727. // $alias = array_column($categorys, 'alias');
  2728. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2729. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2730. // // return Result::success($cat_arr);
  2731. // // $catiall = [];
  2732. // //一级所有子级的记录
  2733. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2734. // return [
  2735. // 'cat_1st_arr' => $cat_alias_arr,
  2736. // 'catiall' => $cat_arr,
  2737. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2738. // 'categoryIds' => $categoryIds,
  2739. // ];
  2740. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2741. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2742. // 取出category_id 对应的aLIas_pinyin
  2743. $categoryIds = array_column($categorys, 'category_id');
  2744. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2745. return $pid != 0;
  2746. })));
  2747. $category_path = array_column($categorys, 'path');
  2748. $cat_arr = array_combine($categoryIds, $category_path);
  2749. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2750. $catiall = [];
  2751. //一级所有子级的记录
  2752. $cat_1st_arr = [];
  2753. foreach ($categorys as $key => $value) {
  2754. // $category_arr_id = json_decode($value->category_arr_id);
  2755. // $pinyin_str = '';
  2756. // // 算出一级 并且算出子级
  2757. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2758. $cat_1st_arr[$value->pid][] = $value->category_id;
  2759. }
  2760. // foreach ($category_arr_id as $k => $v) {
  2761. // $pinyin_str .= $cat_arr[$v] . '/';
  2762. // }
  2763. // $pinyin_str = rtrim($pinyin_str, '/');
  2764. $catiall[$value->category_id]['alias'] = $value->alias;
  2765. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2766. $catiall[$value->category_id]['type'] = $value->type;
  2767. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2768. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2769. }
  2770. return [
  2771. 'cat_1st_arr' => $cat_1st_arr,
  2772. 'catiall' => $catiall,
  2773. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2774. 'categoryIds' => $categoryIds,
  2775. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2776. 'categoryPIds' => $categoryPIds,
  2777. ];
  2778. }
  2779. /**
  2780. * 封装处理文章的路由问题
  2781. * */
  2782. function processArticles($articles, $data)
  2783. {
  2784. // 检查 $articles 是否为数组或可迭代对象
  2785. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2786. return $articles->map(function ($article) use ($data) {
  2787. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2788. $catid = $article->cat_arr_id ?? '';
  2789. }
  2790. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2791. $catid = $article->category_arr_id ?? '';
  2792. }
  2793. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2794. $level = json_decode($catid, true);
  2795. if (!is_array($level)) {
  2796. return $article;
  2797. } else {
  2798. $level = array_map('intval', $level);
  2799. }
  2800. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2801. ->where($data)
  2802. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2803. ->pluck('aLIas_pinyin')
  2804. ->implode('/');
  2805. $article->pinyin = $pinyin ?? '';
  2806. return $article;
  2807. });
  2808. } else {
  2809. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2810. $catid = $articles->cat_arr_id ?? '';
  2811. $level = json_decode($catid, true);
  2812. if (!is_array($level)) {
  2813. return $articles;
  2814. } else {
  2815. $level = array_map('intval', $level);
  2816. }
  2817. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2818. ->where($data)
  2819. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2820. ->pluck('aLIas_pinyin')
  2821. ->implode('/');
  2822. $articles->pinyin = $pinyin ?? '';
  2823. return $articles;
  2824. }
  2825. }
  2826. // 封装处理由问题
  2827. function processJob($job, $data)
  2828. {
  2829. return $job->map(function ($job) use ($data) {
  2830. $category = $job->cat_arr_id ?? '';
  2831. $cityid = $job->city_arr_id ?? '';
  2832. $city = json_decode($cityid, true);
  2833. $pinyin = '';
  2834. $level = json_decode($category, true);
  2835. // 路由
  2836. if (!empty($level) && is_array($level)) {
  2837. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2838. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2839. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2840. ->get(['aLIas_pinyin'])
  2841. ->pluck('aLIas_pinyin')
  2842. ->implode('/');
  2843. if (empty($pinyin)) {
  2844. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2845. }
  2846. $job->pinyin = $pinyin;
  2847. }
  2848. // 取职位-城市 市??省
  2849. if (!empty($city) && is_array($city)) {
  2850. if (isset($city[1]) && !empty($city[1])) {
  2851. $city = District::where('id', $city[1])->first(['name']);
  2852. $job->city_name = $city->name ?? '';
  2853. } else if (isset($city[0]) && !empty($city[0])) {
  2854. $city = District::where('id', $city[0])->first(['name']);
  2855. $job->city_name = $city->name ?? '';
  2856. } else {
  2857. $job->city_name = '全国';
  2858. }
  2859. }
  2860. // 获取简历最后一级地区
  2861. if (isset($job->city_id) && !empty($job->city_id)) {
  2862. $city = District::where('id', $job->city_id)->first(['name']);
  2863. $job->hunt_cityname = $city->name ?? '';
  2864. }
  2865. // 组合详细地址
  2866. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2867. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2868. if (is_array($address_id) && !empty($address_id)) {
  2869. $address = District::whereIn('id', $address_id)
  2870. ->orderBy('level', 'asc')
  2871. ->get(['name'])
  2872. ->pluck('name')
  2873. ->implode('');
  2874. // $job->address_name = $address ?? '';
  2875. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2876. }
  2877. }
  2878. // 取行业
  2879. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2880. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2881. if (!empty($job->industry)) {
  2882. $query->where('hyid', $job->industry);
  2883. } else if (!empty($job->hy_id)) {
  2884. $query->where('hyid', $job->hy_id);
  2885. } else if (!empty($job->company_hy_id)) {
  2886. $query->where('hyid', $job->company_hy_id);
  2887. } else {
  2888. $query->where('hyid', $job->job_industry);
  2889. }
  2890. })->first(['hyname']);
  2891. $job->hy_name = $hy_name->hyname ?? '';
  2892. }
  2893. // 取职位类别
  2894. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2895. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2896. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2897. $job->zw_name = $zw_name->zwname ?? '';
  2898. }
  2899. // 取具体职位
  2900. 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))) {
  2901. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2902. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2903. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2904. }
  2905. // 取工作经验
  2906. if (isset($job->experience) && !empty($job->experience)) {
  2907. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2908. $job->experience_name = $experience->ename ?? '';
  2909. }
  2910. // 取学历
  2911. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2912. $education = $job->educational ?? $job->school_education;
  2913. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2914. $job->education_name = $education->ename ?? '';
  2915. }
  2916. // 语言
  2917. if (isset($job->language) && !empty($job->language)) {
  2918. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2919. $job->language_name = $language->ename ?? '';
  2920. }
  2921. // 薪资
  2922. if (isset($job->salary) && !empty($job->salary)) {
  2923. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2924. $job->salary_name = $salary->ename ?? '';
  2925. }
  2926. // 职位性质
  2927. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2928. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2929. $job->job_nature_name = $job_nature->ename ?? '';
  2930. }
  2931. // 公司规模
  2932. if (isset($job->company_size) && !empty($job->company_size)) {
  2933. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2934. $job->company_size_name = $company_size->ename ?? '';
  2935. }
  2936. // 公司性质
  2937. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2938. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2939. $job->company_nature_name = $company_nature->nature_name ?? '';
  2940. }
  2941. // $job->pinyin = $pinyin;
  2942. return $job;
  2943. });
  2944. }
  2945. /**
  2946. * 获取书籍模块
  2947. * @param array $data
  2948. * @return array
  2949. * */
  2950. public function getWebsiteBook(array $data): array
  2951. {
  2952. $input['id'] = $data['id'];
  2953. $input['website_id'] = $data['website_id'];
  2954. // 将 JSON 字符串转换为 PHP 数组
  2955. $data = json_decode($input['id'], true);
  2956. // 使用 array_map 处理每个元素
  2957. $result = array_map(function ($item) use ($input) {
  2958. // 检查parent元素是否存在且不是undefined
  2959. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2960. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2961. $website = [
  2962. 'website_id' => $input['website_id'],
  2963. ];
  2964. // 查询栏目名称
  2965. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2966. if (empty($category)) {
  2967. $parent_alias = '';
  2968. $parent_pinyin = null;
  2969. $imgBooks = [];
  2970. $textBooks = [];
  2971. } else {
  2972. $parent_alias = $category->alias ?? '';
  2973. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2974. // 查找子分类ID数组
  2975. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2976. array_push($childCategoryIds, $parentCatId);
  2977. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2978. if ($parentImgNum != 0) {
  2979. // 查询图片新闻
  2980. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2981. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2982. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2983. })
  2984. ->where('book.status', 2)
  2985. ->where('book.img_url', '!=', '')
  2986. ->where('book.website_id', $website['website_id'])
  2987. ->leftJoin('website_category', function ($join) use ($website) {
  2988. $join->on('book.cat_id', '=', 'website_category.category_id')
  2989. ->where('website_category.website_id', '=', $website['website_id']);
  2990. })
  2991. ->select(
  2992. 'book.id',
  2993. 'book.title',
  2994. 'book.img_url',
  2995. 'book.price',
  2996. 'book.market_price',
  2997. 'book.description',
  2998. 'book.cat_id',
  2999. 'book.description',
  3000. 'book.updated_at',
  3001. 'website_category.alias as category_name',
  3002. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3003. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3004. )
  3005. ->orderBy('updated_at', 'desc')
  3006. ->limit($parentImgNum)
  3007. ->get()->all();
  3008. // 查询文字新闻
  3009. }
  3010. if ($parentTextNum != 0) {
  3011. $textBooks = [];
  3012. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3013. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3014. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3015. })
  3016. ->where('book.status', 2)
  3017. ->where('book.website_id', $website['website_id'])
  3018. ->leftJoin('website_category', function ($join) use ($website) {
  3019. $join->on('book.cat_id', '=', 'website_category.category_id')
  3020. ->where('website_category.website_id', '=', $website['website_id']);
  3021. })
  3022. ->select(
  3023. 'book.id',
  3024. 'book.title',
  3025. 'book.img_url',
  3026. 'book.price',
  3027. 'book.market_price',
  3028. 'book.description',
  3029. 'book.cat_id',
  3030. 'book.description',
  3031. 'book.updated_at',
  3032. 'website_category.alias as category_name',
  3033. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3034. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3035. )
  3036. ->orderBy('updated_at', 'desc')
  3037. ->limit($parentTextNum)
  3038. ->get()->all();
  3039. }
  3040. }
  3041. }
  3042. $resultItem = [
  3043. 'alias' => $parent_alias ?? '',
  3044. 'category_id' => $parentCatId ?? 0,
  3045. 'pinyin' => $parent_pinyin ?? null,
  3046. 'imgnum' => $imgBooks ?? [],
  3047. 'textnum' => $textBooks ?? [],
  3048. ];
  3049. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3050. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3051. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3052. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3053. ->get()->all();
  3054. if (!empty($childCategory)) {
  3055. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3056. // 查询子栏目名称
  3057. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3058. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3059. ->first();
  3060. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3061. $childImgArticles = [];
  3062. $childTextArticles = [];
  3063. $resultItem['child'] = [];
  3064. } else {
  3065. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3066. // 查询子栏目图片新闻
  3067. $childImgArticles = Book::where('cat_id', $childCatId)
  3068. ->where('status', 2)
  3069. ->where('img_url', '!=', '')
  3070. ->where('book.website_id', $website['website_id'])
  3071. ->leftJoin('website_category', function ($join) use ($website) {
  3072. $join->on('book.cat_id', '=', 'website_category.category_id')
  3073. ->where('website_category.website_id', '=', $website['website_id']);
  3074. })
  3075. ->select(
  3076. 'book.id',
  3077. 'book.title',
  3078. 'book.img_url',
  3079. 'book.price',
  3080. 'book.market_price',
  3081. 'book.description',
  3082. 'book.cat_id',
  3083. 'book.description',
  3084. 'book.updated_at',
  3085. DB::raw("'$child_pinyin' as pinyin")
  3086. )
  3087. ->orderBy('updated_at', 'desc')
  3088. ->limit($childImgNum)
  3089. ->get()->all();
  3090. // 查询子栏目文字新闻
  3091. $childTextArticles = Book::where('cat_id', $childCatId)
  3092. ->where('status', 2)
  3093. ->where('book.website_id', $website['website_id'])
  3094. ->leftJoin('website_category', function ($join) use ($website) {
  3095. $join->on('book.cat_id', '=', 'website_category.category_id')
  3096. ->where('website_category.website_id', '=', $website['website_id']);
  3097. })
  3098. ->select(
  3099. 'book.id',
  3100. 'book.title',
  3101. 'book.img_url',
  3102. 'book.price',
  3103. 'book.market_price',
  3104. 'book.description',
  3105. 'book.cat_id',
  3106. 'book.description',
  3107. 'book.updated_at',
  3108. DB::raw("'$child_pinyin' as pinyin")
  3109. )
  3110. ->orderBy('updated_at', 'desc')
  3111. ->limit($childTextNum)
  3112. ->get()->all();
  3113. $resultItem['child'] = [
  3114. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3115. 'category_id' => $childCatId,
  3116. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3117. 'all_childcat' => $childCategory,
  3118. 'imgnum' => $childImgArticles,
  3119. 'textnum' => $childTextArticles,
  3120. ];
  3121. }
  3122. }
  3123. } else {
  3124. $resultItem['child'] = [];
  3125. }
  3126. return $resultItem;
  3127. }, $data);
  3128. return Result::success($result);
  3129. }
  3130. /**
  3131. * 获取书刊列表
  3132. * @param array $data
  3133. * @return array
  3134. * */
  3135. public function getWebsiteBookList(array $data): array
  3136. {
  3137. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3138. if (empty($web)) {
  3139. return Result::error("查询失败", 0);
  3140. }
  3141. $catid = $data['id'];
  3142. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3143. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3144. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3145. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3146. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3147. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3148. ->where('pid', $category['pid'])
  3149. ->select(
  3150. 'category_id',
  3151. 'alias',
  3152. 'aLIas_pinyin',
  3153. 'pid',
  3154. 'sort',
  3155. 'is_url',
  3156. 'web_url',
  3157. 'seo_title',
  3158. 'seo_keywords',
  3159. 'seo_description',
  3160. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3161. )
  3162. ->orderBy('sort')
  3163. ->get()->all();
  3164. if (empty($category)) {
  3165. return Result::error("查询失败", 0);
  3166. }
  3167. $query = Book::where('book.status', 2)
  3168. ->where('book.website_id', $data['website_id'])
  3169. ->where('book.cat_id', $catid)
  3170. ->select(
  3171. 'book.id',
  3172. 'book.title',
  3173. 'book.img_url',
  3174. 'book.description',
  3175. 'book.updated_at',
  3176. 'book.cat_id',
  3177. DB::raw("'$pinyin' as pinyin")
  3178. )
  3179. ->orderBy('book.updated_at', 'desc');
  3180. $count = $query->count();
  3181. $query = clone $query;
  3182. $Book = $query
  3183. ->limit($data['pageSize'])
  3184. ->offset(($data['page'] - 1) * $data['pageSize'])
  3185. ->get()->all();
  3186. $result = [
  3187. 'category' => $categorys,
  3188. 'books' => $Book,
  3189. 'count' => $count,
  3190. ];
  3191. // if(empty($result)){
  3192. // return Result::error("查询失败", 0);
  3193. // }
  3194. return Result::success($result);
  3195. }
  3196. /**
  3197. * 获取书刊详情
  3198. * @param array $data
  3199. * @return array
  3200. * */
  3201. public function getWebsiteBookInfo(array $data): array
  3202. {
  3203. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3204. if (empty($web)) {
  3205. return Result::error("查询失败", 0);
  3206. }
  3207. $book = Book::where('status', 2)
  3208. ->where('website_id', $data['website_id'])
  3209. ->where('id', $data['id'])
  3210. ->select(
  3211. 'book.*',
  3212. )
  3213. ->orderBy('updated_at', 'desc')
  3214. ->first();
  3215. if (empty($book)) {
  3216. return Result::error("查询失败", 0);
  3217. }
  3218. // 先查询当前分类的 pid
  3219. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3220. ->where('category_id', $book['cat_id'])
  3221. ->first(['pid', 'category_id']);
  3222. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3223. if (!empty($carpid)) {
  3224. if ($carpid->pid != 0) {
  3225. $pid = $carpid['pid'];
  3226. // $parent_pinyin = '';
  3227. } else {
  3228. $pid = $carpid['category_id'];
  3229. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3230. }
  3231. }
  3232. $categorys = $query->where('pid', $pid)
  3233. ->select(
  3234. 'category_id',
  3235. 'alias',
  3236. 'aLIas_pinyin',
  3237. 'pid',
  3238. 'sort',
  3239. 'is_url',
  3240. 'web_url',
  3241. 'category_arr_id as cat_arr_id',
  3242. )
  3243. ->orderBy('sort')
  3244. ->get();
  3245. $category = $this->processArticle($categorys, $data);
  3246. $result = [
  3247. 'category' => $category,
  3248. 'books' => $book,
  3249. ];
  3250. return Result::success($result);
  3251. }
  3252. /**
  3253. * 尝试
  3254. * @param array $data
  3255. * @return array
  3256. * */
  3257. public function test(array $data): array
  3258. {
  3259. $input['id'] = $data['id'];
  3260. $input['website_id'] = $data['website_id'];
  3261. // 将 JSON 字符串转换为 PHP 数组
  3262. $data = json_decode($input['id'], true);
  3263. $result = [];
  3264. $article = $data;
  3265. $result = array_map(function ($item) use ($input) {
  3266. $website = [
  3267. 'website_id' => $input['website_id'],
  3268. ];
  3269. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3270. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3271. $parent = [
  3272. 0 => $category['category_id'] ?? [],
  3273. 1 => $parentImgNum ?? [],
  3274. 2 => $parentTextNum ?? [],
  3275. ];
  3276. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3277. $child = [];
  3278. $resultItem = [
  3279. // 'alias' => $parent_alias ?? '',
  3280. 'category_id' => $parentCatId ?? 0,
  3281. 'pinyin' => $parentImgNum ?? null,
  3282. 'imgnum' => $parentTextNum ?? [],
  3283. // 'textnum' => $textArticles ?? [],
  3284. ];
  3285. return $parent;
  3286. }, $data);
  3287. return Result::success($result);
  3288. // });
  3289. }
  3290. /**
  3291. * 封装处理文章的路由问题
  3292. * */
  3293. function processArticle($article, $data)
  3294. {
  3295. return $article->map(function ($article) use ($data) {
  3296. $catid = $article->cat_arr_id ?? '';
  3297. $level = json_decode($catid, true);
  3298. $pinyin = '';
  3299. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3300. if (!empty($level) && is_array($level)) {
  3301. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3302. ->where('website_id', $data['website_id'])
  3303. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3304. ->get(['aLIas_pinyin'])
  3305. ->pluck('aLIas_pinyin')
  3306. ->implode('/');
  3307. } else {
  3308. $pinyin = '';
  3309. }
  3310. $article->pinyin = $pinyin;
  3311. return $article;
  3312. });
  3313. }
  3314. /**
  3315. * c端-获取招工招聘下拉选框
  3316. * @param array $data
  3317. * @return array
  3318. * */
  3319. public function getWebsiteJobSelect(array $data): array
  3320. {
  3321. $web = Website::where('id', $data['website_id'])->first();
  3322. if (empty($web)) {
  3323. return Result::error("该网站不存在", 0);
  3324. }
  3325. $hy = JobIndustry::get()->all();
  3326. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3327. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3328. $result = [
  3329. 'hy' => $hy,
  3330. 'zw' => $zw,
  3331. 'jtzw' => $jtzw,
  3332. ];
  3333. if (empty($result)) {
  3334. return Result::error("查询失败", 0);
  3335. }
  3336. return Result::success($result);
  3337. }
  3338. /**
  3339. * c端-获取招工招聘
  3340. * @param array $data
  3341. * @return array
  3342. * */
  3343. public function getWebsiteJob(array $data): array
  3344. {
  3345. $web = Website::where('id', $data['website_id'])->first();
  3346. if (empty($web)) {
  3347. return Result::error("该网站不存在", 0);
  3348. }
  3349. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3350. ->where('job_hunting.website_id', $data['website_id'])
  3351. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3352. $query->where(function ($q) use ($data) {
  3353. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3354. });
  3355. })
  3356. ->select(
  3357. 'job_hunting.id',
  3358. 'job_hunting.catid',
  3359. 'job_hunting.cat_arr_id',
  3360. 'job_hunting.job_name_get',
  3361. 'job_hunting.industry',
  3362. 'job_hunting.name',
  3363. 'job_hunting.sexy',
  3364. 'job_hunting.origin',
  3365. 'job_hunting.city_arr_id',
  3366. 'job_hunting.experience',
  3367. 'job_hunting.updated_at',
  3368. 'job_hunting.salary',
  3369. 'job_hunting.skillList',
  3370. 'job_hunting.slelf_evaluation',
  3371. )
  3372. ->orderBy('updated_at', 'desc')
  3373. ->limit($data['job1_num'])
  3374. ->get();
  3375. $web['website_id'] = $data['website_id'];
  3376. if (empty($job_hunting)) {
  3377. $job_huntings = "未查询到相关简历信息";
  3378. } else {
  3379. $job_huntings = $this->processJob($job_hunting, $web);
  3380. }
  3381. // 0:待审核 1:已通过 2:已拒绝
  3382. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3383. ->where('job_recruiting.website_id', $data['website_id'])
  3384. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3385. $query->where(function ($q) use ($data) {
  3386. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3387. });
  3388. })
  3389. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3390. ->select(
  3391. 'job_recruiting.id',
  3392. 'job_recruiting.catid',
  3393. 'job_recruiting.cat_arr_id',
  3394. 'job_recruiting.title',
  3395. 'job_recruiting.jtzw_id',
  3396. 'job_recruiting.hy_id',
  3397. 'job_recruiting.city_arr_id',
  3398. 'job_recruiting.due_data',
  3399. 'job_recruiting.updated_at',
  3400. 'job_recruiting.experience',
  3401. 'job_recruiting.educational',
  3402. 'job_recruiting.salary',
  3403. 'job_recruiting.zw_id',
  3404. 'job_company.business_name',
  3405. 'job_recruiting.keyword',
  3406. 'job_recruiting.description',
  3407. )
  3408. ->orderBy('updated_at', 'desc')
  3409. ->limit($data['job2_num'])
  3410. ->get();
  3411. if (empty($job_recruiting->toArray())) {
  3412. $job_recruitings = "未查询到相关职位信息";
  3413. } else {
  3414. $job_recruitings = $this->processJob($job_recruiting, $web);
  3415. }
  3416. $result = [
  3417. 'job_hunting' => $job_huntings,
  3418. 'job_recuiting' => $job_recruitings,
  3419. ];
  3420. return Result::success($result);
  3421. }
  3422. /**
  3423. * c端-获取招工招聘列表
  3424. * @param array $data
  3425. * @return array
  3426. * */
  3427. public function getWebsiteJobList(array $data): array
  3428. {
  3429. $recruit_where = [];
  3430. $hunt_where = [];
  3431. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3432. if (empty($web)) {
  3433. return Result::error("此网站不存在", 0);
  3434. }
  3435. $website_id['website_id'] = $data['website_id'];
  3436. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3437. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3438. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3439. }
  3440. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3441. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3442. }
  3443. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3444. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3445. }
  3446. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3447. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3448. }
  3449. $query = JobRecruiting::where('job_recruiting.status', 1)
  3450. ->where('job_recruiting.website_id', $data['website_id'])
  3451. ->where($recruit_where)
  3452. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3453. $query->where(function ($q) use ($data) {
  3454. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3455. });
  3456. })
  3457. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3458. $query->where(function ($q) use ($data) {
  3459. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3460. });
  3461. })
  3462. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3463. ->select(
  3464. 'job_recruiting.id',
  3465. 'job_recruiting.catid',
  3466. 'job_recruiting.hy_id',
  3467. 'job_recruiting.title',
  3468. 'job_recruiting.zw_id',
  3469. 'job_recruiting.educational',
  3470. 'job_recruiting.jtzw_id',
  3471. 'job_recruiting.city_arr_id',
  3472. 'job_recruiting.due_data',
  3473. 'job_recruiting.experience',
  3474. 'job_recruiting.cat_arr_id',
  3475. 'job_recruiting.updated_at',
  3476. 'job_company.business_name',
  3477. 'job_recruiting.keyword',
  3478. 'job_recruiting.description',
  3479. )
  3480. ->orderBy('job_recruiting.updated_at', 'desc');
  3481. $recruit_count = $query->count();
  3482. $query = clone $query;
  3483. $JobRecruiting = $query
  3484. ->offset(($data['page'] - 1) * $data['pageSize'])
  3485. ->limit($data['pageSize'])
  3486. ->get();
  3487. if (empty($JobRecruiting)) {
  3488. $JobRecruiting = "暂无相关职位信息";
  3489. } else {
  3490. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3491. }
  3492. }
  3493. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3494. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3495. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3496. }
  3497. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3498. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3499. }
  3500. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3501. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3502. }
  3503. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3504. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3505. }
  3506. $query = JobHunting::where('job_hunting.status', 2)
  3507. ->where('job_hunting.website_id', $data['website_id'])
  3508. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3509. ->where($hunt_where)
  3510. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3511. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3512. // })
  3513. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3514. $query->where(function ($q) use ($data) {
  3515. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3516. });
  3517. })
  3518. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3519. $query->where(function ($q) use ($data) {
  3520. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3521. });
  3522. })
  3523. ->select(
  3524. 'job_hunting.id',
  3525. 'job_hunting.catid',
  3526. 'job_hunting.sexy',
  3527. 'job_hunting.experience',
  3528. 'job_hunting.origin',
  3529. 'job_hunting.industry',
  3530. 'job_hunting.name',
  3531. 'job_hunting.job',
  3532. 'job_hunting.job_name_get',
  3533. 'job_hunting.city_arr_id',
  3534. 'job_hunting.cat_arr_id',
  3535. 'job_hunting.created_at',
  3536. 'job_hunting.updated_at',
  3537. 'job_position.zwname as job_name',
  3538. 'job_hunting.skillList',
  3539. 'job_hunting.slelf_evaluation',
  3540. )
  3541. ->orderBy('job_hunting.updated_at', 'desc');
  3542. $hunt_count = $query->count();
  3543. $query = clone $query;
  3544. $JobHunting = $query
  3545. ->offset(($data['page'] - 1) * $data['pageSize'])
  3546. ->limit($data['pageSize'])
  3547. ->get();
  3548. if (empty($JobHunting)) {
  3549. $JobRecruiting = "暂无相关简历信息";
  3550. } else {
  3551. $JobHunting = $this->processJob($JobHunting, $website_id);
  3552. }
  3553. }
  3554. $result = [
  3555. 'JobRecruiting' => $JobRecruiting ?? [],
  3556. 'recruit_count' => $recruit_count ?? 0,
  3557. 'JobHunting' => $JobHunting ?? [],
  3558. 'hunt_count' => $hunt_count ?? 0,
  3559. ];
  3560. return Result::success($result);
  3561. }
  3562. /**
  3563. * c端-获取招工招聘详情
  3564. * @param array $data
  3565. * @return array
  3566. * */
  3567. public function getWebsiteJobInfo(array $data): array
  3568. {
  3569. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3570. if (empty($web)) {
  3571. return Result::error("该网站不存在", 0);
  3572. }
  3573. $webid = [
  3574. 'website_id' => $data['website_id'],
  3575. ];
  3576. // 职位相关信息
  3577. if ($data['type'] == 1) {
  3578. $query = JobRecruiting::where('status', 1)
  3579. ->where('website_id', $data['website_id'])
  3580. ->select('*');
  3581. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3582. $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();
  3583. if (!empty($company)) {
  3584. $result['company'] = $this->processJob($company, $webid);
  3585. }
  3586. $other_job = JobRecruiting::where('status', 1)
  3587. ->where('website_id', $data['website_id'])
  3588. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3589. ->where('id', '!=', $data['id'])
  3590. ->where('user_id', '=', $job[0]['user_id'])
  3591. ->limit($data['pageSize'])
  3592. ->get();
  3593. if (!empty($other_job)) {
  3594. $result['other_job'] = $this->processJob($other_job, $webid);
  3595. }
  3596. } else {
  3597. // 简历相关信息
  3598. $job = JobHunting::where('job_hunting.status', 2)
  3599. ->where('job_hunting.website_id', $data['website_id'])
  3600. ->where('job_hunting.id', $data['id'])
  3601. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3602. ->select('job_hunting.*', 'user_name')
  3603. ->get();
  3604. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3605. if (!empty($resume->toArray())) {
  3606. $result['resume'] = 1;
  3607. } else {
  3608. $result['resume'] = 0;
  3609. }
  3610. }
  3611. if (empty($job->toArray())) {
  3612. return Result::error("id参数错误", 0);
  3613. }
  3614. if (!empty($job[0]['job_experience'])) {
  3615. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3616. if (!empty($job_experience)) {
  3617. // $hy = [];
  3618. foreach ($job_experience as $key => $value) {
  3619. // $id = $value['id'];
  3620. $hy[$key] = $value['job_industry'];
  3621. $zw_id[$key] = $value['job_typename'];
  3622. $jtzw_id[$key] = $value['job_name'];
  3623. }
  3624. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3625. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3626. // 先将关联表转换为索引数组,提高查找效率
  3627. $hyLookup = [];
  3628. foreach ($hy_table as $item) {
  3629. $hyLookup[$item['hyid']] = $item['hyname'];
  3630. }
  3631. $zwLookup = [];
  3632. foreach ($zw_table as $item) {
  3633. $zwLookup[$item['zwid']] = $item['zwname'];
  3634. }
  3635. foreach ($job_experience as $key => &$value) {
  3636. // 处理行业名称
  3637. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3638. $value['hy_name'] = $hyLookup[$hy[$key]];
  3639. }
  3640. // 处理职位名称
  3641. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3642. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3643. }
  3644. // 处理具体职位名称
  3645. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3646. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3647. }
  3648. }
  3649. // 释放引用,防止意外修改后续代码
  3650. unset($value);
  3651. }
  3652. $result['job_experience'] = $job_experience ?? [];
  3653. }
  3654. if (!empty($job[0]['education_experience'])) {
  3655. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3656. if (!empty($education_experience)) {
  3657. foreach ($education_experience as $key => $value) {
  3658. // $id = $value['id'];
  3659. $education[$key] = $value['school_education'];
  3660. }
  3661. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3662. // // 先将关联表转换为索引数组,提高查找效率
  3663. $educationLookup = [];
  3664. foreach ($education_table as $item) {
  3665. $educationLookup[$item['evalue']] = $item['ename'];
  3666. }
  3667. foreach ($education_experience as $key => &$value) {
  3668. // 处理学历名称
  3669. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3670. $value['education_name'] = $educationLookup[$education[$key]];
  3671. }
  3672. }
  3673. }
  3674. $result['education_experience'] = $job_experience ?? [];
  3675. }
  3676. $result['job'] = $this->processJob($job, $webid);
  3677. // // 返现对应的栏目
  3678. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3679. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3680. ->whereIn('category_id', $catid)
  3681. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3682. ->orderBy('pid')->get()->all();
  3683. if (!empty($category)) {
  3684. $result['category'] = $category;
  3685. }
  3686. $result['job'] = $job;
  3687. $result['job_experience'] = $job_experience ?? [];
  3688. $result['education_experience'] = $education_experience ?? [];
  3689. if (empty($result)) {
  3690. return Result::error("参数错误", 0);
  3691. }
  3692. return Result::success($result);
  3693. }
  3694. /**
  3695. * c端-申请职位
  3696. * @param array $data
  3697. * @return array
  3698. * */
  3699. public function getWebsiteJobApply(array $data): array
  3700. {
  3701. // 首先验证网站是否存在
  3702. // return Result::success($data);
  3703. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3704. if (empty($web)) {
  3705. return Result::error("该网站不存在", 0);
  3706. }
  3707. // 验证用户是否存在且为个人会员/管理员
  3708. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3709. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3710. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3711. return Result::error("用户不存在", 0);
  3712. }
  3713. // 去除重复元素和空元素,并保持原始顺序
  3714. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3715. return !empty($value);
  3716. }));
  3717. // 验证职位是否存在 1:审核通过
  3718. $recruiting = JobRecruiting::where('status', 1)
  3719. ->where('website_id', $data['website_id'])
  3720. ->whereIn('id', $data['recruit_id'])
  3721. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3722. if (empty($recruiting)) {
  3723. return Result::error("该职位不存在", 0);
  3724. }
  3725. // 简历是否存在
  3726. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3727. if (empty($hunt_id)) {
  3728. return Result::error("该简历不存在", 0);
  3729. }
  3730. $data['hunt_id'] = $hunt_id['hunt_id'];
  3731. // // 验证是否已投递过该职位
  3732. $apply = JobApply::where('user_id', $data['user_id'])
  3733. ->where('hunt_id', $data['hunt_id'])
  3734. ->where('website_id', $data['website_id'])
  3735. ->whereIn('recruit_id', $data['recruit_id'])
  3736. ->get(['recruit_id']);
  3737. if (!empty($apply->toArray())) {
  3738. return Result::error("您已投递过该职位!");
  3739. }
  3740. $insertData = array_map(function ($recruiting) use ($data) {
  3741. return [
  3742. 'user_id' => $data['user_id'],
  3743. 'hunt_id' => $data['hunt_id'],
  3744. 'website_id' => $data['website_id'],
  3745. 'recruit_id' => $recruiting['recruit_id'],
  3746. 'receiver_id' => $recruiting['receiver_id'],
  3747. 'status' => 1,
  3748. ];
  3749. }, $recruiting);
  3750. // 批量插入数据
  3751. $result = JobApply::insert($insertData);
  3752. if (empty($result)) {
  3753. return Result::error("投递失败", 0);
  3754. }
  3755. return Result::success($result);
  3756. }
  3757. /**
  3758. * 招工招聘-沟通简历
  3759. * @param array $data
  3760. * @return array
  3761. * */
  3762. public function getWebsiteJobResume(array $data): array
  3763. {
  3764. // 首先验证网站是否存在
  3765. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3766. if (empty($web)) {
  3767. return Result::error("该网站不存在", 0);
  3768. }
  3769. // return Result::success($data);
  3770. // 验证用户是否存在且为企业会员/管理员
  3771. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3772. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3773. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3774. return Result::error("用户不存在", 0);
  3775. }
  3776. // 去除重复元素和空元素,并保持原始顺序
  3777. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3778. return !empty($value);
  3779. }));
  3780. // 验证简历是否存在
  3781. $hunting = JobHunting::where('status', 2)
  3782. ->where('website_id', $data['website_id'])
  3783. ->whereIn('id', $data['hunt_id'])
  3784. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3785. if (empty($hunting)) {
  3786. return Result::error("该简历不存在", 0);
  3787. }
  3788. // 验证是否已沟通过该简历
  3789. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3790. ->where('recruit_id', $data['recruit_id'])
  3791. ->where('website_id', $data['website_id'])
  3792. ->whereIn('hunt_id', $data['hunt_id'])
  3793. ->get(['hunt_id']);
  3794. if (!empty($remuse->toArray())) {
  3795. return Result::error("您已沟通过该简历!");
  3796. }
  3797. // 准备要插入的数据数组
  3798. $insertData = array_map(function ($hunting) use ($data) {
  3799. return [
  3800. 'user_id' => $data['user_id'],
  3801. 'recruit_id' => $data['recruit_id'],
  3802. 'website_id' => $data['website_id'],
  3803. 'hunt_id' => $hunting['hunt_id'],
  3804. 'receiver_id' => $hunting['receiver_id'],
  3805. 'status' => 1,
  3806. ];
  3807. }, $hunting);
  3808. // 批量插入数据
  3809. $result = JobRemuse::insert($insertData);
  3810. if (empty($result)) {
  3811. return Result::error("沟通失败", 0);
  3812. }
  3813. return Result::success($result);
  3814. }
  3815. /**
  3816. * 招工招聘 -我的职位(企业会员)
  3817. * @param array $data
  3818. * @return array
  3819. */
  3820. public function getWebsiteJobRecruiting(array $data): array
  3821. {
  3822. $web = Website::where('id', $data['website_id'])->first('id');
  3823. if (empty($web)) {
  3824. return Result::error("该网站不存在", 0);
  3825. }
  3826. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3827. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3828. return Result::error("用户暂无权限!", 0);
  3829. }
  3830. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3831. $result = JobRecruiting::where('website_id', $data['website_id'])
  3832. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3833. $query->where('user_id', $user['id']);
  3834. })
  3835. ->where('status', 1)
  3836. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3837. ->orderBy('updated_at', 'desc')
  3838. ->limit($data['pageSize'])
  3839. ->get();
  3840. if (empty($result)) {
  3841. return Result::error("暂无相关职位信息", 0);
  3842. }
  3843. return Result::success($result);
  3844. }
  3845. /**
  3846. * c端 - 验证路由
  3847. * @param array $data
  3848. * @return array
  3849. */
  3850. /**
  3851. * c端 - 验证路由
  3852. * @param array $data
  3853. * @return array
  3854. */
  3855. public function checkWebsiteRoute(array $data): array
  3856. {
  3857. // 测试001111111222
  3858. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3859. if (empty($web)) {
  3860. return Result::error("该网站不存在", 0);
  3861. } elseif ($web['status'] != 1) {
  3862. return Result::error("网站已经关闭", 0);
  3863. }
  3864. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3865. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3866. // 验证路由是否存在
  3867. if (empty($whiteRouterInfo)) {
  3868. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3869. }
  3870. if (!empty($whiteRouterInfo)) {
  3871. return Result::success($whiteRouterInfo->toArray());
  3872. }
  3873. }
  3874. // 验证栏目路由
  3875. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3876. ->where('path', $data['all_route'])
  3877. ->get()->all();
  3878. if (count($last_category) == 0) {
  3879. return Result::error("该栏目不存在", 0);
  3880. }
  3881. if (count($last_category) > 1) {
  3882. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3883. }
  3884. if (count($last_category) == 1) {
  3885. $last_category = $last_category[0];
  3886. }
  3887. // return Result::success($last_category);
  3888. if (isset($data['id']) && !empty($data['id'])) {
  3889. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3890. switch ($last_category['type']) {
  3891. case 1:
  3892. // 文章
  3893. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3894. $article = Article::where('status', 1)
  3895. ->where('id', $data['id'])
  3896. ->where(function ($query) use ($data) {
  3897. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3898. ->orWhereNull("ignore_ids");
  3899. })
  3900. ->first(['catid']);
  3901. if (empty($article)) {
  3902. return Result::error("该文章不存在", 0);
  3903. }
  3904. // return Result::success($article);
  3905. break;
  3906. case 2:
  3907. // 商品
  3908. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3909. $article = Good::where('website_id', $data['website_id'])
  3910. ->where('status', 2)
  3911. ->where('id', $data['id'])
  3912. ->first(['cat_arr_id']);
  3913. if (empty($article)) {
  3914. return Result::error("该商品不存在", 0);
  3915. }
  3916. break;
  3917. case 3:
  3918. // 书刊信息
  3919. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3920. $article = Book::where('website_id', $data['website_id'])
  3921. ->where('status', 2)
  3922. ->where('id', $data['id'])
  3923. ->first(['id', 'cat_arr_id']);
  3924. if (empty($article)) {
  3925. return Result::error("该书刊不存在", 0);
  3926. }
  3927. break;
  3928. case 4:
  3929. // 招聘
  3930. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3931. $article = JobRecruiting::where('website_id', $data['website_id'])
  3932. ->where('status', 1)
  3933. ->where('id', $data['id'])
  3934. ->first(['cat_arr_id']);
  3935. if (empty($article)) {
  3936. return Result::error("该招聘不存在", 0);
  3937. }
  3938. break;
  3939. case 5:
  3940. // 求职
  3941. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3942. $article = JobHunting::where('website_id', $data['website_id'])
  3943. ->where('status', 2)
  3944. ->where('id', $data['id'])
  3945. ->first(['cat_arr_id']);
  3946. if (empty($article)) {
  3947. return Result::error("该求职不存在", 0);
  3948. }
  3949. break;
  3950. case 6:
  3951. // 企业
  3952. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3953. $article = Company::
  3954. // where('website_id', $data['website_id'])
  3955. // ->
  3956. where('status', 1)
  3957. ->where('id', $data['id'])
  3958. ->first(['cat_arr_id']);
  3959. if (empty($article)) {
  3960. return Result::error("该企业不存在", 0);
  3961. }
  3962. break;
  3963. case 7:
  3964. // 项目
  3965. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3966. $article = Project::where('website_id', $data['website_id'])
  3967. ->where('status', 1)
  3968. ->where('id', $data['id'])
  3969. ->first(['cat_arr_id']);
  3970. if (empty($article)) {
  3971. return Result::error("该项目不存在", 0);
  3972. }
  3973. break;
  3974. default:
  3975. return Result::error("该数据不存在", 0);
  3976. break;
  3977. }
  3978. // return Result::success($article);
  3979. // $catid =0 ;
  3980. if (!isset($article['cat_arr_id'])) {
  3981. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3982. } else {
  3983. $catidArray = json_decode($article['cat_arr_id'], true);
  3984. $catid = !empty($catidArray) ? end($catidArray) : null;
  3985. }
  3986. // return Result::success($catid);
  3987. // // return Result::success($article['cat_arr_id']);
  3988. if (empty($catid)) {
  3989. return Result::error("该栏目路径不存在", 0);
  3990. }
  3991. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3992. ->where('category_id', $catid)
  3993. ->first('path');
  3994. }
  3995. // else{
  3996. // // if ($last_category['pid'] != 0) {
  3997. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3998. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3999. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4000. // ->where('category_id',$catid)
  4001. // ->where('path',$data['all_route'])
  4002. // ->first('path');
  4003. // // } else {
  4004. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4005. // // }
  4006. // }
  4007. // return Result::success($path);
  4008. if (!empty($path) && $path['path'] != $data['all_route']) {
  4009. return Result::error('非法路径!');
  4010. } else {
  4011. return Result::success($last_category['path']);
  4012. }
  4013. }
  4014. /**
  4015. * 招工招聘 - 获取推荐职位
  4016. * @param array $data
  4017. * @return array
  4018. */
  4019. public function getWebsiteLevelJob(array $data): array
  4020. {
  4021. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4022. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4023. ->where('job_recruiting.status', 1)
  4024. ->where('job_level', $data['job_level'])
  4025. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4026. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4027. ->orderBy('job_recruiting.updated_at', 'desc')
  4028. ->limit($data['pageSize'])
  4029. ->get();
  4030. $web = ['website_id' => $data['website_id']];
  4031. if (!empty($job)) {
  4032. $result = $this->processJob($job, $web);
  4033. }
  4034. if (empty($result)) {
  4035. return Result::error("暂无相关职位信息", 0);
  4036. }
  4037. return Result::success($result);
  4038. }
  4039. /**
  4040. * 验证导航名称是否重复
  4041. * @return void
  4042. */
  4043. //20250226 产品列表
  4044. public function getGoodList(array $data): array
  4045. {
  4046. var_dump($data, '---------1-2--');
  4047. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4048. unset($data['user_type_id']);
  4049. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4050. $where = [];
  4051. if ($type_id != '10000') {
  4052. $where = [
  4053. 'good.user_id' => $user_id,
  4054. ];
  4055. }
  4056. //类型
  4057. if (isset($data['type_id']) && $data['type_id']) {
  4058. $where['good.type_id'] = $data['type_id'];
  4059. }
  4060. //名称
  4061. if (isset($data['name']) && $data['name']) {
  4062. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4063. }
  4064. //status
  4065. if (isset($data['status']) && $data['status'] != '') {
  4066. $where['good.status'] = $data['status'];
  4067. }
  4068. //status1
  4069. // if (isset($data['status1']) && $data['status1'] == 1) {
  4070. // $status1 = 1;
  4071. // }
  4072. $where1 = [];
  4073. //website_id
  4074. // if (isset($data['website_id']) && $data['website_id']) {
  4075. // $where1 = [
  4076. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4077. // ];
  4078. // }
  4079. // website_name
  4080. if (isset($data['website_name']) && $data['website_name']) {
  4081. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4082. }
  4083. // catid
  4084. if (isset($data['category_name']) && $data['category_name']) {
  4085. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4086. }
  4087. // $result = Good::where($where)
  4088. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4089. var_dump($where, '---------1---');
  4090. $result = Good::where($where)
  4091. ->when(!empty($where1), function ($query) use ($where1) {
  4092. return $query->where($where1);
  4093. })
  4094. //status 1待审核2已审核3已拒绝
  4095. ->when(isset($data['status1']), function ($query) {
  4096. return $query->whereIn('good.status', [1, 3]);
  4097. })
  4098. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4099. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4100. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4101. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4102. ->orderBy("updated_at", "desc")
  4103. ->limit($data['page_size'])
  4104. ->offset(($data['page'] - 1) * $data['page_size'])
  4105. ->get();
  4106. $count = Good::where($where)
  4107. ->when(!empty($where1), function ($query) use ($where1) {
  4108. return $query->where($where1);
  4109. })
  4110. //status 1待审核2已审核3已拒绝
  4111. ->when(isset($data['status1']), function ($query) {
  4112. return $query->whereIn('good.status', [1, 3]);
  4113. })
  4114. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4115. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4116. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4117. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4118. ->orderBy("updated_at", "desc")->count();
  4119. $data = [
  4120. 'rows' => $result->toArray(),
  4121. 'count' => $count,
  4122. ];
  4123. if (empty($result)) {
  4124. return Result::error("此栏目暂无相关产品", 0);
  4125. }
  4126. return Result::success($data);
  4127. }
  4128. public function getGoodInfo(array $data): array
  4129. {
  4130. $result = Good::where('id', $data['id'])->first();
  4131. if (empty($result)) {
  4132. return Result::error("此产品不存在", 0);
  4133. }
  4134. return Result::success($result);
  4135. }
  4136. public function addGood(array $data): array
  4137. {
  4138. // unset($data['city_arr_id']);
  4139. // unset($data['cat_arr_id']);
  4140. $data['city_id'] = end($data['city_arr_id']);
  4141. $data['catid'] = end($data['cat_arr_id']);
  4142. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4143. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4144. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4145. unset($data['imgUrl']); //大小写
  4146. if (isset($data['price']) && $data['price'] == '') {
  4147. $data['price'] = 0;
  4148. }
  4149. if ($data['imgurl'] == '') {
  4150. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4151. preg_match_all($reg, $data['detail'], $matches);
  4152. if (isset($matches[1][0])) {
  4153. //截取varchar240
  4154. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4155. }
  4156. }
  4157. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4158. //提取标题+内容中的关键词
  4159. $data['keyword'] = $data['name'];
  4160. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4161. Jieba::init(); // 初始化 jieba-php
  4162. Finalseg::init();
  4163. $segList = Jieba::cut($data['keyword']);
  4164. $segList1 = array_slice($segList, 0, 8);
  4165. $data['keyword'] = implode(',', $segList1);
  4166. }
  4167. if ($data['description'] == '') {
  4168. //提取内容中的描述
  4169. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4170. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4171. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4172. }
  4173. if ($data['status'] == 1) {
  4174. $this->sendMessage([
  4175. 'talk_type' => 200,
  4176. 'title' => $data['name'],
  4177. 'content' => '提交了审核',
  4178. 'messageType' => 3,
  4179. ]);
  4180. }
  4181. $result = Good::insert($data);
  4182. if (empty($result)) {
  4183. return Result::error("添加失败", 0);
  4184. }
  4185. return Result::success($result);
  4186. }
  4187. public function updateGood(array $data): array
  4188. {
  4189. $data['city_id'] = end($data['city_arr_id']);
  4190. $data['catid'] = end($data['cat_arr_id']);
  4191. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4192. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4193. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4194. //设置东八区
  4195. date_default_timezone_set('Asia/Shanghai');
  4196. $data['updated_at'] = date('Y-m-d H:i:s');
  4197. if (isset($data['price']) && $data['price'] == '') {
  4198. $data['price'] = 0;
  4199. }
  4200. if ($data['imgurl'] == '') {
  4201. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4202. preg_match_all($reg, $data['detail'], $matches);
  4203. if (isset($matches[1][0])) {
  4204. //截取varchar240
  4205. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4206. }
  4207. }
  4208. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4209. //提取标题+内容中的关键词
  4210. $data['keyword'] = $data['name'];
  4211. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4212. Jieba::init(); // 初始化 jieba-php
  4213. Finalseg::init();
  4214. $segList = Jieba::cut($data['keyword']);
  4215. $segList1 = array_slice($segList, 0, 8);
  4216. $data['keyword'] = implode(',', $segList1);
  4217. }
  4218. if ($data['description'] == '') {
  4219. //提取内容中的描述
  4220. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4221. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4222. }
  4223. if ($data['status'] == 1) {
  4224. $this->sendMessage([
  4225. 'talk_type' => 200,
  4226. 'title' => $data['name'],
  4227. 'content' => '提交了审核',
  4228. 'messageType' => 3,
  4229. ]);
  4230. }
  4231. $result = Good::where('id', $data['id'])->update($data);
  4232. if (empty($result)) {
  4233. return Result::error("更新失败", 0);
  4234. }
  4235. return Result::success($result);
  4236. }
  4237. public function delGood(array $data): array
  4238. {
  4239. $result = Good::where('id', $data['id'])->delete();
  4240. if (empty($result)) {
  4241. return Result::error("删除失败", 0);
  4242. }
  4243. return Result::success($result);
  4244. }
  4245. //20250226 产品列表
  4246. //20250306 求职信息
  4247. public function getJobHuntingList(array $data): array
  4248. {
  4249. $where = [];
  4250. if (isset($data['username']) && !empty($data['username'])) {
  4251. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4252. }
  4253. //status 1待审核2已审核3已拒绝
  4254. if (isset($data['status']) && $data['status'] != '') {
  4255. $where = [
  4256. 'job_hunting.status' => $data['status'],
  4257. ];
  4258. }
  4259. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4260. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4261. unset($data['type_id']);
  4262. if ($type_id != '10000') {
  4263. $where[] = ['job_hunting.user_id', '=', $user_id];
  4264. }
  4265. $result = JobHunting::where($where)
  4266. ->when(!empty($data['status1']), function ($query) use ($data) {
  4267. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4268. })
  4269. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4270. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4271. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4272. ->orderBy("updated_at", "desc")
  4273. ->limit($data['page_size'])
  4274. ->offset(($data['page'] - 1) * $data['page_size'])
  4275. ->get();
  4276. if (empty($result)) {
  4277. return Result::error("查询失败", 0);
  4278. }
  4279. $count = JobHunting::where($where)
  4280. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4281. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4282. ->count();
  4283. $data = [
  4284. 'rows' => $result->toArray(),
  4285. 'count' => $count,
  4286. ];
  4287. return Result::success($data);
  4288. }
  4289. public function getJobHuntingApply(array $data): array
  4290. {
  4291. var_dump($data, '-----------------test--------1-');
  4292. $where = [];
  4293. if (isset($data['username']) && !empty($data['username'])) {
  4294. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4295. }
  4296. if (isset($data['salary']) && !empty($data['salary'])) {
  4297. $where[] = [
  4298. 'job_hunting.salary',
  4299. '=',
  4300. $data['salary'],
  4301. ];
  4302. }
  4303. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4304. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4305. unset($data['type_id']);
  4306. if ($type_id != '10000') {
  4307. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4308. }
  4309. var_dump($where, '-----------------test---------');
  4310. $result = jobApply::where($where)
  4311. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4312. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4313. // })
  4314. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4315. ->where('job_enum.egroup', '=', 'income')
  4316. ->where('job_hunting.status', 2) //已审核
  4317. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4318. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4319. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4320. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4321. //职位----是申请职位
  4322. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4323. ->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')
  4324. ->orderBy("job_hunting.updated_at", "desc")
  4325. ->limit($data['page_size'])
  4326. ->offset(($data['page'] - 1) * $data['page_size'])
  4327. ->get();
  4328. if (empty($result)) {
  4329. return Result::error("查询失败", 0);
  4330. }
  4331. $count = jobApply::where($where)
  4332. ->where('job_enum.egroup', '=', 'income')
  4333. ->where('job_hunting.status', 2) //已审核
  4334. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4335. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4336. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4337. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4338. //职位----是申请职位
  4339. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4340. ->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')
  4341. ->count();
  4342. $data = [
  4343. 'rows' => $result->toArray(),
  4344. 'count' => $count,
  4345. ];
  4346. return Result::success($data);
  4347. }
  4348. public function addJobHunting(array $data): array
  4349. {
  4350. date_default_timezone_set('Asia/Shanghai');
  4351. unset($data['company_name']);
  4352. unset($data['job_industry']);
  4353. unset($data['job_name']);
  4354. unset($data['department']);
  4355. unset($data['job_timeList']);
  4356. unset($data['job_content']);
  4357. unset($data['job_typename']); //不知道这是啥,
  4358. $data['created_at'] = date('Y-m-d H:i:s');
  4359. $data['updated_at'] = date('Y-m-d H:i:s');
  4360. //根据用户 user_id 只能添加一次
  4361. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4362. if (!empty($result)) {
  4363. return Result::error("您已添加过求职信息", 0);
  4364. }
  4365. var_dump($result, '-----------------test---------');
  4366. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4367. if (is_string($data['city_arr_id'])) {
  4368. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4369. $cityArr = json_decode($data['city_arr_id'], true);
  4370. // 确保 $cityArr 是数组
  4371. if (is_array($cityArr)) {
  4372. $data['city_id'] = end($cityArr);
  4373. }
  4374. } else {
  4375. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4376. if (is_array($data['city_arr_id'])) {
  4377. $data['city_id'] = end($data['city_arr_id']);
  4378. }
  4379. }
  4380. }
  4381. // 处理求职所绑定栏目
  4382. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4383. if (is_string($data['cat_arr_id'])) {
  4384. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4385. // 先清理可能存在的无效 JSON 字符
  4386. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4387. $catArr = json_decode($cleanedCatArrStr, true);
  4388. // 检查 JSON 解码是否成功且结果是数组
  4389. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4390. $data['catid'] = end($catArr);
  4391. }
  4392. } else {
  4393. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4394. if (is_array($data['cat_arr_id'])) {
  4395. $data['catid'] = end($data['cat_arr_id']);
  4396. }
  4397. }
  4398. }
  4399. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4400. $this->sendMessage([
  4401. 'talk_type' => 600,
  4402. 'title' => $data['name'],
  4403. 'content' => '提交了审核',
  4404. 'messageType' => 11,
  4405. ]);
  4406. }
  4407. $result = JobHunting::create($data);
  4408. if (empty($result)) {
  4409. return Result::error("添加失败", 0);
  4410. }
  4411. return Result::success($result);
  4412. }
  4413. public function delJobHunting(array $data): array
  4414. {
  4415. $result = JobHunting::where('id', $data['id'])->delete();
  4416. if (empty($result)) {
  4417. return Result::error("删除失败", 0);
  4418. }
  4419. return Result::success($result);
  4420. }
  4421. public function updateJobHunting(array $data): array
  4422. {
  4423. //设置东八区
  4424. date_default_timezone_set('Asia/Shanghai');
  4425. unset($data['company_name']);
  4426. unset($data['job_industry']);
  4427. unset($data['job_name']);
  4428. unset($data['department']);
  4429. unset($data['job_timeList']);
  4430. unset($data['job_content']);
  4431. unset($data['job_typename']); //不知道这是啥,
  4432. $data['created_at'] = date('Y-m-d H:i:s');
  4433. $data['updated_at'] = date('Y-m-d H:i:s');
  4434. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4435. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4436. $cityArr = json_decode($data['city_arr_id'], true);
  4437. $data['city_id'] = end($cityArr);
  4438. } else {
  4439. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4440. $data['city_id'] = end($data['city_arr_id']);
  4441. }
  4442. // 处理求职所绑定栏目
  4443. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4444. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4445. $catArr = json_decode($data['cat_arr_id'], true);
  4446. $data['catid'] = end($catArr);
  4447. } else {
  4448. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4449. $data['catid'] = end($data['cat_arr_id']);
  4450. }
  4451. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4452. $this->sendMessage([
  4453. 'talk_type' => 600,
  4454. 'title' => $data['name'],
  4455. 'content' => '提交了审核',
  4456. 'messageType' => 11,
  4457. ]);
  4458. }
  4459. $result = JobHunting::where('id', $data['id'])->update($data);
  4460. if (empty($result)) {
  4461. return Result::error("更新失败", 0);
  4462. }
  4463. return Result::success($result);
  4464. }
  4465. public function getJobHuntingInfo(array $data): array
  4466. {
  4467. $result = JobHunting::where('id', $data['id'])->first();
  4468. if (empty($result)) {
  4469. return Result::error("查询失败", 0);
  4470. }
  4471. return Result::success($result);
  4472. }
  4473. public function getJobHuntingData(array $data): array
  4474. {
  4475. $jobEnum = JobEnum::get();
  4476. $jobIndustry = JobIndustry::get();
  4477. $jobNature = JobNature::get();
  4478. $jobPosition = JobPosition::get();
  4479. $data = [
  4480. 'jobEnum' => $jobEnum,
  4481. 'jobIndustry' => $jobIndustry,
  4482. 'jobNature' => $jobNature,
  4483. 'jobPosition' => $jobPosition,
  4484. ];
  4485. return Result::success($data);
  4486. }
  4487. public function delJobHuntingInfo(array $data): array
  4488. {
  4489. $result = JobHunting::where('id', $data['id'])->delete();
  4490. return Result::success();
  4491. }
  4492. //20250324 通知,公告,消息
  4493. public function delNotice(array $data): array
  4494. {
  4495. $result = Notice::where('id', $data['id'])->delete();
  4496. if ($result) {
  4497. return Result::success();
  4498. } else {
  4499. return Result::error("删除失败", 0);
  4500. }
  4501. }
  4502. public function getNoticeInfo(array $data): array
  4503. {
  4504. $result = Notice::where('id', $data['id'])->first();
  4505. // var_dump($result['re_user_ids'], '--------------------');
  4506. if (empty($result)) {
  4507. return Result::error("查询失败", 0);
  4508. }
  4509. return Result::success($result);
  4510. }
  4511. public function readNotice(array $data): array
  4512. {
  4513. $result = Notice::where('id', $data['id'])->first();
  4514. // var_dump($result['re_user_ids'], '--------------------');
  4515. if (empty($result)) {
  4516. return Result::error("查询失败", 0);
  4517. }
  4518. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4519. $re_user_ids = json_decode($result['re_user_ids'], true);
  4520. var_dump($re_user_ids, '--------------1---test---------');
  4521. var_dump($data, '--------------1---test---------');
  4522. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4523. //如果已经存在,就不再添加
  4524. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4525. $read_id = json_decode($result['read_id'], true);
  4526. if (!is_array($read_id)) {
  4527. $read_id = [];
  4528. }
  4529. if (!in_array($data['user_id'], $read_id)) {
  4530. $read_id[] = $data['user_id'];
  4531. $result['read_id'] = json_encode($read_id);
  4532. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4533. }
  4534. } else {
  4535. //如果不存在,就添加
  4536. $result['read_id'] = json_encode([$data['user_id']]);
  4537. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4538. }
  4539. }
  4540. return Result::success($result);
  4541. }
  4542. public function addNotice(array $data): array
  4543. {
  4544. date_default_timezone_set('Asia/Shanghai');
  4545. $data['created_at'] = date('Y-m-d H:i:s');
  4546. $data['updated_at'] = date('Y-m-d H:i:s');
  4547. $user_id = UserInfo::
  4548. //city_id不是null
  4549. whereNotNull('city_id')
  4550. ->whereNotNull('department_id')
  4551. ->where(function ($query) use ($data) {
  4552. $query->where(function ($subQuery) use ($data) {
  4553. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4554. });
  4555. })
  4556. ->where(function ($query) use ($data) {
  4557. $query->where(function ($subQuery) use ($data) {
  4558. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4559. });
  4560. })
  4561. ->pluck('user_id')->toArray();
  4562. $user_id = array_unique($user_id);
  4563. $chat_ids = $user_id;
  4564. $user_id = json_encode($user_id);
  4565. $data['re_user_ids'] = $user_id;
  4566. $this->sendMessage([
  4567. 'talk_type' => 700,
  4568. 'title' => $data['title'],
  4569. 'content' => '提交了审核',
  4570. 'messageType' => 5,
  4571. ]);
  4572. $result = Notice::insertGetId($data);
  4573. if (empty($result)) {
  4574. return Result::error("添加失败", 0);
  4575. }
  4576. return Result::success($result);
  4577. }
  4578. public function updateNotice(array $data): array
  4579. {
  4580. date_default_timezone_set('Asia/Shanghai');
  4581. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4582. $user_id = UserInfo::
  4583. //city_id不是null
  4584. whereNotNull('city_id')
  4585. ->whereNotNull('department_id')
  4586. ->where(function ($query) use ($data) {
  4587. $query->where(function ($subQuery) use ($data) {
  4588. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4589. });
  4590. })
  4591. ->where(function ($query) use ($data) {
  4592. $query->where(function ($subQuery) use ($data) {
  4593. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4594. });
  4595. })
  4596. ->pluck('user_id')->toArray();
  4597. $user_id = array_unique($user_id);
  4598. $user_id = json_encode($user_id);
  4599. $data['re_user_ids'] = $user_id;
  4600. $data['updated_at'] = date('Y-m-d H:i:s');
  4601. $this->sendMessage([
  4602. 'talk_type' => 700,
  4603. 'title' => $data['title'],
  4604. 'content' => '提交了审核',
  4605. 'messageType' => 5,
  4606. ]);
  4607. $result = Notice::where('id', $data['id'])->update($data);
  4608. return Result::success($result);
  4609. }
  4610. public function getNoticeList(array $data): array
  4611. {
  4612. $where = [];
  4613. //title
  4614. if (isset($data['title']) && !empty($data['title'])) {
  4615. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4616. }
  4617. //level
  4618. if (isset($data['level']) && !empty($data['level'])) {
  4619. $where[] = ['notice.level', '=', $data['level']];
  4620. }
  4621. //status
  4622. if (isset($data['status']) && !empty($data['status'])) {
  4623. $where[] = ['notice.status', '=', $data['status']];
  4624. }
  4625. //type
  4626. if (isset($data['type']) && !empty($data['type'])) {
  4627. $where[] = ['notice.type', '=', $data['type']];
  4628. }
  4629. var_dump($data, '------------11111-2----test---------');
  4630. if ($data['type_id'] == 10000) {
  4631. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4632. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4633. })
  4634. ->where($where)
  4635. ->orderBy('updated_at', 'desc')
  4636. ->limit($data['page_size'])
  4637. ->offset(($data['page'] - 1) * $data['page_size'])
  4638. ->get();
  4639. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4640. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4641. })
  4642. ->where($where)
  4643. ->orderBy('updated_at', 'desc')
  4644. ->count();
  4645. } else {
  4646. $result = Notice::where($where)
  4647. // ->where('user_id', $data['user_id'])
  4648. ->Where(function ($query) use ($data) {
  4649. $query->Where(function ($q) use ($data) {
  4650. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4651. ->orWhere('notice.user_id', $data['user_id']);
  4652. });
  4653. })
  4654. ->when(!empty($data['status1']), function ($query) use ($data) {
  4655. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4656. })
  4657. ->orderBy('updated_at', 'desc')
  4658. ->limit($data['page_size'])
  4659. ->offset(($data['page'] - 1) * $data['page_size'])
  4660. ->get();
  4661. $total = Notice::where($where)
  4662. ->when(!empty($data['status1']), function ($query) use ($data) {
  4663. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4664. })
  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. ->count();
  4673. }
  4674. if (empty($result)) {
  4675. return Result::error("查询失败", 0);
  4676. }
  4677. $data = [
  4678. 'rows' => $result,
  4679. 'count' => $total,
  4680. ];
  4681. return Result::success($data);
  4682. }
  4683. public function noticeList(array $data): array
  4684. {
  4685. $where = [];
  4686. //title
  4687. if (isset($data['title']) && !empty($data['title'])) {
  4688. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4689. }
  4690. //level
  4691. if (isset($data['level']) && !empty($data['level'])) {
  4692. $where[] = ['notice.level', '=', $data['level']];
  4693. }
  4694. //status
  4695. if (isset($data['status']) && !empty($data['status'])) {
  4696. $where[] = ['notice.status', '=', $data['status']];
  4697. }
  4698. //type
  4699. if (isset($data['type']) && !empty($data['type'])) {
  4700. $where[] = ['notice.type', '=', $data['type']];
  4701. }
  4702. var_dump($data, '------------11111-2----test---------');
  4703. if ($data['type_id'] == 10000) {
  4704. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4705. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4706. })
  4707. ->where($where)
  4708. ->orderBy('updated_at', 'desc')
  4709. ->limit($data['page_size'])
  4710. ->offset(($data['page'] - 1) * $data['page_size'])
  4711. ->get();
  4712. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4713. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4714. })
  4715. ->where($where)
  4716. ->orderBy('updated_at', 'desc')
  4717. ->count();
  4718. } else {
  4719. $result = Notice::where($where)
  4720. // ->where('user_id', $data['user_id'])
  4721. ->Where(function ($query) use ($data) {
  4722. $query->Where(function ($q) use ($data) {
  4723. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4724. ->orWhere('notice.user_id', $data['user_id']);
  4725. });
  4726. })
  4727. ->when(!empty($data['status1']), function ($query) use ($data) {
  4728. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4729. })
  4730. ->orderBy('updated_at', 'desc')
  4731. ->limit($data['page_size'])
  4732. ->offset(($data['page'] - 1) * $data['page_size'])
  4733. ->get();
  4734. $total = Notice::where($where)
  4735. ->when(!empty($data['status1']), function ($query) use ($data) {
  4736. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4737. })
  4738. // ->where('user_id', $data['user_id'])
  4739. ->Where(function ($query) use ($data) {
  4740. $query->Where(function ($q) use ($data) {
  4741. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4742. ->orWhere('notice.user_id', $data['user_id']);
  4743. });
  4744. })
  4745. ->count();
  4746. }
  4747. if (empty($result)) {
  4748. return Result::error("查询失败", 0);
  4749. }
  4750. $data = [
  4751. 'rows' => $result,
  4752. 'count' => $total,
  4753. ];
  4754. return Result::success($data);
  4755. }
  4756. public function getNoticeDetail(array $data): array
  4757. {
  4758. $result = Notice::where('id', $data['id'])->first();
  4759. if (empty($result)) {
  4760. return Result::error("查询失败", 0);
  4761. }
  4762. return Result::success($result);
  4763. }
  4764. public function deleteNotice(array $data): array
  4765. {
  4766. $notice = Notice::where('id', $data['id'])->first();
  4767. if (empty($notice)) {
  4768. return Result::error("删除失败", 0);
  4769. }
  4770. $chat_group_id = $notice->group_id;
  4771. if ($chat_group_id) {
  4772. //删除群聊
  4773. ChatGroups::where('id', $chat_group_id)->delete();
  4774. //删除群成员
  4775. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4776. //删除群聊记录
  4777. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4778. }
  4779. $result = Notice::where('id', $data['id'])->delete();
  4780. return Result::success($result);
  4781. }
  4782. public function complaintList(array $data): array
  4783. {
  4784. var_dump($data, '---------1---------');
  4785. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4786. unset($data['type_id']);
  4787. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4788. $where = [];
  4789. if ($type_id != 10000 && empty($data['deal_user'])) {
  4790. // $where['complaint.user_id'] = $user_id;
  4791. }
  4792. if (!empty($data['title'])) {
  4793. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4794. }
  4795. if (!empty($data['department_id'])) {
  4796. $where['complaint.department_id'] = $data['department_id'];
  4797. }
  4798. if (!empty($data['deal'])) {
  4799. $where['complaint.deal'] = $data['deal'];
  4800. }
  4801. if (!empty($data['status'])) {
  4802. $where['complaint.status'] = $data['status'];
  4803. }
  4804. var_dump(!empty($data['deal_user']), '----------1');
  4805. var_dump($where, '----------2');
  4806. $result = Complaint::where($where)
  4807. ->when(!empty($data['status1']), function ($query) use ($data) {
  4808. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4809. })
  4810. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4811. //json re_user_ids data[user_id]是不是在里面
  4812. $query->Where(function ($q) use ($data) {
  4813. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4814. ->where('complaint.status', 2);
  4815. });
  4816. })
  4817. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4818. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4819. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4820. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4821. ->orderBy('updated_at', 'desc')
  4822. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4823. //sql输出
  4824. if (empty($result)) {
  4825. return Result::error("暂无投诉信息", 0);
  4826. }
  4827. // 取出数据
  4828. $rows = $result->items();
  4829. $count = $result->total();
  4830. $responseData = [
  4831. 'rows' => $rows,
  4832. 'count' => $count,
  4833. ];
  4834. return Result::success($responseData);
  4835. }
  4836. public function getComplaintList(array $data): array
  4837. {
  4838. var_dump($data, '00000001000000000000');
  4839. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4840. unset($data['type_id']);
  4841. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4842. $where = [];
  4843. if ($type_id != 10000 && empty($data['deal_user'])) {
  4844. $where['complaint.user_id'] = $user_id;
  4845. }
  4846. if (!empty($data['title'])) {
  4847. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4848. }
  4849. if (!empty($data['department_id'])) {
  4850. $where['complaint.department_id'] = $data['department_id'];
  4851. }
  4852. if (!empty($data['deal'])) {
  4853. $where['complaint.deal'] = $data['deal'];
  4854. }
  4855. if (!empty($data['status'])) {
  4856. $where['complaint.status'] = $data['status'];
  4857. }
  4858. var_dump(!empty($data['deal_user']), '----------1');
  4859. var_dump($where, '----------2');
  4860. $result = Complaint::where($where)
  4861. ->when(!empty($data['status1']), function ($query) use ($data) {
  4862. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4863. })
  4864. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4865. // //json re_user_ids data[user_id]是不是在里面
  4866. // $query->Where(function ($q) use ($data) {
  4867. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4868. // ->where('complaint.status', 2);
  4869. // });
  4870. // })
  4871. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4872. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4873. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4874. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4875. ->orderBy('updated_at', 'desc')
  4876. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4877. //sql输出
  4878. if (empty($result)) {
  4879. return Result::error("暂无投诉信息", 0);
  4880. }
  4881. // 取出数据
  4882. $rows = $result->items();
  4883. $count = $result->total();
  4884. $responseData = [
  4885. 'rows' => $rows,
  4886. 'count' => $count,
  4887. ];
  4888. return Result::success($responseData);
  4889. }
  4890. public function getComplaintInfo(array $data): array
  4891. {
  4892. $result = Complaint::where('id', $data['id'])->first();
  4893. if (empty($result)) {
  4894. return Result::error("查询失败", 0);
  4895. }
  4896. return Result::success($result);
  4897. }
  4898. public function readComplaint(array $data): array
  4899. {
  4900. $result = Complaint::where('id', $data['id'])->first();
  4901. if (empty($result)) {
  4902. return Result::error("查询失败", 0);
  4903. }
  4904. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4905. $re_user_ids = json_decode($result['re_user_ids'], true);
  4906. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4907. //如果已经存在,就不再添加
  4908. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4909. $read_id = json_decode($result['read_id'], true);
  4910. if (!is_array($read_id)) {
  4911. $read_id = [];
  4912. }
  4913. if (!in_array($data['user_id'], $read_id)) {
  4914. $read_id[] = $data['user_id'];
  4915. $result['read_id'] = json_encode($read_id);
  4916. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4917. }
  4918. } else {
  4919. //如果不存在,就添加
  4920. $result['read_id'] = json_encode([$data['user_id']]);
  4921. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4922. }
  4923. }
  4924. return Result::success($result);
  4925. }
  4926. public function addComplaint(array $data): array
  4927. {
  4928. date_default_timezone_set('Asia/Shanghai');
  4929. $data['created_at'] = date('Y-m-d H:i:s');
  4930. $data['updated_at'] = date('Y-m-d H:i:s');
  4931. $this->sendMessage([
  4932. 'talk_type' => 800,
  4933. 'title' => $data['title'],
  4934. 'content' => '提交了审核',
  4935. 'messageType' => 6,
  4936. ]);
  4937. $result = Complaint::create($data);
  4938. return Result::success($result);
  4939. }
  4940. public function updateComplaint(array $data): array
  4941. {
  4942. date_default_timezone_set('Asia/Shanghai');
  4943. $data['updated_at'] = date('Y-m-d H:i:s');
  4944. $user_id = $data['user_id'] ?? 0;
  4945. $type_id = $data['type_id'] ?? 0;
  4946. unset($data['user_id']);
  4947. unset($data['type_id']);
  4948. $this->sendMessage([
  4949. 'talk_type' => 800,
  4950. 'title' => $data['title'],
  4951. 'content' => '提交了审核',
  4952. 'messageType' => 6,
  4953. ]);
  4954. $result = Complaint::where('id', $data['id'])->update($data);
  4955. return Result::success($result);
  4956. }
  4957. public function deleteComplaint(array $data): array
  4958. {
  4959. $result = Complaint::where('id', $data['id'])->delete();
  4960. return Result::success($result);
  4961. }
  4962. public function getComplainInfo(array $data): array
  4963. {
  4964. $result = Complaint::where('id', $data['id'])->first();
  4965. if (empty($result)) {
  4966. return Result::error("查询失败", 0);
  4967. }
  4968. return Result::success($result);
  4969. }
  4970. public function updateComplaintStatus(array $data): array
  4971. {
  4972. date_default_timezone_set('Asia/Shanghai');
  4973. $data['updated_at'] = date('Y-m-d H:i:s');
  4974. $user_id = $data['user_id'] ?? 0;
  4975. $type_id = $data['type_id'] ?? 0;
  4976. unset($data['user_id']);
  4977. unset($data['type_id']);
  4978. //处理, 写入处理人
  4979. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4980. $data['real_deal_user'] = $user_id;
  4981. }
  4982. //如果是deal 23,则判断是不是处理人
  4983. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4984. $complaintInof = Complaint::where('id', $data['id'])
  4985. ->where('real_deal_user', $user_id)
  4986. ->first();
  4987. if (empty($complaintInof)) {
  4988. return Result::error("处理人错误", 0);
  4989. }
  4990. }
  4991. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4992. if ($data['status'] == 1) {
  4993. $this->sendMessage([
  4994. 'talk_type' => 800,
  4995. 'title' => $complaintInfo['title'],
  4996. 'content' => '提交了审核',
  4997. 'messageType' => 6,
  4998. ]);
  4999. }
  5000. if ($data['status'] == 2 && !isset($data['deal'])) {
  5001. $this->sendMessage([
  5002. 'talk_type' => 801,
  5003. 'title' => $complaintInfo['title'],
  5004. 'content' => '审核通过',
  5005. 'messageType' => 6,
  5006. 'user_id' => $complaintInfo['user_id'],
  5007. ]);
  5008. $this->sendMessage([
  5009. 'talk_type' => 802,
  5010. 'title' => $complaintInfo['title'],
  5011. 'content' => '待处理',
  5012. 'messageType' => 6,
  5013. 'user_id' => $complaintInfo['re_user_ids'],
  5014. ]);
  5015. }
  5016. if ($data['status'] == 3 && !isset($data['deal'])) {
  5017. $this->sendMessage([
  5018. 'talk_type' => 801,
  5019. 'title' => $complaintInfo['title'],
  5020. 'content' => '审核拒绝',
  5021. 'messageType' => 6,
  5022. 'user_id' => $complaintInfo['user_id'],
  5023. ]);
  5024. }
  5025. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5026. $this->sendMessage([
  5027. 'talk_type' => 802,
  5028. 'title' => $complaintInfo['title'],
  5029. 'content' => '处理中',
  5030. 'messageType' => 6,
  5031. 'user_id' => $complaintInfo['re_user_ids'],
  5032. ]);
  5033. }
  5034. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5035. $this->sendMessage([
  5036. 'talk_type' => 802,
  5037. 'title' => $complaintInfo['title'],
  5038. 'content' => '不予处理',
  5039. 'messageType' => 6,
  5040. 'user_id' => $complaintInfo['re_user_ids'],
  5041. ]);
  5042. }
  5043. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5044. $this->sendMessage([
  5045. 'talk_type' => 802,
  5046. 'title' => $complaintInfo['title'],
  5047. 'content' => '已完结',
  5048. 'messageType' => 6,
  5049. 'user_id' => $complaintInfo['re_user_ids'],
  5050. ]);
  5051. }
  5052. $result = complaint::where('id', $data['id'])->update($data);
  5053. return Result::success($result);
  5054. }
  5055. public function updateGoodStatus(array $data): array
  5056. {
  5057. $user_id = $data['user_id'] ?? 0;
  5058. $type_id = $data['type_id'] ?? 0;
  5059. unset($data['user_id']);
  5060. unset($data['type_id']);
  5061. $goodInfo = Good::where('id', $data['id'])->first();
  5062. if ($data['status'] == 2) {
  5063. $this->sendMessage([
  5064. 'talk_type' => 201,
  5065. 'title' => $goodInfo['name'],
  5066. 'content' => '审核通过',
  5067. 'messageType' => 3,
  5068. 'user_id' => $goodInfo['user_id'],
  5069. ]);
  5070. }
  5071. if ($data['status'] == 3) {
  5072. $this->sendMessage([
  5073. 'talk_type' => 201,
  5074. 'title' => $goodInfo['name'],
  5075. 'content' => '审核拒绝',
  5076. 'messageType' => 3,
  5077. 'user_id' => $goodInfo['user_id'],
  5078. ]);
  5079. }
  5080. if ($data['status'] == 1) {
  5081. $this->sendMessage([
  5082. 'talk_type' => 200,
  5083. 'title' => $goodInfo['name'],
  5084. 'content' => '提交了审核',
  5085. 'messageType' => 3,
  5086. ]);
  5087. }
  5088. $result = Good::where('id', $data['id'])->update($data);
  5089. return Result::success($result);
  5090. }
  5091. public function updateJobHuntingStatus(array $data): array
  5092. {
  5093. $user_id = $data['user_id'] ?? 0;
  5094. $type_id = $data['type_id'] ?? 0;
  5095. unset($data['user_id']);
  5096. unset($data['type_id']);
  5097. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5098. if ($data['status'] == 2) {
  5099. $this->sendMessage([
  5100. 'talk_type' => 601,
  5101. 'title' => $jogHuntingInfo['name'],
  5102. 'content' => '审核通过',
  5103. 'messageType' => 11,
  5104. 'user_id' => $jogHuntingInfo['user_id'],
  5105. ]);
  5106. }
  5107. if ($data['status'] == 3) {
  5108. $this->sendMessage([
  5109. 'talk_type' => 601,
  5110. 'title' => $jogHuntingInfo['name'],
  5111. 'content' => '审核拒绝',
  5112. 'messageType' => 11,
  5113. 'user_id' => $jogHuntingInfo['user_id'],
  5114. ]);
  5115. }
  5116. if ($data['status'] == 1) {
  5117. $this->sendMessage([
  5118. 'talk_type' => 600,
  5119. 'title' => $jogHuntingInfo['name'],
  5120. 'content' => '提交了审核',
  5121. 'messageType' => 11,
  5122. ]);
  5123. }
  5124. $result = JobHunting::where('id', $data['id'])->update($data);
  5125. return Result::success($result);
  5126. }
  5127. public function updateNoticeStatus(array $data): array
  5128. {
  5129. $user_id = $data['user_id'] ?? 0;
  5130. $type_id = $data['type_id'] ?? 0;
  5131. unset($data['user_id']);
  5132. unset($data['type_id']);
  5133. //查询公告
  5134. $notice = Notice::where('id', $data['id'])->first();
  5135. if (empty($notice)) {
  5136. return Result::error("公告不存在", 0);
  5137. }
  5138. //$chat_ids 去除掉$data['user_id']
  5139. $chat_ids = json_decode($notice['re_user_ids'], true);
  5140. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5141. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5142. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5143. //chat_group
  5144. $group_id = PublicData::uuid();
  5145. $groupData = [
  5146. 'id' => $group_id,
  5147. 'creator_id' => $notice['user_id'],
  5148. 'group_name' => $notice['group_name'] ?? '',
  5149. 'profile' => $notice['profile'] ?? 0,
  5150. ];
  5151. var_dump($groupData, '-----------------groupData-------');
  5152. $groupResult = ChatGroups::insertGetId($groupData);
  5153. var_dump($groupResult, '-----------------groupid-------');
  5154. $groupMemberData = [
  5155. 'id' => PublicData::uuid(),
  5156. 'user_id' => $notice['user_id'],
  5157. 'group_id' => $group_id,
  5158. 'leader' => 2,
  5159. ];
  5160. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5161. //插入群成员表
  5162. $groupMemberDataUser = [];
  5163. $chatData = [];
  5164. foreach ($chat_ids as $key => $value) {
  5165. $groupMemberDataUser[] = [
  5166. 'id' => PublicData::uuid(),
  5167. 'user_id' => $value,
  5168. 'group_id' => $group_id,
  5169. 'leader' => 1,
  5170. ];
  5171. $chatData[] = [
  5172. 'user_id' => $value,
  5173. 'msg_type' => 1,
  5174. 'receiver_id' => $group_id,
  5175. 'content' => '通过通知创建群聊',
  5176. 'group_receiver_id' => $notice['user_id'],
  5177. 'action' => 'recieved',
  5178. 'created_at' => date('Y-m-d H:i:s'),
  5179. ];
  5180. }
  5181. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5182. ChatGroupsMember::insert($groupMemberDataUser);
  5183. //插入一条管理员聊天记录
  5184. $chatData[] = [
  5185. 'user_id' => $notice['user_id'],
  5186. 'msg_type' => 1,
  5187. 'receiver_id' => $group_id,
  5188. 'content' => '通过通知创建群聊',
  5189. 'group_receiver_id' => $notice['user_id'],
  5190. 'action' => 'said',
  5191. 'created_at' => date('Y-m-d H:i:s'),
  5192. ];
  5193. var_dump($chatData, '-----------------chatData-------');
  5194. $chatResult = ChatRecords::insert($chatData);
  5195. //处理imp
  5196. $group = [
  5197. 'type' => 1,
  5198. 'name' => $notice['group_name'] ?? '',
  5199. 'profile' => '',
  5200. 'avatar' => '',
  5201. 'creator_id' => $notice['user_id'],
  5202. ];
  5203. $groupResult = GroupImp::insertGetId($group);
  5204. var_dump($groupResult, '获取imp group_id');
  5205. $groupMember = [
  5206. 'user_id' => $notice['user_id'],
  5207. 'group_id' => $groupResult,
  5208. 'leader' => 1,
  5209. 'join_time' => Date('Y-m-d H:i:s')
  5210. ];
  5211. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5212. $talk_session = [
  5213. 'user_id' => $notice['user_id'],
  5214. 'to_from_id' => $groupResult,
  5215. 'talk_mode' => 2,
  5216. 'created_at' => Date('Y-m-d H:i:s'),
  5217. 'updated_at' => Date('Y-m-d H:i:s'),
  5218. ];
  5219. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5220. //被通知人员处理
  5221. foreach ($chat_ids as $key => $value) {
  5222. $groupMemberdata[] = [
  5223. 'user_id' => $value,
  5224. 'group_id' => $groupResult,
  5225. 'leader' => 3,
  5226. 'join_time' => Date('Y-m-d H:i:s')
  5227. ];
  5228. $talk_sessionData[] = [
  5229. 'user_id' => $value,
  5230. 'to_from_id' => $groupResult,
  5231. 'talk_mode' => 2,
  5232. 'created_at' => Date('Y-m-d H:i:s'),
  5233. 'updated_at' => Date('Y-m-d H:i:s'),
  5234. ];
  5235. }
  5236. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5237. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5238. $group_id = $groupResult;
  5239. //更新result的 group_id
  5240. $data['group_id'] = $group_id;
  5241. Notice::where(['id' => $data['id']])->update($data);
  5242. }
  5243. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5244. //删除掉信息
  5245. GroupImp::where('id', $notice['group_id'])->delete();
  5246. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5247. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5248. foreach ($chat_ids as $key => $value) {
  5249. }
  5250. //聊天记录删除
  5251. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5252. $data['group_id'] = null;
  5253. Notice::where(['id' => $data['id']])->update($data);
  5254. }
  5255. $result = Notice::where('id', $data['id'])->update($data);
  5256. $noticeInfo = Notice::where('id', $data['id'])->first();
  5257. if ($data['status'] == 2) {
  5258. $this->sendMessage([
  5259. 'talk_type' => 701,
  5260. 'title' => $noticeInfo['title'],
  5261. 'content' => '审核通过',
  5262. 'messageType' => 3,
  5263. 'user_id' => $noticeInfo['user_id'],
  5264. ]);
  5265. }
  5266. if ($data['status'] == 3) {
  5267. $this->sendMessage([
  5268. 'talk_type' => 701,
  5269. 'title' => $noticeInfo['title'],
  5270. 'content' => '审核拒绝',
  5271. 'messageType' => 3,
  5272. 'user_id' => $noticeInfo['user_id'],
  5273. ]);
  5274. }
  5275. if ($data['status'] == 1) {
  5276. $this->sendMessage([
  5277. 'talk_type' => 700,
  5278. 'title' => $noticeInfo['title'],
  5279. 'content' => '提交了审核',
  5280. 'messageType' => 3,
  5281. ]);
  5282. }
  5283. return Result::success($result);
  5284. }
  5285. public function getDUser(array $data): array
  5286. {
  5287. if (!empty($data['ids'])) {
  5288. $user = User::whereIn('id', $data['ids'])->getall();
  5289. if (empty($user)) {
  5290. return Result::error('无数据', 0);
  5291. }
  5292. return Result::success($user);
  5293. }
  5294. $where = [];
  5295. if (!empty($data['department_id'])) {
  5296. $where['department_id'] = $data['department_id'];
  5297. }
  5298. if (!empty($data['city_id'])) {
  5299. $where['city_id'] = $data['city_id'];
  5300. }
  5301. $result = User::where('type_id', 2)
  5302. ->where('status', 1)
  5303. ->where($where)
  5304. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5305. ->get();
  5306. if (empty($result)) {
  5307. return Result::error("查询失败", 0);
  5308. }
  5309. return Result::success($result);
  5310. }
  5311. /**
  5312. * 验证导航名称是否重复
  5313. * @return void
  5314. */
  5315. public function checkCategoryName(array $data): array
  5316. {
  5317. $result = Category::when($data, function ($query) use ($data) {
  5318. if (isset($data['name']) && $data['name']) {
  5319. $query->where("name", $data['name']);
  5320. }
  5321. if (isset($data['id']) && $data['id']) {
  5322. $query->where("id", "!=", $data['id']);
  5323. }
  5324. })->first();
  5325. if ($result) {
  5326. return Result::error("已存在");
  5327. } else {
  5328. return Result::success();
  5329. }
  5330. }
  5331. //20250226 产品列表
  5332. // 20250306 -------招聘--------fr
  5333. /*
  5334. * 招聘列表
  5335. * */
  5336. public function getJobRecruitingList(array $data): array
  5337. {
  5338. $where = [];
  5339. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5340. if ($data['checkout'] == 0) {
  5341. $job_status = [0, 2];
  5342. } else {
  5343. $job_status = [1];
  5344. }
  5345. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5346. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5347. }
  5348. $user = User::where('id', $data['user_id'])->first();
  5349. if (empty($user)) {
  5350. return Result::error("用户不存在", 0);
  5351. }
  5352. // 3:企业会员
  5353. if ($user['type_id'] == 3) {
  5354. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5355. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5356. }
  5357. // 如果 $where 为空,则不添加 where 条件
  5358. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5359. return $query->where($where);
  5360. })
  5361. ->whereIn('job_recruiting.status', $job_status)
  5362. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5363. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5364. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5365. ->orderBy("updated_at", "desc")
  5366. ->offset(($data['page'] - 1) * $data['page_size'])
  5367. ->limit($data['page_size'])
  5368. ->get()
  5369. ->all();
  5370. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5371. return $query->where($where);
  5372. })
  5373. ->whereIn('job_recruiting.status', $job_status)
  5374. ->count();
  5375. if (empty($result)) {
  5376. return Result::error("暂无招聘信息", 0);
  5377. }
  5378. return Result::success($result);
  5379. }
  5380. /*
  5381. * 招聘信息添加
  5382. * */
  5383. public function addJobRecruiting(array $data): array
  5384. {
  5385. // var_dump('添加招聘进入news------data',$data);
  5386. // return Result::success($data);
  5387. $user = User::where('user.id', $data['user_id'])
  5388. ->where('user.status', 1)
  5389. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5390. ->select(
  5391. 'user.type_id',
  5392. 'user.mobile',
  5393. 'user.email',
  5394. 'user_info.business_name',
  5395. 'user_info.company_hy_id',
  5396. 'user_info.company_nature',
  5397. 'user_info.company_size',
  5398. 'user_info.introduction',
  5399. 'user_info.real_name',
  5400. 'user_info.company_url',
  5401. 'user_info.address_arr_id',
  5402. 'user_info.address'
  5403. )
  5404. ->first();
  5405. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5406. return Result::error("用户不存在", 0);
  5407. }
  5408. $web = Website::where('id', $data['website_id'])->first();
  5409. if (empty($web)) {
  5410. return Result::error("网站不存在", 0);
  5411. }
  5412. // var_dump('添加招聘进入news---user---user',$user);
  5413. // 处理招聘关键词
  5414. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5415. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5416. } else {
  5417. Jieba::init(); // 初始化 jieba-php
  5418. Finalseg::init();
  5419. $segList = Jieba::cut($data['title']);
  5420. $segList1 = array_slice($segList, 0, 8);
  5421. $data['keyword'] = implode(',', $segList1);
  5422. }
  5423. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5424. $content = $data['description'];
  5425. // 去除 <style> 和 <script> 标签及其内容
  5426. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5427. // 去除所有 HTML 标签
  5428. $content = strip_tags($content);
  5429. // 去除 HTML 实体
  5430. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5431. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5432. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5433. // 去除多余空白
  5434. $content = preg_replace('/\s+/u', '', $content);
  5435. // 截取 100 个字符
  5436. $data['seo_description'] = mb_substr($content, 0, 100);
  5437. }
  5438. // return Result::success($user);
  5439. $data['action_id'] = $data['user_id'] ?? null;
  5440. $data['user_type'] = $user['type_id'] ?? null;
  5441. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5442. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5443. $data['catid'] = end($data['cat_arr_id']);
  5444. } else {
  5445. $data['catid'] = 0;
  5446. }
  5447. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5448. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5449. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5450. // 公司地址 管理员必填
  5451. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5452. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5453. // 管理员-企业相关信息
  5454. $company = [
  5455. // 'user_id' => $data['user_id']?? null,
  5456. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5457. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5458. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5459. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5460. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5461. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5462. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5463. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5464. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5465. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5466. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5467. ];
  5468. //去掉相关企业信息
  5469. $job = array_diff_key($data, array_flip(array_keys($company)));
  5470. // var_dump('添加招聘进入news---job---user',$job);
  5471. Db::beginTransaction();
  5472. try {
  5473. // // 先添加职位相关信息
  5474. if ($user['type_id'] == 10000) {
  5475. $job['status'] = 1;
  5476. }
  5477. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5478. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5479. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5480. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5481. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5482. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5483. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5484. // return Result::success($job);
  5485. $jobId = JobRecruiting::insertGetId($job);
  5486. if (empty($jobId)) {
  5487. Db::rollBack();
  5488. return Result::error("添加失败");
  5489. }
  5490. // 添加公司信息
  5491. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5492. $company['job_id'] = $jobId;
  5493. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5494. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5495. if ($user['type_id'] == 10000) {
  5496. // 管理员添加企业信息
  5497. $companyId = JobCompany::insertGetId($company);
  5498. if (empty($companyId)) {
  5499. Db::rollBack();
  5500. return Result::error("添加失败");
  5501. }
  5502. } else {
  5503. // 企业会员添加企业信息
  5504. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5505. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5506. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5507. $company['job_id'] = $jobId;
  5508. $companyId = JobCompany::insertGetId($company);
  5509. if (empty($companyId)) {
  5510. Db::rollBack();
  5511. return Result::error("添加失败");
  5512. }
  5513. }
  5514. Db::commit();
  5515. $result = [
  5516. 'job_id' => $jobId,
  5517. 'company_id' => $companyId,
  5518. ];
  5519. return Result::success($result);
  5520. } catch (\Exception $e) {
  5521. Db::rollBack();
  5522. return Result::error($e->getMessage(), 0);
  5523. }
  5524. // return Result::success($result);
  5525. }
  5526. /*
  5527. * 获取招聘信息详情
  5528. * */
  5529. public function getJobRecruitingInfo(array $data): array
  5530. {
  5531. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5532. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5533. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5534. ->select(
  5535. 'job_recruiting.*',
  5536. 'website.website_name as website_name',
  5537. 'job_company.business_name',
  5538. 'job_company.company_hy_id',
  5539. 'job_company.company_size',
  5540. 'job_company.company_nature',
  5541. 'job_company.introduction',
  5542. 'job_company.real_name',
  5543. 'job_company.mobile',
  5544. 'job_company.company_url',
  5545. 'job_company.address_arr_id',
  5546. 'job_company.address',
  5547. 'job_company.email'
  5548. )
  5549. ->first();
  5550. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5551. if (!empty($cityId)) {
  5552. if (isset($cityId[1]) && $cityId[1] != null) {
  5553. $city = District::where('id', $cityId[1])->first(['name']);
  5554. } else {
  5555. $city = District::where('id', $cityId[0])->first(['name']);
  5556. }
  5557. $result['city'] = $city['name'] ?? '';
  5558. }
  5559. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5560. if (is_array($addressId) && !empty($addressId)) {
  5561. $address = District::whereIn('id', $addressId)
  5562. ->orderBy('level', 'asc')
  5563. ->get(['name'])
  5564. ->pluck('name')
  5565. ->implode('');
  5566. // $job->address_name = $address ?? '';
  5567. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5568. }
  5569. if (empty($result)) {
  5570. return Result::error("招聘信息不存在", 0);
  5571. }
  5572. // return Result::success($job);
  5573. return Result::success($result);
  5574. }
  5575. /*
  5576. * 修改招聘信息
  5577. * */
  5578. public function upJobRecruiting(array $data): array
  5579. {
  5580. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5581. // return Result::success($job);
  5582. if (empty($job)) {
  5583. return Result::error("招聘信息不存在", 0);
  5584. }
  5585. $user = User::where('id', $data['user_id'])->first();
  5586. // return Result::success($user);
  5587. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5588. return Result::error("用户不存在", 0);
  5589. }
  5590. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5591. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5592. }
  5593. // 处理招聘关键词
  5594. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5595. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5596. } else {
  5597. Jieba::init(); // 初始化 jieba-php
  5598. Finalseg::init();
  5599. $segList = Jieba::cut($data['title']);
  5600. $segList1 = array_slice($segList, 0, 8);
  5601. $data['keyword'] = implode(',', $segList1);
  5602. }
  5603. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5604. $content = $data['description'];
  5605. // 去除 <style> 和 <script> 标签及其内容
  5606. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5607. // 去除所有 HTML 标签
  5608. $content = strip_tags($content);
  5609. // 去除 HTML 实体
  5610. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5611. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5612. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5613. // 去除多余空白
  5614. $content = preg_replace('/\s+/u', '', $content);
  5615. // 截取 100 个字符
  5616. $data['seo_description'] = mb_substr($content, 0, 100);
  5617. }
  5618. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5619. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5620. $data['catid'] = end($data['cat_arr_id']);
  5621. } else {
  5622. }
  5623. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5624. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5625. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5626. // 公司地址 管理员必填
  5627. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5628. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5629. // 管理员-企业相关信息
  5630. $company = [
  5631. // 'user_id' => $data['user_id']?? null,
  5632. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5633. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5634. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5635. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5636. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5637. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5638. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5639. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5640. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5641. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5642. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5643. ];
  5644. //去掉相关企业信息
  5645. $data = array_diff_key($data, array_flip(array_keys($company)));
  5646. $jobId = $data['id'];
  5647. $web = $data['website_id'];
  5648. $data['action_id'] = $data['user_id'];
  5649. unset($data['user_id']);
  5650. unset($data['user_type']);
  5651. unset($data['id']);
  5652. unset($data['website_id']);
  5653. // return Result::success($data);
  5654. Db::beginTransaction();
  5655. try {
  5656. // 管理员修改招聘信息
  5657. if ($user['type_id'] == 10000) {
  5658. $data['website_id'] = $web;
  5659. $company['website_id'] = $data['website_id'];
  5660. $data['status'] = 1;
  5661. } else {
  5662. $data['status'] = 0;
  5663. }
  5664. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5665. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5666. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5667. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5668. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5669. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5670. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5671. // return Result::success($job);
  5672. // Db::rollBack();
  5673. // return Result::success($company);
  5674. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5675. $this->sendMessage([
  5676. 'talk_type' => 500,
  5677. 'title' => $data['title'],
  5678. 'content' => '提交了审核',
  5679. 'messageType' => 10,
  5680. ]);
  5681. }
  5682. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5683. if (empty($result['job'])) {
  5684. Db::rollBack();
  5685. return Result::error("修改招聘信息失败");
  5686. }
  5687. // 管理员修改企业相关信息
  5688. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5689. if (empty($result['company'])) {
  5690. Db::rollBack();
  5691. return Result::error("修改企业相关信息失败");
  5692. }
  5693. Db::commit();
  5694. // return Result::success($result);
  5695. } catch (\Exception $e) {
  5696. Db::rollBack();
  5697. return Result::error($e->getMessage(), 0);
  5698. }
  5699. return Result::success($result);
  5700. }
  5701. /*
  5702. * 招聘信息删除
  5703. * */
  5704. public function delJobRecruiting(array $data): array
  5705. {
  5706. $user = User::where('id', $data['user_id'])->first();
  5707. if (empty($user)) {
  5708. return Result::error("用户不存在", 0);
  5709. }
  5710. $job = JobRecruiting::where('id', $data['id'])->first();
  5711. if (empty($job)) {
  5712. return Result::error("招聘信息不存在", 0);
  5713. }
  5714. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5715. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5716. }
  5717. Db::beginTransaction();
  5718. try {
  5719. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5720. if (empty($result['job'])) {
  5721. Db::rollBack();
  5722. return Result::error("删除招聘信息失败");
  5723. }
  5724. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5725. if (empty($result['company'])) {
  5726. Db::rollBack();
  5727. return Result::error("删除企业相关信息失败");
  5728. }
  5729. Db::commit();
  5730. } catch (\Exception $e) {
  5731. Db::rollBack();
  5732. return Result::error($e->getMessage(), 0);
  5733. }
  5734. return Result::success($result);
  5735. }
  5736. /*
  5737. * 获取公司信息
  5738. * */
  5739. public function getJobCompany(array $data): array
  5740. {
  5741. $user = User::where('user.id', $data['user_id'])
  5742. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5743. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5744. ->first();
  5745. // return Result::success($user);
  5746. if (empty($user)) {
  5747. return Result::error("用户不存在", 0);
  5748. }
  5749. if ($user['type_id'] == 3) {
  5750. $result = [
  5751. // 'id' => 0,
  5752. 'user_id' => $data['user_id'],
  5753. 'website_id' => $data['website_id'],
  5754. 'business_name' => $user['business_name'], // 企业名称
  5755. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5756. 'company_nature' => $user['company_nature'], // 公司性质
  5757. 'company_size' => $user['company_size'], // 公司规模
  5758. 'introduction' => $user['introduction'], // 公司简介
  5759. 'real_name' => $user['real_name'], // 企业联系人
  5760. 'mobile' => $user['mobile'], // 企业联系电话
  5761. 'company_url' => $user['company_url'], // 企业网址
  5762. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5763. 'address' => $user['address'], // 企业地址
  5764. 'email' => $user['email'], // 企业邮箱
  5765. ];
  5766. } else {
  5767. return Result::error("用户类型错误", 0);
  5768. }
  5769. if (empty($result)) {
  5770. return Result::error("公司信息不存在", 0);
  5771. }
  5772. return Result::success($result);
  5773. }
  5774. /*
  5775. * 修改公司信息
  5776. * */
  5777. public function upJobCompany(array $data): array
  5778. {
  5779. // return Result::success($data);
  5780. $user = User::where('user.id', $data['user_id'])
  5781. ->where('user.status', 1)
  5782. ->select('user.user_name', 'user.type_id')
  5783. ->first();
  5784. if (empty($user)) {
  5785. return Result::error("用户不存在", 0);
  5786. }
  5787. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5788. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5789. $company = [
  5790. 'business_name' => $data['business_name'], // 企业名称
  5791. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5792. 'company_nature' => $data['company_nature'], // 公司性质
  5793. 'company_size' => $data['company_size'], // 公司规模
  5794. 'introduction' => $data['introduction'], // 公司简介
  5795. // 'real_name' => $data['real_name'], // 企业联系人
  5796. 'company_url' => $data['company_url'], // 企业网址
  5797. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5798. 'address' => $data['address'], // 企业详细地址
  5799. // 'email' => $data['email'], // 企业邮箱
  5800. ];
  5801. if ($user['type_id'] == 3) {
  5802. Db::beginTransaction();
  5803. try {
  5804. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5805. 'business_name' => $data['business_name'], // 企业名称
  5806. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5807. 'company_nature' => $data['company_nature'], // 公司性质
  5808. 'company_size' => $data['company_size'], // 公司规模
  5809. 'introduction' => $data['introduction'], // 公司简介
  5810. // 'real_name' => $data['real_name'], // 企业联系人
  5811. 'company_url' => $data['company_url'], // 企业网址
  5812. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5813. 'address' => $data['address'], // 企业详细地址
  5814. ]);
  5815. if (empty($result['userinfo'])) {
  5816. Db::rollBack();
  5817. return Result::error('修改企业会员信息失败!');
  5818. }
  5819. $result['user'] = User::where('id', $data['user_id'])->update([
  5820. 'email' => $data['email'], // 企业邮箱
  5821. ]);
  5822. if (empty($result['user'])) {
  5823. Db::rollBack();
  5824. return Result::error('修改个人中心信息失败!');
  5825. }
  5826. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5827. if (!empty($job_company)) {
  5828. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5829. if (empty($result['job_company'])) {
  5830. Db::rollBack();
  5831. return Result::error('修改企业会员信息失败!');
  5832. }
  5833. }
  5834. Db::commit();
  5835. return Result::success($result);
  5836. } catch (\Exception $e) {
  5837. Db::rollBack();
  5838. return Result::error($e->getMessage(), 0);
  5839. }
  5840. } else {
  5841. return Result::error("用户类型错误", 0);
  5842. }
  5843. }
  5844. /*
  5845. * 获取省-市
  5846. * */
  5847. public function getJobRecruitingArea(array $data): array
  5848. {
  5849. if (isset($data['pid']) && $data['pid'] != null) {
  5850. $result = District::where('pid', $data['pid'])->get()->all();
  5851. } else {
  5852. $result = District::where('level', 1)->get()->all();
  5853. }
  5854. if (empty($result)) {
  5855. return Result::error("暂无此省市", 0);
  5856. }
  5857. return Result::success($result);
  5858. }
  5859. /*
  5860. * 获取行业分类
  5861. * */
  5862. public function getIndustry(array $data): array
  5863. {
  5864. $result = JobIndustry::get()->all();
  5865. if (empty($result)) {
  5866. return Result::error("暂无行业分类", 0);
  5867. }
  5868. return Result::success($result);
  5869. }
  5870. /*
  5871. * 获取职位
  5872. * */
  5873. public function getPositionList(array $data): array
  5874. {
  5875. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5876. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5877. } else {
  5878. $result = JobPosition::where('zwpid', 0)->get()->all();
  5879. }
  5880. if (empty($result)) {
  5881. return Result::error("暂无此职位", 0);
  5882. }
  5883. return Result::success($result);
  5884. }
  5885. /*
  5886. * 获取工作性质-菜单
  5887. * */
  5888. public function getJobNature(array $data): array
  5889. {
  5890. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5891. if (empty($result)) {
  5892. return Result::error("暂无工作性质", 0);
  5893. }
  5894. return Result::success($result);
  5895. }
  5896. /*
  5897. * 获取工作经验-菜单
  5898. * */
  5899. public function getExperience(array $data): array
  5900. {
  5901. $result = JobEnum::where('egroup', 'years')->get()->all();
  5902. if (empty($result)) {
  5903. return Result::error("暂无工作经验", 0);
  5904. }
  5905. return Result::success($result);
  5906. }
  5907. /*
  5908. * 获取学历-菜单
  5909. * */
  5910. public function getEducation(array $data): array
  5911. {
  5912. $result = JobEnum::where('egroup', 'education')->get()->all();
  5913. if (empty($result)) {
  5914. return Result::error("暂无学历", 0);
  5915. }
  5916. return Result::success($result);
  5917. }
  5918. /*
  5919. * 获取薪资-菜单
  5920. * */
  5921. public function getSalary(array $data): array
  5922. {
  5923. $result = JobEnum::where('egroup', 'income')->get()->all();
  5924. if (empty($result)) {
  5925. return Result::error("暂无薪资", 0);
  5926. }
  5927. return Result::success($result);
  5928. }
  5929. /*
  5930. * 获取语言-菜单
  5931. * */
  5932. public function getLanguage(array $data): array
  5933. {
  5934. $result = JobEnum::where('egroup', 'language')->get()->all();
  5935. if (empty($result)) {
  5936. return Result::error("暂无语言", 0);
  5937. }
  5938. return Result::success($result);
  5939. }
  5940. /*
  5941. * 获取掌握程度-菜单
  5942. * */
  5943. public function getLevel(array $data): array
  5944. {
  5945. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5946. if (empty($result)) {
  5947. return Result::error("暂无工作性质", 0);
  5948. }
  5949. return Result::success($result);
  5950. }
  5951. // 公司信息
  5952. /*
  5953. * 获取公司性质-菜单
  5954. * */
  5955. public function getCompanyNature(array $data): array
  5956. {
  5957. $result = JobNature::get()->all();
  5958. if (empty($result)) {
  5959. return Result::error("暂无公司性质", 0);
  5960. }
  5961. return Result::success($result);
  5962. }
  5963. /*
  5964. * 获取公司规模-菜单
  5965. * */
  5966. public function getCompanySize(array $data): array
  5967. {
  5968. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5969. if (empty($result)) {
  5970. return Result::error("暂无公司规模", 0);
  5971. }
  5972. return Result::success($result);
  5973. }
  5974. /*
  5975. * 招聘信息审核
  5976. * */
  5977. public function checkJobRecruiting(array $data): array
  5978. {
  5979. $user = User::where('id', $data['user_id'])->first();
  5980. if (empty($user)) {
  5981. return Result::error("用户不存在", 0);
  5982. }
  5983. $job = JobRecruiting::where('id', $data['id'])->first();
  5984. if (empty($job)) {
  5985. return Result::error("招聘信息不存在", 0);
  5986. }
  5987. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5988. if ($user['type_id'] != 10000) {
  5989. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5990. }
  5991. // 驳回原因
  5992. if ($data['status'] == 2) {
  5993. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5994. }
  5995. $data['action_id'] = $data['user_id'];
  5996. unset($data['user_id']);
  5997. if ($data['status'] == 1) {
  5998. $this->sendMessage([
  5999. 'talk_type' => 501,
  6000. 'title' => $job['title'],
  6001. 'content' => '审核通过',
  6002. 'messageType' => 10,
  6003. 'user_id' => $job['user_id'],
  6004. ]);
  6005. }
  6006. if ($data['status'] == 2) {
  6007. $this->sendMessage([
  6008. 'talk_type' => 501,
  6009. 'title' => $job['title'],
  6010. 'content' => '审核拒绝',
  6011. 'messageType' => 10,
  6012. 'user_id' => $job['user_id'],
  6013. ]);
  6014. }
  6015. if ($data['status'] == 0) {
  6016. $this->sendMessage([
  6017. 'talk_type' => 500,
  6018. 'title' => $job['title'],
  6019. 'content' => '提交了审核',
  6020. 'messageType' => 10,
  6021. ]);
  6022. }
  6023. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6024. if (empty($result)) {
  6025. return Result::error("审核失败", 0);
  6026. }
  6027. return Result::success($result);
  6028. }
  6029. public function myApplyList(array $data): array
  6030. {
  6031. var_dump($data, '------参数');
  6032. $user = User::where('id', $data['user_id'])->first();
  6033. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6034. return Result::error("用户不存在", 0);
  6035. }
  6036. // 1:个人会员 职场机会
  6037. if ($user['type_id'] == 1) {
  6038. $where['user_id'] = $user['id'];
  6039. }
  6040. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6041. $query->where('user_id', $user['id']);
  6042. })
  6043. ->pluck('recruit_id');
  6044. $where = [];
  6045. if (isset($data['salary']) && $data['salary'] != null) {
  6046. $where['job_recruiting.salary'] = $data['salary'];
  6047. }
  6048. if (isset($data['experience']) && $data['experience'] != null) {
  6049. $where['job_recruiting.experience'] = $data['experience'];
  6050. }
  6051. if (isset($data['business_name']) && $data['business_name'] != null) {
  6052. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6053. }
  6054. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6055. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6056. ->where($where);
  6057. // ->count();
  6058. $count = $query->count();
  6059. $query = clone $query;
  6060. $job = $query
  6061. ->leftJoin('job_enum as income_enum', function ($join) {
  6062. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6063. ->where('income_enum.egroup', 'income');
  6064. })
  6065. ->leftJoin('job_enum as years_enum', function ($join) {
  6066. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6067. ->where('years_enum.egroup', 'years');
  6068. })
  6069. // ->where($where)
  6070. ->orderBy('job_recruiting.updated_at', 'desc')
  6071. ->select(
  6072. 'job_recruiting.id',
  6073. 'job_recruiting.title',
  6074. 'job_company.business_name',
  6075. 'income_enum.evalue as salary_evalue',
  6076. 'income_enum.ename as salary_ename',
  6077. 'years_enum.evalue as experience_evalue',
  6078. 'years_enum.ename as experience_ename',
  6079. 'job_recruiting.updated_at'
  6080. )
  6081. ->offset(($data['page'] - 1) * $data['pageSize'])
  6082. ->limit($data['pageSize'])
  6083. ->get()
  6084. ->all();
  6085. if (empty($job)) {
  6086. return Result::error("暂无招聘信息", 0);
  6087. }
  6088. $result = [
  6089. 'row' => $job,
  6090. 'count' => $count,
  6091. ];
  6092. return Result::success($result);
  6093. }
  6094. public function readJobApply(array $data): array
  6095. {
  6096. $result = JobApply::where('id', $data['id'])->first();
  6097. if (empty($result)) {
  6098. return Result::error("查询失败", 0);
  6099. }
  6100. $result = JobApply::where('id', $data['id'])->update([
  6101. 'status' => 2,
  6102. ]);
  6103. return Result::success($result);
  6104. }
  6105. /*
  6106. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6107. * */
  6108. public function getRecruitingList(array $data): array
  6109. {
  6110. $user = User::where('id', $data['user_id'])->first();
  6111. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6112. return Result::error("用户不存在", 0);
  6113. }
  6114. // 1:个人会员 职场机会
  6115. if ($user['type_id'] == 1) {
  6116. $where['user_id'] = $user['id'];
  6117. }
  6118. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6119. $query->where('receiver_id', $user['id']);
  6120. })
  6121. ->pluck('recruit_id');
  6122. // return Result::success($recruitingId);
  6123. $where = [];
  6124. if (isset($data['salary']) && $data['salary'] != null) {
  6125. $where['job_recruiting.salary'] = $data['salary'];
  6126. }
  6127. if (isset($data['experience']) && $data['experience'] != null) {
  6128. $where['job_recruiting.experience'] = $data['experience'];
  6129. }
  6130. if (isset($data['business_name']) && $data['business_name'] != null) {
  6131. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6132. }
  6133. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6134. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6135. ->where($where);
  6136. // ->count();
  6137. $count = $query->count();
  6138. $query = clone $query;
  6139. $job = $query
  6140. ->leftJoin('job_enum as income_enum', function ($join) {
  6141. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6142. ->where('income_enum.egroup', 'income');
  6143. })
  6144. ->leftJoin('job_enum as years_enum', function ($join) {
  6145. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6146. ->where('years_enum.egroup', 'years');
  6147. })
  6148. // ->where($where)
  6149. ->orderBy('job_recruiting.updated_at', 'desc')
  6150. ->select(
  6151. 'job_recruiting.id',
  6152. 'job_recruiting.title',
  6153. 'job_company.business_name',
  6154. 'income_enum.evalue as salary_evalue',
  6155. 'income_enum.ename as salary_ename',
  6156. 'years_enum.evalue as experience_evalue',
  6157. 'years_enum.ename as experience_ename',
  6158. 'job_recruiting.updated_at'
  6159. )
  6160. ->offset(($data['page'] - 1) * $data['pageSize'])
  6161. ->limit($data['pageSize'])
  6162. ->get()
  6163. ->all();
  6164. if (empty($job)) {
  6165. return Result::error("暂无招聘信息", 0);
  6166. }
  6167. $result = [
  6168. 'row' => $job,
  6169. 'count' => $count,
  6170. ];
  6171. return Result::success($result);
  6172. }
  6173. /*
  6174. * 获取企业会员-招聘信息列表
  6175. * */
  6176. public function getRecruitingInfo(array $data): array
  6177. {
  6178. $user = User::where('id', $data['user_id'])->first();
  6179. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6180. return Result::error("用户不存在", 0);
  6181. }
  6182. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6183. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6184. ->select(
  6185. 'job_recruiting.*',
  6186. 'job_company.business_name',
  6187. 'job_company.company_hy_id',
  6188. 'job_company.company_size',
  6189. 'job_company.company_nature',
  6190. 'job_company.introduction',
  6191. 'job_company.real_name',
  6192. 'job_company.mobile',
  6193. 'job_company.company_url',
  6194. 'job_company.address_arr_id',
  6195. 'job_company.address',
  6196. 'job_company.email'
  6197. )
  6198. ->get();
  6199. if (empty($recruiting)) {
  6200. return Result::error("暂无招聘信息", 0);
  6201. }
  6202. return Result::success($recruiting);
  6203. }
  6204. /*
  6205. * 获取企业会员-我的沟通
  6206. * */
  6207. public function getJobResumeList(array $data): array
  6208. {
  6209. $user = User::where('id', $data['user_id'])->first();
  6210. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6211. return Result::error("用户不存在", 0);
  6212. }
  6213. $where = [];
  6214. if (isset($data['salary']) && $data['salary'] != null) {
  6215. $where['job_hunting.salary'] = $data['salary'];
  6216. }
  6217. if (isset($data['user_name']) && $data['user_name'] != null) {
  6218. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6219. }
  6220. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6221. $query->where('job_resume.user_id', $user['id']);
  6222. })
  6223. ->when(!empty($where), function ($query) use ($where) {
  6224. $query->where($where);
  6225. })
  6226. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6227. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6228. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6229. ->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');
  6230. $count = $job->count();
  6231. if ($count == 0) {
  6232. return Result::error("暂无沟通记录", 0);
  6233. }
  6234. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6235. ->offset(($data['page'] - 1) * $data['pageSize'])
  6236. ->limit($data['pageSize'])
  6237. ->get();
  6238. if (empty($jobs)) {
  6239. return Result::error("暂无沟通记录", 0);
  6240. }
  6241. $result['row'] = $this->processJob($jobs, '');
  6242. $result['count'] = $count;
  6243. return Result::success($result);
  6244. }
  6245. public function readJobResume(array $data): array
  6246. {
  6247. $result = JobResume::where('id', $data['id'])->first();
  6248. if (empty($result)) {
  6249. return Result::error("查询失败", 0);
  6250. }
  6251. $result = JobResume::where('id', $data['id'])->update([
  6252. 'status' => 2,
  6253. ]);
  6254. return Result::success($result);
  6255. }
  6256. // 20250306 招聘
  6257. //20250422 书刊音像
  6258. public function addBook(array $data): array
  6259. {
  6260. $user_id = $data['user_id'] ?? 0;
  6261. $type_id = $data['type_id'] ?? 0;
  6262. // $website_id = $data['website_id'] ?? 0;
  6263. // unset($data['user_id']);
  6264. unset($data['type_id']);
  6265. // unset($data['website_id']);
  6266. //处理数组
  6267. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6268. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6269. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6270. if ($data['img_url'] == '') {
  6271. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6272. preg_match_all($reg, $data['detail'], $matches);
  6273. if (isset($matches[1][0])) {
  6274. //截取varchar240
  6275. $data['img_url'] = substr($matches[1][0], 0, 240);
  6276. }
  6277. }
  6278. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6279. //提取标题+内容中的关键词
  6280. $data['keyword'] = $data['title'];
  6281. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6282. Jieba::init(); // 初始化 jieba-php
  6283. Finalseg::init();
  6284. $segList = Jieba::cut($data['keyword']);
  6285. $segList1 = array_slice($segList, 0, 8);
  6286. $data['keyword'] = implode(',', $segList1);
  6287. }
  6288. if ($data['description'] == '') {
  6289. //提取内容中的描述
  6290. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6291. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6292. }
  6293. var_dump($data, '--');
  6294. if ($data['status'] == 1) {
  6295. $this->sendMessage([
  6296. 'talk_type' => 400,
  6297. 'title' => $data['title'],
  6298. 'content' => '提交了审核',
  6299. 'messageType' => 7,
  6300. ]);
  6301. }
  6302. $result = Book::insertGetId($data);
  6303. if (empty($result)) {
  6304. return Result::error("添加失败", 0);
  6305. }
  6306. return Result::success($result);
  6307. }
  6308. public function getBookList(array $data): array
  6309. {
  6310. $where = [];
  6311. if (!empty($data["title"])) {
  6312. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6313. }
  6314. if (!empty($data['website_name'])) {
  6315. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6316. }
  6317. if (!empty($data['status'])) {
  6318. $where[] = ['book.status', '=', $data['status']];
  6319. }
  6320. $user_id = $data['user_id'];
  6321. $type_id = $data['type_id'];
  6322. // $type_id = 4;
  6323. var_dump($type_id, '------1--------');
  6324. if ($type_id != 10000) {
  6325. $where[] = ['book.user_id', '=', $user_id];
  6326. }
  6327. var_dump(!empty($data['status1']), '=-===1');
  6328. $result = Book::where($where)
  6329. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6330. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6331. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6332. ->when(isset($data['status1']), function ($query) use ($data) {
  6333. $query->whereIn('book.status', [1, 3]);
  6334. })
  6335. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6336. ->orderBy("updated_at", "desc")
  6337. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6338. if (empty($result)) {
  6339. return Result::error("暂无数据", 0);
  6340. }
  6341. // 取出数据
  6342. $rows = $result->items();
  6343. $count = $result->total();
  6344. $responseData = [
  6345. 'rows' => $rows,
  6346. 'count' => $count,
  6347. ];
  6348. return Result::success($responseData);
  6349. }
  6350. public function deleteBook(array $data): array
  6351. {
  6352. $result = Book::where('id', $data['id'])->delete();
  6353. if (empty($result)) {
  6354. return Result::error("删除失败", 0);
  6355. }
  6356. return Result::success($result);
  6357. }
  6358. public function updateBook(array $data): array
  6359. {
  6360. // $user_id = $data['user_id'] ?? 0;
  6361. $type_id = $data['type_id'] ?? 0;
  6362. // $website_id = $data['website_id'] ?? 0;
  6363. unset($data['user_id']);
  6364. unset($data['type_id']);
  6365. // unset($data['website_id']);
  6366. //处理数组
  6367. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6368. if ($data['img_url'] == '') {
  6369. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6370. preg_match_all($reg, $data['detail'], $matches);
  6371. if (isset($matches[1][0])) {
  6372. //截取varchar240
  6373. $data['img_url'] = substr($matches[1][0], 0, 240);
  6374. }
  6375. }
  6376. if ($data['keyword'] == '') {
  6377. //提取标题+内容中的关键词
  6378. $data['keyword'] = $data['title'];
  6379. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6380. Jieba::init(); // 初始化 jieba-php
  6381. Finalseg::init();
  6382. $segList = Jieba::cut($data['keyword']);
  6383. $segList1 = array_slice($segList, 0, 8);
  6384. $data['keyword'] = implode(',', $segList1);
  6385. }
  6386. if ($data['description'] == '') {
  6387. //提取内容中的描述
  6388. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6389. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6390. }
  6391. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6392. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6393. if ($data['status'] == 1) {
  6394. $this->sendMessage([
  6395. 'talk_type' => 400,
  6396. 'title' => $data['title'],
  6397. 'content' => '提交了审核',
  6398. 'messageType' => 7,
  6399. ]);
  6400. }
  6401. $result = Book::where("id", $data["id"])->update($data);
  6402. if (empty($result)) {
  6403. return Result::error("更新失败", 0);
  6404. }
  6405. return Result::success($result);
  6406. }
  6407. public function getBookInfo(array $data): array
  6408. {
  6409. $result = Book::where("id", $data["id"])->first();
  6410. if (empty($result)) {
  6411. return Result::error("获取失败", 0);
  6412. }
  6413. return Result::success($result);
  6414. }
  6415. public function updateBookStatus(array $data): array
  6416. {
  6417. //审核
  6418. unset($data['user_id']);
  6419. $bookInfo = Book::where("id", $data["id"])->first();
  6420. var_dump($bookInfo, '----');
  6421. if ($data['status'] == 2) {
  6422. $this->sendMessage([
  6423. 'talk_type' => 401,
  6424. 'title' => $bookInfo['title'],
  6425. 'content' => '审核通过',
  6426. 'messageType' => 7,
  6427. 'user_id' => $bookInfo['user_id'],
  6428. ]);
  6429. }
  6430. if ($data['status'] == 3) {
  6431. $this->sendMessage([
  6432. 'talk_type' => 401,
  6433. 'title' => $bookInfo['title'],
  6434. 'content' => '审核拒绝',
  6435. 'messageType' => 7,
  6436. 'user_id' => $bookInfo['user_id'],
  6437. ]);
  6438. }
  6439. if ($data['status'] == 1) {
  6440. $this->sendMessage([
  6441. 'talk_type' => 400,
  6442. 'title' => $bookInfo['title'],
  6443. 'content' => '提交了审核',
  6444. 'messageType' => 7,
  6445. // 'user_id'=>$bookInfo['user_id'],
  6446. ]);
  6447. }
  6448. $result = Book::where("id", $data["id"])->update($data);
  6449. if (empty($result)) {
  6450. return Result::error("更新失败", 0);
  6451. }
  6452. return Result::success($result);
  6453. }
  6454. //20250422 书刊音像
  6455. /**
  6456. * 贴身宝贝
  6457. * @param array $data
  6458. * @return array
  6459. */
  6460. public function getWebsiteTsbb(array $data): array
  6461. {
  6462. $month = $data['month'] ?? date('m');
  6463. $day = $data['day'] ?? date('d');
  6464. // 使用缓存键
  6465. $cacheKey = "tsbb_data_{$month}_{$day}";
  6466. // 尝试从缓存获取数据
  6467. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6468. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6469. if ($cachedData = $cache->get($cacheKey)) {
  6470. return Result::success(unserialize($cachedData));
  6471. }
  6472. //查询老黄历
  6473. try {
  6474. $date = date('Y-m-d');
  6475. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6476. // 使用 curl 替代 file_get_contents
  6477. $ch = curl_init();
  6478. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6479. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6480. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6481. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6482. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6483. 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');
  6484. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6485. 'Accept: application/json',
  6486. 'Content-Type: application/json',
  6487. 'Referer: https://www.36jxs.com/'
  6488. ]);
  6489. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6490. curl_setopt($ch, CURLOPT_ENCODING, '');
  6491. $almanacResponse = curl_exec($ch);
  6492. var_dump("====:", $almanacResponse);
  6493. if (curl_errno($ch)) {
  6494. var_dump('Curl error:', curl_error($ch));
  6495. throw new \Exception('Curl error: ' . curl_error($ch));
  6496. }
  6497. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6498. curl_close($ch);
  6499. if ($almanacResponse === false) {
  6500. throw new \Exception('Failed to fetch almanac data');
  6501. }
  6502. $almanacData = json_decode($almanacResponse, true);
  6503. if (json_last_error() !== JSON_ERROR_NONE) {
  6504. throw new \Exception('Failed to parse almanac data');
  6505. }
  6506. $almanacInfo = $almanacData['data'] ?? [];
  6507. } catch (\Exception $e) {
  6508. var_dump('Exception:', $e->getMessage());
  6509. $almanacInfo = [];
  6510. }
  6511. // 获取历史上的今天数据
  6512. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6513. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6514. ->orderBy('year', 'asc')
  6515. ->select("title", "id", "year", DB::raw('1 as type'))
  6516. ->limit(16)
  6517. ->get();
  6518. // 获取节日数据 - 从今天开始获取未来4条
  6519. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6520. ->orderBy('showtime', 'asc')
  6521. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6522. ->limit(16)
  6523. ->get();
  6524. //说文解字
  6525. $chartacterList = Character::orderBy('updated_at', 'desc')
  6526. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6527. ->limit(6)
  6528. ->get();
  6529. //谜语沙龙
  6530. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6531. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6532. ->limit(4)
  6533. ->get();
  6534. //成语欣赏
  6535. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6536. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6537. ->limit(32)
  6538. ->get();
  6539. //名联赏析
  6540. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6541. ->select("id", "first", "second", DB::raw('6 as type'))
  6542. ->limit(6)
  6543. ->get();
  6544. // 获取分类文章数据
  6545. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6546. ->pluck('category_id')
  6547. ->toArray();
  6548. $articlesList = [];
  6549. foreach ($categoryIds as $catid) {
  6550. // 先查有图片的
  6551. $withImg = DB::table('article')
  6552. ->where('status', 1)
  6553. ->where('catid', $catid)
  6554. ->whereNotNull('imgurl')
  6555. ->where('imgurl', '!=', '')
  6556. ->orderBy('updated_at', 'desc')
  6557. ->limit(6)
  6558. ->get();
  6559. $count = $withImg->count();
  6560. if ($count < 6) {
  6561. // 不足6条再查无图片的补足
  6562. $withoutImg = DB::table('article')
  6563. ->where('status', 1)
  6564. ->where('catid', $catid)
  6565. ->where(function ($q) {
  6566. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6567. })
  6568. ->orderBy('updated_at', 'desc')
  6569. ->limit(6 - $count)
  6570. ->get();
  6571. $articles = $withImg->concat($withoutImg);
  6572. } else {
  6573. $articles = $withImg;
  6574. }
  6575. // 组装
  6576. $category = \App\Model\Category::find($catid);
  6577. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6578. $articlesList[] = [
  6579. 'category_name' => $category ? $category->name : '',
  6580. 'catid' => $catid,
  6581. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6582. 'type' => 100,
  6583. 'list' => $articles->map(function ($item) {
  6584. return [
  6585. 'id' => $item->id,
  6586. 'title' => $item->title,
  6587. 'imgurl' => $item->imgurl,
  6588. 'created_at' => $item->created_at
  6589. ];
  6590. })->values()
  6591. ];
  6592. }
  6593. $result = [
  6594. 'almanac' => $almanacInfo,
  6595. 'historyTodayList' => [
  6596. 'category_name' => '历史上的今天',
  6597. 'list' => $historyTodayList,
  6598. 'type' => 1
  6599. ],
  6600. 'festivalList' => [
  6601. 'category_name' => '节日预告',
  6602. 'list' => $festivalList,
  6603. 'type' => 2
  6604. ],
  6605. 'chartacterList' => [
  6606. 'category_name' => '说文解字',
  6607. 'list' => $chartacterList,
  6608. 'type' => 3
  6609. ],
  6610. 'coupletList' => [
  6611. 'category_name' => '名联赏析',
  6612. 'list' => $coupletList,
  6613. 'type' => 6
  6614. ],
  6615. 'riddletList' => [
  6616. 'category_name' => '谜语沙龙',
  6617. 'list' => $riddletList,
  6618. 'type' => 4
  6619. ],
  6620. 'idiomList' => [
  6621. 'category_name' => '成语欣赏',
  6622. 'list' => $idiomList,
  6623. 'type' => 5
  6624. ],
  6625. 'articlesList' => $articlesList
  6626. ];
  6627. // 缓存结果,设置1小时过期
  6628. $cache->set($cacheKey, serialize($result), 3600);
  6629. return Result::success($result);
  6630. }
  6631. /**
  6632. * 获取资讯列表
  6633. */
  6634. public function getWebsiteTsbbList(array $data): array
  6635. {
  6636. $page = $data['page'] ?? 1;
  6637. $pageSize = $data['pageSize'] ?? 10;
  6638. // 如果没有传入月份和日期,则使用今天的日期
  6639. $month = $data['month'] ?? date('m');
  6640. $day = $data['day'] ?? date('d');
  6641. $total = 0;
  6642. $result = [];
  6643. $data['type'] = intval($data['type']);
  6644. var_dump("接收参数:", $data);
  6645. switch ($data['type']) {
  6646. case 1:
  6647. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6648. // 当前月份之后的数据
  6649. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6650. // 或者当前月份且日期大于等于当前日期的数据
  6651. ->orWhere(function ($q) use ($month, $day) {
  6652. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6653. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6654. });
  6655. })
  6656. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6657. $total = $query->count();
  6658. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6659. ->offset(($page - 1) * $pageSize)
  6660. ->limit($pageSize)
  6661. ->get();
  6662. break;
  6663. case 2:
  6664. $query = Festival::where(function ($q) use ($month, $day) {
  6665. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6666. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6667. ->orWhere(function ($q) use ($month, $day) {
  6668. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6669. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6670. });
  6671. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6672. $total = $query->count();
  6673. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6674. ->offset(($page - 1) * $pageSize)
  6675. ->limit($pageSize)
  6676. ->get();
  6677. break;
  6678. case 3:
  6679. $query = Character::orderBy("updated_at", "desc");
  6680. $total = $query->count();
  6681. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6682. ->offset(($page - 1) * $pageSize)
  6683. ->limit($pageSize)
  6684. ->get();
  6685. break;
  6686. case 4:
  6687. $query = Riddle::orderBy("updated_at", "desc");
  6688. $total = $query->count();
  6689. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6690. ->offset(($page - 1) * $pageSize)
  6691. ->limit($pageSize)
  6692. ->get();
  6693. break;
  6694. case 5:
  6695. $query = Idiom::orderBy("updated_at", "desc");
  6696. $total = $query->count();
  6697. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6698. ->offset(($page - 1) * $pageSize)
  6699. ->limit($pageSize)
  6700. ->get();
  6701. break;
  6702. case 6:
  6703. $query = Couplet::orderBy("updated_at", "desc");
  6704. $total = $query->count();
  6705. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6706. ->offset(($page - 1) * $pageSize)
  6707. ->limit($pageSize)
  6708. ->get();
  6709. break;
  6710. default:
  6711. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6712. $total = $query->count();
  6713. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6714. ->offset(($page - 1) * $pageSize)
  6715. ->limit($pageSize)
  6716. ->get();
  6717. }
  6718. return Result::success([
  6719. 'list' => $result,
  6720. 'total' => $total,
  6721. 'page' => (int)$page,
  6722. 'pageSize' => (int)$pageSize,
  6723. 'month' => $month,
  6724. 'day' => $day
  6725. ]);
  6726. }
  6727. /**
  6728. * 1:历史上的今天
  6729. * 2:节日
  6730. * 3:文章
  6731. *
  6732. * 资讯详情信息
  6733. */
  6734. public function getWebsiteTsbbDetail(array $data): array
  6735. {
  6736. $data['type'] = intval($data['type']);
  6737. switch ($data['type']) {
  6738. case 1:
  6739. $result = HistoryToday::where("id", $data['id'])->first();
  6740. break;
  6741. case 2:
  6742. $result = Festival::where("id", $data['id'])->first();
  6743. break;
  6744. case 3:
  6745. $result = Character::where("id", $data['id'])->first();
  6746. break;
  6747. case 4:
  6748. $result = Riddle::where("id", $data['id'])->first();
  6749. break;
  6750. case 5:
  6751. $result = Idiom::where("id", $data['id'])->first();
  6752. break;
  6753. case 6:
  6754. $result = Couplet::where("id", $data['id'])->first();
  6755. break;
  6756. default:
  6757. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6758. break;
  6759. }
  6760. return Result::success($result);
  6761. }
  6762. /**
  6763. * 农网导航首页数据
  6764. */
  6765. public function getWebsiteNwHomeList(array $data): array
  6766. {
  6767. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6768. ->pluck('category_id')
  6769. ->toArray();
  6770. // 使用子查询优化
  6771. $articlesList = DB::table('article')
  6772. ->select([
  6773. 'article.id',
  6774. 'article.title',
  6775. 'article.imgurl',
  6776. 'article.created_at',
  6777. 'category.name as category_name',
  6778. 'category.id as category_id',
  6779. 'website_category.aLIas_pinyin as pinyin',
  6780. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6781. DB::raw('100 as type')
  6782. ])
  6783. ->join('category', 'article.catid', '=', 'category.id')
  6784. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6785. ->leftJoin('website_category as parent_wc', function ($join) {
  6786. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6787. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6788. })
  6789. ->where('website_category.website_id', $data['website_id'])
  6790. ->where('article.status', 1)
  6791. ->whereIn('category.id', $categoryIds)
  6792. ->orderBy('article.created_at', 'desc')
  6793. ->get()
  6794. ->groupBy('category_id')
  6795. ->map(function ($group) {
  6796. // 确保第一条数据有图片
  6797. $firstWithImage = $group->first(function ($item) {
  6798. return !empty($item->imgurl);
  6799. });
  6800. if ($firstWithImage) {
  6801. // 如果有带图片的文章,将其放在第一位
  6802. $group = $group->filter(function ($item) use ($firstWithImage) {
  6803. return $item->id !== $firstWithImage->id;
  6804. })->prepend($firstWithImage);
  6805. }
  6806. return [
  6807. 'category_name' => $group->first()->category_name,
  6808. 'catid' => $group->first()->category_id,
  6809. 'pinyin' => $group->first()->pinyin,
  6810. 'parent_pinyin' => $group->first()->parent_pinyin,
  6811. 'list' => $group->take(4)->map(function ($item) {
  6812. return [
  6813. 'id' => $item->id,
  6814. 'title' => $item->title,
  6815. ];
  6816. })->values()
  6817. ];
  6818. })
  6819. ->values()
  6820. ->toArray();
  6821. return Result::success($articlesList);
  6822. }
  6823. /**
  6824. * 企业管理
  6825. * @param array $data
  6826. * @return array
  6827. */
  6828. public function getCompanyList(array $data): array
  6829. {
  6830. // return Result::success($data);
  6831. $where = [];
  6832. $user = User::where('id', $data['user_id'])->first();
  6833. if (empty($user)) {
  6834. return Result::error('用户不存在!');
  6835. }
  6836. if ($user['type_id'] != 10000) {
  6837. $where['user_id'] = $data['user_id'];
  6838. }
  6839. if (isset($data['title']) && !empty($data['title'])) {
  6840. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6841. }
  6842. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6843. array_push($where, ['website.id', $data['website_id']]);
  6844. }
  6845. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6846. if ($data['ischeck'] == 1) {
  6847. if (isset($data['status']) && $data['status'] != '') {
  6848. array_push($where, ['company.status', $data['status']]);
  6849. $query = Company::where($where);
  6850. } else {
  6851. $query = Company::whereIn('company.status', [0, 2]);
  6852. }
  6853. } else {
  6854. $query = Company::where('company.status', 1);
  6855. }
  6856. }
  6857. $result = $query->where($where)
  6858. ->leftJoin('website_category', function ($query) {
  6859. $query->on('website_category.category_id', '=', 'company.category_id')
  6860. ->on('website_category.website_id', '=', 'company.website_id');
  6861. })
  6862. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6863. ->select(
  6864. 'company.id',
  6865. 'company.title',
  6866. 'company.website_id',
  6867. 'company.category_id',
  6868. 'website.website_name',
  6869. 'website_category.alias as category_name',
  6870. 'company.status',
  6871. 'company.updated_at',
  6872. 'company.user_id'
  6873. )
  6874. ->orderBy('company.updated_at', 'desc')
  6875. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6876. if ($result->isEmpty()) {
  6877. return Result::error("暂无企业", 0);
  6878. }
  6879. return Result::success($result);
  6880. }
  6881. /**
  6882. * 添加企业
  6883. * @param array $data
  6884. * @return array
  6885. */
  6886. public function addCompany(array $data): array
  6887. {
  6888. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6889. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6890. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6891. $data['cat_arr_id'] = json_encode($car_arr_id);
  6892. } else {
  6893. $data['cat_arr_id'] = '';
  6894. }
  6895. if ($data['imgurl'] == '') {
  6896. //content中提取图片第一个图,正则提取
  6897. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6898. preg_match_all($reg, $data['content'], $matches);
  6899. if (isset($matches[1][0])) {
  6900. //截取varchar240
  6901. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6902. }
  6903. }
  6904. if ($data['keyword'] == '') {
  6905. //提取标题+内容中的关键词
  6906. $data['keyword'] = $data['title'];
  6907. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6908. Jieba::init(); // 初始化 jieba-php
  6909. Finalseg::init();
  6910. $segList = Jieba::cut($data['keyword']);
  6911. $segList1 = array_slice($segList, 0, 8);
  6912. $data['keyword'] = implode(',', $segList1);
  6913. }
  6914. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6915. //提取内容中的描述
  6916. $content = $data['content'];
  6917. // 去除 <style> 和 <script> 标签及其内容
  6918. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6919. // 去除所有 HTML 标签
  6920. $content = strip_tags($content);
  6921. // 去除 HTML 实体
  6922. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6923. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6924. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6925. // 去除多余空白
  6926. $content = preg_replace('/\s+/u', '', $content);
  6927. // 截取 100 个字符
  6928. $data['introduce'] = mb_substr($content, 0, 100);
  6929. }
  6930. $user = User::where('id', $data['user_id'])->first();
  6931. if (empty($user)) {
  6932. return Result::error('用户不存在!');
  6933. }
  6934. if ($user['type_id'] == 10000) {
  6935. $data['status'] = 1;
  6936. }
  6937. if (isset($data['level']) && $data['level'] != null) {
  6938. $data['level'] = intval($data['level']);
  6939. } else {
  6940. $data['level'] = null;
  6941. }
  6942. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6943. $this->sendMessage([
  6944. 'talk_type' => 900,
  6945. 'title' => $data['title'],
  6946. 'content' => '提交了审核',
  6947. 'messageType' => 8,
  6948. ]);
  6949. }
  6950. $result = Company::insertGetId($data);
  6951. if ($result) {
  6952. return Result::success($result);
  6953. } else {
  6954. return Result::error('添加失败');
  6955. }
  6956. }
  6957. /**
  6958. * 更新企业
  6959. * @param array $data
  6960. * @return array
  6961. */
  6962. public function upCompany(array $data): array
  6963. {
  6964. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6965. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6966. $data['cat_arr_id'] = json_encode($car_arr_id);
  6967. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6968. } else {
  6969. $data['cat_arr_id'] = '';
  6970. }
  6971. if ($data['imgurl'] == '') {
  6972. //content中提取图片第一个图,正则提取
  6973. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6974. preg_match_all($reg, $data['content'], $matches);
  6975. if (isset($matches[1][0])) {
  6976. //截取varchar
  6977. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6978. }
  6979. }
  6980. if ($data['keyword'] == '') {
  6981. //提取标题+内容中的关键词
  6982. $data['keyword'] = $data['title'];
  6983. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6984. Jieba::init(); // 初始化 jieba-php
  6985. Finalseg::init();
  6986. $segList = Jieba::cut($data['keyword']);
  6987. $segList1 = array_slice($segList, 0, 8);
  6988. $data['keyword'] = implode(',', $segList1);
  6989. }
  6990. if ($data['introduce'] == '') {
  6991. //提取内容中的描述
  6992. $content = $data['content'];
  6993. // 去除 <style> 和 <script> 标签及其内容
  6994. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6995. // 去除所有 HTML 标签
  6996. $content = strip_tags($content);
  6997. // 去除 HTML 实体
  6998. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6999. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7000. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7001. // 去除多余空白
  7002. $content = preg_replace('/\s+/u', '', $content);
  7003. // 截取 100 个字符
  7004. $data['introduce'] = mb_substr($content, 0, 100);
  7005. }
  7006. if (isset($data['level']) && $data['level'] != null) {
  7007. $data['level'] = intval($data['level']);
  7008. } else {
  7009. $data['level'] = null;
  7010. }
  7011. $user = User::where('id', $data['user_id'])->first();
  7012. if (empty($user)) {
  7013. return Result::error('用户不存在!');
  7014. }
  7015. if ($user['type_id'] == 10000) {
  7016. $data['status'] = 1;
  7017. } else {
  7018. $data['status'] = 0;
  7019. }
  7020. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7021. $this->sendMessage([
  7022. 'talk_type' => 900,
  7023. 'title' => $data['title'],
  7024. 'content' => '提交了审核',
  7025. 'messageType' => 8,
  7026. ]);
  7027. }
  7028. $result = Company::where('id', $data['id'])->update($data);
  7029. if ($result) {
  7030. return Result::success($result);
  7031. } else {
  7032. return Result::error('修改失败');
  7033. }
  7034. }
  7035. /**
  7036. * 删除企业
  7037. * @param array $data
  7038. * @return array
  7039. */
  7040. public function delCompany(array $data): array
  7041. {
  7042. $result = Company::where('id', $data['id'])->delete();
  7043. if ($result) {
  7044. return Result::success($result);
  7045. } else {
  7046. return Result::error('删除失败');
  7047. }
  7048. }
  7049. /**
  7050. * 审核企业
  7051. * @param array $data
  7052. * @return array
  7053. */
  7054. public function checkCompany(array $data): array
  7055. {
  7056. $user = User::where('id', $data['user_id'])->first();
  7057. if (empty($user)) {
  7058. return Result::error('用户不存在!');
  7059. }
  7060. $company = Company::where('id', $data['id'])->first();
  7061. if (empty($company)) {
  7062. return Result::error('企业不存在!');
  7063. }
  7064. // 状态:0:未审核 1:已审核 2:已拒绝
  7065. if ($data['status'] == 2 || $data['status'] == '2') {
  7066. $this->sendMessage([
  7067. 'talk_type' => 901,
  7068. 'title' => $company['title'],
  7069. 'content' => '审核拒绝',
  7070. 'messageType' => 8,
  7071. 'user_id' => $company['user_id'],
  7072. ]);
  7073. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7074. } else {
  7075. if ($data['status'] == 1) {
  7076. $this->sendMessage([
  7077. 'talk_type' => 901,
  7078. 'title' => $company['title'],
  7079. 'content' => '审核通过',
  7080. 'messageType' => 8,
  7081. 'user_id' => $company['user_id'],
  7082. ]);
  7083. } else if ($data['status'] == 0) {
  7084. $this->sendMessage([
  7085. 'talk_type' => 900,
  7086. 'title' => $company['title'],
  7087. 'content' => '提交了审核',
  7088. 'messageType' => 8,
  7089. ]);
  7090. }
  7091. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7092. }
  7093. if (empty($result)) {
  7094. return Result::error('审核失败!');
  7095. } else {
  7096. return Result::success($result);
  7097. }
  7098. }
  7099. /**
  7100. * 获取企业信息
  7101. * @param array $data
  7102. * @return array
  7103. */
  7104. public function getCompanyInfo(array $data): array
  7105. {
  7106. $result = Company::where('id', $data['id'])->first();
  7107. $city_arr = json_decode($result['city_arr_id']);
  7108. $result['city_name'] = District::whereIn('id', $city_arr)
  7109. ->pluck('name')
  7110. ->implode('-');
  7111. if (empty($result)) {
  7112. return Result::error('企业不存在!');
  7113. } else {
  7114. return Result::success($result);
  7115. }
  7116. }
  7117. /**
  7118. * @param array $data
  7119. * @return array
  7120. */
  7121. public function getWebsiteCompany(array $data): array
  7122. {
  7123. $categorys = json_decode($data['id'], true);
  7124. $category_arr = $this->processArticlePro($data['website_id']);
  7125. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7126. $catiall = $category_arr['catiall'];
  7127. $categoryIds = $category_arr['categoryIds'];
  7128. // return Result::success($category_arr);
  7129. foreach ($categorys as $key => $value) {
  7130. if (array_key_exists('level', $value)) {
  7131. $parts = explode(',', $value['level']);
  7132. $level = $parts[0] ?? null;
  7133. $imgnum = $parts[1] ?? null;
  7134. $textnum = $parts[2] ?? null;
  7135. if (!empty($textnum) && $textnum > 0) {
  7136. $text_num = Company::where('level', $level)
  7137. ->whereIn('category_id', $categoryIds)
  7138. ->where('status', 1)
  7139. ->select(
  7140. 'company.id',
  7141. 'company.title',
  7142. 'company.description',
  7143. 'company.updated_at',
  7144. 'company.category_id',
  7145. 'company.cat_arr_id'
  7146. )
  7147. ->orderBy('updated_at', 'desc')
  7148. ->limit($textnum)
  7149. ->get()->all();
  7150. }
  7151. if (!empty($imgnum) && $imgnum > 0) {
  7152. $img_num = Company::where('level', $level)
  7153. ->whereIn('category_id', $categoryIds)
  7154. ->where('status', 1)
  7155. ->where('imgurl', '!=', '')
  7156. ->whereNotNull('imgurl')
  7157. ->select(
  7158. 'company.id',
  7159. 'company.title',
  7160. 'company.description',
  7161. 'company.updated_at',
  7162. 'company.imgurl as imgs',
  7163. 'company.category_id',
  7164. 'company.cat_arr_id'
  7165. )
  7166. ->orderBy('updated_at', 'desc')
  7167. ->limit($imgnum)
  7168. ->get()->all();
  7169. }
  7170. }
  7171. if (array_key_exists('id', $value)) {
  7172. $parts = explode(',', $value['id']);
  7173. $category_id = $parts[0] ?? null;
  7174. $imgnum = $parts[1] ?? null;
  7175. $textnum = $parts[2] ?? null;
  7176. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7177. if (!empty($textnum) && $textnum > 0) {
  7178. $text_num = Company::whereIn('category_id', $category_arr)
  7179. // ->where('website_id', $data['website_id'])
  7180. ->where('status', 1)
  7181. ->select(
  7182. 'company.id',
  7183. 'company.title',
  7184. 'company.description',
  7185. 'company.updated_at',
  7186. 'company.category_id',
  7187. 'company.cat_arr_id'
  7188. )
  7189. ->orderBy('updated_at', 'desc')
  7190. ->limit($textnum)
  7191. ->get()->all();
  7192. }
  7193. if (!empty($imgnum) && $imgnum > 0) {
  7194. $img_num = Company::whereIn('category_id', $category_arr)
  7195. // ->where('website_id', $data['website_id'])
  7196. ->where('status', 1)
  7197. ->where('imgurl', '!=', '')
  7198. ->whereNotNull('imgurl')
  7199. ->select(
  7200. 'company.id',
  7201. 'company.title',
  7202. 'company.description',
  7203. 'company.updated_at',
  7204. 'company.imgurl as imgs',
  7205. 'company.category_id',
  7206. 'company.cat_arr_id'
  7207. )
  7208. ->orderBy('updated_at', 'desc')
  7209. ->limit($imgnum)
  7210. ->get()->all();
  7211. }
  7212. }
  7213. if (!empty($text_num)) {
  7214. foreach ($text_num as $k => $v) {
  7215. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7216. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7217. }
  7218. }
  7219. if (!empty($img_num)) {
  7220. foreach ($img_num as $k => $v) {
  7221. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7222. $imgurl = json_decode($v['imgs'], true);
  7223. if (!empty($imgurl)) {
  7224. $img_num[$k]->imgurl = $imgurl[0];
  7225. }
  7226. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7227. }
  7228. }
  7229. $company[$key]['img_num'] = $img_num ?? [];
  7230. $company[$key]['text_num'] = $text_num ?? [];
  7231. }
  7232. if (empty($company)) {
  7233. return Result::error("暂无相关企业信息", 0);
  7234. }
  7235. return Result::success($company);
  7236. }
  7237. /**
  7238. * @param array $data
  7239. * @return array
  7240. */
  7241. public function getWebsiteCompanyList(array $data): array
  7242. {
  7243. $where['website_id'] = $data['website_id'];
  7244. $where['status'] = 1;
  7245. $categoryIds = [];
  7246. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7247. $category_id = $data['category_id'];
  7248. }
  7249. $category_arr = $this->processArticlePro($data['website_id']);
  7250. $categoryIds = $category_arr['categoryIds'];
  7251. // return Result::success($cat_1st_arr);
  7252. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7253. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7254. })
  7255. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7256. $query->whereIn('category_id', $categoryIds);
  7257. })
  7258. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7259. $query->where('category_id', $category_id);
  7260. })
  7261. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7262. ->orderBy('updated_at', 'desc')
  7263. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7264. if (empty($company)) {
  7265. return Result::error("暂无相关公司信息", 0);
  7266. }
  7267. $result = [
  7268. 'count' => $company->total(),
  7269. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7270. ];
  7271. return Result::success($result);
  7272. }
  7273. /**
  7274. * 获取项目列表
  7275. * @param array $data
  7276. * @return array
  7277. */
  7278. public function getProjectList(array $data): array
  7279. {
  7280. $where = [];
  7281. $user = User::where('id', $data['user_id'])->first();
  7282. if (empty($user)) {
  7283. return Result::error('用户不存在!');
  7284. }
  7285. if ($user->type_id != 10000) {
  7286. array_push($where, ['project.user_id', $data['user_id']]);
  7287. }
  7288. $query = Project::query();
  7289. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7290. array_push($where, ['project.website_id', $data['website_id']]);
  7291. }
  7292. if (isset($data['title']) && !empty($data['title'])) {
  7293. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7294. }
  7295. if ($data['status'] != 3) {
  7296. array_push($where, ['project.status', $data['status']]);
  7297. }
  7298. $query = Project::where($where)
  7299. ->when($data['status'] == 3, function ($query) {
  7300. $query->whereIn('project.status', [0, 2]);
  7301. });
  7302. $count = $query->clone()
  7303. ->count();
  7304. $rows = $query->clone()
  7305. ->leftJoin('website', 'project.website_id', 'website.id')
  7306. ->leftJoin('website_category', function ($join) {
  7307. $join->on('project.website_id', '=', 'website_category.website_id')
  7308. ->on('project.category_id', '=', 'website_category.category_id');
  7309. })
  7310. ->select(
  7311. 'project.id',
  7312. 'project.title',
  7313. 'project.updated_at',
  7314. 'project.status',
  7315. 'website.website_name',
  7316. 'website_category.alias as category_name',
  7317. 'project.website_id',
  7318. 'project.user_id'
  7319. )
  7320. ->orderBy('project.updated_at', 'desc')
  7321. ->offset(($data['page'] - 1) * $data['pageSize'])
  7322. ->limit($data['pageSize'])
  7323. ->get();
  7324. if ($rows->isEmpty()) {
  7325. return Result::error("暂无相关项目信息", 0);
  7326. }
  7327. $result = [
  7328. 'count' => $count,
  7329. 'rows' => $rows,
  7330. ];
  7331. return Result::success($result);
  7332. }
  7333. /**
  7334. * 添加项目
  7335. * @param array $data
  7336. * @return array
  7337. */
  7338. public function addProject(array $data): array
  7339. {
  7340. $user = User::where('id', $data['user_id'])->first();
  7341. if (empty($user)) {
  7342. return Result::error("暂无相关用户信息", 0);
  7343. }
  7344. if ($user->type_id == 10000) {
  7345. $data['status'] = 1;
  7346. } else {
  7347. $data['status'] = 0;
  7348. }
  7349. if ($data['keyword'] == '') {
  7350. //提取标题+内容中的关键词
  7351. $data['keyword'] = $data['title'];
  7352. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7353. Jieba::init(); // 初始化 jieba-php
  7354. Finalseg::init();
  7355. $segList = Jieba::cut($data['keyword']);
  7356. $segList1 = array_slice($segList, 0, 8);
  7357. $data['keyword'] = implode(',', $segList1);
  7358. }
  7359. if ($data['description'] == '') {
  7360. //提取内容中的描述
  7361. // var_dump(11111);
  7362. //提取内容中的描述
  7363. $content = $data['introduce'];
  7364. // 去除 <style> 和 <script> 标签及其内容
  7365. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7366. // 去除所有 HTML 标签
  7367. $content = strip_tags($content);
  7368. // 去除 HTML 实体
  7369. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7370. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7371. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7372. // 去除多余空白
  7373. $content = preg_replace('/\s+/u', '', $content);
  7374. // 截取 100 个字符
  7375. $data['description'] = mb_substr($content, 0, 100);
  7376. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7377. }
  7378. if ($data['status'] == 0) {
  7379. $this->sendMessage([
  7380. 'talk_type' => 1000,
  7381. 'title' => $data['title'],
  7382. 'content' => '提交了审核',
  7383. 'messageType' => 9,
  7384. ]);
  7385. }
  7386. $project = Project::insertGetId($data);
  7387. if (empty($project)) {
  7388. return Result::error("暂无相关项目信息", 0);
  7389. }
  7390. return Result::success($project);
  7391. }
  7392. /**
  7393. * 更新项目
  7394. * @param array $data
  7395. * @return array
  7396. */
  7397. public function upProject(array $data): array
  7398. {
  7399. $project = Project::where('id', $data['id'])->first();
  7400. if (empty($project)) {
  7401. return Result::error("暂无相关项目信息", 0);
  7402. }
  7403. $id = $data['id'];
  7404. unset($data['id']);
  7405. $user = User::where('id', $data['user_id'])->first();
  7406. if (empty($user)) {
  7407. return Result::error("暂无相关用户信息", 0);
  7408. }
  7409. if ($user->type_id == 10000) {
  7410. $data['status'] = 1;
  7411. } else {
  7412. $data['status'] = 0;
  7413. }
  7414. unset($data['user_id']);
  7415. if ($data['keyword'] == '') {
  7416. //提取标题+内容中的关键词
  7417. $data['keyword'] = $data['title'];
  7418. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7419. Jieba::init(); // 初始化 jieba-php
  7420. Finalseg::init();
  7421. $segList = Jieba::cut($data['keyword']);
  7422. $segList1 = array_slice($segList, 0, 8);
  7423. $data['keyword'] = implode(',', $segList1);
  7424. }
  7425. if ($data['description'] == '') {
  7426. //提取内容中的描述
  7427. // var_dump(11111);
  7428. //提取内容中的描述
  7429. $content = $data['introduce'];
  7430. // 去除 <style> 和 <script> 标签及其内容
  7431. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7432. // 去除所有 HTML 标签
  7433. $content = strip_tags($content);
  7434. // 去除 HTML 实体
  7435. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7436. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7437. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7438. // 去除多余空白
  7439. $content = preg_replace('/\s+/u', '', $content);
  7440. // 截取 100 个字符
  7441. $data['description'] = mb_substr($content, 0, 100);
  7442. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7443. }
  7444. if ($data['status'] == 0) {
  7445. $this->sendMessage([
  7446. 'talk_type' => 1000,
  7447. 'title' => $data['title'],
  7448. 'content' => '提交了审核',
  7449. 'messageType' => 9,
  7450. ]);
  7451. }
  7452. $result = Project::where('id', $id)->update($data);
  7453. if (empty($result)) {
  7454. return Result::error("更新失败", 0);
  7455. }
  7456. return Result::success($result);
  7457. }
  7458. /**
  7459. * 删除项目
  7460. * @param array $data
  7461. * @return array
  7462. */
  7463. public function delProject(array $data): array
  7464. {
  7465. $user = User::where('id', $data['user_id'])->first();
  7466. if (empty($user)) {
  7467. return Result::error("暂无相关用户信息", 0);
  7468. }
  7469. $project = Project::where('id', $data['id'])->first();
  7470. if (empty($project)) {
  7471. return Result::error("暂无相关项目信息", 0);
  7472. }
  7473. $result = Project::where('id', $data['id'])->delete();
  7474. if (empty($result)) {
  7475. return Result::error("删除失败", 0);
  7476. }
  7477. return Result::success($result);
  7478. }
  7479. /**
  7480. * 审核项目
  7481. * @param array $data
  7482. * @return array
  7483. */
  7484. public function checkProject(array $data): array
  7485. {
  7486. $user = User::where('id', $data['user_id'])->first();
  7487. if (empty($user)) {
  7488. return Result::error("暂无相关用户信息", 0);
  7489. }
  7490. // 0:未审核; 1:已审核; 2:已拒绝;
  7491. if ($user->type_id != 10000) {
  7492. if ($data['status'] == 1 || $data['status'] == 2) {
  7493. return Result::error("此用户权限不足", 0);
  7494. }
  7495. }
  7496. $project = Project::where('id', $data['id'])->first();
  7497. if (empty($project)) {
  7498. return Result::error("暂无相关项目信息", 0);
  7499. }
  7500. if ($data['status'] == 2) {
  7501. $this->sendMessage([
  7502. 'talk_type' => 1001,
  7503. 'title' => $project['title'],
  7504. 'content' => '审核拒绝',
  7505. 'messageType' => 9,
  7506. 'user_id' => $project['user_id'],
  7507. ]);
  7508. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7509. } else {
  7510. if ($data['status'] == 1) {
  7511. $this->sendMessage([
  7512. 'talk_type' => 1001,
  7513. 'title' => $project['title'],
  7514. 'content' => '审核通过',
  7515. 'messageType' => 9,
  7516. 'user_id' => $project['user_id'],
  7517. ]);
  7518. } else if ($data['status'] == 0) {
  7519. $this->sendMessage([
  7520. 'talk_type' => 1000,
  7521. 'title' => $project['title'],
  7522. 'content' => '提交了审核',
  7523. 'messageType' => 9,
  7524. ]);
  7525. }
  7526. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7527. }
  7528. if (empty($result)) {
  7529. return Result::error("审核失败", 0);
  7530. }
  7531. return Result::success($result);
  7532. }
  7533. /**
  7534. * 获取项目详情
  7535. * @param array $data
  7536. * @return array
  7537. */
  7538. public function getProjectInfo(array $data): array
  7539. {
  7540. $project = Project::where('id', $data['id'])->first();
  7541. if (empty($project)) {
  7542. return Result::error("暂无相关项目信息", 0);
  7543. }
  7544. return Result::success($project);
  7545. }
  7546. public function getWebsiteCompanyInfo(array $data): array
  7547. {
  7548. $company = Company::where('id', $data['id'])
  7549. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7550. ->where('status', 1)
  7551. // ->where('website_id', $data['website_id'])
  7552. ->select('company.*', 'job_industry.hyname as hy_name')
  7553. ->first();
  7554. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7555. switch ($company->jobnature_id) {
  7556. case null:
  7557. $company->jobnature_name = '';
  7558. break;
  7559. case 0:
  7560. $company->jobnature_name = '市场监督';
  7561. break;
  7562. case 1:
  7563. $company->jobnature_name = '信访纪检';
  7564. break;
  7565. case 2:
  7566. $company->jobnature_name = '公检法司';
  7567. break;
  7568. case 3:
  7569. $company->jobnature_name = '高关注机构';
  7570. break;
  7571. default:
  7572. $company->jobnature_name = '';
  7573. break;
  7574. }
  7575. $city_arr = $company->city_arr_id;
  7576. if (!empty($city_arr)) {
  7577. $city_arr = json_decode($city_arr, true);
  7578. $cityNames = District::whereIn('id', $city_arr)
  7579. ->pluck('name')
  7580. ->implode('-');
  7581. $company->city_name = $cityNames;
  7582. } else {
  7583. $company->city_name = '';
  7584. }
  7585. if (empty($company)) {
  7586. return Result::error("暂无相关公司信息", 0);
  7587. }
  7588. return Result::success($company);
  7589. }
  7590. public function getMSG(array $data): array
  7591. {
  7592. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7593. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7594. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7595. $result = [];
  7596. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7597. //最近的5篇已审的文章
  7598. $apply_articale = Article::where('status', 1)
  7599. ->where('admin_user_id', $user_id)
  7600. ->orderBy('updated_at', 'desc')
  7601. // ->limit(5)
  7602. ->get();
  7603. //获取5条用户的已审核商品
  7604. $good = Good::where('status', 2)
  7605. ->where('user_id', $user_id)
  7606. ->orderBy('updated_at', 'desc')
  7607. // ->limit(5)
  7608. ->get();
  7609. //获取5条用户待审核的公告
  7610. $notice = Notice::where('status', 2)
  7611. ->where('user_id', $user_id)
  7612. ->orderBy('updated_at', 'desc')
  7613. ->limit(5)->get();
  7614. //获取5条用户的待审核投诉
  7615. $complaint = Complaint::where('status', 2)
  7616. ->where('user_id', $user_id)
  7617. ->orderBy('updated_at', 'desc')
  7618. // ->limit(5)
  7619. ->get();
  7620. //获取5条用户的book
  7621. $book = Book::where('status', 2)
  7622. ->where('user_id', $user_id)
  7623. ->orderBy('updated_at', 'desc')
  7624. // ->limit(5)
  7625. ->get();
  7626. //获取5条用户的求职
  7627. //获取5条用户的求职 1
  7628. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7629. ->where('job_hunting.user_id', $user_id)
  7630. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7631. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7632. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7633. ->orderBy('updated_at', 'desc')
  7634. // ->limit(5)
  7635. ->get();
  7636. //获取5条用户的求职 2
  7637. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7638. ->where('job_recruiting.user_id', $user_id)
  7639. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7640. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7641. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7642. ->orderBy('updated_at', 'desc')
  7643. // ->limit(5)
  7644. ->get();
  7645. //人才库 1
  7646. $job_apply = JobApply::where('job_apply.status', 1)
  7647. ->where('job_apply.receiver_id', $user_id)
  7648. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7649. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7650. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7651. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7652. ->select('job_recruiting', 'job_recruiting.', '', '')
  7653. ->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')
  7654. ->orderBy('updated_at', 'desc')
  7655. // ->limit(5)
  7656. ->get();
  7657. // 职场机会 2
  7658. $job_resume = JobResume::where('job_resume.status', 1)
  7659. ->where('job_resume.receiver_id', $user_id)
  7660. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7661. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7662. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7663. ->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')
  7664. ->orderBy('updated_at', 'desc')
  7665. // ->limit(5)
  7666. ->get();
  7667. //获取5条用户待处理的投诉
  7668. $complaint_deal = Complaint::where('status', 2)
  7669. ->where('deal', 1)
  7670. ->whereJsonContains('re_user_ids', $user_id)
  7671. ->orderBy('updated_at', 'desc')
  7672. // ->limit(5)
  7673. ->get();
  7674. //获取 被通知者未读信息
  7675. $notice_unread = Notice::where('status', 2)
  7676. ->whereJsonContains('re_user_ids', $user_id)
  7677. //未读消息
  7678. ->where(function ($query) use ($user_id) {
  7679. $query->whereJsonDoesntContain('read_id', $user_id)
  7680. ->orWhereNull('read_id');
  7681. })
  7682. ->orderBy('updated_at', 'desc')
  7683. ->get();
  7684. $complaint_unread = Complaint::where('status', 2)
  7685. ->whereJsonContains('re_user_ids', $user_id)
  7686. //未读消息
  7687. ->where(function ($query) use ($user_id) {
  7688. $query->whereJsonDoesntContain('read_id', $user_id)
  7689. ->orWhereNull('read_id');
  7690. })
  7691. ->orderBy('updated_at', 'desc')
  7692. ->get();
  7693. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7694. $complany = Company::where('status', 1)
  7695. ->where('user_id', $user_id)
  7696. ->orderBy('updated_at', 'desc')
  7697. // ->limit(5)
  7698. ->get();
  7699. //获取5条单聊未读聊天消息
  7700. // $chat = ChatRecords::where('is_read', 0)
  7701. // ->where('user_id', $user_id)
  7702. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7703. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7704. // ->where('action', 'recieved')
  7705. // ->where('talk_type', 1)
  7706. // ->orderBy('created_at', 'desc')
  7707. // // ->limit(5)
  7708. // ->get();
  7709. //获取5条未读群聊信息
  7710. // $chat_group = ChatRecords::where('is_read', 0)
  7711. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7712. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7713. // ->where('user_id', $user_id)
  7714. // ->where('talk_type', 2)
  7715. // ->orderBy('created_at', 'desc')
  7716. // // ->limit(5)
  7717. // ->get();
  7718. //获取5条用户的待审核项目
  7719. $project = Project::where('status', 1)
  7720. ->where('user_id', $user_id)
  7721. ->orderBy('updated_at', 'desc')
  7722. // ->limit(5)
  7723. ->get();
  7724. // count($chat) + count($chat_group) +
  7725. $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)
  7726. + count($complany)
  7727. + count($project)
  7728. + count($notice_unread)
  7729. + count($complaint_unread)
  7730. // + count($chat) + count($chat_group)
  7731. ;
  7732. $result = [
  7733. 'apply_articale' => $apply_articale,
  7734. // 'chat' => $chat,
  7735. // 'chat_group' => $chat_group,
  7736. 'good' => $good,
  7737. 'notice' => $notice,
  7738. 'complaint' => $complaint,
  7739. 'book' => $book,
  7740. 'job_hunting' => $job_hunting,
  7741. 'job_recruiting' => $job_recruiting,
  7742. 'job_apply' => $job_apply,
  7743. 'job_resume' => $job_resume,
  7744. 'complaint_deal' => $complaint_deal,
  7745. 'complany' => $complany,
  7746. 'project' => $project,
  7747. 'notice_unread' => $notice_unread,
  7748. 'complaint_unread' => $complaint_unread,
  7749. 'count' => $count,
  7750. ];
  7751. } elseif ($type_id == 12) {
  7752. //最近的5篇已审的文章
  7753. $apply_articale = Article::where('status', 1)
  7754. ->where('admin_user_id', $user_id)
  7755. ->limit(5)->get();
  7756. //获取5条单聊未读聊天消息
  7757. $chat = ChatRecords::where('is_read', 0)
  7758. ->where('user_id', $user_id)
  7759. ->where('talk_type', 1)
  7760. ->orderBy('created_at', 'desc')
  7761. ->limit(5)->get();
  7762. //获取5条未读群聊信息
  7763. $chat_group = ChatRecords::where('is_read', 0)
  7764. ->where('user_id', $user_id)
  7765. ->where('talk_type', 2)
  7766. ->orderBy('created_at', 'desc')
  7767. ->limit(5)->get();
  7768. //获取5条用户的已审核商品
  7769. $good = Good::where('status', 2)
  7770. ->where('user_id', $user_id)
  7771. ->orderBy('updated_at', 'desc')
  7772. ->limit(5)->get();
  7773. //获取5条用户的book
  7774. $book = Book::where('status', 2)
  7775. ->where('user_id', $user_id)
  7776. ->orderBy('updated_at', 'desc')
  7777. ->limit(5)->get();
  7778. //获取5条用户的求职
  7779. //获取5条用户的求职 1
  7780. //count($chat) + count($chat_group)
  7781. $count = count($apply_articale) + count($good);
  7782. $result = [
  7783. 'apply_articale' => $apply_articale,
  7784. 'chat' => $chat,
  7785. 'chat_group' => $chat_group,
  7786. 'good' => $good,
  7787. 'book' => $book,
  7788. 'count' => $count,
  7789. ];
  7790. } elseif ($type_id == 13) {
  7791. //最近的5篇已审的文章
  7792. $apply_articale = Article::where('status', 1)
  7793. ->where('admin_user_id', $user_id)
  7794. ->limit(5)->get();
  7795. //获取5条单聊未读聊天消息
  7796. $chat = ChatRecords::where('is_read', 0)
  7797. ->where('user_id', $user_id)
  7798. ->where('talk_type', 1)
  7799. ->orderBy('created_at', 'desc')
  7800. ->limit(5)->get();
  7801. //获取5条未读群聊信息
  7802. $chat_group = ChatRecords::where('is_read', 0)
  7803. ->where('user_id', $user_id)
  7804. ->where('talk_type', 2)
  7805. ->orderBy('created_at', 'desc')
  7806. ->limit(5)->get();
  7807. //获取5条用户的已审核商品
  7808. $good = Good::where('status', 2)
  7809. ->where('user_id', $user_id)
  7810. ->orderBy('updated_at', 'desc')
  7811. ->limit(5)->get();
  7812. //count($chat) + count($chat_group) +
  7813. $count = count($apply_articale) + count($good);
  7814. $result = [
  7815. 'apply_articale' => $apply_articale,
  7816. 'chat' => $chat,
  7817. 'chat_group' => $chat_group,
  7818. 'good' => $good,
  7819. 'count' => $count,
  7820. ];
  7821. } elseif ($type_id == 14) {
  7822. //最近的5篇已审的文章
  7823. $apply_articale = Article::where('status', 1)
  7824. ->where('admin_user_id', $user_id)
  7825. // ->limit(5)
  7826. ->get();
  7827. //获取5条用户的已审核商品
  7828. $good = Good::where('status', 2)
  7829. ->where('user_id', $user_id)
  7830. ->orderBy('updated_at', 'desc')
  7831. // ->limit(5)
  7832. ->get();
  7833. $count = count($apply_articale) + count($good);
  7834. $result = [
  7835. 'apply_articale' => $apply_articale,
  7836. 'chat' => '',
  7837. 'chat_group' => '',
  7838. 'good' => $good,
  7839. 'count' => $count,
  7840. ];
  7841. } elseif ($type_id == 10000) {
  7842. //获取未审核的5篇文章
  7843. $apply_articale = Article::where('status', 0)
  7844. ->orderBy('updated_at', 'desc')
  7845. // ->limit(5)
  7846. ->get();
  7847. //获取5条单聊未读聊天消息
  7848. //获取5条单聊未读聊天消息
  7849. // $chat = ChatRecords::where('is_read', 0)
  7850. // ->where('user_id', $user_id)
  7851. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7852. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7853. // ->where('action', 'recieved')
  7854. // ->where('talk_type', 1)
  7855. // ->orderBy('created_at', 'desc')
  7856. // // ->limit(5)
  7857. // ->get();
  7858. // //获取5条未读群聊信息
  7859. // $chat_group = ChatRecords::where('is_read', 0)
  7860. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7861. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7862. // ->where('user_id', $user_id)
  7863. // ->where('talk_type', 2)
  7864. // ->orderBy('created_at', 'desc')
  7865. // // ->limit(5)
  7866. // ->get();
  7867. //获取5条用户的已审核商品
  7868. $good = Good::where('status', 1)
  7869. // ->where('user_id', $user_id)
  7870. ->orderBy('updated_at', 'desc')
  7871. // ->limit(5)
  7872. ->get();
  7873. //获取5条用户待审核的公告
  7874. $notice = Notice::where('status', 1)
  7875. ->orderBy('updated_at', 'desc')
  7876. // ->limit(5)
  7877. ->get();
  7878. //获取5条用户的待审核投诉
  7879. $complaint = Complaint::where('status', 1)
  7880. ->orderBy('updated_at', 'desc')
  7881. // ->limit(5)
  7882. ->get();
  7883. //获取5条用户的book
  7884. $book = Book::where('status', 1)
  7885. ->orderBy('updated_at', 'desc')
  7886. // ->limit(5)
  7887. ->get();
  7888. //获取5条用户的求职 1
  7889. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7890. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7891. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7892. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7893. ->orderBy('updated_at', 'desc')
  7894. // ->limit(5)
  7895. ->get();
  7896. //获取5条用户的求职 2
  7897. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7898. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7899. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7900. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7901. ->orderBy('updated_at', 'desc')
  7902. // ->limit(5)
  7903. ->get();
  7904. //人才库 1
  7905. $job_apply = JobApply::where('job_apply.status', 1)
  7906. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7907. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7908. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7909. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7910. ->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')
  7911. ->orderBy('updated_at', 'desc')
  7912. // ->limit(5)
  7913. ->get();
  7914. // 职场机会 2
  7915. $job_resume = JobResume::where('job_resume.status', 1)
  7916. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7917. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7918. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7919. ->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')
  7920. ->orderBy('updated_at', 'desc')
  7921. // ->limit(5)
  7922. ->get();
  7923. //待审核数据com pro
  7924. $complany = Company::where('status', 0)
  7925. ->orderBy('updated_at', 'desc')
  7926. // ->limit(5)
  7927. ->get();
  7928. $project = Project::where('status', 0)
  7929. ->orderBy('updated_at', 'desc')
  7930. // ->limit(5)
  7931. ->get();
  7932. $count =
  7933. // count($chat) +
  7934. // count($chat_group) +
  7935. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7936. // + count($job_apply)
  7937. // + count($job_resume)
  7938. + count($complany)
  7939. + count($project);
  7940. $result = [
  7941. 'apply_articale' => $apply_articale,
  7942. // 'chat' => $chat,
  7943. // 'chat_group' => $chat_group,
  7944. 'good' => $good,
  7945. 'notice' => $notice,
  7946. 'complaint' => $complaint,
  7947. 'book' => $book,
  7948. 'job_hunting' => $job_hunting,
  7949. 'job_recruiting' => $job_recruiting,
  7950. // 'job_apply' => $job_apply,
  7951. // 'job_resume' => $job_resume,
  7952. 'complany' => $complany,
  7953. 'project' => $project,
  7954. 'count' => $count,
  7955. ];
  7956. } elseif ($type_id == 20000) {
  7957. }
  7958. var_dump($type_id, '-----------------test---------');
  7959. return Result::success($result);
  7960. }
  7961. /**
  7962. * @param array $data
  7963. * @return array
  7964. */
  7965. public function getWebsiteProject(array $data): array
  7966. {
  7967. $categorys = json_decode($data['id'], true);
  7968. if (!empty($categorys)) {
  7969. $category_arr = $this->processArticlePro($data['website_id']);
  7970. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7971. $catiall = $category_arr['catiall'];
  7972. // return Result::success($catiall);
  7973. foreach ($categorys as $key => $val) {
  7974. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7975. $level = explode(',', $val['level'])[0];
  7976. $imgnum = explode(',', $val['level'])[1] ?? null;
  7977. $textnum = explode(',', $val['level'])[2] ?? null;
  7978. if ($level == 1) {
  7979. if (!empty($textnum) && $textnum > 0) {
  7980. $text_num = Project::where('level', $level)
  7981. ->where('website_id', $data['website_id'])
  7982. ->where('status', 1)
  7983. ->select(
  7984. 'project.id',
  7985. 'project.title',
  7986. 'project.description',
  7987. 'project.updated_at',
  7988. 'project.category_id',
  7989. 'project.cat_arr_id'
  7990. )
  7991. ->orderBy('updated_at', 'desc')
  7992. ->limit($textnum)
  7993. ->get()->all();
  7994. }
  7995. if (!empty($imgnum) && $imgnum > 0) {
  7996. $img_num = Project::where('level', $level)
  7997. ->where('website_id', $data['website_id'])
  7998. ->where('status', 1)
  7999. ->where('imgurl', '!=', '')
  8000. ->whereNotNull('imgurl')
  8001. ->select(
  8002. 'project.id',
  8003. 'project.title',
  8004. 'project.description',
  8005. 'project.updated_at',
  8006. 'project.imgurl as imgs',
  8007. 'project.category_id',
  8008. 'project.cat_arr_id'
  8009. )
  8010. ->orderBy('updated_at', 'desc')
  8011. ->limit($imgnum)
  8012. ->get()->all();
  8013. }
  8014. } else {
  8015. if (!empty($textnum) && $textnum > 0) {
  8016. $text_num = Project::where('website_id', $data['website_id'])
  8017. ->where('status', 1)
  8018. ->select(
  8019. 'project.id',
  8020. 'project.title',
  8021. 'project.description',
  8022. 'project.updated_at',
  8023. 'project.category_id',
  8024. 'project.cat_arr_id',
  8025. 'project.website_id',
  8026. 'project.updated_at',
  8027. 'project.created_at'
  8028. )
  8029. ->orderBy('updated_at', 'desc')
  8030. ->limit($textnum)
  8031. ->get()->all();
  8032. }
  8033. if (!empty($imgnum) && $imgnum > 0) {
  8034. $img_num = Project::where('website_id', $data['website_id'])
  8035. ->where('status', 1)
  8036. ->where('imgurl', '!=', '')
  8037. ->whereNotNull('imgurl')
  8038. ->select(
  8039. 'project.id',
  8040. 'project.title',
  8041. 'project.description',
  8042. 'project.updated_at',
  8043. 'project.imgurl as imgs',
  8044. 'project.category_id',
  8045. 'project.cat_arr_id'
  8046. )
  8047. ->orderBy('updated_at', 'desc')
  8048. ->limit($imgnum)
  8049. ->get()->all();
  8050. }
  8051. }
  8052. }
  8053. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8054. $category_ids = explode(',', $val['id'])[0];
  8055. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8056. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8057. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8058. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8059. $text_num = Project::whereIn('category_id', $category_arr)
  8060. ->where('website_id', $data['website_id'])
  8061. ->where('status', 1)
  8062. ->select(
  8063. 'project.id',
  8064. 'project.title',
  8065. 'project.description',
  8066. 'project.updated_at',
  8067. 'project.category_id',
  8068. 'project.cat_arr_id'
  8069. )
  8070. ->orderBy('updated_at', 'desc')
  8071. ->limit($cat_textnum)
  8072. ->get()->all();
  8073. }
  8074. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8075. $img_num = Project::whereIn('category_id', $category_arr)
  8076. ->where('website_id', $data['website_id'])
  8077. ->where('status', 1)
  8078. ->where('imgurl', '!=', '')
  8079. ->whereNotNull('imgurl')
  8080. ->select(
  8081. 'project.id',
  8082. 'project.title',
  8083. 'project.description',
  8084. 'project.updated_at',
  8085. 'project.imgurl as imgs',
  8086. 'project.category_id',
  8087. 'project.cat_arr_id'
  8088. )
  8089. ->orderBy('updated_at', 'desc')
  8090. ->limit($cat_imgnum)
  8091. ->get()->all();
  8092. }
  8093. }
  8094. if (!empty($img_num)) {
  8095. foreach ($img_num as $k => $v) {
  8096. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8097. $imgurl = json_decode($v['imgs'], true);
  8098. if (!empty($imgurl)) {
  8099. $img_num[$k]->imgurl = $imgurl[0];
  8100. }
  8101. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8102. }
  8103. }
  8104. if (!empty($text_num)) {
  8105. foreach ($text_num as $k => $v) {
  8106. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8107. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8108. }
  8109. }
  8110. $project[$key]['img_num'] = $img_num ?? [];
  8111. $project[$key]['text_num'] = $text_num ?? [];
  8112. }
  8113. }
  8114. if (empty($project)) {
  8115. return Result::error("暂无相关项目信息", 0);
  8116. }
  8117. return Result::success($project);
  8118. }
  8119. /**
  8120. * @param array $data
  8121. * @return array
  8122. */
  8123. public function getWebsiteProjectInfo(array $data): array
  8124. {
  8125. $project = Project::where('id', $data['id'])
  8126. ->where('status', 1)
  8127. ->where('website_id', $data['website_id'])
  8128. ->select('project.*')
  8129. ->first();
  8130. if (empty($project)) {
  8131. return Result::error("暂无相关项目信息", 0);
  8132. }
  8133. return Result::success($project);
  8134. }
  8135. /**
  8136. * @param array $data
  8137. * @return array
  8138. */
  8139. public function getWebsiteProjectList(array $data): array
  8140. {
  8141. $where = [];
  8142. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8143. $where['category_id'] = $data['category_id'];
  8144. }
  8145. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8146. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8147. }
  8148. $query = Project::where($where)
  8149. ->where('status', 1)
  8150. ->where('website_id', $data['website_id'])
  8151. ->select(
  8152. 'project.id',
  8153. 'project.title',
  8154. 'project.description',
  8155. 'project.imgurl as imgs',
  8156. 'project.category_id',
  8157. 'project.cat_arr_id'
  8158. )
  8159. ->orderBy('updated_at', 'desc');
  8160. $count = $query->count();
  8161. $project = $query->clone()
  8162. ->offset(($data['page'] - 1) * $data['pageSize'])
  8163. ->limit($data['pageSize'])
  8164. ->get()->all();
  8165. if (empty($project)) {
  8166. return Result::error("暂无相关项目信息", 0);
  8167. }
  8168. $categorys = $this->processArticlePro($data['website_id']);
  8169. $catiall = $categorys['catiall'];
  8170. foreach ($project as $key => $val) {
  8171. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8172. if (!empty($val['imgs'])) {
  8173. $imgurl = json_decode($val['imgs'], true);
  8174. if (!empty($imgurl)) {
  8175. $project[$key]->imgurl = $imgurl[0];
  8176. }
  8177. } else {
  8178. $project[$key]->imgurl = '';
  8179. }
  8180. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8181. }
  8182. $result = [
  8183. 'rows' => $project,
  8184. 'count' => $count,
  8185. ];
  8186. return Result::success($result);
  8187. }
  8188. /**
  8189. * @param array $data
  8190. * @return array
  8191. */
  8192. public function getWebsiteCategoryJob(array $data): array
  8193. {
  8194. $categorys = json_decode($data['id'], true);
  8195. if (!empty($categorys)) {
  8196. $category_arr = $this->processArticlePro($data['website_id']);
  8197. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8198. $catiall = $category_arr['catiall'];
  8199. foreach ($categorys as $key => $val) {
  8200. if (isset($val['id']) && !empty($val['id'])) {
  8201. $catid = explode(',', $val['id'])[0] ?? null;
  8202. $type = explode(',', $val['id'])[1] ?? null;
  8203. $textnum = explode(',', $val['id'])[2] ?? null;
  8204. }
  8205. // 4:招聘;5:求职;
  8206. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8207. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8208. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8209. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8210. ->where('job_recruiting.status', 1)
  8211. ->where('job_recruiting.website_id', $data['website_id'])
  8212. ->select(
  8213. 'job_recruiting.id',
  8214. 'job_recruiting.title',
  8215. 'job_company.business_name',
  8216. 'job_recruiting.updated_at',
  8217. 'job_recruiting.cat_arr_id',
  8218. 'job_recruiting.keyword',
  8219. 'job_recruiting.description'
  8220. )
  8221. ->orderBy('job_recruiting.updated_at', 'desc')
  8222. ->limit($textnum)
  8223. ->get()->all();
  8224. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8225. // 状态 审核状态,1待审核2已审核3已拒绝
  8226. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8227. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8228. ->where('job_hunting.status', 2)
  8229. ->where('job_hunting.website_id', $data['website_id'])
  8230. ->select(
  8231. 'job_hunting.id',
  8232. 'job_hunting.name',
  8233. 'job_hunting.cat_arr_id',
  8234. 'job_position.zwname as job_name',
  8235. 'job_hunting.updated_at',
  8236. 'job_hunting.keyword',
  8237. 'job_hunting.slelf_evaluation'
  8238. )
  8239. ->orderBy('updated_at', 'desc')
  8240. ->limit($textnum)
  8241. ->get()->all();
  8242. } else {
  8243. $job = [];
  8244. }
  8245. // var_dump($catid.'222uuuuuuu'.$key);
  8246. if (!empty($job)) {
  8247. foreach ($job as $k => $value) {
  8248. if (isset($value->cat_arr_id)) {
  8249. $catArr = json_decode($value->cat_arr_id, true);
  8250. $catId = end($catArr);
  8251. } else {
  8252. continue;
  8253. }
  8254. if (isset($catiall[$catId])) {
  8255. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8256. }
  8257. }
  8258. }
  8259. // var_dump($catid.'xxxxx'.$key);
  8260. $result[$key] = $job ?? [];
  8261. }
  8262. }
  8263. if (empty($result)) {
  8264. return Result::error("暂无相关分类信息", 0);
  8265. }
  8266. return Result::success($result);
  8267. }
  8268. /**
  8269. * 发送消息
  8270. * @param array $messageData
  8271. * @return void
  8272. */
  8273. public function sendMessage($messageData)
  8274. {
  8275. $msg = [
  8276. 'talk_type' => $messageData['talk_type'],
  8277. 'title' => $messageData['title'],
  8278. 'content' => $messageData['content'],
  8279. 'messageType' => $messageData['messageType'],
  8280. 'user_id' => $messageData['user_id'] ?? '',
  8281. 'time' => microtime(),
  8282. ];
  8283. $message = new MqProducer($msg);
  8284. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8285. $producer->produce($message);
  8286. }
  8287. }