NewsService.php 317 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614
  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. $count = $query->count();
  443. $rep = $query
  444. ->orderBy("article.updated_at", "desc")
  445. ->limit($data['pageSize'])
  446. ->offset(($data['page'] - 1) * $data['pageSize'])
  447. ->get();
  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. // 采集器中的文章内容,在添加时,去掉div标签
  571. if($is_collect == 1){
  572. // 采集来的文章,content中可能包含div标签,需要先移除
  573. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  574. $article_data = preg_replace($pattern, '', $data['content']);
  575. $$articleDataContent['content'] = ArticleData::where('article_id', $data['id'])->update(['content' => $article_data]);
  576. }
  577. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  578. if (!$contentInsertId) {
  579. throw new \Exception('文章内容插入失败');
  580. }
  581. // ------c_show_time********add***2****
  582. // 直接使用当前系统时间,不再强制添加8小时
  583. $now = date('Y-m-d H:i:s');
  584. if($user_type == 10000 || $is_collect == 1){
  585. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  586. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  587. if (!isset($data['catid'])) {
  588. throw new \Exception('缺少必要字段:catid');
  589. }
  590. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  591. $web = WebsiteCategory::where('category_id', $data['catid'])
  592. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  593. ->select('website_id',
  594. 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'))
  595. ->get();
  596. // $id = 225; -----测试开启
  597. // 采集来的文章,错开时间在两小时之内发布
  598. if($user_type == 10000 && $is_collect == 1){
  599. $web_num = $web->where('is_core', '!=', 2)->count();
  600. $waiting_interval = 10;
  601. if($web_num > 12){
  602. // 若网站数量大于12个,则每个网站间隔时间取均值
  603. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  604. $waiting_interval = 120 / max(1, $web_num);
  605. }
  606. $time = 0;
  607. }else{
  608. // 非核心站与核心站----显示时间-----间隔
  609. $time = 20;
  610. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  611. $waiting_interval = 5;
  612. }
  613. // 将 Hyperf\Database\Model\Collection 转换为数组
  614. $webArray = $web->toArray();
  615. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  616. // 检查 $item 对象是否有 is_core 属性
  617. if (!isset($item['is_core'])) {
  618. throw new \Exception('$item 对象缺少 is_core 属性');
  619. }
  620. // 当 is_core 为 2 时,则表示此网站不存在
  621. if ($item['is_core'] == 2) {
  622. return null;
  623. }
  624. if($is_collect == 1){
  625. // 采集来的文章,错开时间在两小时之内发布
  626. // $time = 0;
  627. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  628. $time += $waiting_interval;
  629. }else if($item['is_core'] == 1){
  630. // 当 is_core 为 1 时,则表示此网站是核心站
  631. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  632. }else{
  633. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  634. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  635. if ($item['is_core'] == 0) {
  636. $time += $waiting_interval;
  637. }
  638. }
  639. return [
  640. 'article_id' => $id,
  641. 'website_id' => $item['website_id'],
  642. 'c_show_time' => $c_show_time,
  643. // 'is_core' => $item['is_core'],
  644. // 'time' => $time
  645. ];
  646. }, array_keys($webArray), $webArray)));
  647. // Db::commit();
  648. // return Result::success($article_ignore);
  649. if(!empty($article_ignore)){
  650. $article_ignores = ArticleIgnore::insert($article_ignore);
  651. if(!$article_ignores){
  652. throw new \Exception('c端展示时间插入失败');
  653. }
  654. }
  655. }
  656. // ------c_show_time********add***2****
  657. //处理投票
  658. if ($is_survey == 1) {
  659. //生成年月日时分秒+8位随机数
  660. $uuid = date('YmdHis') . rand(10000000, 99999999);
  661. var_dump($suvey_array, 'suvey_array________');
  662. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  663. var_dump($suveys_array, '---------------------1');
  664. var_dump($suvey_array, '---------------------2');
  665. $suvey_data = [];
  666. foreach ($suveys_array as $key => $value) {
  667. if ($value == '') {
  668. continue;
  669. }
  670. if (is_array($value)) {
  671. $suvey_data[] = [
  672. 'sur_id' => $uuid,
  673. 'art_id' => $id,
  674. 'website_id' => $website_id ?? 2,
  675. 'survey_name' => $survey_name,
  676. 'choice_name' => $value[1],
  677. 'is_other' => 1,
  678. 'other_id' => 0,
  679. 'results' => 0,
  680. ];
  681. } else {
  682. $suvey_data[] = [
  683. 'sur_id' => $uuid,
  684. 'art_id' => $id,
  685. 'website_id' => $website_id ?? 2,
  686. 'survey_name' => $survey_name,
  687. 'choice_name' => $value,
  688. 'is_other' => 0,
  689. 'other_id' => 0,
  690. 'results' => 0,
  691. ];
  692. }
  693. if (empty($suvey_data)) {
  694. throw new \Exception("投票数据为空");
  695. }
  696. }
  697. $result = ArticleSurvey::insert($suvey_data);
  698. if (!$result) {
  699. throw new \Exception("投票失败,ArticleSurvey插入失败");
  700. }
  701. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  702. if (!$result) {
  703. throw new \Exception("投票失败,更新主表失败");
  704. }
  705. }
  706. Db::commit();
  707. return Result::success(['id' => $id]);
  708. } catch (\Throwable $ex) {
  709. Db::rollBack();
  710. var_dump($ex->getMessage());
  711. return Result::error("创建失败", 0);
  712. }
  713. }
  714. /**
  715. * @param array $data
  716. * @return array
  717. */
  718. public function delArticle(array $data): array
  719. {
  720. // ------c_show_time********del*******
  721. Db::beginTransaction();
  722. try{
  723. $article = Article::where(['id' => $data['id']])->delete();
  724. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  725. if (!$article) {
  726. throw new \Exception("删除失败,文章删除失败");
  727. }
  728. //survey投票删除
  729. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  730. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  731. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  732. // 若文章详情删除失败,抛出异常
  733. if (!$article_data) {
  734. throw new \Exception("删除失败,文章详情删除失败");
  735. }
  736. Db::commit(); // 所有操作成功,提交事务
  737. }catch (\Throwable $ex) {
  738. Db::rollBack();
  739. var_dump($ex->getMessage());
  740. return Result::error("删除失败: " . $ex->getMessage(), 0);
  741. }
  742. // ------c_show_time********del*******
  743. if (!$article) {
  744. return Result::error("删除失败");
  745. }
  746. return Result::success($article);
  747. }
  748. /**
  749. * @param array $data
  750. * @return array
  751. */
  752. public function updateArticle(array $data): array
  753. {
  754. var_dump($data, '----------12-----------1');
  755. Db::beginTransaction();
  756. // ------c_show_time********up*******
  757. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  758. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  759. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  760. $web = WebsiteCategory::where('category_id', $data['catid'])
  761. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  762. ->select('website_id',
  763. 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'))
  764. ->get();
  765. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  766. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  767. $websiteIds = $web->pluck('website_id')->toArray();
  768. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  769. if($user_type == 0){
  770. throw new \Exception("用户类型不能为空");
  771. }
  772. if($user_type == 10000 ){
  773. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  774. $web = WebsiteCategory::where('category_id', $data['catid'])
  775. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  776. ->select('website_id',
  777. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  778. ->get();
  779. // 非核心站与核心站----显示时间-----间隔
  780. $time = 20;
  781. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  782. $waiting_interval = 5;
  783. $webArray = $web->toArray();
  784. if(empty($webArray)){
  785. throw new \Exception('网站分类不存在');
  786. }
  787. // 直接使用当前系统时间,不再强制添加8小时
  788. $now = date('Y-m-d H:i:s');
  789. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  790. // 检查 $item 对象是否有 is_core 属性
  791. if (!isset($item['is_core'])) {
  792. throw new \Exception('$item 对象缺少 is_core 属性');
  793. }
  794. // 当 is_core 为 2 时,则表示此网站不存在
  795. if ($item['is_core'] == 2) {
  796. return null;
  797. }else if($item['is_core'] == 1){
  798. // 当 is_core 为 1 时,则表示此网站是核心站
  799. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  800. }else{
  801. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  802. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  803. if ($item['is_core'] == 0) {
  804. $time += $waiting_interval;
  805. }
  806. }
  807. return [
  808. 'article_id' => $data['id'],
  809. 'website_id' => $item['website_id'],
  810. 'c_show_time' => $c_show_time,
  811. ];
  812. }, array_keys($webArray), $webArray)));
  813. if(!empty($article_ignore)){
  814. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  815. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  816. $article_ignores = ArticleIgnore::upsert(
  817. $article_ignore,
  818. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  819. ['c_show_time'] // 需要更新的字段
  820. );
  821. if(!$article_ignores){
  822. throw new \Exception('c端展示时间插入失败');
  823. }
  824. }
  825. // Db::commit();
  826. // return Result::success($article_ignore);
  827. }
  828. // ------c_show_time********up*******
  829. unset($data['user_type']);
  830. // unset($data['web_site_id']);
  831. unset($data['nav_add_pool_id']);
  832. try {
  833. //处理投票
  834. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  835. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  836. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  837. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  838. unset($data['is_survey']);
  839. unset($data['survey_name']);
  840. unset($data['suvey_array']);
  841. unset($data['website_id']);
  842. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  843. if ($data['hits'] == '') {
  844. $data['hits'] = 0;
  845. }
  846. if ($data['is_original'] == '') {
  847. $data['is_original'] = 0;
  848. }
  849. if ($data['status'] == '') {
  850. $data['status'] = 0;
  851. }
  852. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  853. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  854. $articleData = $data;
  855. unset($articleData['content']);
  856. unset($articleData['status_name']);
  857. unset($articleData['name']);
  858. unset($articleData['content']);
  859. unset($articleData['pid_arr']);
  860. unset($articleData['pid']);
  861. //自动处理缩略图、关键字、描述
  862. if ($articleData['imgurl'] == '') {
  863. //如果没有图,设置level=0
  864. $levelArr = json_decode($articleData['level'], true);
  865. var_dump($levelArr, '----------levelArr-----------1');
  866. //content中提取图片第一个图,正则提取
  867. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  868. preg_match_all($reg, $data['content'], $matches);
  869. if (isset($matches[1][0])) {
  870. //截取varchar240
  871. // 截取到第一个<
  872. $articleData['imgurl'] = $matches[1][0];
  873. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  874. $pos = strpos($articleData['imgurl'], '"');
  875. if ($pos !== false) {
  876. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  877. }
  878. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  879. //如果有图,设置level=3
  880. if (!in_array(3, $levelArr)) {
  881. $levelArr[] = 3;
  882. }
  883. $articleData['level'] = json_encode($levelArr);
  884. } else {
  885. if (!in_array(0, $levelArr)) {
  886. $levelArr[] = 0;
  887. }
  888. $articleData['level'] = json_encode($levelArr);
  889. }
  890. }
  891. var_dump($articleData['level'], '----------$articleData[level]----------1');
  892. if ($articleData['keyword'] == '') {
  893. //提取标题+内容中的关键词
  894. $articleData['keyword'] = $data['title'];
  895. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  896. Jieba::init(); // 初始化 jieba-php
  897. Finalseg::init();
  898. $segList = Jieba::cut($articleData['keyword']);
  899. $segList1 = array_slice($segList, 0, 8);
  900. $articleData['keyword'] = implode(',', $segList1);
  901. }
  902. if ($articleData['introduce'] == '') {
  903. //提取内容中的描述
  904. $content = $data['content'];
  905. // 去除 <style> 和 <script> 标签及其内容
  906. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  907. // 去除所有 HTML 标签
  908. $content = strip_tags($content);
  909. // 去除 HTML 实体
  910. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  911. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  912. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  913. // 去除多余空白
  914. $content = preg_replace('/\s+/u', '', $content);
  915. // 截取 100 个字符
  916. $articleData['introduce'] = mb_substr($content, 0, 100);
  917. }
  918. if ($articleData['status'] == 0) {
  919. $this->sendMessage([
  920. 'talk_type' => 100,
  921. 'title' => $articleData['title'],
  922. 'content' => '提交了审核',
  923. 'messageType' => 2,
  924. ]);
  925. }
  926. $id = Article::where(['id' => $data['id']])->update($articleData);
  927. $articleDataContent = [
  928. 'content' => $data['content'],
  929. ];
  930. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  931. //处理投票
  932. $id = $data['id'];
  933. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  934. var_dump($suvey_array, 'suvey_array________delete');
  935. //处理投票
  936. if ($is_survey == 1) {
  937. //生成年月日时分秒+8位随机数
  938. $uuid = date('YmdHis') . rand(10000000, 99999999);
  939. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  940. var_dump($suveys_array, '---------------------1');
  941. $suvey_data = [];
  942. if (is_array($suveys_array)) {
  943. foreach ($suveys_array as $key => $value) {
  944. if ($value == '') {
  945. continue;
  946. }
  947. if (is_array($value)) {
  948. $suvey_data[] = [
  949. 'sur_id' => $uuid,
  950. 'art_id' => $id,
  951. 'website_id' => $website_id ?? 2,
  952. 'survey_name' => $survey_name,
  953. 'choice_name' => $value[1],
  954. 'is_other' => 1,
  955. 'other_id' => 0,
  956. 'results' => 0,
  957. ];
  958. } else {
  959. $suvey_data[] = [
  960. 'sur_id' => $uuid,
  961. 'art_id' => $id,
  962. 'website_id' => $website_id ?? 2,
  963. 'survey_name' => $survey_name,
  964. 'choice_name' => $value,
  965. 'is_other' => 0,
  966. 'other_id' => 0,
  967. 'results' => 0,
  968. ];
  969. }
  970. if (empty($suvey_data)) {
  971. throw new \Exception("投票数据为空");
  972. }
  973. }
  974. }
  975. $result = ArticleSurvey::insert($suvey_data);
  976. if (!$result) {
  977. throw new \Exception("投票失败");
  978. }
  979. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  980. if (!$result) {
  981. throw new \Exception("投票失败");
  982. }
  983. } else {
  984. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  985. }
  986. Db::commit();
  987. return Result::success([]);
  988. } catch (\Throwable $ex) {
  989. Db::rollBack();
  990. var_dump($ex->getMessage());
  991. return Result::error("更新失败" . $ex->getMessage(), 0);
  992. }
  993. }
  994. /**
  995. * 更新资讯状态
  996. * @param array $data
  997. * @return array
  998. */
  999. public function upArticleStatus(array $data): array
  1000. {
  1001. $articleData = Article::where(['id' => $data['id']])->first();
  1002. //发送10次
  1003. // for ($i = 0; $i < 10; $i++) {
  1004. // $this->sendMessage([
  1005. // 'talk_type' => 100,
  1006. // 'title' => $i . $articleData['title'],
  1007. // 'content' => '审核通过',
  1008. // 'messageType' => 2,
  1009. // 'user_id' => $articleData['admin_user_id'],
  1010. // ]);
  1011. // }
  1012. // var_dump($data['status'], 'status');
  1013. // return Result::success();
  1014. if ($data['status'] == 1) {
  1015. $this->sendMessage([
  1016. 'talk_type' => 101,
  1017. 'title' => $articleData['title'],
  1018. 'content' => '审核通过',
  1019. 'messageType' => 2,
  1020. 'user_id' => $articleData['admin_user_id'],
  1021. ]);
  1022. }
  1023. if ($data['status'] == 2) {
  1024. $this->sendMessage([
  1025. 'talk_type' => 101,
  1026. 'title' => $articleData['title'],
  1027. 'content' => '审核拒绝',
  1028. 'messageType' => 2,
  1029. 'user_id' => $articleData['admin_user_id'],
  1030. ]);
  1031. }
  1032. if ($data['status'] == 0) {
  1033. $this->sendMessage([
  1034. 'talk_type' => 100,
  1035. 'title' => $articleData['title'],
  1036. 'content' => '提交了审核',
  1037. 'messageType' => 2,
  1038. ]);
  1039. }
  1040. $result = Article::where(['id' => $data['id']])->update($data);
  1041. // ------c_show_time********up_status*******
  1042. // 若是审核通过 则更新c_show_time
  1043. if($data['status'] == 1){
  1044. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1045. $web = Article::where('article.id',$data['id'])
  1046. ->leftJoin('website_category','article.catid','website_category.category_id')
  1047. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1048. ->select('website_id',
  1049. 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'))
  1050. ->get();
  1051. // 非核心站与核心站----显示时间-----间隔
  1052. $time = 20;
  1053. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1054. $waiting_interval = 5;
  1055. $webArray = $web->toArray();
  1056. if(empty($webArray)){
  1057. throw new \Exception('网站分类不存在');
  1058. }
  1059. // 直接使用当前系统时间,不再强制添加8小时
  1060. $now = date('Y-m-d H:i:s');
  1061. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1062. if(isset($data['ignore_ids'])){
  1063. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1064. if(in_array($item['website_id'], $ignore_website_ids)){
  1065. $is_ignore = 1;
  1066. }else{
  1067. $is_ignore = 0;
  1068. }
  1069. return [
  1070. 'article_id' => $data['id'],
  1071. 'website_id' => $item['website_id'],
  1072. 'is_ignore' => $is_ignore,
  1073. ];
  1074. }else{
  1075. // 检查 $item 对象是否有 is_core 属性
  1076. if (!isset($item['is_core'])) {
  1077. throw new \Exception('$item 对象缺少 is_core 属性');
  1078. }
  1079. // 当 is_core 为 2 时,则表示此网站不存在
  1080. if ($item['is_core'] == 2) {
  1081. return null;
  1082. }else if($item['is_core'] == 1){
  1083. // 当 is_core 为 1 时,则表示此网站是核心站
  1084. $c_show_time = $now;
  1085. }else{
  1086. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1087. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1088. if ($item['is_core'] == 0) {
  1089. $time += $waiting_interval;
  1090. }
  1091. }
  1092. return [
  1093. 'article_id' => $data['id'],
  1094. 'website_id' => $item['website_id'],
  1095. 'c_show_time' => $c_show_time,
  1096. ];
  1097. }
  1098. }, array_keys($webArray), $webArray)));
  1099. if(!empty($article_ignore) && !isset($data['ignore_ids'])){
  1100. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1101. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1102. $websiteIds = $web->pluck('website_id')->toArray();
  1103. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1104. $article_ignores = ArticleIgnore::upsert(
  1105. $article_ignore,
  1106. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1107. ['c_show_time'] // 需要更新的字段
  1108. );
  1109. if(!$article_ignores){
  1110. throw new \Exception('c端展示时间插入失败');
  1111. }
  1112. }
  1113. if(!empty($data['ignore_ids'])){
  1114. // return Result::success($article_ignore);
  1115. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1116. if(!empty($article_ignore)){
  1117. $article_ignores = ArticleIgnore::upsert(
  1118. $article_ignore,
  1119. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1120. ['is_ignore'] // 需要更新的字段
  1121. );
  1122. // if(!$article_ignores){
  1123. // throw new \Exception('屏蔽网站更新失败');
  1124. // }
  1125. }
  1126. }
  1127. }
  1128. // ------c_show_time********up_status*******
  1129. if ($result) {
  1130. return Result::success();
  1131. } else {
  1132. return Result::error("更新状态失败", 0);
  1133. }
  1134. }
  1135. /**
  1136. * 获取新闻详情
  1137. * @param array $data
  1138. * @return array
  1139. */
  1140. public function getArticleInfo(array $data): array
  1141. {
  1142. $where = [
  1143. 'article.id' => $data['id'],
  1144. // 'article.status' => 1,
  1145. ];
  1146. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1147. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1148. $info = $result;
  1149. // var_dump($info, 'info');
  1150. $info['survey_array'] = $articleSurvey;
  1151. if ($result) {
  1152. return Result::success($info);
  1153. } else {
  1154. return Result::error("查询失败", 0);
  1155. }
  1156. }
  1157. /**
  1158. * 获取头条新闻
  1159. * @param array $data
  1160. * @return array
  1161. */
  1162. public function getWebsiteArticlett(array $data): array
  1163. {
  1164. $website_id = $data['website_id'];
  1165. $website = Website::where('id', $data['website_id'])->first();
  1166. if (empty($website)) {
  1167. return Result::error("网站不存在", 0);
  1168. }
  1169. $categorys = $this->processArticlePro($website_id);
  1170. $catiall = $categorys['catiall'];
  1171. $categoryIds = $categorys['categoryIds'];
  1172. $where = [
  1173. 'status' => 1
  1174. ];
  1175. // $website_column = $website['column'];
  1176. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1177. $website_column = json_decode($website['website_column_arr_id'], true);
  1178. }
  1179. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1180. // return Result::success($diff_pid_categoryIds);
  1181. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1182. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1183. }
  1184. // $website_id = $data['website_id'];
  1185. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1186. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1187. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1188. switch ($data['level']) {
  1189. case 1:
  1190. case 2:
  1191. case 3:
  1192. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1193. $query = Article::where($where)
  1194. ->where('level', 'like', '%' . $data['level'] . '%')
  1195. ->orderBy('updated_at', 'desc');
  1196. break;
  1197. case 4: //最新资讯
  1198. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1199. break;
  1200. case 5: //资讯推荐
  1201. $query = Article::where($where)
  1202. ->where('updated_at', '>', $month);
  1203. break;
  1204. case 7: //资讯分类
  1205. if (isset($data['id']) && !empty($data['id'])) {
  1206. $keyword = Article::where('id', $data['id'])->value('keyword');
  1207. $keywordArray = explode(',', $keyword);
  1208. $whereL7 = [];
  1209. foreach ($keywordArray as $k => $v) {
  1210. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1211. }
  1212. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1213. break;
  1214. } else {
  1215. return Result::error("请输入资讯ID", 0);
  1216. break;
  1217. }
  1218. default:
  1219. break;
  1220. }
  1221. // $whereL7 = [];
  1222. // if(isset($data['id']) && !empty($data['id'])){
  1223. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1224. // $keywordArray = explode(',', $keyword);
  1225. // foreach ($keywordArray as $k => $v) {
  1226. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1227. // }
  1228. // }
  1229. // $query = Article::where($where)
  1230. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1231. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1232. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1233. // }
  1234. // if($data['level'] == 7){
  1235. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1236. // }
  1237. // if($data['level'] == 4){
  1238. // $query = $query->inRandomOrder()
  1239. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1240. // }
  1241. // if($data['level'] == 5){
  1242. // $query = $query->orderBy('updated_at','desc');
  1243. // }
  1244. // });
  1245. if ($data['textnum'] > 0) {
  1246. $query = clone $query;
  1247. $result['text'] = $query
  1248. ->whereIn('catid', $categoryIds)
  1249. ->leftJoinSub(function ($query) use ($website_id) {
  1250. $query->from('article_ignore')
  1251. ->where('website_id', $website_id);
  1252. }, 'article_ignore', function ($join) {
  1253. $join->on('article_ignore.article_id', '=', 'article.id');
  1254. })
  1255. ->where(function ($query) {
  1256. $query->whereNull('article_ignore.article_id')
  1257. ->orWhere(function ($subQuery) {
  1258. $subQuery->whereNotNull('article_ignore.article_id')
  1259. ->where('article_ignore.is_ignore', 0)
  1260. ->where(function ($subSubQuery) {
  1261. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1262. ->orWhereNull('article_ignore.c_show_time');
  1263. });
  1264. });
  1265. })
  1266. // ->where(function ($query) use ($website_id) {
  1267. // $query->whereNull('article_ignore.article_id')
  1268. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1269. // })
  1270. ->select(
  1271. 'article.id',
  1272. 'article.title',
  1273. 'article.author',
  1274. 'article.updated_at',
  1275. 'article.introduce',
  1276. 'article.islink',
  1277. 'article.linkurl',
  1278. 'article.copyfrom',
  1279. 'article.cat_arr_id',
  1280. 'article.catid',
  1281. 'article.level',
  1282. // 'article_ignore.is_ignore',
  1283. // 'article_ignore.c_show_time',
  1284. )
  1285. ->offset($data['placeid'])
  1286. ->limit($data['textnum'])
  1287. ->get()->all();
  1288. foreach ($result['text'] as $k => $v) {
  1289. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1290. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1291. }
  1292. }
  1293. if ($data['imgnum'] > 0) {
  1294. $query = clone $query;
  1295. if($data['textnum'] == 0){
  1296. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1297. $query->from('article_ignore')
  1298. ->where('website_id', $website_id);
  1299. }, 'article_ignore', function ($join) {
  1300. $join->on('article_ignore.article_id', '=', 'article.id');
  1301. })
  1302. ->where(function ($query) {
  1303. $query->whereNull('article_ignore.article_id')
  1304. ->orWhere(function ($subQuery) {
  1305. $subQuery->whereNotNull('article_ignore.article_id')
  1306. ->where('article_ignore.is_ignore', 0)
  1307. ->where(function ($subSubQuery) {
  1308. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1309. ->orWhereNull('article_ignore.c_show_time');
  1310. });
  1311. });
  1312. });
  1313. }
  1314. $result['img'] = $query
  1315. ->whereIn('catid', $categoryIds)
  1316. ->where('article.imgurl', '!=', '')
  1317. ->select(
  1318. 'article.id',
  1319. 'article.title',
  1320. 'article.imgurl',
  1321. 'article.author',
  1322. 'article.updated_at',
  1323. 'article.introduce',
  1324. 'article.islink',
  1325. 'article.linkurl',
  1326. 'article.copyfrom',
  1327. 'article.cat_arr_id',
  1328. 'article.catid',
  1329. 'article.level',
  1330. // 'article_ignore.is_ignore',
  1331. // 'article_ignore.c_show_time',
  1332. )
  1333. ->offset($data['placeid'])
  1334. ->limit($data['imgnum'])
  1335. ->get()->all();
  1336. foreach ($result['img'] as $k => $v) {
  1337. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1338. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1339. }
  1340. }
  1341. if (empty($result)) {
  1342. return Result::error("暂无相关资讯", 0);
  1343. }
  1344. return Result::success($result);
  1345. }
  1346. /**
  1347. * 获取模块新闻
  1348. * @param array $data
  1349. * @return array
  1350. */
  1351. public function getWebsiteModelArticles(array $data): array
  1352. {
  1353. $catid = $data['catid'];
  1354. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1355. $category = $category->toArray();
  1356. if (!empty($category)) {
  1357. $where = [
  1358. 'status' => 1,
  1359. 'catid' => $catid,
  1360. ];
  1361. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1362. // 1:文字新闻;2:轮播图;3:图文;
  1363. // 级别:0:未分类
  1364. // 3:推荐图片
  1365. if ($data['level'] == 1) {
  1366. $data['level'] = 0;
  1367. }
  1368. $result = Article::where($where)
  1369. ->where(function ($query) use ($data) {
  1370. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1371. ->orWhereNull("level")
  1372. ->orWhereRaw("level = '[]'");
  1373. })
  1374. ->leftJoinSub(function ($query) use ($data) {
  1375. $query->from('article_ignore')
  1376. ->where('website_id', $data['website_id']);
  1377. }, 'article_ignore', function ($join) {
  1378. $join->on('article_ignore.article_id', '=', 'article.id');
  1379. })
  1380. ->where(function ($query) {
  1381. $query->whereNull('article_ignore.article_id')
  1382. ->orWhere(function ($subQuery) {
  1383. $subQuery->whereNotNull('article_ignore.article_id')
  1384. ->where('article_ignore.is_ignore', 0)
  1385. ->where(function ($subSubQuery) {
  1386. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1387. ->orWhereNull('article_ignore.c_show_time');
  1388. });
  1389. });
  1390. })
  1391. // ->where(function ($query) use ($data) {
  1392. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1393. // ->orWhereNull("ignore_ids");
  1394. // })
  1395. ->orderBy("updated_at", "desc")
  1396. ->offset($placeid)
  1397. ->limit($data['pagesize'])
  1398. ->get();
  1399. if (empty($result)) {
  1400. return Result::error("此栏目暂无相关新闻", 0);
  1401. }
  1402. } else {
  1403. return Result::error("此网站暂无此栏目", 0);
  1404. }
  1405. return Result::success($result);
  1406. }
  1407. /**
  1408. *获取新闻列表
  1409. * @param array $data
  1410. * @return array
  1411. */
  1412. public function getWebsiteArticleList(array $data): array
  1413. {
  1414. // return Result::success($data);
  1415. $where[] = ['status', '=', 1];
  1416. $website_id = $data['website_id'];
  1417. $website = Website::where('id', $data['website_id'])->first();
  1418. if (empty($website)) {
  1419. return Result::error("网站不存在", 0);
  1420. }
  1421. // $website_column = $website['column'];
  1422. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1423. $website_column = json_decode($website['website_column_arr_id'], true);
  1424. }
  1425. $categorys = $this->processArticlePro($website_id);
  1426. $cat_1st_arr = $categorys['cat_1st_arr'];
  1427. $catiall = $categorys['catiall'];
  1428. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1429. // return Result::success($diff_pid_categoryIds);
  1430. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1431. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1432. }
  1433. if (isset($data['catid']) && !empty($data['catid'])) {
  1434. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1435. if (empty($category)) {
  1436. return Result::error("此网站暂无此栏目", 0);
  1437. }
  1438. array_push($where, ['catid', '=', $data['catid']]);
  1439. }
  1440. // return Result::success($where);
  1441. $query = Article::where($where)
  1442. ->leftJoinSub(function ($query) use ($website_id) {
  1443. $query->from('article_ignore')
  1444. ->where('website_id', $website_id);
  1445. }, 'article_ignore', function ($join) {
  1446. $join->on('article_ignore.article_id', '=', 'article.id');
  1447. })
  1448. ->where(function ($query) {
  1449. $query->whereNull('article_ignore.article_id')
  1450. ->orWhere(function ($subQuery) {
  1451. $subQuery->whereNotNull('article_ignore.article_id')
  1452. ->where('article_ignore.is_ignore', 0)
  1453. ->where(function ($subSubQuery) {
  1454. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1455. ->orWhereNull('article_ignore.c_show_time');
  1456. });
  1457. });
  1458. })
  1459. ->select(
  1460. 'article.id',
  1461. 'article.title',
  1462. 'article.imgurl',
  1463. 'article.author',
  1464. 'article.updated_at',
  1465. 'article.introduce',
  1466. 'article.islink',
  1467. 'article.linkurl',
  1468. 'article.copyfrom',
  1469. 'article.cat_arr_id',
  1470. 'article.catid'
  1471. );
  1472. $count = $query->count();
  1473. $rep = $query->orderBy("updated_at", "desc")
  1474. ->offset(($data['page'] - 1) * $data['pageSize'])
  1475. ->limit($data['pageSize'])
  1476. ->get()->all();
  1477. $categorys = $this->processArticlePro($website_id);
  1478. $cat_1st_arr = $categorys['cat_1st_arr'];
  1479. $catiall = $categorys['catiall'];
  1480. // $web['website_id'] = $data['website_id'];
  1481. foreach ($rep as $k => $v) {
  1482. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1483. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1484. }
  1485. // $rep = $this->processArticles($rep,$web);
  1486. $data = [
  1487. 'rows' => $rep,
  1488. 'count' => $count,
  1489. ];
  1490. if (empty($rep)) {
  1491. return Result::error("没有信息数据");
  1492. }
  1493. return Result::success($data);
  1494. }
  1495. /**
  1496. * 前端-获取新闻详情
  1497. * @param array $data
  1498. * @return array
  1499. */
  1500. public function selectWebsiteArticleInfo(array $data): array
  1501. {
  1502. $where = [
  1503. 'article.id' => $data['id'],
  1504. 'article.status' => 1,
  1505. ];
  1506. $result = Article::where($where)
  1507. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1508. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1509. // ->where(function ($query) use ($data) {
  1510. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1511. // ->orWhereNull("ignore_ids");
  1512. // })
  1513. ->leftJoinSub(function ($query) use ($data) {
  1514. $query->from('article_ignore')
  1515. ->where('website_id', $data['website_id']);
  1516. }, 'article_ignore', function ($join) {
  1517. $join->on('article_ignore.article_id', '=', 'article.id');
  1518. })
  1519. ->where(function ($query) {
  1520. $query->whereNull('article_ignore.article_id')
  1521. ->orWhere(function ($subQuery) {
  1522. $subQuery->whereNotNull('article_ignore.article_id')
  1523. ->where('article_ignore.is_ignore', 0)
  1524. ->where(function ($subSubQuery) {
  1525. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1526. ->orWhereNull('article_ignore.c_show_time');
  1527. });
  1528. });
  1529. })
  1530. ->select(
  1531. 'article.*',
  1532. 'article_data.content',
  1533. 'article_data.article_id',
  1534. 'article_extend.website_url',
  1535. 'article_extend.email',
  1536. 'article_extend.contacts',
  1537. 'article_extend.contacts_mobile',
  1538. 'article_extend.contacts_address',
  1539. 'article_extend.zip_code',
  1540. 'article_extend.enterprise_name'
  1541. )
  1542. ->first();
  1543. if (empty($result)) {
  1544. return Result::error("暂无此新闻!", 0);
  1545. }
  1546. if (!empty($result['publiced_at'])) {
  1547. $result['updated_at'] = $result['publiced_at'];
  1548. }
  1549. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1550. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1551. ->where('website_category.website_id', $data['website_id'])
  1552. ->where(['website_category.category_id' => $result['catid']])
  1553. ->first();
  1554. if (empty($category)) {
  1555. return Result::error("查询失败", 0);
  1556. }
  1557. //手动推荐文章
  1558. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1559. if (empty($commend_ids)) {
  1560. $commendArticle = [];
  1561. } else {
  1562. //去除不存在的文章ID
  1563. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1564. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1565. ->leftJoinSub(function ($query) use ($data) {
  1566. $query->from('article_ignore')
  1567. ->where('website_id', $data['website_id']);
  1568. }, 'article_ignore', function ($join) {
  1569. $join->on('article_ignore.article_id', '=', 'article.id');
  1570. })
  1571. ->where(function ($query) {
  1572. $query->whereNull('article_ignore.article_id')
  1573. ->orWhere(function ($subQuery) {
  1574. $subQuery->whereNotNull('article_ignore.article_id')
  1575. ->where('article_ignore.is_ignore', 0)
  1576. ->where(function ($subSubQuery) {
  1577. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1578. ->orWhereNull('article_ignore.c_show_time');
  1579. });
  1580. });
  1581. })
  1582. ->where('article.status', 1)
  1583. ->where('website_category.website_id', $data['website_id'])
  1584. ->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')
  1585. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1586. // ->orderBy('article.updated_at', 'desc')
  1587. ->limit(5)
  1588. ->get();
  1589. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1590. foreach ($commendArticle as $k => $v) {
  1591. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1592. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1593. $cat_arr_id = array_unique($cat_arr_id);
  1594. // 从website_category取出alias_pinyin
  1595. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1596. ->whereIn('category_id', $cat_arr_id)
  1597. ->pluck('alias_pinyin', 'category_id')
  1598. ->toArray();
  1599. // 将cat_arr_id的json转成路径/隔开
  1600. $path_parts = [];
  1601. foreach ($cat_arr_id as $cat_id) {
  1602. if (isset($cat_arr[$cat_id])) {
  1603. $path_parts[] = $cat_arr[$cat_id];
  1604. }
  1605. }
  1606. $v->alias_pinyin = implode('/', $path_parts);
  1607. } else {
  1608. $v->alias_pinyin = '';
  1609. }
  1610. }
  1611. }
  1612. $result['category_id'] = $category['category_id'];
  1613. $result['cat_name'] = $category['alias'];
  1614. $result['website_name'] = $category['website_name'] ?? "";
  1615. $result['suffix'] = $category['suffix'] ?? "";
  1616. $result['commendArticle'] = $commendArticle;
  1617. $result['commend_ids'] = $commend_ids;
  1618. return Result::success($result);
  1619. }
  1620. /**
  1621. * 前端-获取网站调查问卷
  1622. * @param array $data
  1623. * @return array
  1624. */
  1625. public function getWebsiteSurvey(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. }
  1633. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1634. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1635. if (empty($article)) {
  1636. return Result::error("暂无此文章", 0);
  1637. }
  1638. // return Result::error($data,0);
  1639. $where['art_id'] = $data['art_id'];
  1640. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1641. } else {
  1642. $survey = Article::where(function ($query) {
  1643. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1644. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1645. })
  1646. ->where('status', 1)
  1647. ->where('is_survey', 1)
  1648. ->select('survey_id')
  1649. ->orderBy('updated_at', 'desc')
  1650. ->first();
  1651. if (empty($survey)) {
  1652. return Result::error("暂无调查问卷", 0);
  1653. }
  1654. $where['sur_id'] = $survey['survey_id'];
  1655. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1656. }
  1657. // return Result::success($where);
  1658. $result = ArticleSurvey::where($where)
  1659. ->where(function ($query) {
  1660. $query->where('is_other', 0)
  1661. ->orWhere(function ($subQuery) {
  1662. $subQuery->where('is_other', 1)
  1663. ->where('other_id', 0);
  1664. });
  1665. })
  1666. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1667. ->select('article_survey.*', 'article.survey_type')
  1668. ->get()->all();
  1669. if (empty($result)) {
  1670. return Result::error("此文章暂无调查问卷", 0);
  1671. }
  1672. return Result::success($result);
  1673. }
  1674. /**
  1675. * 前端-添加网站调查问卷选项
  1676. * @param array $data
  1677. * @return array
  1678. */
  1679. public function addWebsiteSurveyOption(array $data): array
  1680. {
  1681. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1682. $website = Website::where('id', $data['website_id'])->first();
  1683. if (empty($website)) {
  1684. return Result::error("暂无此网站", 0);
  1685. }
  1686. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1687. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1688. if (empty($survey)) {
  1689. return Result::error("此调查问卷不可添加选项", 0);
  1690. }
  1691. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1692. $choice = [
  1693. 'art_id' => $survey['art_id'],
  1694. 'website_id' => $data['website_id'],
  1695. 'survey_name' => $survey['survey_name'],
  1696. 'choice_name' => $data['choice_name'],
  1697. 'sur_id' => $survey['sur_id'],
  1698. 'is_other' => 1,
  1699. 'other_id' => $survey['id'],
  1700. ];
  1701. $result = ArticleSurvey::insertGetId($choice);
  1702. if (empty($result)) {
  1703. return Result::error("添加失败", 0);
  1704. }
  1705. return Result::success($result);
  1706. }
  1707. }
  1708. return Result::error("添加失败", 0);
  1709. }
  1710. return Result::error("添加失败", 0);
  1711. }
  1712. /**
  1713. * 前端-调查问卷投票
  1714. * @param array $data
  1715. * @return array
  1716. */
  1717. public function addWebsiteSurveyVote(array $data): array
  1718. {
  1719. // return Result::success($data);
  1720. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1721. $website = Website::where('id', $data['website_id'])->first();
  1722. if (empty($website)) {
  1723. return Result::error("暂无此网站", 0);
  1724. }
  1725. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1726. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1727. // return Result::success($survey);
  1728. if (empty($is_survey)) {
  1729. return Result::error("此调查问卷不存在", 0);
  1730. }
  1731. // return Result::success($survey);
  1732. // 调查问卷类型
  1733. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1734. //多选 若是json型则转化成数组类型
  1735. if (strpos($data['choice_id'], '[') === 0) {
  1736. $data['choice_id'] = json_decode($data['choice_id'], true);
  1737. } else {
  1738. // 单选 也转换成数组
  1739. $data['choice_id'] = [$data['choice_id']];
  1740. }
  1741. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1742. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1743. // ->where('website_id',$data['website_id'])
  1744. ->where('is_other', 1)
  1745. ->where('other_id', 0)
  1746. ->first();
  1747. if (!empty($other)) {
  1748. return Result::error("请选择已有的选项!", 0);
  1749. }
  1750. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1751. // ->where('website_id',$data['website_id'])
  1752. ->where('is_other', 1)
  1753. ->where('other_id', '!=', 0)
  1754. ->first();
  1755. // return Result::success($choice['other']);
  1756. $choice_id = $data['choice_id'];
  1757. if (!empty($choice['other'])) {
  1758. // array_push($data['choice_id'],$choice['other']['other_id']);
  1759. if (!empty($choice_id)) {
  1760. $key = array_search($choice['other']['id'], $choice_id);
  1761. if ($key !== false) {
  1762. unset($choice_id[$key]);
  1763. $choice_id = array_values($choice_id);
  1764. }
  1765. array_push($choice_id, $choice['other']['other_id']);
  1766. } else {
  1767. $choice_id[0] = $choice['other']['other_id'];
  1768. }
  1769. array_push($data['choice_id'], $choice['other']['other_id']);
  1770. }
  1771. // return Result::success($data);
  1772. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1773. // ->where('website_id',$data['website_id'])
  1774. ->increment('results', 1);
  1775. if (empty($choice)) {
  1776. return Result::error("请选择已有的选项!", 0);
  1777. }
  1778. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1779. // ->where('website_id',$data['website_id'])
  1780. ->where('other_id', 0)
  1781. ->get();
  1782. $survey['choice'] = $choice_id;
  1783. return Result::success($survey);
  1784. }
  1785. return Result::error("参数必填!");
  1786. }
  1787. return Result::error("此调查问卷不存在", 0);
  1788. }
  1789. return Result::error("参数必填!");
  1790. }
  1791. /**
  1792. * 后端-获取网站调查问卷列表
  1793. * @param array $data
  1794. * @return array
  1795. */
  1796. public function getSurveyList(array $data): array
  1797. {
  1798. $where = [];
  1799. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1800. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1801. }
  1802. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1803. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1804. }
  1805. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1806. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1807. }
  1808. // return Result::success($where);
  1809. if (!empty($where)) {
  1810. $query = Article::where($where)->where(function ($q) {
  1811. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1812. });
  1813. } else {
  1814. $query = Article::where(function ($q) {
  1815. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1816. });
  1817. }
  1818. $count = $query->count();
  1819. $survey = $query->orderByDesc('id')
  1820. ->limit($data['pageSize'])
  1821. ->offset(($data['page'] - 1) * $data['pageSize'])
  1822. ->get();
  1823. if (empty($survey->toArray())) {
  1824. return Result::error("暂无调查问卷!", 0);
  1825. }
  1826. $result = [
  1827. 'rows' => $survey,
  1828. 'count' => $count,
  1829. ];
  1830. return Result::success($result);
  1831. }
  1832. /**
  1833. * 后端-获取网站调查问卷详情
  1834. * @param array $data
  1835. * @return array
  1836. */
  1837. public function getSurveyInfo(array $data): array
  1838. {
  1839. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1840. $where = ['sur_id' => $data['sur_id']];
  1841. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1842. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1843. ->select('article_survey.*', 'article.survey_type')
  1844. ->get()->all();
  1845. if (empty($choose)) {
  1846. return Result::error("此调查问卷不存在", 0);
  1847. }
  1848. $resultsArray = array_column($choose, 'results');
  1849. $total = array_sum($resultsArray);
  1850. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1851. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1852. // $total = 0;
  1853. if (!empty($other)) {
  1854. $total = $total + $other['results'];
  1855. $other['choice_name'] = '(其他)';
  1856. if (!empty($others)) {
  1857. $other['hasChildren'] = true;
  1858. // array_push($other,['hasChildren','=',true]);
  1859. $other['children'] = $others;
  1860. $other_choices = [$other->toArray()];
  1861. $mer_choice = array_merge($choose, $other_choices);
  1862. $value_choice = array_values($mer_choice);
  1863. } else {
  1864. // return Result::error('1111');
  1865. $other_choices = [$other->toArray()];
  1866. $other_choices = array_merge($choose, $other_choices);
  1867. $value_choice = array_values($other_choices);
  1868. // return Result::success($result);
  1869. }
  1870. } else {
  1871. $value_choice = $choose;
  1872. }
  1873. $result = [
  1874. 'choose' => $value_choice,
  1875. 'total' => $total,
  1876. ];
  1877. }
  1878. return Result::success($result);
  1879. }
  1880. /**
  1881. * 前端-搜索新闻列表
  1882. * @param array $data
  1883. * @return array
  1884. */
  1885. public function selectWebsiteArticle(array $data): array
  1886. {
  1887. $website = Website::where('id', $data['website_id'])->first();
  1888. if (empty($website)) {
  1889. return Result::error("网站不存在", 0);
  1890. }
  1891. // $website_column = $website['column'];
  1892. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1893. $website_column = json_decode($website['website_column_arr_id'], true);
  1894. }
  1895. $website_id = $data['website_id'];
  1896. $categorys = $this->processArticlePro($website_id);
  1897. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1898. // return Result::success($diff_pid_categoryIds);
  1899. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1900. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1901. }
  1902. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1903. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1904. $catiall = $categorys['catiall'];
  1905. $categoryIds = $categorys['categoryIds'];
  1906. // return Result::success($categoryIds);
  1907. $query = Article::where('status', 1)
  1908. ->whereIn('catid', $categoryIds)
  1909. ->leftJoinSub(function ($query) use ($website_id) {
  1910. $query->from('article_ignore')
  1911. ->where('website_id', $website_id);
  1912. }, 'article_ignore', function ($join) {
  1913. $join->on('article_ignore.article_id', '=', 'article.id');
  1914. })
  1915. ->where(function ($query) {
  1916. $query->whereNull('article_ignore.article_id')
  1917. ->orWhere(function ($subQuery) {
  1918. $subQuery->whereNotNull('article_ignore.article_id')
  1919. ->where('article_ignore.is_ignore', 0)
  1920. ->where(function ($subSubQuery) {
  1921. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1922. ->orWhereNull('article_ignore.c_show_time');
  1923. });
  1924. });
  1925. });
  1926. // ->get()->all();
  1927. // return Result::success($query);
  1928. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1929. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1930. }
  1931. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1932. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1933. }
  1934. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1935. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1936. }
  1937. // 计算总数
  1938. $count = $query->count();
  1939. // return Result::success($count);
  1940. // 分页查询
  1941. $articles = $query
  1942. ->select(
  1943. 'article.id',
  1944. 'article.title',
  1945. 'article.imgurl',
  1946. 'article.author',
  1947. 'article.updated_at',
  1948. 'article.introduce',
  1949. 'article.islink',
  1950. 'article.linkurl',
  1951. 'article.copyfrom',
  1952. 'article.cat_arr_id',
  1953. 'article.catid',
  1954. 'article.department_arr_id',
  1955. 'article.city_arr_id',
  1956. // 'article_ignore.c_show_time',
  1957. // 'article_ignore.is_ignore'
  1958. )
  1959. ->orderBy("updated_at", "desc")
  1960. ->offset(($data['page'] - 1) * $data['pageSize'])
  1961. ->limit($data['pageSize'])
  1962. ->get();
  1963. // return Result::success($articles);
  1964. foreach ($articles as $k => $v) {
  1965. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1966. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1967. }
  1968. if (empty($articles)) {
  1969. return Result::error("没有符合条件的资讯数据");
  1970. }
  1971. $result = [
  1972. 'rows' => $articles,
  1973. 'count' => $count,
  1974. ];
  1975. return Result::success($result);
  1976. }
  1977. /**
  1978. * 模块新闻加强版
  1979. * @param array $data
  1980. * @return array
  1981. */
  1982. public function getWebsiteCatidArticle(array $data): array
  1983. {
  1984. $where = [
  1985. 'website_category.category_id' => $data['catid'],
  1986. 'website_category.website_id' => $data['website_id'],
  1987. ];
  1988. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1989. $child_catnum = $data['child_catnum'] ?? 1;
  1990. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1991. $childCategoryIds = array_column($category['child'], 'category_id');
  1992. if (empty($childCategoryIds)) {
  1993. return Result::error("暂无子栏目", 0);
  1994. }
  1995. $imgArticles = [];
  1996. $textArticles = [];
  1997. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1998. // 初始化子分类图片新闻和文字新闻数组
  1999. // 查询所有子级栏目的图文新闻
  2000. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2001. ->where(function ($query) use ($data) {
  2002. $query->where(function ($subQuery) use ($data) {
  2003. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2004. })->orWhereNull("ignore_ids");
  2005. })
  2006. ->where('status', 1)
  2007. ->where('imgurl', '!=', '')
  2008. ->select('*')
  2009. ->orderBy('updated_at', 'desc')
  2010. ->limit($data['child_imgnum'])
  2011. ->get();
  2012. }
  2013. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2014. // 查询所有子级栏目的文字新闻
  2015. $textArticles = Article::where('catid', $childCategoryIds[0])
  2016. ->where('status', 1)
  2017. ->where(function ($query) use ($data) {
  2018. $query->where(function ($subQuery) use ($data) {
  2019. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2020. })->orWhereNull("ignore_ids");
  2021. })
  2022. ->select('*')
  2023. ->orderBy('updated_at', 'desc')
  2024. ->limit($data['child_textnum'])
  2025. ->get();
  2026. }
  2027. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2028. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2029. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2030. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2031. return $child;
  2032. }, $category['child']);
  2033. }
  2034. // }
  2035. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2036. $category['img'] = WebsiteCategory::where($where)
  2037. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2038. ->where('article.status', 1)
  2039. ->where('article.imgurl', '!=', '')
  2040. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2041. ->orderBy('article.updated_at', 'desc')
  2042. ->limit($data['img_num'])
  2043. ->get();
  2044. }
  2045. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2046. $category['text'] = WebsiteCategory::where($where)
  2047. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2048. ->where('article.status', 1)
  2049. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2050. ->orderBy('article.updated_at', 'desc')
  2051. ->limit($data['text_num'])
  2052. ->get();
  2053. }
  2054. // $category = $category->get();
  2055. if (empty($category)) {
  2056. return Result::error("查询失败", 0);
  2057. }
  2058. return Result::success($category);
  2059. }
  2060. /**
  2061. * 模块新闻加强plus版
  2062. * @param array $data
  2063. * @return array
  2064. */
  2065. public function getWebsiteAllArticle(array $data): array
  2066. {
  2067. // return Result::success($data);
  2068. $time1 = microtime(true);
  2069. $wetbsite_id = $data['website_id'] ?? 2;
  2070. $data = json_decode($data['id'], true);
  2071. $website = Website::where('id', $wetbsite_id)->first();
  2072. if (empty($website)) {
  2073. return Result::error("网站不存在", 0);
  2074. }
  2075. // return Result::success($website);
  2076. $website_column = $website['website_column_arr_id'] ?? '[]';
  2077. $website_column = json_decode($website_column, true);
  2078. $categorys = $this->processArticlePro($wetbsite_id);
  2079. $cat_1st_arr = $categorys['cat_1st_arr'];
  2080. $catiall = $categorys['catiall'];
  2081. // return Result::success($catiall);
  2082. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2083. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2084. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2085. }
  2086. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2087. // return Result::success($categorys);
  2088. $parent_category = array_column($data, 'parent');
  2089. $parent_cat = [];
  2090. $child_category = array_column($data, 'child');
  2091. if (!empty($parent_category)) {
  2092. foreach ($parent_category as $key => $value) {
  2093. $arr = array_map('intval', explode(',', $value));
  2094. $parent_cat[$key] = $arr[0] ?? 0;
  2095. $parent_category = $arr[0] ?? 0;
  2096. $article_imgnum = $arr[1] ?? 0;
  2097. $article_textnum = $arr[2] ?? 0;
  2098. if ($parent_category != 0) {
  2099. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2100. // return Result::success($category_arr);
  2101. if ($article_imgnum != 0) {
  2102. $img_article = Article::whereIn('catid', $category_arr)
  2103. ->where('status', 1)
  2104. ->where('imgurl', '!=', '')
  2105. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2106. $query->from('article_ignore')
  2107. ->where('website_id', $wetbsite_id);
  2108. }, 'article_ignore', function ($join) {
  2109. $join->on('article_ignore.article_id', '=', 'article.id');
  2110. })
  2111. ->where(function ($query) {
  2112. $query->whereNull('article_ignore.article_id')
  2113. ->orWhere(function ($subQuery) {
  2114. $subQuery->whereNotNull('article_ignore.article_id')
  2115. ->where('article_ignore.is_ignore', 0)
  2116. ->where(function ($subSubQuery) {
  2117. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2118. ->orWhereNull('article_ignore.c_show_time');
  2119. });
  2120. });
  2121. })
  2122. ->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')
  2123. ->orderBy('updated_at', 'desc')
  2124. ->limit($article_imgnum)
  2125. ->get()->all();
  2126. foreach ($img_article as $k => $v) {
  2127. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2128. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2129. }
  2130. } else {
  2131. $img_article = [];
  2132. }
  2133. if ($article_textnum != 0) {
  2134. $text_article = Article::whereIn('catid', $category_arr)
  2135. ->where('status', 1)
  2136. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2137. $query->from('article_ignore')
  2138. ->where('website_id', $wetbsite_id);
  2139. }, 'article_ignore', function ($join) {
  2140. $join->on('article_ignore.article_id', '=', 'article.id');
  2141. })
  2142. ->where(function ($query) {
  2143. $query->whereNull('article_ignore.article_id')
  2144. ->orWhere(function ($subQuery) {
  2145. $subQuery->whereNotNull('article_ignore.article_id')
  2146. ->where('article_ignore.is_ignore', 0)
  2147. ->where(function ($subSubQuery) {
  2148. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2149. ->orWhereNull('article_ignore.c_show_time');
  2150. });
  2151. });
  2152. })
  2153. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2154. ->orderBy('updated_at', 'desc')
  2155. ->limit($article_textnum)
  2156. ->get()->all();
  2157. foreach ($text_article as $k => $v) {
  2158. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2159. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2160. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2161. }
  2162. } else {
  2163. $text_article = [];
  2164. }
  2165. $catiall[$parent_category]['imgnum'] = $img_article;
  2166. $catiall[$parent_category]['textnum'] = $text_article;
  2167. $parent[$key] = $catiall[$parent_category];
  2168. } else {
  2169. $parent[$key] = '';
  2170. }
  2171. }
  2172. }
  2173. if (!empty($child_category)) {
  2174. foreach ($child_category as $key => $value) {
  2175. $arr = array_map('intval', explode(',', $value));
  2176. $parent_category = $parent_cat[$key];
  2177. $child_category = $arr[0] ?? 0;
  2178. $article_imgnum = $arr[1] ?? 0;
  2179. $article_textnum = $arr[2] ?? 0;
  2180. if ($child_category != 0) {
  2181. $all_childcat = $cat_1st_arr[$parent_category];
  2182. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2183. // 从 $websiteInfoIndexed 中获取对应的数据
  2184. $info = $websiteInfoIndexed[$v];
  2185. // 返回一个包含所需信息的数组
  2186. return [
  2187. 'alias' => $info->alias,
  2188. 'category_id' => $info->category_id,
  2189. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2190. 'pid' => $info->pid,
  2191. 'type' => $info->type,
  2192. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2193. 'pinyin' => $info->pinyin,
  2194. ];
  2195. }, $all_childcat);
  2196. if ($article_imgnum != 0) {
  2197. $img_article = Article::where('catid', $child_category)
  2198. ->where('status', 1)
  2199. ->where('imgurl', '!=', '')
  2200. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2201. $query->from('article_ignore')
  2202. ->where('website_id', $wetbsite_id);
  2203. }, 'article_ignore', function ($join) {
  2204. $join->on('article_ignore.article_id', '=', 'article.id');
  2205. })
  2206. ->where(function ($query) {
  2207. $query->whereNull('article_ignore.article_id')
  2208. ->orWhere(function ($subQuery) {
  2209. $subQuery->whereNotNull('article_ignore.article_id')
  2210. ->where('article_ignore.is_ignore', 0)
  2211. ->where(function ($subSubQuery) {
  2212. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2213. ->orWhereNull('article_ignore.c_show_time');
  2214. });
  2215. });
  2216. })
  2217. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2218. ->orderBy('updated_at', 'desc')
  2219. ->limit($article_imgnum)
  2220. ->get()->all();
  2221. foreach ($img_article as $k => $v) {
  2222. // var_dump($v);
  2223. // var_dump($k);
  2224. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2225. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2226. }
  2227. } else {
  2228. $img_article = [];
  2229. }
  2230. if ($article_textnum != 0) {
  2231. $text_article = Article::where('catid', $child_category)
  2232. ->where('status', 1)
  2233. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2234. $query->from('article_ignore')
  2235. ->where('website_id', $wetbsite_id);
  2236. }, 'article_ignore', function ($join) {
  2237. $join->on('article_ignore.article_id', '=', 'article.id');
  2238. })
  2239. ->where(function ($query) {
  2240. $query->whereNull('article_ignore.article_id')
  2241. ->orWhere(function ($subQuery) {
  2242. $subQuery->whereNotNull('article_ignore.article_id')
  2243. ->where('article_ignore.is_ignore', 0)
  2244. ->where(function ($subSubQuery) {
  2245. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2246. ->orWhereNull('article_ignore.c_show_time');
  2247. });
  2248. });
  2249. })
  2250. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2251. ->orderBy('updated_at', 'desc')
  2252. ->limit($article_textnum)
  2253. ->get()->all();
  2254. foreach ($text_article as $k => $v) {
  2255. // var_dump($v);
  2256. // var_dump($k);
  2257. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2258. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2259. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2260. }
  2261. } else {
  2262. $text_article = [];
  2263. }
  2264. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2265. $catiall[$child_category]['imgnum'] = $img_article;
  2266. $catiall[$child_category]['textnum'] = $text_article;
  2267. $child[$key] = $catiall[$child_category];
  2268. // var_dump($pids);
  2269. } else {
  2270. $child[$key] = '';
  2271. }
  2272. }
  2273. }
  2274. foreach ($parent as $key => $value) {
  2275. $result[$key] = $value;
  2276. if (!empty($child[$key])) {
  2277. // var_dump($child[$key]);
  2278. $result[$key]['child'] = $child[$key];
  2279. // $value[$key]['child'] = $child[$key];
  2280. } else {
  2281. $result[$key]['child'] = [
  2282. "alias" => null,
  2283. "category_id" => null,
  2284. "type" => null,
  2285. "pinyin" => null,
  2286. "all_childcat" => [],
  2287. "imgnum" => [],
  2288. "textnum" => []
  2289. ];
  2290. }
  2291. }
  2292. return Result::success($result);
  2293. }
  2294. /**
  2295. * 辅助方法:获取文章列表
  2296. */
  2297. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2298. {
  2299. sleep(1);
  2300. $query = Article::where('article.status', 1)
  2301. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2302. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2303. ->where(function ($query) use ($website) {
  2304. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2305. })
  2306. ->leftJoin('website_category', function ($join) use ($website) {
  2307. $join->on('article.catid', '=', 'website_category.category_id')
  2308. ->where('website_category.website_id', '=', $website['website_id']);
  2309. })
  2310. ->select(
  2311. 'article.id',
  2312. 'article.title',
  2313. 'article.imgurl',
  2314. 'article.author',
  2315. 'article.updated_at',
  2316. 'article.introduce',
  2317. 'article.islink',
  2318. 'article.linkurl',
  2319. 'article.copyfrom',
  2320. 'article.cat_arr_id',
  2321. 'article.catid',
  2322. 'website_category.alias as category_name'
  2323. )
  2324. ->orderBy('updated_at', 'desc')
  2325. ->limit($limit);
  2326. // 如果是图片文章,添加图片URL条件
  2327. if ($isImageArticle) {
  2328. $query->where('imgurl', '!=', '');
  2329. } else {
  2330. // 文字文章不需要imgurl字段
  2331. $query->addSelect('article.introduce');
  2332. }
  2333. $articles = $query->get();
  2334. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2335. }
  2336. /**
  2337. * 乡村网-获取特殊新闻模块
  2338. * @param array $data
  2339. * @return array
  2340. */
  2341. public function getWebsiteArticles(array $data): array
  2342. {
  2343. $website_id = $data['website_id'];
  2344. $website = Website::where('id', $website_id)->first();
  2345. if (empty($website)) {
  2346. return Result::error("网站不存在", 0);
  2347. }
  2348. // return Result::success($website);
  2349. $website_column = $website['website_column_arr_id'] ?? '[]';
  2350. $website_column = json_decode($website_column, true);
  2351. $catids = json_decode($data['id'], true);
  2352. $parent_category = array_column($catids, 'parent');
  2353. if (!empty($parent_category) && is_array($parent_category)) {
  2354. $categorys = $this->processArticlePro($website_id);
  2355. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2356. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2357. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2358. }
  2359. $catiall = $categorys['catiall'];
  2360. $cat_1st_arr = $categorys['cat_1st_arr'];
  2361. // return Result::success($categorys);
  2362. foreach ($parent_category as $key => $value) {
  2363. $arr = array_map('intval', explode(',', $value));
  2364. $parent_category = $arr[0] ?? 0;
  2365. $article_imgnum = $arr[1] ?? 0;
  2366. $article_textnum = $arr[2] ?? 0;
  2367. if ($parent_category != 0) {
  2368. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2369. // return Result::success($category_arr);
  2370. if ($article_imgnum != 0) {
  2371. $img_article = Article::whereIn('article.catid', $category_arr)
  2372. ->where('article.status', 1)
  2373. ->where('article.imgurl', '!=', '')
  2374. ->leftJoinSub(function ($query) use ($website_id) {
  2375. $query->from('article_ignore')
  2376. ->where('website_id', $website_id);
  2377. }, 'article_ignore', function ($join) {
  2378. $join->on('article_ignore.article_id', '=', 'article.id');
  2379. })
  2380. ->where(function ($query) {
  2381. $query->whereNull('article_ignore.article_id')
  2382. ->orWhere(function ($subQuery) {
  2383. $subQuery->whereNotNull('article_ignore.article_id')
  2384. ->where('article_ignore.is_ignore', 0)
  2385. ->where(function ($subSubQuery) {
  2386. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2387. ->orWhereNull('article_ignore.c_show_time');
  2388. });
  2389. });
  2390. })
  2391. ->select(
  2392. 'article.id',
  2393. 'article.title',
  2394. 'article.imgurl',
  2395. 'article.author',
  2396. 'article.updated_at',
  2397. 'article.introduce',
  2398. 'article.islink',
  2399. 'article.linkurl',
  2400. 'article.copyfrom',
  2401. 'article.cat_arr_id',
  2402. 'article.catid as category_id'
  2403. )
  2404. ->orderBy('updated_at', 'desc')
  2405. ->limit($article_imgnum)
  2406. ->get()->all();
  2407. foreach ($img_article as $k => $v) {
  2408. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2409. // return Result::success($v);
  2410. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2411. }
  2412. } else {
  2413. $img_article = [];
  2414. }
  2415. if ($article_textnum != 0) {
  2416. $text_article = Article::whereIn('article.catid', $category_arr)
  2417. ->where('article.status', 1)
  2418. ->leftJoinSub(function ($query) use ($website_id) {
  2419. $query->from('article_ignore')
  2420. ->where('website_id', $website_id);
  2421. }, 'article_ignore', function ($join) {
  2422. $join->on('article_ignore.article_id', '=', 'article.id');
  2423. })
  2424. ->where(function ($query) {
  2425. $query->whereNull('article_ignore.article_id')
  2426. ->orWhere(function ($subQuery) {
  2427. $subQuery->whereNotNull('article_ignore.article_id')
  2428. ->where('article_ignore.is_ignore', 0)
  2429. ->where(function ($subSubQuery) {
  2430. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2431. ->orWhereNull('article_ignore.c_show_time');
  2432. });
  2433. });
  2434. })
  2435. ->select(
  2436. 'article.id',
  2437. 'article.title',
  2438. 'article.author',
  2439. 'article.updated_at',
  2440. 'article.introduce',
  2441. 'article.islink',
  2442. 'article.linkurl',
  2443. 'article.copyfrom',
  2444. 'article.cat_arr_id',
  2445. 'article.catid as category_id'
  2446. )
  2447. ->orderBy('updated_at', 'desc')
  2448. ->limit($article_textnum)
  2449. ->get()->all();
  2450. foreach ($text_article as $k => $v) {
  2451. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2452. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2453. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2454. }
  2455. } else {
  2456. $text_article = [];
  2457. }
  2458. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2459. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2460. $parent[$key] = $catiall[$parent_category];
  2461. } else {
  2462. $parent[$key] = [];
  2463. }
  2464. }
  2465. }
  2466. return Result::success($parent);
  2467. }
  2468. // 封装处理商品的路由问题
  2469. function processGoods($goods, $data)
  2470. {
  2471. return $goods->map(function ($good) use ($data) {
  2472. $catid = $good->catid ?? 0;
  2473. // $pinyin = '';
  2474. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2475. if (!empty($category->pid) && $category->pid != 0) {
  2476. $level = json_decode($category->category_arr_id, true);
  2477. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2478. ->whereIn('category_id', $level)
  2479. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2480. ->get(['aLIas_pinyin'])
  2481. ->pluck('aLIas_pinyin')
  2482. ->implode('/');
  2483. } else {
  2484. $pinyin = $category->aLIas_pinyin ?? '';
  2485. }
  2486. if (isset($good->city_id) && !empty($good->city_id)) {
  2487. $city = District::where('id', $good->city_id)->first(['name']);
  2488. $good->city_name = $city->name ?? '';
  2489. }
  2490. // 解析imgurl JSON并取第一条数据
  2491. $imgUrls = json_decode($good->imgurl, true);
  2492. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2493. $good->pinyin = $pinyin;
  2494. return $good;
  2495. });
  2496. }
  2497. /**
  2498. * 获取商城首页-根据栏目id
  2499. * @param array $data
  2500. * @return array
  2501. * */
  2502. function getWebsiteCatidshop(array $data): array
  2503. {
  2504. $input['catid'] = $data['catid'];
  2505. $input['website_id'] = $data['website_id'];
  2506. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2507. $result = array_map(function ($item) use ($input) {
  2508. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2509. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2510. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2511. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2512. if (empty($category) || $category->type != 2) {
  2513. return Result::error("暂无此栏目", 0);
  2514. } else {
  2515. $website['website_id'] = $input['website_id'];
  2516. $goods = Good::where('good.status', 2)
  2517. ->where('good.website_id', $website['website_id'])
  2518. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2519. ->select(
  2520. 'good.id',
  2521. 'good.name',
  2522. 'good.imgurl',
  2523. 'good.description',
  2524. 'good.updated_at',
  2525. 'good.catid',
  2526. 'good.type_id',
  2527. 'good.price',
  2528. 'good.com',
  2529. 'good.level',
  2530. 'good.unit'
  2531. )
  2532. ->orderBy('updated_at', 'desc')
  2533. ->offset($goodStart)
  2534. ->limit($goodNum);
  2535. $all_goods = $goods->get();
  2536. $all_goods = $this->processGoods($all_goods, $website);
  2537. }
  2538. return $all_goods ?? [];
  2539. }
  2540. }, $data);
  2541. return Result::success($result);
  2542. }
  2543. /**
  2544. * 获取商品模块
  2545. * @param array $data
  2546. * @return array
  2547. * */
  2548. public function getWebsiteshop(array $data): array
  2549. {
  2550. $input['id'] = $data['id'];
  2551. $input['website_id'] = $data['website_id'];
  2552. $catid = $data['catid'];
  2553. $data = json_decode($input['id'] ?? '', true) ?? [];
  2554. $result['goods'] = array_map(function ($item) use ($input) {
  2555. // 检查parent元素是否存在且不是undefined
  2556. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2557. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2558. $website = $input['website_id'];
  2559. $query = Good::where('good.status', 2)
  2560. ->where('good.website_id', $website);
  2561. switch ($Levelid) {
  2562. case 1:
  2563. case 2:
  2564. case 3:
  2565. $goods = $query->where(function ($q) use ($Levelid) {
  2566. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2567. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2568. });
  2569. break;
  2570. case 4:
  2571. $goods = $query;
  2572. break;
  2573. case 5:
  2574. $goods = $query->where('type_id', 1);
  2575. break;
  2576. case 6:
  2577. $goods = $query->where('type_id', 2);
  2578. break;
  2579. default:
  2580. return [];
  2581. }
  2582. $all_goods = $goods
  2583. ->select(
  2584. 'good.id',
  2585. 'good.name',
  2586. 'good.imgurl',
  2587. 'good.description',
  2588. 'good.updated_at',
  2589. 'good.catid',
  2590. 'good.type_id',
  2591. 'good.price',
  2592. 'good.level',
  2593. 'good.website_id'
  2594. )
  2595. ->orderBy('updated_at', 'desc')
  2596. ->offset($goodStart)
  2597. ->limit($goodNum)
  2598. ->get();
  2599. $web['website_id'] = $website;
  2600. $all_goods = $this->processGoods($all_goods, $web);
  2601. }
  2602. return $all_goods;
  2603. }, $data);
  2604. $website = $input['website_id'];
  2605. $result['article'] = Article::where(function ($query) use ($website) {
  2606. $query->where(function ($subQuery) use ($website) {
  2607. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2608. })->orWhereNull("ignore_ids");
  2609. })
  2610. ->where('catid', $catid)
  2611. ->where('article.status', 1)
  2612. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2613. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2614. ->orderBy('article.updated_at', 'desc')
  2615. ->first();
  2616. return Result::success($result);
  2617. }
  2618. /**
  2619. * 获取商品分类
  2620. * @param array $data
  2621. * @return array
  2622. * */
  2623. public function getWebsiteshopCat(array $data): array
  2624. {
  2625. $website = $data['website_id'];
  2626. $category = WebsiteCategory::where('website_id', $website)
  2627. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2628. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2629. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2630. ->orderBy('sort')
  2631. ->get();
  2632. $cat = $category->map(function ($item) use ($website) {
  2633. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2634. $pid = $item->pid ?? 0;
  2635. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2636. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2637. ->where('website_id', $website)
  2638. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2639. ->get(['aLIas_pinyin'])
  2640. ->pluck('aLIas_pinyin')
  2641. ->implode('/');
  2642. } else {
  2643. $pinyin = $item->aLIas_pinyin ?? '';
  2644. }
  2645. $item->pinyin = $pinyin;
  2646. });
  2647. if (empty($category)) {
  2648. return Result::error("栏目查询失败", 0);
  2649. }
  2650. $cat_tree = Result::buildMenuTree($category);
  2651. $web['website_id'] = $website;
  2652. $goods = Good::where('website_id', $website)
  2653. ->where('status', 2)
  2654. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2655. ->latest('updated_at')
  2656. ->offset(($data['page'] - 1) * $data['pageSize'])
  2657. ->limit($data['pageSize'])
  2658. ->get();
  2659. if (!empty($goods)) {
  2660. if ($goods->count() > 1 && !empty($goods)) {
  2661. $goods = $this->processGoods($goods, $web);
  2662. }
  2663. } else {
  2664. $goods = [];
  2665. }
  2666. $result = [
  2667. 'category' => $cat_tree,
  2668. 'goods' => $goods,
  2669. ];
  2670. // $resul['goods'] = $goods;
  2671. if (empty($result)) {
  2672. return Result::error("查询失败", 0);
  2673. }
  2674. return Result::success($result);
  2675. }
  2676. /*
  2677. * 获取商品列表
  2678. * @param array $data
  2679. * @return array
  2680. * */
  2681. public function getWebsiteshopList(array $data): array
  2682. {
  2683. // return Result::success($data);
  2684. $where = [
  2685. 'status' => 2,
  2686. 'website_id' => $data['website_id'],
  2687. ];
  2688. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2689. // return Result::error("查询失败", 0);
  2690. // }
  2691. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2692. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2693. $data['catid'] = $category->category_id ?? 0;
  2694. }
  2695. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2696. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2697. }
  2698. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2699. array_push($where, ['type_id', $data['type_id']]);
  2700. }
  2701. $query = Good::where($where)
  2702. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2703. $query->where(function ($q) use ($data) {
  2704. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2705. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2706. });
  2707. })
  2708. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2709. $query->where(function ($q) use ($data) {
  2710. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2711. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2712. });
  2713. })
  2714. ->select(
  2715. 'good.id',
  2716. 'good.name',
  2717. 'good.imgurl',
  2718. 'good.description',
  2719. 'good.updated_at',
  2720. 'good.com',
  2721. 'good.catid',
  2722. 'good.type_id',
  2723. 'good.website_id',
  2724. 'good.cat_arr_id',
  2725. 'good.created_at',
  2726. 'good.city_id'
  2727. )
  2728. ->latest('updated_at');
  2729. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2730. $result['count'] = $query->clone()->count();
  2731. $result['goods'] = $this->processGoods(
  2732. $query->clone()
  2733. ->offset(($data['page'] - 1) * $data['pageSize'])
  2734. ->limit($data['pageSize'])
  2735. ->get(),
  2736. $data
  2737. );
  2738. } else {
  2739. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2740. // 获取 type_id 为 1 的数据
  2741. $result['type1'] = $this->processGoods(
  2742. $query->clone()
  2743. ->where('type_id', 1)
  2744. ->offset(($data['page'] - 1) * $data['pageSize'])
  2745. ->limit($data['pageSize'])
  2746. ->get(),
  2747. $data
  2748. );
  2749. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2750. // 获取 type_id 为 2 的数据
  2751. $result['type2'] = $this->processGoods(
  2752. $query->clone()
  2753. ->where('type_id', 2)
  2754. ->offset(($data['page'] - 1) * $data['pageSize'])
  2755. ->limit($data['pageSize'])
  2756. ->get(),
  2757. $data
  2758. );
  2759. }
  2760. if (empty($result)) {
  2761. return Result::error("查询失败", 0);
  2762. }
  2763. return Result::success($result);
  2764. }
  2765. /**
  2766. * 获取商品详情
  2767. * @param array $data
  2768. * @return array
  2769. * */
  2770. public function getWebsiteshopInfo(array $data): array
  2771. {
  2772. $where = [
  2773. 'good.status' => 2,
  2774. 'good.website_id' => $data['website_id'],
  2775. 'good.id' => $data['id'],
  2776. ];
  2777. $goods = Good::where($where)
  2778. ->where('good.id', $data['id'])
  2779. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2780. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2781. ->first();
  2782. if (empty($goods)) {
  2783. return Result::error("查询失败", 0);
  2784. }
  2785. $goods->imgurl = json_decode($goods->imgurl, true);
  2786. return Result::success($goods);
  2787. }
  2788. /**
  2789. * plus pro 处理文章路由问题
  2790. */
  2791. function processArticlePro($website_id)
  2792. {
  2793. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2794. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2795. // // 取出category_id 对应的aLIas_pinyin
  2796. // $categoryIds = array_column($categorys, 'category_id');
  2797. // $categoryPIds = array_column($categorys, 'pid');
  2798. // $aliasPinyins = array_column($categorys, 'path');
  2799. // $alias = array_column($categorys, 'alias');
  2800. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2801. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2802. // // return Result::success($cat_arr);
  2803. // // $catiall = [];
  2804. // //一级所有子级的记录
  2805. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2806. // return [
  2807. // 'cat_1st_arr' => $cat_alias_arr,
  2808. // 'catiall' => $cat_arr,
  2809. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2810. // 'categoryIds' => $categoryIds,
  2811. // ];
  2812. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2813. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2814. // 取出category_id 对应的aLIas_pinyin
  2815. $categoryIds = array_column($categorys, 'category_id');
  2816. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2817. return $pid != 0;
  2818. })));
  2819. $category_path = array_column($categorys, 'path');
  2820. $cat_arr = array_combine($categoryIds, $category_path);
  2821. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2822. $catiall = [];
  2823. //一级所有子级的记录
  2824. $cat_1st_arr = [];
  2825. foreach ($categorys as $key => $value) {
  2826. // $category_arr_id = json_decode($value->category_arr_id);
  2827. // $pinyin_str = '';
  2828. // // 算出一级 并且算出子级
  2829. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2830. $cat_1st_arr[$value->pid][] = $value->category_id;
  2831. }
  2832. // foreach ($category_arr_id as $k => $v) {
  2833. // $pinyin_str .= $cat_arr[$v] . '/';
  2834. // }
  2835. // $pinyin_str = rtrim($pinyin_str, '/');
  2836. $catiall[$value->category_id]['alias'] = $value->alias;
  2837. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2838. $catiall[$value->category_id]['type'] = $value->type;
  2839. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2840. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2841. }
  2842. return [
  2843. 'cat_1st_arr' => $cat_1st_arr,
  2844. 'catiall' => $catiall,
  2845. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2846. 'categoryIds' => $categoryIds,
  2847. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2848. 'categoryPIds' => $categoryPIds,
  2849. ];
  2850. }
  2851. /**
  2852. * 封装处理文章的路由问题
  2853. * */
  2854. function processArticles($articles, $data)
  2855. {
  2856. // 检查 $articles 是否为数组或可迭代对象
  2857. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2858. return $articles->map(function ($article) use ($data) {
  2859. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2860. $catid = $article->cat_arr_id ?? '';
  2861. }
  2862. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2863. $catid = $article->category_arr_id ?? '';
  2864. }
  2865. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2866. $level = json_decode($catid, true);
  2867. if (!is_array($level)) {
  2868. return $article;
  2869. } else {
  2870. $level = array_map('intval', $level);
  2871. }
  2872. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2873. ->where($data)
  2874. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2875. ->pluck('aLIas_pinyin')
  2876. ->implode('/');
  2877. $article->pinyin = $pinyin ?? '';
  2878. return $article;
  2879. });
  2880. } else {
  2881. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2882. $catid = $articles->cat_arr_id ?? '';
  2883. $level = json_decode($catid, true);
  2884. if (!is_array($level)) {
  2885. return $articles;
  2886. } else {
  2887. $level = array_map('intval', $level);
  2888. }
  2889. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2890. ->where($data)
  2891. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2892. ->pluck('aLIas_pinyin')
  2893. ->implode('/');
  2894. $articles->pinyin = $pinyin ?? '';
  2895. return $articles;
  2896. }
  2897. }
  2898. // 封装处理由问题
  2899. function processJob($job, $data)
  2900. {
  2901. return $job->map(function ($job) use ($data) {
  2902. $category = $job->cat_arr_id ?? '';
  2903. $cityid = $job->city_arr_id ?? '';
  2904. $city = json_decode($cityid, true);
  2905. $pinyin = '';
  2906. $level = json_decode($category, true);
  2907. // 路由
  2908. if (!empty($level) && is_array($level)) {
  2909. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2910. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2911. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2912. ->get(['aLIas_pinyin'])
  2913. ->pluck('aLIas_pinyin')
  2914. ->implode('/');
  2915. if (empty($pinyin)) {
  2916. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2917. }
  2918. $job->pinyin = $pinyin;
  2919. }
  2920. // 取职位-城市 市??省
  2921. if (!empty($city) && is_array($city)) {
  2922. if (isset($city[1]) && !empty($city[1])) {
  2923. $city = District::where('id', $city[1])->first(['name']);
  2924. $job->city_name = $city->name ?? '';
  2925. } else if (isset($city[0]) && !empty($city[0])) {
  2926. $city = District::where('id', $city[0])->first(['name']);
  2927. $job->city_name = $city->name ?? '';
  2928. } else {
  2929. $job->city_name = '全国';
  2930. }
  2931. }
  2932. // 获取简历最后一级地区
  2933. if (isset($job->city_id) && !empty($job->city_id)) {
  2934. $city = District::where('id', $job->city_id)->first(['name']);
  2935. $job->hunt_cityname = $city->name ?? '';
  2936. }
  2937. // 组合详细地址
  2938. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2939. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2940. if (is_array($address_id) && !empty($address_id)) {
  2941. $address = District::whereIn('id', $address_id)
  2942. ->orderBy('level', 'asc')
  2943. ->get(['name'])
  2944. ->pluck('name')
  2945. ->implode('');
  2946. // $job->address_name = $address ?? '';
  2947. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2948. }
  2949. }
  2950. // 取行业
  2951. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2952. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2953. if (!empty($job->industry)) {
  2954. $query->where('hyid', $job->industry);
  2955. } else if (!empty($job->hy_id)) {
  2956. $query->where('hyid', $job->hy_id);
  2957. } else if (!empty($job->company_hy_id)) {
  2958. $query->where('hyid', $job->company_hy_id);
  2959. } else {
  2960. $query->where('hyid', $job->job_industry);
  2961. }
  2962. })->first(['hyname']);
  2963. $job->hy_name = $hy_name->hyname ?? '';
  2964. }
  2965. // 取职位类别
  2966. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2967. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2968. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2969. $job->zw_name = $zw_name->zwname ?? '';
  2970. }
  2971. // 取具体职位
  2972. 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))) {
  2973. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2974. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2975. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2976. }
  2977. // 取工作经验
  2978. if (isset($job->experience) && !empty($job->experience)) {
  2979. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2980. $job->experience_name = $experience->ename ?? '';
  2981. }
  2982. // 取学历
  2983. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2984. $education = $job->educational ?? $job->school_education;
  2985. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2986. $job->education_name = $education->ename ?? '';
  2987. }
  2988. // 语言
  2989. if (isset($job->language) && !empty($job->language)) {
  2990. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2991. $job->language_name = $language->ename ?? '';
  2992. }
  2993. // 薪资
  2994. if (isset($job->salary) && !empty($job->salary)) {
  2995. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2996. $job->salary_name = $salary->ename ?? '';
  2997. }
  2998. // 职位性质
  2999. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3000. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3001. $job->job_nature_name = $job_nature->ename ?? '';
  3002. }
  3003. // 公司规模
  3004. if (isset($job->company_size) && !empty($job->company_size)) {
  3005. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3006. $job->company_size_name = $company_size->ename ?? '';
  3007. }
  3008. // 公司性质
  3009. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3010. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3011. $job->company_nature_name = $company_nature->nature_name ?? '';
  3012. }
  3013. // $job->pinyin = $pinyin;
  3014. return $job;
  3015. });
  3016. }
  3017. /**
  3018. * 获取书籍模块
  3019. * @param array $data
  3020. * @return array
  3021. * */
  3022. public function getWebsiteBook(array $data): array
  3023. {
  3024. $input['id'] = $data['id'];
  3025. $input['website_id'] = $data['website_id'];
  3026. // 将 JSON 字符串转换为 PHP 数组
  3027. $data = json_decode($input['id'], true);
  3028. // 使用 array_map 处理每个元素
  3029. $result = array_map(function ($item) use ($input) {
  3030. // 检查parent元素是否存在且不是undefined
  3031. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3032. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3033. $website = [
  3034. 'website_id' => $input['website_id'],
  3035. ];
  3036. // 查询栏目名称
  3037. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3038. if (empty($category)) {
  3039. $parent_alias = '';
  3040. $parent_pinyin = null;
  3041. $imgBooks = [];
  3042. $textBooks = [];
  3043. } else {
  3044. $parent_alias = $category->alias ?? '';
  3045. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3046. // 查找子分类ID数组
  3047. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3048. array_push($childCategoryIds, $parentCatId);
  3049. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3050. if ($parentImgNum != 0) {
  3051. // 查询图片新闻
  3052. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3053. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3054. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3055. })
  3056. ->where('book.status', 2)
  3057. ->where('book.img_url', '!=', '')
  3058. ->where('book.website_id', $website['website_id'])
  3059. ->leftJoin('website_category', function ($join) use ($website) {
  3060. $join->on('book.cat_id', '=', 'website_category.category_id')
  3061. ->where('website_category.website_id', '=', $website['website_id']);
  3062. })
  3063. ->select(
  3064. 'book.id',
  3065. 'book.title',
  3066. 'book.img_url',
  3067. 'book.price',
  3068. 'book.market_price',
  3069. 'book.description',
  3070. 'book.cat_id',
  3071. 'book.description',
  3072. 'book.updated_at',
  3073. 'website_category.alias as category_name',
  3074. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3075. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3076. )
  3077. ->orderBy('updated_at', 'desc')
  3078. ->limit($parentImgNum)
  3079. ->get()->all();
  3080. // 查询文字新闻
  3081. }
  3082. if ($parentTextNum != 0) {
  3083. $textBooks = [];
  3084. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3085. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3086. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3087. })
  3088. ->where('book.status', 2)
  3089. ->where('book.website_id', $website['website_id'])
  3090. ->leftJoin('website_category', function ($join) use ($website) {
  3091. $join->on('book.cat_id', '=', 'website_category.category_id')
  3092. ->where('website_category.website_id', '=', $website['website_id']);
  3093. })
  3094. ->select(
  3095. 'book.id',
  3096. 'book.title',
  3097. 'book.img_url',
  3098. 'book.price',
  3099. 'book.market_price',
  3100. 'book.description',
  3101. 'book.cat_id',
  3102. 'book.description',
  3103. 'book.updated_at',
  3104. 'website_category.alias as category_name',
  3105. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3106. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3107. )
  3108. ->orderBy('updated_at', 'desc')
  3109. ->limit($parentTextNum)
  3110. ->get()->all();
  3111. }
  3112. }
  3113. }
  3114. $resultItem = [
  3115. 'alias' => $parent_alias ?? '',
  3116. 'category_id' => $parentCatId ?? 0,
  3117. 'pinyin' => $parent_pinyin ?? null,
  3118. 'imgnum' => $imgBooks ?? [],
  3119. 'textnum' => $textBooks ?? [],
  3120. ];
  3121. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3122. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3123. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3124. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3125. ->get()->all();
  3126. if (!empty($childCategory)) {
  3127. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3128. // 查询子栏目名称
  3129. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3130. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3131. ->first();
  3132. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3133. $childImgArticles = [];
  3134. $childTextArticles = [];
  3135. $resultItem['child'] = [];
  3136. } else {
  3137. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3138. // 查询子栏目图片新闻
  3139. $childImgArticles = Book::where('cat_id', $childCatId)
  3140. ->where('status', 2)
  3141. ->where('img_url', '!=', '')
  3142. ->where('book.website_id', $website['website_id'])
  3143. ->leftJoin('website_category', function ($join) use ($website) {
  3144. $join->on('book.cat_id', '=', 'website_category.category_id')
  3145. ->where('website_category.website_id', '=', $website['website_id']);
  3146. })
  3147. ->select(
  3148. 'book.id',
  3149. 'book.title',
  3150. 'book.img_url',
  3151. 'book.price',
  3152. 'book.market_price',
  3153. 'book.description',
  3154. 'book.cat_id',
  3155. 'book.description',
  3156. 'book.updated_at',
  3157. DB::raw("'$child_pinyin' as pinyin")
  3158. )
  3159. ->orderBy('updated_at', 'desc')
  3160. ->limit($childImgNum)
  3161. ->get()->all();
  3162. // 查询子栏目文字新闻
  3163. $childTextArticles = Book::where('cat_id', $childCatId)
  3164. ->where('status', 2)
  3165. ->where('book.website_id', $website['website_id'])
  3166. ->leftJoin('website_category', function ($join) use ($website) {
  3167. $join->on('book.cat_id', '=', 'website_category.category_id')
  3168. ->where('website_category.website_id', '=', $website['website_id']);
  3169. })
  3170. ->select(
  3171. 'book.id',
  3172. 'book.title',
  3173. 'book.img_url',
  3174. 'book.price',
  3175. 'book.market_price',
  3176. 'book.description',
  3177. 'book.cat_id',
  3178. 'book.description',
  3179. 'book.updated_at',
  3180. DB::raw("'$child_pinyin' as pinyin")
  3181. )
  3182. ->orderBy('updated_at', 'desc')
  3183. ->limit($childTextNum)
  3184. ->get()->all();
  3185. $resultItem['child'] = [
  3186. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3187. 'category_id' => $childCatId,
  3188. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3189. 'all_childcat' => $childCategory,
  3190. 'imgnum' => $childImgArticles,
  3191. 'textnum' => $childTextArticles,
  3192. ];
  3193. }
  3194. }
  3195. } else {
  3196. $resultItem['child'] = [];
  3197. }
  3198. return $resultItem;
  3199. }, $data);
  3200. return Result::success($result);
  3201. }
  3202. /**
  3203. * 获取书刊列表
  3204. * @param array $data
  3205. * @return array
  3206. * */
  3207. public function getWebsiteBookList(array $data): array
  3208. {
  3209. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3210. if (empty($web)) {
  3211. return Result::error("查询失败", 0);
  3212. }
  3213. $catid = $data['id'];
  3214. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3215. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3216. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3217. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3218. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3219. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3220. ->where('pid', $category['pid'])
  3221. ->select(
  3222. 'category_id',
  3223. 'alias',
  3224. 'aLIas_pinyin',
  3225. 'pid',
  3226. 'sort',
  3227. 'is_url',
  3228. 'web_url',
  3229. 'seo_title',
  3230. 'seo_keywords',
  3231. 'seo_description',
  3232. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3233. )
  3234. ->orderBy('sort')
  3235. ->get()->all();
  3236. if (empty($category)) {
  3237. return Result::error("查询失败", 0);
  3238. }
  3239. $query = Book::where('book.status', 2)
  3240. ->where('book.website_id', $data['website_id'])
  3241. ->where('book.cat_id', $catid)
  3242. ->select(
  3243. 'book.id',
  3244. 'book.title',
  3245. 'book.img_url',
  3246. 'book.description',
  3247. 'book.updated_at',
  3248. 'book.cat_id',
  3249. DB::raw("'$pinyin' as pinyin")
  3250. )
  3251. ->orderBy('book.updated_at', 'desc');
  3252. $count = $query->count();
  3253. $query = clone $query;
  3254. $Book = $query
  3255. ->limit($data['pageSize'])
  3256. ->offset(($data['page'] - 1) * $data['pageSize'])
  3257. ->get()->all();
  3258. $result = [
  3259. 'category' => $categorys,
  3260. 'books' => $Book,
  3261. 'count' => $count,
  3262. ];
  3263. // if(empty($result)){
  3264. // return Result::error("查询失败", 0);
  3265. // }
  3266. return Result::success($result);
  3267. }
  3268. /**
  3269. * 获取书刊详情
  3270. * @param array $data
  3271. * @return array
  3272. * */
  3273. public function getWebsiteBookInfo(array $data): array
  3274. {
  3275. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3276. if (empty($web)) {
  3277. return Result::error("查询失败", 0);
  3278. }
  3279. $book = Book::where('status', 2)
  3280. ->where('website_id', $data['website_id'])
  3281. ->where('id', $data['id'])
  3282. ->select(
  3283. 'book.*',
  3284. )
  3285. ->orderBy('updated_at', 'desc')
  3286. ->first();
  3287. if (empty($book)) {
  3288. return Result::error("查询失败", 0);
  3289. }
  3290. // 先查询当前分类的 pid
  3291. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3292. ->where('category_id', $book['cat_id'])
  3293. ->first(['pid', 'category_id']);
  3294. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3295. if (!empty($carpid)) {
  3296. if ($carpid->pid != 0) {
  3297. $pid = $carpid['pid'];
  3298. // $parent_pinyin = '';
  3299. } else {
  3300. $pid = $carpid['category_id'];
  3301. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3302. }
  3303. }
  3304. $categorys = $query->where('pid', $pid)
  3305. ->select(
  3306. 'category_id',
  3307. 'alias',
  3308. 'aLIas_pinyin',
  3309. 'pid',
  3310. 'sort',
  3311. 'is_url',
  3312. 'web_url',
  3313. 'category_arr_id as cat_arr_id',
  3314. )
  3315. ->orderBy('sort')
  3316. ->get();
  3317. $category = $this->processArticle($categorys, $data);
  3318. $result = [
  3319. 'category' => $category,
  3320. 'books' => $book,
  3321. ];
  3322. return Result::success($result);
  3323. }
  3324. /**
  3325. * 尝试
  3326. * @param array $data
  3327. * @return array
  3328. * */
  3329. public function test(array $data): array
  3330. {
  3331. $input['id'] = $data['id'];
  3332. $input['website_id'] = $data['website_id'];
  3333. // 将 JSON 字符串转换为 PHP 数组
  3334. $data = json_decode($input['id'], true);
  3335. $result = [];
  3336. $article = $data;
  3337. $result = array_map(function ($item) use ($input) {
  3338. $website = [
  3339. 'website_id' => $input['website_id'],
  3340. ];
  3341. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3342. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3343. $parent = [
  3344. 0 => $category['category_id'] ?? [],
  3345. 1 => $parentImgNum ?? [],
  3346. 2 => $parentTextNum ?? [],
  3347. ];
  3348. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3349. $child = [];
  3350. $resultItem = [
  3351. // 'alias' => $parent_alias ?? '',
  3352. 'category_id' => $parentCatId ?? 0,
  3353. 'pinyin' => $parentImgNum ?? null,
  3354. 'imgnum' => $parentTextNum ?? [],
  3355. // 'textnum' => $textArticles ?? [],
  3356. ];
  3357. return $parent;
  3358. }, $data);
  3359. return Result::success($result);
  3360. // });
  3361. }
  3362. /**
  3363. * 封装处理文章的路由问题
  3364. * */
  3365. function processArticle($article, $data)
  3366. {
  3367. return $article->map(function ($article) use ($data) {
  3368. $catid = $article->cat_arr_id ?? '';
  3369. $level = json_decode($catid, true);
  3370. $pinyin = '';
  3371. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3372. if (!empty($level) && is_array($level)) {
  3373. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3374. ->where('website_id', $data['website_id'])
  3375. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3376. ->get(['aLIas_pinyin'])
  3377. ->pluck('aLIas_pinyin')
  3378. ->implode('/');
  3379. } else {
  3380. $pinyin = '';
  3381. }
  3382. $article->pinyin = $pinyin;
  3383. return $article;
  3384. });
  3385. }
  3386. /**
  3387. * c端-获取招工招聘下拉选框
  3388. * @param array $data
  3389. * @return array
  3390. * */
  3391. public function getWebsiteJobSelect(array $data): array
  3392. {
  3393. $web = Website::where('id', $data['website_id'])->first();
  3394. if (empty($web)) {
  3395. return Result::error("该网站不存在", 0);
  3396. }
  3397. $hy = JobIndustry::get()->all();
  3398. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3399. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3400. $result = [
  3401. 'hy' => $hy,
  3402. 'zw' => $zw,
  3403. 'jtzw' => $jtzw,
  3404. ];
  3405. if (empty($result)) {
  3406. return Result::error("查询失败", 0);
  3407. }
  3408. return Result::success($result);
  3409. }
  3410. /**
  3411. * c端-获取招工招聘
  3412. * @param array $data
  3413. * @return array
  3414. * */
  3415. public function getWebsiteJob(array $data): array
  3416. {
  3417. $web = Website::where('id', $data['website_id'])->first();
  3418. if (empty($web)) {
  3419. return Result::error("该网站不存在", 0);
  3420. }
  3421. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3422. ->where('job_hunting.website_id', $data['website_id'])
  3423. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3424. $query->where(function ($q) use ($data) {
  3425. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3426. });
  3427. })
  3428. ->select(
  3429. 'job_hunting.id',
  3430. 'job_hunting.catid',
  3431. 'job_hunting.cat_arr_id',
  3432. 'job_hunting.job_name_get',
  3433. 'job_hunting.industry',
  3434. 'job_hunting.name',
  3435. 'job_hunting.sexy',
  3436. 'job_hunting.origin',
  3437. 'job_hunting.city_arr_id',
  3438. 'job_hunting.experience',
  3439. 'job_hunting.updated_at',
  3440. 'job_hunting.salary',
  3441. 'job_hunting.skillList',
  3442. 'job_hunting.slelf_evaluation',
  3443. )
  3444. ->orderBy('updated_at', 'desc')
  3445. ->limit($data['job1_num'])
  3446. ->get();
  3447. $web['website_id'] = $data['website_id'];
  3448. if (empty($job_hunting)) {
  3449. $job_huntings = "未查询到相关简历信息";
  3450. } else {
  3451. $job_huntings = $this->processJob($job_hunting, $web);
  3452. }
  3453. // 0:待审核 1:已通过 2:已拒绝
  3454. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3455. ->where('job_recruiting.website_id', $data['website_id'])
  3456. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3457. $query->where(function ($q) use ($data) {
  3458. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3459. });
  3460. })
  3461. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3462. ->select(
  3463. 'job_recruiting.id',
  3464. 'job_recruiting.catid',
  3465. 'job_recruiting.cat_arr_id',
  3466. 'job_recruiting.title',
  3467. 'job_recruiting.jtzw_id',
  3468. 'job_recruiting.hy_id',
  3469. 'job_recruiting.city_arr_id',
  3470. 'job_recruiting.due_data',
  3471. 'job_recruiting.updated_at',
  3472. 'job_recruiting.experience',
  3473. 'job_recruiting.educational',
  3474. 'job_recruiting.salary',
  3475. 'job_recruiting.zw_id',
  3476. 'job_company.business_name',
  3477. 'job_recruiting.keyword',
  3478. 'job_recruiting.description',
  3479. )
  3480. ->orderBy('updated_at', 'desc')
  3481. ->limit($data['job2_num'])
  3482. ->get();
  3483. if (empty($job_recruiting->toArray())) {
  3484. $job_recruitings = "未查询到相关职位信息";
  3485. } else {
  3486. $job_recruitings = $this->processJob($job_recruiting, $web);
  3487. }
  3488. $result = [
  3489. 'job_hunting' => $job_huntings,
  3490. 'job_recuiting' => $job_recruitings,
  3491. ];
  3492. return Result::success($result);
  3493. }
  3494. /**
  3495. * c端-获取招工招聘列表
  3496. * @param array $data
  3497. * @return array
  3498. * */
  3499. public function getWebsiteJobList(array $data): array
  3500. {
  3501. $recruit_where = [];
  3502. $hunt_where = [];
  3503. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3504. if (empty($web)) {
  3505. return Result::error("此网站不存在", 0);
  3506. }
  3507. $website_id['website_id'] = $data['website_id'];
  3508. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3509. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3510. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3511. }
  3512. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3513. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3514. }
  3515. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3516. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3517. }
  3518. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3519. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3520. }
  3521. $query = JobRecruiting::where('job_recruiting.status', 1)
  3522. ->where('job_recruiting.website_id', $data['website_id'])
  3523. ->where($recruit_where)
  3524. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3525. $query->where(function ($q) use ($data) {
  3526. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3527. });
  3528. })
  3529. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3530. $query->where(function ($q) use ($data) {
  3531. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3532. });
  3533. })
  3534. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3535. ->select(
  3536. 'job_recruiting.id',
  3537. 'job_recruiting.catid',
  3538. 'job_recruiting.hy_id',
  3539. 'job_recruiting.title',
  3540. 'job_recruiting.zw_id',
  3541. 'job_recruiting.educational',
  3542. 'job_recruiting.jtzw_id',
  3543. 'job_recruiting.city_arr_id',
  3544. 'job_recruiting.due_data',
  3545. 'job_recruiting.experience',
  3546. 'job_recruiting.cat_arr_id',
  3547. 'job_recruiting.updated_at',
  3548. 'job_company.business_name',
  3549. 'job_recruiting.keyword',
  3550. 'job_recruiting.description',
  3551. )
  3552. ->orderBy('job_recruiting.updated_at', 'desc');
  3553. $recruit_count = $query->count();
  3554. $query = clone $query;
  3555. $JobRecruiting = $query
  3556. ->offset(($data['page'] - 1) * $data['pageSize'])
  3557. ->limit($data['pageSize'])
  3558. ->get();
  3559. if (empty($JobRecruiting)) {
  3560. $JobRecruiting = "暂无相关职位信息";
  3561. } else {
  3562. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3563. }
  3564. }
  3565. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3566. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3567. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3568. }
  3569. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3570. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3571. }
  3572. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3573. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3574. }
  3575. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3576. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3577. }
  3578. $query = JobHunting::where('job_hunting.status', 2)
  3579. ->where('job_hunting.website_id', $data['website_id'])
  3580. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3581. ->where($hunt_where)
  3582. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3583. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3584. // })
  3585. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3586. $query->where(function ($q) use ($data) {
  3587. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3588. });
  3589. })
  3590. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3591. $query->where(function ($q) use ($data) {
  3592. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3593. });
  3594. })
  3595. ->select(
  3596. 'job_hunting.id',
  3597. 'job_hunting.catid',
  3598. 'job_hunting.sexy',
  3599. 'job_hunting.experience',
  3600. 'job_hunting.origin',
  3601. 'job_hunting.industry',
  3602. 'job_hunting.name',
  3603. 'job_hunting.job',
  3604. 'job_hunting.job_name_get',
  3605. 'job_hunting.city_arr_id',
  3606. 'job_hunting.cat_arr_id',
  3607. 'job_hunting.created_at',
  3608. 'job_hunting.updated_at',
  3609. 'job_position.zwname as job_name',
  3610. 'job_hunting.skillList',
  3611. 'job_hunting.slelf_evaluation',
  3612. )
  3613. ->orderBy('job_hunting.updated_at', 'desc');
  3614. $hunt_count = $query->count();
  3615. $query = clone $query;
  3616. $JobHunting = $query
  3617. ->offset(($data['page'] - 1) * $data['pageSize'])
  3618. ->limit($data['pageSize'])
  3619. ->get();
  3620. if (empty($JobHunting)) {
  3621. $JobRecruiting = "暂无相关简历信息";
  3622. } else {
  3623. $JobHunting = $this->processJob($JobHunting, $website_id);
  3624. }
  3625. }
  3626. $result = [
  3627. 'JobRecruiting' => $JobRecruiting ?? [],
  3628. 'recruit_count' => $recruit_count ?? 0,
  3629. 'JobHunting' => $JobHunting ?? [],
  3630. 'hunt_count' => $hunt_count ?? 0,
  3631. ];
  3632. return Result::success($result);
  3633. }
  3634. /**
  3635. * c端-获取招工招聘详情
  3636. * @param array $data
  3637. * @return array
  3638. * */
  3639. public function getWebsiteJobInfo(array $data): array
  3640. {
  3641. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3642. if (empty($web)) {
  3643. return Result::error("该网站不存在", 0);
  3644. }
  3645. $webid = [
  3646. 'website_id' => $data['website_id'],
  3647. ];
  3648. // 职位相关信息
  3649. if ($data['type'] == 1) {
  3650. $query = JobRecruiting::where('status', 1)
  3651. ->where('website_id', $data['website_id'])
  3652. ->select('*');
  3653. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3654. $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();
  3655. if (!empty($company)) {
  3656. $result['company'] = $this->processJob($company, $webid);
  3657. }
  3658. $other_job = JobRecruiting::where('status', 1)
  3659. ->where('website_id', $data['website_id'])
  3660. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3661. ->where('id', '!=', $data['id'])
  3662. ->where('user_id', '=', $job[0]['user_id'])
  3663. ->limit($data['pageSize'])
  3664. ->get();
  3665. if (!empty($other_job)) {
  3666. $result['other_job'] = $this->processJob($other_job, $webid);
  3667. }
  3668. } else {
  3669. // 简历相关信息
  3670. $job = JobHunting::where('job_hunting.status', 2)
  3671. ->where('job_hunting.website_id', $data['website_id'])
  3672. ->where('job_hunting.id', $data['id'])
  3673. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3674. ->select('job_hunting.*', 'user_name')
  3675. ->get();
  3676. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3677. if (!empty($resume->toArray())) {
  3678. $result['resume'] = 1;
  3679. } else {
  3680. $result['resume'] = 0;
  3681. }
  3682. }
  3683. if (empty($job->toArray())) {
  3684. return Result::error("id参数错误", 0);
  3685. }
  3686. if (!empty($job[0]['job_experience'])) {
  3687. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3688. if (!empty($job_experience)) {
  3689. // $hy = [];
  3690. foreach ($job_experience as $key => $value) {
  3691. // $id = $value['id'];
  3692. $hy[$key] = $value['job_industry'];
  3693. $zw_id[$key] = $value['job_typename'];
  3694. $jtzw_id[$key] = $value['job_name'];
  3695. }
  3696. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3697. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3698. // 先将关联表转换为索引数组,提高查找效率
  3699. $hyLookup = [];
  3700. foreach ($hy_table as $item) {
  3701. $hyLookup[$item['hyid']] = $item['hyname'];
  3702. }
  3703. $zwLookup = [];
  3704. foreach ($zw_table as $item) {
  3705. $zwLookup[$item['zwid']] = $item['zwname'];
  3706. }
  3707. foreach ($job_experience as $key => &$value) {
  3708. // 处理行业名称
  3709. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3710. $value['hy_name'] = $hyLookup[$hy[$key]];
  3711. }
  3712. // 处理职位名称
  3713. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3714. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3715. }
  3716. // 处理具体职位名称
  3717. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3718. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3719. }
  3720. }
  3721. // 释放引用,防止意外修改后续代码
  3722. unset($value);
  3723. }
  3724. $result['job_experience'] = $job_experience ?? [];
  3725. }
  3726. if (!empty($job[0]['education_experience'])) {
  3727. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3728. if (!empty($education_experience)) {
  3729. foreach ($education_experience as $key => $value) {
  3730. // $id = $value['id'];
  3731. $education[$key] = $value['school_education'];
  3732. }
  3733. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3734. // // 先将关联表转换为索引数组,提高查找效率
  3735. $educationLookup = [];
  3736. foreach ($education_table as $item) {
  3737. $educationLookup[$item['evalue']] = $item['ename'];
  3738. }
  3739. foreach ($education_experience as $key => &$value) {
  3740. // 处理学历名称
  3741. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3742. $value['education_name'] = $educationLookup[$education[$key]];
  3743. }
  3744. }
  3745. }
  3746. $result['education_experience'] = $job_experience ?? [];
  3747. }
  3748. $result['job'] = $this->processJob($job, $webid);
  3749. // // 返现对应的栏目
  3750. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3751. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3752. ->whereIn('category_id', $catid)
  3753. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3754. ->orderBy('pid')->get()->all();
  3755. if (!empty($category)) {
  3756. $result['category'] = $category;
  3757. }
  3758. $result['job'] = $job;
  3759. $result['job_experience'] = $job_experience ?? [];
  3760. $result['education_experience'] = $education_experience ?? [];
  3761. if (empty($result)) {
  3762. return Result::error("参数错误", 0);
  3763. }
  3764. return Result::success($result);
  3765. }
  3766. /**
  3767. * c端-申请职位
  3768. * @param array $data
  3769. * @return array
  3770. * */
  3771. public function getWebsiteJobApply(array $data): array
  3772. {
  3773. // 首先验证网站是否存在
  3774. // return Result::success($data);
  3775. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3776. if (empty($web)) {
  3777. return Result::error("该网站不存在", 0);
  3778. }
  3779. // 验证用户是否存在且为个人会员/管理员
  3780. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3781. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3782. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3783. return Result::error("用户不存在", 0);
  3784. }
  3785. // 去除重复元素和空元素,并保持原始顺序
  3786. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3787. return !empty($value);
  3788. }));
  3789. // 验证职位是否存在 1:审核通过
  3790. $recruiting = JobRecruiting::where('status', 1)
  3791. ->where('website_id', $data['website_id'])
  3792. ->whereIn('id', $data['recruit_id'])
  3793. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3794. if (empty($recruiting)) {
  3795. return Result::error("该职位不存在", 0);
  3796. }
  3797. // 简历是否存在
  3798. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3799. if (empty($hunt_id)) {
  3800. return Result::error("该简历不存在", 0);
  3801. }
  3802. $data['hunt_id'] = $hunt_id['hunt_id'];
  3803. // // 验证是否已投递过该职位
  3804. $apply = JobApply::where('user_id', $data['user_id'])
  3805. ->where('hunt_id', $data['hunt_id'])
  3806. ->where('website_id', $data['website_id'])
  3807. ->whereIn('recruit_id', $data['recruit_id'])
  3808. ->get(['recruit_id']);
  3809. if (!empty($apply->toArray())) {
  3810. return Result::error("您已投递过该职位!");
  3811. }
  3812. $insertData = array_map(function ($recruiting) use ($data) {
  3813. return [
  3814. 'user_id' => $data['user_id'],
  3815. 'hunt_id' => $data['hunt_id'],
  3816. 'website_id' => $data['website_id'],
  3817. 'recruit_id' => $recruiting['recruit_id'],
  3818. 'receiver_id' => $recruiting['receiver_id'],
  3819. 'status' => 1,
  3820. ];
  3821. }, $recruiting);
  3822. // 批量插入数据
  3823. $result = JobApply::insert($insertData);
  3824. if (empty($result)) {
  3825. return Result::error("投递失败", 0);
  3826. }
  3827. return Result::success($result);
  3828. }
  3829. /**
  3830. * 招工招聘-沟通简历
  3831. * @param array $data
  3832. * @return array
  3833. * */
  3834. public function getWebsiteJobResume(array $data): array
  3835. {
  3836. // 首先验证网站是否存在
  3837. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3838. if (empty($web)) {
  3839. return Result::error("该网站不存在", 0);
  3840. }
  3841. // return Result::success($data);
  3842. // 验证用户是否存在且为企业会员/管理员
  3843. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3844. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3845. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3846. return Result::error("用户不存在", 0);
  3847. }
  3848. // 去除重复元素和空元素,并保持原始顺序
  3849. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3850. return !empty($value);
  3851. }));
  3852. // 验证简历是否存在
  3853. $hunting = JobHunting::where('status', 2)
  3854. ->where('website_id', $data['website_id'])
  3855. ->whereIn('id', $data['hunt_id'])
  3856. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3857. if (empty($hunting)) {
  3858. return Result::error("该简历不存在", 0);
  3859. }
  3860. // 验证是否已沟通过该简历
  3861. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3862. ->where('recruit_id', $data['recruit_id'])
  3863. ->where('website_id', $data['website_id'])
  3864. ->whereIn('hunt_id', $data['hunt_id'])
  3865. ->get(['hunt_id']);
  3866. if (!empty($remuse->toArray())) {
  3867. return Result::error("您已沟通过该简历!");
  3868. }
  3869. // 准备要插入的数据数组
  3870. $insertData = array_map(function ($hunting) use ($data) {
  3871. return [
  3872. 'user_id' => $data['user_id'],
  3873. 'recruit_id' => $data['recruit_id'],
  3874. 'website_id' => $data['website_id'],
  3875. 'hunt_id' => $hunting['hunt_id'],
  3876. 'receiver_id' => $hunting['receiver_id'],
  3877. 'status' => 1,
  3878. ];
  3879. }, $hunting);
  3880. // 批量插入数据
  3881. $result = JobRemuse::insert($insertData);
  3882. if (empty($result)) {
  3883. return Result::error("沟通失败", 0);
  3884. }
  3885. return Result::success($result);
  3886. }
  3887. /**
  3888. * 招工招聘 -我的职位(企业会员)
  3889. * @param array $data
  3890. * @return array
  3891. */
  3892. public function getWebsiteJobRecruiting(array $data): array
  3893. {
  3894. $web = Website::where('id', $data['website_id'])->first('id');
  3895. if (empty($web)) {
  3896. return Result::error("该网站不存在", 0);
  3897. }
  3898. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3899. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3900. return Result::error("用户暂无权限!", 0);
  3901. }
  3902. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3903. $result = JobRecruiting::where('website_id', $data['website_id'])
  3904. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3905. $query->where('user_id', $user['id']);
  3906. })
  3907. ->where('status', 1)
  3908. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3909. ->orderBy('updated_at', 'desc')
  3910. ->limit($data['pageSize'])
  3911. ->get();
  3912. if (empty($result)) {
  3913. return Result::error("暂无相关职位信息", 0);
  3914. }
  3915. return Result::success($result);
  3916. }
  3917. /**
  3918. * c端 - 验证路由
  3919. * @param array $data
  3920. * @return array
  3921. */
  3922. /**
  3923. * c端 - 验证路由
  3924. * @param array $data
  3925. * @return array
  3926. */
  3927. public function checkWebsiteRoute(array $data): array
  3928. {
  3929. // 测试001111111222
  3930. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3931. if (empty($web)) {
  3932. return Result::error("该网站不存在", 0);
  3933. } elseif ($web['status'] != 1) {
  3934. return Result::error("网站已经关闭", 0);
  3935. }
  3936. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3937. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3938. // 验证路由是否存在
  3939. if (empty($whiteRouterInfo)) {
  3940. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3941. }
  3942. if (!empty($whiteRouterInfo)) {
  3943. return Result::success($whiteRouterInfo->toArray());
  3944. }
  3945. }
  3946. // 验证栏目路由
  3947. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3948. ->where('path', $data['all_route'])
  3949. ->get()->all();
  3950. if (count($last_category) == 0) {
  3951. return Result::error("该栏目不存在", 0);
  3952. }
  3953. if (count($last_category) > 1) {
  3954. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3955. }
  3956. if (count($last_category) == 1) {
  3957. $last_category = $last_category[0];
  3958. }
  3959. // return Result::success($last_category);
  3960. if (isset($data['id']) && !empty($data['id'])) {
  3961. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3962. switch ($last_category['type']) {
  3963. case 1:
  3964. // 文章
  3965. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3966. $article = Article::where('status', 1)
  3967. ->where('id', $data['id'])
  3968. ->where(function ($query) use ($data) {
  3969. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3970. ->orWhereNull("ignore_ids");
  3971. })
  3972. ->first(['catid']);
  3973. if (empty($article)) {
  3974. return Result::error("该文章不存在", 0);
  3975. }
  3976. // return Result::success($article);
  3977. break;
  3978. case 2:
  3979. // 商品
  3980. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3981. $article = Good::where('website_id', $data['website_id'])
  3982. ->where('status', 2)
  3983. ->where('id', $data['id'])
  3984. ->first(['cat_arr_id']);
  3985. if (empty($article)) {
  3986. return Result::error("该商品不存在", 0);
  3987. }
  3988. break;
  3989. case 3:
  3990. // 书刊信息
  3991. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3992. $article = Book::where('website_id', $data['website_id'])
  3993. ->where('status', 2)
  3994. ->where('id', $data['id'])
  3995. ->first(['id', 'cat_arr_id']);
  3996. if (empty($article)) {
  3997. return Result::error("该书刊不存在", 0);
  3998. }
  3999. break;
  4000. case 4:
  4001. // 招聘
  4002. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4003. $article = JobRecruiting::where('website_id', $data['website_id'])
  4004. ->where('status', 1)
  4005. ->where('id', $data['id'])
  4006. ->first(['cat_arr_id']);
  4007. if (empty($article)) {
  4008. return Result::error("该招聘不存在", 0);
  4009. }
  4010. break;
  4011. case 5:
  4012. // 求职
  4013. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4014. $article = JobHunting::where('website_id', $data['website_id'])
  4015. ->where('status', 2)
  4016. ->where('id', $data['id'])
  4017. ->first(['cat_arr_id']);
  4018. if (empty($article)) {
  4019. return Result::error("该求职不存在", 0);
  4020. }
  4021. break;
  4022. case 6:
  4023. // 企业
  4024. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4025. $article = Company::
  4026. // where('website_id', $data['website_id'])
  4027. // ->
  4028. where('status', 1)
  4029. ->where('id', $data['id'])
  4030. ->first(['cat_arr_id']);
  4031. if (empty($article)) {
  4032. return Result::error("该企业不存在", 0);
  4033. }
  4034. break;
  4035. case 7:
  4036. // 项目
  4037. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4038. $article = Project::where('website_id', $data['website_id'])
  4039. ->where('status', 1)
  4040. ->where('id', $data['id'])
  4041. ->first(['cat_arr_id']);
  4042. if (empty($article)) {
  4043. return Result::error("该项目不存在", 0);
  4044. }
  4045. break;
  4046. default:
  4047. return Result::error("该数据不存在", 0);
  4048. break;
  4049. }
  4050. // return Result::success($article);
  4051. // $catid =0 ;
  4052. if (!isset($article['cat_arr_id'])) {
  4053. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4054. } else {
  4055. $catidArray = json_decode($article['cat_arr_id'], true);
  4056. $catid = !empty($catidArray) ? end($catidArray) : null;
  4057. }
  4058. // return Result::success($catid);
  4059. // // return Result::success($article['cat_arr_id']);
  4060. if (empty($catid)) {
  4061. return Result::error("该栏目路径不存在", 0);
  4062. }
  4063. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4064. ->where('category_id', $catid)
  4065. ->first('path');
  4066. }
  4067. // else{
  4068. // // if ($last_category['pid'] != 0) {
  4069. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4070. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4071. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4072. // ->where('category_id',$catid)
  4073. // ->where('path',$data['all_route'])
  4074. // ->first('path');
  4075. // // } else {
  4076. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4077. // // }
  4078. // }
  4079. // return Result::success($path);
  4080. if (!empty($path) && $path['path'] != $data['all_route']) {
  4081. return Result::error('非法路径!');
  4082. } else {
  4083. return Result::success($last_category['path']);
  4084. }
  4085. }
  4086. /**
  4087. * 招工招聘 - 获取推荐职位
  4088. * @param array $data
  4089. * @return array
  4090. */
  4091. public function getWebsiteLevelJob(array $data): array
  4092. {
  4093. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4094. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4095. ->where('job_recruiting.status', 1)
  4096. ->where('job_level', $data['job_level'])
  4097. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4098. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4099. ->orderBy('job_recruiting.updated_at', 'desc')
  4100. ->limit($data['pageSize'])
  4101. ->get();
  4102. $web = ['website_id' => $data['website_id']];
  4103. if (!empty($job)) {
  4104. $result = $this->processJob($job, $web);
  4105. }
  4106. if (empty($result)) {
  4107. return Result::error("暂无相关职位信息", 0);
  4108. }
  4109. return Result::success($result);
  4110. }
  4111. /**
  4112. * 验证导航名称是否重复
  4113. * @return void
  4114. */
  4115. //20250226 产品列表
  4116. public function getGoodList(array $data): array
  4117. {
  4118. var_dump($data, '---------1-2--');
  4119. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4120. unset($data['user_type_id']);
  4121. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4122. $where = [];
  4123. if ($type_id != '10000') {
  4124. $where = [
  4125. 'good.user_id' => $user_id,
  4126. ];
  4127. }
  4128. //类型
  4129. if (isset($data['type_id']) && $data['type_id']) {
  4130. $where['good.type_id'] = $data['type_id'];
  4131. }
  4132. //名称
  4133. if (isset($data['name']) && $data['name']) {
  4134. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4135. }
  4136. //status
  4137. if (isset($data['status']) && $data['status'] != '') {
  4138. $where['good.status'] = $data['status'];
  4139. }
  4140. //status1
  4141. // if (isset($data['status1']) && $data['status1'] == 1) {
  4142. // $status1 = 1;
  4143. // }
  4144. $where1 = [];
  4145. //website_id
  4146. // if (isset($data['website_id']) && $data['website_id']) {
  4147. // $where1 = [
  4148. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4149. // ];
  4150. // }
  4151. // website_name
  4152. if (isset($data['website_name']) && $data['website_name']) {
  4153. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4154. }
  4155. // catid
  4156. if (isset($data['category_name']) && $data['category_name']) {
  4157. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4158. }
  4159. // $result = Good::where($where)
  4160. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4161. var_dump($where, '---------1---');
  4162. $result = Good::where($where)
  4163. ->when(!empty($where1), function ($query) use ($where1) {
  4164. return $query->where($where1);
  4165. })
  4166. //status 1待审核2已审核3已拒绝
  4167. ->when(isset($data['status1']), function ($query) {
  4168. return $query->whereIn('good.status', [1, 3]);
  4169. })
  4170. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4171. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4172. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4173. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4174. ->orderBy("updated_at", "desc")
  4175. ->limit($data['page_size'])
  4176. ->offset(($data['page'] - 1) * $data['page_size'])
  4177. ->get();
  4178. $count = Good::where($where)
  4179. ->when(!empty($where1), function ($query) use ($where1) {
  4180. return $query->where($where1);
  4181. })
  4182. //status 1待审核2已审核3已拒绝
  4183. ->when(isset($data['status1']), function ($query) {
  4184. return $query->whereIn('good.status', [1, 3]);
  4185. })
  4186. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4187. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4188. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4189. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4190. ->orderBy("updated_at", "desc")->count();
  4191. $data = [
  4192. 'rows' => $result->toArray(),
  4193. 'count' => $count,
  4194. ];
  4195. if (empty($result)) {
  4196. return Result::error("此栏目暂无相关产品", 0);
  4197. }
  4198. return Result::success($data);
  4199. }
  4200. public function getGoodInfo(array $data): array
  4201. {
  4202. $result = Good::where('id', $data['id'])->first();
  4203. if (empty($result)) {
  4204. return Result::error("此产品不存在", 0);
  4205. }
  4206. return Result::success($result);
  4207. }
  4208. public function addGood(array $data): array
  4209. {
  4210. // unset($data['city_arr_id']);
  4211. // unset($data['cat_arr_id']);
  4212. $data['city_id'] = end($data['city_arr_id']);
  4213. $data['catid'] = end($data['cat_arr_id']);
  4214. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4215. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4216. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4217. unset($data['imgUrl']); //大小写
  4218. if (isset($data['price']) && $data['price'] == '') {
  4219. $data['price'] = 0;
  4220. }
  4221. if ($data['imgurl'] == '') {
  4222. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4223. preg_match_all($reg, $data['detail'], $matches);
  4224. if (isset($matches[1][0])) {
  4225. //截取varchar240
  4226. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4227. }
  4228. }
  4229. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4230. //提取标题+内容中的关键词
  4231. $data['keyword'] = $data['name'];
  4232. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4233. Jieba::init(); // 初始化 jieba-php
  4234. Finalseg::init();
  4235. $segList = Jieba::cut($data['keyword']);
  4236. $segList1 = array_slice($segList, 0, 8);
  4237. $data['keyword'] = implode(',', $segList1);
  4238. }
  4239. if ($data['description'] == '') {
  4240. //提取内容中的描述
  4241. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4242. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4243. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4244. }
  4245. if ($data['status'] == 1) {
  4246. $this->sendMessage([
  4247. 'talk_type' => 200,
  4248. 'title' => $data['name'],
  4249. 'content' => '提交了审核',
  4250. 'messageType' => 3,
  4251. ]);
  4252. }
  4253. $result = Good::insert($data);
  4254. if (empty($result)) {
  4255. return Result::error("添加失败", 0);
  4256. }
  4257. return Result::success($result);
  4258. }
  4259. public function updateGood(array $data): array
  4260. {
  4261. $data['city_id'] = end($data['city_arr_id']);
  4262. $data['catid'] = end($data['cat_arr_id']);
  4263. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4264. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4265. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4266. //设置东八区
  4267. date_default_timezone_set('Asia/Shanghai');
  4268. $data['updated_at'] = date('Y-m-d H:i:s');
  4269. if (isset($data['price']) && $data['price'] == '') {
  4270. $data['price'] = 0;
  4271. }
  4272. if ($data['imgurl'] == '') {
  4273. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4274. preg_match_all($reg, $data['detail'], $matches);
  4275. if (isset($matches[1][0])) {
  4276. //截取varchar240
  4277. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4278. }
  4279. }
  4280. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4281. //提取标题+内容中的关键词
  4282. $data['keyword'] = $data['name'];
  4283. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4284. Jieba::init(); // 初始化 jieba-php
  4285. Finalseg::init();
  4286. $segList = Jieba::cut($data['keyword']);
  4287. $segList1 = array_slice($segList, 0, 8);
  4288. $data['keyword'] = implode(',', $segList1);
  4289. }
  4290. if ($data['description'] == '') {
  4291. //提取内容中的描述
  4292. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4293. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4294. }
  4295. if ($data['status'] == 1) {
  4296. $this->sendMessage([
  4297. 'talk_type' => 200,
  4298. 'title' => $data['name'],
  4299. 'content' => '提交了审核',
  4300. 'messageType' => 3,
  4301. ]);
  4302. }
  4303. $result = Good::where('id', $data['id'])->update($data);
  4304. if (empty($result)) {
  4305. return Result::error("更新失败", 0);
  4306. }
  4307. return Result::success($result);
  4308. }
  4309. public function delGood(array $data): array
  4310. {
  4311. $result = Good::where('id', $data['id'])->delete();
  4312. if (empty($result)) {
  4313. return Result::error("删除失败", 0);
  4314. }
  4315. return Result::success($result);
  4316. }
  4317. //20250226 产品列表
  4318. //20250306 求职信息
  4319. public function getJobHuntingList(array $data): array
  4320. {
  4321. $where = [];
  4322. if (isset($data['username']) && !empty($data['username'])) {
  4323. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4324. }
  4325. //status 1待审核2已审核3已拒绝
  4326. if (isset($data['status']) && $data['status'] != '') {
  4327. $where = [
  4328. 'job_hunting.status' => $data['status'],
  4329. ];
  4330. }
  4331. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4332. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4333. unset($data['type_id']);
  4334. if ($type_id != '10000') {
  4335. $where[] = ['job_hunting.user_id', '=', $user_id];
  4336. }
  4337. $result = JobHunting::where($where)
  4338. ->when(!empty($data['status1']), function ($query) use ($data) {
  4339. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4340. })
  4341. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4342. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4343. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4344. ->orderBy("updated_at", "desc")
  4345. ->limit($data['page_size'])
  4346. ->offset(($data['page'] - 1) * $data['page_size'])
  4347. ->get();
  4348. if (empty($result)) {
  4349. return Result::error("查询失败", 0);
  4350. }
  4351. $count = JobHunting::where($where)
  4352. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4353. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4354. ->count();
  4355. $data = [
  4356. 'rows' => $result->toArray(),
  4357. 'count' => $count,
  4358. ];
  4359. return Result::success($data);
  4360. }
  4361. public function getJobHuntingApply(array $data): array
  4362. {
  4363. var_dump($data, '-----------------test--------1-');
  4364. $where = [];
  4365. if (isset($data['username']) && !empty($data['username'])) {
  4366. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4367. }
  4368. if (isset($data['salary']) && !empty($data['salary'])) {
  4369. $where[] = [
  4370. 'job_hunting.salary',
  4371. '=',
  4372. $data['salary'],
  4373. ];
  4374. }
  4375. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4376. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4377. unset($data['type_id']);
  4378. if ($type_id != '10000') {
  4379. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4380. }
  4381. var_dump($where, '-----------------test---------');
  4382. $result = jobApply::where($where)
  4383. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4384. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4385. // })
  4386. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4387. ->where('job_enum.egroup', '=', 'income')
  4388. ->where('job_hunting.status', 2) //已审核
  4389. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4390. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4391. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4392. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4393. //职位----是申请职位
  4394. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4395. ->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')
  4396. ->orderBy("job_hunting.updated_at", "desc")
  4397. ->limit($data['page_size'])
  4398. ->offset(($data['page'] - 1) * $data['page_size'])
  4399. ->get();
  4400. if (empty($result)) {
  4401. return Result::error("查询失败", 0);
  4402. }
  4403. $count = jobApply::where($where)
  4404. ->where('job_enum.egroup', '=', 'income')
  4405. ->where('job_hunting.status', 2) //已审核
  4406. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4407. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4408. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4409. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4410. //职位----是申请职位
  4411. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4412. ->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')
  4413. ->count();
  4414. $data = [
  4415. 'rows' => $result->toArray(),
  4416. 'count' => $count,
  4417. ];
  4418. return Result::success($data);
  4419. }
  4420. public function addJobHunting(array $data): array
  4421. {
  4422. date_default_timezone_set('Asia/Shanghai');
  4423. unset($data['company_name']);
  4424. unset($data['job_industry']);
  4425. unset($data['job_name']);
  4426. unset($data['department']);
  4427. unset($data['job_timeList']);
  4428. unset($data['job_content']);
  4429. unset($data['job_typename']); //不知道这是啥,
  4430. $data['created_at'] = date('Y-m-d H:i:s');
  4431. $data['updated_at'] = date('Y-m-d H:i:s');
  4432. //根据用户 user_id 只能添加一次
  4433. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4434. if (!empty($result)) {
  4435. return Result::error("您已添加过求职信息", 0);
  4436. }
  4437. var_dump($result, '-----------------test---------');
  4438. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4439. if (is_string($data['city_arr_id'])) {
  4440. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4441. $cityArr = json_decode($data['city_arr_id'], true);
  4442. // 确保 $cityArr 是数组
  4443. if (is_array($cityArr)) {
  4444. $data['city_id'] = end($cityArr);
  4445. }
  4446. } else {
  4447. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4448. if (is_array($data['city_arr_id'])) {
  4449. $data['city_id'] = end($data['city_arr_id']);
  4450. }
  4451. }
  4452. }
  4453. // 处理求职所绑定栏目
  4454. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4455. if (is_string($data['cat_arr_id'])) {
  4456. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4457. // 先清理可能存在的无效 JSON 字符
  4458. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4459. $catArr = json_decode($cleanedCatArrStr, true);
  4460. // 检查 JSON 解码是否成功且结果是数组
  4461. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4462. $data['catid'] = end($catArr);
  4463. }
  4464. } else {
  4465. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4466. if (is_array($data['cat_arr_id'])) {
  4467. $data['catid'] = end($data['cat_arr_id']);
  4468. }
  4469. }
  4470. }
  4471. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4472. $this->sendMessage([
  4473. 'talk_type' => 600,
  4474. 'title' => $data['name'],
  4475. 'content' => '提交了审核',
  4476. 'messageType' => 11,
  4477. ]);
  4478. }
  4479. $result = JobHunting::create($data);
  4480. if (empty($result)) {
  4481. return Result::error("添加失败", 0);
  4482. }
  4483. return Result::success($result);
  4484. }
  4485. public function delJobHunting(array $data): array
  4486. {
  4487. $result = JobHunting::where('id', $data['id'])->delete();
  4488. if (empty($result)) {
  4489. return Result::error("删除失败", 0);
  4490. }
  4491. return Result::success($result);
  4492. }
  4493. public function updateJobHunting(array $data): array
  4494. {
  4495. //设置东八区
  4496. date_default_timezone_set('Asia/Shanghai');
  4497. unset($data['company_name']);
  4498. unset($data['job_industry']);
  4499. unset($data['job_name']);
  4500. unset($data['department']);
  4501. unset($data['job_timeList']);
  4502. unset($data['job_content']);
  4503. unset($data['job_typename']); //不知道这是啥,
  4504. $data['created_at'] = date('Y-m-d H:i:s');
  4505. $data['updated_at'] = date('Y-m-d H:i:s');
  4506. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4507. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4508. $cityArr = json_decode($data['city_arr_id'], true);
  4509. $data['city_id'] = end($cityArr);
  4510. } else {
  4511. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4512. $data['city_id'] = end($data['city_arr_id']);
  4513. }
  4514. // 处理求职所绑定栏目
  4515. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4516. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4517. $catArr = json_decode($data['cat_arr_id'], true);
  4518. $data['catid'] = end($catArr);
  4519. } else {
  4520. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4521. $data['catid'] = end($data['cat_arr_id']);
  4522. }
  4523. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4524. $this->sendMessage([
  4525. 'talk_type' => 600,
  4526. 'title' => $data['name'],
  4527. 'content' => '提交了审核',
  4528. 'messageType' => 11,
  4529. ]);
  4530. }
  4531. $result = JobHunting::where('id', $data['id'])->update($data);
  4532. if (empty($result)) {
  4533. return Result::error("更新失败", 0);
  4534. }
  4535. return Result::success($result);
  4536. }
  4537. public function getJobHuntingInfo(array $data): array
  4538. {
  4539. $result = JobHunting::where('id', $data['id'])->first();
  4540. if (empty($result)) {
  4541. return Result::error("查询失败", 0);
  4542. }
  4543. return Result::success($result);
  4544. }
  4545. public function getJobHuntingData(array $data): array
  4546. {
  4547. $jobEnum = JobEnum::get();
  4548. $jobIndustry = JobIndustry::get();
  4549. $jobNature = JobNature::get();
  4550. $jobPosition = JobPosition::get();
  4551. $data = [
  4552. 'jobEnum' => $jobEnum,
  4553. 'jobIndustry' => $jobIndustry,
  4554. 'jobNature' => $jobNature,
  4555. 'jobPosition' => $jobPosition,
  4556. ];
  4557. return Result::success($data);
  4558. }
  4559. public function delJobHuntingInfo(array $data): array
  4560. {
  4561. $result = JobHunting::where('id', $data['id'])->delete();
  4562. return Result::success();
  4563. }
  4564. //20250324 通知,公告,消息
  4565. public function delNotice(array $data): array
  4566. {
  4567. $result = Notice::where('id', $data['id'])->delete();
  4568. if ($result) {
  4569. return Result::success();
  4570. } else {
  4571. return Result::error("删除失败", 0);
  4572. }
  4573. }
  4574. public function getNoticeInfo(array $data): array
  4575. {
  4576. $result = Notice::where('id', $data['id'])->first();
  4577. // var_dump($result['re_user_ids'], '--------------------');
  4578. if (empty($result)) {
  4579. return Result::error("查询失败", 0);
  4580. }
  4581. return Result::success($result);
  4582. }
  4583. public function readNotice(array $data): array
  4584. {
  4585. $result = Notice::where('id', $data['id'])->first();
  4586. // var_dump($result['re_user_ids'], '--------------------');
  4587. if (empty($result)) {
  4588. return Result::error("查询失败", 0);
  4589. }
  4590. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4591. $re_user_ids = json_decode($result['re_user_ids'], true);
  4592. var_dump($re_user_ids, '--------------1---test---------');
  4593. var_dump($data, '--------------1---test---------');
  4594. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4595. //如果已经存在,就不再添加
  4596. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4597. $read_id = json_decode($result['read_id'], true);
  4598. if (!is_array($read_id)) {
  4599. $read_id = [];
  4600. }
  4601. if (!in_array($data['user_id'], $read_id)) {
  4602. $read_id[] = $data['user_id'];
  4603. $result['read_id'] = json_encode($read_id);
  4604. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4605. }
  4606. } else {
  4607. //如果不存在,就添加
  4608. $result['read_id'] = json_encode([$data['user_id']]);
  4609. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4610. }
  4611. }
  4612. return Result::success($result);
  4613. }
  4614. public function addNotice(array $data): array
  4615. {
  4616. date_default_timezone_set('Asia/Shanghai');
  4617. $data['created_at'] = date('Y-m-d H:i:s');
  4618. $data['updated_at'] = date('Y-m-d H:i:s');
  4619. $user_id = UserInfo::
  4620. //city_id不是null
  4621. whereNotNull('city_id')
  4622. ->whereNotNull('department_id')
  4623. ->where(function ($query) use ($data) {
  4624. $query->where(function ($subQuery) use ($data) {
  4625. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4626. });
  4627. })
  4628. ->where(function ($query) use ($data) {
  4629. $query->where(function ($subQuery) use ($data) {
  4630. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4631. });
  4632. })
  4633. ->pluck('user_id')->toArray();
  4634. $user_id = array_unique($user_id);
  4635. $chat_ids = $user_id;
  4636. $user_id = json_encode($user_id);
  4637. $data['re_user_ids'] = $user_id;
  4638. $this->sendMessage([
  4639. 'talk_type' => 700,
  4640. 'title' => $data['title'],
  4641. 'content' => '提交了审核',
  4642. 'messageType' => 5,
  4643. ]);
  4644. $result = Notice::insertGetId($data);
  4645. if (empty($result)) {
  4646. return Result::error("添加失败", 0);
  4647. }
  4648. return Result::success($result);
  4649. }
  4650. public function updateNotice(array $data): array
  4651. {
  4652. date_default_timezone_set('Asia/Shanghai');
  4653. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4654. $user_id = UserInfo::
  4655. //city_id不是null
  4656. whereNotNull('city_id')
  4657. ->whereNotNull('department_id')
  4658. ->where(function ($query) use ($data) {
  4659. $query->where(function ($subQuery) use ($data) {
  4660. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4661. });
  4662. })
  4663. ->where(function ($query) use ($data) {
  4664. $query->where(function ($subQuery) use ($data) {
  4665. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4666. });
  4667. })
  4668. ->pluck('user_id')->toArray();
  4669. $user_id = array_unique($user_id);
  4670. $user_id = json_encode($user_id);
  4671. $data['re_user_ids'] = $user_id;
  4672. $data['updated_at'] = date('Y-m-d H:i:s');
  4673. $this->sendMessage([
  4674. 'talk_type' => 700,
  4675. 'title' => $data['title'],
  4676. 'content' => '提交了审核',
  4677. 'messageType' => 5,
  4678. ]);
  4679. $result = Notice::where('id', $data['id'])->update($data);
  4680. return Result::success($result);
  4681. }
  4682. public function getNoticeList(array $data): array
  4683. {
  4684. $where = [];
  4685. //title
  4686. if (isset($data['title']) && !empty($data['title'])) {
  4687. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4688. }
  4689. //level
  4690. if (isset($data['level']) && !empty($data['level'])) {
  4691. $where[] = ['notice.level', '=', $data['level']];
  4692. }
  4693. //status
  4694. if (isset($data['status']) && !empty($data['status'])) {
  4695. $where[] = ['notice.status', '=', $data['status']];
  4696. }
  4697. //type
  4698. if (isset($data['type']) && !empty($data['type'])) {
  4699. $where[] = ['notice.type', '=', $data['type']];
  4700. }
  4701. var_dump($data, '------------11111-2----test---------');
  4702. if ($data['type_id'] == 10000) {
  4703. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4704. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4705. })
  4706. ->where($where)
  4707. ->orderBy('updated_at', 'desc')
  4708. ->limit($data['page_size'])
  4709. ->offset(($data['page'] - 1) * $data['page_size'])
  4710. ->get();
  4711. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4712. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4713. })
  4714. ->where($where)
  4715. ->orderBy('updated_at', 'desc')
  4716. ->count();
  4717. } else {
  4718. $result = Notice::where($where)
  4719. // ->where('user_id', $data['user_id'])
  4720. ->Where(function ($query) use ($data) {
  4721. $query->Where(function ($q) use ($data) {
  4722. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4723. ->orWhere('notice.user_id', $data['user_id']);
  4724. });
  4725. })
  4726. ->when(!empty($data['status1']), function ($query) use ($data) {
  4727. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4728. })
  4729. ->orderBy('updated_at', 'desc')
  4730. ->limit($data['page_size'])
  4731. ->offset(($data['page'] - 1) * $data['page_size'])
  4732. ->get();
  4733. $total = Notice::where($where)
  4734. ->when(!empty($data['status1']), function ($query) use ($data) {
  4735. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4736. })
  4737. // ->where('user_id', $data['user_id'])
  4738. ->Where(function ($query) use ($data) {
  4739. $query->Where(function ($q) use ($data) {
  4740. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4741. ->orWhere('notice.user_id', $data['user_id']);
  4742. });
  4743. })
  4744. ->count();
  4745. }
  4746. if (empty($result)) {
  4747. return Result::error("查询失败", 0);
  4748. }
  4749. $data = [
  4750. 'rows' => $result,
  4751. 'count' => $total,
  4752. ];
  4753. return Result::success($data);
  4754. }
  4755. public function noticeList(array $data): array
  4756. {
  4757. $where = [];
  4758. //title
  4759. if (isset($data['title']) && !empty($data['title'])) {
  4760. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4761. }
  4762. //level
  4763. if (isset($data['level']) && !empty($data['level'])) {
  4764. $where[] = ['notice.level', '=', $data['level']];
  4765. }
  4766. //status
  4767. if (isset($data['status']) && !empty($data['status'])) {
  4768. $where[] = ['notice.status', '=', $data['status']];
  4769. }
  4770. //type
  4771. if (isset($data['type']) && !empty($data['type'])) {
  4772. $where[] = ['notice.type', '=', $data['type']];
  4773. }
  4774. var_dump($data, '------------11111-2----test---------');
  4775. if ($data['type_id'] == 10000) {
  4776. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4777. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4778. })
  4779. ->where($where)
  4780. ->orderBy('updated_at', 'desc')
  4781. ->limit($data['page_size'])
  4782. ->offset(($data['page'] - 1) * $data['page_size'])
  4783. ->get();
  4784. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4785. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4786. })
  4787. ->where($where)
  4788. ->orderBy('updated_at', 'desc')
  4789. ->count();
  4790. } else {
  4791. $result = Notice::where($where)
  4792. // ->where('user_id', $data['user_id'])
  4793. ->Where(function ($query) use ($data) {
  4794. $query->Where(function ($q) use ($data) {
  4795. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4796. ->orWhere('notice.user_id', $data['user_id']);
  4797. });
  4798. })
  4799. ->when(!empty($data['status1']), function ($query) use ($data) {
  4800. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4801. })
  4802. ->orderBy('updated_at', 'desc')
  4803. ->limit($data['page_size'])
  4804. ->offset(($data['page'] - 1) * $data['page_size'])
  4805. ->get();
  4806. $total = Notice::where($where)
  4807. ->when(!empty($data['status1']), function ($query) use ($data) {
  4808. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4809. })
  4810. // ->where('user_id', $data['user_id'])
  4811. ->Where(function ($query) use ($data) {
  4812. $query->Where(function ($q) use ($data) {
  4813. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4814. ->orWhere('notice.user_id', $data['user_id']);
  4815. });
  4816. })
  4817. ->count();
  4818. }
  4819. if (empty($result)) {
  4820. return Result::error("查询失败", 0);
  4821. }
  4822. $data = [
  4823. 'rows' => $result,
  4824. 'count' => $total,
  4825. ];
  4826. return Result::success($data);
  4827. }
  4828. public function getNoticeDetail(array $data): array
  4829. {
  4830. $result = Notice::where('id', $data['id'])->first();
  4831. if (empty($result)) {
  4832. return Result::error("查询失败", 0);
  4833. }
  4834. return Result::success($result);
  4835. }
  4836. public function deleteNotice(array $data): array
  4837. {
  4838. $notice = Notice::where('id', $data['id'])->first();
  4839. if (empty($notice)) {
  4840. return Result::error("删除失败", 0);
  4841. }
  4842. $chat_group_id = $notice->group_id;
  4843. if ($chat_group_id) {
  4844. //删除群聊
  4845. ChatGroups::where('id', $chat_group_id)->delete();
  4846. //删除群成员
  4847. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4848. //删除群聊记录
  4849. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4850. }
  4851. $result = Notice::where('id', $data['id'])->delete();
  4852. return Result::success($result);
  4853. }
  4854. public function complaintList(array $data): array
  4855. {
  4856. var_dump($data, '---------1---------');
  4857. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4858. unset($data['type_id']);
  4859. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4860. $where = [];
  4861. if ($type_id != 10000 && empty($data['deal_user'])) {
  4862. // $where['complaint.user_id'] = $user_id;
  4863. }
  4864. if (!empty($data['title'])) {
  4865. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4866. }
  4867. if (!empty($data['department_id'])) {
  4868. $where['complaint.department_id'] = $data['department_id'];
  4869. }
  4870. if (!empty($data['deal'])) {
  4871. $where['complaint.deal'] = $data['deal'];
  4872. }
  4873. if (!empty($data['status'])) {
  4874. $where['complaint.status'] = $data['status'];
  4875. }
  4876. var_dump(!empty($data['deal_user']), '----------1');
  4877. var_dump($where, '----------2');
  4878. $result = Complaint::where($where)
  4879. ->when(!empty($data['status1']), function ($query) use ($data) {
  4880. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4881. })
  4882. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4883. //json re_user_ids data[user_id]是不是在里面
  4884. $query->Where(function ($q) use ($data) {
  4885. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4886. ->where('complaint.status', 2);
  4887. });
  4888. })
  4889. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4890. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4891. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4892. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4893. ->orderBy('updated_at', 'desc')
  4894. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4895. //sql输出
  4896. if (empty($result)) {
  4897. return Result::error("暂无投诉信息", 0);
  4898. }
  4899. // 取出数据
  4900. $rows = $result->items();
  4901. $count = $result->total();
  4902. $responseData = [
  4903. 'rows' => $rows,
  4904. 'count' => $count,
  4905. ];
  4906. return Result::success($responseData);
  4907. }
  4908. public function getComplaintList(array $data): array
  4909. {
  4910. var_dump($data, '00000001000000000000');
  4911. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4912. unset($data['type_id']);
  4913. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4914. $where = [];
  4915. if ($type_id != 10000 && empty($data['deal_user'])) {
  4916. $where['complaint.user_id'] = $user_id;
  4917. }
  4918. if (!empty($data['title'])) {
  4919. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4920. }
  4921. if (!empty($data['department_id'])) {
  4922. $where['complaint.department_id'] = $data['department_id'];
  4923. }
  4924. if (!empty($data['deal'])) {
  4925. $where['complaint.deal'] = $data['deal'];
  4926. }
  4927. if (!empty($data['status'])) {
  4928. $where['complaint.status'] = $data['status'];
  4929. }
  4930. var_dump(!empty($data['deal_user']), '----------1');
  4931. var_dump($where, '----------2');
  4932. $result = Complaint::where($where)
  4933. ->when(!empty($data['status1']), function ($query) use ($data) {
  4934. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4935. })
  4936. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4937. // //json re_user_ids data[user_id]是不是在里面
  4938. // $query->Where(function ($q) use ($data) {
  4939. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4940. // ->where('complaint.status', 2);
  4941. // });
  4942. // })
  4943. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4944. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4945. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4946. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4947. ->orderBy('updated_at', 'desc')
  4948. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4949. //sql输出
  4950. if (empty($result)) {
  4951. return Result::error("暂无投诉信息", 0);
  4952. }
  4953. // 取出数据
  4954. $rows = $result->items();
  4955. $count = $result->total();
  4956. $responseData = [
  4957. 'rows' => $rows,
  4958. 'count' => $count,
  4959. ];
  4960. return Result::success($responseData);
  4961. }
  4962. public function getComplaintInfo(array $data): array
  4963. {
  4964. $result = Complaint::where('id', $data['id'])->first();
  4965. if (empty($result)) {
  4966. return Result::error("查询失败", 0);
  4967. }
  4968. return Result::success($result);
  4969. }
  4970. public function readComplaint(array $data): array
  4971. {
  4972. $result = Complaint::where('id', $data['id'])->first();
  4973. if (empty($result)) {
  4974. return Result::error("查询失败", 0);
  4975. }
  4976. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4977. $re_user_ids = json_decode($result['re_user_ids'], true);
  4978. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4979. //如果已经存在,就不再添加
  4980. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4981. $read_id = json_decode($result['read_id'], true);
  4982. if (!is_array($read_id)) {
  4983. $read_id = [];
  4984. }
  4985. if (!in_array($data['user_id'], $read_id)) {
  4986. $read_id[] = $data['user_id'];
  4987. $result['read_id'] = json_encode($read_id);
  4988. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4989. }
  4990. } else {
  4991. //如果不存在,就添加
  4992. $result['read_id'] = json_encode([$data['user_id']]);
  4993. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4994. }
  4995. }
  4996. return Result::success($result);
  4997. }
  4998. public function addComplaint(array $data): array
  4999. {
  5000. date_default_timezone_set('Asia/Shanghai');
  5001. $data['created_at'] = date('Y-m-d H:i:s');
  5002. $data['updated_at'] = date('Y-m-d H:i:s');
  5003. $this->sendMessage([
  5004. 'talk_type' => 800,
  5005. 'title' => $data['title'],
  5006. 'content' => '提交了审核',
  5007. 'messageType' => 6,
  5008. ]);
  5009. $result = Complaint::create($data);
  5010. return Result::success($result);
  5011. }
  5012. public function updateComplaint(array $data): array
  5013. {
  5014. date_default_timezone_set('Asia/Shanghai');
  5015. $data['updated_at'] = date('Y-m-d H:i:s');
  5016. $user_id = $data['user_id'] ?? 0;
  5017. $type_id = $data['type_id'] ?? 0;
  5018. unset($data['user_id']);
  5019. unset($data['type_id']);
  5020. $this->sendMessage([
  5021. 'talk_type' => 800,
  5022. 'title' => $data['title'],
  5023. 'content' => '提交了审核',
  5024. 'messageType' => 6,
  5025. ]);
  5026. $result = Complaint::where('id', $data['id'])->update($data);
  5027. return Result::success($result);
  5028. }
  5029. public function deleteComplaint(array $data): array
  5030. {
  5031. $result = Complaint::where('id', $data['id'])->delete();
  5032. return Result::success($result);
  5033. }
  5034. public function getComplainInfo(array $data): array
  5035. {
  5036. $result = Complaint::where('id', $data['id'])->first();
  5037. if (empty($result)) {
  5038. return Result::error("查询失败", 0);
  5039. }
  5040. return Result::success($result);
  5041. }
  5042. public function updateComplaintStatus(array $data): array
  5043. {
  5044. date_default_timezone_set('Asia/Shanghai');
  5045. $data['updated_at'] = date('Y-m-d H:i:s');
  5046. $user_id = $data['user_id'] ?? 0;
  5047. $type_id = $data['type_id'] ?? 0;
  5048. unset($data['user_id']);
  5049. unset($data['type_id']);
  5050. //处理, 写入处理人
  5051. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5052. $data['real_deal_user'] = $user_id;
  5053. }
  5054. //如果是deal 23,则判断是不是处理人
  5055. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5056. $complaintInof = Complaint::where('id', $data['id'])
  5057. ->where('real_deal_user', $user_id)
  5058. ->first();
  5059. if (empty($complaintInof)) {
  5060. return Result::error("处理人错误", 0);
  5061. }
  5062. }
  5063. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5064. if ($data['status'] == 1) {
  5065. $this->sendMessage([
  5066. 'talk_type' => 800,
  5067. 'title' => $complaintInfo['title'],
  5068. 'content' => '提交了审核',
  5069. 'messageType' => 6,
  5070. ]);
  5071. }
  5072. if ($data['status'] == 2 && !isset($data['deal'])) {
  5073. $this->sendMessage([
  5074. 'talk_type' => 801,
  5075. 'title' => $complaintInfo['title'],
  5076. 'content' => '审核通过',
  5077. 'messageType' => 6,
  5078. 'user_id' => $complaintInfo['user_id'],
  5079. ]);
  5080. $this->sendMessage([
  5081. 'talk_type' => 802,
  5082. 'title' => $complaintInfo['title'],
  5083. 'content' => '待处理',
  5084. 'messageType' => 6,
  5085. 'user_id' => $complaintInfo['re_user_ids'],
  5086. ]);
  5087. }
  5088. if ($data['status'] == 3 && !isset($data['deal'])) {
  5089. $this->sendMessage([
  5090. 'talk_type' => 801,
  5091. 'title' => $complaintInfo['title'],
  5092. 'content' => '审核拒绝',
  5093. 'messageType' => 6,
  5094. 'user_id' => $complaintInfo['user_id'],
  5095. ]);
  5096. }
  5097. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5098. $this->sendMessage([
  5099. 'talk_type' => 802,
  5100. 'title' => $complaintInfo['title'],
  5101. 'content' => '处理中',
  5102. 'messageType' => 6,
  5103. 'user_id' => $complaintInfo['re_user_ids'],
  5104. ]);
  5105. }
  5106. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5107. $this->sendMessage([
  5108. 'talk_type' => 802,
  5109. 'title' => $complaintInfo['title'],
  5110. 'content' => '不予处理',
  5111. 'messageType' => 6,
  5112. 'user_id' => $complaintInfo['re_user_ids'],
  5113. ]);
  5114. }
  5115. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5116. $this->sendMessage([
  5117. 'talk_type' => 802,
  5118. 'title' => $complaintInfo['title'],
  5119. 'content' => '已完结',
  5120. 'messageType' => 6,
  5121. 'user_id' => $complaintInfo['re_user_ids'],
  5122. ]);
  5123. }
  5124. $result = complaint::where('id', $data['id'])->update($data);
  5125. return Result::success($result);
  5126. }
  5127. public function updateGoodStatus(array $data): array
  5128. {
  5129. $user_id = $data['user_id'] ?? 0;
  5130. $type_id = $data['type_id'] ?? 0;
  5131. unset($data['user_id']);
  5132. unset($data['type_id']);
  5133. $goodInfo = Good::where('id', $data['id'])->first();
  5134. if ($data['status'] == 2) {
  5135. $this->sendMessage([
  5136. 'talk_type' => 201,
  5137. 'title' => $goodInfo['name'],
  5138. 'content' => '审核通过',
  5139. 'messageType' => 3,
  5140. 'user_id' => $goodInfo['user_id'],
  5141. ]);
  5142. }
  5143. if ($data['status'] == 3) {
  5144. $this->sendMessage([
  5145. 'talk_type' => 201,
  5146. 'title' => $goodInfo['name'],
  5147. 'content' => '审核拒绝',
  5148. 'messageType' => 3,
  5149. 'user_id' => $goodInfo['user_id'],
  5150. ]);
  5151. }
  5152. if ($data['status'] == 1) {
  5153. $this->sendMessage([
  5154. 'talk_type' => 200,
  5155. 'title' => $goodInfo['name'],
  5156. 'content' => '提交了审核',
  5157. 'messageType' => 3,
  5158. ]);
  5159. }
  5160. $result = Good::where('id', $data['id'])->update($data);
  5161. return Result::success($result);
  5162. }
  5163. public function updateJobHuntingStatus(array $data): array
  5164. {
  5165. $user_id = $data['user_id'] ?? 0;
  5166. $type_id = $data['type_id'] ?? 0;
  5167. unset($data['user_id']);
  5168. unset($data['type_id']);
  5169. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5170. if ($data['status'] == 2) {
  5171. $this->sendMessage([
  5172. 'talk_type' => 601,
  5173. 'title' => $jogHuntingInfo['name'],
  5174. 'content' => '审核通过',
  5175. 'messageType' => 11,
  5176. 'user_id' => $jogHuntingInfo['user_id'],
  5177. ]);
  5178. }
  5179. if ($data['status'] == 3) {
  5180. $this->sendMessage([
  5181. 'talk_type' => 601,
  5182. 'title' => $jogHuntingInfo['name'],
  5183. 'content' => '审核拒绝',
  5184. 'messageType' => 11,
  5185. 'user_id' => $jogHuntingInfo['user_id'],
  5186. ]);
  5187. }
  5188. if ($data['status'] == 1) {
  5189. $this->sendMessage([
  5190. 'talk_type' => 600,
  5191. 'title' => $jogHuntingInfo['name'],
  5192. 'content' => '提交了审核',
  5193. 'messageType' => 11,
  5194. ]);
  5195. }
  5196. $result = JobHunting::where('id', $data['id'])->update($data);
  5197. return Result::success($result);
  5198. }
  5199. public function updateNoticeStatus(array $data): array
  5200. {
  5201. $user_id = $data['user_id'] ?? 0;
  5202. $type_id = $data['type_id'] ?? 0;
  5203. unset($data['user_id']);
  5204. unset($data['type_id']);
  5205. //查询公告
  5206. $notice = Notice::where('id', $data['id'])->first();
  5207. if (empty($notice)) {
  5208. return Result::error("公告不存在", 0);
  5209. }
  5210. //$chat_ids 去除掉$data['user_id']
  5211. $chat_ids = json_decode($notice['re_user_ids'], true);
  5212. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5213. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5214. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5215. //chat_group
  5216. $group_id = PublicData::uuid();
  5217. $groupData = [
  5218. 'id' => $group_id,
  5219. 'creator_id' => $notice['user_id'],
  5220. 'group_name' => $notice['group_name'] ?? '',
  5221. 'profile' => $notice['profile'] ?? 0,
  5222. ];
  5223. var_dump($groupData, '-----------------groupData-------');
  5224. $groupResult = ChatGroups::insertGetId($groupData);
  5225. var_dump($groupResult, '-----------------groupid-------');
  5226. $groupMemberData = [
  5227. 'id' => PublicData::uuid(),
  5228. 'user_id' => $notice['user_id'],
  5229. 'group_id' => $group_id,
  5230. 'leader' => 2,
  5231. ];
  5232. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5233. //插入群成员表
  5234. $groupMemberDataUser = [];
  5235. $chatData = [];
  5236. foreach ($chat_ids as $key => $value) {
  5237. $groupMemberDataUser[] = [
  5238. 'id' => PublicData::uuid(),
  5239. 'user_id' => $value,
  5240. 'group_id' => $group_id,
  5241. 'leader' => 1,
  5242. ];
  5243. $chatData[] = [
  5244. 'user_id' => $value,
  5245. 'msg_type' => 1,
  5246. 'receiver_id' => $group_id,
  5247. 'content' => '通过通知创建群聊',
  5248. 'group_receiver_id' => $notice['user_id'],
  5249. 'action' => 'recieved',
  5250. 'created_at' => date('Y-m-d H:i:s'),
  5251. ];
  5252. }
  5253. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5254. ChatGroupsMember::insert($groupMemberDataUser);
  5255. //插入一条管理员聊天记录
  5256. $chatData[] = [
  5257. 'user_id' => $notice['user_id'],
  5258. 'msg_type' => 1,
  5259. 'receiver_id' => $group_id,
  5260. 'content' => '通过通知创建群聊',
  5261. 'group_receiver_id' => $notice['user_id'],
  5262. 'action' => 'said',
  5263. 'created_at' => date('Y-m-d H:i:s'),
  5264. ];
  5265. var_dump($chatData, '-----------------chatData-------');
  5266. $chatResult = ChatRecords::insert($chatData);
  5267. //处理imp
  5268. $group = [
  5269. 'type' => 1,
  5270. 'name' => $notice['group_name'] ?? '',
  5271. 'profile' => '',
  5272. 'avatar' => '',
  5273. 'creator_id' => $notice['user_id'],
  5274. ];
  5275. $groupResult = GroupImp::insertGetId($group);
  5276. var_dump($groupResult, '获取imp group_id');
  5277. $groupMember = [
  5278. 'user_id' => $notice['user_id'],
  5279. 'group_id' => $groupResult,
  5280. 'leader' => 1,
  5281. 'join_time' => Date('Y-m-d H:i:s')
  5282. ];
  5283. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5284. $talk_session = [
  5285. 'user_id' => $notice['user_id'],
  5286. 'to_from_id' => $groupResult,
  5287. 'talk_mode' => 2,
  5288. 'created_at' => Date('Y-m-d H:i:s'),
  5289. 'updated_at' => Date('Y-m-d H:i:s'),
  5290. ];
  5291. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5292. //被通知人员处理
  5293. foreach ($chat_ids as $key => $value) {
  5294. $groupMemberdata[] = [
  5295. 'user_id' => $value,
  5296. 'group_id' => $groupResult,
  5297. 'leader' => 3,
  5298. 'join_time' => Date('Y-m-d H:i:s')
  5299. ];
  5300. $talk_sessionData[] = [
  5301. 'user_id' => $value,
  5302. 'to_from_id' => $groupResult,
  5303. 'talk_mode' => 2,
  5304. 'created_at' => Date('Y-m-d H:i:s'),
  5305. 'updated_at' => Date('Y-m-d H:i:s'),
  5306. ];
  5307. }
  5308. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5309. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5310. $group_id = $groupResult;
  5311. //更新result的 group_id
  5312. $data['group_id'] = $group_id;
  5313. Notice::where(['id' => $data['id']])->update($data);
  5314. }
  5315. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5316. //删除掉信息
  5317. GroupImp::where('id', $notice['group_id'])->delete();
  5318. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5319. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5320. foreach ($chat_ids as $key => $value) {
  5321. }
  5322. //聊天记录删除
  5323. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5324. $data['group_id'] = null;
  5325. Notice::where(['id' => $data['id']])->update($data);
  5326. }
  5327. $result = Notice::where('id', $data['id'])->update($data);
  5328. $noticeInfo = Notice::where('id', $data['id'])->first();
  5329. if ($data['status'] == 2) {
  5330. $this->sendMessage([
  5331. 'talk_type' => 701,
  5332. 'title' => $noticeInfo['title'],
  5333. 'content' => '审核通过',
  5334. 'messageType' => 3,
  5335. 'user_id' => $noticeInfo['user_id'],
  5336. ]);
  5337. }
  5338. if ($data['status'] == 3) {
  5339. $this->sendMessage([
  5340. 'talk_type' => 701,
  5341. 'title' => $noticeInfo['title'],
  5342. 'content' => '审核拒绝',
  5343. 'messageType' => 3,
  5344. 'user_id' => $noticeInfo['user_id'],
  5345. ]);
  5346. }
  5347. if ($data['status'] == 1) {
  5348. $this->sendMessage([
  5349. 'talk_type' => 700,
  5350. 'title' => $noticeInfo['title'],
  5351. 'content' => '提交了审核',
  5352. 'messageType' => 3,
  5353. ]);
  5354. }
  5355. return Result::success($result);
  5356. }
  5357. public function getDUser(array $data): array
  5358. {
  5359. if (!empty($data['ids'])) {
  5360. $user = User::whereIn('id', $data['ids'])->getall();
  5361. if (empty($user)) {
  5362. return Result::error('无数据', 0);
  5363. }
  5364. return Result::success($user);
  5365. }
  5366. $where = [];
  5367. if (!empty($data['department_id'])) {
  5368. $where['department_id'] = $data['department_id'];
  5369. }
  5370. if (!empty($data['city_id'])) {
  5371. $where['city_id'] = $data['city_id'];
  5372. }
  5373. $result = User::where('type_id', 2)
  5374. ->where('status', 1)
  5375. ->where($where)
  5376. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5377. ->get();
  5378. if (empty($result)) {
  5379. return Result::error("查询失败", 0);
  5380. }
  5381. return Result::success($result);
  5382. }
  5383. /**
  5384. * 验证导航名称是否重复
  5385. * @return void
  5386. */
  5387. public function checkCategoryName(array $data): array
  5388. {
  5389. $result = Category::when($data, function ($query) use ($data) {
  5390. if (isset($data['name']) && $data['name']) {
  5391. $query->where("name", $data['name']);
  5392. }
  5393. if (isset($data['id']) && $data['id']) {
  5394. $query->where("id", "!=", $data['id']);
  5395. }
  5396. })->first();
  5397. if ($result) {
  5398. return Result::error("已存在");
  5399. } else {
  5400. return Result::success();
  5401. }
  5402. }
  5403. //20250226 产品列表
  5404. // 20250306 -------招聘--------fr
  5405. /*
  5406. * 招聘列表
  5407. * */
  5408. public function getJobRecruitingList(array $data): array
  5409. {
  5410. $where = [];
  5411. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5412. if ($data['checkout'] == 0) {
  5413. $job_status = [0, 2];
  5414. } else {
  5415. $job_status = [1];
  5416. }
  5417. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5418. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5419. }
  5420. $user = User::where('id', $data['user_id'])->first();
  5421. if (empty($user)) {
  5422. return Result::error("用户不存在", 0);
  5423. }
  5424. // 3:企业会员
  5425. if ($user['type_id'] == 3) {
  5426. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5427. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5428. }
  5429. // 如果 $where 为空,则不添加 where 条件
  5430. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5431. return $query->where($where);
  5432. })
  5433. ->whereIn('job_recruiting.status', $job_status)
  5434. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5435. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5436. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5437. ->orderBy("updated_at", "desc")
  5438. ->offset(($data['page'] - 1) * $data['page_size'])
  5439. ->limit($data['page_size'])
  5440. ->get()
  5441. ->all();
  5442. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5443. return $query->where($where);
  5444. })
  5445. ->whereIn('job_recruiting.status', $job_status)
  5446. ->count();
  5447. if (empty($result)) {
  5448. return Result::error("暂无招聘信息", 0);
  5449. }
  5450. return Result::success($result);
  5451. }
  5452. /*
  5453. * 招聘信息添加
  5454. * */
  5455. public function addJobRecruiting(array $data): array
  5456. {
  5457. // var_dump('添加招聘进入news------data',$data);
  5458. // return Result::success($data);
  5459. $user = User::where('user.id', $data['user_id'])
  5460. ->where('user.status', 1)
  5461. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5462. ->select(
  5463. 'user.type_id',
  5464. 'user.mobile',
  5465. 'user.email',
  5466. 'user_info.business_name',
  5467. 'user_info.company_hy_id',
  5468. 'user_info.company_nature',
  5469. 'user_info.company_size',
  5470. 'user_info.introduction',
  5471. 'user_info.real_name',
  5472. 'user_info.company_url',
  5473. 'user_info.address_arr_id',
  5474. 'user_info.address'
  5475. )
  5476. ->first();
  5477. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5478. return Result::error("用户不存在", 0);
  5479. }
  5480. $web = Website::where('id', $data['website_id'])->first();
  5481. if (empty($web)) {
  5482. return Result::error("网站不存在", 0);
  5483. }
  5484. // var_dump('添加招聘进入news---user---user',$user);
  5485. // 处理招聘关键词
  5486. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5487. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5488. } else {
  5489. Jieba::init(); // 初始化 jieba-php
  5490. Finalseg::init();
  5491. $segList = Jieba::cut($data['title']);
  5492. $segList1 = array_slice($segList, 0, 8);
  5493. $data['keyword'] = implode(',', $segList1);
  5494. }
  5495. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5496. $content = $data['description'];
  5497. // 去除 <style> 和 <script> 标签及其内容
  5498. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5499. // 去除所有 HTML 标签
  5500. $content = strip_tags($content);
  5501. // 去除 HTML 实体
  5502. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5503. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5504. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5505. // 去除多余空白
  5506. $content = preg_replace('/\s+/u', '', $content);
  5507. // 截取 100 个字符
  5508. $data['seo_description'] = mb_substr($content, 0, 100);
  5509. }
  5510. // return Result::success($user);
  5511. $data['action_id'] = $data['user_id'] ?? null;
  5512. $data['user_type'] = $user['type_id'] ?? null;
  5513. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5514. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5515. $data['catid'] = end($data['cat_arr_id']);
  5516. } else {
  5517. $data['catid'] = 0;
  5518. }
  5519. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5520. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5521. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5522. // 公司地址 管理员必填
  5523. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5524. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5525. // 管理员-企业相关信息
  5526. $company = [
  5527. // 'user_id' => $data['user_id']?? null,
  5528. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5529. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5530. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5531. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5532. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5533. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5534. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5535. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5536. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5537. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5538. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5539. ];
  5540. //去掉相关企业信息
  5541. $job = array_diff_key($data, array_flip(array_keys($company)));
  5542. // var_dump('添加招聘进入news---job---user',$job);
  5543. Db::beginTransaction();
  5544. try {
  5545. // // 先添加职位相关信息
  5546. if ($user['type_id'] == 10000) {
  5547. $job['status'] = 1;
  5548. }
  5549. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5550. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5551. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5552. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5553. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5554. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5555. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5556. // return Result::success($job);
  5557. $jobId = JobRecruiting::insertGetId($job);
  5558. if (empty($jobId)) {
  5559. Db::rollBack();
  5560. return Result::error("添加失败");
  5561. }
  5562. // 添加公司信息
  5563. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5564. $company['job_id'] = $jobId;
  5565. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5566. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5567. if ($user['type_id'] == 10000) {
  5568. // 管理员添加企业信息
  5569. $companyId = JobCompany::insertGetId($company);
  5570. if (empty($companyId)) {
  5571. Db::rollBack();
  5572. return Result::error("添加失败");
  5573. }
  5574. } else {
  5575. // 企业会员添加企业信息
  5576. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5577. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5578. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5579. $company['job_id'] = $jobId;
  5580. $companyId = JobCompany::insertGetId($company);
  5581. if (empty($companyId)) {
  5582. Db::rollBack();
  5583. return Result::error("添加失败");
  5584. }
  5585. }
  5586. Db::commit();
  5587. $result = [
  5588. 'job_id' => $jobId,
  5589. 'company_id' => $companyId,
  5590. ];
  5591. return Result::success($result);
  5592. } catch (\Exception $e) {
  5593. Db::rollBack();
  5594. return Result::error($e->getMessage(), 0);
  5595. }
  5596. // return Result::success($result);
  5597. }
  5598. /*
  5599. * 获取招聘信息详情
  5600. * */
  5601. public function getJobRecruitingInfo(array $data): array
  5602. {
  5603. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5604. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5605. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5606. ->select(
  5607. 'job_recruiting.*',
  5608. 'website.website_name as website_name',
  5609. 'job_company.business_name',
  5610. 'job_company.company_hy_id',
  5611. 'job_company.company_size',
  5612. 'job_company.company_nature',
  5613. 'job_company.introduction',
  5614. 'job_company.real_name',
  5615. 'job_company.mobile',
  5616. 'job_company.company_url',
  5617. 'job_company.address_arr_id',
  5618. 'job_company.address',
  5619. 'job_company.email'
  5620. )
  5621. ->first();
  5622. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5623. if (!empty($cityId)) {
  5624. if (isset($cityId[1]) && $cityId[1] != null) {
  5625. $city = District::where('id', $cityId[1])->first(['name']);
  5626. } else {
  5627. $city = District::where('id', $cityId[0])->first(['name']);
  5628. }
  5629. $result['city'] = $city['name'] ?? '';
  5630. }
  5631. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5632. if (is_array($addressId) && !empty($addressId)) {
  5633. $address = District::whereIn('id', $addressId)
  5634. ->orderBy('level', 'asc')
  5635. ->get(['name'])
  5636. ->pluck('name')
  5637. ->implode('');
  5638. // $job->address_name = $address ?? '';
  5639. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5640. }
  5641. if (empty($result)) {
  5642. return Result::error("招聘信息不存在", 0);
  5643. }
  5644. // return Result::success($job);
  5645. return Result::success($result);
  5646. }
  5647. /*
  5648. * 修改招聘信息
  5649. * */
  5650. public function upJobRecruiting(array $data): array
  5651. {
  5652. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5653. // return Result::success($job);
  5654. if (empty($job)) {
  5655. return Result::error("招聘信息不存在", 0);
  5656. }
  5657. $user = User::where('id', $data['user_id'])->first();
  5658. // return Result::success($user);
  5659. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5660. return Result::error("用户不存在", 0);
  5661. }
  5662. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5663. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5664. }
  5665. // 处理招聘关键词
  5666. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5667. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5668. } else {
  5669. Jieba::init(); // 初始化 jieba-php
  5670. Finalseg::init();
  5671. $segList = Jieba::cut($data['title']);
  5672. $segList1 = array_slice($segList, 0, 8);
  5673. $data['keyword'] = implode(',', $segList1);
  5674. }
  5675. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5676. $content = $data['description'];
  5677. // 去除 <style> 和 <script> 标签及其内容
  5678. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5679. // 去除所有 HTML 标签
  5680. $content = strip_tags($content);
  5681. // 去除 HTML 实体
  5682. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5683. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5684. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5685. // 去除多余空白
  5686. $content = preg_replace('/\s+/u', '', $content);
  5687. // 截取 100 个字符
  5688. $data['seo_description'] = mb_substr($content, 0, 100);
  5689. }
  5690. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5691. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5692. $data['catid'] = end($data['cat_arr_id']);
  5693. } else {
  5694. }
  5695. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5696. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5697. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5698. // 公司地址 管理员必填
  5699. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5700. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5701. // 管理员-企业相关信息
  5702. $company = [
  5703. // 'user_id' => $data['user_id']?? null,
  5704. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5705. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5706. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5707. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5708. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5709. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5710. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5711. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5712. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5713. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5714. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5715. ];
  5716. //去掉相关企业信息
  5717. $data = array_diff_key($data, array_flip(array_keys($company)));
  5718. $jobId = $data['id'];
  5719. $web = $data['website_id'];
  5720. $data['action_id'] = $data['user_id'];
  5721. unset($data['user_id']);
  5722. unset($data['user_type']);
  5723. unset($data['id']);
  5724. unset($data['website_id']);
  5725. // return Result::success($data);
  5726. Db::beginTransaction();
  5727. try {
  5728. // 管理员修改招聘信息
  5729. if ($user['type_id'] == 10000) {
  5730. $data['website_id'] = $web;
  5731. $company['website_id'] = $data['website_id'];
  5732. $data['status'] = 1;
  5733. } else {
  5734. $data['status'] = 0;
  5735. }
  5736. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5737. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5738. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5739. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5740. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5741. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5742. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5743. // return Result::success($job);
  5744. // Db::rollBack();
  5745. // return Result::success($company);
  5746. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5747. $this->sendMessage([
  5748. 'talk_type' => 500,
  5749. 'title' => $data['title'],
  5750. 'content' => '提交了审核',
  5751. 'messageType' => 10,
  5752. ]);
  5753. }
  5754. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5755. if (empty($result['job'])) {
  5756. Db::rollBack();
  5757. return Result::error("修改招聘信息失败");
  5758. }
  5759. // 管理员修改企业相关信息
  5760. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5761. if (empty($result['company'])) {
  5762. Db::rollBack();
  5763. return Result::error("修改企业相关信息失败");
  5764. }
  5765. Db::commit();
  5766. // return Result::success($result);
  5767. } catch (\Exception $e) {
  5768. Db::rollBack();
  5769. return Result::error($e->getMessage(), 0);
  5770. }
  5771. return Result::success($result);
  5772. }
  5773. /*
  5774. * 招聘信息删除
  5775. * */
  5776. public function delJobRecruiting(array $data): array
  5777. {
  5778. $user = User::where('id', $data['user_id'])->first();
  5779. if (empty($user)) {
  5780. return Result::error("用户不存在", 0);
  5781. }
  5782. $job = JobRecruiting::where('id', $data['id'])->first();
  5783. if (empty($job)) {
  5784. return Result::error("招聘信息不存在", 0);
  5785. }
  5786. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5787. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5788. }
  5789. Db::beginTransaction();
  5790. try {
  5791. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5792. if (empty($result['job'])) {
  5793. Db::rollBack();
  5794. return Result::error("删除招聘信息失败");
  5795. }
  5796. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5797. if (empty($result['company'])) {
  5798. Db::rollBack();
  5799. return Result::error("删除企业相关信息失败");
  5800. }
  5801. Db::commit();
  5802. } catch (\Exception $e) {
  5803. Db::rollBack();
  5804. return Result::error($e->getMessage(), 0);
  5805. }
  5806. return Result::success($result);
  5807. }
  5808. /*
  5809. * 获取公司信息
  5810. * */
  5811. public function getJobCompany(array $data): array
  5812. {
  5813. $user = User::where('user.id', $data['user_id'])
  5814. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5815. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5816. ->first();
  5817. // return Result::success($user);
  5818. if (empty($user)) {
  5819. return Result::error("用户不存在", 0);
  5820. }
  5821. if ($user['type_id'] == 3) {
  5822. $result = [
  5823. // 'id' => 0,
  5824. 'user_id' => $data['user_id'],
  5825. 'website_id' => $data['website_id'],
  5826. 'business_name' => $user['business_name'], // 企业名称
  5827. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5828. 'company_nature' => $user['company_nature'], // 公司性质
  5829. 'company_size' => $user['company_size'], // 公司规模
  5830. 'introduction' => $user['introduction'], // 公司简介
  5831. 'real_name' => $user['real_name'], // 企业联系人
  5832. 'mobile' => $user['mobile'], // 企业联系电话
  5833. 'company_url' => $user['company_url'], // 企业网址
  5834. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5835. 'address' => $user['address'], // 企业地址
  5836. 'email' => $user['email'], // 企业邮箱
  5837. ];
  5838. } else {
  5839. return Result::error("用户类型错误", 0);
  5840. }
  5841. if (empty($result)) {
  5842. return Result::error("公司信息不存在", 0);
  5843. }
  5844. return Result::success($result);
  5845. }
  5846. /*
  5847. * 修改公司信息
  5848. * */
  5849. public function upJobCompany(array $data): array
  5850. {
  5851. // return Result::success($data);
  5852. $user = User::where('user.id', $data['user_id'])
  5853. ->where('user.status', 1)
  5854. ->select('user.user_name', 'user.type_id')
  5855. ->first();
  5856. if (empty($user)) {
  5857. return Result::error("用户不存在", 0);
  5858. }
  5859. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5860. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5861. $company = [
  5862. 'business_name' => $data['business_name'], // 企业名称
  5863. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5864. 'company_nature' => $data['company_nature'], // 公司性质
  5865. 'company_size' => $data['company_size'], // 公司规模
  5866. 'introduction' => $data['introduction'], // 公司简介
  5867. // 'real_name' => $data['real_name'], // 企业联系人
  5868. 'company_url' => $data['company_url'], // 企业网址
  5869. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5870. 'address' => $data['address'], // 企业详细地址
  5871. // 'email' => $data['email'], // 企业邮箱
  5872. ];
  5873. if ($user['type_id'] == 3) {
  5874. Db::beginTransaction();
  5875. try {
  5876. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5877. 'business_name' => $data['business_name'], // 企业名称
  5878. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5879. 'company_nature' => $data['company_nature'], // 公司性质
  5880. 'company_size' => $data['company_size'], // 公司规模
  5881. 'introduction' => $data['introduction'], // 公司简介
  5882. // 'real_name' => $data['real_name'], // 企业联系人
  5883. 'company_url' => $data['company_url'], // 企业网址
  5884. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5885. 'address' => $data['address'], // 企业详细地址
  5886. ]);
  5887. if (empty($result['userinfo'])) {
  5888. Db::rollBack();
  5889. return Result::error('修改企业会员信息失败!');
  5890. }
  5891. $result['user'] = User::where('id', $data['user_id'])->update([
  5892. 'email' => $data['email'], // 企业邮箱
  5893. ]);
  5894. if (empty($result['user'])) {
  5895. Db::rollBack();
  5896. return Result::error('修改个人中心信息失败!');
  5897. }
  5898. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5899. if (!empty($job_company)) {
  5900. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5901. if (empty($result['job_company'])) {
  5902. Db::rollBack();
  5903. return Result::error('修改企业会员信息失败!');
  5904. }
  5905. }
  5906. Db::commit();
  5907. return Result::success($result);
  5908. } catch (\Exception $e) {
  5909. Db::rollBack();
  5910. return Result::error($e->getMessage(), 0);
  5911. }
  5912. } else {
  5913. return Result::error("用户类型错误", 0);
  5914. }
  5915. }
  5916. /*
  5917. * 获取省-市
  5918. * */
  5919. public function getJobRecruitingArea(array $data): array
  5920. {
  5921. if (isset($data['pid']) && $data['pid'] != null) {
  5922. $result = District::where('pid', $data['pid'])->get()->all();
  5923. } else {
  5924. $result = District::where('level', 1)->get()->all();
  5925. }
  5926. if (empty($result)) {
  5927. return Result::error("暂无此省市", 0);
  5928. }
  5929. return Result::success($result);
  5930. }
  5931. /*
  5932. * 获取行业分类
  5933. * */
  5934. public function getIndustry(array $data): array
  5935. {
  5936. $result = JobIndustry::get()->all();
  5937. if (empty($result)) {
  5938. return Result::error("暂无行业分类", 0);
  5939. }
  5940. return Result::success($result);
  5941. }
  5942. /*
  5943. * 获取职位
  5944. * */
  5945. public function getPositionList(array $data): array
  5946. {
  5947. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5948. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5949. } else {
  5950. $result = JobPosition::where('zwpid', 0)->get()->all();
  5951. }
  5952. if (empty($result)) {
  5953. return Result::error("暂无此职位", 0);
  5954. }
  5955. return Result::success($result);
  5956. }
  5957. /*
  5958. * 获取工作性质-菜单
  5959. * */
  5960. public function getJobNature(array $data): array
  5961. {
  5962. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5963. if (empty($result)) {
  5964. return Result::error("暂无工作性质", 0);
  5965. }
  5966. return Result::success($result);
  5967. }
  5968. /*
  5969. * 获取工作经验-菜单
  5970. * */
  5971. public function getExperience(array $data): array
  5972. {
  5973. $result = JobEnum::where('egroup', 'years')->get()->all();
  5974. if (empty($result)) {
  5975. return Result::error("暂无工作经验", 0);
  5976. }
  5977. return Result::success($result);
  5978. }
  5979. /*
  5980. * 获取学历-菜单
  5981. * */
  5982. public function getEducation(array $data): array
  5983. {
  5984. $result = JobEnum::where('egroup', 'education')->get()->all();
  5985. if (empty($result)) {
  5986. return Result::error("暂无学历", 0);
  5987. }
  5988. return Result::success($result);
  5989. }
  5990. /*
  5991. * 获取薪资-菜单
  5992. * */
  5993. public function getSalary(array $data): array
  5994. {
  5995. $result = JobEnum::where('egroup', 'income')->get()->all();
  5996. if (empty($result)) {
  5997. return Result::error("暂无薪资", 0);
  5998. }
  5999. return Result::success($result);
  6000. }
  6001. /*
  6002. * 获取语言-菜单
  6003. * */
  6004. public function getLanguage(array $data): array
  6005. {
  6006. $result = JobEnum::where('egroup', 'language')->get()->all();
  6007. if (empty($result)) {
  6008. return Result::error("暂无语言", 0);
  6009. }
  6010. return Result::success($result);
  6011. }
  6012. /*
  6013. * 获取掌握程度-菜单
  6014. * */
  6015. public function getLevel(array $data): array
  6016. {
  6017. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6018. if (empty($result)) {
  6019. return Result::error("暂无工作性质", 0);
  6020. }
  6021. return Result::success($result);
  6022. }
  6023. // 公司信息
  6024. /*
  6025. * 获取公司性质-菜单
  6026. * */
  6027. public function getCompanyNature(array $data): array
  6028. {
  6029. $result = JobNature::get()->all();
  6030. if (empty($result)) {
  6031. return Result::error("暂无公司性质", 0);
  6032. }
  6033. return Result::success($result);
  6034. }
  6035. /*
  6036. * 获取公司规模-菜单
  6037. * */
  6038. public function getCompanySize(array $data): array
  6039. {
  6040. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6041. if (empty($result)) {
  6042. return Result::error("暂无公司规模", 0);
  6043. }
  6044. return Result::success($result);
  6045. }
  6046. /*
  6047. * 招聘信息审核
  6048. * */
  6049. public function checkJobRecruiting(array $data): array
  6050. {
  6051. $user = User::where('id', $data['user_id'])->first();
  6052. if (empty($user)) {
  6053. return Result::error("用户不存在", 0);
  6054. }
  6055. $job = JobRecruiting::where('id', $data['id'])->first();
  6056. if (empty($job)) {
  6057. return Result::error("招聘信息不存在", 0);
  6058. }
  6059. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6060. if ($user['type_id'] != 10000) {
  6061. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6062. }
  6063. // 驳回原因
  6064. if ($data['status'] == 2) {
  6065. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6066. }
  6067. $data['action_id'] = $data['user_id'];
  6068. unset($data['user_id']);
  6069. if ($data['status'] == 1) {
  6070. $this->sendMessage([
  6071. 'talk_type' => 501,
  6072. 'title' => $job['title'],
  6073. 'content' => '审核通过',
  6074. 'messageType' => 10,
  6075. 'user_id' => $job['user_id'],
  6076. ]);
  6077. }
  6078. if ($data['status'] == 2) {
  6079. $this->sendMessage([
  6080. 'talk_type' => 501,
  6081. 'title' => $job['title'],
  6082. 'content' => '审核拒绝',
  6083. 'messageType' => 10,
  6084. 'user_id' => $job['user_id'],
  6085. ]);
  6086. }
  6087. if ($data['status'] == 0) {
  6088. $this->sendMessage([
  6089. 'talk_type' => 500,
  6090. 'title' => $job['title'],
  6091. 'content' => '提交了审核',
  6092. 'messageType' => 10,
  6093. ]);
  6094. }
  6095. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6096. if (empty($result)) {
  6097. return Result::error("审核失败", 0);
  6098. }
  6099. return Result::success($result);
  6100. }
  6101. public function myApplyList(array $data): array
  6102. {
  6103. var_dump($data, '------参数');
  6104. $user = User::where('id', $data['user_id'])->first();
  6105. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6106. return Result::error("用户不存在", 0);
  6107. }
  6108. // 1:个人会员 职场机会
  6109. if ($user['type_id'] == 1) {
  6110. $where['user_id'] = $user['id'];
  6111. }
  6112. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6113. $query->where('user_id', $user['id']);
  6114. })
  6115. ->pluck('recruit_id');
  6116. $where = [];
  6117. if (isset($data['salary']) && $data['salary'] != null) {
  6118. $where['job_recruiting.salary'] = $data['salary'];
  6119. }
  6120. if (isset($data['experience']) && $data['experience'] != null) {
  6121. $where['job_recruiting.experience'] = $data['experience'];
  6122. }
  6123. if (isset($data['business_name']) && $data['business_name'] != null) {
  6124. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6125. }
  6126. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6127. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6128. ->where($where);
  6129. // ->count();
  6130. $count = $query->count();
  6131. $query = clone $query;
  6132. $job = $query
  6133. ->leftJoin('job_enum as income_enum', function ($join) {
  6134. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6135. ->where('income_enum.egroup', 'income');
  6136. })
  6137. ->leftJoin('job_enum as years_enum', function ($join) {
  6138. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6139. ->where('years_enum.egroup', 'years');
  6140. })
  6141. // ->where($where)
  6142. ->orderBy('job_recruiting.updated_at', 'desc')
  6143. ->select(
  6144. 'job_recruiting.id',
  6145. 'job_recruiting.title',
  6146. 'job_company.business_name',
  6147. 'income_enum.evalue as salary_evalue',
  6148. 'income_enum.ename as salary_ename',
  6149. 'years_enum.evalue as experience_evalue',
  6150. 'years_enum.ename as experience_ename',
  6151. 'job_recruiting.updated_at'
  6152. )
  6153. ->offset(($data['page'] - 1) * $data['pageSize'])
  6154. ->limit($data['pageSize'])
  6155. ->get()
  6156. ->all();
  6157. if (empty($job)) {
  6158. return Result::error("暂无招聘信息", 0);
  6159. }
  6160. $result = [
  6161. 'row' => $job,
  6162. 'count' => $count,
  6163. ];
  6164. return Result::success($result);
  6165. }
  6166. public function readJobApply(array $data): array
  6167. {
  6168. $result = JobApply::where('id', $data['id'])->first();
  6169. if (empty($result)) {
  6170. return Result::error("查询失败", 0);
  6171. }
  6172. $result = JobApply::where('id', $data['id'])->update([
  6173. 'status' => 2,
  6174. ]);
  6175. return Result::success($result);
  6176. }
  6177. /*
  6178. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6179. * */
  6180. public function getRecruitingList(array $data): array
  6181. {
  6182. $user = User::where('id', $data['user_id'])->first();
  6183. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6184. return Result::error("用户不存在", 0);
  6185. }
  6186. // 1:个人会员 职场机会
  6187. if ($user['type_id'] == 1) {
  6188. $where['user_id'] = $user['id'];
  6189. }
  6190. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6191. $query->where('receiver_id', $user['id']);
  6192. })
  6193. ->pluck('recruit_id');
  6194. // return Result::success($recruitingId);
  6195. $where = [];
  6196. if (isset($data['salary']) && $data['salary'] != null) {
  6197. $where['job_recruiting.salary'] = $data['salary'];
  6198. }
  6199. if (isset($data['experience']) && $data['experience'] != null) {
  6200. $where['job_recruiting.experience'] = $data['experience'];
  6201. }
  6202. if (isset($data['business_name']) && $data['business_name'] != null) {
  6203. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6204. }
  6205. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6206. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6207. ->where($where);
  6208. // ->count();
  6209. $count = $query->count();
  6210. $query = clone $query;
  6211. $job = $query
  6212. ->leftJoin('job_enum as income_enum', function ($join) {
  6213. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6214. ->where('income_enum.egroup', 'income');
  6215. })
  6216. ->leftJoin('job_enum as years_enum', function ($join) {
  6217. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6218. ->where('years_enum.egroup', 'years');
  6219. })
  6220. // ->where($where)
  6221. ->orderBy('job_recruiting.updated_at', 'desc')
  6222. ->select(
  6223. 'job_recruiting.id',
  6224. 'job_recruiting.title',
  6225. 'job_company.business_name',
  6226. 'income_enum.evalue as salary_evalue',
  6227. 'income_enum.ename as salary_ename',
  6228. 'years_enum.evalue as experience_evalue',
  6229. 'years_enum.ename as experience_ename',
  6230. 'job_recruiting.updated_at'
  6231. )
  6232. ->offset(($data['page'] - 1) * $data['pageSize'])
  6233. ->limit($data['pageSize'])
  6234. ->get()
  6235. ->all();
  6236. if (empty($job)) {
  6237. return Result::error("暂无招聘信息", 0);
  6238. }
  6239. $result = [
  6240. 'row' => $job,
  6241. 'count' => $count,
  6242. ];
  6243. return Result::success($result);
  6244. }
  6245. /*
  6246. * 获取企业会员-招聘信息列表
  6247. * */
  6248. public function getRecruitingInfo(array $data): array
  6249. {
  6250. $user = User::where('id', $data['user_id'])->first();
  6251. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6252. return Result::error("用户不存在", 0);
  6253. }
  6254. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6255. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6256. ->select(
  6257. 'job_recruiting.*',
  6258. 'job_company.business_name',
  6259. 'job_company.company_hy_id',
  6260. 'job_company.company_size',
  6261. 'job_company.company_nature',
  6262. 'job_company.introduction',
  6263. 'job_company.real_name',
  6264. 'job_company.mobile',
  6265. 'job_company.company_url',
  6266. 'job_company.address_arr_id',
  6267. 'job_company.address',
  6268. 'job_company.email'
  6269. )
  6270. ->get();
  6271. if (empty($recruiting)) {
  6272. return Result::error("暂无招聘信息", 0);
  6273. }
  6274. return Result::success($recruiting);
  6275. }
  6276. /*
  6277. * 获取企业会员-我的沟通
  6278. * */
  6279. public function getJobResumeList(array $data): array
  6280. {
  6281. $user = User::where('id', $data['user_id'])->first();
  6282. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6283. return Result::error("用户不存在", 0);
  6284. }
  6285. $where = [];
  6286. if (isset($data['salary']) && $data['salary'] != null) {
  6287. $where['job_hunting.salary'] = $data['salary'];
  6288. }
  6289. if (isset($data['user_name']) && $data['user_name'] != null) {
  6290. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6291. }
  6292. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6293. $query->where('job_resume.user_id', $user['id']);
  6294. })
  6295. ->when(!empty($where), function ($query) use ($where) {
  6296. $query->where($where);
  6297. })
  6298. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6299. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6300. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6301. ->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');
  6302. $count = $job->count();
  6303. if ($count == 0) {
  6304. return Result::error("暂无沟通记录", 0);
  6305. }
  6306. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6307. ->offset(($data['page'] - 1) * $data['pageSize'])
  6308. ->limit($data['pageSize'])
  6309. ->get();
  6310. if (empty($jobs)) {
  6311. return Result::error("暂无沟通记录", 0);
  6312. }
  6313. $result['row'] = $this->processJob($jobs, '');
  6314. $result['count'] = $count;
  6315. return Result::success($result);
  6316. }
  6317. public function readJobResume(array $data): array
  6318. {
  6319. $result = JobResume::where('id', $data['id'])->first();
  6320. if (empty($result)) {
  6321. return Result::error("查询失败", 0);
  6322. }
  6323. $result = JobResume::where('id', $data['id'])->update([
  6324. 'status' => 2,
  6325. ]);
  6326. return Result::success($result);
  6327. }
  6328. // 20250306 招聘
  6329. //20250422 书刊音像
  6330. public function addBook(array $data): array
  6331. {
  6332. $user_id = $data['user_id'] ?? 0;
  6333. $type_id = $data['type_id'] ?? 0;
  6334. // $website_id = $data['website_id'] ?? 0;
  6335. // unset($data['user_id']);
  6336. unset($data['type_id']);
  6337. // unset($data['website_id']);
  6338. //处理数组
  6339. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6340. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6341. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6342. if ($data['img_url'] == '') {
  6343. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6344. preg_match_all($reg, $data['detail'], $matches);
  6345. if (isset($matches[1][0])) {
  6346. //截取varchar240
  6347. $data['img_url'] = substr($matches[1][0], 0, 240);
  6348. }
  6349. }
  6350. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6351. //提取标题+内容中的关键词
  6352. $data['keyword'] = $data['title'];
  6353. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6354. Jieba::init(); // 初始化 jieba-php
  6355. Finalseg::init();
  6356. $segList = Jieba::cut($data['keyword']);
  6357. $segList1 = array_slice($segList, 0, 8);
  6358. $data['keyword'] = implode(',', $segList1);
  6359. }
  6360. if ($data['description'] == '') {
  6361. //提取内容中的描述
  6362. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6363. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6364. }
  6365. var_dump($data, '--');
  6366. if ($data['status'] == 1) {
  6367. $this->sendMessage([
  6368. 'talk_type' => 400,
  6369. 'title' => $data['title'],
  6370. 'content' => '提交了审核',
  6371. 'messageType' => 7,
  6372. ]);
  6373. }
  6374. $result = Book::insertGetId($data);
  6375. if (empty($result)) {
  6376. return Result::error("添加失败", 0);
  6377. }
  6378. return Result::success($result);
  6379. }
  6380. public function getBookList(array $data): array
  6381. {
  6382. $where = [];
  6383. if (!empty($data["title"])) {
  6384. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6385. }
  6386. if (!empty($data['website_name'])) {
  6387. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6388. }
  6389. if (!empty($data['status'])) {
  6390. $where[] = ['book.status', '=', $data['status']];
  6391. }
  6392. $user_id = $data['user_id'];
  6393. $type_id = $data['type_id'];
  6394. // $type_id = 4;
  6395. var_dump($type_id, '------1--------');
  6396. if ($type_id != 10000) {
  6397. $where[] = ['book.user_id', '=', $user_id];
  6398. }
  6399. var_dump(!empty($data['status1']), '=-===1');
  6400. $result = Book::where($where)
  6401. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6402. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6403. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6404. ->when(isset($data['status1']), function ($query) use ($data) {
  6405. $query->whereIn('book.status', [1, 3]);
  6406. })
  6407. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6408. ->orderBy("updated_at", "desc")
  6409. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6410. if (empty($result)) {
  6411. return Result::error("暂无数据", 0);
  6412. }
  6413. // 取出数据
  6414. $rows = $result->items();
  6415. $count = $result->total();
  6416. $responseData = [
  6417. 'rows' => $rows,
  6418. 'count' => $count,
  6419. ];
  6420. return Result::success($responseData);
  6421. }
  6422. public function deleteBook(array $data): array
  6423. {
  6424. $result = Book::where('id', $data['id'])->delete();
  6425. if (empty($result)) {
  6426. return Result::error("删除失败", 0);
  6427. }
  6428. return Result::success($result);
  6429. }
  6430. public function updateBook(array $data): array
  6431. {
  6432. // $user_id = $data['user_id'] ?? 0;
  6433. $type_id = $data['type_id'] ?? 0;
  6434. // $website_id = $data['website_id'] ?? 0;
  6435. unset($data['user_id']);
  6436. unset($data['type_id']);
  6437. // unset($data['website_id']);
  6438. //处理数组
  6439. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6440. if ($data['img_url'] == '') {
  6441. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6442. preg_match_all($reg, $data['detail'], $matches);
  6443. if (isset($matches[1][0])) {
  6444. //截取varchar240
  6445. $data['img_url'] = substr($matches[1][0], 0, 240);
  6446. }
  6447. }
  6448. if ($data['keyword'] == '') {
  6449. //提取标题+内容中的关键词
  6450. $data['keyword'] = $data['title'];
  6451. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6452. Jieba::init(); // 初始化 jieba-php
  6453. Finalseg::init();
  6454. $segList = Jieba::cut($data['keyword']);
  6455. $segList1 = array_slice($segList, 0, 8);
  6456. $data['keyword'] = implode(',', $segList1);
  6457. }
  6458. if ($data['description'] == '') {
  6459. //提取内容中的描述
  6460. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6461. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6462. }
  6463. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6464. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6465. if ($data['status'] == 1) {
  6466. $this->sendMessage([
  6467. 'talk_type' => 400,
  6468. 'title' => $data['title'],
  6469. 'content' => '提交了审核',
  6470. 'messageType' => 7,
  6471. ]);
  6472. }
  6473. $result = Book::where("id", $data["id"])->update($data);
  6474. if (empty($result)) {
  6475. return Result::error("更新失败", 0);
  6476. }
  6477. return Result::success($result);
  6478. }
  6479. public function getBookInfo(array $data): array
  6480. {
  6481. $result = Book::where("id", $data["id"])->first();
  6482. if (empty($result)) {
  6483. return Result::error("获取失败", 0);
  6484. }
  6485. return Result::success($result);
  6486. }
  6487. public function updateBookStatus(array $data): array
  6488. {
  6489. //审核
  6490. unset($data['user_id']);
  6491. $bookInfo = Book::where("id", $data["id"])->first();
  6492. var_dump($bookInfo, '----');
  6493. if ($data['status'] == 2) {
  6494. $this->sendMessage([
  6495. 'talk_type' => 401,
  6496. 'title' => $bookInfo['title'],
  6497. 'content' => '审核通过',
  6498. 'messageType' => 7,
  6499. 'user_id' => $bookInfo['user_id'],
  6500. ]);
  6501. }
  6502. if ($data['status'] == 3) {
  6503. $this->sendMessage([
  6504. 'talk_type' => 401,
  6505. 'title' => $bookInfo['title'],
  6506. 'content' => '审核拒绝',
  6507. 'messageType' => 7,
  6508. 'user_id' => $bookInfo['user_id'],
  6509. ]);
  6510. }
  6511. if ($data['status'] == 1) {
  6512. $this->sendMessage([
  6513. 'talk_type' => 400,
  6514. 'title' => $bookInfo['title'],
  6515. 'content' => '提交了审核',
  6516. 'messageType' => 7,
  6517. // 'user_id'=>$bookInfo['user_id'],
  6518. ]);
  6519. }
  6520. $result = Book::where("id", $data["id"])->update($data);
  6521. if (empty($result)) {
  6522. return Result::error("更新失败", 0);
  6523. }
  6524. return Result::success($result);
  6525. }
  6526. //20250422 书刊音像
  6527. /**
  6528. * 贴身宝贝
  6529. * @param array $data
  6530. * @return array
  6531. */
  6532. public function getWebsiteTsbb(array $data): array
  6533. {
  6534. $month = $data['month'] ?? date('m');
  6535. $day = $data['day'] ?? date('d');
  6536. // 使用缓存键
  6537. $cacheKey = "tsbb_data_{$month}_{$day}";
  6538. // 尝试从缓存获取数据
  6539. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6540. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6541. if ($cachedData = $cache->get($cacheKey)) {
  6542. return Result::success(unserialize($cachedData));
  6543. }
  6544. //查询老黄历
  6545. try {
  6546. $date = date('Y-m-d');
  6547. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6548. // 使用 curl 替代 file_get_contents
  6549. $ch = curl_init();
  6550. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6551. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6552. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6553. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6554. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6555. 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');
  6556. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6557. 'Accept: application/json',
  6558. 'Content-Type: application/json',
  6559. 'Referer: https://www.36jxs.com/'
  6560. ]);
  6561. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6562. curl_setopt($ch, CURLOPT_ENCODING, '');
  6563. $almanacResponse = curl_exec($ch);
  6564. var_dump("====:", $almanacResponse);
  6565. if (curl_errno($ch)) {
  6566. var_dump('Curl error:', curl_error($ch));
  6567. throw new \Exception('Curl error: ' . curl_error($ch));
  6568. }
  6569. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6570. curl_close($ch);
  6571. if ($almanacResponse === false) {
  6572. throw new \Exception('Failed to fetch almanac data');
  6573. }
  6574. $almanacData = json_decode($almanacResponse, true);
  6575. if (json_last_error() !== JSON_ERROR_NONE) {
  6576. throw new \Exception('Failed to parse almanac data');
  6577. }
  6578. $almanacInfo = $almanacData['data'] ?? [];
  6579. } catch (\Exception $e) {
  6580. var_dump('Exception:', $e->getMessage());
  6581. $almanacInfo = [];
  6582. }
  6583. // 获取历史上的今天数据
  6584. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6585. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6586. ->orderBy('year', 'asc')
  6587. ->select("title", "id", "year", DB::raw('1 as type'))
  6588. ->limit(16)
  6589. ->get();
  6590. // 获取节日数据 - 从今天开始获取未来4条
  6591. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6592. ->orderBy('showtime', 'asc')
  6593. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6594. ->limit(16)
  6595. ->get();
  6596. //说文解字
  6597. $chartacterList = Character::orderBy('updated_at', 'desc')
  6598. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6599. ->limit(6)
  6600. ->get();
  6601. //谜语沙龙
  6602. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6603. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6604. ->limit(4)
  6605. ->get();
  6606. //成语欣赏
  6607. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6608. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6609. ->limit(32)
  6610. ->get();
  6611. //名联赏析
  6612. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6613. ->select("id", "first", "second", DB::raw('6 as type'))
  6614. ->limit(6)
  6615. ->get();
  6616. // 获取分类文章数据
  6617. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6618. ->pluck('category_id')
  6619. ->toArray();
  6620. $articlesList = [];
  6621. foreach ($categoryIds as $catid) {
  6622. // 先查有图片的
  6623. $withImg = DB::table('article')
  6624. ->where('status', 1)
  6625. ->where('catid', $catid)
  6626. ->whereNotNull('imgurl')
  6627. ->where('imgurl', '!=', '')
  6628. ->orderBy('updated_at', 'desc')
  6629. ->limit(6)
  6630. ->get();
  6631. $count = $withImg->count();
  6632. if ($count < 6) {
  6633. // 不足6条再查无图片的补足
  6634. $withoutImg = DB::table('article')
  6635. ->where('status', 1)
  6636. ->where('catid', $catid)
  6637. ->where(function ($q) {
  6638. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6639. })
  6640. ->orderBy('updated_at', 'desc')
  6641. ->limit(6 - $count)
  6642. ->get();
  6643. $articles = $withImg->concat($withoutImg);
  6644. } else {
  6645. $articles = $withImg;
  6646. }
  6647. // 组装
  6648. $category = \App\Model\Category::find($catid);
  6649. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6650. $articlesList[] = [
  6651. 'category_name' => $category ? $category->name : '',
  6652. 'catid' => $catid,
  6653. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6654. 'type' => 100,
  6655. 'list' => $articles->map(function ($item) {
  6656. return [
  6657. 'id' => $item->id,
  6658. 'title' => $item->title,
  6659. 'imgurl' => $item->imgurl,
  6660. 'created_at' => $item->created_at
  6661. ];
  6662. })->values()
  6663. ];
  6664. }
  6665. $result = [
  6666. 'almanac' => $almanacInfo,
  6667. 'historyTodayList' => [
  6668. 'category_name' => '历史上的今天',
  6669. 'list' => $historyTodayList,
  6670. 'type' => 1
  6671. ],
  6672. 'festivalList' => [
  6673. 'category_name' => '节日预告',
  6674. 'list' => $festivalList,
  6675. 'type' => 2
  6676. ],
  6677. 'chartacterList' => [
  6678. 'category_name' => '说文解字',
  6679. 'list' => $chartacterList,
  6680. 'type' => 3
  6681. ],
  6682. 'coupletList' => [
  6683. 'category_name' => '名联赏析',
  6684. 'list' => $coupletList,
  6685. 'type' => 6
  6686. ],
  6687. 'riddletList' => [
  6688. 'category_name' => '谜语沙龙',
  6689. 'list' => $riddletList,
  6690. 'type' => 4
  6691. ],
  6692. 'idiomList' => [
  6693. 'category_name' => '成语欣赏',
  6694. 'list' => $idiomList,
  6695. 'type' => 5
  6696. ],
  6697. 'articlesList' => $articlesList
  6698. ];
  6699. // 缓存结果,设置1小时过期
  6700. $cache->set($cacheKey, serialize($result), 3600);
  6701. return Result::success($result);
  6702. }
  6703. /**
  6704. * 获取资讯列表
  6705. */
  6706. public function getWebsiteTsbbList(array $data): array
  6707. {
  6708. $page = $data['page'] ?? 1;
  6709. $pageSize = $data['pageSize'] ?? 10;
  6710. // 如果没有传入月份和日期,则使用今天的日期
  6711. $month = $data['month'] ?? date('m');
  6712. $day = $data['day'] ?? date('d');
  6713. $total = 0;
  6714. $result = [];
  6715. $data['type'] = intval($data['type']);
  6716. var_dump("接收参数:", $data);
  6717. switch ($data['type']) {
  6718. case 1:
  6719. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6720. // 当前月份之后的数据
  6721. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6722. // 或者当前月份且日期大于等于当前日期的数据
  6723. ->orWhere(function ($q) use ($month, $day) {
  6724. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6725. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6726. });
  6727. })
  6728. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6729. $total = $query->count();
  6730. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6731. ->offset(($page - 1) * $pageSize)
  6732. ->limit($pageSize)
  6733. ->get();
  6734. break;
  6735. case 2:
  6736. $query = Festival::where(function ($q) use ($month, $day) {
  6737. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6738. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6739. ->orWhere(function ($q) use ($month, $day) {
  6740. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6741. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6742. });
  6743. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6744. $total = $query->count();
  6745. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6746. ->offset(($page - 1) * $pageSize)
  6747. ->limit($pageSize)
  6748. ->get();
  6749. break;
  6750. case 3:
  6751. $query = Character::orderBy("updated_at", "desc");
  6752. $total = $query->count();
  6753. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6754. ->offset(($page - 1) * $pageSize)
  6755. ->limit($pageSize)
  6756. ->get();
  6757. break;
  6758. case 4:
  6759. $query = Riddle::orderBy("updated_at", "desc");
  6760. $total = $query->count();
  6761. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6762. ->offset(($page - 1) * $pageSize)
  6763. ->limit($pageSize)
  6764. ->get();
  6765. break;
  6766. case 5:
  6767. $query = Idiom::orderBy("updated_at", "desc");
  6768. $total = $query->count();
  6769. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6770. ->offset(($page - 1) * $pageSize)
  6771. ->limit($pageSize)
  6772. ->get();
  6773. break;
  6774. case 6:
  6775. $query = Couplet::orderBy("updated_at", "desc");
  6776. $total = $query->count();
  6777. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6778. ->offset(($page - 1) * $pageSize)
  6779. ->limit($pageSize)
  6780. ->get();
  6781. break;
  6782. default:
  6783. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6784. $total = $query->count();
  6785. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6786. ->offset(($page - 1) * $pageSize)
  6787. ->limit($pageSize)
  6788. ->get();
  6789. }
  6790. return Result::success([
  6791. 'list' => $result,
  6792. 'total' => $total,
  6793. 'page' => (int)$page,
  6794. 'pageSize' => (int)$pageSize,
  6795. 'month' => $month,
  6796. 'day' => $day
  6797. ]);
  6798. }
  6799. /**
  6800. * 1:历史上的今天
  6801. * 2:节日
  6802. * 3:文章
  6803. *
  6804. * 资讯详情信息
  6805. */
  6806. public function getWebsiteTsbbDetail(array $data): array
  6807. {
  6808. $data['type'] = intval($data['type']);
  6809. switch ($data['type']) {
  6810. case 1:
  6811. $result = HistoryToday::where("id", $data['id'])->first();
  6812. break;
  6813. case 2:
  6814. $result = Festival::where("id", $data['id'])->first();
  6815. break;
  6816. case 3:
  6817. $result = Character::where("id", $data['id'])->first();
  6818. break;
  6819. case 4:
  6820. $result = Riddle::where("id", $data['id'])->first();
  6821. break;
  6822. case 5:
  6823. $result = Idiom::where("id", $data['id'])->first();
  6824. break;
  6825. case 6:
  6826. $result = Couplet::where("id", $data['id'])->first();
  6827. break;
  6828. default:
  6829. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6830. break;
  6831. }
  6832. return Result::success($result);
  6833. }
  6834. /**
  6835. * 农网导航首页数据
  6836. */
  6837. public function getWebsiteNwHomeList(array $data): array
  6838. {
  6839. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6840. ->pluck('category_id')
  6841. ->toArray();
  6842. // 使用子查询优化
  6843. $articlesList = DB::table('article')
  6844. ->select([
  6845. 'article.id',
  6846. 'article.title',
  6847. 'article.imgurl',
  6848. 'article.created_at',
  6849. 'category.name as category_name',
  6850. 'category.id as category_id',
  6851. 'website_category.aLIas_pinyin as pinyin',
  6852. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6853. DB::raw('100 as type')
  6854. ])
  6855. ->join('category', 'article.catid', '=', 'category.id')
  6856. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6857. ->leftJoin('website_category as parent_wc', function ($join) {
  6858. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6859. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6860. })
  6861. ->where('website_category.website_id', $data['website_id'])
  6862. ->where('article.status', 1)
  6863. ->whereIn('category.id', $categoryIds)
  6864. ->orderBy('article.created_at', 'desc')
  6865. ->get()
  6866. ->groupBy('category_id')
  6867. ->map(function ($group) {
  6868. // 确保第一条数据有图片
  6869. $firstWithImage = $group->first(function ($item) {
  6870. return !empty($item->imgurl);
  6871. });
  6872. if ($firstWithImage) {
  6873. // 如果有带图片的文章,将其放在第一位
  6874. $group = $group->filter(function ($item) use ($firstWithImage) {
  6875. return $item->id !== $firstWithImage->id;
  6876. })->prepend($firstWithImage);
  6877. }
  6878. return [
  6879. 'category_name' => $group->first()->category_name,
  6880. 'catid' => $group->first()->category_id,
  6881. 'pinyin' => $group->first()->pinyin,
  6882. 'parent_pinyin' => $group->first()->parent_pinyin,
  6883. 'list' => $group->take(4)->map(function ($item) {
  6884. return [
  6885. 'id' => $item->id,
  6886. 'title' => $item->title,
  6887. ];
  6888. })->values()
  6889. ];
  6890. })
  6891. ->values()
  6892. ->toArray();
  6893. return Result::success($articlesList);
  6894. }
  6895. /**
  6896. * 企业管理
  6897. * @param array $data
  6898. * @return array
  6899. */
  6900. public function getCompanyList(array $data): array
  6901. {
  6902. // return Result::success($data);
  6903. $where = [];
  6904. $user = User::where('id', $data['user_id'])->first();
  6905. if (empty($user)) {
  6906. return Result::error('用户不存在!');
  6907. }
  6908. if ($user['type_id'] != 10000) {
  6909. $where['user_id'] = $data['user_id'];
  6910. }
  6911. if (isset($data['title']) && !empty($data['title'])) {
  6912. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6913. }
  6914. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6915. array_push($where, ['website.id', $data['website_id']]);
  6916. }
  6917. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6918. if ($data['ischeck'] == 1) {
  6919. if (isset($data['status']) && $data['status'] != '') {
  6920. array_push($where, ['company.status', $data['status']]);
  6921. $query = Company::where($where);
  6922. } else {
  6923. $query = Company::whereIn('company.status', [0, 2]);
  6924. }
  6925. } else {
  6926. $query = Company::where('company.status', 1);
  6927. }
  6928. }
  6929. $result = $query->where($where)
  6930. ->leftJoin('website_category', function ($query) {
  6931. $query->on('website_category.category_id', '=', 'company.category_id')
  6932. ->on('website_category.website_id', '=', 'company.website_id');
  6933. })
  6934. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6935. ->select(
  6936. 'company.id',
  6937. 'company.title',
  6938. 'company.website_id',
  6939. 'company.category_id',
  6940. 'website.website_name',
  6941. 'website_category.alias as category_name',
  6942. 'company.status',
  6943. 'company.updated_at',
  6944. 'company.user_id'
  6945. )
  6946. ->orderBy('company.updated_at', 'desc')
  6947. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6948. if ($result->isEmpty()) {
  6949. return Result::error("暂无企业", 0);
  6950. }
  6951. return Result::success($result);
  6952. }
  6953. /**
  6954. * 添加企业
  6955. * @param array $data
  6956. * @return array
  6957. */
  6958. public function addCompany(array $data): array
  6959. {
  6960. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  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. } else {
  6965. $data['cat_arr_id'] = '';
  6966. }
  6967. if ($data['imgurl'] == '') {
  6968. //content中提取图片第一个图,正则提取
  6969. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6970. preg_match_all($reg, $data['content'], $matches);
  6971. if (isset($matches[1][0])) {
  6972. //截取varchar240
  6973. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6974. }
  6975. }
  6976. if ($data['keyword'] == '') {
  6977. //提取标题+内容中的关键词
  6978. $data['keyword'] = $data['title'];
  6979. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6980. Jieba::init(); // 初始化 jieba-php
  6981. Finalseg::init();
  6982. $segList = Jieba::cut($data['keyword']);
  6983. $segList1 = array_slice($segList, 0, 8);
  6984. $data['keyword'] = implode(',', $segList1);
  6985. }
  6986. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6987. //提取内容中的描述
  6988. $content = $data['content'];
  6989. // 去除 <style> 和 <script> 标签及其内容
  6990. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6991. // 去除所有 HTML 标签
  6992. $content = strip_tags($content);
  6993. // 去除 HTML 实体
  6994. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6995. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6996. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6997. // 去除多余空白
  6998. $content = preg_replace('/\s+/u', '', $content);
  6999. // 截取 100 个字符
  7000. $data['introduce'] = mb_substr($content, 0, 100);
  7001. }
  7002. $user = User::where('id', $data['user_id'])->first();
  7003. if (empty($user)) {
  7004. return Result::error('用户不存在!');
  7005. }
  7006. if ($user['type_id'] == 10000) {
  7007. $data['status'] = 1;
  7008. }
  7009. if (isset($data['level']) && $data['level'] != null) {
  7010. $data['level'] = intval($data['level']);
  7011. } else {
  7012. $data['level'] = null;
  7013. }
  7014. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7015. $this->sendMessage([
  7016. 'talk_type' => 900,
  7017. 'title' => $data['title'],
  7018. 'content' => '提交了审核',
  7019. 'messageType' => 8,
  7020. ]);
  7021. }
  7022. $result = Company::insertGetId($data);
  7023. if ($result) {
  7024. return Result::success($result);
  7025. } else {
  7026. return Result::error('添加失败');
  7027. }
  7028. }
  7029. /**
  7030. * 更新企业
  7031. * @param array $data
  7032. * @return array
  7033. */
  7034. public function upCompany(array $data): array
  7035. {
  7036. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7037. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7038. $data['cat_arr_id'] = json_encode($car_arr_id);
  7039. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7040. } else {
  7041. $data['cat_arr_id'] = '';
  7042. }
  7043. if ($data['imgurl'] == '') {
  7044. //content中提取图片第一个图,正则提取
  7045. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7046. preg_match_all($reg, $data['content'], $matches);
  7047. if (isset($matches[1][0])) {
  7048. //截取varchar
  7049. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7050. }
  7051. }
  7052. if ($data['keyword'] == '') {
  7053. //提取标题+内容中的关键词
  7054. $data['keyword'] = $data['title'];
  7055. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7056. Jieba::init(); // 初始化 jieba-php
  7057. Finalseg::init();
  7058. $segList = Jieba::cut($data['keyword']);
  7059. $segList1 = array_slice($segList, 0, 8);
  7060. $data['keyword'] = implode(',', $segList1);
  7061. }
  7062. if ($data['introduce'] == '') {
  7063. //提取内容中的描述
  7064. $content = $data['content'];
  7065. // 去除 <style> 和 <script> 标签及其内容
  7066. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7067. // 去除所有 HTML 标签
  7068. $content = strip_tags($content);
  7069. // 去除 HTML 实体
  7070. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7071. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7072. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7073. // 去除多余空白
  7074. $content = preg_replace('/\s+/u', '', $content);
  7075. // 截取 100 个字符
  7076. $data['introduce'] = mb_substr($content, 0, 100);
  7077. }
  7078. if (isset($data['level']) && $data['level'] != null) {
  7079. $data['level'] = intval($data['level']);
  7080. } else {
  7081. $data['level'] = null;
  7082. }
  7083. $user = User::where('id', $data['user_id'])->first();
  7084. if (empty($user)) {
  7085. return Result::error('用户不存在!');
  7086. }
  7087. if ($user['type_id'] == 10000) {
  7088. $data['status'] = 1;
  7089. } else {
  7090. $data['status'] = 0;
  7091. }
  7092. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7093. $this->sendMessage([
  7094. 'talk_type' => 900,
  7095. 'title' => $data['title'],
  7096. 'content' => '提交了审核',
  7097. 'messageType' => 8,
  7098. ]);
  7099. }
  7100. $result = Company::where('id', $data['id'])->update($data);
  7101. if ($result) {
  7102. return Result::success($result);
  7103. } else {
  7104. return Result::error('修改失败');
  7105. }
  7106. }
  7107. /**
  7108. * 删除企业
  7109. * @param array $data
  7110. * @return array
  7111. */
  7112. public function delCompany(array $data): array
  7113. {
  7114. $result = Company::where('id', $data['id'])->delete();
  7115. if ($result) {
  7116. return Result::success($result);
  7117. } else {
  7118. return Result::error('删除失败');
  7119. }
  7120. }
  7121. /**
  7122. * 审核企业
  7123. * @param array $data
  7124. * @return array
  7125. */
  7126. public function checkCompany(array $data): array
  7127. {
  7128. $user = User::where('id', $data['user_id'])->first();
  7129. if (empty($user)) {
  7130. return Result::error('用户不存在!');
  7131. }
  7132. $company = Company::where('id', $data['id'])->first();
  7133. if (empty($company)) {
  7134. return Result::error('企业不存在!');
  7135. }
  7136. // 状态:0:未审核 1:已审核 2:已拒绝
  7137. if ($data['status'] == 2 || $data['status'] == '2') {
  7138. $this->sendMessage([
  7139. 'talk_type' => 901,
  7140. 'title' => $company['title'],
  7141. 'content' => '审核拒绝',
  7142. 'messageType' => 8,
  7143. 'user_id' => $company['user_id'],
  7144. ]);
  7145. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7146. } else {
  7147. if ($data['status'] == 1) {
  7148. $this->sendMessage([
  7149. 'talk_type' => 901,
  7150. 'title' => $company['title'],
  7151. 'content' => '审核通过',
  7152. 'messageType' => 8,
  7153. 'user_id' => $company['user_id'],
  7154. ]);
  7155. } else if ($data['status'] == 0) {
  7156. $this->sendMessage([
  7157. 'talk_type' => 900,
  7158. 'title' => $company['title'],
  7159. 'content' => '提交了审核',
  7160. 'messageType' => 8,
  7161. ]);
  7162. }
  7163. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7164. }
  7165. if (empty($result)) {
  7166. return Result::error('审核失败!');
  7167. } else {
  7168. return Result::success($result);
  7169. }
  7170. }
  7171. /**
  7172. * 获取企业信息
  7173. * @param array $data
  7174. * @return array
  7175. */
  7176. public function getCompanyInfo(array $data): array
  7177. {
  7178. $result = Company::where('id', $data['id'])->first();
  7179. $city_arr = json_decode($result['city_arr_id']);
  7180. $result['city_name'] = District::whereIn('id', $city_arr)
  7181. ->pluck('name')
  7182. ->implode('-');
  7183. if (empty($result)) {
  7184. return Result::error('企业不存在!');
  7185. } else {
  7186. return Result::success($result);
  7187. }
  7188. }
  7189. /**
  7190. * @param array $data
  7191. * @return array
  7192. */
  7193. public function getWebsiteCompany(array $data): array
  7194. {
  7195. $categorys = json_decode($data['id'], true);
  7196. $category_arr = $this->processArticlePro($data['website_id']);
  7197. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7198. $catiall = $category_arr['catiall'];
  7199. $categoryIds = $category_arr['categoryIds'];
  7200. // return Result::success($category_arr);
  7201. foreach ($categorys as $key => $value) {
  7202. if (array_key_exists('level', $value)) {
  7203. $parts = explode(',', $value['level']);
  7204. $level = $parts[0] ?? null;
  7205. $imgnum = $parts[1] ?? null;
  7206. $textnum = $parts[2] ?? null;
  7207. if (!empty($textnum) && $textnum > 0) {
  7208. $text_num = Company::where('level', $level)
  7209. ->whereIn('category_id', $categoryIds)
  7210. ->where('status', 1)
  7211. ->select(
  7212. 'company.id',
  7213. 'company.title',
  7214. 'company.description',
  7215. 'company.updated_at',
  7216. 'company.category_id',
  7217. 'company.cat_arr_id'
  7218. )
  7219. ->orderBy('updated_at', 'desc')
  7220. ->limit($textnum)
  7221. ->get()->all();
  7222. }
  7223. if (!empty($imgnum) && $imgnum > 0) {
  7224. $img_num = Company::where('level', $level)
  7225. ->whereIn('category_id', $categoryIds)
  7226. ->where('status', 1)
  7227. ->where('imgurl', '!=', '')
  7228. ->whereNotNull('imgurl')
  7229. ->select(
  7230. 'company.id',
  7231. 'company.title',
  7232. 'company.description',
  7233. 'company.updated_at',
  7234. 'company.imgurl as imgs',
  7235. 'company.category_id',
  7236. 'company.cat_arr_id'
  7237. )
  7238. ->orderBy('updated_at', 'desc')
  7239. ->limit($imgnum)
  7240. ->get()->all();
  7241. }
  7242. }
  7243. if (array_key_exists('id', $value)) {
  7244. $parts = explode(',', $value['id']);
  7245. $category_id = $parts[0] ?? null;
  7246. $imgnum = $parts[1] ?? null;
  7247. $textnum = $parts[2] ?? null;
  7248. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7249. if (!empty($textnum) && $textnum > 0) {
  7250. $text_num = Company::whereIn('category_id', $category_arr)
  7251. // ->where('website_id', $data['website_id'])
  7252. ->where('status', 1)
  7253. ->select(
  7254. 'company.id',
  7255. 'company.title',
  7256. 'company.description',
  7257. 'company.updated_at',
  7258. 'company.category_id',
  7259. 'company.cat_arr_id'
  7260. )
  7261. ->orderBy('updated_at', 'desc')
  7262. ->limit($textnum)
  7263. ->get()->all();
  7264. }
  7265. if (!empty($imgnum) && $imgnum > 0) {
  7266. $img_num = Company::whereIn('category_id', $category_arr)
  7267. // ->where('website_id', $data['website_id'])
  7268. ->where('status', 1)
  7269. ->where('imgurl', '!=', '')
  7270. ->whereNotNull('imgurl')
  7271. ->select(
  7272. 'company.id',
  7273. 'company.title',
  7274. 'company.description',
  7275. 'company.updated_at',
  7276. 'company.imgurl as imgs',
  7277. 'company.category_id',
  7278. 'company.cat_arr_id'
  7279. )
  7280. ->orderBy('updated_at', 'desc')
  7281. ->limit($imgnum)
  7282. ->get()->all();
  7283. }
  7284. }
  7285. if (!empty($text_num)) {
  7286. foreach ($text_num as $k => $v) {
  7287. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7288. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7289. }
  7290. }
  7291. if (!empty($img_num)) {
  7292. foreach ($img_num as $k => $v) {
  7293. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7294. $imgurl = json_decode($v['imgs'], true);
  7295. if (!empty($imgurl)) {
  7296. $img_num[$k]->imgurl = $imgurl[0];
  7297. }
  7298. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7299. }
  7300. }
  7301. $company[$key]['img_num'] = $img_num ?? [];
  7302. $company[$key]['text_num'] = $text_num ?? [];
  7303. }
  7304. if (empty($company)) {
  7305. return Result::error("暂无相关企业信息", 0);
  7306. }
  7307. return Result::success($company);
  7308. }
  7309. /**
  7310. * @param array $data
  7311. * @return array
  7312. */
  7313. public function getWebsiteCompanyList(array $data): array
  7314. {
  7315. $where['website_id'] = $data['website_id'];
  7316. $where['status'] = 1;
  7317. $categoryIds = [];
  7318. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7319. $category_id = $data['category_id'];
  7320. }
  7321. $category_arr = $this->processArticlePro($data['website_id']);
  7322. $categoryIds = $category_arr['categoryIds'];
  7323. // return Result::success($cat_1st_arr);
  7324. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7325. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7326. })
  7327. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7328. $query->whereIn('category_id', $categoryIds);
  7329. })
  7330. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7331. $query->where('category_id', $category_id);
  7332. })
  7333. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7334. ->orderBy('updated_at', 'desc')
  7335. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7336. if (empty($company)) {
  7337. return Result::error("暂无相关公司信息", 0);
  7338. }
  7339. $result = [
  7340. 'count' => $company->total(),
  7341. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7342. ];
  7343. return Result::success($result);
  7344. }
  7345. /**
  7346. * 获取项目列表
  7347. * @param array $data
  7348. * @return array
  7349. */
  7350. public function getProjectList(array $data): array
  7351. {
  7352. $where = [];
  7353. $user = User::where('id', $data['user_id'])->first();
  7354. if (empty($user)) {
  7355. return Result::error('用户不存在!');
  7356. }
  7357. if ($user->type_id != 10000) {
  7358. array_push($where, ['project.user_id', $data['user_id']]);
  7359. }
  7360. $query = Project::query();
  7361. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7362. array_push($where, ['project.website_id', $data['website_id']]);
  7363. }
  7364. if (isset($data['title']) && !empty($data['title'])) {
  7365. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7366. }
  7367. if ($data['status'] != 3) {
  7368. array_push($where, ['project.status', $data['status']]);
  7369. }
  7370. $query = Project::where($where)
  7371. ->when($data['status'] == 3, function ($query) {
  7372. $query->whereIn('project.status', [0, 2]);
  7373. });
  7374. $count = $query->clone()
  7375. ->count();
  7376. $rows = $query->clone()
  7377. ->leftJoin('website', 'project.website_id', 'website.id')
  7378. ->leftJoin('website_category', function ($join) {
  7379. $join->on('project.website_id', '=', 'website_category.website_id')
  7380. ->on('project.category_id', '=', 'website_category.category_id');
  7381. })
  7382. ->select(
  7383. 'project.id',
  7384. 'project.title',
  7385. 'project.updated_at',
  7386. 'project.status',
  7387. 'website.website_name',
  7388. 'website_category.alias as category_name',
  7389. 'project.website_id',
  7390. 'project.user_id'
  7391. )
  7392. ->orderBy('project.updated_at', 'desc')
  7393. ->offset(($data['page'] - 1) * $data['pageSize'])
  7394. ->limit($data['pageSize'])
  7395. ->get();
  7396. if ($rows->isEmpty()) {
  7397. return Result::error("暂无相关项目信息", 0);
  7398. }
  7399. $result = [
  7400. 'count' => $count,
  7401. 'rows' => $rows,
  7402. ];
  7403. return Result::success($result);
  7404. }
  7405. /**
  7406. * 添加项目
  7407. * @param array $data
  7408. * @return array
  7409. */
  7410. public function addProject(array $data): array
  7411. {
  7412. $user = User::where('id', $data['user_id'])->first();
  7413. if (empty($user)) {
  7414. return Result::error("暂无相关用户信息", 0);
  7415. }
  7416. if ($user->type_id == 10000) {
  7417. $data['status'] = 1;
  7418. } else {
  7419. $data['status'] = 0;
  7420. }
  7421. if ($data['keyword'] == '') {
  7422. //提取标题+内容中的关键词
  7423. $data['keyword'] = $data['title'];
  7424. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7425. Jieba::init(); // 初始化 jieba-php
  7426. Finalseg::init();
  7427. $segList = Jieba::cut($data['keyword']);
  7428. $segList1 = array_slice($segList, 0, 8);
  7429. $data['keyword'] = implode(',', $segList1);
  7430. }
  7431. if ($data['description'] == '') {
  7432. //提取内容中的描述
  7433. // var_dump(11111);
  7434. //提取内容中的描述
  7435. $content = $data['introduce'];
  7436. // 去除 <style> 和 <script> 标签及其内容
  7437. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7438. // 去除所有 HTML 标签
  7439. $content = strip_tags($content);
  7440. // 去除 HTML 实体
  7441. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7442. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7443. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7444. // 去除多余空白
  7445. $content = preg_replace('/\s+/u', '', $content);
  7446. // 截取 100 个字符
  7447. $data['description'] = mb_substr($content, 0, 100);
  7448. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7449. }
  7450. if ($data['status'] == 0) {
  7451. $this->sendMessage([
  7452. 'talk_type' => 1000,
  7453. 'title' => $data['title'],
  7454. 'content' => '提交了审核',
  7455. 'messageType' => 9,
  7456. ]);
  7457. }
  7458. $project = Project::insertGetId($data);
  7459. if (empty($project)) {
  7460. return Result::error("暂无相关项目信息", 0);
  7461. }
  7462. return Result::success($project);
  7463. }
  7464. /**
  7465. * 更新项目
  7466. * @param array $data
  7467. * @return array
  7468. */
  7469. public function upProject(array $data): array
  7470. {
  7471. $project = Project::where('id', $data['id'])->first();
  7472. if (empty($project)) {
  7473. return Result::error("暂无相关项目信息", 0);
  7474. }
  7475. $id = $data['id'];
  7476. unset($data['id']);
  7477. $user = User::where('id', $data['user_id'])->first();
  7478. if (empty($user)) {
  7479. return Result::error("暂无相关用户信息", 0);
  7480. }
  7481. if ($user->type_id == 10000) {
  7482. $data['status'] = 1;
  7483. } else {
  7484. $data['status'] = 0;
  7485. }
  7486. unset($data['user_id']);
  7487. if ($data['keyword'] == '') {
  7488. //提取标题+内容中的关键词
  7489. $data['keyword'] = $data['title'];
  7490. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7491. Jieba::init(); // 初始化 jieba-php
  7492. Finalseg::init();
  7493. $segList = Jieba::cut($data['keyword']);
  7494. $segList1 = array_slice($segList, 0, 8);
  7495. $data['keyword'] = implode(',', $segList1);
  7496. }
  7497. if ($data['description'] == '') {
  7498. //提取内容中的描述
  7499. // var_dump(11111);
  7500. //提取内容中的描述
  7501. $content = $data['introduce'];
  7502. // 去除 <style> 和 <script> 标签及其内容
  7503. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7504. // 去除所有 HTML 标签
  7505. $content = strip_tags($content);
  7506. // 去除 HTML 实体
  7507. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7508. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7509. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7510. // 去除多余空白
  7511. $content = preg_replace('/\s+/u', '', $content);
  7512. // 截取 100 个字符
  7513. $data['description'] = mb_substr($content, 0, 100);
  7514. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7515. }
  7516. if ($data['status'] == 0) {
  7517. $this->sendMessage([
  7518. 'talk_type' => 1000,
  7519. 'title' => $data['title'],
  7520. 'content' => '提交了审核',
  7521. 'messageType' => 9,
  7522. ]);
  7523. }
  7524. $result = Project::where('id', $id)->update($data);
  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 delProject(array $data): array
  7536. {
  7537. $user = User::where('id', $data['user_id'])->first();
  7538. if (empty($user)) {
  7539. return Result::error("暂无相关用户信息", 0);
  7540. }
  7541. $project = Project::where('id', $data['id'])->first();
  7542. if (empty($project)) {
  7543. return Result::error("暂无相关项目信息", 0);
  7544. }
  7545. $result = Project::where('id', $data['id'])->delete();
  7546. if (empty($result)) {
  7547. return Result::error("删除失败", 0);
  7548. }
  7549. return Result::success($result);
  7550. }
  7551. /**
  7552. * 审核项目
  7553. * @param array $data
  7554. * @return array
  7555. */
  7556. public function checkProject(array $data): array
  7557. {
  7558. $user = User::where('id', $data['user_id'])->first();
  7559. if (empty($user)) {
  7560. return Result::error("暂无相关用户信息", 0);
  7561. }
  7562. // 0:未审核; 1:已审核; 2:已拒绝;
  7563. if ($user->type_id != 10000) {
  7564. if ($data['status'] == 1 || $data['status'] == 2) {
  7565. return Result::error("此用户权限不足", 0);
  7566. }
  7567. }
  7568. $project = Project::where('id', $data['id'])->first();
  7569. if (empty($project)) {
  7570. return Result::error("暂无相关项目信息", 0);
  7571. }
  7572. if ($data['status'] == 2) {
  7573. $this->sendMessage([
  7574. 'talk_type' => 1001,
  7575. 'title' => $project['title'],
  7576. 'content' => '审核拒绝',
  7577. 'messageType' => 9,
  7578. 'user_id' => $project['user_id'],
  7579. ]);
  7580. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7581. } else {
  7582. if ($data['status'] == 1) {
  7583. $this->sendMessage([
  7584. 'talk_type' => 1001,
  7585. 'title' => $project['title'],
  7586. 'content' => '审核通过',
  7587. 'messageType' => 9,
  7588. 'user_id' => $project['user_id'],
  7589. ]);
  7590. } else if ($data['status'] == 0) {
  7591. $this->sendMessage([
  7592. 'talk_type' => 1000,
  7593. 'title' => $project['title'],
  7594. 'content' => '提交了审核',
  7595. 'messageType' => 9,
  7596. ]);
  7597. }
  7598. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7599. }
  7600. if (empty($result)) {
  7601. return Result::error("审核失败", 0);
  7602. }
  7603. return Result::success($result);
  7604. }
  7605. /**
  7606. * 获取项目详情
  7607. * @param array $data
  7608. * @return array
  7609. */
  7610. public function getProjectInfo(array $data): array
  7611. {
  7612. $project = Project::where('id', $data['id'])->first();
  7613. if (empty($project)) {
  7614. return Result::error("暂无相关项目信息", 0);
  7615. }
  7616. return Result::success($project);
  7617. }
  7618. public function getWebsiteCompanyInfo(array $data): array
  7619. {
  7620. $company = Company::where('id', $data['id'])
  7621. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7622. ->where('status', 1)
  7623. // ->where('website_id', $data['website_id'])
  7624. ->select('company.*', 'job_industry.hyname as hy_name')
  7625. ->first();
  7626. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7627. switch ($company->jobnature_id) {
  7628. case null:
  7629. $company->jobnature_name = '';
  7630. break;
  7631. case 0:
  7632. $company->jobnature_name = '市场监督';
  7633. break;
  7634. case 1:
  7635. $company->jobnature_name = '信访纪检';
  7636. break;
  7637. case 2:
  7638. $company->jobnature_name = '公检法司';
  7639. break;
  7640. case 3:
  7641. $company->jobnature_name = '高关注机构';
  7642. break;
  7643. default:
  7644. $company->jobnature_name = '';
  7645. break;
  7646. }
  7647. $city_arr = $company->city_arr_id;
  7648. if (!empty($city_arr)) {
  7649. $city_arr = json_decode($city_arr, true);
  7650. $cityNames = District::whereIn('id', $city_arr)
  7651. ->pluck('name')
  7652. ->implode('-');
  7653. $company->city_name = $cityNames;
  7654. } else {
  7655. $company->city_name = '';
  7656. }
  7657. if (empty($company)) {
  7658. return Result::error("暂无相关公司信息", 0);
  7659. }
  7660. return Result::success($company);
  7661. }
  7662. public function getMSG(array $data): array
  7663. {
  7664. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7665. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7666. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7667. $result = [];
  7668. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7669. //最近的5篇已审的文章
  7670. $apply_articale = Article::where('status', 1)
  7671. ->where('admin_user_id', $user_id)
  7672. ->orderBy('updated_at', 'desc')
  7673. // ->limit(5)
  7674. ->get();
  7675. //获取5条用户的已审核商品
  7676. $good = Good::where('status', 2)
  7677. ->where('user_id', $user_id)
  7678. ->orderBy('updated_at', 'desc')
  7679. // ->limit(5)
  7680. ->get();
  7681. //获取5条用户待审核的公告
  7682. $notice = Notice::where('status', 2)
  7683. ->where('user_id', $user_id)
  7684. ->orderBy('updated_at', 'desc')
  7685. ->limit(5)->get();
  7686. //获取5条用户的待审核投诉
  7687. $complaint = Complaint::where('status', 2)
  7688. ->where('user_id', $user_id)
  7689. ->orderBy('updated_at', 'desc')
  7690. // ->limit(5)
  7691. ->get();
  7692. //获取5条用户的book
  7693. $book = Book::where('status', 2)
  7694. ->where('user_id', $user_id)
  7695. ->orderBy('updated_at', 'desc')
  7696. // ->limit(5)
  7697. ->get();
  7698. //获取5条用户的求职
  7699. //获取5条用户的求职 1
  7700. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7701. ->where('job_hunting.user_id', $user_id)
  7702. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7703. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7704. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7705. ->orderBy('updated_at', 'desc')
  7706. // ->limit(5)
  7707. ->get();
  7708. //获取5条用户的求职 2
  7709. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7710. ->where('job_recruiting.user_id', $user_id)
  7711. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7712. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7713. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7714. ->orderBy('updated_at', 'desc')
  7715. // ->limit(5)
  7716. ->get();
  7717. //人才库 1
  7718. $job_apply = JobApply::where('job_apply.status', 1)
  7719. ->where('job_apply.receiver_id', $user_id)
  7720. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7721. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7722. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7723. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7724. ->select('job_recruiting', 'job_recruiting.', '', '')
  7725. ->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')
  7726. ->orderBy('updated_at', 'desc')
  7727. // ->limit(5)
  7728. ->get();
  7729. // 职场机会 2
  7730. $job_resume = JobResume::where('job_resume.status', 1)
  7731. ->where('job_resume.receiver_id', $user_id)
  7732. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7733. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7734. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7735. ->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')
  7736. ->orderBy('updated_at', 'desc')
  7737. // ->limit(5)
  7738. ->get();
  7739. //获取5条用户待处理的投诉
  7740. $complaint_deal = Complaint::where('status', 2)
  7741. ->where('deal', 1)
  7742. ->whereJsonContains('re_user_ids', $user_id)
  7743. ->orderBy('updated_at', 'desc')
  7744. // ->limit(5)
  7745. ->get();
  7746. //获取 被通知者未读信息
  7747. $notice_unread = Notice::where('status', 2)
  7748. ->whereJsonContains('re_user_ids', $user_id)
  7749. //未读消息
  7750. ->where(function ($query) use ($user_id) {
  7751. $query->whereJsonDoesntContain('read_id', $user_id)
  7752. ->orWhereNull('read_id');
  7753. })
  7754. ->orderBy('updated_at', 'desc')
  7755. ->get();
  7756. $complaint_unread = Complaint::where('status', 2)
  7757. ->whereJsonContains('re_user_ids', $user_id)
  7758. //未读消息
  7759. ->where(function ($query) use ($user_id) {
  7760. $query->whereJsonDoesntContain('read_id', $user_id)
  7761. ->orWhereNull('read_id');
  7762. })
  7763. ->orderBy('updated_at', 'desc')
  7764. ->get();
  7765. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7766. $complany = Company::where('status', 1)
  7767. ->where('user_id', $user_id)
  7768. ->orderBy('updated_at', 'desc')
  7769. // ->limit(5)
  7770. ->get();
  7771. //获取5条单聊未读聊天消息
  7772. // $chat = ChatRecords::where('is_read', 0)
  7773. // ->where('user_id', $user_id)
  7774. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7775. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7776. // ->where('action', 'recieved')
  7777. // ->where('talk_type', 1)
  7778. // ->orderBy('created_at', 'desc')
  7779. // // ->limit(5)
  7780. // ->get();
  7781. //获取5条未读群聊信息
  7782. // $chat_group = ChatRecords::where('is_read', 0)
  7783. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7784. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7785. // ->where('user_id', $user_id)
  7786. // ->where('talk_type', 2)
  7787. // ->orderBy('created_at', 'desc')
  7788. // // ->limit(5)
  7789. // ->get();
  7790. //获取5条用户的待审核项目
  7791. $project = Project::where('status', 1)
  7792. ->where('user_id', $user_id)
  7793. ->orderBy('updated_at', 'desc')
  7794. // ->limit(5)
  7795. ->get();
  7796. // count($chat) + count($chat_group) +
  7797. $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)
  7798. + count($complany)
  7799. + count($project)
  7800. + count($notice_unread)
  7801. + count($complaint_unread)
  7802. // + count($chat) + count($chat_group)
  7803. ;
  7804. $result = [
  7805. 'apply_articale' => $apply_articale,
  7806. // 'chat' => $chat,
  7807. // 'chat_group' => $chat_group,
  7808. 'good' => $good,
  7809. 'notice' => $notice,
  7810. 'complaint' => $complaint,
  7811. 'book' => $book,
  7812. 'job_hunting' => $job_hunting,
  7813. 'job_recruiting' => $job_recruiting,
  7814. 'job_apply' => $job_apply,
  7815. 'job_resume' => $job_resume,
  7816. 'complaint_deal' => $complaint_deal,
  7817. 'complany' => $complany,
  7818. 'project' => $project,
  7819. 'notice_unread' => $notice_unread,
  7820. 'complaint_unread' => $complaint_unread,
  7821. 'count' => $count,
  7822. ];
  7823. } elseif ($type_id == 12) {
  7824. //最近的5篇已审的文章
  7825. $apply_articale = Article::where('status', 1)
  7826. ->where('admin_user_id', $user_id)
  7827. ->limit(5)->get();
  7828. //获取5条单聊未读聊天消息
  7829. $chat = ChatRecords::where('is_read', 0)
  7830. ->where('user_id', $user_id)
  7831. ->where('talk_type', 1)
  7832. ->orderBy('created_at', 'desc')
  7833. ->limit(5)->get();
  7834. //获取5条未读群聊信息
  7835. $chat_group = ChatRecords::where('is_read', 0)
  7836. ->where('user_id', $user_id)
  7837. ->where('talk_type', 2)
  7838. ->orderBy('created_at', 'desc')
  7839. ->limit(5)->get();
  7840. //获取5条用户的已审核商品
  7841. $good = Good::where('status', 2)
  7842. ->where('user_id', $user_id)
  7843. ->orderBy('updated_at', 'desc')
  7844. ->limit(5)->get();
  7845. //获取5条用户的book
  7846. $book = Book::where('status', 2)
  7847. ->where('user_id', $user_id)
  7848. ->orderBy('updated_at', 'desc')
  7849. ->limit(5)->get();
  7850. //获取5条用户的求职
  7851. //获取5条用户的求职 1
  7852. //count($chat) + count($chat_group)
  7853. $count = count($apply_articale) + count($good);
  7854. $result = [
  7855. 'apply_articale' => $apply_articale,
  7856. 'chat' => $chat,
  7857. 'chat_group' => $chat_group,
  7858. 'good' => $good,
  7859. 'book' => $book,
  7860. 'count' => $count,
  7861. ];
  7862. } elseif ($type_id == 13) {
  7863. //最近的5篇已审的文章
  7864. $apply_articale = Article::where('status', 1)
  7865. ->where('admin_user_id', $user_id)
  7866. ->limit(5)->get();
  7867. //获取5条单聊未读聊天消息
  7868. $chat = ChatRecords::where('is_read', 0)
  7869. ->where('user_id', $user_id)
  7870. ->where('talk_type', 1)
  7871. ->orderBy('created_at', 'desc')
  7872. ->limit(5)->get();
  7873. //获取5条未读群聊信息
  7874. $chat_group = ChatRecords::where('is_read', 0)
  7875. ->where('user_id', $user_id)
  7876. ->where('talk_type', 2)
  7877. ->orderBy('created_at', 'desc')
  7878. ->limit(5)->get();
  7879. //获取5条用户的已审核商品
  7880. $good = Good::where('status', 2)
  7881. ->where('user_id', $user_id)
  7882. ->orderBy('updated_at', 'desc')
  7883. ->limit(5)->get();
  7884. //count($chat) + count($chat_group) +
  7885. $count = count($apply_articale) + count($good);
  7886. $result = [
  7887. 'apply_articale' => $apply_articale,
  7888. 'chat' => $chat,
  7889. 'chat_group' => $chat_group,
  7890. 'good' => $good,
  7891. 'count' => $count,
  7892. ];
  7893. } elseif ($type_id == 14) {
  7894. //最近的5篇已审的文章
  7895. $apply_articale = Article::where('status', 1)
  7896. ->where('admin_user_id', $user_id)
  7897. // ->limit(5)
  7898. ->get();
  7899. //获取5条用户的已审核商品
  7900. $good = Good::where('status', 2)
  7901. ->where('user_id', $user_id)
  7902. ->orderBy('updated_at', 'desc')
  7903. // ->limit(5)
  7904. ->get();
  7905. $count = count($apply_articale) + count($good);
  7906. $result = [
  7907. 'apply_articale' => $apply_articale,
  7908. 'chat' => '',
  7909. 'chat_group' => '',
  7910. 'good' => $good,
  7911. 'count' => $count,
  7912. ];
  7913. } elseif ($type_id == 10000) {
  7914. //获取未审核的5篇文章
  7915. $apply_articale = Article::where('status', 0)
  7916. ->orderBy('updated_at', 'desc')
  7917. // ->limit(5)
  7918. ->get();
  7919. //获取5条单聊未读聊天消息
  7920. //获取5条单聊未读聊天消息
  7921. // $chat = ChatRecords::where('is_read', 0)
  7922. // ->where('user_id', $user_id)
  7923. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7924. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7925. // ->where('action', 'recieved')
  7926. // ->where('talk_type', 1)
  7927. // ->orderBy('created_at', 'desc')
  7928. // // ->limit(5)
  7929. // ->get();
  7930. // //获取5条未读群聊信息
  7931. // $chat_group = ChatRecords::where('is_read', 0)
  7932. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7933. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7934. // ->where('user_id', $user_id)
  7935. // ->where('talk_type', 2)
  7936. // ->orderBy('created_at', 'desc')
  7937. // // ->limit(5)
  7938. // ->get();
  7939. //获取5条用户的已审核商品
  7940. $good = Good::where('status', 1)
  7941. // ->where('user_id', $user_id)
  7942. ->orderBy('updated_at', 'desc')
  7943. // ->limit(5)
  7944. ->get();
  7945. //获取5条用户待审核的公告
  7946. $notice = Notice::where('status', 1)
  7947. ->orderBy('updated_at', 'desc')
  7948. // ->limit(5)
  7949. ->get();
  7950. //获取5条用户的待审核投诉
  7951. $complaint = Complaint::where('status', 1)
  7952. ->orderBy('updated_at', 'desc')
  7953. // ->limit(5)
  7954. ->get();
  7955. //获取5条用户的book
  7956. $book = Book::where('status', 1)
  7957. ->orderBy('updated_at', 'desc')
  7958. // ->limit(5)
  7959. ->get();
  7960. //获取5条用户的求职 1
  7961. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7962. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7963. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7964. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7965. ->orderBy('updated_at', 'desc')
  7966. // ->limit(5)
  7967. ->get();
  7968. //获取5条用户的求职 2
  7969. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7970. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7971. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7972. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7973. ->orderBy('updated_at', 'desc')
  7974. // ->limit(5)
  7975. ->get();
  7976. //人才库 1
  7977. $job_apply = JobApply::where('job_apply.status', 1)
  7978. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7979. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7980. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7981. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7982. ->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')
  7983. ->orderBy('updated_at', 'desc')
  7984. // ->limit(5)
  7985. ->get();
  7986. // 职场机会 2
  7987. $job_resume = JobResume::where('job_resume.status', 1)
  7988. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7989. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7990. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7991. ->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')
  7992. ->orderBy('updated_at', 'desc')
  7993. // ->limit(5)
  7994. ->get();
  7995. //待审核数据com pro
  7996. $complany = Company::where('status', 0)
  7997. ->orderBy('updated_at', 'desc')
  7998. // ->limit(5)
  7999. ->get();
  8000. $project = Project::where('status', 0)
  8001. ->orderBy('updated_at', 'desc')
  8002. // ->limit(5)
  8003. ->get();
  8004. $count =
  8005. // count($chat) +
  8006. // count($chat_group) +
  8007. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8008. // + count($job_apply)
  8009. // + count($job_resume)
  8010. + count($complany)
  8011. + count($project);
  8012. $result = [
  8013. 'apply_articale' => $apply_articale,
  8014. // 'chat' => $chat,
  8015. // 'chat_group' => $chat_group,
  8016. 'good' => $good,
  8017. 'notice' => $notice,
  8018. 'complaint' => $complaint,
  8019. 'book' => $book,
  8020. 'job_hunting' => $job_hunting,
  8021. 'job_recruiting' => $job_recruiting,
  8022. // 'job_apply' => $job_apply,
  8023. // 'job_resume' => $job_resume,
  8024. 'complany' => $complany,
  8025. 'project' => $project,
  8026. 'count' => $count,
  8027. ];
  8028. } elseif ($type_id == 20000) {
  8029. }
  8030. var_dump($type_id, '-----------------test---------');
  8031. return Result::success($result);
  8032. }
  8033. /**
  8034. * @param array $data
  8035. * @return array
  8036. */
  8037. public function getWebsiteProject(array $data): array
  8038. {
  8039. $categorys = json_decode($data['id'], true);
  8040. if (!empty($categorys)) {
  8041. $category_arr = $this->processArticlePro($data['website_id']);
  8042. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8043. $catiall = $category_arr['catiall'];
  8044. // return Result::success($catiall);
  8045. foreach ($categorys as $key => $val) {
  8046. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8047. $level = explode(',', $val['level'])[0];
  8048. $imgnum = explode(',', $val['level'])[1] ?? null;
  8049. $textnum = explode(',', $val['level'])[2] ?? null;
  8050. if ($level == 1) {
  8051. if (!empty($textnum) && $textnum > 0) {
  8052. $text_num = Project::where('level', $level)
  8053. ->where('website_id', $data['website_id'])
  8054. ->where('status', 1)
  8055. ->select(
  8056. 'project.id',
  8057. 'project.title',
  8058. 'project.description',
  8059. 'project.updated_at',
  8060. 'project.category_id',
  8061. 'project.cat_arr_id'
  8062. )
  8063. ->orderBy('updated_at', 'desc')
  8064. ->limit($textnum)
  8065. ->get()->all();
  8066. }
  8067. if (!empty($imgnum) && $imgnum > 0) {
  8068. $img_num = Project::where('level', $level)
  8069. ->where('website_id', $data['website_id'])
  8070. ->where('status', 1)
  8071. ->where('imgurl', '!=', '')
  8072. ->whereNotNull('imgurl')
  8073. ->select(
  8074. 'project.id',
  8075. 'project.title',
  8076. 'project.description',
  8077. 'project.updated_at',
  8078. 'project.imgurl as imgs',
  8079. 'project.category_id',
  8080. 'project.cat_arr_id'
  8081. )
  8082. ->orderBy('updated_at', 'desc')
  8083. ->limit($imgnum)
  8084. ->get()->all();
  8085. }
  8086. } else {
  8087. if (!empty($textnum) && $textnum > 0) {
  8088. $text_num = Project::where('website_id', $data['website_id'])
  8089. ->where('status', 1)
  8090. ->select(
  8091. 'project.id',
  8092. 'project.title',
  8093. 'project.description',
  8094. 'project.updated_at',
  8095. 'project.category_id',
  8096. 'project.cat_arr_id',
  8097. 'project.website_id',
  8098. 'project.updated_at',
  8099. 'project.created_at'
  8100. )
  8101. ->orderBy('updated_at', 'desc')
  8102. ->limit($textnum)
  8103. ->get()->all();
  8104. }
  8105. if (!empty($imgnum) && $imgnum > 0) {
  8106. $img_num = Project::where('website_id', $data['website_id'])
  8107. ->where('status', 1)
  8108. ->where('imgurl', '!=', '')
  8109. ->whereNotNull('imgurl')
  8110. ->select(
  8111. 'project.id',
  8112. 'project.title',
  8113. 'project.description',
  8114. 'project.updated_at',
  8115. 'project.imgurl as imgs',
  8116. 'project.category_id',
  8117. 'project.cat_arr_id'
  8118. )
  8119. ->orderBy('updated_at', 'desc')
  8120. ->limit($imgnum)
  8121. ->get()->all();
  8122. }
  8123. }
  8124. }
  8125. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8126. $category_ids = explode(',', $val['id'])[0];
  8127. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8128. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8129. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8130. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8131. $text_num = Project::whereIn('category_id', $category_arr)
  8132. ->where('website_id', $data['website_id'])
  8133. ->where('status', 1)
  8134. ->select(
  8135. 'project.id',
  8136. 'project.title',
  8137. 'project.description',
  8138. 'project.updated_at',
  8139. 'project.category_id',
  8140. 'project.cat_arr_id'
  8141. )
  8142. ->orderBy('updated_at', 'desc')
  8143. ->limit($cat_textnum)
  8144. ->get()->all();
  8145. }
  8146. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8147. $img_num = Project::whereIn('category_id', $category_arr)
  8148. ->where('website_id', $data['website_id'])
  8149. ->where('status', 1)
  8150. ->where('imgurl', '!=', '')
  8151. ->whereNotNull('imgurl')
  8152. ->select(
  8153. 'project.id',
  8154. 'project.title',
  8155. 'project.description',
  8156. 'project.updated_at',
  8157. 'project.imgurl as imgs',
  8158. 'project.category_id',
  8159. 'project.cat_arr_id'
  8160. )
  8161. ->orderBy('updated_at', 'desc')
  8162. ->limit($cat_imgnum)
  8163. ->get()->all();
  8164. }
  8165. }
  8166. if (!empty($img_num)) {
  8167. foreach ($img_num as $k => $v) {
  8168. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8169. $imgurl = json_decode($v['imgs'], true);
  8170. if (!empty($imgurl)) {
  8171. $img_num[$k]->imgurl = $imgurl[0];
  8172. }
  8173. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8174. }
  8175. }
  8176. if (!empty($text_num)) {
  8177. foreach ($text_num as $k => $v) {
  8178. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8179. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8180. }
  8181. }
  8182. $project[$key]['img_num'] = $img_num ?? [];
  8183. $project[$key]['text_num'] = $text_num ?? [];
  8184. }
  8185. }
  8186. if (empty($project)) {
  8187. return Result::error("暂无相关项目信息", 0);
  8188. }
  8189. return Result::success($project);
  8190. }
  8191. /**
  8192. * @param array $data
  8193. * @return array
  8194. */
  8195. public function getWebsiteProjectInfo(array $data): array
  8196. {
  8197. $project = Project::where('id', $data['id'])
  8198. ->where('status', 1)
  8199. ->where('website_id', $data['website_id'])
  8200. ->select('project.*')
  8201. ->first();
  8202. if (empty($project)) {
  8203. return Result::error("暂无相关项目信息", 0);
  8204. }
  8205. return Result::success($project);
  8206. }
  8207. /**
  8208. * @param array $data
  8209. * @return array
  8210. */
  8211. public function getWebsiteProjectList(array $data): array
  8212. {
  8213. $where = [];
  8214. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8215. $where['category_id'] = $data['category_id'];
  8216. }
  8217. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8218. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8219. }
  8220. $query = Project::where($where)
  8221. ->where('status', 1)
  8222. ->where('website_id', $data['website_id'])
  8223. ->select(
  8224. 'project.id',
  8225. 'project.title',
  8226. 'project.description',
  8227. 'project.imgurl as imgs',
  8228. 'project.category_id',
  8229. 'project.cat_arr_id'
  8230. )
  8231. ->orderBy('updated_at', 'desc');
  8232. $count = $query->count();
  8233. $project = $query->clone()
  8234. ->offset(($data['page'] - 1) * $data['pageSize'])
  8235. ->limit($data['pageSize'])
  8236. ->get()->all();
  8237. if (empty($project)) {
  8238. return Result::error("暂无相关项目信息", 0);
  8239. }
  8240. $categorys = $this->processArticlePro($data['website_id']);
  8241. $catiall = $categorys['catiall'];
  8242. foreach ($project as $key => $val) {
  8243. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8244. if (!empty($val['imgs'])) {
  8245. $imgurl = json_decode($val['imgs'], true);
  8246. if (!empty($imgurl)) {
  8247. $project[$key]->imgurl = $imgurl[0];
  8248. }
  8249. } else {
  8250. $project[$key]->imgurl = '';
  8251. }
  8252. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8253. }
  8254. $result = [
  8255. 'rows' => $project,
  8256. 'count' => $count,
  8257. ];
  8258. return Result::success($result);
  8259. }
  8260. /**
  8261. * @param array $data
  8262. * @return array
  8263. */
  8264. public function getWebsiteCategoryJob(array $data): array
  8265. {
  8266. $categorys = json_decode($data['id'], true);
  8267. if (!empty($categorys)) {
  8268. $category_arr = $this->processArticlePro($data['website_id']);
  8269. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8270. $catiall = $category_arr['catiall'];
  8271. foreach ($categorys as $key => $val) {
  8272. if (isset($val['id']) && !empty($val['id'])) {
  8273. $catid = explode(',', $val['id'])[0] ?? null;
  8274. $type = explode(',', $val['id'])[1] ?? null;
  8275. $textnum = explode(',', $val['id'])[2] ?? null;
  8276. }
  8277. // 4:招聘;5:求职;
  8278. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8279. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8280. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8281. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8282. ->where('job_recruiting.status', 1)
  8283. ->where('job_recruiting.website_id', $data['website_id'])
  8284. ->select(
  8285. 'job_recruiting.id',
  8286. 'job_recruiting.title',
  8287. 'job_company.business_name',
  8288. 'job_recruiting.updated_at',
  8289. 'job_recruiting.cat_arr_id',
  8290. 'job_recruiting.keyword',
  8291. 'job_recruiting.description'
  8292. )
  8293. ->orderBy('job_recruiting.updated_at', 'desc')
  8294. ->limit($textnum)
  8295. ->get()->all();
  8296. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8297. // 状态 审核状态,1待审核2已审核3已拒绝
  8298. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8299. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8300. ->where('job_hunting.status', 2)
  8301. ->where('job_hunting.website_id', $data['website_id'])
  8302. ->select(
  8303. 'job_hunting.id',
  8304. 'job_hunting.name',
  8305. 'job_hunting.cat_arr_id',
  8306. 'job_position.zwname as job_name',
  8307. 'job_hunting.updated_at',
  8308. 'job_hunting.keyword',
  8309. 'job_hunting.slelf_evaluation'
  8310. )
  8311. ->orderBy('updated_at', 'desc')
  8312. ->limit($textnum)
  8313. ->get()->all();
  8314. } else {
  8315. $job = [];
  8316. }
  8317. // var_dump($catid.'222uuuuuuu'.$key);
  8318. if (!empty($job)) {
  8319. foreach ($job as $k => $value) {
  8320. if (isset($value->cat_arr_id)) {
  8321. $catArr = json_decode($value->cat_arr_id, true);
  8322. $catId = end($catArr);
  8323. } else {
  8324. continue;
  8325. }
  8326. if (isset($catiall[$catId])) {
  8327. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8328. }
  8329. }
  8330. }
  8331. // var_dump($catid.'xxxxx'.$key);
  8332. $result[$key] = $job ?? [];
  8333. }
  8334. }
  8335. if (empty($result)) {
  8336. return Result::error("暂无相关分类信息", 0);
  8337. }
  8338. return Result::success($result);
  8339. }
  8340. /**
  8341. * 发送消息
  8342. * @param array $messageData
  8343. * @return void
  8344. */
  8345. public function sendMessage($messageData)
  8346. {
  8347. $msg = [
  8348. 'talk_type' => $messageData['talk_type'],
  8349. 'title' => $messageData['title'],
  8350. 'content' => $messageData['content'],
  8351. 'messageType' => $messageData['messageType'],
  8352. 'user_id' => $messageData['user_id'] ?? '',
  8353. 'time' => microtime(),
  8354. ];
  8355. $message = new MqProducer($msg);
  8356. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8357. $producer->produce($message);
  8358. }
  8359. }