NewsService.php 313 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536
  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'])->whereIn('website_id',$website_ids)->update(['is_ignore' => 1]);
  1049. }else{
  1050. // ------c_show_time********up_status*******
  1051. // 若是审核通过 则更新c_show_time
  1052. if($data['status'] == 1){
  1053. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1054. $web = Article::where('article.id',$data['id'])
  1055. ->leftJoin('website_category','article.catid','website_category.category_id')
  1056. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1057. ->select('website_id',
  1058. 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'))
  1059. ->get();
  1060. // 非核心站与核心站----显示时间-----间隔
  1061. $time = 20;
  1062. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1063. $waiting_interval = 5;
  1064. $webArray = $web->toArray();
  1065. if(empty($webArray)){
  1066. throw new \Exception('网站分类不存在');
  1067. }
  1068. // 直接使用当前系统时间,不再强制添加8小时
  1069. $now = date('Y-m-d H:i:s');
  1070. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1071. // 检查 $item 对象是否有 is_core 属性
  1072. if (!isset($item['is_core'])) {
  1073. throw new \Exception('$item 对象缺少 is_core 属性');
  1074. }
  1075. // 当 is_core 为 2 时,则表示此网站不存在
  1076. if ($item['is_core'] == 2) {
  1077. return null;
  1078. }else if($item['is_core'] == 1){
  1079. // 当 is_core 为 1 时,则表示此网站是核心站
  1080. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  1081. }else{
  1082. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1083. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1084. if ($item['is_core'] == 0) {
  1085. $time += $waiting_interval;
  1086. }
  1087. }
  1088. return [
  1089. 'article_id' => $data['id'],
  1090. 'website_id' => $item['website_id'],
  1091. 'c_show_time' => $c_show_time,
  1092. ];
  1093. }, array_keys($webArray), $webArray)));
  1094. if(!empty($article_ignore)){
  1095. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1096. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1097. $article_ignores = ArticleIgnore::upsert(
  1098. $article_ignore,
  1099. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1100. ['c_show_time'] // 需要更新的字段
  1101. );
  1102. if(!$article_ignores){
  1103. throw new \Exception('c端展示时间插入失败');
  1104. }
  1105. }
  1106. }
  1107. // ------c_show_time********up_status*******
  1108. }
  1109. if ($result) {
  1110. return Result::success();
  1111. } else {
  1112. return Result::error("更新状态失败", 0);
  1113. }
  1114. }
  1115. /**
  1116. * 获取新闻详情
  1117. * @param array $data
  1118. * @return array
  1119. */
  1120. public function getArticleInfo(array $data): array
  1121. {
  1122. $where = [
  1123. 'article.id' => $data['id'],
  1124. // 'article.status' => 1,
  1125. ];
  1126. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1127. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1128. $info = $result;
  1129. // var_dump($info, 'info');
  1130. $info['survey_array'] = $articleSurvey;
  1131. if ($result) {
  1132. return Result::success($info);
  1133. } else {
  1134. return Result::error("查询失败", 0);
  1135. }
  1136. }
  1137. /**
  1138. * 获取头条新闻
  1139. * @param array $data
  1140. * @return array
  1141. */
  1142. public function getWebsiteArticlett(array $data): array
  1143. {
  1144. $website_id = $data['website_id'];
  1145. $website = Website::where('id', $data['website_id'])->first();
  1146. if (empty($website)) {
  1147. return Result::error("网站不存在", 0);
  1148. }
  1149. $categorys = $this->processArticlePro($website_id);
  1150. $catiall = $categorys['catiall'];
  1151. $categoryIds = $categorys['categoryIds'];
  1152. $where = [
  1153. 'status' => 1
  1154. ];
  1155. // $website_column = $website['column'];
  1156. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1157. $website_column = json_decode($website['website_column_arr_id'], true);
  1158. }
  1159. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1160. // return Result::success($diff_pid_categoryIds);
  1161. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1162. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1163. }
  1164. // $website_id = $data['website_id'];
  1165. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1166. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1167. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1168. switch ($data['level']) {
  1169. case 1:
  1170. case 2:
  1171. case 3:
  1172. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1173. $query = Article::where($where)
  1174. ->where('level', 'like', '%' . $data['level'] . '%')
  1175. ->orderBy('updated_at', 'desc');
  1176. break;
  1177. case 4: //最新资讯
  1178. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1179. break;
  1180. case 5: //资讯推荐
  1181. $query = Article::where($where)
  1182. ->where('updated_at', '>', $month);
  1183. break;
  1184. case 7: //资讯分类
  1185. if (isset($data['id']) && !empty($data['id'])) {
  1186. $keyword = Article::where('id', $data['id'])->value('keyword');
  1187. $keywordArray = explode(',', $keyword);
  1188. $whereL7 = [];
  1189. foreach ($keywordArray as $k => $v) {
  1190. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1191. }
  1192. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1193. break;
  1194. } else {
  1195. return Result::error("请输入资讯ID", 0);
  1196. break;
  1197. }
  1198. default:
  1199. break;
  1200. }
  1201. // $whereL7 = [];
  1202. // if(isset($data['id']) && !empty($data['id'])){
  1203. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1204. // $keywordArray = explode(',', $keyword);
  1205. // foreach ($keywordArray as $k => $v) {
  1206. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1207. // }
  1208. // }
  1209. // $query = Article::where($where)
  1210. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1211. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1212. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1213. // }
  1214. // if($data['level'] == 7){
  1215. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1216. // }
  1217. // if($data['level'] == 4){
  1218. // $query = $query->inRandomOrder()
  1219. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1220. // }
  1221. // if($data['level'] == 5){
  1222. // $query = $query->orderBy('updated_at','desc');
  1223. // }
  1224. // });
  1225. if ($data['textnum'] > 0) {
  1226. $query = clone $query;
  1227. $result['text'] = $query
  1228. ->whereIn('catid', $categoryIds)
  1229. ->leftJoinSub(function ($query) use ($website_id) {
  1230. $query->from('article_ignore')
  1231. ->where('website_id', $website_id);
  1232. }, 'article_ignore', function ($join) {
  1233. $join->on('article_ignore.article_id', '=', 'article.id');
  1234. })
  1235. ->where(function ($query) {
  1236. $query->whereNull('article_ignore.article_id')
  1237. ->orWhere(function ($subQuery) {
  1238. $subQuery->whereNotNull('article_ignore.article_id')
  1239. ->where('article_ignore.is_ignore', 0)
  1240. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1241. });
  1242. })
  1243. // ->where(function ($query) use ($website_id) {
  1244. // $query->whereNull('article_ignore.article_id')
  1245. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1246. // })
  1247. ->select(
  1248. 'article.id',
  1249. 'article.title',
  1250. 'article.author',
  1251. 'article.updated_at',
  1252. 'article.introduce',
  1253. 'article.islink',
  1254. 'article.linkurl',
  1255. 'article.copyfrom',
  1256. 'article.cat_arr_id',
  1257. 'article.catid',
  1258. 'article.level',
  1259. // 'article_ignore.is_ignore',
  1260. // 'article_ignore.c_show_time',
  1261. )
  1262. ->offset($data['placeid'])
  1263. ->limit($data['textnum'])
  1264. ->get()->all();
  1265. foreach ($result['text'] as $k => $v) {
  1266. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1267. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1268. }
  1269. }
  1270. if ($data['imgnum'] > 0) {
  1271. $query = clone $query;
  1272. $result['img'] = $query
  1273. ->whereIn('catid', $categoryIds)
  1274. ->where('article.imgurl', '!=', '')
  1275. ->select(
  1276. 'article.id',
  1277. 'article.title',
  1278. 'article.imgurl',
  1279. 'article.author',
  1280. 'article.updated_at',
  1281. 'article.introduce',
  1282. 'article.islink',
  1283. 'article.linkurl',
  1284. 'article.copyfrom',
  1285. 'article.cat_arr_id',
  1286. 'article.catid',
  1287. 'article.level',
  1288. // 'article_ignore.is_ignore',
  1289. // 'article_ignore.c_show_time',
  1290. )
  1291. ->offset($data['placeid'])
  1292. ->limit($data['imgnum'])
  1293. ->get()->all();
  1294. foreach ($result['img'] as $k => $v) {
  1295. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1296. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1297. }
  1298. }
  1299. if (empty($result)) {
  1300. return Result::error("暂无相关资讯", 0);
  1301. }
  1302. return Result::success($result);
  1303. }
  1304. /**
  1305. * 获取模块新闻
  1306. * @param array $data
  1307. * @return array
  1308. */
  1309. public function getWebsiteModelArticles(array $data): array
  1310. {
  1311. $catid = $data['catid'];
  1312. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1313. $category = $category->toArray();
  1314. if (!empty($category)) {
  1315. $where = [
  1316. 'status' => 1,
  1317. 'catid' => $catid,
  1318. ];
  1319. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1320. // 1:文字新闻;2:轮播图;3:图文;
  1321. // 级别:0:未分类
  1322. // 3:推荐图片
  1323. if ($data['level'] == 1) {
  1324. $data['level'] = 0;
  1325. }
  1326. $result = Article::where($where)
  1327. ->where(function ($query) use ($data) {
  1328. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1329. ->orWhereNull("level")
  1330. ->orWhereRaw("level = '[]'");
  1331. })
  1332. ->leftJoinSub(function ($query) use ($data) {
  1333. $query->from('article_ignore')
  1334. ->where('website_id', $data['website_id']);
  1335. }, 'article_ignore', function ($join) {
  1336. $join->on('article_ignore.article_id', '=', 'article.id');
  1337. })
  1338. ->where(function ($query) {
  1339. $query->whereNull('article_ignore.article_id')
  1340. ->orWhere(function ($subQuery) {
  1341. $subQuery->whereNotNull('article_ignore.article_id')
  1342. ->where('article_ignore.is_ignore', 0)
  1343. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1344. });
  1345. })
  1346. // ->where(function ($query) use ($data) {
  1347. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1348. // ->orWhereNull("ignore_ids");
  1349. // })
  1350. ->orderBy("updated_at", "desc")
  1351. ->offset($placeid)
  1352. ->limit($data['pagesize'])
  1353. ->get();
  1354. if (empty($result)) {
  1355. return Result::error("此栏目暂无相关新闻", 0);
  1356. }
  1357. } else {
  1358. return Result::error("此网站暂无此栏目", 0);
  1359. }
  1360. return Result::success($result);
  1361. }
  1362. /**
  1363. *获取新闻列表
  1364. * @param array $data
  1365. * @return array
  1366. */
  1367. public function getWebsiteArticleList(array $data): array
  1368. {
  1369. // return Result::success($data);
  1370. $where[] = ['status', '=', 1];
  1371. $website_id = $data['website_id'];
  1372. $website = Website::where('id', $data['website_id'])->first();
  1373. if (empty($website)) {
  1374. return Result::error("网站不存在", 0);
  1375. }
  1376. // $website_column = $website['column'];
  1377. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1378. $website_column = json_decode($website['website_column_arr_id'], true);
  1379. }
  1380. $categorys = $this->processArticlePro($website_id);
  1381. $cat_1st_arr = $categorys['cat_1st_arr'];
  1382. $catiall = $categorys['catiall'];
  1383. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1384. // return Result::success($diff_pid_categoryIds);
  1385. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1386. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1387. }
  1388. if (isset($data['catid']) && !empty($data['catid'])) {
  1389. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1390. if (empty($category)) {
  1391. return Result::error("此网站暂无此栏目", 0);
  1392. }
  1393. array_push($where, ['catid', '=', $data['catid']]);
  1394. }
  1395. // return Result::success($where);
  1396. $query = Article::where($where)
  1397. ->leftJoinSub(function ($query) use ($website_id) {
  1398. $query->from('article_ignore')
  1399. ->where('website_id', $website_id);
  1400. }, 'article_ignore', function ($join) {
  1401. $join->on('article_ignore.article_id', '=', 'article.id');
  1402. })
  1403. ->where(function ($query) {
  1404. $query->whereNull('article_ignore.article_id')
  1405. ->orWhere(function ($subQuery) {
  1406. $subQuery->whereNotNull('article_ignore.article_id')
  1407. ->where('article_ignore.is_ignore', 0)
  1408. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1409. });
  1410. })
  1411. ->select(
  1412. 'article.id',
  1413. 'article.title',
  1414. 'article.imgurl',
  1415. 'article.author',
  1416. 'article.updated_at',
  1417. 'article.introduce',
  1418. 'article.islink',
  1419. 'article.linkurl',
  1420. 'article.copyfrom',
  1421. 'article.cat_arr_id',
  1422. 'article.catid'
  1423. );
  1424. $count = $query->count();
  1425. $rep = $query->orderBy("updated_at", "desc")
  1426. ->offset(($data['page'] - 1) * $data['pageSize'])
  1427. ->limit($data['pageSize'])
  1428. ->get()->all();
  1429. $categorys = $this->processArticlePro($website_id);
  1430. $cat_1st_arr = $categorys['cat_1st_arr'];
  1431. $catiall = $categorys['catiall'];
  1432. // $web['website_id'] = $data['website_id'];
  1433. foreach ($rep as $k => $v) {
  1434. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1435. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1436. }
  1437. // $rep = $this->processArticles($rep,$web);
  1438. $data = [
  1439. 'rows' => $rep,
  1440. 'count' => $count,
  1441. ];
  1442. if (empty($rep)) {
  1443. return Result::error("没有信息数据");
  1444. }
  1445. return Result::success($data);
  1446. }
  1447. /**
  1448. * 前端-获取新闻详情
  1449. * @param array $data
  1450. * @return array
  1451. */
  1452. public function selectWebsiteArticleInfo(array $data): array
  1453. {
  1454. $where = [
  1455. 'article.id' => $data['id'],
  1456. 'article.status' => 1,
  1457. ];
  1458. $result = Article::where($where)
  1459. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1460. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1461. // ->where(function ($query) use ($data) {
  1462. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1463. // ->orWhereNull("ignore_ids");
  1464. // })
  1465. ->leftJoinSub(function ($query) use ($data) {
  1466. $query->from('article_ignore')
  1467. ->where('website_id', $data['website_id']);
  1468. }, 'article_ignore', function ($join) {
  1469. $join->on('article_ignore.article_id', '=', 'article.id');
  1470. })
  1471. ->where(function ($query) {
  1472. $query->whereNull('article_ignore.article_id')
  1473. ->orWhere(function ($subQuery) {
  1474. $subQuery->whereNotNull('article_ignore.article_id')
  1475. ->where('article_ignore.is_ignore', 0)
  1476. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1477. });
  1478. })
  1479. ->select(
  1480. 'article.*',
  1481. 'article_data.content',
  1482. 'article_data.article_id',
  1483. 'article_extend.website_url',
  1484. 'article_extend.email',
  1485. 'article_extend.contacts',
  1486. 'article_extend.contacts_mobile',
  1487. 'article_extend.contacts_address',
  1488. 'article_extend.zip_code',
  1489. 'article_extend.enterprise_name'
  1490. )
  1491. ->first();
  1492. if (empty($result)) {
  1493. return Result::error("暂无此新闻!", 0);
  1494. }
  1495. if (!empty($result['publiced_at'])) {
  1496. $result['updated_at'] = $result['publiced_at'];
  1497. }
  1498. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1499. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1500. ->where('website_category.website_id', $data['website_id'])
  1501. ->where(['website_category.category_id' => $result['catid']])
  1502. ->first();
  1503. if (empty($category)) {
  1504. return Result::error("查询失败", 0);
  1505. }
  1506. //手动推荐文章
  1507. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1508. if (empty($commend_ids)) {
  1509. $commendArticle = [];
  1510. } else {
  1511. //去除不存在的文章ID
  1512. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1513. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1514. ->leftJoinSub(function ($query) use ($data) {
  1515. $query->from('article_ignore')
  1516. ->where('website_id', $data['website_id']);
  1517. }, 'article_ignore', function ($join) {
  1518. $join->on('article_ignore.article_id', '=', 'article.id');
  1519. })
  1520. ->where(function ($query) {
  1521. $query->whereNull('article_ignore.article_id')
  1522. ->orWhere(function ($subQuery) {
  1523. $subQuery->whereNotNull('article_ignore.article_id')
  1524. ->where('article_ignore.is_ignore', 0)
  1525. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1526. });
  1527. })
  1528. ->where('article.status', 1)
  1529. ->where('website_category.website_id', $data['website_id'])
  1530. ->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')
  1531. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1532. // ->orderBy('article.updated_at', 'desc')
  1533. ->limit(5)
  1534. ->get();
  1535. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1536. foreach ($commendArticle as $k => $v) {
  1537. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1538. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1539. $cat_arr_id = array_unique($cat_arr_id);
  1540. // 从website_category取出alias_pinyin
  1541. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1542. ->whereIn('category_id', $cat_arr_id)
  1543. ->pluck('alias_pinyin', 'category_id')
  1544. ->toArray();
  1545. // 将cat_arr_id的json转成路径/隔开
  1546. $path_parts = [];
  1547. foreach ($cat_arr_id as $cat_id) {
  1548. if (isset($cat_arr[$cat_id])) {
  1549. $path_parts[] = $cat_arr[$cat_id];
  1550. }
  1551. }
  1552. $v->alias_pinyin = implode('/', $path_parts);
  1553. } else {
  1554. $v->alias_pinyin = '';
  1555. }
  1556. }
  1557. }
  1558. $result['category_id'] = $category['category_id'];
  1559. $result['cat_name'] = $category['alias'];
  1560. $result['website_name'] = $category['website_name'] ?? "";
  1561. $result['suffix'] = $category['suffix'] ?? "";
  1562. $result['commendArticle'] = $commendArticle;
  1563. $result['commend_ids'] = $commend_ids;
  1564. return Result::success($result);
  1565. }
  1566. /**
  1567. * 前端-获取网站调查问卷
  1568. * @param array $data
  1569. * @return array
  1570. */
  1571. public function getWebsiteSurvey(array $data): array
  1572. {
  1573. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1574. $website = Website::where('id', $data['website_id'])->first();
  1575. if (empty($website)) {
  1576. return Result::error("暂无此网站", 0);
  1577. }
  1578. }
  1579. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1580. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1581. if (empty($article)) {
  1582. return Result::error("暂无此文章", 0);
  1583. }
  1584. // return Result::error($data,0);
  1585. $where['art_id'] = $data['art_id'];
  1586. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1587. } else {
  1588. $survey = Article::where(function ($query) {
  1589. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1590. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1591. })
  1592. ->where('status', 1)
  1593. ->where('is_survey', 1)
  1594. ->select('survey_id')
  1595. ->orderBy('updated_at', 'desc')
  1596. ->first();
  1597. if (empty($survey)) {
  1598. return Result::error("暂无调查问卷", 0);
  1599. }
  1600. $where['sur_id'] = $survey['survey_id'];
  1601. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1602. }
  1603. // return Result::success($where);
  1604. $result = ArticleSurvey::where($where)
  1605. ->where(function ($query) {
  1606. $query->where('is_other', 0)
  1607. ->orWhere(function ($subQuery) {
  1608. $subQuery->where('is_other', 1)
  1609. ->where('other_id', 0);
  1610. });
  1611. })
  1612. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1613. ->select('article_survey.*', 'article.survey_type')
  1614. ->get()->all();
  1615. if (empty($result)) {
  1616. return Result::error("此文章暂无调查问卷", 0);
  1617. }
  1618. return Result::success($result);
  1619. }
  1620. /**
  1621. * 前端-添加网站调查问卷选项
  1622. * @param array $data
  1623. * @return array
  1624. */
  1625. public function addWebsiteSurveyOption(array $data): array
  1626. {
  1627. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1628. $website = Website::where('id', $data['website_id'])->first();
  1629. if (empty($website)) {
  1630. return Result::error("暂无此网站", 0);
  1631. }
  1632. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1633. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1634. if (empty($survey)) {
  1635. return Result::error("此调查问卷不可添加选项", 0);
  1636. }
  1637. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1638. $choice = [
  1639. 'art_id' => $survey['art_id'],
  1640. 'website_id' => $data['website_id'],
  1641. 'survey_name' => $survey['survey_name'],
  1642. 'choice_name' => $data['choice_name'],
  1643. 'sur_id' => $survey['sur_id'],
  1644. 'is_other' => 1,
  1645. 'other_id' => $survey['id'],
  1646. ];
  1647. $result = ArticleSurvey::insertGetId($choice);
  1648. if (empty($result)) {
  1649. return Result::error("添加失败", 0);
  1650. }
  1651. return Result::success($result);
  1652. }
  1653. }
  1654. return Result::error("添加失败", 0);
  1655. }
  1656. return Result::error("添加失败", 0);
  1657. }
  1658. /**
  1659. * 前端-调查问卷投票
  1660. * @param array $data
  1661. * @return array
  1662. */
  1663. public function addWebsiteSurveyVote(array $data): array
  1664. {
  1665. // return Result::success($data);
  1666. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1667. $website = Website::where('id', $data['website_id'])->first();
  1668. if (empty($website)) {
  1669. return Result::error("暂无此网站", 0);
  1670. }
  1671. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1672. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1673. // return Result::success($survey);
  1674. if (empty($is_survey)) {
  1675. return Result::error("此调查问卷不存在", 0);
  1676. }
  1677. // return Result::success($survey);
  1678. // 调查问卷类型
  1679. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1680. //多选 若是json型则转化成数组类型
  1681. if (strpos($data['choice_id'], '[') === 0) {
  1682. $data['choice_id'] = json_decode($data['choice_id'], true);
  1683. } else {
  1684. // 单选 也转换成数组
  1685. $data['choice_id'] = [$data['choice_id']];
  1686. }
  1687. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1688. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1689. // ->where('website_id',$data['website_id'])
  1690. ->where('is_other', 1)
  1691. ->where('other_id', 0)
  1692. ->first();
  1693. if (!empty($other)) {
  1694. return Result::error("请选择已有的选项!", 0);
  1695. }
  1696. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1697. // ->where('website_id',$data['website_id'])
  1698. ->where('is_other', 1)
  1699. ->where('other_id', '!=', 0)
  1700. ->first();
  1701. // return Result::success($choice['other']);
  1702. $choice_id = $data['choice_id'];
  1703. if (!empty($choice['other'])) {
  1704. // array_push($data['choice_id'],$choice['other']['other_id']);
  1705. if (!empty($choice_id)) {
  1706. $key = array_search($choice['other']['id'], $choice_id);
  1707. if ($key !== false) {
  1708. unset($choice_id[$key]);
  1709. $choice_id = array_values($choice_id);
  1710. }
  1711. array_push($choice_id, $choice['other']['other_id']);
  1712. } else {
  1713. $choice_id[0] = $choice['other']['other_id'];
  1714. }
  1715. array_push($data['choice_id'], $choice['other']['other_id']);
  1716. }
  1717. // return Result::success($data);
  1718. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1719. // ->where('website_id',$data['website_id'])
  1720. ->increment('results', 1);
  1721. if (empty($choice)) {
  1722. return Result::error("请选择已有的选项!", 0);
  1723. }
  1724. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1725. // ->where('website_id',$data['website_id'])
  1726. ->where('other_id', 0)
  1727. ->get();
  1728. $survey['choice'] = $choice_id;
  1729. return Result::success($survey);
  1730. }
  1731. return Result::error("参数必填!");
  1732. }
  1733. return Result::error("此调查问卷不存在", 0);
  1734. }
  1735. return Result::error("参数必填!");
  1736. }
  1737. /**
  1738. * 后端-获取网站调查问卷列表
  1739. * @param array $data
  1740. * @return array
  1741. */
  1742. public function getSurveyList(array $data): array
  1743. {
  1744. $where = [];
  1745. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1746. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1747. }
  1748. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1749. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1750. }
  1751. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1752. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1753. }
  1754. // return Result::success($where);
  1755. if (!empty($where)) {
  1756. $query = Article::where($where)->where(function ($q) {
  1757. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1758. });
  1759. } else {
  1760. $query = Article::where(function ($q) {
  1761. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1762. });
  1763. }
  1764. $count = $query->count();
  1765. $survey = $query->orderByDesc('id')
  1766. ->limit($data['pageSize'])
  1767. ->offset(($data['page'] - 1) * $data['pageSize'])
  1768. ->get();
  1769. if (empty($survey->toArray())) {
  1770. return Result::error("暂无调查问卷!", 0);
  1771. }
  1772. $result = [
  1773. 'rows' => $survey,
  1774. 'count' => $count,
  1775. ];
  1776. return Result::success($result);
  1777. }
  1778. /**
  1779. * 后端-获取网站调查问卷详情
  1780. * @param array $data
  1781. * @return array
  1782. */
  1783. public function getSurveyInfo(array $data): array
  1784. {
  1785. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1786. $where = ['sur_id' => $data['sur_id']];
  1787. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1788. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1789. ->select('article_survey.*', 'article.survey_type')
  1790. ->get()->all();
  1791. if (empty($choose)) {
  1792. return Result::error("此调查问卷不存在", 0);
  1793. }
  1794. $resultsArray = array_column($choose, 'results');
  1795. $total = array_sum($resultsArray);
  1796. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1797. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1798. // $total = 0;
  1799. if (!empty($other)) {
  1800. $total = $total + $other['results'];
  1801. $other['choice_name'] = '(其他)';
  1802. if (!empty($others)) {
  1803. $other['hasChildren'] = true;
  1804. // array_push($other,['hasChildren','=',true]);
  1805. $other['children'] = $others;
  1806. $other_choices = [$other->toArray()];
  1807. $mer_choice = array_merge($choose, $other_choices);
  1808. $value_choice = array_values($mer_choice);
  1809. } else {
  1810. // return Result::error('1111');
  1811. $other_choices = [$other->toArray()];
  1812. $other_choices = array_merge($choose, $other_choices);
  1813. $value_choice = array_values($other_choices);
  1814. // return Result::success($result);
  1815. }
  1816. } else {
  1817. $value_choice = $choose;
  1818. }
  1819. $result = [
  1820. 'choose' => $value_choice,
  1821. 'total' => $total,
  1822. ];
  1823. }
  1824. return Result::success($result);
  1825. }
  1826. /**
  1827. * 前端-搜索新闻列表
  1828. * @param array $data
  1829. * @return array
  1830. */
  1831. public function selectWebsiteArticle(array $data): array
  1832. {
  1833. $website = Website::where('id', $data['website_id'])->first();
  1834. if (empty($website)) {
  1835. return Result::error("网站不存在", 0);
  1836. }
  1837. // $website_column = $website['column'];
  1838. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1839. $website_column = json_decode($website['website_column_arr_id'], true);
  1840. }
  1841. $website_id = $data['website_id'];
  1842. $categorys = $this->processArticlePro($website_id);
  1843. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1844. // return Result::success($diff_pid_categoryIds);
  1845. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1846. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1847. }
  1848. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1849. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1850. $catiall = $categorys['catiall'];
  1851. $categoryIds = $categorys['categoryIds'];
  1852. // return Result::success($categoryIds);
  1853. $query = Article::where('status', 1)
  1854. ->whereIn('catid', $categoryIds)
  1855. ->leftJoinSub(function ($query) use ($website_id) {
  1856. $query->from('article_ignore')
  1857. ->where('website_id', $website_id);
  1858. }, 'article_ignore', function ($join) {
  1859. $join->on('article_ignore.article_id', '=', 'article.id');
  1860. })
  1861. ->where(function ($query) {
  1862. $query->whereNull('article_ignore.article_id')
  1863. ->orWhere(function ($subQuery) {
  1864. $subQuery->whereNotNull('article_ignore.article_id')
  1865. ->where('article_ignore.is_ignore', 0)
  1866. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1867. });
  1868. });
  1869. // ->get()->all();
  1870. // return Result::success($query);
  1871. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1872. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1873. }
  1874. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1875. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1876. }
  1877. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1878. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1879. }
  1880. // 计算总数
  1881. $count = $query->count();
  1882. // return Result::success($count);
  1883. // 分页查询
  1884. $articles = $query
  1885. ->select(
  1886. 'article.id',
  1887. 'article.title',
  1888. 'article.imgurl',
  1889. 'article.author',
  1890. 'article.updated_at',
  1891. 'article.introduce',
  1892. 'article.islink',
  1893. 'article.linkurl',
  1894. 'article.copyfrom',
  1895. 'article.cat_arr_id',
  1896. 'article.catid',
  1897. 'article.department_arr_id',
  1898. 'article.city_arr_id',
  1899. // 'article_ignore.c_show_time',
  1900. // 'article_ignore.is_ignore'
  1901. )
  1902. ->orderBy("updated_at", "desc")
  1903. ->offset(($data['page'] - 1) * $data['pageSize'])
  1904. ->limit($data['pageSize'])
  1905. ->get();
  1906. // return Result::success($articles);
  1907. foreach ($articles as $k => $v) {
  1908. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1909. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1910. }
  1911. if (empty($articles)) {
  1912. return Result::error("没有符合条件的资讯数据");
  1913. }
  1914. $result = [
  1915. 'rows' => $articles,
  1916. 'count' => $count,
  1917. ];
  1918. return Result::success($result);
  1919. }
  1920. /**
  1921. * 模块新闻加强版
  1922. * @param array $data
  1923. * @return array
  1924. */
  1925. public function getWebsiteCatidArticle(array $data): array
  1926. {
  1927. $where = [
  1928. 'website_category.category_id' => $data['catid'],
  1929. 'website_category.website_id' => $data['website_id'],
  1930. ];
  1931. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1932. $child_catnum = $data['child_catnum'] ?? 1;
  1933. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1934. $childCategoryIds = array_column($category['child'], 'category_id');
  1935. if (empty($childCategoryIds)) {
  1936. return Result::error("暂无子栏目", 0);
  1937. }
  1938. $imgArticles = [];
  1939. $textArticles = [];
  1940. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1941. // 初始化子分类图片新闻和文字新闻数组
  1942. // 查询所有子级栏目的图文新闻
  1943. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1944. ->where(function ($query) use ($data) {
  1945. $query->where(function ($subQuery) use ($data) {
  1946. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1947. })->orWhereNull("ignore_ids");
  1948. })
  1949. ->where('status', 1)
  1950. ->where('imgurl', '!=', '')
  1951. ->select('*')
  1952. ->orderBy('updated_at', 'desc')
  1953. ->limit($data['child_imgnum'])
  1954. ->get();
  1955. }
  1956. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1957. // 查询所有子级栏目的文字新闻
  1958. $textArticles = Article::where('catid', $childCategoryIds[0])
  1959. ->where('status', 1)
  1960. ->where(function ($query) use ($data) {
  1961. $query->where(function ($subQuery) use ($data) {
  1962. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1963. })->orWhereNull("ignore_ids");
  1964. })
  1965. ->select('*')
  1966. ->orderBy('updated_at', 'desc')
  1967. ->limit($data['child_textnum'])
  1968. ->get();
  1969. }
  1970. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1971. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1972. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1973. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1974. return $child;
  1975. }, $category['child']);
  1976. }
  1977. // }
  1978. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1979. $category['img'] = WebsiteCategory::where($where)
  1980. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1981. ->where('article.status', 1)
  1982. ->where('article.imgurl', '!=', '')
  1983. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1984. ->orderBy('article.updated_at', 'desc')
  1985. ->limit($data['img_num'])
  1986. ->get();
  1987. }
  1988. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1989. $category['text'] = WebsiteCategory::where($where)
  1990. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1991. ->where('article.status', 1)
  1992. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1993. ->orderBy('article.updated_at', 'desc')
  1994. ->limit($data['text_num'])
  1995. ->get();
  1996. }
  1997. // $category = $category->get();
  1998. if (empty($category)) {
  1999. return Result::error("查询失败", 0);
  2000. }
  2001. return Result::success($category);
  2002. }
  2003. /**
  2004. * 模块新闻加强plus版
  2005. * @param array $data
  2006. * @return array
  2007. */
  2008. public function getWebsiteAllArticle(array $data): array
  2009. {
  2010. // return Result::success($data);
  2011. $time1 = microtime(true);
  2012. $wetbsite_id = $data['website_id'] ?? 2;
  2013. $data = json_decode($data['id'], true);
  2014. $website = Website::where('id', $wetbsite_id)->first();
  2015. if (empty($website)) {
  2016. return Result::error("网站不存在", 0);
  2017. }
  2018. // return Result::success($website);
  2019. $website_column = $website['website_column_arr_id'] ?? '[]';
  2020. $website_column = json_decode($website_column, true);
  2021. $categorys = $this->processArticlePro($wetbsite_id);
  2022. $cat_1st_arr = $categorys['cat_1st_arr'];
  2023. $catiall = $categorys['catiall'];
  2024. // return Result::success($catiall);
  2025. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2026. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2027. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2028. }
  2029. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2030. // return Result::success($categorys);
  2031. $parent_category = array_column($data, 'parent');
  2032. $parent_cat = [];
  2033. $child_category = array_column($data, 'child');
  2034. if (!empty($parent_category)) {
  2035. foreach ($parent_category as $key => $value) {
  2036. $arr = array_map('intval', explode(',', $value));
  2037. $parent_cat[$key] = $arr[0] ?? 0;
  2038. $parent_category = $arr[0] ?? 0;
  2039. $article_imgnum = $arr[1] ?? 0;
  2040. $article_textnum = $arr[2] ?? 0;
  2041. if ($parent_category != 0) {
  2042. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2043. // return Result::success($category_arr);
  2044. if ($article_imgnum != 0) {
  2045. $img_article = Article::whereIn('catid', $category_arr)
  2046. ->where('status', 1)
  2047. ->where('imgurl', '!=', '')
  2048. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2049. $query->from('article_ignore')
  2050. ->where('website_id', $wetbsite_id);
  2051. }, 'article_ignore', function ($join) {
  2052. $join->on('article_ignore.article_id', '=', 'article.id');
  2053. })
  2054. ->where(function ($query) {
  2055. $query->whereNull('article_ignore.article_id')
  2056. ->orWhere(function ($subQuery) {
  2057. $subQuery->whereNotNull('article_ignore.article_id')
  2058. ->where('article_ignore.is_ignore', 0)
  2059. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2060. });
  2061. })
  2062. ->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')
  2063. ->orderBy('updated_at', 'desc')
  2064. ->limit($article_imgnum)
  2065. ->get()->all();
  2066. foreach ($img_article as $k => $v) {
  2067. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2068. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2069. }
  2070. } else {
  2071. $img_article = [];
  2072. }
  2073. if ($article_textnum != 0) {
  2074. $text_article = Article::whereIn('catid', $category_arr)
  2075. ->where('status', 1)
  2076. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2077. $query->from('article_ignore')
  2078. ->where('website_id', $wetbsite_id);
  2079. }, 'article_ignore', function ($join) {
  2080. $join->on('article_ignore.article_id', '=', 'article.id');
  2081. })
  2082. ->where(function ($query) {
  2083. $query->whereNull('article_ignore.article_id')
  2084. ->orWhere(function ($subQuery) {
  2085. $subQuery->whereNotNull('article_ignore.article_id')
  2086. ->where('article_ignore.is_ignore', 0)
  2087. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2088. });
  2089. })
  2090. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2091. ->orderBy('updated_at', 'desc')
  2092. ->limit($article_textnum)
  2093. ->get()->all();
  2094. foreach ($text_article as $k => $v) {
  2095. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2096. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2097. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2098. }
  2099. } else {
  2100. $text_article = [];
  2101. }
  2102. $catiall[$parent_category]['imgnum'] = $img_article;
  2103. $catiall[$parent_category]['textnum'] = $text_article;
  2104. $parent[$key] = $catiall[$parent_category];
  2105. } else {
  2106. $parent[$key] = '';
  2107. }
  2108. }
  2109. }
  2110. if (!empty($child_category)) {
  2111. foreach ($child_category as $key => $value) {
  2112. $arr = array_map('intval', explode(',', $value));
  2113. $parent_category = $parent_cat[$key];
  2114. $child_category = $arr[0] ?? 0;
  2115. $article_imgnum = $arr[1] ?? 0;
  2116. $article_textnum = $arr[2] ?? 0;
  2117. if ($child_category != 0) {
  2118. $all_childcat = $cat_1st_arr[$parent_category];
  2119. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2120. // 从 $websiteInfoIndexed 中获取对应的数据
  2121. $info = $websiteInfoIndexed[$v];
  2122. // 返回一个包含所需信息的数组
  2123. return [
  2124. 'alias' => $info->alias,
  2125. 'category_id' => $info->category_id,
  2126. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2127. 'pid' => $info->pid,
  2128. 'type' => $info->type,
  2129. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2130. 'pinyin' => $info->pinyin,
  2131. ];
  2132. }, $all_childcat);
  2133. if ($article_imgnum != 0) {
  2134. $img_article = Article::where('catid', $child_category)
  2135. ->where('status', 1)
  2136. ->where('imgurl', '!=', '')
  2137. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2138. $query->from('article_ignore')
  2139. ->where('website_id', $wetbsite_id);
  2140. }, 'article_ignore', function ($join) {
  2141. $join->on('article_ignore.article_id', '=', 'article.id');
  2142. })
  2143. ->where(function ($query) {
  2144. $query->whereNull('article_ignore.article_id')
  2145. ->orWhere(function ($subQuery) {
  2146. $subQuery->whereNotNull('article_ignore.article_id')
  2147. ->where('article_ignore.is_ignore', 0)
  2148. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2149. });
  2150. })
  2151. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2152. ->orderBy('updated_at', 'desc')
  2153. ->limit($article_imgnum)
  2154. ->get()->all();
  2155. foreach ($img_article as $k => $v) {
  2156. // var_dump($v);
  2157. // var_dump($k);
  2158. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2159. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2160. }
  2161. } else {
  2162. $img_article = [];
  2163. }
  2164. if ($article_textnum != 0) {
  2165. $text_article = Article::where('catid', $child_category)
  2166. ->where('status', 1)
  2167. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2168. $query->from('article_ignore')
  2169. ->where('website_id', $wetbsite_id);
  2170. }, 'article_ignore', function ($join) {
  2171. $join->on('article_ignore.article_id', '=', 'article.id');
  2172. })
  2173. ->where(function ($query) {
  2174. $query->whereNull('article_ignore.article_id')
  2175. ->orWhere(function ($subQuery) {
  2176. $subQuery->whereNotNull('article_ignore.article_id')
  2177. ->where('article_ignore.is_ignore', 0)
  2178. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2179. });
  2180. })
  2181. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2182. ->orderBy('updated_at', 'desc')
  2183. ->limit($article_textnum)
  2184. ->get()->all();
  2185. foreach ($text_article as $k => $v) {
  2186. // var_dump($v);
  2187. // var_dump($k);
  2188. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2189. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2190. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2191. }
  2192. } else {
  2193. $text_article = [];
  2194. }
  2195. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2196. $catiall[$child_category]['imgnum'] = $img_article;
  2197. $catiall[$child_category]['textnum'] = $text_article;
  2198. $child[$key] = $catiall[$child_category];
  2199. // var_dump($pids);
  2200. } else {
  2201. $child[$key] = '';
  2202. }
  2203. }
  2204. }
  2205. foreach ($parent as $key => $value) {
  2206. $result[$key] = $value;
  2207. if (!empty($child[$key])) {
  2208. // var_dump($child[$key]);
  2209. $result[$key]['child'] = $child[$key];
  2210. // $value[$key]['child'] = $child[$key];
  2211. } else {
  2212. $result[$key]['child'] = [
  2213. "alias" => null,
  2214. "category_id" => null,
  2215. "type" => null,
  2216. "pinyin" => null,
  2217. "all_childcat" => [],
  2218. "imgnum" => [],
  2219. "textnum" => []
  2220. ];
  2221. }
  2222. }
  2223. return Result::success($result);
  2224. }
  2225. /**
  2226. * 辅助方法:获取文章列表
  2227. */
  2228. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2229. {
  2230. sleep(1);
  2231. $query = Article::where('article.status', 1)
  2232. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2233. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2234. ->where(function ($query) use ($website) {
  2235. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2236. })
  2237. ->leftJoin('website_category', function ($join) use ($website) {
  2238. $join->on('article.catid', '=', 'website_category.category_id')
  2239. ->where('website_category.website_id', '=', $website['website_id']);
  2240. })
  2241. ->select(
  2242. 'article.id',
  2243. 'article.title',
  2244. 'article.imgurl',
  2245. 'article.author',
  2246. 'article.updated_at',
  2247. 'article.introduce',
  2248. 'article.islink',
  2249. 'article.linkurl',
  2250. 'article.copyfrom',
  2251. 'article.cat_arr_id',
  2252. 'article.catid',
  2253. 'website_category.alias as category_name'
  2254. )
  2255. ->orderBy('updated_at', 'desc')
  2256. ->limit($limit);
  2257. // 如果是图片文章,添加图片URL条件
  2258. if ($isImageArticle) {
  2259. $query->where('imgurl', '!=', '');
  2260. } else {
  2261. // 文字文章不需要imgurl字段
  2262. $query->addSelect('article.introduce');
  2263. }
  2264. $articles = $query->get();
  2265. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2266. }
  2267. /**
  2268. * 乡村网-获取特殊新闻模块
  2269. * @param array $data
  2270. * @return array
  2271. */
  2272. public function getWebsiteArticles(array $data): array
  2273. {
  2274. $website_id = $data['website_id'];
  2275. $website = Website::where('id', $website_id)->first();
  2276. if (empty($website)) {
  2277. return Result::error("网站不存在", 0);
  2278. }
  2279. // return Result::success($website);
  2280. $website_column = $website['website_column_arr_id'] ?? '[]';
  2281. $website_column = json_decode($website_column, true);
  2282. $catids = json_decode($data['id'], true);
  2283. $parent_category = array_column($catids, 'parent');
  2284. if (!empty($parent_category) && is_array($parent_category)) {
  2285. $categorys = $this->processArticlePro($website_id);
  2286. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2287. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2288. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2289. }
  2290. $catiall = $categorys['catiall'];
  2291. $cat_1st_arr = $categorys['cat_1st_arr'];
  2292. // return Result::success($categorys);
  2293. foreach ($parent_category as $key => $value) {
  2294. $arr = array_map('intval', explode(',', $value));
  2295. $parent_category = $arr[0] ?? 0;
  2296. $article_imgnum = $arr[1] ?? 0;
  2297. $article_textnum = $arr[2] ?? 0;
  2298. if ($parent_category != 0) {
  2299. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2300. // return Result::success($category_arr);
  2301. if ($article_imgnum != 0) {
  2302. $img_article = Article::whereIn('article.catid', $category_arr)
  2303. ->where('article.status', 1)
  2304. ->where('article.imgurl', '!=', '')
  2305. ->leftJoinSub(function ($query) use ($website_id) {
  2306. $query->from('article_ignore')
  2307. ->where('website_id', $website_id);
  2308. }, 'article_ignore', function ($join) {
  2309. $join->on('article_ignore.article_id', '=', 'article.id');
  2310. })
  2311. ->where(function ($query) {
  2312. $query->whereNull('article_ignore.article_id')
  2313. ->orWhere(function ($subQuery) {
  2314. $subQuery->whereNotNull('article_ignore.article_id')
  2315. ->where('article_ignore.is_ignore', 0)
  2316. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2317. });
  2318. })
  2319. ->select(
  2320. 'article.id',
  2321. 'article.title',
  2322. 'article.imgurl',
  2323. 'article.author',
  2324. 'article.updated_at',
  2325. 'article.introduce',
  2326. 'article.islink',
  2327. 'article.linkurl',
  2328. 'article.copyfrom',
  2329. 'article.cat_arr_id',
  2330. 'article.catid as category_id'
  2331. )
  2332. ->orderBy('updated_at', 'desc')
  2333. ->limit($article_imgnum)
  2334. ->get()->all();
  2335. foreach ($img_article as $k => $v) {
  2336. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2337. // return Result::success($v);
  2338. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2339. }
  2340. } else {
  2341. $img_article = [];
  2342. }
  2343. if ($article_textnum != 0) {
  2344. $text_article = Article::whereIn('article.catid', $category_arr)
  2345. ->where('article.status', 1)
  2346. ->leftJoinSub(function ($query) use ($website_id) {
  2347. $query->from('article_ignore')
  2348. ->where('website_id', $website_id);
  2349. }, 'article_ignore', function ($join) {
  2350. $join->on('article_ignore.article_id', '=', 'article.id');
  2351. })
  2352. ->where(function ($query) {
  2353. $query->whereNull('article_ignore.article_id')
  2354. ->orWhere(function ($subQuery) {
  2355. $subQuery->whereNotNull('article_ignore.article_id')
  2356. ->where('article_ignore.is_ignore', 0)
  2357. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2358. });
  2359. })
  2360. ->select(
  2361. 'article.id',
  2362. 'article.title',
  2363. 'article.author',
  2364. 'article.updated_at',
  2365. 'article.introduce',
  2366. 'article.islink',
  2367. 'article.linkurl',
  2368. 'article.copyfrom',
  2369. 'article.cat_arr_id',
  2370. 'article.catid as category_id'
  2371. )
  2372. ->orderBy('updated_at', 'desc')
  2373. ->limit($article_textnum)
  2374. ->get()->all();
  2375. foreach ($text_article as $k => $v) {
  2376. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2377. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2378. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2379. }
  2380. } else {
  2381. $text_article = [];
  2382. }
  2383. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2384. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2385. $parent[$key] = $catiall[$parent_category];
  2386. } else {
  2387. $parent[$key] = [];
  2388. }
  2389. }
  2390. }
  2391. return Result::success($parent);
  2392. }
  2393. // 封装处理商品的路由问题
  2394. function processGoods($goods, $data)
  2395. {
  2396. return $goods->map(function ($good) use ($data) {
  2397. $catid = $good->catid ?? 0;
  2398. // $pinyin = '';
  2399. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2400. if (!empty($category->pid) && $category->pid != 0) {
  2401. $level = json_decode($category->category_arr_id, true);
  2402. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2403. ->whereIn('category_id', $level)
  2404. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2405. ->get(['aLIas_pinyin'])
  2406. ->pluck('aLIas_pinyin')
  2407. ->implode('/');
  2408. } else {
  2409. $pinyin = $category->aLIas_pinyin ?? '';
  2410. }
  2411. if (isset($good->city_id) && !empty($good->city_id)) {
  2412. $city = District::where('id', $good->city_id)->first(['name']);
  2413. $good->city_name = $city->name ?? '';
  2414. }
  2415. // 解析imgurl JSON并取第一条数据
  2416. $imgUrls = json_decode($good->imgurl, true);
  2417. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2418. $good->pinyin = $pinyin;
  2419. return $good;
  2420. });
  2421. }
  2422. /**
  2423. * 获取商城首页-根据栏目id
  2424. * @param array $data
  2425. * @return array
  2426. * */
  2427. function getWebsiteCatidshop(array $data): array
  2428. {
  2429. $input['catid'] = $data['catid'];
  2430. $input['website_id'] = $data['website_id'];
  2431. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2432. $result = array_map(function ($item) use ($input) {
  2433. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2434. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2435. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2436. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2437. if (empty($category) || $category->type != 2) {
  2438. return Result::error("暂无此栏目", 0);
  2439. } else {
  2440. $website['website_id'] = $input['website_id'];
  2441. $goods = Good::where('good.status', 2)
  2442. ->where('good.website_id', $website['website_id'])
  2443. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2444. ->select(
  2445. 'good.id',
  2446. 'good.name',
  2447. 'good.imgurl',
  2448. 'good.description',
  2449. 'good.updated_at',
  2450. 'good.catid',
  2451. 'good.type_id',
  2452. 'good.price',
  2453. 'good.com',
  2454. 'good.level',
  2455. 'good.unit'
  2456. )
  2457. ->orderBy('updated_at', 'desc')
  2458. ->offset($goodStart)
  2459. ->limit($goodNum);
  2460. $all_goods = $goods->get();
  2461. $all_goods = $this->processGoods($all_goods, $website);
  2462. }
  2463. return $all_goods ?? [];
  2464. }
  2465. }, $data);
  2466. return Result::success($result);
  2467. }
  2468. /**
  2469. * 获取商品模块
  2470. * @param array $data
  2471. * @return array
  2472. * */
  2473. public function getWebsiteshop(array $data): array
  2474. {
  2475. $input['id'] = $data['id'];
  2476. $input['website_id'] = $data['website_id'];
  2477. $catid = $data['catid'];
  2478. $data = json_decode($input['id'] ?? '', true) ?? [];
  2479. $result['goods'] = array_map(function ($item) use ($input) {
  2480. // 检查parent元素是否存在且不是undefined
  2481. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2482. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2483. $website = $input['website_id'];
  2484. $query = Good::where('good.status', 2)
  2485. ->where('good.website_id', $website);
  2486. switch ($Levelid) {
  2487. case 1:
  2488. case 2:
  2489. case 3:
  2490. $goods = $query->where(function ($q) use ($Levelid) {
  2491. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2492. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2493. });
  2494. break;
  2495. case 4:
  2496. $goods = $query;
  2497. break;
  2498. case 5:
  2499. $goods = $query->where('type_id', 1);
  2500. break;
  2501. case 6:
  2502. $goods = $query->where('type_id', 2);
  2503. break;
  2504. default:
  2505. return [];
  2506. }
  2507. $all_goods = $goods
  2508. ->select(
  2509. 'good.id',
  2510. 'good.name',
  2511. 'good.imgurl',
  2512. 'good.description',
  2513. 'good.updated_at',
  2514. 'good.catid',
  2515. 'good.type_id',
  2516. 'good.price',
  2517. 'good.level',
  2518. 'good.website_id'
  2519. )
  2520. ->orderBy('updated_at', 'desc')
  2521. ->offset($goodStart)
  2522. ->limit($goodNum)
  2523. ->get();
  2524. $web['website_id'] = $website;
  2525. $all_goods = $this->processGoods($all_goods, $web);
  2526. }
  2527. return $all_goods;
  2528. }, $data);
  2529. $website = $input['website_id'];
  2530. $result['article'] = Article::where(function ($query) use ($website) {
  2531. $query->where(function ($subQuery) use ($website) {
  2532. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2533. })->orWhereNull("ignore_ids");
  2534. })
  2535. ->where('catid', $catid)
  2536. ->where('article.status', 1)
  2537. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2538. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2539. ->orderBy('article.updated_at', 'desc')
  2540. ->first();
  2541. return Result::success($result);
  2542. }
  2543. /**
  2544. * 获取商品分类
  2545. * @param array $data
  2546. * @return array
  2547. * */
  2548. public function getWebsiteshopCat(array $data): array
  2549. {
  2550. $website = $data['website_id'];
  2551. $category = WebsiteCategory::where('website_id', $website)
  2552. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2553. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2554. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2555. ->orderBy('sort')
  2556. ->get();
  2557. $cat = $category->map(function ($item) use ($website) {
  2558. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2559. $pid = $item->pid ?? 0;
  2560. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2561. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2562. ->where('website_id', $website)
  2563. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2564. ->get(['aLIas_pinyin'])
  2565. ->pluck('aLIas_pinyin')
  2566. ->implode('/');
  2567. } else {
  2568. $pinyin = $item->aLIas_pinyin ?? '';
  2569. }
  2570. $item->pinyin = $pinyin;
  2571. });
  2572. if (empty($category)) {
  2573. return Result::error("栏目查询失败", 0);
  2574. }
  2575. $cat_tree = Result::buildMenuTree($category);
  2576. $web['website_id'] = $website;
  2577. $goods = Good::where('website_id', $website)
  2578. ->where('status', 2)
  2579. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2580. ->latest('updated_at')
  2581. ->offset(($data['page'] - 1) * $data['pageSize'])
  2582. ->limit($data['pageSize'])
  2583. ->get();
  2584. if (!empty($goods)) {
  2585. if ($goods->count() > 1 && !empty($goods)) {
  2586. $goods = $this->processGoods($goods, $web);
  2587. }
  2588. } else {
  2589. $goods = [];
  2590. }
  2591. $result = [
  2592. 'category' => $cat_tree,
  2593. 'goods' => $goods,
  2594. ];
  2595. // $resul['goods'] = $goods;
  2596. if (empty($result)) {
  2597. return Result::error("查询失败", 0);
  2598. }
  2599. return Result::success($result);
  2600. }
  2601. /*
  2602. * 获取商品列表
  2603. * @param array $data
  2604. * @return array
  2605. * */
  2606. public function getWebsiteshopList(array $data): array
  2607. {
  2608. // return Result::success($data);
  2609. $where = [
  2610. 'status' => 2,
  2611. 'website_id' => $data['website_id'],
  2612. ];
  2613. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2614. // return Result::error("查询失败", 0);
  2615. // }
  2616. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2617. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2618. $data['catid'] = $category->category_id ?? 0;
  2619. }
  2620. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2621. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2622. }
  2623. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2624. array_push($where, ['type_id', $data['type_id']]);
  2625. }
  2626. $query = Good::where($where)
  2627. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2628. $query->where(function ($q) use ($data) {
  2629. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2630. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2631. });
  2632. })
  2633. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2634. $query->where(function ($q) use ($data) {
  2635. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2636. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2637. });
  2638. })
  2639. ->select(
  2640. 'good.id',
  2641. 'good.name',
  2642. 'good.imgurl',
  2643. 'good.description',
  2644. 'good.updated_at',
  2645. 'good.com',
  2646. 'good.catid',
  2647. 'good.type_id',
  2648. 'good.website_id',
  2649. 'good.cat_arr_id',
  2650. 'good.created_at',
  2651. 'good.city_id'
  2652. )
  2653. ->latest('updated_at');
  2654. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2655. $result['count'] = $query->clone()->count();
  2656. $result['goods'] = $this->processGoods(
  2657. $query->clone()
  2658. ->offset(($data['page'] - 1) * $data['pageSize'])
  2659. ->limit($data['pageSize'])
  2660. ->get(),
  2661. $data
  2662. );
  2663. } else {
  2664. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2665. // 获取 type_id 为 1 的数据
  2666. $result['type1'] = $this->processGoods(
  2667. $query->clone()
  2668. ->where('type_id', 1)
  2669. ->offset(($data['page'] - 1) * $data['pageSize'])
  2670. ->limit($data['pageSize'])
  2671. ->get(),
  2672. $data
  2673. );
  2674. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2675. // 获取 type_id 为 2 的数据
  2676. $result['type2'] = $this->processGoods(
  2677. $query->clone()
  2678. ->where('type_id', 2)
  2679. ->offset(($data['page'] - 1) * $data['pageSize'])
  2680. ->limit($data['pageSize'])
  2681. ->get(),
  2682. $data
  2683. );
  2684. }
  2685. if (empty($result)) {
  2686. return Result::error("查询失败", 0);
  2687. }
  2688. return Result::success($result);
  2689. }
  2690. /**
  2691. * 获取商品详情
  2692. * @param array $data
  2693. * @return array
  2694. * */
  2695. public function getWebsiteshopInfo(array $data): array
  2696. {
  2697. $where = [
  2698. 'good.status' => 2,
  2699. 'good.website_id' => $data['website_id'],
  2700. 'good.id' => $data['id'],
  2701. ];
  2702. $goods = Good::where($where)
  2703. ->where('good.id', $data['id'])
  2704. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2705. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2706. ->first();
  2707. if (empty($goods)) {
  2708. return Result::error("查询失败", 0);
  2709. }
  2710. $goods->imgurl = json_decode($goods->imgurl, true);
  2711. return Result::success($goods);
  2712. }
  2713. /**
  2714. * plus pro 处理文章路由问题
  2715. */
  2716. function processArticlePro($website_id)
  2717. {
  2718. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2719. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2720. // // 取出category_id 对应的aLIas_pinyin
  2721. // $categoryIds = array_column($categorys, 'category_id');
  2722. // $categoryPIds = array_column($categorys, 'pid');
  2723. // $aliasPinyins = array_column($categorys, 'path');
  2724. // $alias = array_column($categorys, 'alias');
  2725. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2726. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2727. // // return Result::success($cat_arr);
  2728. // // $catiall = [];
  2729. // //一级所有子级的记录
  2730. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2731. // return [
  2732. // 'cat_1st_arr' => $cat_alias_arr,
  2733. // 'catiall' => $cat_arr,
  2734. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2735. // 'categoryIds' => $categoryIds,
  2736. // ];
  2737. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2738. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2739. // 取出category_id 对应的aLIas_pinyin
  2740. $categoryIds = array_column($categorys, 'category_id');
  2741. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2742. return $pid != 0;
  2743. })));
  2744. $category_path = array_column($categorys, 'path');
  2745. $cat_arr = array_combine($categoryIds, $category_path);
  2746. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2747. $catiall = [];
  2748. //一级所有子级的记录
  2749. $cat_1st_arr = [];
  2750. foreach ($categorys as $key => $value) {
  2751. // $category_arr_id = json_decode($value->category_arr_id);
  2752. // $pinyin_str = '';
  2753. // // 算出一级 并且算出子级
  2754. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2755. $cat_1st_arr[$value->pid][] = $value->category_id;
  2756. }
  2757. // foreach ($category_arr_id as $k => $v) {
  2758. // $pinyin_str .= $cat_arr[$v] . '/';
  2759. // }
  2760. // $pinyin_str = rtrim($pinyin_str, '/');
  2761. $catiall[$value->category_id]['alias'] = $value->alias;
  2762. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2763. $catiall[$value->category_id]['type'] = $value->type;
  2764. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2765. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2766. }
  2767. return [
  2768. 'cat_1st_arr' => $cat_1st_arr,
  2769. 'catiall' => $catiall,
  2770. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2771. 'categoryIds' => $categoryIds,
  2772. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2773. 'categoryPIds' => $categoryPIds,
  2774. ];
  2775. }
  2776. /**
  2777. * 封装处理文章的路由问题
  2778. * */
  2779. function processArticles($articles, $data)
  2780. {
  2781. // 检查 $articles 是否为数组或可迭代对象
  2782. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2783. return $articles->map(function ($article) use ($data) {
  2784. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2785. $catid = $article->cat_arr_id ?? '';
  2786. }
  2787. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2788. $catid = $article->category_arr_id ?? '';
  2789. }
  2790. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2791. $level = json_decode($catid, true);
  2792. if (!is_array($level)) {
  2793. return $article;
  2794. } else {
  2795. $level = array_map('intval', $level);
  2796. }
  2797. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2798. ->where($data)
  2799. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2800. ->pluck('aLIas_pinyin')
  2801. ->implode('/');
  2802. $article->pinyin = $pinyin ?? '';
  2803. return $article;
  2804. });
  2805. } else {
  2806. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2807. $catid = $articles->cat_arr_id ?? '';
  2808. $level = json_decode($catid, true);
  2809. if (!is_array($level)) {
  2810. return $articles;
  2811. } else {
  2812. $level = array_map('intval', $level);
  2813. }
  2814. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2815. ->where($data)
  2816. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2817. ->pluck('aLIas_pinyin')
  2818. ->implode('/');
  2819. $articles->pinyin = $pinyin ?? '';
  2820. return $articles;
  2821. }
  2822. }
  2823. // 封装处理由问题
  2824. function processJob($job, $data)
  2825. {
  2826. return $job->map(function ($job) use ($data) {
  2827. $category = $job->cat_arr_id ?? '';
  2828. $cityid = $job->city_arr_id ?? '';
  2829. $city = json_decode($cityid, true);
  2830. $pinyin = '';
  2831. $level = json_decode($category, true);
  2832. // 路由
  2833. if (!empty($level) && is_array($level)) {
  2834. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2835. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2836. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2837. ->get(['aLIas_pinyin'])
  2838. ->pluck('aLIas_pinyin')
  2839. ->implode('/');
  2840. if (empty($pinyin)) {
  2841. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2842. }
  2843. $job->pinyin = $pinyin;
  2844. }
  2845. // 取职位-城市 市??省
  2846. if (!empty($city) && is_array($city)) {
  2847. if (isset($city[1]) && !empty($city[1])) {
  2848. $city = District::where('id', $city[1])->first(['name']);
  2849. $job->city_name = $city->name ?? '';
  2850. } else if (isset($city[0]) && !empty($city[0])) {
  2851. $city = District::where('id', $city[0])->first(['name']);
  2852. $job->city_name = $city->name ?? '';
  2853. } else {
  2854. $job->city_name = '全国';
  2855. }
  2856. }
  2857. // 获取简历最后一级地区
  2858. if (isset($job->city_id) && !empty($job->city_id)) {
  2859. $city = District::where('id', $job->city_id)->first(['name']);
  2860. $job->hunt_cityname = $city->name ?? '';
  2861. }
  2862. // 组合详细地址
  2863. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2864. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2865. if (is_array($address_id) && !empty($address_id)) {
  2866. $address = District::whereIn('id', $address_id)
  2867. ->orderBy('level', 'asc')
  2868. ->get(['name'])
  2869. ->pluck('name')
  2870. ->implode('');
  2871. // $job->address_name = $address ?? '';
  2872. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2873. }
  2874. }
  2875. // 取行业
  2876. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2877. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2878. if (!empty($job->industry)) {
  2879. $query->where('hyid', $job->industry);
  2880. } else if (!empty($job->hy_id)) {
  2881. $query->where('hyid', $job->hy_id);
  2882. } else if (!empty($job->company_hy_id)) {
  2883. $query->where('hyid', $job->company_hy_id);
  2884. } else {
  2885. $query->where('hyid', $job->job_industry);
  2886. }
  2887. })->first(['hyname']);
  2888. $job->hy_name = $hy_name->hyname ?? '';
  2889. }
  2890. // 取职位类别
  2891. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2892. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2893. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2894. $job->zw_name = $zw_name->zwname ?? '';
  2895. }
  2896. // 取具体职位
  2897. 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))) {
  2898. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2899. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2900. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2901. }
  2902. // 取工作经验
  2903. if (isset($job->experience) && !empty($job->experience)) {
  2904. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2905. $job->experience_name = $experience->ename ?? '';
  2906. }
  2907. // 取学历
  2908. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2909. $education = $job->educational ?? $job->school_education;
  2910. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2911. $job->education_name = $education->ename ?? '';
  2912. }
  2913. // 语言
  2914. if (isset($job->language) && !empty($job->language)) {
  2915. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2916. $job->language_name = $language->ename ?? '';
  2917. }
  2918. // 薪资
  2919. if (isset($job->salary) && !empty($job->salary)) {
  2920. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2921. $job->salary_name = $salary->ename ?? '';
  2922. }
  2923. // 职位性质
  2924. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2925. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2926. $job->job_nature_name = $job_nature->ename ?? '';
  2927. }
  2928. // 公司规模
  2929. if (isset($job->company_size) && !empty($job->company_size)) {
  2930. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2931. $job->company_size_name = $company_size->ename ?? '';
  2932. }
  2933. // 公司性质
  2934. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2935. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2936. $job->company_nature_name = $company_nature->nature_name ?? '';
  2937. }
  2938. // $job->pinyin = $pinyin;
  2939. return $job;
  2940. });
  2941. }
  2942. /**
  2943. * 获取书籍模块
  2944. * @param array $data
  2945. * @return array
  2946. * */
  2947. public function getWebsiteBook(array $data): array
  2948. {
  2949. $input['id'] = $data['id'];
  2950. $input['website_id'] = $data['website_id'];
  2951. // 将 JSON 字符串转换为 PHP 数组
  2952. $data = json_decode($input['id'], true);
  2953. // 使用 array_map 处理每个元素
  2954. $result = array_map(function ($item) use ($input) {
  2955. // 检查parent元素是否存在且不是undefined
  2956. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2957. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2958. $website = [
  2959. 'website_id' => $input['website_id'],
  2960. ];
  2961. // 查询栏目名称
  2962. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2963. if (empty($category)) {
  2964. $parent_alias = '';
  2965. $parent_pinyin = null;
  2966. $imgBooks = [];
  2967. $textBooks = [];
  2968. } else {
  2969. $parent_alias = $category->alias ?? '';
  2970. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2971. // 查找子分类ID数组
  2972. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2973. array_push($childCategoryIds, $parentCatId);
  2974. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2975. if ($parentImgNum != 0) {
  2976. // 查询图片新闻
  2977. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2978. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2979. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2980. })
  2981. ->where('book.status', 2)
  2982. ->where('book.img_url', '!=', '')
  2983. ->where('book.website_id', $website['website_id'])
  2984. ->leftJoin('website_category', function ($join) use ($website) {
  2985. $join->on('book.cat_id', '=', 'website_category.category_id')
  2986. ->where('website_category.website_id', '=', $website['website_id']);
  2987. })
  2988. ->select(
  2989. 'book.id',
  2990. 'book.title',
  2991. 'book.img_url',
  2992. 'book.price',
  2993. 'book.market_price',
  2994. 'book.description',
  2995. 'book.cat_id',
  2996. 'book.description',
  2997. 'book.updated_at',
  2998. 'website_category.alias as category_name',
  2999. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3000. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3001. )
  3002. ->orderBy('updated_at', 'desc')
  3003. ->limit($parentImgNum)
  3004. ->get()->all();
  3005. // 查询文字新闻
  3006. }
  3007. if ($parentTextNum != 0) {
  3008. $textBooks = [];
  3009. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3010. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3011. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3012. })
  3013. ->where('book.status', 2)
  3014. ->where('book.website_id', $website['website_id'])
  3015. ->leftJoin('website_category', function ($join) use ($website) {
  3016. $join->on('book.cat_id', '=', 'website_category.category_id')
  3017. ->where('website_category.website_id', '=', $website['website_id']);
  3018. })
  3019. ->select(
  3020. 'book.id',
  3021. 'book.title',
  3022. 'book.img_url',
  3023. 'book.price',
  3024. 'book.market_price',
  3025. 'book.description',
  3026. 'book.cat_id',
  3027. 'book.description',
  3028. 'book.updated_at',
  3029. 'website_category.alias as category_name',
  3030. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3031. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3032. )
  3033. ->orderBy('updated_at', 'desc')
  3034. ->limit($parentTextNum)
  3035. ->get()->all();
  3036. }
  3037. }
  3038. }
  3039. $resultItem = [
  3040. 'alias' => $parent_alias ?? '',
  3041. 'category_id' => $parentCatId ?? 0,
  3042. 'pinyin' => $parent_pinyin ?? null,
  3043. 'imgnum' => $imgBooks ?? [],
  3044. 'textnum' => $textBooks ?? [],
  3045. ];
  3046. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3047. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3048. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3049. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3050. ->get()->all();
  3051. if (!empty($childCategory)) {
  3052. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3053. // 查询子栏目名称
  3054. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3055. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3056. ->first();
  3057. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3058. $childImgArticles = [];
  3059. $childTextArticles = [];
  3060. $resultItem['child'] = [];
  3061. } else {
  3062. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3063. // 查询子栏目图片新闻
  3064. $childImgArticles = Book::where('cat_id', $childCatId)
  3065. ->where('status', 2)
  3066. ->where('img_url', '!=', '')
  3067. ->where('book.website_id', $website['website_id'])
  3068. ->leftJoin('website_category', function ($join) use ($website) {
  3069. $join->on('book.cat_id', '=', 'website_category.category_id')
  3070. ->where('website_category.website_id', '=', $website['website_id']);
  3071. })
  3072. ->select(
  3073. 'book.id',
  3074. 'book.title',
  3075. 'book.img_url',
  3076. 'book.price',
  3077. 'book.market_price',
  3078. 'book.description',
  3079. 'book.cat_id',
  3080. 'book.description',
  3081. 'book.updated_at',
  3082. DB::raw("'$child_pinyin' as pinyin")
  3083. )
  3084. ->orderBy('updated_at', 'desc')
  3085. ->limit($childImgNum)
  3086. ->get()->all();
  3087. // 查询子栏目文字新闻
  3088. $childTextArticles = Book::where('cat_id', $childCatId)
  3089. ->where('status', 2)
  3090. ->where('book.website_id', $website['website_id'])
  3091. ->leftJoin('website_category', function ($join) use ($website) {
  3092. $join->on('book.cat_id', '=', 'website_category.category_id')
  3093. ->where('website_category.website_id', '=', $website['website_id']);
  3094. })
  3095. ->select(
  3096. 'book.id',
  3097. 'book.title',
  3098. 'book.img_url',
  3099. 'book.price',
  3100. 'book.market_price',
  3101. 'book.description',
  3102. 'book.cat_id',
  3103. 'book.description',
  3104. 'book.updated_at',
  3105. DB::raw("'$child_pinyin' as pinyin")
  3106. )
  3107. ->orderBy('updated_at', 'desc')
  3108. ->limit($childTextNum)
  3109. ->get()->all();
  3110. $resultItem['child'] = [
  3111. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3112. 'category_id' => $childCatId,
  3113. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3114. 'all_childcat' => $childCategory,
  3115. 'imgnum' => $childImgArticles,
  3116. 'textnum' => $childTextArticles,
  3117. ];
  3118. }
  3119. }
  3120. } else {
  3121. $resultItem['child'] = [];
  3122. }
  3123. return $resultItem;
  3124. }, $data);
  3125. return Result::success($result);
  3126. }
  3127. /**
  3128. * 获取书刊列表
  3129. * @param array $data
  3130. * @return array
  3131. * */
  3132. public function getWebsiteBookList(array $data): array
  3133. {
  3134. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3135. if (empty($web)) {
  3136. return Result::error("查询失败", 0);
  3137. }
  3138. $catid = $data['id'];
  3139. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3140. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3141. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3142. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3143. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3144. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3145. ->where('pid', $category['pid'])
  3146. ->select(
  3147. 'category_id',
  3148. 'alias',
  3149. 'aLIas_pinyin',
  3150. 'pid',
  3151. 'sort',
  3152. 'is_url',
  3153. 'web_url',
  3154. 'seo_title',
  3155. 'seo_keywords',
  3156. 'seo_description',
  3157. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3158. )
  3159. ->orderBy('sort')
  3160. ->get()->all();
  3161. if (empty($category)) {
  3162. return Result::error("查询失败", 0);
  3163. }
  3164. $query = Book::where('book.status', 2)
  3165. ->where('book.website_id', $data['website_id'])
  3166. ->where('book.cat_id', $catid)
  3167. ->select(
  3168. 'book.id',
  3169. 'book.title',
  3170. 'book.img_url',
  3171. 'book.description',
  3172. 'book.updated_at',
  3173. 'book.cat_id',
  3174. DB::raw("'$pinyin' as pinyin")
  3175. )
  3176. ->orderBy('book.updated_at', 'desc');
  3177. $count = $query->count();
  3178. $query = clone $query;
  3179. $Book = $query
  3180. ->limit($data['pageSize'])
  3181. ->offset(($data['page'] - 1) * $data['pageSize'])
  3182. ->get()->all();
  3183. $result = [
  3184. 'category' => $categorys,
  3185. 'books' => $Book,
  3186. 'count' => $count,
  3187. ];
  3188. // if(empty($result)){
  3189. // return Result::error("查询失败", 0);
  3190. // }
  3191. return Result::success($result);
  3192. }
  3193. /**
  3194. * 获取书刊详情
  3195. * @param array $data
  3196. * @return array
  3197. * */
  3198. public function getWebsiteBookInfo(array $data): array
  3199. {
  3200. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3201. if (empty($web)) {
  3202. return Result::error("查询失败", 0);
  3203. }
  3204. $book = Book::where('status', 2)
  3205. ->where('website_id', $data['website_id'])
  3206. ->where('id', $data['id'])
  3207. ->select(
  3208. 'book.*',
  3209. )
  3210. ->orderBy('updated_at', 'desc')
  3211. ->first();
  3212. if (empty($book)) {
  3213. return Result::error("查询失败", 0);
  3214. }
  3215. // 先查询当前分类的 pid
  3216. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3217. ->where('category_id', $book['cat_id'])
  3218. ->first(['pid', 'category_id']);
  3219. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3220. if (!empty($carpid)) {
  3221. if ($carpid->pid != 0) {
  3222. $pid = $carpid['pid'];
  3223. // $parent_pinyin = '';
  3224. } else {
  3225. $pid = $carpid['category_id'];
  3226. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3227. }
  3228. }
  3229. $categorys = $query->where('pid', $pid)
  3230. ->select(
  3231. 'category_id',
  3232. 'alias',
  3233. 'aLIas_pinyin',
  3234. 'pid',
  3235. 'sort',
  3236. 'is_url',
  3237. 'web_url',
  3238. 'category_arr_id as cat_arr_id',
  3239. )
  3240. ->orderBy('sort')
  3241. ->get();
  3242. $category = $this->processArticle($categorys, $data);
  3243. $result = [
  3244. 'category' => $category,
  3245. 'books' => $book,
  3246. ];
  3247. return Result::success($result);
  3248. }
  3249. /**
  3250. * 尝试
  3251. * @param array $data
  3252. * @return array
  3253. * */
  3254. public function test(array $data): array
  3255. {
  3256. $input['id'] = $data['id'];
  3257. $input['website_id'] = $data['website_id'];
  3258. // 将 JSON 字符串转换为 PHP 数组
  3259. $data = json_decode($input['id'], true);
  3260. $result = [];
  3261. $article = $data;
  3262. $result = array_map(function ($item) use ($input) {
  3263. $website = [
  3264. 'website_id' => $input['website_id'],
  3265. ];
  3266. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3267. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3268. $parent = [
  3269. 0 => $category['category_id'] ?? [],
  3270. 1 => $parentImgNum ?? [],
  3271. 2 => $parentTextNum ?? [],
  3272. ];
  3273. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3274. $child = [];
  3275. $resultItem = [
  3276. // 'alias' => $parent_alias ?? '',
  3277. 'category_id' => $parentCatId ?? 0,
  3278. 'pinyin' => $parentImgNum ?? null,
  3279. 'imgnum' => $parentTextNum ?? [],
  3280. // 'textnum' => $textArticles ?? [],
  3281. ];
  3282. return $parent;
  3283. }, $data);
  3284. return Result::success($result);
  3285. // });
  3286. }
  3287. /**
  3288. * 封装处理文章的路由问题
  3289. * */
  3290. function processArticle($article, $data)
  3291. {
  3292. return $article->map(function ($article) use ($data) {
  3293. $catid = $article->cat_arr_id ?? '';
  3294. $level = json_decode($catid, true);
  3295. $pinyin = '';
  3296. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3297. if (!empty($level) && is_array($level)) {
  3298. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3299. ->where('website_id', $data['website_id'])
  3300. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3301. ->get(['aLIas_pinyin'])
  3302. ->pluck('aLIas_pinyin')
  3303. ->implode('/');
  3304. } else {
  3305. $pinyin = '';
  3306. }
  3307. $article->pinyin = $pinyin;
  3308. return $article;
  3309. });
  3310. }
  3311. /**
  3312. * c端-获取招工招聘下拉选框
  3313. * @param array $data
  3314. * @return array
  3315. * */
  3316. public function getWebsiteJobSelect(array $data): array
  3317. {
  3318. $web = Website::where('id', $data['website_id'])->first();
  3319. if (empty($web)) {
  3320. return Result::error("该网站不存在", 0);
  3321. }
  3322. $hy = JobIndustry::get()->all();
  3323. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3324. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3325. $result = [
  3326. 'hy' => $hy,
  3327. 'zw' => $zw,
  3328. 'jtzw' => $jtzw,
  3329. ];
  3330. if (empty($result)) {
  3331. return Result::error("查询失败", 0);
  3332. }
  3333. return Result::success($result);
  3334. }
  3335. /**
  3336. * c端-获取招工招聘
  3337. * @param array $data
  3338. * @return array
  3339. * */
  3340. public function getWebsiteJob(array $data): array
  3341. {
  3342. $web = Website::where('id', $data['website_id'])->first();
  3343. if (empty($web)) {
  3344. return Result::error("该网站不存在", 0);
  3345. }
  3346. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3347. ->where('job_hunting.website_id', $data['website_id'])
  3348. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3349. $query->where(function ($q) use ($data) {
  3350. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3351. });
  3352. })
  3353. ->select(
  3354. 'job_hunting.id',
  3355. 'job_hunting.catid',
  3356. 'job_hunting.cat_arr_id',
  3357. 'job_hunting.job_name_get',
  3358. 'job_hunting.industry',
  3359. 'job_hunting.name',
  3360. 'job_hunting.sexy',
  3361. 'job_hunting.origin',
  3362. 'job_hunting.city_arr_id',
  3363. 'job_hunting.experience',
  3364. 'job_hunting.updated_at',
  3365. 'job_hunting.salary',
  3366. 'job_hunting.skillList',
  3367. 'job_hunting.slelf_evaluation',
  3368. )
  3369. ->orderBy('updated_at', 'desc')
  3370. ->limit($data['job1_num'])
  3371. ->get();
  3372. $web['website_id'] = $data['website_id'];
  3373. if (empty($job_hunting)) {
  3374. $job_huntings = "未查询到相关简历信息";
  3375. } else {
  3376. $job_huntings = $this->processJob($job_hunting, $web);
  3377. }
  3378. // 0:待审核 1:已通过 2:已拒绝
  3379. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3380. ->where('job_recruiting.website_id', $data['website_id'])
  3381. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3382. $query->where(function ($q) use ($data) {
  3383. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3384. });
  3385. })
  3386. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3387. ->select(
  3388. 'job_recruiting.id',
  3389. 'job_recruiting.catid',
  3390. 'job_recruiting.cat_arr_id',
  3391. 'job_recruiting.title',
  3392. 'job_recruiting.jtzw_id',
  3393. 'job_recruiting.hy_id',
  3394. 'job_recruiting.city_arr_id',
  3395. 'job_recruiting.due_data',
  3396. 'job_recruiting.updated_at',
  3397. 'job_recruiting.experience',
  3398. 'job_recruiting.educational',
  3399. 'job_recruiting.salary',
  3400. 'job_recruiting.zw_id',
  3401. 'job_company.business_name',
  3402. 'job_recruiting.keyword',
  3403. 'job_recruiting.description',
  3404. )
  3405. ->orderBy('updated_at', 'desc')
  3406. ->limit($data['job2_num'])
  3407. ->get();
  3408. if (empty($job_recruiting->toArray())) {
  3409. $job_recruitings = "未查询到相关职位信息";
  3410. } else {
  3411. $job_recruitings = $this->processJob($job_recruiting, $web);
  3412. }
  3413. $result = [
  3414. 'job_hunting' => $job_huntings,
  3415. 'job_recuiting' => $job_recruitings,
  3416. ];
  3417. return Result::success($result);
  3418. }
  3419. /**
  3420. * c端-获取招工招聘列表
  3421. * @param array $data
  3422. * @return array
  3423. * */
  3424. public function getWebsiteJobList(array $data): array
  3425. {
  3426. $recruit_where = [];
  3427. $hunt_where = [];
  3428. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3429. if (empty($web)) {
  3430. return Result::error("此网站不存在", 0);
  3431. }
  3432. $website_id['website_id'] = $data['website_id'];
  3433. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3434. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3435. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3436. }
  3437. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3438. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3439. }
  3440. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3441. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3442. }
  3443. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3444. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3445. }
  3446. $query = JobRecruiting::where('job_recruiting.status', 1)
  3447. ->where('job_recruiting.website_id', $data['website_id'])
  3448. ->where($recruit_where)
  3449. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3450. $query->where(function ($q) use ($data) {
  3451. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3452. });
  3453. })
  3454. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3455. $query->where(function ($q) use ($data) {
  3456. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3457. });
  3458. })
  3459. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3460. ->select(
  3461. 'job_recruiting.id',
  3462. 'job_recruiting.catid',
  3463. 'job_recruiting.hy_id',
  3464. 'job_recruiting.title',
  3465. 'job_recruiting.zw_id',
  3466. 'job_recruiting.educational',
  3467. 'job_recruiting.jtzw_id',
  3468. 'job_recruiting.city_arr_id',
  3469. 'job_recruiting.due_data',
  3470. 'job_recruiting.experience',
  3471. 'job_recruiting.cat_arr_id',
  3472. 'job_recruiting.updated_at',
  3473. 'job_company.business_name',
  3474. 'job_recruiting.keyword',
  3475. 'job_recruiting.description',
  3476. )
  3477. ->orderBy('job_recruiting.updated_at', 'desc');
  3478. $recruit_count = $query->count();
  3479. $query = clone $query;
  3480. $JobRecruiting = $query
  3481. ->offset(($data['page'] - 1) * $data['pageSize'])
  3482. ->limit($data['pageSize'])
  3483. ->get();
  3484. if (empty($JobRecruiting)) {
  3485. $JobRecruiting = "暂无相关职位信息";
  3486. } else {
  3487. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3488. }
  3489. }
  3490. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3491. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3492. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3493. }
  3494. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3495. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3496. }
  3497. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3498. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3499. }
  3500. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3501. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3502. }
  3503. $query = JobHunting::where('job_hunting.status', 2)
  3504. ->where('job_hunting.website_id', $data['website_id'])
  3505. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3506. ->where($hunt_where)
  3507. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3508. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3509. // })
  3510. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3511. $query->where(function ($q) use ($data) {
  3512. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3513. });
  3514. })
  3515. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3516. $query->where(function ($q) use ($data) {
  3517. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3518. });
  3519. })
  3520. ->select(
  3521. 'job_hunting.id',
  3522. 'job_hunting.catid',
  3523. 'job_hunting.sexy',
  3524. 'job_hunting.experience',
  3525. 'job_hunting.origin',
  3526. 'job_hunting.industry',
  3527. 'job_hunting.name',
  3528. 'job_hunting.job',
  3529. 'job_hunting.job_name_get',
  3530. 'job_hunting.city_arr_id',
  3531. 'job_hunting.cat_arr_id',
  3532. 'job_hunting.created_at',
  3533. 'job_hunting.updated_at',
  3534. 'job_position.zwname as job_name',
  3535. 'job_hunting.skillList',
  3536. 'job_hunting.slelf_evaluation',
  3537. )
  3538. ->orderBy('job_hunting.updated_at', 'desc');
  3539. $hunt_count = $query->count();
  3540. $query = clone $query;
  3541. $JobHunting = $query
  3542. ->offset(($data['page'] - 1) * $data['pageSize'])
  3543. ->limit($data['pageSize'])
  3544. ->get();
  3545. if (empty($JobHunting)) {
  3546. $JobRecruiting = "暂无相关简历信息";
  3547. } else {
  3548. $JobHunting = $this->processJob($JobHunting, $website_id);
  3549. }
  3550. }
  3551. $result = [
  3552. 'JobRecruiting' => $JobRecruiting ?? [],
  3553. 'recruit_count' => $recruit_count ?? 0,
  3554. 'JobHunting' => $JobHunting ?? [],
  3555. 'hunt_count' => $hunt_count ?? 0,
  3556. ];
  3557. return Result::success($result);
  3558. }
  3559. /**
  3560. * c端-获取招工招聘详情
  3561. * @param array $data
  3562. * @return array
  3563. * */
  3564. public function getWebsiteJobInfo(array $data): array
  3565. {
  3566. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3567. if (empty($web)) {
  3568. return Result::error("该网站不存在", 0);
  3569. }
  3570. $webid = [
  3571. 'website_id' => $data['website_id'],
  3572. ];
  3573. // 职位相关信息
  3574. if ($data['type'] == 1) {
  3575. $query = JobRecruiting::where('status', 1)
  3576. ->where('website_id', $data['website_id'])
  3577. ->select('*');
  3578. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3579. $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();
  3580. if (!empty($company)) {
  3581. $result['company'] = $this->processJob($company, $webid);
  3582. }
  3583. $other_job = JobRecruiting::where('status', 1)
  3584. ->where('website_id', $data['website_id'])
  3585. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3586. ->where('id', '!=', $data['id'])
  3587. ->where('user_id', '=', $job[0]['user_id'])
  3588. ->limit($data['pageSize'])
  3589. ->get();
  3590. if (!empty($other_job)) {
  3591. $result['other_job'] = $this->processJob($other_job, $webid);
  3592. }
  3593. } else {
  3594. // 简历相关信息
  3595. $job = JobHunting::where('job_hunting.status', 2)
  3596. ->where('job_hunting.website_id', $data['website_id'])
  3597. ->where('job_hunting.id', $data['id'])
  3598. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3599. ->select('job_hunting.*', 'user_name')
  3600. ->get();
  3601. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3602. if (!empty($resume->toArray())) {
  3603. $result['resume'] = 1;
  3604. } else {
  3605. $result['resume'] = 0;
  3606. }
  3607. }
  3608. if (empty($job->toArray())) {
  3609. return Result::error("id参数错误", 0);
  3610. }
  3611. if (!empty($job[0]['job_experience'])) {
  3612. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3613. if (!empty($job_experience)) {
  3614. // $hy = [];
  3615. foreach ($job_experience as $key => $value) {
  3616. // $id = $value['id'];
  3617. $hy[$key] = $value['job_industry'];
  3618. $zw_id[$key] = $value['job_typename'];
  3619. $jtzw_id[$key] = $value['job_name'];
  3620. }
  3621. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3622. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3623. // 先将关联表转换为索引数组,提高查找效率
  3624. $hyLookup = [];
  3625. foreach ($hy_table as $item) {
  3626. $hyLookup[$item['hyid']] = $item['hyname'];
  3627. }
  3628. $zwLookup = [];
  3629. foreach ($zw_table as $item) {
  3630. $zwLookup[$item['zwid']] = $item['zwname'];
  3631. }
  3632. foreach ($job_experience as $key => &$value) {
  3633. // 处理行业名称
  3634. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3635. $value['hy_name'] = $hyLookup[$hy[$key]];
  3636. }
  3637. // 处理职位名称
  3638. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3639. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3640. }
  3641. // 处理具体职位名称
  3642. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3643. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3644. }
  3645. }
  3646. // 释放引用,防止意外修改后续代码
  3647. unset($value);
  3648. }
  3649. $result['job_experience'] = $job_experience ?? [];
  3650. }
  3651. if (!empty($job[0]['education_experience'])) {
  3652. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3653. if (!empty($education_experience)) {
  3654. foreach ($education_experience as $key => $value) {
  3655. // $id = $value['id'];
  3656. $education[$key] = $value['school_education'];
  3657. }
  3658. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3659. // // 先将关联表转换为索引数组,提高查找效率
  3660. $educationLookup = [];
  3661. foreach ($education_table as $item) {
  3662. $educationLookup[$item['evalue']] = $item['ename'];
  3663. }
  3664. foreach ($education_experience as $key => &$value) {
  3665. // 处理学历名称
  3666. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3667. $value['education_name'] = $educationLookup[$education[$key]];
  3668. }
  3669. }
  3670. }
  3671. $result['education_experience'] = $job_experience ?? [];
  3672. }
  3673. $result['job'] = $this->processJob($job, $webid);
  3674. // // 返现对应的栏目
  3675. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3676. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3677. ->whereIn('category_id', $catid)
  3678. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3679. ->orderBy('pid')->get()->all();
  3680. if (!empty($category)) {
  3681. $result['category'] = $category;
  3682. }
  3683. $result['job'] = $job;
  3684. $result['job_experience'] = $job_experience ?? [];
  3685. $result['education_experience'] = $education_experience ?? [];
  3686. if (empty($result)) {
  3687. return Result::error("参数错误", 0);
  3688. }
  3689. return Result::success($result);
  3690. }
  3691. /**
  3692. * c端-申请职位
  3693. * @param array $data
  3694. * @return array
  3695. * */
  3696. public function getWebsiteJobApply(array $data): array
  3697. {
  3698. // 首先验证网站是否存在
  3699. // return Result::success($data);
  3700. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3701. if (empty($web)) {
  3702. return Result::error("该网站不存在", 0);
  3703. }
  3704. // 验证用户是否存在且为个人会员/管理员
  3705. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3706. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3707. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3708. return Result::error("用户不存在", 0);
  3709. }
  3710. // 去除重复元素和空元素,并保持原始顺序
  3711. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3712. return !empty($value);
  3713. }));
  3714. // 验证职位是否存在 1:审核通过
  3715. $recruiting = JobRecruiting::where('status', 1)
  3716. ->where('website_id', $data['website_id'])
  3717. ->whereIn('id', $data['recruit_id'])
  3718. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3719. if (empty($recruiting)) {
  3720. return Result::error("该职位不存在", 0);
  3721. }
  3722. // 简历是否存在
  3723. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3724. if (empty($hunt_id)) {
  3725. return Result::error("该简历不存在", 0);
  3726. }
  3727. $data['hunt_id'] = $hunt_id['hunt_id'];
  3728. // // 验证是否已投递过该职位
  3729. $apply = JobApply::where('user_id', $data['user_id'])
  3730. ->where('hunt_id', $data['hunt_id'])
  3731. ->where('website_id', $data['website_id'])
  3732. ->whereIn('recruit_id', $data['recruit_id'])
  3733. ->get(['recruit_id']);
  3734. if (!empty($apply->toArray())) {
  3735. return Result::error("您已投递过该职位!");
  3736. }
  3737. $insertData = array_map(function ($recruiting) use ($data) {
  3738. return [
  3739. 'user_id' => $data['user_id'],
  3740. 'hunt_id' => $data['hunt_id'],
  3741. 'website_id' => $data['website_id'],
  3742. 'recruit_id' => $recruiting['recruit_id'],
  3743. 'receiver_id' => $recruiting['receiver_id'],
  3744. 'status' => 1,
  3745. ];
  3746. }, $recruiting);
  3747. // 批量插入数据
  3748. $result = JobApply::insert($insertData);
  3749. if (empty($result)) {
  3750. return Result::error("投递失败", 0);
  3751. }
  3752. return Result::success($result);
  3753. }
  3754. /**
  3755. * 招工招聘-沟通简历
  3756. * @param array $data
  3757. * @return array
  3758. * */
  3759. public function getWebsiteJobResume(array $data): array
  3760. {
  3761. // 首先验证网站是否存在
  3762. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3763. if (empty($web)) {
  3764. return Result::error("该网站不存在", 0);
  3765. }
  3766. // return Result::success($data);
  3767. // 验证用户是否存在且为企业会员/管理员
  3768. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3769. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3770. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3771. return Result::error("用户不存在", 0);
  3772. }
  3773. // 去除重复元素和空元素,并保持原始顺序
  3774. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3775. return !empty($value);
  3776. }));
  3777. // 验证简历是否存在
  3778. $hunting = JobHunting::where('status', 2)
  3779. ->where('website_id', $data['website_id'])
  3780. ->whereIn('id', $data['hunt_id'])
  3781. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3782. if (empty($hunting)) {
  3783. return Result::error("该简历不存在", 0);
  3784. }
  3785. // 验证是否已沟通过该简历
  3786. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3787. ->where('recruit_id', $data['recruit_id'])
  3788. ->where('website_id', $data['website_id'])
  3789. ->whereIn('hunt_id', $data['hunt_id'])
  3790. ->get(['hunt_id']);
  3791. if (!empty($remuse->toArray())) {
  3792. return Result::error("您已沟通过该简历!");
  3793. }
  3794. // 准备要插入的数据数组
  3795. $insertData = array_map(function ($hunting) use ($data) {
  3796. return [
  3797. 'user_id' => $data['user_id'],
  3798. 'recruit_id' => $data['recruit_id'],
  3799. 'website_id' => $data['website_id'],
  3800. 'hunt_id' => $hunting['hunt_id'],
  3801. 'receiver_id' => $hunting['receiver_id'],
  3802. 'status' => 1,
  3803. ];
  3804. }, $hunting);
  3805. // 批量插入数据
  3806. $result = JobRemuse::insert($insertData);
  3807. if (empty($result)) {
  3808. return Result::error("沟通失败", 0);
  3809. }
  3810. return Result::success($result);
  3811. }
  3812. /**
  3813. * 招工招聘 -我的职位(企业会员)
  3814. * @param array $data
  3815. * @return array
  3816. */
  3817. public function getWebsiteJobRecruiting(array $data): array
  3818. {
  3819. $web = Website::where('id', $data['website_id'])->first('id');
  3820. if (empty($web)) {
  3821. return Result::error("该网站不存在", 0);
  3822. }
  3823. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3824. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3825. return Result::error("用户暂无权限!", 0);
  3826. }
  3827. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3828. $result = JobRecruiting::where('website_id', $data['website_id'])
  3829. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3830. $query->where('user_id', $user['id']);
  3831. })
  3832. ->where('status', 1)
  3833. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3834. ->orderBy('updated_at', 'desc')
  3835. ->limit($data['pageSize'])
  3836. ->get();
  3837. if (empty($result)) {
  3838. return Result::error("暂无相关职位信息", 0);
  3839. }
  3840. return Result::success($result);
  3841. }
  3842. /**
  3843. * c端 - 验证路由
  3844. * @param array $data
  3845. * @return array
  3846. */
  3847. /**
  3848. * c端 - 验证路由
  3849. * @param array $data
  3850. * @return array
  3851. */
  3852. public function checkWebsiteRoute(array $data): array
  3853. {
  3854. // 测试001111111222
  3855. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3856. if (empty($web)) {
  3857. return Result::error("该网站不存在", 0);
  3858. } elseif ($web['status'] != 1) {
  3859. return Result::error("网站已经关闭", 0);
  3860. }
  3861. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3862. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3863. // 验证路由是否存在
  3864. if (empty($whiteRouterInfo)) {
  3865. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3866. }
  3867. if (!empty($whiteRouterInfo)) {
  3868. return Result::success($whiteRouterInfo->toArray());
  3869. }
  3870. }
  3871. // 验证栏目路由
  3872. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3873. ->where('path', $data['all_route'])
  3874. ->get()->all();
  3875. if (count($last_category) == 0) {
  3876. return Result::error("该栏目不存在", 0);
  3877. }
  3878. if (count($last_category) > 1) {
  3879. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3880. }
  3881. if (count($last_category) == 1) {
  3882. $last_category = $last_category[0];
  3883. }
  3884. // return Result::success($last_category);
  3885. if (isset($data['id']) && !empty($data['id'])) {
  3886. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3887. switch ($last_category['type']) {
  3888. case 1:
  3889. // 文章
  3890. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3891. $article = Article::where('status', 1)
  3892. ->where('id', $data['id'])
  3893. ->where(function ($query) use ($data) {
  3894. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3895. ->orWhereNull("ignore_ids");
  3896. })
  3897. ->first(['catid']);
  3898. if (empty($article)) {
  3899. return Result::error("该文章不存在", 0);
  3900. }
  3901. // return Result::success($article);
  3902. break;
  3903. case 2:
  3904. // 商品
  3905. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3906. $article = Good::where('website_id', $data['website_id'])
  3907. ->where('status', 2)
  3908. ->where('id', $data['id'])
  3909. ->first(['cat_arr_id']);
  3910. if (empty($article)) {
  3911. return Result::error("该商品不存在", 0);
  3912. }
  3913. break;
  3914. case 3:
  3915. // 书刊信息
  3916. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3917. $article = Book::where('website_id', $data['website_id'])
  3918. ->where('status', 2)
  3919. ->where('id', $data['id'])
  3920. ->first(['id', 'cat_arr_id']);
  3921. if (empty($article)) {
  3922. return Result::error("该书刊不存在", 0);
  3923. }
  3924. break;
  3925. case 4:
  3926. // 招聘
  3927. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3928. $article = JobRecruiting::where('website_id', $data['website_id'])
  3929. ->where('status', 1)
  3930. ->where('id', $data['id'])
  3931. ->first(['cat_arr_id']);
  3932. if (empty($article)) {
  3933. return Result::error("该招聘不存在", 0);
  3934. }
  3935. break;
  3936. case 5:
  3937. // 求职
  3938. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3939. $article = JobHunting::where('website_id', $data['website_id'])
  3940. ->where('status', 2)
  3941. ->where('id', $data['id'])
  3942. ->first(['cat_arr_id']);
  3943. if (empty($article)) {
  3944. return Result::error("该求职不存在", 0);
  3945. }
  3946. break;
  3947. case 6:
  3948. // 企业
  3949. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3950. $article = Company::
  3951. // where('website_id', $data['website_id'])
  3952. // ->
  3953. where('status', 1)
  3954. ->where('id', $data['id'])
  3955. ->first(['cat_arr_id']);
  3956. if (empty($article)) {
  3957. return Result::error("该企业不存在", 0);
  3958. }
  3959. break;
  3960. case 7:
  3961. // 项目
  3962. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3963. $article = Project::where('website_id', $data['website_id'])
  3964. ->where('status', 1)
  3965. ->where('id', $data['id'])
  3966. ->first(['cat_arr_id']);
  3967. if (empty($article)) {
  3968. return Result::error("该项目不存在", 0);
  3969. }
  3970. break;
  3971. default:
  3972. return Result::error("该数据不存在", 0);
  3973. break;
  3974. }
  3975. // return Result::success($article);
  3976. // $catid =0 ;
  3977. if (!isset($article['cat_arr_id'])) {
  3978. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3979. } else {
  3980. $catidArray = json_decode($article['cat_arr_id'], true);
  3981. $catid = !empty($catidArray) ? end($catidArray) : null;
  3982. }
  3983. // return Result::success($catid);
  3984. // // return Result::success($article['cat_arr_id']);
  3985. if (empty($catid)) {
  3986. return Result::error("该栏目路径不存在", 0);
  3987. }
  3988. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3989. ->where('category_id', $catid)
  3990. ->first('path');
  3991. }
  3992. // else{
  3993. // // if ($last_category['pid'] != 0) {
  3994. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3995. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3996. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3997. // ->where('category_id',$catid)
  3998. // ->where('path',$data['all_route'])
  3999. // ->first('path');
  4000. // // } else {
  4001. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4002. // // }
  4003. // }
  4004. // return Result::success($path);
  4005. if (!empty($path) && $path['path'] != $data['all_route']) {
  4006. return Result::error('非法路径!');
  4007. } else {
  4008. return Result::success($last_category['path']);
  4009. }
  4010. }
  4011. /**
  4012. * 招工招聘 - 获取推荐职位
  4013. * @param array $data
  4014. * @return array
  4015. */
  4016. public function getWebsiteLevelJob(array $data): array
  4017. {
  4018. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4019. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4020. ->where('job_recruiting.status', 1)
  4021. ->where('job_level', $data['job_level'])
  4022. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4023. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4024. ->orderBy('job_recruiting.updated_at', 'desc')
  4025. ->limit($data['pageSize'])
  4026. ->get();
  4027. $web = ['website_id' => $data['website_id']];
  4028. if (!empty($job)) {
  4029. $result = $this->processJob($job, $web);
  4030. }
  4031. if (empty($result)) {
  4032. return Result::error("暂无相关职位信息", 0);
  4033. }
  4034. return Result::success($result);
  4035. }
  4036. /**
  4037. * 验证导航名称是否重复
  4038. * @return void
  4039. */
  4040. //20250226 产品列表
  4041. public function getGoodList(array $data): array
  4042. {
  4043. var_dump($data, '---------1-2--');
  4044. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4045. unset($data['user_type_id']);
  4046. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4047. $where = [];
  4048. if ($type_id != '10000') {
  4049. $where = [
  4050. 'good.user_id' => $user_id,
  4051. ];
  4052. }
  4053. //类型
  4054. if (isset($data['type_id']) && $data['type_id']) {
  4055. $where['good.type_id'] = $data['type_id'];
  4056. }
  4057. //名称
  4058. if (isset($data['name']) && $data['name']) {
  4059. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4060. }
  4061. //status
  4062. if (isset($data['status']) && $data['status'] != '') {
  4063. $where['good.status'] = $data['status'];
  4064. }
  4065. //status1
  4066. // if (isset($data['status1']) && $data['status1'] == 1) {
  4067. // $status1 = 1;
  4068. // }
  4069. $where1 = [];
  4070. //website_id
  4071. // if (isset($data['website_id']) && $data['website_id']) {
  4072. // $where1 = [
  4073. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4074. // ];
  4075. // }
  4076. // website_name
  4077. if (isset($data['website_name']) && $data['website_name']) {
  4078. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4079. }
  4080. // catid
  4081. if (isset($data['category_name']) && $data['category_name']) {
  4082. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4083. }
  4084. // $result = Good::where($where)
  4085. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4086. var_dump($where, '---------1---');
  4087. $result = Good::where($where)
  4088. ->when(!empty($where1), function ($query) use ($where1) {
  4089. return $query->where($where1);
  4090. })
  4091. //status 1待审核2已审核3已拒绝
  4092. ->when(isset($data['status1']), function ($query) {
  4093. return $query->whereIn('good.status', [1, 3]);
  4094. })
  4095. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4096. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4097. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4098. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4099. ->orderBy("updated_at", "desc")
  4100. ->limit($data['page_size'])
  4101. ->offset(($data['page'] - 1) * $data['page_size'])
  4102. ->get();
  4103. $count = Good::where($where)
  4104. ->when(!empty($where1), function ($query) use ($where1) {
  4105. return $query->where($where1);
  4106. })
  4107. //status 1待审核2已审核3已拒绝
  4108. ->when(isset($data['status1']), function ($query) {
  4109. return $query->whereIn('good.status', [1, 3]);
  4110. })
  4111. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4112. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4113. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4114. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4115. ->orderBy("updated_at", "desc")->count();
  4116. $data = [
  4117. 'rows' => $result->toArray(),
  4118. 'count' => $count,
  4119. ];
  4120. if (empty($result)) {
  4121. return Result::error("此栏目暂无相关产品", 0);
  4122. }
  4123. return Result::success($data);
  4124. }
  4125. public function getGoodInfo(array $data): array
  4126. {
  4127. $result = Good::where('id', $data['id'])->first();
  4128. if (empty($result)) {
  4129. return Result::error("此产品不存在", 0);
  4130. }
  4131. return Result::success($result);
  4132. }
  4133. public function addGood(array $data): array
  4134. {
  4135. // unset($data['city_arr_id']);
  4136. // unset($data['cat_arr_id']);
  4137. $data['city_id'] = end($data['city_arr_id']);
  4138. $data['catid'] = end($data['cat_arr_id']);
  4139. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4140. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4141. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4142. unset($data['imgUrl']); //大小写
  4143. if (isset($data['price']) && $data['price'] == '') {
  4144. $data['price'] = 0;
  4145. }
  4146. if ($data['imgurl'] == '') {
  4147. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4148. preg_match_all($reg, $data['detail'], $matches);
  4149. if (isset($matches[1][0])) {
  4150. //截取varchar240
  4151. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4152. }
  4153. }
  4154. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4155. //提取标题+内容中的关键词
  4156. $data['keyword'] = $data['name'];
  4157. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4158. Jieba::init(); // 初始化 jieba-php
  4159. Finalseg::init();
  4160. $segList = Jieba::cut($data['keyword']);
  4161. $segList1 = array_slice($segList, 0, 8);
  4162. $data['keyword'] = implode(',', $segList1);
  4163. }
  4164. if ($data['description'] == '') {
  4165. //提取内容中的描述
  4166. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4167. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4168. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4169. }
  4170. if ($data['status'] == 1) {
  4171. $this->sendMessage([
  4172. 'talk_type' => 200,
  4173. 'title' => $data['name'],
  4174. 'content' => '提交了审核',
  4175. 'messageType' => 3,
  4176. ]);
  4177. }
  4178. $result = Good::insert($data);
  4179. if (empty($result)) {
  4180. return Result::error("添加失败", 0);
  4181. }
  4182. return Result::success($result);
  4183. }
  4184. public function updateGood(array $data): array
  4185. {
  4186. $data['city_id'] = end($data['city_arr_id']);
  4187. $data['catid'] = end($data['cat_arr_id']);
  4188. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4189. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4190. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4191. //设置东八区
  4192. date_default_timezone_set('Asia/Shanghai');
  4193. $data['updated_at'] = date('Y-m-d H:i:s');
  4194. if (isset($data['price']) && $data['price'] == '') {
  4195. $data['price'] = 0;
  4196. }
  4197. if ($data['imgurl'] == '') {
  4198. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4199. preg_match_all($reg, $data['detail'], $matches);
  4200. if (isset($matches[1][0])) {
  4201. //截取varchar240
  4202. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4203. }
  4204. }
  4205. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4206. //提取标题+内容中的关键词
  4207. $data['keyword'] = $data['name'];
  4208. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4209. Jieba::init(); // 初始化 jieba-php
  4210. Finalseg::init();
  4211. $segList = Jieba::cut($data['keyword']);
  4212. $segList1 = array_slice($segList, 0, 8);
  4213. $data['keyword'] = implode(',', $segList1);
  4214. }
  4215. if ($data['description'] == '') {
  4216. //提取内容中的描述
  4217. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4218. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4219. }
  4220. if ($data['status'] == 1) {
  4221. $this->sendMessage([
  4222. 'talk_type' => 200,
  4223. 'title' => $data['name'],
  4224. 'content' => '提交了审核',
  4225. 'messageType' => 3,
  4226. ]);
  4227. }
  4228. $result = Good::where('id', $data['id'])->update($data);
  4229. if (empty($result)) {
  4230. return Result::error("更新失败", 0);
  4231. }
  4232. return Result::success($result);
  4233. }
  4234. public function delGood(array $data): array
  4235. {
  4236. $result = Good::where('id', $data['id'])->delete();
  4237. if (empty($result)) {
  4238. return Result::error("删除失败", 0);
  4239. }
  4240. return Result::success($result);
  4241. }
  4242. //20250226 产品列表
  4243. //20250306 求职信息
  4244. public function getJobHuntingList(array $data): array
  4245. {
  4246. $where = [];
  4247. if (isset($data['username']) && !empty($data['username'])) {
  4248. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4249. }
  4250. //status 1待审核2已审核3已拒绝
  4251. if (isset($data['status']) && $data['status'] != '') {
  4252. $where = [
  4253. 'job_hunting.status' => $data['status'],
  4254. ];
  4255. }
  4256. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4257. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4258. unset($data['type_id']);
  4259. if ($type_id != '10000') {
  4260. $where[] = ['job_hunting.user_id', '=', $user_id];
  4261. }
  4262. $result = JobHunting::where($where)
  4263. ->when(!empty($data['status1']), function ($query) use ($data) {
  4264. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4265. })
  4266. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4267. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4268. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4269. ->orderBy("updated_at", "desc")
  4270. ->limit($data['page_size'])
  4271. ->offset(($data['page'] - 1) * $data['page_size'])
  4272. ->get();
  4273. if (empty($result)) {
  4274. return Result::error("查询失败", 0);
  4275. }
  4276. $count = JobHunting::where($where)
  4277. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4278. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4279. ->count();
  4280. $data = [
  4281. 'rows' => $result->toArray(),
  4282. 'count' => $count,
  4283. ];
  4284. return Result::success($data);
  4285. }
  4286. public function getJobHuntingApply(array $data): array
  4287. {
  4288. var_dump($data, '-----------------test--------1-');
  4289. $where = [];
  4290. if (isset($data['username']) && !empty($data['username'])) {
  4291. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4292. }
  4293. if (isset($data['salary']) && !empty($data['salary'])) {
  4294. $where[] = [
  4295. 'job_hunting.salary',
  4296. '=',
  4297. $data['salary'],
  4298. ];
  4299. }
  4300. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4301. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4302. unset($data['type_id']);
  4303. if ($type_id != '10000') {
  4304. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4305. }
  4306. var_dump($where, '-----------------test---------');
  4307. $result = jobApply::where($where)
  4308. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4309. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4310. // })
  4311. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4312. ->where('job_enum.egroup', '=', 'income')
  4313. ->where('job_hunting.status', 2) //已审核
  4314. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4315. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4316. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4317. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4318. //职位----是申请职位
  4319. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4320. ->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')
  4321. ->orderBy("job_hunting.updated_at", "desc")
  4322. ->limit($data['page_size'])
  4323. ->offset(($data['page'] - 1) * $data['page_size'])
  4324. ->get();
  4325. if (empty($result)) {
  4326. return Result::error("查询失败", 0);
  4327. }
  4328. $count = jobApply::where($where)
  4329. ->where('job_enum.egroup', '=', 'income')
  4330. ->where('job_hunting.status', 2) //已审核
  4331. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4332. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4333. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4334. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4335. //职位----是申请职位
  4336. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4337. ->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')
  4338. ->count();
  4339. $data = [
  4340. 'rows' => $result->toArray(),
  4341. 'count' => $count,
  4342. ];
  4343. return Result::success($data);
  4344. }
  4345. public function addJobHunting(array $data): array
  4346. {
  4347. date_default_timezone_set('Asia/Shanghai');
  4348. unset($data['company_name']);
  4349. unset($data['job_industry']);
  4350. unset($data['job_name']);
  4351. unset($data['department']);
  4352. unset($data['job_timeList']);
  4353. unset($data['job_content']);
  4354. unset($data['job_typename']); //不知道这是啥,
  4355. $data['created_at'] = date('Y-m-d H:i:s');
  4356. $data['updated_at'] = date('Y-m-d H:i:s');
  4357. //根据用户 user_id 只能添加一次
  4358. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4359. if (!empty($result)) {
  4360. return Result::error("您已添加过求职信息", 0);
  4361. }
  4362. var_dump($result, '-----------------test---------');
  4363. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4364. if (is_string($data['city_arr_id'])) {
  4365. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4366. $cityArr = json_decode($data['city_arr_id'], true);
  4367. // 确保 $cityArr 是数组
  4368. if (is_array($cityArr)) {
  4369. $data['city_id'] = end($cityArr);
  4370. }
  4371. } else {
  4372. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4373. if (is_array($data['city_arr_id'])) {
  4374. $data['city_id'] = end($data['city_arr_id']);
  4375. }
  4376. }
  4377. }
  4378. // 处理求职所绑定栏目
  4379. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4380. if (is_string($data['cat_arr_id'])) {
  4381. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4382. // 先清理可能存在的无效 JSON 字符
  4383. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4384. $catArr = json_decode($cleanedCatArrStr, true);
  4385. // 检查 JSON 解码是否成功且结果是数组
  4386. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4387. $data['catid'] = end($catArr);
  4388. }
  4389. } else {
  4390. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4391. if (is_array($data['cat_arr_id'])) {
  4392. $data['catid'] = end($data['cat_arr_id']);
  4393. }
  4394. }
  4395. }
  4396. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4397. $this->sendMessage([
  4398. 'talk_type' => 600,
  4399. 'title' => $data['name'],
  4400. 'content' => '提交了审核',
  4401. 'messageType' => 11,
  4402. ]);
  4403. }
  4404. $result = JobHunting::create($data);
  4405. if (empty($result)) {
  4406. return Result::error("添加失败", 0);
  4407. }
  4408. return Result::success($result);
  4409. }
  4410. public function delJobHunting(array $data): array
  4411. {
  4412. $result = JobHunting::where('id', $data['id'])->delete();
  4413. if (empty($result)) {
  4414. return Result::error("删除失败", 0);
  4415. }
  4416. return Result::success($result);
  4417. }
  4418. public function updateJobHunting(array $data): array
  4419. {
  4420. //设置东八区
  4421. date_default_timezone_set('Asia/Shanghai');
  4422. unset($data['company_name']);
  4423. unset($data['job_industry']);
  4424. unset($data['job_name']);
  4425. unset($data['department']);
  4426. unset($data['job_timeList']);
  4427. unset($data['job_content']);
  4428. unset($data['job_typename']); //不知道这是啥,
  4429. $data['created_at'] = date('Y-m-d H:i:s');
  4430. $data['updated_at'] = date('Y-m-d H:i:s');
  4431. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4432. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4433. $cityArr = json_decode($data['city_arr_id'], true);
  4434. $data['city_id'] = end($cityArr);
  4435. } else {
  4436. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4437. $data['city_id'] = end($data['city_arr_id']);
  4438. }
  4439. // 处理求职所绑定栏目
  4440. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4441. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4442. $catArr = json_decode($data['cat_arr_id'], true);
  4443. $data['catid'] = end($catArr);
  4444. } else {
  4445. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4446. $data['catid'] = end($data['cat_arr_id']);
  4447. }
  4448. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4449. $this->sendMessage([
  4450. 'talk_type' => 600,
  4451. 'title' => $data['name'],
  4452. 'content' => '提交了审核',
  4453. 'messageType' => 11,
  4454. ]);
  4455. }
  4456. $result = JobHunting::where('id', $data['id'])->update($data);
  4457. if (empty($result)) {
  4458. return Result::error("更新失败", 0);
  4459. }
  4460. return Result::success($result);
  4461. }
  4462. public function getJobHuntingInfo(array $data): array
  4463. {
  4464. $result = JobHunting::where('id', $data['id'])->first();
  4465. if (empty($result)) {
  4466. return Result::error("查询失败", 0);
  4467. }
  4468. return Result::success($result);
  4469. }
  4470. public function getJobHuntingData(array $data): array
  4471. {
  4472. $jobEnum = JobEnum::get();
  4473. $jobIndustry = JobIndustry::get();
  4474. $jobNature = JobNature::get();
  4475. $jobPosition = JobPosition::get();
  4476. $data = [
  4477. 'jobEnum' => $jobEnum,
  4478. 'jobIndustry' => $jobIndustry,
  4479. 'jobNature' => $jobNature,
  4480. 'jobPosition' => $jobPosition,
  4481. ];
  4482. return Result::success($data);
  4483. }
  4484. public function delJobHuntingInfo(array $data): array
  4485. {
  4486. $result = JobHunting::where('id', $data['id'])->delete();
  4487. return Result::success();
  4488. }
  4489. //20250324 通知,公告,消息
  4490. public function delNotice(array $data): array
  4491. {
  4492. $result = Notice::where('id', $data['id'])->delete();
  4493. if ($result) {
  4494. return Result::success();
  4495. } else {
  4496. return Result::error("删除失败", 0);
  4497. }
  4498. }
  4499. public function getNoticeInfo(array $data): array
  4500. {
  4501. $result = Notice::where('id', $data['id'])->first();
  4502. // var_dump($result['re_user_ids'], '--------------------');
  4503. if (empty($result)) {
  4504. return Result::error("查询失败", 0);
  4505. }
  4506. return Result::success($result);
  4507. }
  4508. public function readNotice(array $data): array
  4509. {
  4510. $result = Notice::where('id', $data['id'])->first();
  4511. // var_dump($result['re_user_ids'], '--------------------');
  4512. if (empty($result)) {
  4513. return Result::error("查询失败", 0);
  4514. }
  4515. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4516. $re_user_ids = json_decode($result['re_user_ids'], true);
  4517. var_dump($re_user_ids, '--------------1---test---------');
  4518. var_dump($data, '--------------1---test---------');
  4519. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4520. //如果已经存在,就不再添加
  4521. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4522. $read_id = json_decode($result['read_id'], true);
  4523. if (!is_array($read_id)) {
  4524. $read_id = [];
  4525. }
  4526. if (!in_array($data['user_id'], $read_id)) {
  4527. $read_id[] = $data['user_id'];
  4528. $result['read_id'] = json_encode($read_id);
  4529. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4530. }
  4531. } else {
  4532. //如果不存在,就添加
  4533. $result['read_id'] = json_encode([$data['user_id']]);
  4534. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4535. }
  4536. }
  4537. return Result::success($result);
  4538. }
  4539. public function addNotice(array $data): array
  4540. {
  4541. date_default_timezone_set('Asia/Shanghai');
  4542. $data['created_at'] = date('Y-m-d H:i:s');
  4543. $data['updated_at'] = date('Y-m-d H:i:s');
  4544. $user_id = UserInfo::
  4545. //city_id不是null
  4546. whereNotNull('city_id')
  4547. ->whereNotNull('department_id')
  4548. ->where(function ($query) use ($data) {
  4549. $query->where(function ($subQuery) use ($data) {
  4550. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4551. });
  4552. })
  4553. ->where(function ($query) use ($data) {
  4554. $query->where(function ($subQuery) use ($data) {
  4555. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4556. });
  4557. })
  4558. ->pluck('user_id')->toArray();
  4559. $user_id = array_unique($user_id);
  4560. $chat_ids = $user_id;
  4561. $user_id = json_encode($user_id);
  4562. $data['re_user_ids'] = $user_id;
  4563. $this->sendMessage([
  4564. 'talk_type' => 700,
  4565. 'title' => $data['title'],
  4566. 'content' => '提交了审核',
  4567. 'messageType' => 5,
  4568. ]);
  4569. $result = Notice::insertGetId($data);
  4570. if (empty($result)) {
  4571. return Result::error("添加失败", 0);
  4572. }
  4573. return Result::success($result);
  4574. }
  4575. public function updateNotice(array $data): array
  4576. {
  4577. date_default_timezone_set('Asia/Shanghai');
  4578. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4579. $user_id = UserInfo::
  4580. //city_id不是null
  4581. whereNotNull('city_id')
  4582. ->whereNotNull('department_id')
  4583. ->where(function ($query) use ($data) {
  4584. $query->where(function ($subQuery) use ($data) {
  4585. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4586. });
  4587. })
  4588. ->where(function ($query) use ($data) {
  4589. $query->where(function ($subQuery) use ($data) {
  4590. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4591. });
  4592. })
  4593. ->pluck('user_id')->toArray();
  4594. $user_id = array_unique($user_id);
  4595. $user_id = json_encode($user_id);
  4596. $data['re_user_ids'] = $user_id;
  4597. $data['updated_at'] = date('Y-m-d H:i:s');
  4598. $this->sendMessage([
  4599. 'talk_type' => 700,
  4600. 'title' => $data['title'],
  4601. 'content' => '提交了审核',
  4602. 'messageType' => 5,
  4603. ]);
  4604. $result = Notice::where('id', $data['id'])->update($data);
  4605. return Result::success($result);
  4606. }
  4607. public function getNoticeList(array $data): array
  4608. {
  4609. $where = [];
  4610. //title
  4611. if (isset($data['title']) && !empty($data['title'])) {
  4612. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4613. }
  4614. //level
  4615. if (isset($data['level']) && !empty($data['level'])) {
  4616. $where[] = ['notice.level', '=', $data['level']];
  4617. }
  4618. //status
  4619. if (isset($data['status']) && !empty($data['status'])) {
  4620. $where[] = ['notice.status', '=', $data['status']];
  4621. }
  4622. //type
  4623. if (isset($data['type']) && !empty($data['type'])) {
  4624. $where[] = ['notice.type', '=', $data['type']];
  4625. }
  4626. var_dump($data, '------------11111-2----test---------');
  4627. if ($data['type_id'] == 10000) {
  4628. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4629. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4630. })
  4631. ->where($where)
  4632. ->orderBy('updated_at', 'desc')
  4633. ->limit($data['page_size'])
  4634. ->offset(($data['page'] - 1) * $data['page_size'])
  4635. ->get();
  4636. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4637. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4638. })
  4639. ->where($where)
  4640. ->orderBy('updated_at', 'desc')
  4641. ->count();
  4642. } else {
  4643. $result = Notice::where($where)
  4644. // ->where('user_id', $data['user_id'])
  4645. ->Where(function ($query) use ($data) {
  4646. $query->Where(function ($q) use ($data) {
  4647. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4648. ->orWhere('notice.user_id', $data['user_id']);
  4649. });
  4650. })
  4651. ->when(!empty($data['status1']), function ($query) use ($data) {
  4652. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4653. })
  4654. ->orderBy('updated_at', 'desc')
  4655. ->limit($data['page_size'])
  4656. ->offset(($data['page'] - 1) * $data['page_size'])
  4657. ->get();
  4658. $total = Notice::where($where)
  4659. ->when(!empty($data['status1']), function ($query) use ($data) {
  4660. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4661. })
  4662. // ->where('user_id', $data['user_id'])
  4663. ->Where(function ($query) use ($data) {
  4664. $query->Where(function ($q) use ($data) {
  4665. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4666. ->orWhere('notice.user_id', $data['user_id']);
  4667. });
  4668. })
  4669. ->count();
  4670. }
  4671. if (empty($result)) {
  4672. return Result::error("查询失败", 0);
  4673. }
  4674. $data = [
  4675. 'rows' => $result,
  4676. 'count' => $total,
  4677. ];
  4678. return Result::success($data);
  4679. }
  4680. public function noticeList(array $data): array
  4681. {
  4682. $where = [];
  4683. //title
  4684. if (isset($data['title']) && !empty($data['title'])) {
  4685. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4686. }
  4687. //level
  4688. if (isset($data['level']) && !empty($data['level'])) {
  4689. $where[] = ['notice.level', '=', $data['level']];
  4690. }
  4691. //status
  4692. if (isset($data['status']) && !empty($data['status'])) {
  4693. $where[] = ['notice.status', '=', $data['status']];
  4694. }
  4695. //type
  4696. if (isset($data['type']) && !empty($data['type'])) {
  4697. $where[] = ['notice.type', '=', $data['type']];
  4698. }
  4699. var_dump($data, '------------11111-2----test---------');
  4700. if ($data['type_id'] == 10000) {
  4701. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4702. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4703. })
  4704. ->where($where)
  4705. ->orderBy('updated_at', 'desc')
  4706. ->limit($data['page_size'])
  4707. ->offset(($data['page'] - 1) * $data['page_size'])
  4708. ->get();
  4709. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4710. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4711. })
  4712. ->where($where)
  4713. ->orderBy('updated_at', 'desc')
  4714. ->count();
  4715. } else {
  4716. $result = Notice::where($where)
  4717. // ->where('user_id', $data['user_id'])
  4718. ->Where(function ($query) use ($data) {
  4719. $query->Where(function ($q) use ($data) {
  4720. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4721. ->orWhere('notice.user_id', $data['user_id']);
  4722. });
  4723. })
  4724. ->when(!empty($data['status1']), function ($query) use ($data) {
  4725. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4726. })
  4727. ->orderBy('updated_at', 'desc')
  4728. ->limit($data['page_size'])
  4729. ->offset(($data['page'] - 1) * $data['page_size'])
  4730. ->get();
  4731. $total = Notice::where($where)
  4732. ->when(!empty($data['status1']), function ($query) use ($data) {
  4733. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4734. })
  4735. // ->where('user_id', $data['user_id'])
  4736. ->Where(function ($query) use ($data) {
  4737. $query->Where(function ($q) use ($data) {
  4738. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4739. ->orWhere('notice.user_id', $data['user_id']);
  4740. });
  4741. })
  4742. ->count();
  4743. }
  4744. if (empty($result)) {
  4745. return Result::error("查询失败", 0);
  4746. }
  4747. $data = [
  4748. 'rows' => $result,
  4749. 'count' => $total,
  4750. ];
  4751. return Result::success($data);
  4752. }
  4753. public function getNoticeDetail(array $data): array
  4754. {
  4755. $result = Notice::where('id', $data['id'])->first();
  4756. if (empty($result)) {
  4757. return Result::error("查询失败", 0);
  4758. }
  4759. return Result::success($result);
  4760. }
  4761. public function deleteNotice(array $data): array
  4762. {
  4763. $notice = Notice::where('id', $data['id'])->first();
  4764. if (empty($notice)) {
  4765. return Result::error("删除失败", 0);
  4766. }
  4767. $chat_group_id = $notice->group_id;
  4768. if ($chat_group_id) {
  4769. //删除群聊
  4770. ChatGroups::where('id', $chat_group_id)->delete();
  4771. //删除群成员
  4772. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4773. //删除群聊记录
  4774. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4775. }
  4776. $result = Notice::where('id', $data['id'])->delete();
  4777. return Result::success($result);
  4778. }
  4779. public function complaintList(array $data): array
  4780. {
  4781. var_dump($data, '---------1---------');
  4782. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4783. unset($data['type_id']);
  4784. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4785. $where = [];
  4786. if ($type_id != 10000 && empty($data['deal_user'])) {
  4787. // $where['complaint.user_id'] = $user_id;
  4788. }
  4789. if (!empty($data['title'])) {
  4790. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4791. }
  4792. if (!empty($data['department_id'])) {
  4793. $where['complaint.department_id'] = $data['department_id'];
  4794. }
  4795. if (!empty($data['deal'])) {
  4796. $where['complaint.deal'] = $data['deal'];
  4797. }
  4798. if (!empty($data['status'])) {
  4799. $where['complaint.status'] = $data['status'];
  4800. }
  4801. var_dump(!empty($data['deal_user']), '----------1');
  4802. var_dump($where, '----------2');
  4803. $result = Complaint::where($where)
  4804. ->when(!empty($data['status1']), function ($query) use ($data) {
  4805. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4806. })
  4807. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4808. //json re_user_ids data[user_id]是不是在里面
  4809. $query->Where(function ($q) use ($data) {
  4810. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4811. ->where('complaint.status', 2);
  4812. });
  4813. })
  4814. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4815. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4816. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4817. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4818. ->orderBy('updated_at', 'desc')
  4819. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4820. //sql输出
  4821. if (empty($result)) {
  4822. return Result::error("暂无投诉信息", 0);
  4823. }
  4824. // 取出数据
  4825. $rows = $result->items();
  4826. $count = $result->total();
  4827. $responseData = [
  4828. 'rows' => $rows,
  4829. 'count' => $count,
  4830. ];
  4831. return Result::success($responseData);
  4832. }
  4833. public function getComplaintList(array $data): array
  4834. {
  4835. var_dump($data, '00000001000000000000');
  4836. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4837. unset($data['type_id']);
  4838. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4839. $where = [];
  4840. if ($type_id != 10000 && empty($data['deal_user'])) {
  4841. $where['complaint.user_id'] = $user_id;
  4842. }
  4843. if (!empty($data['title'])) {
  4844. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4845. }
  4846. if (!empty($data['department_id'])) {
  4847. $where['complaint.department_id'] = $data['department_id'];
  4848. }
  4849. if (!empty($data['deal'])) {
  4850. $where['complaint.deal'] = $data['deal'];
  4851. }
  4852. if (!empty($data['status'])) {
  4853. $where['complaint.status'] = $data['status'];
  4854. }
  4855. var_dump(!empty($data['deal_user']), '----------1');
  4856. var_dump($where, '----------2');
  4857. $result = Complaint::where($where)
  4858. ->when(!empty($data['status1']), function ($query) use ($data) {
  4859. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4860. })
  4861. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4862. // //json re_user_ids data[user_id]是不是在里面
  4863. // $query->Where(function ($q) use ($data) {
  4864. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4865. // ->where('complaint.status', 2);
  4866. // });
  4867. // })
  4868. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4869. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4870. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4871. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4872. ->orderBy('updated_at', 'desc')
  4873. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4874. //sql输出
  4875. if (empty($result)) {
  4876. return Result::error("暂无投诉信息", 0);
  4877. }
  4878. // 取出数据
  4879. $rows = $result->items();
  4880. $count = $result->total();
  4881. $responseData = [
  4882. 'rows' => $rows,
  4883. 'count' => $count,
  4884. ];
  4885. return Result::success($responseData);
  4886. }
  4887. public function getComplaintInfo(array $data): array
  4888. {
  4889. $result = Complaint::where('id', $data['id'])->first();
  4890. if (empty($result)) {
  4891. return Result::error("查询失败", 0);
  4892. }
  4893. return Result::success($result);
  4894. }
  4895. public function readComplaint(array $data): array
  4896. {
  4897. $result = Complaint::where('id', $data['id'])->first();
  4898. if (empty($result)) {
  4899. return Result::error("查询失败", 0);
  4900. }
  4901. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4902. $re_user_ids = json_decode($result['re_user_ids'], true);
  4903. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4904. //如果已经存在,就不再添加
  4905. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4906. $read_id = json_decode($result['read_id'], true);
  4907. if (!is_array($read_id)) {
  4908. $read_id = [];
  4909. }
  4910. if (!in_array($data['user_id'], $read_id)) {
  4911. $read_id[] = $data['user_id'];
  4912. $result['read_id'] = json_encode($read_id);
  4913. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4914. }
  4915. } else {
  4916. //如果不存在,就添加
  4917. $result['read_id'] = json_encode([$data['user_id']]);
  4918. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4919. }
  4920. }
  4921. return Result::success($result);
  4922. }
  4923. public function addComplaint(array $data): array
  4924. {
  4925. date_default_timezone_set('Asia/Shanghai');
  4926. $data['created_at'] = date('Y-m-d H:i:s');
  4927. $data['updated_at'] = date('Y-m-d H:i:s');
  4928. $this->sendMessage([
  4929. 'talk_type' => 800,
  4930. 'title' => $data['title'],
  4931. 'content' => '提交了审核',
  4932. 'messageType' => 6,
  4933. ]);
  4934. $result = Complaint::create($data);
  4935. return Result::success($result);
  4936. }
  4937. public function updateComplaint(array $data): array
  4938. {
  4939. date_default_timezone_set('Asia/Shanghai');
  4940. $data['updated_at'] = date('Y-m-d H:i:s');
  4941. $user_id = $data['user_id'] ?? 0;
  4942. $type_id = $data['type_id'] ?? 0;
  4943. unset($data['user_id']);
  4944. unset($data['type_id']);
  4945. $this->sendMessage([
  4946. 'talk_type' => 800,
  4947. 'title' => $data['title'],
  4948. 'content' => '提交了审核',
  4949. 'messageType' => 6,
  4950. ]);
  4951. $result = Complaint::where('id', $data['id'])->update($data);
  4952. return Result::success($result);
  4953. }
  4954. public function deleteComplaint(array $data): array
  4955. {
  4956. $result = Complaint::where('id', $data['id'])->delete();
  4957. return Result::success($result);
  4958. }
  4959. public function getComplainInfo(array $data): array
  4960. {
  4961. $result = Complaint::where('id', $data['id'])->first();
  4962. if (empty($result)) {
  4963. return Result::error("查询失败", 0);
  4964. }
  4965. return Result::success($result);
  4966. }
  4967. public function updateComplaintStatus(array $data): array
  4968. {
  4969. date_default_timezone_set('Asia/Shanghai');
  4970. $data['updated_at'] = date('Y-m-d H:i:s');
  4971. $user_id = $data['user_id'] ?? 0;
  4972. $type_id = $data['type_id'] ?? 0;
  4973. unset($data['user_id']);
  4974. unset($data['type_id']);
  4975. //处理, 写入处理人
  4976. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4977. $data['real_deal_user'] = $user_id;
  4978. }
  4979. //如果是deal 23,则判断是不是处理人
  4980. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4981. $complaintInof = Complaint::where('id', $data['id'])
  4982. ->where('real_deal_user', $user_id)
  4983. ->first();
  4984. if (empty($complaintInof)) {
  4985. return Result::error("处理人错误", 0);
  4986. }
  4987. }
  4988. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4989. if ($data['status'] == 1) {
  4990. $this->sendMessage([
  4991. 'talk_type' => 800,
  4992. 'title' => $complaintInfo['title'],
  4993. 'content' => '提交了审核',
  4994. 'messageType' => 6,
  4995. ]);
  4996. }
  4997. if ($data['status'] == 2 && !isset($data['deal'])) {
  4998. $this->sendMessage([
  4999. 'talk_type' => 801,
  5000. 'title' => $complaintInfo['title'],
  5001. 'content' => '审核通过',
  5002. 'messageType' => 6,
  5003. 'user_id' => $complaintInfo['user_id'],
  5004. ]);
  5005. $this->sendMessage([
  5006. 'talk_type' => 802,
  5007. 'title' => $complaintInfo['title'],
  5008. 'content' => '待处理',
  5009. 'messageType' => 6,
  5010. 'user_id' => $complaintInfo['re_user_ids'],
  5011. ]);
  5012. }
  5013. if ($data['status'] == 3 && !isset($data['deal'])) {
  5014. $this->sendMessage([
  5015. 'talk_type' => 801,
  5016. 'title' => $complaintInfo['title'],
  5017. 'content' => '审核拒绝',
  5018. 'messageType' => 6,
  5019. 'user_id' => $complaintInfo['user_id'],
  5020. ]);
  5021. }
  5022. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5023. $this->sendMessage([
  5024. 'talk_type' => 802,
  5025. 'title' => $complaintInfo['title'],
  5026. 'content' => '处理中',
  5027. 'messageType' => 6,
  5028. 'user_id' => $complaintInfo['re_user_ids'],
  5029. ]);
  5030. }
  5031. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5032. $this->sendMessage([
  5033. 'talk_type' => 802,
  5034. 'title' => $complaintInfo['title'],
  5035. 'content' => '不予处理',
  5036. 'messageType' => 6,
  5037. 'user_id' => $complaintInfo['re_user_ids'],
  5038. ]);
  5039. }
  5040. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5041. $this->sendMessage([
  5042. 'talk_type' => 802,
  5043. 'title' => $complaintInfo['title'],
  5044. 'content' => '已完结',
  5045. 'messageType' => 6,
  5046. 'user_id' => $complaintInfo['re_user_ids'],
  5047. ]);
  5048. }
  5049. $result = complaint::where('id', $data['id'])->update($data);
  5050. return Result::success($result);
  5051. }
  5052. public function updateGoodStatus(array $data): array
  5053. {
  5054. $user_id = $data['user_id'] ?? 0;
  5055. $type_id = $data['type_id'] ?? 0;
  5056. unset($data['user_id']);
  5057. unset($data['type_id']);
  5058. $goodInfo = Good::where('id', $data['id'])->first();
  5059. if ($data['status'] == 2) {
  5060. $this->sendMessage([
  5061. 'talk_type' => 201,
  5062. 'title' => $goodInfo['name'],
  5063. 'content' => '审核通过',
  5064. 'messageType' => 3,
  5065. 'user_id' => $goodInfo['user_id'],
  5066. ]);
  5067. }
  5068. if ($data['status'] == 3) {
  5069. $this->sendMessage([
  5070. 'talk_type' => 201,
  5071. 'title' => $goodInfo['name'],
  5072. 'content' => '审核拒绝',
  5073. 'messageType' => 3,
  5074. 'user_id' => $goodInfo['user_id'],
  5075. ]);
  5076. }
  5077. if ($data['status'] == 1) {
  5078. $this->sendMessage([
  5079. 'talk_type' => 200,
  5080. 'title' => $goodInfo['name'],
  5081. 'content' => '提交了审核',
  5082. 'messageType' => 3,
  5083. ]);
  5084. }
  5085. $result = Good::where('id', $data['id'])->update($data);
  5086. return Result::success($result);
  5087. }
  5088. public function updateJobHuntingStatus(array $data): array
  5089. {
  5090. $user_id = $data['user_id'] ?? 0;
  5091. $type_id = $data['type_id'] ?? 0;
  5092. unset($data['user_id']);
  5093. unset($data['type_id']);
  5094. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5095. if ($data['status'] == 2) {
  5096. $this->sendMessage([
  5097. 'talk_type' => 601,
  5098. 'title' => $jogHuntingInfo['name'],
  5099. 'content' => '审核通过',
  5100. 'messageType' => 11,
  5101. 'user_id' => $jogHuntingInfo['user_id'],
  5102. ]);
  5103. }
  5104. if ($data['status'] == 3) {
  5105. $this->sendMessage([
  5106. 'talk_type' => 601,
  5107. 'title' => $jogHuntingInfo['name'],
  5108. 'content' => '审核拒绝',
  5109. 'messageType' => 11,
  5110. 'user_id' => $jogHuntingInfo['user_id'],
  5111. ]);
  5112. }
  5113. if ($data['status'] == 1) {
  5114. $this->sendMessage([
  5115. 'talk_type' => 600,
  5116. 'title' => $jogHuntingInfo['name'],
  5117. 'content' => '提交了审核',
  5118. 'messageType' => 11,
  5119. ]);
  5120. }
  5121. $result = JobHunting::where('id', $data['id'])->update($data);
  5122. return Result::success($result);
  5123. }
  5124. public function updateNoticeStatus(array $data): array
  5125. {
  5126. $user_id = $data['user_id'] ?? 0;
  5127. $type_id = $data['type_id'] ?? 0;
  5128. unset($data['user_id']);
  5129. unset($data['type_id']);
  5130. //查询公告
  5131. $notice = Notice::where('id', $data['id'])->first();
  5132. if (empty($notice)) {
  5133. return Result::error("公告不存在", 0);
  5134. }
  5135. //$chat_ids 去除掉$data['user_id']
  5136. $chat_ids = json_decode($notice['re_user_ids'], true);
  5137. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5138. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5139. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5140. //chat_group
  5141. $group_id = PublicData::uuid();
  5142. $groupData = [
  5143. 'id' => $group_id,
  5144. 'creator_id' => $notice['user_id'],
  5145. 'group_name' => $notice['group_name'] ?? '',
  5146. 'profile' => $notice['profile'] ?? 0,
  5147. ];
  5148. var_dump($groupData, '-----------------groupData-------');
  5149. $groupResult = ChatGroups::insertGetId($groupData);
  5150. var_dump($groupResult, '-----------------groupid-------');
  5151. $groupMemberData = [
  5152. 'id' => PublicData::uuid(),
  5153. 'user_id' => $notice['user_id'],
  5154. 'group_id' => $group_id,
  5155. 'leader' => 2,
  5156. ];
  5157. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5158. //插入群成员表
  5159. $groupMemberDataUser = [];
  5160. $chatData = [];
  5161. foreach ($chat_ids as $key => $value) {
  5162. $groupMemberDataUser[] = [
  5163. 'id' => PublicData::uuid(),
  5164. 'user_id' => $value,
  5165. 'group_id' => $group_id,
  5166. 'leader' => 1,
  5167. ];
  5168. $chatData[] = [
  5169. 'user_id' => $value,
  5170. 'msg_type' => 1,
  5171. 'receiver_id' => $group_id,
  5172. 'content' => '通过通知创建群聊',
  5173. 'group_receiver_id' => $notice['user_id'],
  5174. 'action' => 'recieved',
  5175. 'created_at' => date('Y-m-d H:i:s'),
  5176. ];
  5177. }
  5178. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5179. ChatGroupsMember::insert($groupMemberDataUser);
  5180. //插入一条管理员聊天记录
  5181. $chatData[] = [
  5182. 'user_id' => $notice['user_id'],
  5183. 'msg_type' => 1,
  5184. 'receiver_id' => $group_id,
  5185. 'content' => '通过通知创建群聊',
  5186. 'group_receiver_id' => $notice['user_id'],
  5187. 'action' => 'said',
  5188. 'created_at' => date('Y-m-d H:i:s'),
  5189. ];
  5190. var_dump($chatData, '-----------------chatData-------');
  5191. $chatResult = ChatRecords::insert($chatData);
  5192. //处理imp
  5193. $group = [
  5194. 'type' => 1,
  5195. 'name' => $notice['group_name'] ?? '',
  5196. 'profile' => '',
  5197. 'avatar' => '',
  5198. 'creator_id' => $notice['user_id'],
  5199. ];
  5200. $groupResult = GroupImp::insertGetId($group);
  5201. var_dump($groupResult, '获取imp group_id');
  5202. $groupMember = [
  5203. 'user_id' => $notice['user_id'],
  5204. 'group_id' => $groupResult,
  5205. 'leader' => 1,
  5206. 'join_time' => Date('Y-m-d H:i:s')
  5207. ];
  5208. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5209. $talk_session = [
  5210. 'user_id' => $notice['user_id'],
  5211. 'to_from_id' => $groupResult,
  5212. 'talk_mode' => 2,
  5213. 'created_at' => Date('Y-m-d H:i:s'),
  5214. 'updated_at' => Date('Y-m-d H:i:s'),
  5215. ];
  5216. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5217. //被通知人员处理
  5218. foreach ($chat_ids as $key => $value) {
  5219. $groupMemberdata[] = [
  5220. 'user_id' => $value,
  5221. 'group_id' => $groupResult,
  5222. 'leader' => 3,
  5223. 'join_time' => Date('Y-m-d H:i:s')
  5224. ];
  5225. $talk_sessionData[] = [
  5226. 'user_id' => $value,
  5227. 'to_from_id' => $groupResult,
  5228. 'talk_mode' => 2,
  5229. 'created_at' => Date('Y-m-d H:i:s'),
  5230. 'updated_at' => Date('Y-m-d H:i:s'),
  5231. ];
  5232. }
  5233. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5234. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5235. $group_id = $groupResult;
  5236. //更新result的 group_id
  5237. $data['group_id'] = $group_id;
  5238. Notice::where(['id' => $data['id']])->update($data);
  5239. }
  5240. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5241. //删除掉信息
  5242. GroupImp::where('id', $notice['group_id'])->delete();
  5243. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5244. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5245. foreach ($chat_ids as $key => $value) {
  5246. }
  5247. //聊天记录删除
  5248. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5249. $data['group_id'] = null;
  5250. Notice::where(['id' => $data['id']])->update($data);
  5251. }
  5252. $result = Notice::where('id', $data['id'])->update($data);
  5253. $noticeInfo = Notice::where('id', $data['id'])->first();
  5254. if ($data['status'] == 2) {
  5255. $this->sendMessage([
  5256. 'talk_type' => 701,
  5257. 'title' => $noticeInfo['title'],
  5258. 'content' => '审核通过',
  5259. 'messageType' => 3,
  5260. 'user_id' => $noticeInfo['user_id'],
  5261. ]);
  5262. }
  5263. if ($data['status'] == 3) {
  5264. $this->sendMessage([
  5265. 'talk_type' => 701,
  5266. 'title' => $noticeInfo['title'],
  5267. 'content' => '审核拒绝',
  5268. 'messageType' => 3,
  5269. 'user_id' => $noticeInfo['user_id'],
  5270. ]);
  5271. }
  5272. if ($data['status'] == 1) {
  5273. $this->sendMessage([
  5274. 'talk_type' => 700,
  5275. 'title' => $noticeInfo['title'],
  5276. 'content' => '提交了审核',
  5277. 'messageType' => 3,
  5278. ]);
  5279. }
  5280. return Result::success($result);
  5281. }
  5282. public function getDUser(array $data): array
  5283. {
  5284. if (!empty($data['ids'])) {
  5285. $user = User::whereIn('id', $data['ids'])->getall();
  5286. if (empty($user)) {
  5287. return Result::error('无数据', 0);
  5288. }
  5289. return Result::success($user);
  5290. }
  5291. $where = [];
  5292. if (!empty($data['department_id'])) {
  5293. $where['department_id'] = $data['department_id'];
  5294. }
  5295. if (!empty($data['city_id'])) {
  5296. $where['city_id'] = $data['city_id'];
  5297. }
  5298. $result = User::where('type_id', 2)
  5299. ->where('status', 1)
  5300. ->where($where)
  5301. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5302. ->get();
  5303. if (empty($result)) {
  5304. return Result::error("查询失败", 0);
  5305. }
  5306. return Result::success($result);
  5307. }
  5308. /**
  5309. * 验证导航名称是否重复
  5310. * @return void
  5311. */
  5312. public function checkCategoryName(array $data): array
  5313. {
  5314. $result = Category::when($data, function ($query) use ($data) {
  5315. if (isset($data['name']) && $data['name']) {
  5316. $query->where("name", $data['name']);
  5317. }
  5318. if (isset($data['id']) && $data['id']) {
  5319. $query->where("id", "!=", $data['id']);
  5320. }
  5321. })->first();
  5322. if ($result) {
  5323. return Result::error("已存在");
  5324. } else {
  5325. return Result::success();
  5326. }
  5327. }
  5328. //20250226 产品列表
  5329. // 20250306 -------招聘--------fr
  5330. /*
  5331. * 招聘列表
  5332. * */
  5333. public function getJobRecruitingList(array $data): array
  5334. {
  5335. $where = [];
  5336. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5337. if ($data['checkout'] == 0) {
  5338. $job_status = [0, 2];
  5339. } else {
  5340. $job_status = [1];
  5341. }
  5342. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5343. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5344. }
  5345. $user = User::where('id', $data['user_id'])->first();
  5346. if (empty($user)) {
  5347. return Result::error("用户不存在", 0);
  5348. }
  5349. // 3:企业会员
  5350. if ($user['type_id'] == 3) {
  5351. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5352. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5353. }
  5354. // 如果 $where 为空,则不添加 where 条件
  5355. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5356. return $query->where($where);
  5357. })
  5358. ->whereIn('job_recruiting.status', $job_status)
  5359. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5360. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5361. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5362. ->orderBy("updated_at", "desc")
  5363. ->offset(($data['page'] - 1) * $data['page_size'])
  5364. ->limit($data['page_size'])
  5365. ->get()
  5366. ->all();
  5367. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5368. return $query->where($where);
  5369. })
  5370. ->whereIn('job_recruiting.status', $job_status)
  5371. ->count();
  5372. if (empty($result)) {
  5373. return Result::error("暂无招聘信息", 0);
  5374. }
  5375. return Result::success($result);
  5376. }
  5377. /*
  5378. * 招聘信息添加
  5379. * */
  5380. public function addJobRecruiting(array $data): array
  5381. {
  5382. // var_dump('添加招聘进入news------data',$data);
  5383. // return Result::success($data);
  5384. $user = User::where('user.id', $data['user_id'])
  5385. ->where('user.status', 1)
  5386. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5387. ->select(
  5388. 'user.type_id',
  5389. 'user.mobile',
  5390. 'user.email',
  5391. 'user_info.business_name',
  5392. 'user_info.company_hy_id',
  5393. 'user_info.company_nature',
  5394. 'user_info.company_size',
  5395. 'user_info.introduction',
  5396. 'user_info.real_name',
  5397. 'user_info.company_url',
  5398. 'user_info.address_arr_id',
  5399. 'user_info.address'
  5400. )
  5401. ->first();
  5402. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5403. return Result::error("用户不存在", 0);
  5404. }
  5405. $web = Website::where('id', $data['website_id'])->first();
  5406. if (empty($web)) {
  5407. return Result::error("网站不存在", 0);
  5408. }
  5409. // var_dump('添加招聘进入news---user---user',$user);
  5410. // 处理招聘关键词
  5411. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5412. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5413. } else {
  5414. Jieba::init(); // 初始化 jieba-php
  5415. Finalseg::init();
  5416. $segList = Jieba::cut($data['title']);
  5417. $segList1 = array_slice($segList, 0, 8);
  5418. $data['keyword'] = implode(',', $segList1);
  5419. }
  5420. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5421. $content = $data['description'];
  5422. // 去除 <style> 和 <script> 标签及其内容
  5423. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5424. // 去除所有 HTML 标签
  5425. $content = strip_tags($content);
  5426. // 去除 HTML 实体
  5427. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5428. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5429. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5430. // 去除多余空白
  5431. $content = preg_replace('/\s+/u', '', $content);
  5432. // 截取 100 个字符
  5433. $data['seo_description'] = mb_substr($content, 0, 100);
  5434. }
  5435. // return Result::success($user);
  5436. $data['action_id'] = $data['user_id'] ?? null;
  5437. $data['user_type'] = $user['type_id'] ?? null;
  5438. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5439. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5440. $data['catid'] = end($data['cat_arr_id']);
  5441. } else {
  5442. $data['catid'] = 0;
  5443. }
  5444. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5445. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5446. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5447. // 公司地址 管理员必填
  5448. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5449. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5450. // 管理员-企业相关信息
  5451. $company = [
  5452. // 'user_id' => $data['user_id']?? null,
  5453. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5454. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5455. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5456. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5457. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5458. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5459. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5460. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5461. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5462. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5463. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5464. ];
  5465. //去掉相关企业信息
  5466. $job = array_diff_key($data, array_flip(array_keys($company)));
  5467. // var_dump('添加招聘进入news---job---user',$job);
  5468. Db::beginTransaction();
  5469. try {
  5470. // // 先添加职位相关信息
  5471. if ($user['type_id'] == 10000) {
  5472. $job['status'] = 1;
  5473. }
  5474. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5475. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5476. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5477. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5478. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5479. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5480. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5481. // return Result::success($job);
  5482. $jobId = JobRecruiting::insertGetId($job);
  5483. if (empty($jobId)) {
  5484. Db::rollBack();
  5485. return Result::error("添加失败");
  5486. }
  5487. // 添加公司信息
  5488. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5489. $company['job_id'] = $jobId;
  5490. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5491. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5492. if ($user['type_id'] == 10000) {
  5493. // 管理员添加企业信息
  5494. $companyId = JobCompany::insertGetId($company);
  5495. if (empty($companyId)) {
  5496. Db::rollBack();
  5497. return Result::error("添加失败");
  5498. }
  5499. } else {
  5500. // 企业会员添加企业信息
  5501. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5502. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5503. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5504. $company['job_id'] = $jobId;
  5505. $companyId = JobCompany::insertGetId($company);
  5506. if (empty($companyId)) {
  5507. Db::rollBack();
  5508. return Result::error("添加失败");
  5509. }
  5510. }
  5511. Db::commit();
  5512. $result = [
  5513. 'job_id' => $jobId,
  5514. 'company_id' => $companyId,
  5515. ];
  5516. return Result::success($result);
  5517. } catch (\Exception $e) {
  5518. Db::rollBack();
  5519. return Result::error($e->getMessage(), 0);
  5520. }
  5521. // return Result::success($result);
  5522. }
  5523. /*
  5524. * 获取招聘信息详情
  5525. * */
  5526. public function getJobRecruitingInfo(array $data): array
  5527. {
  5528. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5529. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5530. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5531. ->select(
  5532. 'job_recruiting.*',
  5533. 'website.website_name as website_name',
  5534. 'job_company.business_name',
  5535. 'job_company.company_hy_id',
  5536. 'job_company.company_size',
  5537. 'job_company.company_nature',
  5538. 'job_company.introduction',
  5539. 'job_company.real_name',
  5540. 'job_company.mobile',
  5541. 'job_company.company_url',
  5542. 'job_company.address_arr_id',
  5543. 'job_company.address',
  5544. 'job_company.email'
  5545. )
  5546. ->first();
  5547. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5548. if (!empty($cityId)) {
  5549. if (isset($cityId[1]) && $cityId[1] != null) {
  5550. $city = District::where('id', $cityId[1])->first(['name']);
  5551. } else {
  5552. $city = District::where('id', $cityId[0])->first(['name']);
  5553. }
  5554. $result['city'] = $city['name'] ?? '';
  5555. }
  5556. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5557. if (is_array($addressId) && !empty($addressId)) {
  5558. $address = District::whereIn('id', $addressId)
  5559. ->orderBy('level', 'asc')
  5560. ->get(['name'])
  5561. ->pluck('name')
  5562. ->implode('');
  5563. // $job->address_name = $address ?? '';
  5564. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5565. }
  5566. if (empty($result)) {
  5567. return Result::error("招聘信息不存在", 0);
  5568. }
  5569. // return Result::success($job);
  5570. return Result::success($result);
  5571. }
  5572. /*
  5573. * 修改招聘信息
  5574. * */
  5575. public function upJobRecruiting(array $data): array
  5576. {
  5577. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5578. // return Result::success($job);
  5579. if (empty($job)) {
  5580. return Result::error("招聘信息不存在", 0);
  5581. }
  5582. $user = User::where('id', $data['user_id'])->first();
  5583. // return Result::success($user);
  5584. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5585. return Result::error("用户不存在", 0);
  5586. }
  5587. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5588. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5589. }
  5590. // 处理招聘关键词
  5591. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5592. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5593. } else {
  5594. Jieba::init(); // 初始化 jieba-php
  5595. Finalseg::init();
  5596. $segList = Jieba::cut($data['title']);
  5597. $segList1 = array_slice($segList, 0, 8);
  5598. $data['keyword'] = implode(',', $segList1);
  5599. }
  5600. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5601. $content = $data['description'];
  5602. // 去除 <style> 和 <script> 标签及其内容
  5603. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5604. // 去除所有 HTML 标签
  5605. $content = strip_tags($content);
  5606. // 去除 HTML 实体
  5607. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5608. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5609. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5610. // 去除多余空白
  5611. $content = preg_replace('/\s+/u', '', $content);
  5612. // 截取 100 个字符
  5613. $data['seo_description'] = mb_substr($content, 0, 100);
  5614. }
  5615. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5616. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5617. $data['catid'] = end($data['cat_arr_id']);
  5618. } else {
  5619. }
  5620. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5621. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5622. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5623. // 公司地址 管理员必填
  5624. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5625. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5626. // 管理员-企业相关信息
  5627. $company = [
  5628. // 'user_id' => $data['user_id']?? null,
  5629. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5630. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5631. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5632. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5633. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5634. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5635. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5636. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5637. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5638. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5639. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5640. ];
  5641. //去掉相关企业信息
  5642. $data = array_diff_key($data, array_flip(array_keys($company)));
  5643. $jobId = $data['id'];
  5644. $web = $data['website_id'];
  5645. $data['action_id'] = $data['user_id'];
  5646. unset($data['user_id']);
  5647. unset($data['user_type']);
  5648. unset($data['id']);
  5649. unset($data['website_id']);
  5650. // return Result::success($data);
  5651. Db::beginTransaction();
  5652. try {
  5653. // 管理员修改招聘信息
  5654. if ($user['type_id'] == 10000) {
  5655. $data['website_id'] = $web;
  5656. $company['website_id'] = $data['website_id'];
  5657. $data['status'] = 1;
  5658. } else {
  5659. $data['status'] = 0;
  5660. }
  5661. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5662. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5663. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5664. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5665. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5666. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5667. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5668. // return Result::success($job);
  5669. // Db::rollBack();
  5670. // return Result::success($company);
  5671. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5672. $this->sendMessage([
  5673. 'talk_type' => 500,
  5674. 'title' => $data['title'],
  5675. 'content' => '提交了审核',
  5676. 'messageType' => 10,
  5677. ]);
  5678. }
  5679. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5680. if (empty($result['job'])) {
  5681. Db::rollBack();
  5682. return Result::error("修改招聘信息失败");
  5683. }
  5684. // 管理员修改企业相关信息
  5685. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5686. if (empty($result['company'])) {
  5687. Db::rollBack();
  5688. return Result::error("修改企业相关信息失败");
  5689. }
  5690. Db::commit();
  5691. // return Result::success($result);
  5692. } catch (\Exception $e) {
  5693. Db::rollBack();
  5694. return Result::error($e->getMessage(), 0);
  5695. }
  5696. return Result::success($result);
  5697. }
  5698. /*
  5699. * 招聘信息删除
  5700. * */
  5701. public function delJobRecruiting(array $data): array
  5702. {
  5703. $user = User::where('id', $data['user_id'])->first();
  5704. if (empty($user)) {
  5705. return Result::error("用户不存在", 0);
  5706. }
  5707. $job = JobRecruiting::where('id', $data['id'])->first();
  5708. if (empty($job)) {
  5709. return Result::error("招聘信息不存在", 0);
  5710. }
  5711. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5712. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5713. }
  5714. Db::beginTransaction();
  5715. try {
  5716. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5717. if (empty($result['job'])) {
  5718. Db::rollBack();
  5719. return Result::error("删除招聘信息失败");
  5720. }
  5721. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5722. if (empty($result['company'])) {
  5723. Db::rollBack();
  5724. return Result::error("删除企业相关信息失败");
  5725. }
  5726. Db::commit();
  5727. } catch (\Exception $e) {
  5728. Db::rollBack();
  5729. return Result::error($e->getMessage(), 0);
  5730. }
  5731. return Result::success($result);
  5732. }
  5733. /*
  5734. * 获取公司信息
  5735. * */
  5736. public function getJobCompany(array $data): array
  5737. {
  5738. $user = User::where('user.id', $data['user_id'])
  5739. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5740. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5741. ->first();
  5742. // return Result::success($user);
  5743. if (empty($user)) {
  5744. return Result::error("用户不存在", 0);
  5745. }
  5746. if ($user['type_id'] == 3) {
  5747. $result = [
  5748. // 'id' => 0,
  5749. 'user_id' => $data['user_id'],
  5750. 'website_id' => $data['website_id'],
  5751. 'business_name' => $user['business_name'], // 企业名称
  5752. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5753. 'company_nature' => $user['company_nature'], // 公司性质
  5754. 'company_size' => $user['company_size'], // 公司规模
  5755. 'introduction' => $user['introduction'], // 公司简介
  5756. 'real_name' => $user['real_name'], // 企业联系人
  5757. 'mobile' => $user['mobile'], // 企业联系电话
  5758. 'company_url' => $user['company_url'], // 企业网址
  5759. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5760. 'address' => $user['address'], // 企业地址
  5761. 'email' => $user['email'], // 企业邮箱
  5762. ];
  5763. } else {
  5764. return Result::error("用户类型错误", 0);
  5765. }
  5766. if (empty($result)) {
  5767. return Result::error("公司信息不存在", 0);
  5768. }
  5769. return Result::success($result);
  5770. }
  5771. /*
  5772. * 修改公司信息
  5773. * */
  5774. public function upJobCompany(array $data): array
  5775. {
  5776. // return Result::success($data);
  5777. $user = User::where('user.id', $data['user_id'])
  5778. ->where('user.status', 1)
  5779. ->select('user.user_name', 'user.type_id')
  5780. ->first();
  5781. if (empty($user)) {
  5782. return Result::error("用户不存在", 0);
  5783. }
  5784. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5785. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5786. $company = [
  5787. 'business_name' => $data['business_name'], // 企业名称
  5788. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5789. 'company_nature' => $data['company_nature'], // 公司性质
  5790. 'company_size' => $data['company_size'], // 公司规模
  5791. 'introduction' => $data['introduction'], // 公司简介
  5792. // 'real_name' => $data['real_name'], // 企业联系人
  5793. 'company_url' => $data['company_url'], // 企业网址
  5794. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5795. 'address' => $data['address'], // 企业详细地址
  5796. // 'email' => $data['email'], // 企业邮箱
  5797. ];
  5798. if ($user['type_id'] == 3) {
  5799. Db::beginTransaction();
  5800. try {
  5801. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5802. 'business_name' => $data['business_name'], // 企业名称
  5803. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5804. 'company_nature' => $data['company_nature'], // 公司性质
  5805. 'company_size' => $data['company_size'], // 公司规模
  5806. 'introduction' => $data['introduction'], // 公司简介
  5807. // 'real_name' => $data['real_name'], // 企业联系人
  5808. 'company_url' => $data['company_url'], // 企业网址
  5809. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5810. 'address' => $data['address'], // 企业详细地址
  5811. ]);
  5812. if (empty($result['userinfo'])) {
  5813. Db::rollBack();
  5814. return Result::error('修改企业会员信息失败!');
  5815. }
  5816. $result['user'] = User::where('id', $data['user_id'])->update([
  5817. 'email' => $data['email'], // 企业邮箱
  5818. ]);
  5819. if (empty($result['user'])) {
  5820. Db::rollBack();
  5821. return Result::error('修改个人中心信息失败!');
  5822. }
  5823. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5824. if (!empty($job_company)) {
  5825. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5826. if (empty($result['job_company'])) {
  5827. Db::rollBack();
  5828. return Result::error('修改企业会员信息失败!');
  5829. }
  5830. }
  5831. Db::commit();
  5832. return Result::success($result);
  5833. } catch (\Exception $e) {
  5834. Db::rollBack();
  5835. return Result::error($e->getMessage(), 0);
  5836. }
  5837. } else {
  5838. return Result::error("用户类型错误", 0);
  5839. }
  5840. }
  5841. /*
  5842. * 获取省-市
  5843. * */
  5844. public function getJobRecruitingArea(array $data): array
  5845. {
  5846. if (isset($data['pid']) && $data['pid'] != null) {
  5847. $result = District::where('pid', $data['pid'])->get()->all();
  5848. } else {
  5849. $result = District::where('level', 1)->get()->all();
  5850. }
  5851. if (empty($result)) {
  5852. return Result::error("暂无此省市", 0);
  5853. }
  5854. return Result::success($result);
  5855. }
  5856. /*
  5857. * 获取行业分类
  5858. * */
  5859. public function getIndustry(array $data): array
  5860. {
  5861. $result = JobIndustry::get()->all();
  5862. if (empty($result)) {
  5863. return Result::error("暂无行业分类", 0);
  5864. }
  5865. return Result::success($result);
  5866. }
  5867. /*
  5868. * 获取职位
  5869. * */
  5870. public function getPositionList(array $data): array
  5871. {
  5872. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5873. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5874. } else {
  5875. $result = JobPosition::where('zwpid', 0)->get()->all();
  5876. }
  5877. if (empty($result)) {
  5878. return Result::error("暂无此职位", 0);
  5879. }
  5880. return Result::success($result);
  5881. }
  5882. /*
  5883. * 获取工作性质-菜单
  5884. * */
  5885. public function getJobNature(array $data): array
  5886. {
  5887. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5888. if (empty($result)) {
  5889. return Result::error("暂无工作性质", 0);
  5890. }
  5891. return Result::success($result);
  5892. }
  5893. /*
  5894. * 获取工作经验-菜单
  5895. * */
  5896. public function getExperience(array $data): array
  5897. {
  5898. $result = JobEnum::where('egroup', 'years')->get()->all();
  5899. if (empty($result)) {
  5900. return Result::error("暂无工作经验", 0);
  5901. }
  5902. return Result::success($result);
  5903. }
  5904. /*
  5905. * 获取学历-菜单
  5906. * */
  5907. public function getEducation(array $data): array
  5908. {
  5909. $result = JobEnum::where('egroup', 'education')->get()->all();
  5910. if (empty($result)) {
  5911. return Result::error("暂无学历", 0);
  5912. }
  5913. return Result::success($result);
  5914. }
  5915. /*
  5916. * 获取薪资-菜单
  5917. * */
  5918. public function getSalary(array $data): array
  5919. {
  5920. $result = JobEnum::where('egroup', 'income')->get()->all();
  5921. if (empty($result)) {
  5922. return Result::error("暂无薪资", 0);
  5923. }
  5924. return Result::success($result);
  5925. }
  5926. /*
  5927. * 获取语言-菜单
  5928. * */
  5929. public function getLanguage(array $data): array
  5930. {
  5931. $result = JobEnum::where('egroup', 'language')->get()->all();
  5932. if (empty($result)) {
  5933. return Result::error("暂无语言", 0);
  5934. }
  5935. return Result::success($result);
  5936. }
  5937. /*
  5938. * 获取掌握程度-菜单
  5939. * */
  5940. public function getLevel(array $data): array
  5941. {
  5942. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5943. if (empty($result)) {
  5944. return Result::error("暂无工作性质", 0);
  5945. }
  5946. return Result::success($result);
  5947. }
  5948. // 公司信息
  5949. /*
  5950. * 获取公司性质-菜单
  5951. * */
  5952. public function getCompanyNature(array $data): array
  5953. {
  5954. $result = JobNature::get()->all();
  5955. if (empty($result)) {
  5956. return Result::error("暂无公司性质", 0);
  5957. }
  5958. return Result::success($result);
  5959. }
  5960. /*
  5961. * 获取公司规模-菜单
  5962. * */
  5963. public function getCompanySize(array $data): array
  5964. {
  5965. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5966. if (empty($result)) {
  5967. return Result::error("暂无公司规模", 0);
  5968. }
  5969. return Result::success($result);
  5970. }
  5971. /*
  5972. * 招聘信息审核
  5973. * */
  5974. public function checkJobRecruiting(array $data): array
  5975. {
  5976. $user = User::where('id', $data['user_id'])->first();
  5977. if (empty($user)) {
  5978. return Result::error("用户不存在", 0);
  5979. }
  5980. $job = JobRecruiting::where('id', $data['id'])->first();
  5981. if (empty($job)) {
  5982. return Result::error("招聘信息不存在", 0);
  5983. }
  5984. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5985. if ($user['type_id'] != 10000) {
  5986. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5987. }
  5988. // 驳回原因
  5989. if ($data['status'] == 2) {
  5990. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5991. }
  5992. $data['action_id'] = $data['user_id'];
  5993. unset($data['user_id']);
  5994. if ($data['status'] == 1) {
  5995. $this->sendMessage([
  5996. 'talk_type' => 501,
  5997. 'title' => $job['title'],
  5998. 'content' => '审核通过',
  5999. 'messageType' => 10,
  6000. 'user_id' => $job['user_id'],
  6001. ]);
  6002. }
  6003. if ($data['status'] == 2) {
  6004. $this->sendMessage([
  6005. 'talk_type' => 501,
  6006. 'title' => $job['title'],
  6007. 'content' => '审核拒绝',
  6008. 'messageType' => 10,
  6009. 'user_id' => $job['user_id'],
  6010. ]);
  6011. }
  6012. if ($data['status'] == 0) {
  6013. $this->sendMessage([
  6014. 'talk_type' => 500,
  6015. 'title' => $job['title'],
  6016. 'content' => '提交了审核',
  6017. 'messageType' => 10,
  6018. ]);
  6019. }
  6020. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6021. if (empty($result)) {
  6022. return Result::error("审核失败", 0);
  6023. }
  6024. return Result::success($result);
  6025. }
  6026. public function myApplyList(array $data): array
  6027. {
  6028. var_dump($data, '------参数');
  6029. $user = User::where('id', $data['user_id'])->first();
  6030. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6031. return Result::error("用户不存在", 0);
  6032. }
  6033. // 1:个人会员 职场机会
  6034. if ($user['type_id'] == 1) {
  6035. $where['user_id'] = $user['id'];
  6036. }
  6037. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6038. $query->where('user_id', $user['id']);
  6039. })
  6040. ->pluck('recruit_id');
  6041. $where = [];
  6042. if (isset($data['salary']) && $data['salary'] != null) {
  6043. $where['job_recruiting.salary'] = $data['salary'];
  6044. }
  6045. if (isset($data['experience']) && $data['experience'] != null) {
  6046. $where['job_recruiting.experience'] = $data['experience'];
  6047. }
  6048. if (isset($data['business_name']) && $data['business_name'] != null) {
  6049. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6050. }
  6051. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6052. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6053. ->where($where);
  6054. // ->count();
  6055. $count = $query->count();
  6056. $query = clone $query;
  6057. $job = $query
  6058. ->leftJoin('job_enum as income_enum', function ($join) {
  6059. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6060. ->where('income_enum.egroup', 'income');
  6061. })
  6062. ->leftJoin('job_enum as years_enum', function ($join) {
  6063. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6064. ->where('years_enum.egroup', 'years');
  6065. })
  6066. // ->where($where)
  6067. ->orderBy('job_recruiting.updated_at', 'desc')
  6068. ->select(
  6069. 'job_recruiting.id',
  6070. 'job_recruiting.title',
  6071. 'job_company.business_name',
  6072. 'income_enum.evalue as salary_evalue',
  6073. 'income_enum.ename as salary_ename',
  6074. 'years_enum.evalue as experience_evalue',
  6075. 'years_enum.ename as experience_ename',
  6076. 'job_recruiting.updated_at'
  6077. )
  6078. ->offset(($data['page'] - 1) * $data['pageSize'])
  6079. ->limit($data['pageSize'])
  6080. ->get()
  6081. ->all();
  6082. if (empty($job)) {
  6083. return Result::error("暂无招聘信息", 0);
  6084. }
  6085. $result = [
  6086. 'row' => $job,
  6087. 'count' => $count,
  6088. ];
  6089. return Result::success($result);
  6090. }
  6091. public function readJobApply(array $data): array
  6092. {
  6093. $result = JobApply::where('id', $data['id'])->first();
  6094. if (empty($result)) {
  6095. return Result::error("查询失败", 0);
  6096. }
  6097. $result = JobApply::where('id', $data['id'])->update([
  6098. 'status' => 2,
  6099. ]);
  6100. return Result::success($result);
  6101. }
  6102. /*
  6103. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6104. * */
  6105. public function getRecruitingList(array $data): array
  6106. {
  6107. $user = User::where('id', $data['user_id'])->first();
  6108. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6109. return Result::error("用户不存在", 0);
  6110. }
  6111. // 1:个人会员 职场机会
  6112. if ($user['type_id'] == 1) {
  6113. $where['user_id'] = $user['id'];
  6114. }
  6115. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6116. $query->where('receiver_id', $user['id']);
  6117. })
  6118. ->pluck('recruit_id');
  6119. // return Result::success($recruitingId);
  6120. $where = [];
  6121. if (isset($data['salary']) && $data['salary'] != null) {
  6122. $where['job_recruiting.salary'] = $data['salary'];
  6123. }
  6124. if (isset($data['experience']) && $data['experience'] != null) {
  6125. $where['job_recruiting.experience'] = $data['experience'];
  6126. }
  6127. if (isset($data['business_name']) && $data['business_name'] != null) {
  6128. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6129. }
  6130. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6131. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6132. ->where($where);
  6133. // ->count();
  6134. $count = $query->count();
  6135. $query = clone $query;
  6136. $job = $query
  6137. ->leftJoin('job_enum as income_enum', function ($join) {
  6138. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6139. ->where('income_enum.egroup', 'income');
  6140. })
  6141. ->leftJoin('job_enum as years_enum', function ($join) {
  6142. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6143. ->where('years_enum.egroup', 'years');
  6144. })
  6145. // ->where($where)
  6146. ->orderBy('job_recruiting.updated_at', 'desc')
  6147. ->select(
  6148. 'job_recruiting.id',
  6149. 'job_recruiting.title',
  6150. 'job_company.business_name',
  6151. 'income_enum.evalue as salary_evalue',
  6152. 'income_enum.ename as salary_ename',
  6153. 'years_enum.evalue as experience_evalue',
  6154. 'years_enum.ename as experience_ename',
  6155. 'job_recruiting.updated_at'
  6156. )
  6157. ->offset(($data['page'] - 1) * $data['pageSize'])
  6158. ->limit($data['pageSize'])
  6159. ->get()
  6160. ->all();
  6161. if (empty($job)) {
  6162. return Result::error("暂无招聘信息", 0);
  6163. }
  6164. $result = [
  6165. 'row' => $job,
  6166. 'count' => $count,
  6167. ];
  6168. return Result::success($result);
  6169. }
  6170. /*
  6171. * 获取企业会员-招聘信息列表
  6172. * */
  6173. public function getRecruitingInfo(array $data): array
  6174. {
  6175. $user = User::where('id', $data['user_id'])->first();
  6176. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6177. return Result::error("用户不存在", 0);
  6178. }
  6179. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6180. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6181. ->select(
  6182. 'job_recruiting.*',
  6183. 'job_company.business_name',
  6184. 'job_company.company_hy_id',
  6185. 'job_company.company_size',
  6186. 'job_company.company_nature',
  6187. 'job_company.introduction',
  6188. 'job_company.real_name',
  6189. 'job_company.mobile',
  6190. 'job_company.company_url',
  6191. 'job_company.address_arr_id',
  6192. 'job_company.address',
  6193. 'job_company.email'
  6194. )
  6195. ->get();
  6196. if (empty($recruiting)) {
  6197. return Result::error("暂无招聘信息", 0);
  6198. }
  6199. return Result::success($recruiting);
  6200. }
  6201. /*
  6202. * 获取企业会员-我的沟通
  6203. * */
  6204. public function getJobResumeList(array $data): array
  6205. {
  6206. $user = User::where('id', $data['user_id'])->first();
  6207. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6208. return Result::error("用户不存在", 0);
  6209. }
  6210. $where = [];
  6211. if (isset($data['salary']) && $data['salary'] != null) {
  6212. $where['job_hunting.salary'] = $data['salary'];
  6213. }
  6214. if (isset($data['user_name']) && $data['user_name'] != null) {
  6215. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6216. }
  6217. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6218. $query->where('job_resume.user_id', $user['id']);
  6219. })
  6220. ->when(!empty($where), function ($query) use ($where) {
  6221. $query->where($where);
  6222. })
  6223. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6224. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6225. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6226. ->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');
  6227. $count = $job->count();
  6228. if ($count == 0) {
  6229. return Result::error("暂无沟通记录", 0);
  6230. }
  6231. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6232. ->offset(($data['page'] - 1) * $data['pageSize'])
  6233. ->limit($data['pageSize'])
  6234. ->get();
  6235. if (empty($jobs)) {
  6236. return Result::error("暂无沟通记录", 0);
  6237. }
  6238. $result['row'] = $this->processJob($jobs, '');
  6239. $result['count'] = $count;
  6240. return Result::success($result);
  6241. }
  6242. public function readJobResume(array $data): array
  6243. {
  6244. $result = JobResume::where('id', $data['id'])->first();
  6245. if (empty($result)) {
  6246. return Result::error("查询失败", 0);
  6247. }
  6248. $result = JobResume::where('id', $data['id'])->update([
  6249. 'status' => 2,
  6250. ]);
  6251. return Result::success($result);
  6252. }
  6253. // 20250306 招聘
  6254. //20250422 书刊音像
  6255. public function addBook(array $data): array
  6256. {
  6257. $user_id = $data['user_id'] ?? 0;
  6258. $type_id = $data['type_id'] ?? 0;
  6259. // $website_id = $data['website_id'] ?? 0;
  6260. // unset($data['user_id']);
  6261. unset($data['type_id']);
  6262. // unset($data['website_id']);
  6263. //处理数组
  6264. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6265. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6266. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6267. if ($data['img_url'] == '') {
  6268. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6269. preg_match_all($reg, $data['detail'], $matches);
  6270. if (isset($matches[1][0])) {
  6271. //截取varchar240
  6272. $data['img_url'] = substr($matches[1][0], 0, 240);
  6273. }
  6274. }
  6275. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6276. //提取标题+内容中的关键词
  6277. $data['keyword'] = $data['title'];
  6278. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6279. Jieba::init(); // 初始化 jieba-php
  6280. Finalseg::init();
  6281. $segList = Jieba::cut($data['keyword']);
  6282. $segList1 = array_slice($segList, 0, 8);
  6283. $data['keyword'] = implode(',', $segList1);
  6284. }
  6285. if ($data['description'] == '') {
  6286. //提取内容中的描述
  6287. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6288. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6289. }
  6290. var_dump($data, '--');
  6291. if ($data['status'] == 1) {
  6292. $this->sendMessage([
  6293. 'talk_type' => 400,
  6294. 'title' => $data['title'],
  6295. 'content' => '提交了审核',
  6296. 'messageType' => 7,
  6297. ]);
  6298. }
  6299. $result = Book::insertGetId($data);
  6300. if (empty($result)) {
  6301. return Result::error("添加失败", 0);
  6302. }
  6303. return Result::success($result);
  6304. }
  6305. public function getBookList(array $data): array
  6306. {
  6307. $where = [];
  6308. if (!empty($data["title"])) {
  6309. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6310. }
  6311. if (!empty($data['website_name'])) {
  6312. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6313. }
  6314. if (!empty($data['status'])) {
  6315. $where[] = ['book.status', '=', $data['status']];
  6316. }
  6317. $user_id = $data['user_id'];
  6318. $type_id = $data['type_id'];
  6319. // $type_id = 4;
  6320. var_dump($type_id, '------1--------');
  6321. if ($type_id != 10000) {
  6322. $where[] = ['book.user_id', '=', $user_id];
  6323. }
  6324. var_dump(!empty($data['status1']), '=-===1');
  6325. $result = Book::where($where)
  6326. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6327. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6328. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6329. ->when(isset($data['status1']), function ($query) use ($data) {
  6330. $query->whereIn('book.status', [1, 3]);
  6331. })
  6332. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6333. ->orderBy("updated_at", "desc")
  6334. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6335. if (empty($result)) {
  6336. return Result::error("暂无数据", 0);
  6337. }
  6338. // 取出数据
  6339. $rows = $result->items();
  6340. $count = $result->total();
  6341. $responseData = [
  6342. 'rows' => $rows,
  6343. 'count' => $count,
  6344. ];
  6345. return Result::success($responseData);
  6346. }
  6347. public function deleteBook(array $data): array
  6348. {
  6349. $result = Book::where('id', $data['id'])->delete();
  6350. if (empty($result)) {
  6351. return Result::error("删除失败", 0);
  6352. }
  6353. return Result::success($result);
  6354. }
  6355. public function updateBook(array $data): array
  6356. {
  6357. // $user_id = $data['user_id'] ?? 0;
  6358. $type_id = $data['type_id'] ?? 0;
  6359. // $website_id = $data['website_id'] ?? 0;
  6360. unset($data['user_id']);
  6361. unset($data['type_id']);
  6362. // unset($data['website_id']);
  6363. //处理数组
  6364. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6365. if ($data['img_url'] == '') {
  6366. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6367. preg_match_all($reg, $data['detail'], $matches);
  6368. if (isset($matches[1][0])) {
  6369. //截取varchar240
  6370. $data['img_url'] = substr($matches[1][0], 0, 240);
  6371. }
  6372. }
  6373. if ($data['keyword'] == '') {
  6374. //提取标题+内容中的关键词
  6375. $data['keyword'] = $data['title'];
  6376. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6377. Jieba::init(); // 初始化 jieba-php
  6378. Finalseg::init();
  6379. $segList = Jieba::cut($data['keyword']);
  6380. $segList1 = array_slice($segList, 0, 8);
  6381. $data['keyword'] = implode(',', $segList1);
  6382. }
  6383. if ($data['description'] == '') {
  6384. //提取内容中的描述
  6385. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6386. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6387. }
  6388. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6389. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6390. if ($data['status'] == 1) {
  6391. $this->sendMessage([
  6392. 'talk_type' => 400,
  6393. 'title' => $data['title'],
  6394. 'content' => '提交了审核',
  6395. 'messageType' => 7,
  6396. ]);
  6397. }
  6398. $result = Book::where("id", $data["id"])->update($data);
  6399. if (empty($result)) {
  6400. return Result::error("更新失败", 0);
  6401. }
  6402. return Result::success($result);
  6403. }
  6404. public function getBookInfo(array $data): array
  6405. {
  6406. $result = Book::where("id", $data["id"])->first();
  6407. if (empty($result)) {
  6408. return Result::error("获取失败", 0);
  6409. }
  6410. return Result::success($result);
  6411. }
  6412. public function updateBookStatus(array $data): array
  6413. {
  6414. //审核
  6415. unset($data['user_id']);
  6416. $bookInfo = Book::where("id", $data["id"])->first();
  6417. var_dump($bookInfo, '----');
  6418. if ($data['status'] == 2) {
  6419. $this->sendMessage([
  6420. 'talk_type' => 401,
  6421. 'title' => $bookInfo['title'],
  6422. 'content' => '审核通过',
  6423. 'messageType' => 7,
  6424. 'user_id' => $bookInfo['user_id'],
  6425. ]);
  6426. }
  6427. if ($data['status'] == 3) {
  6428. $this->sendMessage([
  6429. 'talk_type' => 401,
  6430. 'title' => $bookInfo['title'],
  6431. 'content' => '审核拒绝',
  6432. 'messageType' => 7,
  6433. 'user_id' => $bookInfo['user_id'],
  6434. ]);
  6435. }
  6436. if ($data['status'] == 1) {
  6437. $this->sendMessage([
  6438. 'talk_type' => 400,
  6439. 'title' => $bookInfo['title'],
  6440. 'content' => '提交了审核',
  6441. 'messageType' => 7,
  6442. // 'user_id'=>$bookInfo['user_id'],
  6443. ]);
  6444. }
  6445. $result = Book::where("id", $data["id"])->update($data);
  6446. if (empty($result)) {
  6447. return Result::error("更新失败", 0);
  6448. }
  6449. return Result::success($result);
  6450. }
  6451. //20250422 书刊音像
  6452. /**
  6453. * 贴身宝贝
  6454. * @param array $data
  6455. * @return array
  6456. */
  6457. public function getWebsiteTsbb(array $data): array
  6458. {
  6459. $month = $data['month'] ?? date('m');
  6460. $day = $data['day'] ?? date('d');
  6461. // 使用缓存键
  6462. $cacheKey = "tsbb_data_{$month}_{$day}";
  6463. // 尝试从缓存获取数据
  6464. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6465. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6466. if ($cachedData = $cache->get($cacheKey)) {
  6467. return Result::success(unserialize($cachedData));
  6468. }
  6469. //查询老黄历
  6470. try {
  6471. $date = date('Y-m-d');
  6472. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6473. // 使用 curl 替代 file_get_contents
  6474. $ch = curl_init();
  6475. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6476. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6477. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6478. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6479. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6480. 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');
  6481. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6482. 'Accept: application/json',
  6483. 'Content-Type: application/json',
  6484. 'Referer: https://www.36jxs.com/'
  6485. ]);
  6486. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6487. curl_setopt($ch, CURLOPT_ENCODING, '');
  6488. $almanacResponse = curl_exec($ch);
  6489. var_dump("====:", $almanacResponse);
  6490. if (curl_errno($ch)) {
  6491. var_dump('Curl error:', curl_error($ch));
  6492. throw new \Exception('Curl error: ' . curl_error($ch));
  6493. }
  6494. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6495. curl_close($ch);
  6496. if ($almanacResponse === false) {
  6497. throw new \Exception('Failed to fetch almanac data');
  6498. }
  6499. $almanacData = json_decode($almanacResponse, true);
  6500. if (json_last_error() !== JSON_ERROR_NONE) {
  6501. throw new \Exception('Failed to parse almanac data');
  6502. }
  6503. $almanacInfo = $almanacData['data'] ?? [];
  6504. } catch (\Exception $e) {
  6505. var_dump('Exception:', $e->getMessage());
  6506. $almanacInfo = [];
  6507. }
  6508. // 获取历史上的今天数据
  6509. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6510. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6511. ->orderBy('year', 'asc')
  6512. ->select("title", "id", "year", DB::raw('1 as type'))
  6513. ->limit(16)
  6514. ->get();
  6515. // 获取节日数据 - 从今天开始获取未来4条
  6516. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6517. ->orderBy('showtime', 'asc')
  6518. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6519. ->limit(16)
  6520. ->get();
  6521. //说文解字
  6522. $chartacterList = Character::orderBy('updated_at', 'desc')
  6523. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6524. ->limit(6)
  6525. ->get();
  6526. //谜语沙龙
  6527. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6528. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6529. ->limit(4)
  6530. ->get();
  6531. //成语欣赏
  6532. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6533. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6534. ->limit(32)
  6535. ->get();
  6536. //名联赏析
  6537. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6538. ->select("id", "first", "second", DB::raw('6 as type'))
  6539. ->limit(6)
  6540. ->get();
  6541. // 获取分类文章数据
  6542. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6543. ->pluck('category_id')
  6544. ->toArray();
  6545. $articlesList = [];
  6546. foreach ($categoryIds as $catid) {
  6547. // 先查有图片的
  6548. $withImg = DB::table('article')
  6549. ->where('status', 1)
  6550. ->where('catid', $catid)
  6551. ->whereNotNull('imgurl')
  6552. ->where('imgurl', '!=', '')
  6553. ->orderBy('updated_at', 'desc')
  6554. ->limit(6)
  6555. ->get();
  6556. $count = $withImg->count();
  6557. if ($count < 6) {
  6558. // 不足6条再查无图片的补足
  6559. $withoutImg = DB::table('article')
  6560. ->where('status', 1)
  6561. ->where('catid', $catid)
  6562. ->where(function ($q) {
  6563. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6564. })
  6565. ->orderBy('updated_at', 'desc')
  6566. ->limit(6 - $count)
  6567. ->get();
  6568. $articles = $withImg->concat($withoutImg);
  6569. } else {
  6570. $articles = $withImg;
  6571. }
  6572. // 组装
  6573. $category = \App\Model\Category::find($catid);
  6574. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6575. $articlesList[] = [
  6576. 'category_name' => $category ? $category->name : '',
  6577. 'catid' => $catid,
  6578. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6579. 'type' => 100,
  6580. 'list' => $articles->map(function ($item) {
  6581. return [
  6582. 'id' => $item->id,
  6583. 'title' => $item->title,
  6584. 'imgurl' => $item->imgurl,
  6585. 'created_at' => $item->created_at
  6586. ];
  6587. })->values()
  6588. ];
  6589. }
  6590. $result = [
  6591. 'almanac' => $almanacInfo,
  6592. 'historyTodayList' => [
  6593. 'category_name' => '历史上的今天',
  6594. 'list' => $historyTodayList,
  6595. 'type' => 1
  6596. ],
  6597. 'festivalList' => [
  6598. 'category_name' => '节日预告',
  6599. 'list' => $festivalList,
  6600. 'type' => 2
  6601. ],
  6602. 'chartacterList' => [
  6603. 'category_name' => '说文解字',
  6604. 'list' => $chartacterList,
  6605. 'type' => 3
  6606. ],
  6607. 'coupletList' => [
  6608. 'category_name' => '名联赏析',
  6609. 'list' => $coupletList,
  6610. 'type' => 6
  6611. ],
  6612. 'riddletList' => [
  6613. 'category_name' => '谜语沙龙',
  6614. 'list' => $riddletList,
  6615. 'type' => 4
  6616. ],
  6617. 'idiomList' => [
  6618. 'category_name' => '成语欣赏',
  6619. 'list' => $idiomList,
  6620. 'type' => 5
  6621. ],
  6622. 'articlesList' => $articlesList
  6623. ];
  6624. // 缓存结果,设置1小时过期
  6625. $cache->set($cacheKey, serialize($result), 3600);
  6626. return Result::success($result);
  6627. }
  6628. /**
  6629. * 获取资讯列表
  6630. */
  6631. public function getWebsiteTsbbList(array $data): array
  6632. {
  6633. $page = $data['page'] ?? 1;
  6634. $pageSize = $data['pageSize'] ?? 10;
  6635. // 如果没有传入月份和日期,则使用今天的日期
  6636. $month = $data['month'] ?? date('m');
  6637. $day = $data['day'] ?? date('d');
  6638. $total = 0;
  6639. $result = [];
  6640. $data['type'] = intval($data['type']);
  6641. var_dump("接收参数:", $data);
  6642. switch ($data['type']) {
  6643. case 1:
  6644. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6645. // 当前月份之后的数据
  6646. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6647. // 或者当前月份且日期大于等于当前日期的数据
  6648. ->orWhere(function ($q) use ($month, $day) {
  6649. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6650. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6651. });
  6652. })
  6653. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6654. $total = $query->count();
  6655. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6656. ->offset(($page - 1) * $pageSize)
  6657. ->limit($pageSize)
  6658. ->get();
  6659. break;
  6660. case 2:
  6661. $query = Festival::where(function ($q) use ($month, $day) {
  6662. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6663. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6664. ->orWhere(function ($q) use ($month, $day) {
  6665. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6666. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6667. });
  6668. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6669. $total = $query->count();
  6670. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6671. ->offset(($page - 1) * $pageSize)
  6672. ->limit($pageSize)
  6673. ->get();
  6674. break;
  6675. case 3:
  6676. $query = Character::orderBy("updated_at", "desc");
  6677. $total = $query->count();
  6678. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6679. ->offset(($page - 1) * $pageSize)
  6680. ->limit($pageSize)
  6681. ->get();
  6682. break;
  6683. case 4:
  6684. $query = Riddle::orderBy("updated_at", "desc");
  6685. $total = $query->count();
  6686. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6687. ->offset(($page - 1) * $pageSize)
  6688. ->limit($pageSize)
  6689. ->get();
  6690. break;
  6691. case 5:
  6692. $query = Idiom::orderBy("updated_at", "desc");
  6693. $total = $query->count();
  6694. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6695. ->offset(($page - 1) * $pageSize)
  6696. ->limit($pageSize)
  6697. ->get();
  6698. break;
  6699. case 6:
  6700. $query = Couplet::orderBy("updated_at", "desc");
  6701. $total = $query->count();
  6702. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6703. ->offset(($page - 1) * $pageSize)
  6704. ->limit($pageSize)
  6705. ->get();
  6706. break;
  6707. default:
  6708. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6709. $total = $query->count();
  6710. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6711. ->offset(($page - 1) * $pageSize)
  6712. ->limit($pageSize)
  6713. ->get();
  6714. }
  6715. return Result::success([
  6716. 'list' => $result,
  6717. 'total' => $total,
  6718. 'page' => (int)$page,
  6719. 'pageSize' => (int)$pageSize,
  6720. 'month' => $month,
  6721. 'day' => $day
  6722. ]);
  6723. }
  6724. /**
  6725. * 1:历史上的今天
  6726. * 2:节日
  6727. * 3:文章
  6728. *
  6729. * 资讯详情信息
  6730. */
  6731. public function getWebsiteTsbbDetail(array $data): array
  6732. {
  6733. $data['type'] = intval($data['type']);
  6734. switch ($data['type']) {
  6735. case 1:
  6736. $result = HistoryToday::where("id", $data['id'])->first();
  6737. break;
  6738. case 2:
  6739. $result = Festival::where("id", $data['id'])->first();
  6740. break;
  6741. case 3:
  6742. $result = Character::where("id", $data['id'])->first();
  6743. break;
  6744. case 4:
  6745. $result = Riddle::where("id", $data['id'])->first();
  6746. break;
  6747. case 5:
  6748. $result = Idiom::where("id", $data['id'])->first();
  6749. break;
  6750. case 6:
  6751. $result = Couplet::where("id", $data['id'])->first();
  6752. break;
  6753. default:
  6754. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6755. break;
  6756. }
  6757. return Result::success($result);
  6758. }
  6759. /**
  6760. * 农网导航首页数据
  6761. */
  6762. public function getWebsiteNwHomeList(array $data): array
  6763. {
  6764. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6765. ->pluck('category_id')
  6766. ->toArray();
  6767. // 使用子查询优化
  6768. $articlesList = DB::table('article')
  6769. ->select([
  6770. 'article.id',
  6771. 'article.title',
  6772. 'article.imgurl',
  6773. 'article.created_at',
  6774. 'category.name as category_name',
  6775. 'category.id as category_id',
  6776. 'website_category.aLIas_pinyin as pinyin',
  6777. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6778. DB::raw('100 as type')
  6779. ])
  6780. ->join('category', 'article.catid', '=', 'category.id')
  6781. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6782. ->leftJoin('website_category as parent_wc', function ($join) {
  6783. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6784. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6785. })
  6786. ->where('website_category.website_id', $data['website_id'])
  6787. ->where('article.status', 1)
  6788. ->whereIn('category.id', $categoryIds)
  6789. ->orderBy('article.created_at', 'desc')
  6790. ->get()
  6791. ->groupBy('category_id')
  6792. ->map(function ($group) {
  6793. // 确保第一条数据有图片
  6794. $firstWithImage = $group->first(function ($item) {
  6795. return !empty($item->imgurl);
  6796. });
  6797. if ($firstWithImage) {
  6798. // 如果有带图片的文章,将其放在第一位
  6799. $group = $group->filter(function ($item) use ($firstWithImage) {
  6800. return $item->id !== $firstWithImage->id;
  6801. })->prepend($firstWithImage);
  6802. }
  6803. return [
  6804. 'category_name' => $group->first()->category_name,
  6805. 'catid' => $group->first()->category_id,
  6806. 'pinyin' => $group->first()->pinyin,
  6807. 'parent_pinyin' => $group->first()->parent_pinyin,
  6808. 'list' => $group->take(4)->map(function ($item) {
  6809. return [
  6810. 'id' => $item->id,
  6811. 'title' => $item->title,
  6812. ];
  6813. })->values()
  6814. ];
  6815. })
  6816. ->values()
  6817. ->toArray();
  6818. return Result::success($articlesList);
  6819. }
  6820. /**
  6821. * 企业管理
  6822. * @param array $data
  6823. * @return array
  6824. */
  6825. public function getCompanyList(array $data): array
  6826. {
  6827. // return Result::success($data);
  6828. $where = [];
  6829. $user = User::where('id', $data['user_id'])->first();
  6830. if (empty($user)) {
  6831. return Result::error('用户不存在!');
  6832. }
  6833. if ($user['type_id'] != 10000) {
  6834. $where['user_id'] = $data['user_id'];
  6835. }
  6836. if (isset($data['title']) && !empty($data['title'])) {
  6837. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6838. }
  6839. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6840. array_push($where, ['website.id', $data['website_id']]);
  6841. }
  6842. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6843. if ($data['ischeck'] == 1) {
  6844. if (isset($data['status']) && $data['status'] != '') {
  6845. array_push($where, ['company.status', $data['status']]);
  6846. $query = Company::where($where);
  6847. } else {
  6848. $query = Company::whereIn('company.status', [0, 2]);
  6849. }
  6850. } else {
  6851. $query = Company::where('company.status', 1);
  6852. }
  6853. }
  6854. $result = $query->where($where)
  6855. ->leftJoin('website_category', function ($query) {
  6856. $query->on('website_category.category_id', '=', 'company.category_id')
  6857. ->on('website_category.website_id', '=', 'company.website_id');
  6858. })
  6859. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6860. ->select(
  6861. 'company.id',
  6862. 'company.title',
  6863. 'company.website_id',
  6864. 'company.category_id',
  6865. 'website.website_name',
  6866. 'website_category.alias as category_name',
  6867. 'company.status',
  6868. 'company.updated_at',
  6869. 'company.user_id'
  6870. )
  6871. ->orderBy('company.updated_at', 'desc')
  6872. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6873. if ($result->isEmpty()) {
  6874. return Result::error("暂无企业", 0);
  6875. }
  6876. return Result::success($result);
  6877. }
  6878. /**
  6879. * 添加企业
  6880. * @param array $data
  6881. * @return array
  6882. */
  6883. public function addCompany(array $data): array
  6884. {
  6885. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6886. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6887. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6888. $data['cat_arr_id'] = json_encode($car_arr_id);
  6889. } else {
  6890. $data['cat_arr_id'] = '';
  6891. }
  6892. if ($data['imgurl'] == '') {
  6893. //content中提取图片第一个图,正则提取
  6894. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6895. preg_match_all($reg, $data['content'], $matches);
  6896. if (isset($matches[1][0])) {
  6897. //截取varchar240
  6898. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6899. }
  6900. }
  6901. if ($data['keyword'] == '') {
  6902. //提取标题+内容中的关键词
  6903. $data['keyword'] = $data['title'];
  6904. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6905. Jieba::init(); // 初始化 jieba-php
  6906. Finalseg::init();
  6907. $segList = Jieba::cut($data['keyword']);
  6908. $segList1 = array_slice($segList, 0, 8);
  6909. $data['keyword'] = implode(',', $segList1);
  6910. }
  6911. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6912. //提取内容中的描述
  6913. $content = $data['content'];
  6914. // 去除 <style> 和 <script> 标签及其内容
  6915. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6916. // 去除所有 HTML 标签
  6917. $content = strip_tags($content);
  6918. // 去除 HTML 实体
  6919. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6920. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6921. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6922. // 去除多余空白
  6923. $content = preg_replace('/\s+/u', '', $content);
  6924. // 截取 100 个字符
  6925. $data['introduce'] = mb_substr($content, 0, 100);
  6926. }
  6927. $user = User::where('id', $data['user_id'])->first();
  6928. if (empty($user)) {
  6929. return Result::error('用户不存在!');
  6930. }
  6931. if ($user['type_id'] == 10000) {
  6932. $data['status'] = 1;
  6933. }
  6934. if (isset($data['level']) && $data['level'] != null) {
  6935. $data['level'] = intval($data['level']);
  6936. } else {
  6937. $data['level'] = null;
  6938. }
  6939. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6940. $this->sendMessage([
  6941. 'talk_type' => 900,
  6942. 'title' => $data['title'],
  6943. 'content' => '提交了审核',
  6944. 'messageType' => 8,
  6945. ]);
  6946. }
  6947. $result = Company::insertGetId($data);
  6948. if ($result) {
  6949. return Result::success($result);
  6950. } else {
  6951. return Result::error('添加失败');
  6952. }
  6953. }
  6954. /**
  6955. * 更新企业
  6956. * @param array $data
  6957. * @return array
  6958. */
  6959. public function upCompany(array $data): array
  6960. {
  6961. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6962. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6963. $data['cat_arr_id'] = json_encode($car_arr_id);
  6964. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6965. } else {
  6966. $data['cat_arr_id'] = '';
  6967. }
  6968. if ($data['imgurl'] == '') {
  6969. //content中提取图片第一个图,正则提取
  6970. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6971. preg_match_all($reg, $data['content'], $matches);
  6972. if (isset($matches[1][0])) {
  6973. //截取varchar
  6974. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6975. }
  6976. }
  6977. if ($data['keyword'] == '') {
  6978. //提取标题+内容中的关键词
  6979. $data['keyword'] = $data['title'];
  6980. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6981. Jieba::init(); // 初始化 jieba-php
  6982. Finalseg::init();
  6983. $segList = Jieba::cut($data['keyword']);
  6984. $segList1 = array_slice($segList, 0, 8);
  6985. $data['keyword'] = implode(',', $segList1);
  6986. }
  6987. if ($data['introduce'] == '') {
  6988. //提取内容中的描述
  6989. $content = $data['content'];
  6990. // 去除 <style> 和 <script> 标签及其内容
  6991. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6992. // 去除所有 HTML 标签
  6993. $content = strip_tags($content);
  6994. // 去除 HTML 实体
  6995. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6996. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6997. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6998. // 去除多余空白
  6999. $content = preg_replace('/\s+/u', '', $content);
  7000. // 截取 100 个字符
  7001. $data['introduce'] = mb_substr($content, 0, 100);
  7002. }
  7003. if (isset($data['level']) && $data['level'] != null) {
  7004. $data['level'] = intval($data['level']);
  7005. } else {
  7006. $data['level'] = null;
  7007. }
  7008. $user = User::where('id', $data['user_id'])->first();
  7009. if (empty($user)) {
  7010. return Result::error('用户不存在!');
  7011. }
  7012. if ($user['type_id'] == 10000) {
  7013. $data['status'] = 1;
  7014. } else {
  7015. $data['status'] = 0;
  7016. }
  7017. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7018. $this->sendMessage([
  7019. 'talk_type' => 900,
  7020. 'title' => $data['title'],
  7021. 'content' => '提交了审核',
  7022. 'messageType' => 8,
  7023. ]);
  7024. }
  7025. $result = Company::where('id', $data['id'])->update($data);
  7026. if ($result) {
  7027. return Result::success($result);
  7028. } else {
  7029. return Result::error('修改失败');
  7030. }
  7031. }
  7032. /**
  7033. * 删除企业
  7034. * @param array $data
  7035. * @return array
  7036. */
  7037. public function delCompany(array $data): array
  7038. {
  7039. $result = Company::where('id', $data['id'])->delete();
  7040. if ($result) {
  7041. return Result::success($result);
  7042. } else {
  7043. return Result::error('删除失败');
  7044. }
  7045. }
  7046. /**
  7047. * 审核企业
  7048. * @param array $data
  7049. * @return array
  7050. */
  7051. public function checkCompany(array $data): array
  7052. {
  7053. $user = User::where('id', $data['user_id'])->first();
  7054. if (empty($user)) {
  7055. return Result::error('用户不存在!');
  7056. }
  7057. $company = Company::where('id', $data['id'])->first();
  7058. if (empty($company)) {
  7059. return Result::error('企业不存在!');
  7060. }
  7061. // 状态:0:未审核 1:已审核 2:已拒绝
  7062. if ($data['status'] == 2 || $data['status'] == '2') {
  7063. $this->sendMessage([
  7064. 'talk_type' => 901,
  7065. 'title' => $company['title'],
  7066. 'content' => '审核拒绝',
  7067. 'messageType' => 8,
  7068. 'user_id' => $company['user_id'],
  7069. ]);
  7070. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7071. } else {
  7072. if ($data['status'] == 1) {
  7073. $this->sendMessage([
  7074. 'talk_type' => 901,
  7075. 'title' => $company['title'],
  7076. 'content' => '审核通过',
  7077. 'messageType' => 8,
  7078. 'user_id' => $company['user_id'],
  7079. ]);
  7080. } else if ($data['status'] == 0) {
  7081. $this->sendMessage([
  7082. 'talk_type' => 900,
  7083. 'title' => $company['title'],
  7084. 'content' => '提交了审核',
  7085. 'messageType' => 8,
  7086. ]);
  7087. }
  7088. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7089. }
  7090. if (empty($result)) {
  7091. return Result::error('审核失败!');
  7092. } else {
  7093. return Result::success($result);
  7094. }
  7095. }
  7096. /**
  7097. * 获取企业信息
  7098. * @param array $data
  7099. * @return array
  7100. */
  7101. public function getCompanyInfo(array $data): array
  7102. {
  7103. $result = Company::where('id', $data['id'])->first();
  7104. $city_arr = json_decode($result['city_arr_id']);
  7105. $result['city_name'] = District::whereIn('id', $city_arr)
  7106. ->pluck('name')
  7107. ->implode('-');
  7108. if (empty($result)) {
  7109. return Result::error('企业不存在!');
  7110. } else {
  7111. return Result::success($result);
  7112. }
  7113. }
  7114. /**
  7115. * @param array $data
  7116. * @return array
  7117. */
  7118. public function getWebsiteCompany(array $data): array
  7119. {
  7120. $categorys = json_decode($data['id'], true);
  7121. $category_arr = $this->processArticlePro($data['website_id']);
  7122. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7123. $catiall = $category_arr['catiall'];
  7124. $categoryIds = $category_arr['categoryIds'];
  7125. // return Result::success($category_arr);
  7126. foreach ($categorys as $key => $value) {
  7127. if (array_key_exists('level', $value)) {
  7128. $parts = explode(',', $value['level']);
  7129. $level = $parts[0] ?? null;
  7130. $imgnum = $parts[1] ?? null;
  7131. $textnum = $parts[2] ?? null;
  7132. if (!empty($textnum) && $textnum > 0) {
  7133. $text_num = Company::where('level', $level)
  7134. ->whereIn('category_id', $categoryIds)
  7135. ->where('status', 1)
  7136. ->select(
  7137. 'company.id',
  7138. 'company.title',
  7139. 'company.description',
  7140. 'company.updated_at',
  7141. 'company.category_id',
  7142. 'company.cat_arr_id'
  7143. )
  7144. ->orderBy('updated_at', 'desc')
  7145. ->limit($textnum)
  7146. ->get()->all();
  7147. }
  7148. if (!empty($imgnum) && $imgnum > 0) {
  7149. $img_num = Company::where('level', $level)
  7150. ->whereIn('category_id', $categoryIds)
  7151. ->where('status', 1)
  7152. ->where('imgurl', '!=', '')
  7153. ->whereNotNull('imgurl')
  7154. ->select(
  7155. 'company.id',
  7156. 'company.title',
  7157. 'company.description',
  7158. 'company.updated_at',
  7159. 'company.imgurl as imgs',
  7160. 'company.category_id',
  7161. 'company.cat_arr_id'
  7162. )
  7163. ->orderBy('updated_at', 'desc')
  7164. ->limit($imgnum)
  7165. ->get()->all();
  7166. }
  7167. }
  7168. if (array_key_exists('id', $value)) {
  7169. $parts = explode(',', $value['id']);
  7170. $category_id = $parts[0] ?? null;
  7171. $imgnum = $parts[1] ?? null;
  7172. $textnum = $parts[2] ?? null;
  7173. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7174. if (!empty($textnum) && $textnum > 0) {
  7175. $text_num = Company::whereIn('category_id', $category_arr)
  7176. // ->where('website_id', $data['website_id'])
  7177. ->where('status', 1)
  7178. ->select(
  7179. 'company.id',
  7180. 'company.title',
  7181. 'company.description',
  7182. 'company.updated_at',
  7183. 'company.category_id',
  7184. 'company.cat_arr_id'
  7185. )
  7186. ->orderBy('updated_at', 'desc')
  7187. ->limit($textnum)
  7188. ->get()->all();
  7189. }
  7190. if (!empty($imgnum) && $imgnum > 0) {
  7191. $img_num = Company::whereIn('category_id', $category_arr)
  7192. // ->where('website_id', $data['website_id'])
  7193. ->where('status', 1)
  7194. ->where('imgurl', '!=', '')
  7195. ->whereNotNull('imgurl')
  7196. ->select(
  7197. 'company.id',
  7198. 'company.title',
  7199. 'company.description',
  7200. 'company.updated_at',
  7201. 'company.imgurl as imgs',
  7202. 'company.category_id',
  7203. 'company.cat_arr_id'
  7204. )
  7205. ->orderBy('updated_at', 'desc')
  7206. ->limit($imgnum)
  7207. ->get()->all();
  7208. }
  7209. }
  7210. if (!empty($text_num)) {
  7211. foreach ($text_num as $k => $v) {
  7212. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7213. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7214. }
  7215. }
  7216. if (!empty($img_num)) {
  7217. foreach ($img_num as $k => $v) {
  7218. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7219. $imgurl = json_decode($v['imgs'], true);
  7220. if (!empty($imgurl)) {
  7221. $img_num[$k]->imgurl = $imgurl[0];
  7222. }
  7223. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7224. }
  7225. }
  7226. $company[$key]['img_num'] = $img_num ?? [];
  7227. $company[$key]['text_num'] = $text_num ?? [];
  7228. }
  7229. if (empty($company)) {
  7230. return Result::error("暂无相关企业信息", 0);
  7231. }
  7232. return Result::success($company);
  7233. }
  7234. /**
  7235. * @param array $data
  7236. * @return array
  7237. */
  7238. public function getWebsiteCompanyList(array $data): array
  7239. {
  7240. $where['website_id'] = $data['website_id'];
  7241. $where['status'] = 1;
  7242. $categoryIds = [];
  7243. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7244. $category_id = $data['category_id'];
  7245. }
  7246. $category_arr = $this->processArticlePro($data['website_id']);
  7247. $categoryIds = $category_arr['categoryIds'];
  7248. // return Result::success($cat_1st_arr);
  7249. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7250. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7251. })
  7252. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7253. $query->whereIn('category_id', $categoryIds);
  7254. })
  7255. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7256. $query->where('category_id', $category_id);
  7257. })
  7258. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7259. ->orderBy('updated_at', 'desc')
  7260. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7261. if (empty($company)) {
  7262. return Result::error("暂无相关公司信息", 0);
  7263. }
  7264. $result = [
  7265. 'count' => $company->total(),
  7266. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7267. ];
  7268. return Result::success($result);
  7269. }
  7270. /**
  7271. * 获取项目列表
  7272. * @param array $data
  7273. * @return array
  7274. */
  7275. public function getProjectList(array $data): array
  7276. {
  7277. $where = [];
  7278. $user = User::where('id', $data['user_id'])->first();
  7279. if (empty($user)) {
  7280. return Result::error('用户不存在!');
  7281. }
  7282. if ($user->type_id != 10000) {
  7283. array_push($where, ['project.user_id', $data['user_id']]);
  7284. }
  7285. $query = Project::query();
  7286. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7287. array_push($where, ['project.website_id', $data['website_id']]);
  7288. }
  7289. if (isset($data['title']) && !empty($data['title'])) {
  7290. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7291. }
  7292. if ($data['status'] != 3) {
  7293. array_push($where, ['project.status', $data['status']]);
  7294. }
  7295. $query = Project::where($where)
  7296. ->when($data['status'] == 3, function ($query) {
  7297. $query->whereIn('project.status', [0, 2]);
  7298. });
  7299. $count = $query->clone()
  7300. ->count();
  7301. $rows = $query->clone()
  7302. ->leftJoin('website', 'project.website_id', 'website.id')
  7303. ->leftJoin('website_category', function ($join) {
  7304. $join->on('project.website_id', '=', 'website_category.website_id')
  7305. ->on('project.category_id', '=', 'website_category.category_id');
  7306. })
  7307. ->select(
  7308. 'project.id',
  7309. 'project.title',
  7310. 'project.updated_at',
  7311. 'project.status',
  7312. 'website.website_name',
  7313. 'website_category.alias as category_name',
  7314. 'project.website_id',
  7315. 'project.user_id'
  7316. )
  7317. ->orderBy('project.updated_at', 'desc')
  7318. ->offset(($data['page'] - 1) * $data['pageSize'])
  7319. ->limit($data['pageSize'])
  7320. ->get();
  7321. if ($rows->isEmpty()) {
  7322. return Result::error("暂无相关项目信息", 0);
  7323. }
  7324. $result = [
  7325. 'count' => $count,
  7326. 'rows' => $rows,
  7327. ];
  7328. return Result::success($result);
  7329. }
  7330. /**
  7331. * 添加项目
  7332. * @param array $data
  7333. * @return array
  7334. */
  7335. public function addProject(array $data): array
  7336. {
  7337. $user = User::where('id', $data['user_id'])->first();
  7338. if (empty($user)) {
  7339. return Result::error("暂无相关用户信息", 0);
  7340. }
  7341. if ($user->type_id == 10000) {
  7342. $data['status'] = 1;
  7343. } else {
  7344. $data['status'] = 0;
  7345. }
  7346. if ($data['keyword'] == '') {
  7347. //提取标题+内容中的关键词
  7348. $data['keyword'] = $data['title'];
  7349. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7350. Jieba::init(); // 初始化 jieba-php
  7351. Finalseg::init();
  7352. $segList = Jieba::cut($data['keyword']);
  7353. $segList1 = array_slice($segList, 0, 8);
  7354. $data['keyword'] = implode(',', $segList1);
  7355. }
  7356. if ($data['description'] == '') {
  7357. //提取内容中的描述
  7358. // var_dump(11111);
  7359. //提取内容中的描述
  7360. $content = $data['introduce'];
  7361. // 去除 <style> 和 <script> 标签及其内容
  7362. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7363. // 去除所有 HTML 标签
  7364. $content = strip_tags($content);
  7365. // 去除 HTML 实体
  7366. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7367. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7368. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7369. // 去除多余空白
  7370. $content = preg_replace('/\s+/u', '', $content);
  7371. // 截取 100 个字符
  7372. $data['description'] = mb_substr($content, 0, 100);
  7373. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7374. }
  7375. if ($data['status'] == 0) {
  7376. $this->sendMessage([
  7377. 'talk_type' => 1000,
  7378. 'title' => $data['title'],
  7379. 'content' => '提交了审核',
  7380. 'messageType' => 9,
  7381. ]);
  7382. }
  7383. $project = Project::insertGetId($data);
  7384. if (empty($project)) {
  7385. return Result::error("暂无相关项目信息", 0);
  7386. }
  7387. return Result::success($project);
  7388. }
  7389. /**
  7390. * 更新项目
  7391. * @param array $data
  7392. * @return array
  7393. */
  7394. public function upProject(array $data): array
  7395. {
  7396. $project = Project::where('id', $data['id'])->first();
  7397. if (empty($project)) {
  7398. return Result::error("暂无相关项目信息", 0);
  7399. }
  7400. $id = $data['id'];
  7401. unset($data['id']);
  7402. $user = User::where('id', $data['user_id'])->first();
  7403. if (empty($user)) {
  7404. return Result::error("暂无相关用户信息", 0);
  7405. }
  7406. if ($user->type_id == 10000) {
  7407. $data['status'] = 1;
  7408. } else {
  7409. $data['status'] = 0;
  7410. }
  7411. unset($data['user_id']);
  7412. if ($data['keyword'] == '') {
  7413. //提取标题+内容中的关键词
  7414. $data['keyword'] = $data['title'];
  7415. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7416. Jieba::init(); // 初始化 jieba-php
  7417. Finalseg::init();
  7418. $segList = Jieba::cut($data['keyword']);
  7419. $segList1 = array_slice($segList, 0, 8);
  7420. $data['keyword'] = implode(',', $segList1);
  7421. }
  7422. if ($data['description'] == '') {
  7423. //提取内容中的描述
  7424. // var_dump(11111);
  7425. //提取内容中的描述
  7426. $content = $data['introduce'];
  7427. // 去除 <style> 和 <script> 标签及其内容
  7428. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7429. // 去除所有 HTML 标签
  7430. $content = strip_tags($content);
  7431. // 去除 HTML 实体
  7432. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7433. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7434. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7435. // 去除多余空白
  7436. $content = preg_replace('/\s+/u', '', $content);
  7437. // 截取 100 个字符
  7438. $data['description'] = mb_substr($content, 0, 100);
  7439. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7440. }
  7441. if ($data['status'] == 0) {
  7442. $this->sendMessage([
  7443. 'talk_type' => 1000,
  7444. 'title' => $data['title'],
  7445. 'content' => '提交了审核',
  7446. 'messageType' => 9,
  7447. ]);
  7448. }
  7449. $result = Project::where('id', $id)->update($data);
  7450. if (empty($result)) {
  7451. return Result::error("更新失败", 0);
  7452. }
  7453. return Result::success($result);
  7454. }
  7455. /**
  7456. * 删除项目
  7457. * @param array $data
  7458. * @return array
  7459. */
  7460. public function delProject(array $data): array
  7461. {
  7462. $user = User::where('id', $data['user_id'])->first();
  7463. if (empty($user)) {
  7464. return Result::error("暂无相关用户信息", 0);
  7465. }
  7466. $project = Project::where('id', $data['id'])->first();
  7467. if (empty($project)) {
  7468. return Result::error("暂无相关项目信息", 0);
  7469. }
  7470. $result = Project::where('id', $data['id'])->delete();
  7471. if (empty($result)) {
  7472. return Result::error("删除失败", 0);
  7473. }
  7474. return Result::success($result);
  7475. }
  7476. /**
  7477. * 审核项目
  7478. * @param array $data
  7479. * @return array
  7480. */
  7481. public function checkProject(array $data): array
  7482. {
  7483. $user = User::where('id', $data['user_id'])->first();
  7484. if (empty($user)) {
  7485. return Result::error("暂无相关用户信息", 0);
  7486. }
  7487. // 0:未审核; 1:已审核; 2:已拒绝;
  7488. if ($user->type_id != 10000) {
  7489. if ($data['status'] == 1 || $data['status'] == 2) {
  7490. return Result::error("此用户权限不足", 0);
  7491. }
  7492. }
  7493. $project = Project::where('id', $data['id'])->first();
  7494. if (empty($project)) {
  7495. return Result::error("暂无相关项目信息", 0);
  7496. }
  7497. if ($data['status'] == 2) {
  7498. $this->sendMessage([
  7499. 'talk_type' => 1001,
  7500. 'title' => $project['title'],
  7501. 'content' => '审核拒绝',
  7502. 'messageType' => 9,
  7503. 'user_id' => $project['user_id'],
  7504. ]);
  7505. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7506. } else {
  7507. if ($data['status'] == 1) {
  7508. $this->sendMessage([
  7509. 'talk_type' => 1001,
  7510. 'title' => $project['title'],
  7511. 'content' => '审核通过',
  7512. 'messageType' => 9,
  7513. 'user_id' => $project['user_id'],
  7514. ]);
  7515. } else if ($data['status'] == 0) {
  7516. $this->sendMessage([
  7517. 'talk_type' => 1000,
  7518. 'title' => $project['title'],
  7519. 'content' => '提交了审核',
  7520. 'messageType' => 9,
  7521. ]);
  7522. }
  7523. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7524. }
  7525. if (empty($result)) {
  7526. return Result::error("审核失败", 0);
  7527. }
  7528. return Result::success($result);
  7529. }
  7530. /**
  7531. * 获取项目详情
  7532. * @param array $data
  7533. * @return array
  7534. */
  7535. public function getProjectInfo(array $data): array
  7536. {
  7537. $project = Project::where('id', $data['id'])->first();
  7538. if (empty($project)) {
  7539. return Result::error("暂无相关项目信息", 0);
  7540. }
  7541. return Result::success($project);
  7542. }
  7543. public function getWebsiteCompanyInfo(array $data): array
  7544. {
  7545. $company = Company::where('id', $data['id'])
  7546. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7547. ->where('status', 1)
  7548. // ->where('website_id', $data['website_id'])
  7549. ->select('company.*', 'job_industry.hyname as hy_name')
  7550. ->first();
  7551. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7552. switch ($company->jobnature_id) {
  7553. case null:
  7554. $company->jobnature_name = '';
  7555. break;
  7556. case 0:
  7557. $company->jobnature_name = '市场监督';
  7558. break;
  7559. case 1:
  7560. $company->jobnature_name = '信访纪检';
  7561. break;
  7562. case 2:
  7563. $company->jobnature_name = '公检法司';
  7564. break;
  7565. case 3:
  7566. $company->jobnature_name = '高关注机构';
  7567. break;
  7568. default:
  7569. $company->jobnature_name = '';
  7570. break;
  7571. }
  7572. $city_arr = $company->city_arr_id;
  7573. if (!empty($city_arr)) {
  7574. $city_arr = json_decode($city_arr, true);
  7575. $cityNames = District::whereIn('id', $city_arr)
  7576. ->pluck('name')
  7577. ->implode('-');
  7578. $company->city_name = $cityNames;
  7579. } else {
  7580. $company->city_name = '';
  7581. }
  7582. if (empty($company)) {
  7583. return Result::error("暂无相关公司信息", 0);
  7584. }
  7585. return Result::success($company);
  7586. }
  7587. public function getMSG(array $data): array
  7588. {
  7589. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7590. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7591. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7592. $result = [];
  7593. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7594. //最近的5篇已审的文章
  7595. $apply_articale = Article::where('status', 1)
  7596. ->where('admin_user_id', $user_id)
  7597. ->orderBy('updated_at', 'desc')
  7598. // ->limit(5)
  7599. ->get();
  7600. //获取5条用户的已审核商品
  7601. $good = Good::where('status', 2)
  7602. ->where('user_id', $user_id)
  7603. ->orderBy('updated_at', 'desc')
  7604. // ->limit(5)
  7605. ->get();
  7606. //获取5条用户待审核的公告
  7607. $notice = Notice::where('status', 2)
  7608. ->where('user_id', $user_id)
  7609. ->orderBy('updated_at', 'desc')
  7610. ->limit(5)->get();
  7611. //获取5条用户的待审核投诉
  7612. $complaint = Complaint::where('status', 2)
  7613. ->where('user_id', $user_id)
  7614. ->orderBy('updated_at', 'desc')
  7615. // ->limit(5)
  7616. ->get();
  7617. //获取5条用户的book
  7618. $book = Book::where('status', 2)
  7619. ->where('user_id', $user_id)
  7620. ->orderBy('updated_at', 'desc')
  7621. // ->limit(5)
  7622. ->get();
  7623. //获取5条用户的求职
  7624. //获取5条用户的求职 1
  7625. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7626. ->where('job_hunting.user_id', $user_id)
  7627. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7628. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7629. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7630. ->orderBy('updated_at', 'desc')
  7631. // ->limit(5)
  7632. ->get();
  7633. //获取5条用户的求职 2
  7634. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7635. ->where('job_recruiting.user_id', $user_id)
  7636. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7637. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7638. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7639. ->orderBy('updated_at', 'desc')
  7640. // ->limit(5)
  7641. ->get();
  7642. //人才库 1
  7643. $job_apply = JobApply::where('job_apply.status', 1)
  7644. ->where('job_apply.receiver_id', $user_id)
  7645. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7646. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7647. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7648. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7649. ->select('job_recruiting', 'job_recruiting.', '', '')
  7650. ->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')
  7651. ->orderBy('updated_at', 'desc')
  7652. // ->limit(5)
  7653. ->get();
  7654. // 职场机会 2
  7655. $job_resume = JobResume::where('job_resume.status', 1)
  7656. ->where('job_resume.receiver_id', $user_id)
  7657. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7658. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7659. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7660. ->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')
  7661. ->orderBy('updated_at', 'desc')
  7662. // ->limit(5)
  7663. ->get();
  7664. //获取5条用户待处理的投诉
  7665. $complaint_deal = Complaint::where('status', 2)
  7666. ->where('deal', 1)
  7667. ->whereJsonContains('re_user_ids', $user_id)
  7668. ->orderBy('updated_at', 'desc')
  7669. // ->limit(5)
  7670. ->get();
  7671. //获取 被通知者未读信息
  7672. $notice_unread = Notice::where('status', 2)
  7673. ->whereJsonContains('re_user_ids', $user_id)
  7674. //未读消息
  7675. ->where(function ($query) use ($user_id) {
  7676. $query->whereJsonDoesntContain('read_id', $user_id)
  7677. ->orWhereNull('read_id');
  7678. })
  7679. ->orderBy('updated_at', 'desc')
  7680. ->get();
  7681. $complaint_unread = Complaint::where('status', 2)
  7682. ->whereJsonContains('re_user_ids', $user_id)
  7683. //未读消息
  7684. ->where(function ($query) use ($user_id) {
  7685. $query->whereJsonDoesntContain('read_id', $user_id)
  7686. ->orWhereNull('read_id');
  7687. })
  7688. ->orderBy('updated_at', 'desc')
  7689. ->get();
  7690. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7691. $complany = Company::where('status', 1)
  7692. ->where('user_id', $user_id)
  7693. ->orderBy('updated_at', 'desc')
  7694. // ->limit(5)
  7695. ->get();
  7696. //获取5条单聊未读聊天消息
  7697. // $chat = ChatRecords::where('is_read', 0)
  7698. // ->where('user_id', $user_id)
  7699. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7700. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7701. // ->where('action', 'recieved')
  7702. // ->where('talk_type', 1)
  7703. // ->orderBy('created_at', 'desc')
  7704. // // ->limit(5)
  7705. // ->get();
  7706. //获取5条未读群聊信息
  7707. // $chat_group = ChatRecords::where('is_read', 0)
  7708. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7709. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7710. // ->where('user_id', $user_id)
  7711. // ->where('talk_type', 2)
  7712. // ->orderBy('created_at', 'desc')
  7713. // // ->limit(5)
  7714. // ->get();
  7715. //获取5条用户的待审核项目
  7716. $project = Project::where('status', 1)
  7717. ->where('user_id', $user_id)
  7718. ->orderBy('updated_at', 'desc')
  7719. // ->limit(5)
  7720. ->get();
  7721. // count($chat) + count($chat_group) +
  7722. $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)
  7723. + count($complany)
  7724. + count($project)
  7725. + count($notice_unread)
  7726. + count($complaint_unread)
  7727. // + count($chat) + count($chat_group)
  7728. ;
  7729. $result = [
  7730. 'apply_articale' => $apply_articale,
  7731. // 'chat' => $chat,
  7732. // 'chat_group' => $chat_group,
  7733. 'good' => $good,
  7734. 'notice' => $notice,
  7735. 'complaint' => $complaint,
  7736. 'book' => $book,
  7737. 'job_hunting' => $job_hunting,
  7738. 'job_recruiting' => $job_recruiting,
  7739. 'job_apply' => $job_apply,
  7740. 'job_resume' => $job_resume,
  7741. 'complaint_deal' => $complaint_deal,
  7742. 'complany' => $complany,
  7743. 'project' => $project,
  7744. 'notice_unread' => $notice_unread,
  7745. 'complaint_unread' => $complaint_unread,
  7746. 'count' => $count,
  7747. ];
  7748. } elseif ($type_id == 12) {
  7749. //最近的5篇已审的文章
  7750. $apply_articale = Article::where('status', 1)
  7751. ->where('admin_user_id', $user_id)
  7752. ->limit(5)->get();
  7753. //获取5条单聊未读聊天消息
  7754. $chat = ChatRecords::where('is_read', 0)
  7755. ->where('user_id', $user_id)
  7756. ->where('talk_type', 1)
  7757. ->orderBy('created_at', 'desc')
  7758. ->limit(5)->get();
  7759. //获取5条未读群聊信息
  7760. $chat_group = ChatRecords::where('is_read', 0)
  7761. ->where('user_id', $user_id)
  7762. ->where('talk_type', 2)
  7763. ->orderBy('created_at', 'desc')
  7764. ->limit(5)->get();
  7765. //获取5条用户的已审核商品
  7766. $good = Good::where('status', 2)
  7767. ->where('user_id', $user_id)
  7768. ->orderBy('updated_at', 'desc')
  7769. ->limit(5)->get();
  7770. //获取5条用户的book
  7771. $book = Book::where('status', 2)
  7772. ->where('user_id', $user_id)
  7773. ->orderBy('updated_at', 'desc')
  7774. ->limit(5)->get();
  7775. //获取5条用户的求职
  7776. //获取5条用户的求职 1
  7777. //count($chat) + count($chat_group)
  7778. $count = count($apply_articale) + count($good);
  7779. $result = [
  7780. 'apply_articale' => $apply_articale,
  7781. 'chat' => $chat,
  7782. 'chat_group' => $chat_group,
  7783. 'good' => $good,
  7784. 'book' => $book,
  7785. 'count' => $count,
  7786. ];
  7787. } elseif ($type_id == 13) {
  7788. //最近的5篇已审的文章
  7789. $apply_articale = Article::where('status', 1)
  7790. ->where('admin_user_id', $user_id)
  7791. ->limit(5)->get();
  7792. //获取5条单聊未读聊天消息
  7793. $chat = ChatRecords::where('is_read', 0)
  7794. ->where('user_id', $user_id)
  7795. ->where('talk_type', 1)
  7796. ->orderBy('created_at', 'desc')
  7797. ->limit(5)->get();
  7798. //获取5条未读群聊信息
  7799. $chat_group = ChatRecords::where('is_read', 0)
  7800. ->where('user_id', $user_id)
  7801. ->where('talk_type', 2)
  7802. ->orderBy('created_at', 'desc')
  7803. ->limit(5)->get();
  7804. //获取5条用户的已审核商品
  7805. $good = Good::where('status', 2)
  7806. ->where('user_id', $user_id)
  7807. ->orderBy('updated_at', 'desc')
  7808. ->limit(5)->get();
  7809. //count($chat) + count($chat_group) +
  7810. $count = count($apply_articale) + count($good);
  7811. $result = [
  7812. 'apply_articale' => $apply_articale,
  7813. 'chat' => $chat,
  7814. 'chat_group' => $chat_group,
  7815. 'good' => $good,
  7816. 'count' => $count,
  7817. ];
  7818. } elseif ($type_id == 14) {
  7819. //最近的5篇已审的文章
  7820. $apply_articale = Article::where('status', 1)
  7821. ->where('admin_user_id', $user_id)
  7822. // ->limit(5)
  7823. ->get();
  7824. //获取5条用户的已审核商品
  7825. $good = Good::where('status', 2)
  7826. ->where('user_id', $user_id)
  7827. ->orderBy('updated_at', 'desc')
  7828. // ->limit(5)
  7829. ->get();
  7830. $count = count($apply_articale) + count($good);
  7831. $result = [
  7832. 'apply_articale' => $apply_articale,
  7833. 'chat' => '',
  7834. 'chat_group' => '',
  7835. 'good' => $good,
  7836. 'count' => $count,
  7837. ];
  7838. } elseif ($type_id == 10000) {
  7839. //获取未审核的5篇文章
  7840. $apply_articale = Article::where('status', 0)
  7841. ->orderBy('updated_at', 'desc')
  7842. // ->limit(5)
  7843. ->get();
  7844. //获取5条单聊未读聊天消息
  7845. //获取5条单聊未读聊天消息
  7846. // $chat = ChatRecords::where('is_read', 0)
  7847. // ->where('user_id', $user_id)
  7848. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7849. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7850. // ->where('action', 'recieved')
  7851. // ->where('talk_type', 1)
  7852. // ->orderBy('created_at', 'desc')
  7853. // // ->limit(5)
  7854. // ->get();
  7855. // //获取5条未读群聊信息
  7856. // $chat_group = ChatRecords::where('is_read', 0)
  7857. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7858. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7859. // ->where('user_id', $user_id)
  7860. // ->where('talk_type', 2)
  7861. // ->orderBy('created_at', 'desc')
  7862. // // ->limit(5)
  7863. // ->get();
  7864. //获取5条用户的已审核商品
  7865. $good = Good::where('status', 1)
  7866. // ->where('user_id', $user_id)
  7867. ->orderBy('updated_at', 'desc')
  7868. // ->limit(5)
  7869. ->get();
  7870. //获取5条用户待审核的公告
  7871. $notice = Notice::where('status', 1)
  7872. ->orderBy('updated_at', 'desc')
  7873. // ->limit(5)
  7874. ->get();
  7875. //获取5条用户的待审核投诉
  7876. $complaint = Complaint::where('status', 1)
  7877. ->orderBy('updated_at', 'desc')
  7878. // ->limit(5)
  7879. ->get();
  7880. //获取5条用户的book
  7881. $book = Book::where('status', 1)
  7882. ->orderBy('updated_at', 'desc')
  7883. // ->limit(5)
  7884. ->get();
  7885. //获取5条用户的求职 1
  7886. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7887. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7888. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7889. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7890. ->orderBy('updated_at', 'desc')
  7891. // ->limit(5)
  7892. ->get();
  7893. //获取5条用户的求职 2
  7894. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7895. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7896. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7897. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7898. ->orderBy('updated_at', 'desc')
  7899. // ->limit(5)
  7900. ->get();
  7901. //人才库 1
  7902. $job_apply = JobApply::where('job_apply.status', 1)
  7903. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7904. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7905. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7906. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7907. ->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')
  7908. ->orderBy('updated_at', 'desc')
  7909. // ->limit(5)
  7910. ->get();
  7911. // 职场机会 2
  7912. $job_resume = JobResume::where('job_resume.status', 1)
  7913. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7914. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7915. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7916. ->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')
  7917. ->orderBy('updated_at', 'desc')
  7918. // ->limit(5)
  7919. ->get();
  7920. //待审核数据com pro
  7921. $complany = Company::where('status', 0)
  7922. ->orderBy('updated_at', 'desc')
  7923. // ->limit(5)
  7924. ->get();
  7925. $project = Project::where('status', 0)
  7926. ->orderBy('updated_at', 'desc')
  7927. // ->limit(5)
  7928. ->get();
  7929. $count =
  7930. // count($chat) +
  7931. // count($chat_group) +
  7932. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7933. // + count($job_apply)
  7934. // + count($job_resume)
  7935. + count($complany)
  7936. + count($project);
  7937. $result = [
  7938. 'apply_articale' => $apply_articale,
  7939. // 'chat' => $chat,
  7940. // 'chat_group' => $chat_group,
  7941. 'good' => $good,
  7942. 'notice' => $notice,
  7943. 'complaint' => $complaint,
  7944. 'book' => $book,
  7945. 'job_hunting' => $job_hunting,
  7946. 'job_recruiting' => $job_recruiting,
  7947. // 'job_apply' => $job_apply,
  7948. // 'job_resume' => $job_resume,
  7949. 'complany' => $complany,
  7950. 'project' => $project,
  7951. 'count' => $count,
  7952. ];
  7953. } elseif ($type_id == 20000) {
  7954. }
  7955. var_dump($type_id, '-----------------test---------');
  7956. return Result::success($result);
  7957. }
  7958. /**
  7959. * @param array $data
  7960. * @return array
  7961. */
  7962. public function getWebsiteProject(array $data): array
  7963. {
  7964. $categorys = json_decode($data['id'], true);
  7965. if (!empty($categorys)) {
  7966. $category_arr = $this->processArticlePro($data['website_id']);
  7967. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7968. $catiall = $category_arr['catiall'];
  7969. // return Result::success($catiall);
  7970. foreach ($categorys as $key => $val) {
  7971. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7972. $level = explode(',', $val['level'])[0];
  7973. $imgnum = explode(',', $val['level'])[1] ?? null;
  7974. $textnum = explode(',', $val['level'])[2] ?? null;
  7975. if ($level == 1) {
  7976. if (!empty($textnum) && $textnum > 0) {
  7977. $text_num = Project::where('level', $level)
  7978. ->where('website_id', $data['website_id'])
  7979. ->where('status', 1)
  7980. ->select(
  7981. 'project.id',
  7982. 'project.title',
  7983. 'project.description',
  7984. 'project.updated_at',
  7985. 'project.category_id',
  7986. 'project.cat_arr_id'
  7987. )
  7988. ->orderBy('updated_at', 'desc')
  7989. ->limit($textnum)
  7990. ->get()->all();
  7991. }
  7992. if (!empty($imgnum) && $imgnum > 0) {
  7993. $img_num = Project::where('level', $level)
  7994. ->where('website_id', $data['website_id'])
  7995. ->where('status', 1)
  7996. ->where('imgurl', '!=', '')
  7997. ->whereNotNull('imgurl')
  7998. ->select(
  7999. 'project.id',
  8000. 'project.title',
  8001. 'project.description',
  8002. 'project.updated_at',
  8003. 'project.imgurl as imgs',
  8004. 'project.category_id',
  8005. 'project.cat_arr_id'
  8006. )
  8007. ->orderBy('updated_at', 'desc')
  8008. ->limit($imgnum)
  8009. ->get()->all();
  8010. }
  8011. } else {
  8012. if (!empty($textnum) && $textnum > 0) {
  8013. $text_num = Project::where('website_id', $data['website_id'])
  8014. ->where('status', 1)
  8015. ->select(
  8016. 'project.id',
  8017. 'project.title',
  8018. 'project.description',
  8019. 'project.updated_at',
  8020. 'project.category_id',
  8021. 'project.cat_arr_id',
  8022. 'project.website_id',
  8023. 'project.updated_at',
  8024. 'project.created_at'
  8025. )
  8026. ->orderBy('updated_at', 'desc')
  8027. ->limit($textnum)
  8028. ->get()->all();
  8029. }
  8030. if (!empty($imgnum) && $imgnum > 0) {
  8031. $img_num = Project::where('website_id', $data['website_id'])
  8032. ->where('status', 1)
  8033. ->where('imgurl', '!=', '')
  8034. ->whereNotNull('imgurl')
  8035. ->select(
  8036. 'project.id',
  8037. 'project.title',
  8038. 'project.description',
  8039. 'project.updated_at',
  8040. 'project.imgurl as imgs',
  8041. 'project.category_id',
  8042. 'project.cat_arr_id'
  8043. )
  8044. ->orderBy('updated_at', 'desc')
  8045. ->limit($imgnum)
  8046. ->get()->all();
  8047. }
  8048. }
  8049. }
  8050. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8051. $category_ids = explode(',', $val['id'])[0];
  8052. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8053. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8054. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8055. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8056. $text_num = Project::whereIn('category_id', $category_arr)
  8057. ->where('website_id', $data['website_id'])
  8058. ->where('status', 1)
  8059. ->select(
  8060. 'project.id',
  8061. 'project.title',
  8062. 'project.description',
  8063. 'project.updated_at',
  8064. 'project.category_id',
  8065. 'project.cat_arr_id'
  8066. )
  8067. ->orderBy('updated_at', 'desc')
  8068. ->limit($cat_textnum)
  8069. ->get()->all();
  8070. }
  8071. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8072. $img_num = Project::whereIn('category_id', $category_arr)
  8073. ->where('website_id', $data['website_id'])
  8074. ->where('status', 1)
  8075. ->where('imgurl', '!=', '')
  8076. ->whereNotNull('imgurl')
  8077. ->select(
  8078. 'project.id',
  8079. 'project.title',
  8080. 'project.description',
  8081. 'project.updated_at',
  8082. 'project.imgurl as imgs',
  8083. 'project.category_id',
  8084. 'project.cat_arr_id'
  8085. )
  8086. ->orderBy('updated_at', 'desc')
  8087. ->limit($cat_imgnum)
  8088. ->get()->all();
  8089. }
  8090. }
  8091. if (!empty($img_num)) {
  8092. foreach ($img_num as $k => $v) {
  8093. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8094. $imgurl = json_decode($v['imgs'], true);
  8095. if (!empty($imgurl)) {
  8096. $img_num[$k]->imgurl = $imgurl[0];
  8097. }
  8098. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8099. }
  8100. }
  8101. if (!empty($text_num)) {
  8102. foreach ($text_num as $k => $v) {
  8103. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8104. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8105. }
  8106. }
  8107. $project[$key]['img_num'] = $img_num ?? [];
  8108. $project[$key]['text_num'] = $text_num ?? [];
  8109. }
  8110. }
  8111. if (empty($project)) {
  8112. return Result::error("暂无相关项目信息", 0);
  8113. }
  8114. return Result::success($project);
  8115. }
  8116. /**
  8117. * @param array $data
  8118. * @return array
  8119. */
  8120. public function getWebsiteProjectInfo(array $data): array
  8121. {
  8122. $project = Project::where('id', $data['id'])
  8123. ->where('status', 1)
  8124. ->where('website_id', $data['website_id'])
  8125. ->select('project.*')
  8126. ->first();
  8127. if (empty($project)) {
  8128. return Result::error("暂无相关项目信息", 0);
  8129. }
  8130. return Result::success($project);
  8131. }
  8132. /**
  8133. * @param array $data
  8134. * @return array
  8135. */
  8136. public function getWebsiteProjectList(array $data): array
  8137. {
  8138. $where = [];
  8139. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8140. $where['category_id'] = $data['category_id'];
  8141. }
  8142. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8143. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8144. }
  8145. $query = Project::where($where)
  8146. ->where('status', 1)
  8147. ->where('website_id', $data['website_id'])
  8148. ->select(
  8149. 'project.id',
  8150. 'project.title',
  8151. 'project.description',
  8152. 'project.imgurl as imgs',
  8153. 'project.category_id',
  8154. 'project.cat_arr_id'
  8155. )
  8156. ->orderBy('updated_at', 'desc');
  8157. $count = $query->count();
  8158. $project = $query->clone()
  8159. ->offset(($data['page'] - 1) * $data['pageSize'])
  8160. ->limit($data['pageSize'])
  8161. ->get()->all();
  8162. if (empty($project)) {
  8163. return Result::error("暂无相关项目信息", 0);
  8164. }
  8165. $categorys = $this->processArticlePro($data['website_id']);
  8166. $catiall = $categorys['catiall'];
  8167. foreach ($project as $key => $val) {
  8168. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8169. if (!empty($val['imgs'])) {
  8170. $imgurl = json_decode($val['imgs'], true);
  8171. if (!empty($imgurl)) {
  8172. $project[$key]->imgurl = $imgurl[0];
  8173. }
  8174. } else {
  8175. $project[$key]->imgurl = '';
  8176. }
  8177. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8178. }
  8179. $result = [
  8180. 'rows' => $project,
  8181. 'count' => $count,
  8182. ];
  8183. return Result::success($result);
  8184. }
  8185. /**
  8186. * @param array $data
  8187. * @return array
  8188. */
  8189. public function getWebsiteCategoryJob(array $data): array
  8190. {
  8191. $categorys = json_decode($data['id'], true);
  8192. if (!empty($categorys)) {
  8193. $category_arr = $this->processArticlePro($data['website_id']);
  8194. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8195. $catiall = $category_arr['catiall'];
  8196. foreach ($categorys as $key => $val) {
  8197. if (isset($val['id']) && !empty($val['id'])) {
  8198. $catid = explode(',', $val['id'])[0] ?? null;
  8199. $type = explode(',', $val['id'])[1] ?? null;
  8200. $textnum = explode(',', $val['id'])[2] ?? null;
  8201. }
  8202. // 4:招聘;5:求职;
  8203. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8204. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8205. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8206. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8207. ->where('job_recruiting.status', 1)
  8208. ->where('job_recruiting.website_id', $data['website_id'])
  8209. ->select(
  8210. 'job_recruiting.id',
  8211. 'job_recruiting.title',
  8212. 'job_company.business_name',
  8213. 'job_recruiting.updated_at',
  8214. 'job_recruiting.cat_arr_id',
  8215. 'job_recruiting.keyword',
  8216. 'job_recruiting.description'
  8217. )
  8218. ->orderBy('job_recruiting.updated_at', 'desc')
  8219. ->limit($textnum)
  8220. ->get()->all();
  8221. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8222. // 状态 审核状态,1待审核2已审核3已拒绝
  8223. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8224. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8225. ->where('job_hunting.status', 2)
  8226. ->where('job_hunting.website_id', $data['website_id'])
  8227. ->select(
  8228. 'job_hunting.id',
  8229. 'job_hunting.name',
  8230. 'job_hunting.cat_arr_id',
  8231. 'job_position.zwname as job_name',
  8232. 'job_hunting.updated_at',
  8233. 'job_hunting.keyword',
  8234. 'job_hunting.slelf_evaluation'
  8235. )
  8236. ->orderBy('updated_at', 'desc')
  8237. ->limit($textnum)
  8238. ->get()->all();
  8239. } else {
  8240. $job = [];
  8241. }
  8242. // var_dump($catid.'222uuuuuuu'.$key);
  8243. if (!empty($job)) {
  8244. foreach ($job as $k => $value) {
  8245. if (isset($value->cat_arr_id)) {
  8246. $catArr = json_decode($value->cat_arr_id, true);
  8247. $catId = end($catArr);
  8248. } else {
  8249. continue;
  8250. }
  8251. if (isset($catiall[$catId])) {
  8252. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8253. }
  8254. }
  8255. }
  8256. // var_dump($catid.'xxxxx'.$key);
  8257. $result[$key] = $job ?? [];
  8258. }
  8259. }
  8260. if (empty($result)) {
  8261. return Result::error("暂无相关分类信息", 0);
  8262. }
  8263. return Result::success($result);
  8264. }
  8265. /**
  8266. * 发送消息
  8267. * @param array $messageData
  8268. * @return void
  8269. */
  8270. public function sendMessage($messageData)
  8271. {
  8272. $msg = [
  8273. 'talk_type' => $messageData['talk_type'],
  8274. 'title' => $messageData['title'],
  8275. 'content' => $messageData['content'],
  8276. 'messageType' => $messageData['messageType'],
  8277. 'user_id' => $messageData['user_id'] ?? '',
  8278. 'time' => microtime(),
  8279. ];
  8280. $message = new MqProducer($msg);
  8281. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8282. $producer->produce($message);
  8283. }
  8284. }