NewsService.php 324 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851
  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. $startTime = microtime(true);
  361. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  362. $type_id = $data['type_id'];
  363. unset($data['type_id']);
  364. $user_id = $data['user_id'];
  365. unset($data['user_id']);
  366. $where = [];
  367. $status1 = [];
  368. if (isset($data['id']) && $data['id']) {
  369. array_push($where, ['article.id', '=', $data['id']]);
  370. }
  371. if (isset($data['title']) && $data['title']) {
  372. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  373. }
  374. if (isset($data['category_name']) && $data['category_name']) {
  375. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  376. }
  377. if (isset($data['catid']) && $data['catid']) {
  378. array_push($where, ['article.catid', '=', $data['catid']]);
  379. }
  380. if (isset($data['author']) && $data['author']) {
  381. array_push($where, ['article.author', '=', $data['author']]);
  382. }
  383. if (isset($data['islink']) && $data['islink'] !== "") {
  384. array_push($where, ['article.islink', '=', $data['islink']]);
  385. }
  386. if (isset($data['status']) && $data['status'] !== "") {
  387. array_push($where, ['article.status', '=', $data['status']]);
  388. }
  389. if (isset($data['status1'])) {
  390. $status1 = json_decode(($data['status1']));
  391. }
  392. //不是管理员展示个人数据;
  393. if ($type_id != 10000) {
  394. $where[] = ['article.admin_user_id', '=', $user_id];
  395. }
  396. // $rep = Article::where($where)
  397. // ->whereNotIn('article.status', [404])
  398. // ->when($status1, function ($query) use ($status1) {
  399. // if (isset($status1) && $status1) {
  400. // $query->whereIn('article.status', $status1);
  401. // }
  402. // })
  403. // ->leftJoin('category', 'article.catid', 'category.id')
  404. // ->leftJoin('website_category', function ($join) {
  405. // $join->on('article.web_site_id', '=', 'website_category.website_id')
  406. // ->on('article.catid', '=', 'website_category.category_id');
  407. // })
  408. // ->when($type_id != 10000 && !empty($data['website_id']), function ($query) use ($data) {
  409. // $query->leftJoin('article_ignore', function ($join) use ($data) {
  410. // $join->on('article.id', '=', 'article_ignore.article_id')
  411. // ->where('article_ignore.website_id', $data['website_id']);
  412. // });
  413. // })
  414. // ->select("article.*", "category.name as category_name", "website_category.alias",
  415. // Db::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time'))
  416. // ->orderBy("article.updated_at", "desc")
  417. // ->limit($data['pageSize'])
  418. // ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  419. //
  420. $query = Article::where($where)
  421. ->whereNotIn('article.status', [404])
  422. ->when($status1, function ($query) use ($status1) {
  423. if (isset($status1) && $status1) {
  424. $query->whereIn('article.status', $status1);
  425. }
  426. })
  427. ->leftJoin('category', 'article.catid', 'category.id')
  428. ->leftJoin('website_category', function ($join) {
  429. $join->on('article.web_site_id', '=', 'website_category.website_id')
  430. ->on('article.catid', '=', 'website_category.category_id');
  431. });
  432. if ($type_id != 10000 && !empty($data['website_id'])) {
  433. $query = $query
  434. ->leftJoin('article_ignore', function ($join) use ($data) {
  435. $join->on('article.id', '=', 'article_ignore.article_id')
  436. ->where('article_ignore.website_id', $data['website_id']);
  437. })
  438. ->select("article.*", "category.name as category_name", "website_category.alias", 'article_ignore.c_show_time');
  439. } else {
  440. $query = $query
  441. ->select("article.*", "category.name as category_name", "website_category.alias");
  442. }
  443. $count = $query->count();
  444. $rep = $query
  445. ->orderBy("article.updated_at", "desc")
  446. ->limit($data['pageSize'])
  447. ->offset(($data['page'] - 1) * $data['pageSize'])
  448. ->get();
  449. $data = [
  450. 'rows' => $rep->items(),
  451. 'count' => $rep->total(),
  452. ];
  453. // 执行查询
  454. $endTime = microtime(true);
  455. $executionTime = ($endTime - $startTime) * 1000;
  456. echo "查询执行时间: {$executionTime}ms\n";
  457. return Result::success($data);
  458. }
  459. /**
  460. * @param array $data
  461. * @return array
  462. */
  463. public function addArticle(array $data): array
  464. {
  465. var_dump($data, '----------12-----------1');
  466. // ------c_show_time********add***1****
  467. $is_collect = $data['is_collect'] ?? 0;
  468. $user_type = $data['user_type'];
  469. unset($data['is_collect']);
  470. unset($data['user_type']);
  471. // ------c_show_time********add***1****
  472. unset($data['nav_add_pool_id']);
  473. // unset($data['commend_id']);
  474. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  475. Db::beginTransaction();
  476. try {
  477. //处理投票
  478. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  479. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  480. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  481. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  482. unset($data['is_survey']);
  483. unset($data['survey_name']);
  484. unset($data['suvey_array']);
  485. // unset($data['website_id']);
  486. // unset($data['web_site_id']);
  487. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  488. if ($data['hits'] == '') {
  489. $data['hits'] = 0;
  490. }
  491. if ($data['is_original'] == '') {
  492. $data['is_original'] = 0;
  493. }
  494. if ($data['status'] == '') {
  495. $data['status'] = 0;
  496. }
  497. $articleData = $data;
  498. unset($articleData['content']);
  499. //自动处理缩略图、关键字、描述
  500. if ($articleData['imgurl'] == '') {
  501. //如果没有图,设置level=0
  502. $levelArr = json_decode($articleData['level'], true);
  503. var_dump($levelArr, '----------levelArr-----------1');
  504. //content中提取图片第一个图,正则提取
  505. // -------采集器相关优化-----
  506. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  507. if ($is_collect == 1) {
  508. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  509. } else {
  510. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  511. }
  512. // -------采集器相关优化-----
  513. preg_match_all($reg, $data['content'], $matches);
  514. if (isset($matches[1][0])) {
  515. //截取varchar240
  516. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  517. //如果有图,设置level=3
  518. if (!in_array(3, $levelArr)) {
  519. $levelArr[] = 3;
  520. }
  521. $articleData['level'] = json_encode($levelArr);
  522. } else {
  523. if (!in_array(0, $levelArr)) {
  524. $levelArr[] = 0;
  525. }
  526. $articleData['level'] = json_encode($levelArr);
  527. }
  528. }
  529. var_dump($articleData['level'], '----------$articleData[level]----------1');
  530. if ($articleData['keyword'] == '') {
  531. //提取标题+内容中的关键词
  532. $articleData['keyword'] = $data['title'];
  533. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  534. Jieba::init(); // 初始化 jieba-php
  535. Finalseg::init();
  536. $segList = Jieba::cut($articleData['keyword']);
  537. $segList1 = array_slice($segList, 0, 8);
  538. $articleData['keyword'] = implode(',', $segList1);
  539. }
  540. if ($articleData['introduce'] == '') {
  541. //提取内容中的描述
  542. $content = $data['content'];
  543. // 去除 <style> 和 <script> 标签及其内容
  544. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  545. // 去除所有 HTML 标签
  546. $content = strip_tags($content);
  547. // 去除 HTML 实体
  548. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  549. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  550. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  551. // 去除多余空白
  552. $content = preg_replace('/\s+/u', '', $content);
  553. // 截取 100 个字符
  554. $articleData['introduce'] = mb_substr($content, 0, 100);
  555. }
  556. if ($articleData['status'] == 0) {
  557. $this->sendMessage([
  558. 'talk_type' => 100,
  559. 'title' => $articleData['title'],
  560. 'content' => '提交了审核',
  561. 'messageType' => 2,
  562. ]);
  563. }
  564. $id = Article::insertGetId($articleData);
  565. if (!$id) {
  566. throw new \Exception('文章插入失败');
  567. }
  568. $articleDataContent = [
  569. 'article_id' => $id,
  570. 'content' => $data['content'],
  571. ];
  572. // 采集器中的文章内容,在添加时,去掉div标签
  573. if ($is_collect == 1) {
  574. // 采集来的文章,content中可能包含div标签,需要先移除
  575. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  576. $article_data = preg_replace($pattern, '', $data['content']);
  577. $$articleDataContent['content'] = $article_data;
  578. }
  579. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  580. if (!$contentInsertId) {
  581. throw new \Exception('文章内容插入失败');
  582. }
  583. // ------c_show_time********add***2****
  584. // 直接使用当前系统时间,不再强制添加8小时
  585. $now = date('Y-m-d H:i:s');
  586. if ($user_type == 10000 || $is_collect == 1) {
  587. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  588. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  589. if (!isset($data['catid'])) {
  590. throw new \Exception('缺少必要字段:catid');
  591. }
  592. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  593. $web = WebsiteCategory::where('category_id', $data['catid'])
  594. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  595. ->select(
  596. 'website_id',
  597. 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')
  598. )
  599. ->get();
  600. // $id = 225; -----测试开启
  601. // 采集来的文章,错开时间在两小时之内发布
  602. if ($user_type == 10000 && $is_collect == 1) {
  603. $web_num = $web->where('is_core', '!=', 2)->count();
  604. $waiting_interval = 10;
  605. if ($web_num > 12) {
  606. // 若网站数量大于12个,则每个网站间隔时间取均值
  607. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  608. $waiting_interval = 120 / max(1, $web_num);
  609. }
  610. $time = 0;
  611. } else {
  612. // 非核心站与核心站----显示时间-----间隔
  613. $time = 20;
  614. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  615. $waiting_interval = 5;
  616. }
  617. // 将 Hyperf\Database\Model\Collection 转换为数组
  618. $webArray = $web->toArray();
  619. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  620. // 检查 $item 对象是否有 is_core 属性
  621. if (!isset($item['is_core'])) {
  622. throw new \Exception('$item 对象缺少 is_core 属性');
  623. }
  624. // 当 is_core 为 2 时,则表示此网站不存在
  625. if ($item['is_core'] == 2) {
  626. return null;
  627. }
  628. if ($is_collect == 1) {
  629. // 采集来的文章,错开时间在两小时之内发布
  630. // $time = 0;
  631. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  632. $time += $waiting_interval;
  633. } else if ($item['is_core'] == 1) {
  634. // 当 is_core 为 1 时,则表示此网站是核心站
  635. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  636. } else {
  637. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  638. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  639. if ($item['is_core'] == 0) {
  640. $time += $waiting_interval;
  641. }
  642. }
  643. return [
  644. 'article_id' => $id,
  645. 'website_id' => $item['website_id'],
  646. 'c_show_time' => $c_show_time,
  647. // 'is_core' => $item['is_core'],
  648. // 'time' => $time
  649. ];
  650. }, array_keys($webArray), $webArray)));
  651. // Db::commit();
  652. // return Result::success($article_ignore);
  653. if (!empty($article_ignore)) {
  654. $article_ignores = ArticleIgnore::insert($article_ignore);
  655. if (!$article_ignores) {
  656. throw new \Exception('c端展示时间插入失败');
  657. }
  658. }
  659. }
  660. // ------c_show_time********add***2****
  661. //处理投票
  662. if ($is_survey == 1) {
  663. //生成年月日时分秒+8位随机数
  664. $uuid = date('YmdHis') . rand(10000000, 99999999);
  665. var_dump($suvey_array, 'suvey_array________');
  666. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  667. var_dump($suveys_array, '---------------------1');
  668. var_dump($suvey_array, '---------------------2');
  669. $suvey_data = [];
  670. foreach ($suveys_array as $key => $value) {
  671. if ($value == '') {
  672. continue;
  673. }
  674. if (is_array($value)) {
  675. $suvey_data[] = [
  676. 'sur_id' => $uuid,
  677. 'art_id' => $id,
  678. 'website_id' => $website_id ?? 2,
  679. 'survey_name' => $survey_name,
  680. 'choice_name' => $value[1],
  681. 'is_other' => 1,
  682. 'other_id' => 0,
  683. 'results' => 0,
  684. ];
  685. } else {
  686. $suvey_data[] = [
  687. 'sur_id' => $uuid,
  688. 'art_id' => $id,
  689. 'website_id' => $website_id ?? 2,
  690. 'survey_name' => $survey_name,
  691. 'choice_name' => $value,
  692. 'is_other' => 0,
  693. 'other_id' => 0,
  694. 'results' => 0,
  695. ];
  696. }
  697. if (empty($suvey_data)) {
  698. throw new \Exception("投票数据为空");
  699. }
  700. }
  701. $result = ArticleSurvey::insert($suvey_data);
  702. if (!$result) {
  703. throw new \Exception("投票失败,ArticleSurvey插入失败");
  704. }
  705. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  706. if (!$result) {
  707. throw new \Exception("投票失败,更新主表失败");
  708. }
  709. }
  710. Db::commit();
  711. return Result::success(['id' => $id]);
  712. } catch (\Throwable $ex) {
  713. Db::rollBack();
  714. var_dump($ex->getMessage());
  715. return Result::error("创建失败", 0);
  716. }
  717. }
  718. /**
  719. * @param array $data
  720. * @return array
  721. */
  722. public function delArticle(array $data): array
  723. {
  724. // ------c_show_time********del*******
  725. Db::beginTransaction();
  726. try {
  727. $article = Article::where(['id' => $data['id']])->delete();
  728. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  729. if (!$article) {
  730. throw new \Exception("删除失败,文章删除失败");
  731. }
  732. //survey投票删除
  733. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  734. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  735. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  736. // 若文章详情删除失败,抛出异常
  737. if (!$article_data) {
  738. throw new \Exception("删除失败,文章详情删除失败");
  739. }
  740. Db::commit(); // 所有操作成功,提交事务
  741. } catch (\Throwable $ex) {
  742. Db::rollBack();
  743. var_dump($ex->getMessage());
  744. return Result::error("删除失败: " . $ex->getMessage(), 0);
  745. }
  746. // ------c_show_time********del*******
  747. if (!$article) {
  748. return Result::error("删除失败");
  749. }
  750. return Result::success($article);
  751. }
  752. /**
  753. * @param array $data
  754. * @return array
  755. */
  756. public function updateArticle(array $data): array
  757. {
  758. var_dump($data, '----------12-----------1');
  759. Db::beginTransaction();
  760. // ------c_show_time********up*******
  761. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  762. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  763. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  764. $web = WebsiteCategory::where('category_id', $data['catid'])
  765. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  766. ->select(
  767. 'website_id',
  768. 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')
  769. )
  770. ->get();
  771. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  772. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  773. $websiteIds = $web->pluck('website_id')->toArray();
  774. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  775. if ($user_type == 0) {
  776. throw new \Exception("用户类型不能为空");
  777. }
  778. if ($user_type == 10000) {
  779. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  780. $web = WebsiteCategory::where('category_id', $data['catid'])
  781. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  782. ->select(
  783. 'website_id',
  784. 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')
  785. )
  786. ->get();
  787. // 非核心站与核心站----显示时间-----间隔
  788. $time = 20;
  789. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  790. $waiting_interval = 5;
  791. $webArray = $web->toArray();
  792. if (empty($webArray)) {
  793. throw new \Exception('网站分类不存在');
  794. }
  795. // 直接使用当前系统时间,不再强制添加8小时
  796. $now = date('Y-m-d H:i:s');
  797. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  798. // 检查 $item 对象是否有 is_core 属性
  799. if (!isset($item['is_core'])) {
  800. throw new \Exception('$item 对象缺少 is_core 属性');
  801. }
  802. // 当 is_core 为 2 时,则表示此网站不存在
  803. if ($item['is_core'] == 2) {
  804. return null;
  805. } else if ($item['is_core'] == 1) {
  806. // 当 is_core 为 1 时,则表示此网站是核心站
  807. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  808. } else {
  809. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  810. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  811. if ($item['is_core'] == 0) {
  812. $time += $waiting_interval;
  813. }
  814. }
  815. return [
  816. 'article_id' => $data['id'],
  817. 'website_id' => $item['website_id'],
  818. 'c_show_time' => $c_show_time,
  819. ];
  820. }, array_keys($webArray), $webArray)));
  821. if (!empty($article_ignore)) {
  822. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  823. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  824. $article_ignores = ArticleIgnore::upsert(
  825. $article_ignore,
  826. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  827. ['c_show_time'] // 需要更新的字段
  828. );
  829. if (!$article_ignores) {
  830. throw new \Exception('c端展示时间插入失败');
  831. }
  832. }
  833. // Db::commit();
  834. // return Result::success($article_ignore);
  835. }
  836. // ------c_show_time********up*******
  837. unset($data['user_type']);
  838. // unset($data['web_site_id']);
  839. unset($data['nav_add_pool_id']);
  840. try {
  841. //处理投票
  842. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  843. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  844. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  845. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  846. unset($data['is_survey']);
  847. unset($data['survey_name']);
  848. unset($data['suvey_array']);
  849. unset($data['website_id']);
  850. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  851. if ($data['hits'] == '') {
  852. $data['hits'] = 0;
  853. }
  854. if ($data['is_original'] == '') {
  855. $data['is_original'] = 0;
  856. }
  857. if ($data['status'] == '') {
  858. $data['status'] = 0;
  859. }
  860. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  861. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  862. $articleData = $data;
  863. unset($articleData['content']);
  864. unset($articleData['status_name']);
  865. unset($articleData['name']);
  866. unset($articleData['content']);
  867. unset($articleData['pid_arr']);
  868. unset($articleData['pid']);
  869. //自动处理缩略图、关键字、描述
  870. if ($articleData['imgurl'] == '') {
  871. //如果没有图,设置level=0
  872. $levelArr = json_decode($articleData['level'], true);
  873. var_dump($levelArr, '----------levelArr-----------1');
  874. //content中提取图片第一个图,正则提取
  875. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  876. preg_match_all($reg, $data['content'], $matches);
  877. if (isset($matches[1][0])) {
  878. //截取varchar240
  879. // 截取到第一个<
  880. $articleData['imgurl'] = $matches[1][0];
  881. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  882. $pos = strpos($articleData['imgurl'], '"');
  883. if ($pos !== false) {
  884. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  885. }
  886. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  887. //如果有图,设置level=3
  888. if (!in_array(3, $levelArr)) {
  889. $levelArr[] = 3;
  890. }
  891. $articleData['level'] = json_encode($levelArr);
  892. } else {
  893. if (!in_array(0, $levelArr)) {
  894. $levelArr[] = 0;
  895. }
  896. $articleData['level'] = json_encode($levelArr);
  897. }
  898. }
  899. var_dump($articleData['level'], '----------$articleData[level]----------1');
  900. if ($articleData['keyword'] == '') {
  901. //提取标题+内容中的关键词
  902. $articleData['keyword'] = $data['title'];
  903. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  904. Jieba::init(); // 初始化 jieba-php
  905. Finalseg::init();
  906. $segList = Jieba::cut($articleData['keyword']);
  907. $segList1 = array_slice($segList, 0, 8);
  908. $articleData['keyword'] = implode(',', $segList1);
  909. }
  910. if ($articleData['introduce'] == '') {
  911. //提取内容中的描述
  912. $content = $data['content'];
  913. // 去除 <style> 和 <script> 标签及其内容
  914. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  915. // 去除所有 HTML 标签
  916. $content = strip_tags($content);
  917. // 去除 HTML 实体
  918. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  919. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  920. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  921. // 去除多余空白
  922. $content = preg_replace('/\s+/u', '', $content);
  923. // 截取 100 个字符
  924. $articleData['introduce'] = mb_substr($content, 0, 100);
  925. }
  926. if ($articleData['status'] == 0) {
  927. $this->sendMessage([
  928. 'talk_type' => 100,
  929. 'title' => $articleData['title'],
  930. 'content' => '提交了审核',
  931. 'messageType' => 2,
  932. ]);
  933. }
  934. $id = Article::where(['id' => $data['id']])->update($articleData);
  935. // $articleDataContent = [
  936. // 'content' => $data['content'],
  937. // ];
  938. // 采集来的文章,content中可能包含div标签,需要先移除
  939. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  940. $article_data = preg_replace($pattern, '', $data['content']);
  941. $articleDataContent['content'] = $article_data;
  942. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  943. //处理投票
  944. $id = $data['id'];
  945. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  946. var_dump($suvey_array, 'suvey_array________delete');
  947. //处理投票
  948. if ($is_survey == 1) {
  949. //生成年月日时分秒+8位随机数
  950. $uuid = date('YmdHis') . rand(10000000, 99999999);
  951. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  952. var_dump($suveys_array, '---------------------1');
  953. $suvey_data = [];
  954. if (is_array($suveys_array)) {
  955. foreach ($suveys_array as $key => $value) {
  956. if ($value == '') {
  957. continue;
  958. }
  959. if (is_array($value)) {
  960. $suvey_data[] = [
  961. 'sur_id' => $uuid,
  962. 'art_id' => $id,
  963. 'website_id' => $website_id ?? 2,
  964. 'survey_name' => $survey_name,
  965. 'choice_name' => $value[1],
  966. 'is_other' => 1,
  967. 'other_id' => 0,
  968. 'results' => 0,
  969. ];
  970. } else {
  971. $suvey_data[] = [
  972. 'sur_id' => $uuid,
  973. 'art_id' => $id,
  974. 'website_id' => $website_id ?? 2,
  975. 'survey_name' => $survey_name,
  976. 'choice_name' => $value,
  977. 'is_other' => 0,
  978. 'other_id' => 0,
  979. 'results' => 0,
  980. ];
  981. }
  982. if (empty($suvey_data)) {
  983. throw new \Exception("投票数据为空");
  984. }
  985. }
  986. }
  987. $result = ArticleSurvey::insert($suvey_data);
  988. if (!$result) {
  989. throw new \Exception("投票失败");
  990. }
  991. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  992. if (!$result) {
  993. throw new \Exception("投票失败");
  994. }
  995. } else {
  996. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  997. }
  998. Db::commit();
  999. return Result::success([]);
  1000. } catch (\Throwable $ex) {
  1001. Db::rollBack();
  1002. var_dump($ex->getMessage());
  1003. return Result::error("更新失败" . $ex->getMessage(), 0);
  1004. }
  1005. }
  1006. /**
  1007. * 更新资讯状态
  1008. * @param array $data
  1009. * @return array
  1010. */
  1011. public function upArticleStatus(array $data): array
  1012. {
  1013. $articleData = Article::where(['id' => $data['id']])->first();
  1014. //发送10次
  1015. // for ($i = 0; $i < 10; $i++) {
  1016. // $this->sendMessage([
  1017. // 'talk_type' => 100,
  1018. // 'title' => $i . $articleData['title'],
  1019. // 'content' => '审核通过',
  1020. // 'messageType' => 2,
  1021. // 'user_id' => $articleData['admin_user_id'],
  1022. // ]);
  1023. // }
  1024. // var_dump($data['status'], 'status');
  1025. // return Result::success();
  1026. if ($data['status'] == 1) {
  1027. $this->sendMessage([
  1028. 'talk_type' => 101,
  1029. 'title' => $articleData['title'],
  1030. 'content' => '审核通过',
  1031. 'messageType' => 2,
  1032. 'user_id' => $articleData['admin_user_id'],
  1033. ]);
  1034. }
  1035. if ($data['status'] == 2) {
  1036. $this->sendMessage([
  1037. 'talk_type' => 101,
  1038. 'title' => $articleData['title'],
  1039. 'content' => '审核拒绝',
  1040. 'messageType' => 2,
  1041. 'user_id' => $articleData['admin_user_id'],
  1042. ]);
  1043. }
  1044. if ($data['status'] == 0) {
  1045. $this->sendMessage([
  1046. 'talk_type' => 100,
  1047. 'title' => $articleData['title'],
  1048. 'content' => '提交了审核',
  1049. 'messageType' => 2,
  1050. ]);
  1051. }
  1052. $result = Article::where(['id' => $data['id']])->update($data);
  1053. // ------c_show_time********up_status*******
  1054. // 若是审核通过 则更新c_show_time
  1055. if ($data['status'] == 1) {
  1056. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1057. $web = Article::where('article.id', $data['id'])
  1058. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1059. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1060. ->select(
  1061. 'website_id',
  1062. 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')
  1063. )
  1064. ->get();
  1065. // 非核心站与核心站----显示时间-----间隔
  1066. $time = 20;
  1067. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1068. $waiting_interval = 5;
  1069. $webArray = $web->toArray();
  1070. if (empty($webArray)) {
  1071. throw new \Exception('网站分类不存在');
  1072. }
  1073. // 直接使用当前系统时间,不再强制添加8小时
  1074. $now = date('Y-m-d H:i:s');
  1075. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1076. if (isset($data['ignore_ids'])) {
  1077. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1078. if (in_array($item['website_id'], $ignore_website_ids)) {
  1079. $is_ignore = 1;
  1080. } else {
  1081. $is_ignore = 0;
  1082. }
  1083. return [
  1084. 'article_id' => $data['id'],
  1085. 'website_id' => $item['website_id'],
  1086. 'is_ignore' => $is_ignore,
  1087. ];
  1088. } else {
  1089. // 检查 $item 对象是否有 is_core 属性
  1090. if (!isset($item['is_core'])) {
  1091. throw new \Exception('$item 对象缺少 is_core 属性');
  1092. }
  1093. // 当 is_core 为 2 时,则表示此网站不存在
  1094. if ($item['is_core'] == 2) {
  1095. return null;
  1096. } else if ($item['is_core'] == 1) {
  1097. // 当 is_core 为 1 时,则表示此网站是核心站
  1098. $c_show_time = $now;
  1099. } else {
  1100. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1101. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1102. if ($item['is_core'] == 0) {
  1103. $time += $waiting_interval;
  1104. }
  1105. }
  1106. return [
  1107. 'article_id' => $data['id'],
  1108. 'website_id' => $item['website_id'],
  1109. 'c_show_time' => $c_show_time,
  1110. ];
  1111. }
  1112. }, array_keys($webArray), $webArray)));
  1113. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1114. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1115. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1116. $websiteIds = $web->pluck('website_id')->toArray();
  1117. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1118. $article_ignores = ArticleIgnore::upsert(
  1119. $article_ignore,
  1120. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1121. ['c_show_time'] // 需要更新的字段
  1122. );
  1123. if (!$article_ignores) {
  1124. throw new \Exception('c端展示时间插入失败');
  1125. }
  1126. }
  1127. if (!empty($data['ignore_ids'])) {
  1128. // return Result::success($article_ignore);
  1129. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1130. if (!empty($article_ignore)) {
  1131. $article_ignores = ArticleIgnore::upsert(
  1132. $article_ignore,
  1133. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1134. ['is_ignore'] // 需要更新的字段
  1135. );
  1136. // if(!$article_ignores){
  1137. // throw new \Exception('屏蔽网站更新失败');
  1138. // }
  1139. }
  1140. }
  1141. }
  1142. // ------c_show_time********up_status*******
  1143. if ($result) {
  1144. return Result::success();
  1145. } else {
  1146. return Result::error("更新状态失败", 0);
  1147. }
  1148. }
  1149. /**
  1150. * 获取新闻详情
  1151. * @param array $data
  1152. * @return array
  1153. */
  1154. public function getArticleInfo(array $data): array
  1155. {
  1156. $where = [
  1157. 'article.id' => $data['id'],
  1158. // 'article.status' => 1,
  1159. ];
  1160. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1161. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1162. $info = $result;
  1163. // var_dump($info, 'info');
  1164. $info['survey_array'] = $articleSurvey;
  1165. if ($result) {
  1166. return Result::success($info);
  1167. } else {
  1168. return Result::error("查询失败", 0);
  1169. }
  1170. }
  1171. /**
  1172. * 获取头条新闻
  1173. * @param array $data
  1174. * @return array
  1175. */
  1176. public function getWebsiteArticlett(array $data): array
  1177. {
  1178. $website_id = $data['website_id'];
  1179. $website = Website::where('id', $data['website_id'])->first();
  1180. if (empty($website)) {
  1181. return Result::error("网站不存在", 0);
  1182. }
  1183. $categorys = $this->processArticlePro($website_id);
  1184. $catiall = $categorys['catiall'];
  1185. $categoryIds = $categorys['categoryIds'];
  1186. $where = [
  1187. 'status' => 1
  1188. ];
  1189. // $website_column = $website['column'];
  1190. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1191. $website_column = json_decode($website['website_column_arr_id'], true);
  1192. }
  1193. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1194. // return Result::success($diff_pid_categoryIds);
  1195. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1196. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1197. }
  1198. // $website_id = $data['website_id'];
  1199. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1200. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1201. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1202. switch ($data['level']) {
  1203. case 1:
  1204. case 2:
  1205. case 3:
  1206. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1207. $query = Article::where($where)
  1208. ->where('level', 'like', '%' . $data['level'] . '%')
  1209. ->orderBy('updated_at', 'desc');
  1210. break;
  1211. case 4: //最新资讯
  1212. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1213. break;
  1214. case 5: //资讯推荐
  1215. $query = Article::where($where)
  1216. ->where('updated_at', '>', $month);
  1217. break;
  1218. case 7: //资讯分类
  1219. if (isset($data['id']) && !empty($data['id'])) {
  1220. $keyword = Article::where('id', $data['id'])->value('keyword');
  1221. $keywordArray = explode(',', $keyword);
  1222. $whereL7 = [];
  1223. foreach ($keywordArray as $k => $v) {
  1224. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1225. }
  1226. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1227. break;
  1228. } else {
  1229. return Result::error("请输入资讯ID", 0);
  1230. break;
  1231. }
  1232. default:
  1233. break;
  1234. }
  1235. // $whereL7 = [];
  1236. // if(isset($data['id']) && !empty($data['id'])){
  1237. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1238. // $keywordArray = explode(',', $keyword);
  1239. // foreach ($keywordArray as $k => $v) {
  1240. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1241. // }
  1242. // }
  1243. // $query = Article::where($where)
  1244. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1245. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1246. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1247. // }
  1248. // if($data['level'] == 7){
  1249. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1250. // }
  1251. // if($data['level'] == 4){
  1252. // $query = $query->inRandomOrder()
  1253. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1254. // }
  1255. // if($data['level'] == 5){
  1256. // $query = $query->orderBy('updated_at','desc');
  1257. // }
  1258. // });
  1259. if ($data['textnum'] > 0) {
  1260. $query = clone $query;
  1261. $result['text'] = $query
  1262. ->whereIn('catid', $categoryIds)
  1263. ->leftJoinSub(function ($query) use ($website_id) {
  1264. $query->from('article_ignore')
  1265. ->where('website_id', $website_id);
  1266. }, 'article_ignore', function ($join) {
  1267. $join->on('article_ignore.article_id', '=', 'article.id');
  1268. })
  1269. ->where(function ($query) {
  1270. $query->whereNull('article_ignore.article_id')
  1271. ->orWhere(function ($subQuery) {
  1272. $subQuery->whereNotNull('article_ignore.article_id')
  1273. ->where('article_ignore.is_ignore', 0)
  1274. ->where(function ($subSubQuery) {
  1275. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1276. ->orWhereNull('article_ignore.c_show_time');
  1277. });
  1278. });
  1279. })
  1280. // ->where(function ($query) use ($website_id) {
  1281. // $query->whereNull('article_ignore.article_id')
  1282. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1283. // })
  1284. ->select(
  1285. 'article.id',
  1286. 'article.title',
  1287. 'article.author',
  1288. 'article.updated_at',
  1289. 'article.introduce',
  1290. 'article.islink',
  1291. 'article.linkurl',
  1292. 'article.copyfrom',
  1293. 'article.cat_arr_id',
  1294. 'article.catid',
  1295. 'article.level',
  1296. // 'article_ignore.is_ignore',
  1297. // 'article_ignore.c_show_time',
  1298. )
  1299. ->offset($data['placeid'])
  1300. ->limit($data['textnum'])
  1301. ->get()->all();
  1302. foreach ($result['text'] as $k => $v) {
  1303. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1304. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1305. }
  1306. }
  1307. if ($data['imgnum'] > 0) {
  1308. $query = clone $query;
  1309. if ($data['textnum'] == 0) {
  1310. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1311. $query->from('article_ignore')
  1312. ->where('website_id', $website_id);
  1313. }, 'article_ignore', function ($join) {
  1314. $join->on('article_ignore.article_id', '=', 'article.id');
  1315. })
  1316. ->where(function ($query) {
  1317. $query->whereNull('article_ignore.article_id')
  1318. ->orWhere(function ($subQuery) {
  1319. $subQuery->whereNotNull('article_ignore.article_id')
  1320. ->where('article_ignore.is_ignore', 0)
  1321. ->where(function ($subSubQuery) {
  1322. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1323. ->orWhereNull('article_ignore.c_show_time');
  1324. });
  1325. });
  1326. });
  1327. }
  1328. $result['img'] = $query
  1329. ->whereIn('catid', $categoryIds)
  1330. ->where('article.imgurl', '!=', '')
  1331. ->select(
  1332. 'article.id',
  1333. 'article.title',
  1334. 'article.imgurl',
  1335. 'article.author',
  1336. 'article.updated_at',
  1337. 'article.introduce',
  1338. 'article.islink',
  1339. 'article.linkurl',
  1340. 'article.copyfrom',
  1341. 'article.cat_arr_id',
  1342. 'article.catid',
  1343. 'article.level',
  1344. // 'article_ignore.is_ignore',
  1345. // 'article_ignore.c_show_time',
  1346. )
  1347. ->offset($data['placeid'])
  1348. ->limit($data['imgnum'])
  1349. ->get()->all();
  1350. foreach ($result['img'] as $k => $v) {
  1351. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1352. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1353. }
  1354. }
  1355. if (empty($result)) {
  1356. return Result::error("暂无相关资讯", 0);
  1357. }
  1358. return Result::success($result);
  1359. }
  1360. /**
  1361. * 获取模块新闻
  1362. * @param array $data
  1363. * @return array
  1364. */
  1365. public function getWebsiteModelArticles(array $data): array
  1366. {
  1367. $catid = $data['catid'];
  1368. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1369. $category = $category->toArray();
  1370. if (!empty($category)) {
  1371. $where = [
  1372. 'status' => 1,
  1373. 'catid' => $catid,
  1374. ];
  1375. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1376. // 1:文字新闻;2:轮播图;3:图文;
  1377. // 级别:0:未分类
  1378. // 3:推荐图片
  1379. if ($data['level'] == 1) {
  1380. $data['level'] = 0;
  1381. }
  1382. $result = Article::where($where)
  1383. ->where(function ($query) use ($data) {
  1384. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1385. ->orWhereNull("level")
  1386. ->orWhereRaw("level = '[]'");
  1387. })
  1388. ->leftJoinSub(function ($query) use ($data) {
  1389. $query->from('article_ignore')
  1390. ->where('website_id', $data['website_id']);
  1391. }, 'article_ignore', function ($join) {
  1392. $join->on('article_ignore.article_id', '=', 'article.id');
  1393. })
  1394. ->where(function ($query) {
  1395. $query->whereNull('article_ignore.article_id')
  1396. ->orWhere(function ($subQuery) {
  1397. $subQuery->whereNotNull('article_ignore.article_id')
  1398. ->where('article_ignore.is_ignore', 0)
  1399. ->where(function ($subSubQuery) {
  1400. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1401. ->orWhereNull('article_ignore.c_show_time');
  1402. });
  1403. });
  1404. })
  1405. // ->where(function ($query) use ($data) {
  1406. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1407. // ->orWhereNull("ignore_ids");
  1408. // })
  1409. ->orderBy("updated_at", "desc")
  1410. ->offset($placeid)
  1411. ->limit($data['pagesize'])
  1412. ->get();
  1413. if (empty($result)) {
  1414. return Result::error("此栏目暂无相关新闻", 0);
  1415. }
  1416. } else {
  1417. return Result::error("此网站暂无此栏目", 0);
  1418. }
  1419. return Result::success($result);
  1420. }
  1421. /**
  1422. *获取新闻列表
  1423. * @param array $data
  1424. * @return array
  1425. */
  1426. public function getWebsiteArticleList(array $data): array
  1427. {
  1428. // return Result::success($data);
  1429. $where[] = ['status', '=', 1];
  1430. $website_id = $data['website_id'];
  1431. $website = Website::where('id', $data['website_id'])->first();
  1432. if (empty($website)) {
  1433. return Result::error("网站不存在", 0);
  1434. }
  1435. // $website_column = $website['column'];
  1436. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1437. $website_column = json_decode($website['website_column_arr_id'], true);
  1438. }
  1439. $categorys = $this->processArticlePro($website_id);
  1440. $cat_1st_arr = $categorys['cat_1st_arr'];
  1441. $catiall = $categorys['catiall'];
  1442. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1443. // return Result::success($diff_pid_categoryIds);
  1444. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1445. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1446. }
  1447. if (isset($data['catid']) && !empty($data['catid'])) {
  1448. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1449. if (empty($category)) {
  1450. return Result::error("此网站暂无此栏目", 0);
  1451. }
  1452. array_push($where, ['catid', '=', $data['catid']]);
  1453. }
  1454. // return Result::success($where);
  1455. $query = Article::where($where)
  1456. ->leftJoinSub(function ($query) use ($website_id) {
  1457. $query->from('article_ignore')
  1458. ->where('website_id', $website_id);
  1459. }, 'article_ignore', function ($join) {
  1460. $join->on('article_ignore.article_id', '=', 'article.id');
  1461. })
  1462. ->where(function ($query) {
  1463. $query->whereNull('article_ignore.article_id')
  1464. ->orWhere(function ($subQuery) {
  1465. $subQuery->whereNotNull('article_ignore.article_id')
  1466. ->where('article_ignore.is_ignore', 0)
  1467. ->where(function ($subSubQuery) {
  1468. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1469. ->orWhereNull('article_ignore.c_show_time');
  1470. });
  1471. });
  1472. })
  1473. ->select(
  1474. 'article.id',
  1475. 'article.title',
  1476. 'article.imgurl',
  1477. 'article.author',
  1478. 'article.updated_at',
  1479. 'article.introduce',
  1480. 'article.islink',
  1481. 'article.linkurl',
  1482. 'article.copyfrom',
  1483. 'article.cat_arr_id',
  1484. 'article.catid'
  1485. );
  1486. $count = $query->count();
  1487. $rep = $query->orderBy("updated_at", "desc")
  1488. ->offset(($data['page'] - 1) * $data['pageSize'])
  1489. ->limit($data['pageSize'])
  1490. ->get()->all();
  1491. $categorys = $this->processArticlePro($website_id);
  1492. $cat_1st_arr = $categorys['cat_1st_arr'];
  1493. $catiall = $categorys['catiall'];
  1494. // $web['website_id'] = $data['website_id'];
  1495. foreach ($rep as $k => $v) {
  1496. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1497. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1498. }
  1499. // $rep = $this->processArticles($rep,$web);
  1500. $data = [
  1501. 'rows' => $rep,
  1502. 'count' => $count,
  1503. ];
  1504. if (empty($rep)) {
  1505. return Result::error("没有信息数据");
  1506. }
  1507. return Result::success($data);
  1508. }
  1509. /**
  1510. * 前端-获取新闻详情
  1511. * @param array $data
  1512. * @return array
  1513. */
  1514. public function selectWebsiteArticleInfo(array $data): array
  1515. {
  1516. $where = [
  1517. 'article.id' => $data['id'],
  1518. 'article.status' => 1,
  1519. ];
  1520. $result = Article::where($where)
  1521. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1522. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1523. // ->where(function ($query) use ($data) {
  1524. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1525. // ->orWhereNull("ignore_ids");
  1526. // })
  1527. ->leftJoinSub(function ($query) use ($data) {
  1528. $query->from('article_ignore')
  1529. ->where('website_id', $data['website_id']);
  1530. }, 'article_ignore', function ($join) {
  1531. $join->on('article_ignore.article_id', '=', 'article.id');
  1532. })
  1533. ->where(function ($query) {
  1534. $query->whereNull('article_ignore.article_id')
  1535. ->orWhere(function ($subQuery) {
  1536. $subQuery->whereNotNull('article_ignore.article_id')
  1537. ->where('article_ignore.is_ignore', 0)
  1538. ->where(function ($subSubQuery) {
  1539. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1540. ->orWhereNull('article_ignore.c_show_time');
  1541. });
  1542. });
  1543. })
  1544. ->select(
  1545. 'article.*',
  1546. 'article_data.content',
  1547. 'article_data.article_id',
  1548. 'article_extend.website_url',
  1549. 'article_extend.email',
  1550. 'article_extend.contacts',
  1551. 'article_extend.contacts_mobile',
  1552. 'article_extend.contacts_address',
  1553. 'article_extend.zip_code',
  1554. 'article_extend.enterprise_name'
  1555. )
  1556. ->first();
  1557. if (empty($result)) {
  1558. return Result::error("暂无此新闻!", 0);
  1559. }
  1560. if (!empty($result['publiced_at'])) {
  1561. $result['updated_at'] = $result['publiced_at'];
  1562. }
  1563. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1564. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1565. ->where('website_category.website_id', $data['website_id'])
  1566. ->where(['website_category.category_id' => $result['catid']])
  1567. ->first();
  1568. if (empty($category)) {
  1569. return Result::error("查询失败", 0);
  1570. }
  1571. //手动推荐文章
  1572. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1573. if (empty($commend_ids)) {
  1574. $commendArticle = [];
  1575. } else {
  1576. //去除不存在的文章ID
  1577. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1578. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1579. ->leftJoinSub(function ($query) use ($data) {
  1580. $query->from('article_ignore')
  1581. ->where('website_id', $data['website_id']);
  1582. }, 'article_ignore', function ($join) {
  1583. $join->on('article_ignore.article_id', '=', 'article.id');
  1584. })
  1585. ->where(function ($query) {
  1586. $query->whereNull('article_ignore.article_id')
  1587. ->orWhere(function ($subQuery) {
  1588. $subQuery->whereNotNull('article_ignore.article_id')
  1589. ->where('article_ignore.is_ignore', 0)
  1590. ->where(function ($subSubQuery) {
  1591. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1592. ->orWhereNull('article_ignore.c_show_time');
  1593. });
  1594. });
  1595. })
  1596. ->where('article.status', 1)
  1597. ->where('website_category.website_id', $data['website_id'])
  1598. ->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')
  1599. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1600. // ->orderBy('article.updated_at', 'desc')
  1601. ->limit(5)
  1602. ->get();
  1603. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1604. foreach ($commendArticle as $k => $v) {
  1605. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1606. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1607. $cat_arr_id = array_unique($cat_arr_id);
  1608. // 从website_category取出alias_pinyin
  1609. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1610. ->whereIn('category_id', $cat_arr_id)
  1611. ->pluck('alias_pinyin', 'category_id')
  1612. ->toArray();
  1613. // 将cat_arr_id的json转成路径/隔开
  1614. $path_parts = [];
  1615. foreach ($cat_arr_id as $cat_id) {
  1616. if (isset($cat_arr[$cat_id])) {
  1617. $path_parts[] = $cat_arr[$cat_id];
  1618. }
  1619. }
  1620. $v->alias_pinyin = implode('/', $path_parts);
  1621. } else {
  1622. $v->alias_pinyin = '';
  1623. }
  1624. }
  1625. }
  1626. $result['category_id'] = $category['category_id'];
  1627. $result['cat_name'] = $category['alias'];
  1628. $result['website_name'] = $category['website_name'] ?? "";
  1629. $result['suffix'] = $category['suffix'] ?? "";
  1630. $result['commendArticle'] = $commendArticle;
  1631. $result['commend_ids'] = $commend_ids;
  1632. return Result::success($result);
  1633. }
  1634. /**
  1635. * 前端-获取网站调查问卷
  1636. * @param array $data
  1637. * @return array
  1638. */
  1639. public function getWebsiteSurvey(array $data): array
  1640. {
  1641. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1642. $website = Website::where('id', $data['website_id'])->first();
  1643. if (empty($website)) {
  1644. return Result::error("暂无此网站", 0);
  1645. }
  1646. }
  1647. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1648. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1649. if (empty($article)) {
  1650. return Result::error("暂无此文章", 0);
  1651. }
  1652. // return Result::error($data,0);
  1653. $where['art_id'] = $data['art_id'];
  1654. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1655. } else {
  1656. $survey = Article::where(function ($query) {
  1657. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1658. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1659. })
  1660. ->where('status', 1)
  1661. ->where('is_survey', 1)
  1662. ->select('survey_id')
  1663. ->orderBy('updated_at', 'desc')
  1664. ->first();
  1665. if (empty($survey)) {
  1666. return Result::error("暂无调查问卷", 0);
  1667. }
  1668. $where['sur_id'] = $survey['survey_id'];
  1669. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1670. }
  1671. // return Result::success($where);
  1672. $result = ArticleSurvey::where($where)
  1673. ->where(function ($query) {
  1674. $query->where('is_other', 0)
  1675. ->orWhere(function ($subQuery) {
  1676. $subQuery->where('is_other', 1)
  1677. ->where('other_id', 0);
  1678. });
  1679. })
  1680. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1681. ->select('article_survey.*', 'article.survey_type')
  1682. ->get()->all();
  1683. if (empty($result)) {
  1684. return Result::error("此文章暂无调查问卷", 0);
  1685. }
  1686. return Result::success($result);
  1687. }
  1688. /**
  1689. * 前端-添加网站调查问卷选项
  1690. * @param array $data
  1691. * @return array
  1692. */
  1693. public function addWebsiteSurveyOption(array $data): array
  1694. {
  1695. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1696. $website = Website::where('id', $data['website_id'])->first();
  1697. if (empty($website)) {
  1698. return Result::error("暂无此网站", 0);
  1699. }
  1700. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1701. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1702. if (empty($survey)) {
  1703. return Result::error("此调查问卷不可添加选项", 0);
  1704. }
  1705. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1706. $choice = [
  1707. 'art_id' => $survey['art_id'],
  1708. 'website_id' => $data['website_id'],
  1709. 'survey_name' => $survey['survey_name'],
  1710. 'choice_name' => $data['choice_name'],
  1711. 'sur_id' => $survey['sur_id'],
  1712. 'is_other' => 1,
  1713. 'other_id' => $survey['id'],
  1714. ];
  1715. $result = ArticleSurvey::insertGetId($choice);
  1716. if (empty($result)) {
  1717. return Result::error("添加失败", 0);
  1718. }
  1719. return Result::success($result);
  1720. }
  1721. }
  1722. return Result::error("添加失败", 0);
  1723. }
  1724. return Result::error("添加失败", 0);
  1725. }
  1726. /**
  1727. * 前端-调查问卷投票
  1728. * @param array $data
  1729. * @return array
  1730. */
  1731. public function addWebsiteSurveyVote(array $data): array
  1732. {
  1733. // return Result::success($data);
  1734. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1735. $website = Website::where('id', $data['website_id'])->first();
  1736. if (empty($website)) {
  1737. return Result::error("暂无此网站", 0);
  1738. }
  1739. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1740. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1741. // return Result::success($survey);
  1742. if (empty($is_survey)) {
  1743. return Result::error("此调查问卷不存在", 0);
  1744. }
  1745. // return Result::success($survey);
  1746. // 调查问卷类型
  1747. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1748. //多选 若是json型则转化成数组类型
  1749. if (strpos($data['choice_id'], '[') === 0) {
  1750. $data['choice_id'] = json_decode($data['choice_id'], true);
  1751. } else {
  1752. // 单选 也转换成数组
  1753. $data['choice_id'] = [$data['choice_id']];
  1754. }
  1755. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1756. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1757. // ->where('website_id',$data['website_id'])
  1758. ->where('is_other', 1)
  1759. ->where('other_id', 0)
  1760. ->first();
  1761. if (!empty($other)) {
  1762. return Result::error("请选择已有的选项!", 0);
  1763. }
  1764. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1765. // ->where('website_id',$data['website_id'])
  1766. ->where('is_other', 1)
  1767. ->where('other_id', '!=', 0)
  1768. ->first();
  1769. // return Result::success($choice['other']);
  1770. $choice_id = $data['choice_id'];
  1771. if (!empty($choice['other'])) {
  1772. // array_push($data['choice_id'],$choice['other']['other_id']);
  1773. if (!empty($choice_id)) {
  1774. $key = array_search($choice['other']['id'], $choice_id);
  1775. if ($key !== false) {
  1776. unset($choice_id[$key]);
  1777. $choice_id = array_values($choice_id);
  1778. }
  1779. array_push($choice_id, $choice['other']['other_id']);
  1780. } else {
  1781. $choice_id[0] = $choice['other']['other_id'];
  1782. }
  1783. array_push($data['choice_id'], $choice['other']['other_id']);
  1784. }
  1785. // return Result::success($data);
  1786. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1787. // ->where('website_id',$data['website_id'])
  1788. ->increment('results', 1);
  1789. if (empty($choice)) {
  1790. return Result::error("请选择已有的选项!", 0);
  1791. }
  1792. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1793. // ->where('website_id',$data['website_id'])
  1794. ->where('other_id', 0)
  1795. ->get();
  1796. $survey['choice'] = $choice_id;
  1797. return Result::success($survey);
  1798. }
  1799. return Result::error("参数必填!");
  1800. }
  1801. return Result::error("此调查问卷不存在", 0);
  1802. }
  1803. return Result::error("参数必填!");
  1804. }
  1805. /**
  1806. * 后端-获取网站调查问卷列表
  1807. * @param array $data
  1808. * @return array
  1809. */
  1810. public function getSurveyList(array $data): array
  1811. {
  1812. $where = [];
  1813. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1814. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1815. }
  1816. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1817. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1818. }
  1819. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1820. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1821. }
  1822. // return Result::success($where);
  1823. if (!empty($where)) {
  1824. $query = Article::where($where)->where(function ($q) {
  1825. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1826. });
  1827. } else {
  1828. $query = Article::where(function ($q) {
  1829. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1830. });
  1831. }
  1832. $count = $query->count();
  1833. $survey = $query->orderByDesc('id')
  1834. ->limit($data['pageSize'])
  1835. ->offset(($data['page'] - 1) * $data['pageSize'])
  1836. ->get();
  1837. if (empty($survey->toArray())) {
  1838. return Result::error("暂无调查问卷!", 0);
  1839. }
  1840. $result = [
  1841. 'rows' => $survey,
  1842. 'count' => $count,
  1843. ];
  1844. return Result::success($result);
  1845. }
  1846. /**
  1847. * 后端-获取网站调查问卷详情
  1848. * @param array $data
  1849. * @return array
  1850. */
  1851. public function getSurveyInfo(array $data): array
  1852. {
  1853. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1854. $where = ['sur_id' => $data['sur_id']];
  1855. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1856. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1857. ->select('article_survey.*', 'article.survey_type')
  1858. ->get()->all();
  1859. if (empty($choose)) {
  1860. return Result::error("此调查问卷不存在", 0);
  1861. }
  1862. $resultsArray = array_column($choose, 'results');
  1863. $total = array_sum($resultsArray);
  1864. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1865. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1866. // $total = 0;
  1867. if (!empty($other)) {
  1868. $total = $total + $other['results'];
  1869. $other['choice_name'] = '(其他)';
  1870. if (!empty($others)) {
  1871. $other['hasChildren'] = true;
  1872. // array_push($other,['hasChildren','=',true]);
  1873. $other['children'] = $others;
  1874. $other_choices = [$other->toArray()];
  1875. $mer_choice = array_merge($choose, $other_choices);
  1876. $value_choice = array_values($mer_choice);
  1877. } else {
  1878. // return Result::error('1111');
  1879. $other_choices = [$other->toArray()];
  1880. $other_choices = array_merge($choose, $other_choices);
  1881. $value_choice = array_values($other_choices);
  1882. // return Result::success($result);
  1883. }
  1884. } else {
  1885. $value_choice = $choose;
  1886. }
  1887. $result = [
  1888. 'choose' => $value_choice,
  1889. 'total' => $total,
  1890. ];
  1891. }
  1892. return Result::success($result);
  1893. }
  1894. /**
  1895. * 前端-搜索新闻列表
  1896. * @param array $data
  1897. * @return array
  1898. */
  1899. public function selectWebsiteArticle(array $data): array
  1900. {
  1901. $website = Website::where('id', $data['website_id'])->first();
  1902. if (empty($website)) {
  1903. return Result::error("网站不存在", 0);
  1904. }
  1905. // $website_column = $website['column'];
  1906. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1907. $website_column = json_decode($website['website_column_arr_id'], true);
  1908. }
  1909. $website_id = $data['website_id'];
  1910. $categorys = $this->processArticlePro($website_id);
  1911. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1912. // return Result::success($diff_pid_categoryIds);
  1913. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1914. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1915. }
  1916. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1917. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1918. $catiall = $categorys['catiall'];
  1919. $categoryIds = $categorys['categoryIds'];
  1920. // return Result::success($categoryIds);
  1921. $query = Article::where('status', 1)
  1922. ->whereIn('catid', $categoryIds)
  1923. ->leftJoinSub(function ($query) use ($website_id) {
  1924. $query->from('article_ignore')
  1925. ->where('website_id', $website_id);
  1926. }, 'article_ignore', function ($join) {
  1927. $join->on('article_ignore.article_id', '=', 'article.id');
  1928. })
  1929. ->where(function ($query) {
  1930. $query->whereNull('article_ignore.article_id')
  1931. ->orWhere(function ($subQuery) {
  1932. $subQuery->whereNotNull('article_ignore.article_id')
  1933. ->where('article_ignore.is_ignore', 0)
  1934. ->where(function ($subSubQuery) {
  1935. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1936. ->orWhereNull('article_ignore.c_show_time');
  1937. });
  1938. });
  1939. });
  1940. // ->get()->all();
  1941. // return Result::success($query);
  1942. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1943. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1944. }
  1945. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1946. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1947. }
  1948. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1949. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1950. }
  1951. // 计算总数
  1952. $count = $query->count();
  1953. // return Result::success($count);
  1954. // 分页查询
  1955. $articles = $query
  1956. ->select(
  1957. 'article.id',
  1958. 'article.title',
  1959. 'article.imgurl',
  1960. 'article.author',
  1961. 'article.updated_at',
  1962. 'article.introduce',
  1963. 'article.islink',
  1964. 'article.linkurl',
  1965. 'article.copyfrom',
  1966. 'article.cat_arr_id',
  1967. 'article.catid',
  1968. 'article.department_arr_id',
  1969. 'article.city_arr_id',
  1970. // 'article_ignore.c_show_time',
  1971. // 'article_ignore.is_ignore'
  1972. )
  1973. ->orderBy("updated_at", "desc")
  1974. ->offset(($data['page'] - 1) * $data['pageSize'])
  1975. ->limit($data['pageSize'])
  1976. ->get();
  1977. // return Result::success($articles);
  1978. foreach ($articles as $k => $v) {
  1979. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1980. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1981. }
  1982. if (empty($articles)) {
  1983. return Result::error("没有符合条件的资讯数据");
  1984. }
  1985. $result = [
  1986. 'rows' => $articles,
  1987. 'count' => $count,
  1988. ];
  1989. return Result::success($result);
  1990. }
  1991. /**
  1992. * 模块新闻加强版
  1993. * @param array $data
  1994. * @return array
  1995. */
  1996. public function getWebsiteCatidArticle(array $data): array
  1997. {
  1998. $where = [
  1999. 'website_category.category_id' => $data['catid'],
  2000. 'website_category.website_id' => $data['website_id'],
  2001. ];
  2002. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2003. $child_catnum = $data['child_catnum'] ?? 1;
  2004. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2005. $childCategoryIds = array_column($category['child'], 'category_id');
  2006. if (empty($childCategoryIds)) {
  2007. return Result::error("暂无子栏目", 0);
  2008. }
  2009. $imgArticles = [];
  2010. $textArticles = [];
  2011. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2012. // 初始化子分类图片新闻和文字新闻数组
  2013. // 查询所有子级栏目的图文新闻
  2014. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2015. ->where(function ($query) use ($data) {
  2016. $query->where(function ($subQuery) use ($data) {
  2017. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2018. })->orWhereNull("ignore_ids");
  2019. })
  2020. ->where('status', 1)
  2021. ->where('imgurl', '!=', '')
  2022. ->select('*')
  2023. ->orderBy('updated_at', 'desc')
  2024. ->limit($data['child_imgnum'])
  2025. ->get();
  2026. }
  2027. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2028. // 查询所有子级栏目的文字新闻
  2029. $textArticles = Article::where('catid', $childCategoryIds[0])
  2030. ->where('status', 1)
  2031. ->where(function ($query) use ($data) {
  2032. $query->where(function ($subQuery) use ($data) {
  2033. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2034. })->orWhereNull("ignore_ids");
  2035. })
  2036. ->select('*')
  2037. ->orderBy('updated_at', 'desc')
  2038. ->limit($data['child_textnum'])
  2039. ->get();
  2040. }
  2041. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2042. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2043. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2044. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2045. return $child;
  2046. }, $category['child']);
  2047. }
  2048. // }
  2049. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2050. $category['img'] = WebsiteCategory::where($where)
  2051. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2052. ->where('article.status', 1)
  2053. ->where('article.imgurl', '!=', '')
  2054. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2055. ->orderBy('article.updated_at', 'desc')
  2056. ->limit($data['img_num'])
  2057. ->get();
  2058. }
  2059. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2060. $category['text'] = WebsiteCategory::where($where)
  2061. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2062. ->where('article.status', 1)
  2063. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2064. ->orderBy('article.updated_at', 'desc')
  2065. ->limit($data['text_num'])
  2066. ->get();
  2067. }
  2068. // $category = $category->get();
  2069. if (empty($category)) {
  2070. return Result::error("查询失败", 0);
  2071. }
  2072. return Result::success($category);
  2073. }
  2074. /**
  2075. * 模块新闻加强plus版
  2076. * @param array $data
  2077. * @return array
  2078. */
  2079. public function getWebsiteAllArticle(array $data): array
  2080. {
  2081. // return Result::success($data);
  2082. $time1 = microtime(true);
  2083. $wetbsite_id = $data['website_id'] ?? 2;
  2084. $data = json_decode($data['id'], true);
  2085. $website = Website::where('id', $wetbsite_id)->first();
  2086. if (empty($website)) {
  2087. return Result::error("网站不存在", 0);
  2088. }
  2089. // return Result::success($website);
  2090. $website_column = $website['website_column_arr_id'] ?? '[]';
  2091. $website_column = json_decode($website_column, true);
  2092. $categorys = $this->processArticlePro($wetbsite_id);
  2093. $cat_1st_arr = $categorys['cat_1st_arr'];
  2094. $catiall = $categorys['catiall'];
  2095. // return Result::success($catiall);
  2096. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2097. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2098. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2099. }
  2100. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2101. // return Result::success($categorys);
  2102. $parent_category = array_column($data, 'parent');
  2103. $parent_cat = [];
  2104. $child_category = array_column($data, 'child');
  2105. if (!empty($parent_category)) {
  2106. foreach ($parent_category as $key => $value) {
  2107. $arr = array_map('intval', explode(',', $value));
  2108. $parent_cat[$key] = $arr[0] ?? 0;
  2109. $parent_category = $arr[0] ?? 0;
  2110. $article_imgnum = $arr[1] ?? 0;
  2111. $article_textnum = $arr[2] ?? 0;
  2112. if ($parent_category != 0) {
  2113. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2114. // return Result::success($category_arr);
  2115. if ($article_imgnum != 0) {
  2116. $img_article = Article::whereIn('catid', $category_arr)
  2117. ->where('status', 1)
  2118. ->where('imgurl', '!=', '')
  2119. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2120. $query->from('article_ignore')
  2121. ->where('website_id', $wetbsite_id);
  2122. }, 'article_ignore', function ($join) {
  2123. $join->on('article_ignore.article_id', '=', 'article.id');
  2124. })
  2125. ->where(function ($query) {
  2126. $query->whereNull('article_ignore.article_id')
  2127. ->orWhere(function ($subQuery) {
  2128. $subQuery->whereNotNull('article_ignore.article_id')
  2129. ->where('article_ignore.is_ignore', 0)
  2130. ->where(function ($subSubQuery) {
  2131. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2132. ->orWhereNull('article_ignore.c_show_time');
  2133. });
  2134. });
  2135. })
  2136. ->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')
  2137. ->orderBy('updated_at', 'desc')
  2138. ->limit($article_imgnum)
  2139. ->get()->all();
  2140. foreach ($img_article as $k => $v) {
  2141. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2142. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2143. }
  2144. } else {
  2145. $img_article = [];
  2146. }
  2147. if ($article_textnum != 0) {
  2148. $text_article = Article::whereIn('catid', $category_arr)
  2149. ->where('status', 1)
  2150. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2151. $query->from('article_ignore')
  2152. ->where('website_id', $wetbsite_id);
  2153. }, 'article_ignore', function ($join) {
  2154. $join->on('article_ignore.article_id', '=', 'article.id');
  2155. })
  2156. ->where(function ($query) {
  2157. $query->whereNull('article_ignore.article_id')
  2158. ->orWhere(function ($subQuery) {
  2159. $subQuery->whereNotNull('article_ignore.article_id')
  2160. ->where('article_ignore.is_ignore', 0)
  2161. ->where(function ($subSubQuery) {
  2162. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2163. ->orWhereNull('article_ignore.c_show_time');
  2164. });
  2165. });
  2166. })
  2167. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2168. ->orderBy('updated_at', 'desc')
  2169. ->limit($article_textnum)
  2170. ->get()->all();
  2171. foreach ($text_article as $k => $v) {
  2172. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2173. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2174. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2175. }
  2176. } else {
  2177. $text_article = [];
  2178. }
  2179. $catiall[$parent_category]['imgnum'] = $img_article;
  2180. $catiall[$parent_category]['textnum'] = $text_article;
  2181. $parent[$key] = $catiall[$parent_category];
  2182. } else {
  2183. $parent[$key] = '';
  2184. }
  2185. }
  2186. }
  2187. if (!empty($child_category)) {
  2188. foreach ($child_category as $key => $value) {
  2189. $arr = array_map('intval', explode(',', $value));
  2190. $parent_category = $parent_cat[$key];
  2191. $child_category = $arr[0] ?? 0;
  2192. $article_imgnum = $arr[1] ?? 0;
  2193. $article_textnum = $arr[2] ?? 0;
  2194. if ($child_category != 0) {
  2195. $all_childcat = $cat_1st_arr[$parent_category];
  2196. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2197. // 从 $websiteInfoIndexed 中获取对应的数据
  2198. $info = $websiteInfoIndexed[$v];
  2199. // 返回一个包含所需信息的数组
  2200. return [
  2201. 'alias' => $info->alias,
  2202. 'category_id' => $info->category_id,
  2203. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2204. 'pid' => $info->pid,
  2205. 'type' => $info->type,
  2206. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2207. 'pinyin' => $info->pinyin,
  2208. ];
  2209. }, $all_childcat);
  2210. if ($article_imgnum != 0) {
  2211. $img_article = Article::where('catid', $child_category)
  2212. ->where('status', 1)
  2213. ->where('imgurl', '!=', '')
  2214. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2215. $query->from('article_ignore')
  2216. ->where('website_id', $wetbsite_id);
  2217. }, 'article_ignore', function ($join) {
  2218. $join->on('article_ignore.article_id', '=', 'article.id');
  2219. })
  2220. ->where(function ($query) {
  2221. $query->whereNull('article_ignore.article_id')
  2222. ->orWhere(function ($subQuery) {
  2223. $subQuery->whereNotNull('article_ignore.article_id')
  2224. ->where('article_ignore.is_ignore', 0)
  2225. ->where(function ($subSubQuery) {
  2226. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2227. ->orWhereNull('article_ignore.c_show_time');
  2228. });
  2229. });
  2230. })
  2231. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2232. ->orderBy('updated_at', 'desc')
  2233. ->limit($article_imgnum)
  2234. ->get()->all();
  2235. foreach ($img_article as $k => $v) {
  2236. // var_dump($v);
  2237. // var_dump($k);
  2238. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2239. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2240. }
  2241. } else {
  2242. $img_article = [];
  2243. }
  2244. if ($article_textnum != 0) {
  2245. $text_article = Article::where('catid', $child_category)
  2246. ->where('status', 1)
  2247. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2248. $query->from('article_ignore')
  2249. ->where('website_id', $wetbsite_id);
  2250. }, 'article_ignore', function ($join) {
  2251. $join->on('article_ignore.article_id', '=', 'article.id');
  2252. })
  2253. ->where(function ($query) {
  2254. $query->whereNull('article_ignore.article_id')
  2255. ->orWhere(function ($subQuery) {
  2256. $subQuery->whereNotNull('article_ignore.article_id')
  2257. ->where('article_ignore.is_ignore', 0)
  2258. ->where(function ($subSubQuery) {
  2259. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2260. ->orWhereNull('article_ignore.c_show_time');
  2261. });
  2262. });
  2263. })
  2264. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2265. ->orderBy('updated_at', 'desc')
  2266. ->limit($article_textnum)
  2267. ->get()->all();
  2268. foreach ($text_article as $k => $v) {
  2269. // var_dump($v);
  2270. // var_dump($k);
  2271. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2272. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2273. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2274. }
  2275. } else {
  2276. $text_article = [];
  2277. }
  2278. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2279. $catiall[$child_category]['imgnum'] = $img_article;
  2280. $catiall[$child_category]['textnum'] = $text_article;
  2281. $child[$key] = $catiall[$child_category];
  2282. // var_dump($pids);
  2283. } else {
  2284. $child[$key] = '';
  2285. }
  2286. }
  2287. }
  2288. foreach ($parent as $key => $value) {
  2289. $result[$key] = $value;
  2290. if (!empty($child[$key])) {
  2291. // var_dump($child[$key]);
  2292. $result[$key]['child'] = $child[$key];
  2293. // $value[$key]['child'] = $child[$key];
  2294. } else {
  2295. $result[$key]['child'] = [
  2296. "alias" => null,
  2297. "category_id" => null,
  2298. "type" => null,
  2299. "pinyin" => null,
  2300. "all_childcat" => [],
  2301. "imgnum" => [],
  2302. "textnum" => []
  2303. ];
  2304. }
  2305. }
  2306. return Result::success($result);
  2307. }
  2308. /**
  2309. * 辅助方法:获取文章列表
  2310. */
  2311. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2312. {
  2313. sleep(1);
  2314. $query = Article::where('article.status', 1)
  2315. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2316. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2317. ->where(function ($query) use ($website) {
  2318. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2319. })
  2320. ->leftJoin('website_category', function ($join) use ($website) {
  2321. $join->on('article.catid', '=', 'website_category.category_id')
  2322. ->where('website_category.website_id', '=', $website['website_id']);
  2323. })
  2324. ->select(
  2325. 'article.id',
  2326. 'article.title',
  2327. 'article.imgurl',
  2328. 'article.author',
  2329. 'article.updated_at',
  2330. 'article.introduce',
  2331. 'article.islink',
  2332. 'article.linkurl',
  2333. 'article.copyfrom',
  2334. 'article.cat_arr_id',
  2335. 'article.catid',
  2336. 'website_category.alias as category_name'
  2337. )
  2338. ->orderBy('updated_at', 'desc')
  2339. ->limit($limit);
  2340. // 如果是图片文章,添加图片URL条件
  2341. if ($isImageArticle) {
  2342. $query->where('imgurl', '!=', '');
  2343. } else {
  2344. // 文字文章不需要imgurl字段
  2345. $query->addSelect('article.introduce');
  2346. }
  2347. $articles = $query->get();
  2348. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2349. }
  2350. /**
  2351. * 乡村网-获取特殊新闻模块
  2352. * @param array $data
  2353. * @return array
  2354. */
  2355. public function getWebsiteArticles(array $data): array
  2356. {
  2357. $website_id = $data['website_id'];
  2358. $website = Website::where('id', $website_id)->first();
  2359. if (empty($website)) {
  2360. return Result::error("网站不存在", 0);
  2361. }
  2362. // return Result::success($website);
  2363. $website_column = $website['website_column_arr_id'] ?? '[]';
  2364. $website_column = json_decode($website_column, true);
  2365. $catids = json_decode($data['id'], true);
  2366. $parent_category = array_column($catids, 'parent');
  2367. if (!empty($parent_category) && is_array($parent_category)) {
  2368. $categorys = $this->processArticlePro($website_id);
  2369. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2370. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2371. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2372. }
  2373. $catiall = $categorys['catiall'];
  2374. $cat_1st_arr = $categorys['cat_1st_arr'];
  2375. // return Result::success($categorys);
  2376. foreach ($parent_category as $key => $value) {
  2377. $arr = array_map('intval', explode(',', $value));
  2378. $parent_category = $arr[0] ?? 0;
  2379. $article_imgnum = $arr[1] ?? 0;
  2380. $article_textnum = $arr[2] ?? 0;
  2381. if ($parent_category != 0) {
  2382. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2383. // return Result::success($category_arr);
  2384. if ($article_imgnum != 0) {
  2385. $img_article = Article::whereIn('article.catid', $category_arr)
  2386. ->where('article.status', 1)
  2387. ->where('article.imgurl', '!=', '')
  2388. ->leftJoinSub(function ($query) use ($website_id) {
  2389. $query->from('article_ignore')
  2390. ->where('website_id', $website_id);
  2391. }, 'article_ignore', function ($join) {
  2392. $join->on('article_ignore.article_id', '=', 'article.id');
  2393. })
  2394. ->where(function ($query) {
  2395. $query->whereNull('article_ignore.article_id')
  2396. ->orWhere(function ($subQuery) {
  2397. $subQuery->whereNotNull('article_ignore.article_id')
  2398. ->where('article_ignore.is_ignore', 0)
  2399. ->where(function ($subSubQuery) {
  2400. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2401. ->orWhereNull('article_ignore.c_show_time');
  2402. });
  2403. });
  2404. })
  2405. ->select(
  2406. 'article.id',
  2407. 'article.title',
  2408. 'article.imgurl',
  2409. 'article.author',
  2410. 'article.updated_at',
  2411. 'article.introduce',
  2412. 'article.islink',
  2413. 'article.linkurl',
  2414. 'article.copyfrom',
  2415. 'article.cat_arr_id',
  2416. 'article.catid as category_id'
  2417. )
  2418. ->orderBy('updated_at', 'desc')
  2419. ->limit($article_imgnum)
  2420. ->get()->all();
  2421. foreach ($img_article as $k => $v) {
  2422. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2423. // return Result::success($v);
  2424. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2425. }
  2426. } else {
  2427. $img_article = [];
  2428. }
  2429. if ($article_textnum != 0) {
  2430. $text_article = Article::whereIn('article.catid', $category_arr)
  2431. ->where('article.status', 1)
  2432. ->leftJoinSub(function ($query) use ($website_id) {
  2433. $query->from('article_ignore')
  2434. ->where('website_id', $website_id);
  2435. }, 'article_ignore', function ($join) {
  2436. $join->on('article_ignore.article_id', '=', 'article.id');
  2437. })
  2438. ->where(function ($query) {
  2439. $query->whereNull('article_ignore.article_id')
  2440. ->orWhere(function ($subQuery) {
  2441. $subQuery->whereNotNull('article_ignore.article_id')
  2442. ->where('article_ignore.is_ignore', 0)
  2443. ->where(function ($subSubQuery) {
  2444. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2445. ->orWhereNull('article_ignore.c_show_time');
  2446. });
  2447. });
  2448. })
  2449. ->select(
  2450. 'article.id',
  2451. 'article.title',
  2452. 'article.author',
  2453. 'article.updated_at',
  2454. 'article.introduce',
  2455. 'article.islink',
  2456. 'article.linkurl',
  2457. 'article.copyfrom',
  2458. 'article.cat_arr_id',
  2459. 'article.catid as category_id'
  2460. )
  2461. ->orderBy('updated_at', 'desc')
  2462. ->limit($article_textnum)
  2463. ->get()->all();
  2464. foreach ($text_article as $k => $v) {
  2465. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2466. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2467. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2468. }
  2469. } else {
  2470. $text_article = [];
  2471. }
  2472. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2473. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2474. $parent[$key] = $catiall[$parent_category];
  2475. } else {
  2476. $parent[$key] = [];
  2477. }
  2478. }
  2479. }
  2480. return Result::success($parent);
  2481. }
  2482. // 封装处理商品的路由问题
  2483. function processGoods($goods, $data)
  2484. {
  2485. return $goods->map(function ($good) use ($data) {
  2486. $catid = $good->catid ?? 0;
  2487. // $pinyin = '';
  2488. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2489. if (!empty($category->pid) && $category->pid != 0) {
  2490. $level = json_decode($category->category_arr_id, true);
  2491. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2492. ->whereIn('category_id', $level)
  2493. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2494. ->get(['aLIas_pinyin'])
  2495. ->pluck('aLIas_pinyin')
  2496. ->implode('/');
  2497. } else {
  2498. $pinyin = $category->aLIas_pinyin ?? '';
  2499. }
  2500. if (isset($good->city_id) && !empty($good->city_id)) {
  2501. $city = District::where('id', $good->city_id)->first(['name']);
  2502. $good->city_name = $city->name ?? '';
  2503. }
  2504. // 解析imgurl JSON并取第一条数据
  2505. $imgUrls = json_decode($good->imgurl, true);
  2506. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2507. $good->pinyin = $pinyin;
  2508. return $good;
  2509. });
  2510. }
  2511. /**
  2512. * 获取商城首页-根据栏目id
  2513. * @param array $data
  2514. * @return array
  2515. * */
  2516. function getWebsiteCatidshop(array $data): array
  2517. {
  2518. $input['catid'] = $data['catid'];
  2519. $input['website_id'] = $data['website_id'];
  2520. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2521. $result = array_map(function ($item) use ($input) {
  2522. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2523. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2524. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2525. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2526. if (empty($category) || $category->type != 2) {
  2527. return Result::error("暂无此栏目", 0);
  2528. } else {
  2529. $website['website_id'] = $input['website_id'];
  2530. $goods = Good::where('good.status', 2)
  2531. ->where('good.website_id', $website['website_id'])
  2532. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2533. ->select(
  2534. 'good.id',
  2535. 'good.name',
  2536. 'good.imgurl',
  2537. 'good.description',
  2538. 'good.updated_at',
  2539. 'good.catid',
  2540. 'good.type_id',
  2541. 'good.price',
  2542. 'good.com',
  2543. 'good.level',
  2544. 'good.unit'
  2545. )
  2546. ->orderBy('updated_at', 'desc')
  2547. ->offset($goodStart)
  2548. ->limit($goodNum);
  2549. $all_goods = $goods->get();
  2550. $all_goods = $this->processGoods($all_goods, $website);
  2551. }
  2552. return $all_goods ?? [];
  2553. }
  2554. }, $data);
  2555. return Result::success($result);
  2556. }
  2557. /**
  2558. * 获取商品模块
  2559. * @param array $data
  2560. * @return array
  2561. * */
  2562. public function getWebsiteshop(array $data): array
  2563. {
  2564. $input['id'] = $data['id'];
  2565. $input['website_id'] = $data['website_id'];
  2566. $catid = $data['catid'];
  2567. $data = json_decode($input['id'] ?? '', true) ?? [];
  2568. $result['goods'] = array_map(function ($item) use ($input) {
  2569. // 检查parent元素是否存在且不是undefined
  2570. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2571. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2572. $website = $input['website_id'];
  2573. $query = Good::where('good.status', 2)
  2574. ->where('good.website_id', $website);
  2575. switch ($Levelid) {
  2576. case 1:
  2577. case 2:
  2578. case 3:
  2579. $goods = $query->where(function ($q) use ($Levelid) {
  2580. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2581. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2582. });
  2583. break;
  2584. case 4:
  2585. $goods = $query;
  2586. break;
  2587. case 5:
  2588. $goods = $query->where('type_id', 1);
  2589. break;
  2590. case 6:
  2591. $goods = $query->where('type_id', 2);
  2592. break;
  2593. default:
  2594. return [];
  2595. }
  2596. $all_goods = $goods
  2597. ->select(
  2598. 'good.id',
  2599. 'good.name',
  2600. 'good.imgurl',
  2601. 'good.description',
  2602. 'good.updated_at',
  2603. 'good.catid',
  2604. 'good.type_id',
  2605. 'good.price',
  2606. 'good.level',
  2607. 'good.website_id'
  2608. )
  2609. ->orderBy('updated_at', 'desc')
  2610. ->offset($goodStart)
  2611. ->limit($goodNum)
  2612. ->get();
  2613. $web['website_id'] = $website;
  2614. $all_goods = $this->processGoods($all_goods, $web);
  2615. }
  2616. return $all_goods;
  2617. }, $data);
  2618. $website = $input['website_id'];
  2619. $result['article'] = Article::where(function ($query) use ($website) {
  2620. $query->where(function ($subQuery) use ($website) {
  2621. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2622. })->orWhereNull("ignore_ids");
  2623. })
  2624. ->where('catid', $catid)
  2625. ->where('article.status', 1)
  2626. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2627. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2628. ->orderBy('article.updated_at', 'desc')
  2629. ->first();
  2630. return Result::success($result);
  2631. }
  2632. /**
  2633. * 获取商品分类
  2634. * @param array $data
  2635. * @return array
  2636. * */
  2637. public function getWebsiteshopCat(array $data): array
  2638. {
  2639. $website = $data['website_id'];
  2640. $category = WebsiteCategory::where('website_id', $website)
  2641. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2642. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2643. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2644. ->orderBy('sort')
  2645. ->get();
  2646. $cat = $category->map(function ($item) use ($website) {
  2647. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2648. $pid = $item->pid ?? 0;
  2649. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2650. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2651. ->where('website_id', $website)
  2652. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2653. ->get(['aLIas_pinyin'])
  2654. ->pluck('aLIas_pinyin')
  2655. ->implode('/');
  2656. } else {
  2657. $pinyin = $item->aLIas_pinyin ?? '';
  2658. }
  2659. $item->pinyin = $pinyin;
  2660. });
  2661. if (empty($category)) {
  2662. return Result::error("栏目查询失败", 0);
  2663. }
  2664. $cat_tree = Result::buildMenuTree($category);
  2665. $web['website_id'] = $website;
  2666. $goods = Good::where('website_id', $website)
  2667. ->where('status', 2)
  2668. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2669. ->latest('updated_at')
  2670. ->offset(($data['page'] - 1) * $data['pageSize'])
  2671. ->limit($data['pageSize'])
  2672. ->get();
  2673. if (!empty($goods)) {
  2674. if ($goods->count() > 1 && !empty($goods)) {
  2675. $goods = $this->processGoods($goods, $web);
  2676. }
  2677. } else {
  2678. $goods = [];
  2679. }
  2680. $result = [
  2681. 'category' => $cat_tree,
  2682. 'goods' => $goods,
  2683. ];
  2684. // $resul['goods'] = $goods;
  2685. if (empty($result)) {
  2686. return Result::error("查询失败", 0);
  2687. }
  2688. return Result::success($result);
  2689. }
  2690. /*
  2691. * 获取商品列表
  2692. * @param array $data
  2693. * @return array
  2694. * */
  2695. public function getWebsiteshopList(array $data): array
  2696. {
  2697. // return Result::success($data);
  2698. $where = [
  2699. 'status' => 2,
  2700. 'website_id' => $data['website_id'],
  2701. ];
  2702. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2703. // return Result::error("查询失败", 0);
  2704. // }
  2705. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2706. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2707. $data['catid'] = $category->category_id ?? 0;
  2708. }
  2709. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2710. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2711. }
  2712. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2713. array_push($where, ['type_id', $data['type_id']]);
  2714. }
  2715. $query = Good::where($where)
  2716. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2717. $query->where(function ($q) use ($data) {
  2718. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2719. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2720. });
  2721. })
  2722. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2723. $query->where(function ($q) use ($data) {
  2724. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2725. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2726. });
  2727. })
  2728. ->select(
  2729. 'good.id',
  2730. 'good.name',
  2731. 'good.imgurl',
  2732. 'good.description',
  2733. 'good.updated_at',
  2734. 'good.com',
  2735. 'good.catid',
  2736. 'good.type_id',
  2737. 'good.website_id',
  2738. 'good.cat_arr_id',
  2739. 'good.created_at',
  2740. 'good.city_id'
  2741. )
  2742. ->latest('updated_at');
  2743. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2744. $result['count'] = $query->clone()->count();
  2745. $result['goods'] = $this->processGoods(
  2746. $query->clone()
  2747. ->offset(($data['page'] - 1) * $data['pageSize'])
  2748. ->limit($data['pageSize'])
  2749. ->get(),
  2750. $data
  2751. );
  2752. } else {
  2753. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2754. // 获取 type_id 为 1 的数据
  2755. $result['type1'] = $this->processGoods(
  2756. $query->clone()
  2757. ->where('type_id', 1)
  2758. ->offset(($data['page'] - 1) * $data['pageSize'])
  2759. ->limit($data['pageSize'])
  2760. ->get(),
  2761. $data
  2762. );
  2763. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2764. // 获取 type_id 为 2 的数据
  2765. $result['type2'] = $this->processGoods(
  2766. $query->clone()
  2767. ->where('type_id', 2)
  2768. ->offset(($data['page'] - 1) * $data['pageSize'])
  2769. ->limit($data['pageSize'])
  2770. ->get(),
  2771. $data
  2772. );
  2773. }
  2774. if (empty($result)) {
  2775. return Result::error("查询失败", 0);
  2776. }
  2777. return Result::success($result);
  2778. }
  2779. /**
  2780. * 获取商品详情
  2781. * @param array $data
  2782. * @return array
  2783. * */
  2784. public function getWebsiteshopInfo(array $data): array
  2785. {
  2786. $where = [
  2787. 'good.status' => 2,
  2788. 'good.website_id' => $data['website_id'],
  2789. 'good.id' => $data['id'],
  2790. ];
  2791. $goods = Good::where($where)
  2792. ->where('good.id', $data['id'])
  2793. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2794. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2795. ->first();
  2796. if (empty($goods)) {
  2797. return Result::error("查询失败", 0);
  2798. }
  2799. $goods->imgurl = json_decode($goods->imgurl, true);
  2800. return Result::success($goods);
  2801. }
  2802. /**
  2803. * plus pro 处理文章路由问题
  2804. */
  2805. function processArticlePro($website_id)
  2806. {
  2807. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2808. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2809. // // 取出category_id 对应的aLIas_pinyin
  2810. // $categoryIds = array_column($categorys, 'category_id');
  2811. // $categoryPIds = array_column($categorys, 'pid');
  2812. // $aliasPinyins = array_column($categorys, 'path');
  2813. // $alias = array_column($categorys, 'alias');
  2814. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2815. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2816. // // return Result::success($cat_arr);
  2817. // // $catiall = [];
  2818. // //一级所有子级的记录
  2819. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2820. // return [
  2821. // 'cat_1st_arr' => $cat_alias_arr,
  2822. // 'catiall' => $cat_arr,
  2823. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2824. // 'categoryIds' => $categoryIds,
  2825. // ];
  2826. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2827. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2828. // 取出category_id 对应的aLIas_pinyin
  2829. $categoryIds = array_column($categorys, 'category_id');
  2830. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2831. return $pid != 0;
  2832. })));
  2833. $category_path = array_column($categorys, 'path');
  2834. $cat_arr = array_combine($categoryIds, $category_path);
  2835. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2836. $catiall = [];
  2837. //一级所有子级的记录
  2838. $cat_1st_arr = [];
  2839. foreach ($categorys as $key => $value) {
  2840. // $category_arr_id = json_decode($value->category_arr_id);
  2841. // $pinyin_str = '';
  2842. // // 算出一级 并且算出子级
  2843. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2844. $cat_1st_arr[$value->pid][] = $value->category_id;
  2845. }
  2846. // foreach ($category_arr_id as $k => $v) {
  2847. // $pinyin_str .= $cat_arr[$v] . '/';
  2848. // }
  2849. // $pinyin_str = rtrim($pinyin_str, '/');
  2850. $catiall[$value->category_id]['alias'] = $value->alias;
  2851. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2852. $catiall[$value->category_id]['type'] = $value->type;
  2853. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2854. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2855. }
  2856. return [
  2857. 'cat_1st_arr' => $cat_1st_arr,
  2858. 'catiall' => $catiall,
  2859. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2860. 'categoryIds' => $categoryIds,
  2861. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2862. 'categoryPIds' => $categoryPIds,
  2863. ];
  2864. }
  2865. /**
  2866. * 封装处理文章的路由问题
  2867. * */
  2868. function processArticles($articles, $data)
  2869. {
  2870. // 检查 $articles 是否为数组或可迭代对象
  2871. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2872. return $articles->map(function ($article) use ($data) {
  2873. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2874. $catid = $article->cat_arr_id ?? '';
  2875. }
  2876. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2877. $catid = $article->category_arr_id ?? '';
  2878. }
  2879. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2880. $level = json_decode($catid, true);
  2881. if (!is_array($level)) {
  2882. return $article;
  2883. } else {
  2884. $level = array_map('intval', $level);
  2885. }
  2886. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2887. ->where($data)
  2888. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2889. ->pluck('aLIas_pinyin')
  2890. ->implode('/');
  2891. $article->pinyin = $pinyin ?? '';
  2892. return $article;
  2893. });
  2894. } else {
  2895. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2896. $catid = $articles->cat_arr_id ?? '';
  2897. $level = json_decode($catid, true);
  2898. if (!is_array($level)) {
  2899. return $articles;
  2900. } else {
  2901. $level = array_map('intval', $level);
  2902. }
  2903. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2904. ->where($data)
  2905. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2906. ->pluck('aLIas_pinyin')
  2907. ->implode('/');
  2908. $articles->pinyin = $pinyin ?? '';
  2909. return $articles;
  2910. }
  2911. }
  2912. // 封装处理由问题
  2913. function processJob($job, $data)
  2914. {
  2915. return $job->map(function ($job) use ($data) {
  2916. $category = $job->cat_arr_id ?? '';
  2917. $cityid = $job->city_arr_id ?? '';
  2918. $city = json_decode($cityid, true);
  2919. $pinyin = '';
  2920. $level = json_decode($category, true);
  2921. // 路由
  2922. if (!empty($level) && is_array($level)) {
  2923. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2924. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2925. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2926. ->get(['aLIas_pinyin'])
  2927. ->pluck('aLIas_pinyin')
  2928. ->implode('/');
  2929. if (empty($pinyin)) {
  2930. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2931. }
  2932. $job->pinyin = $pinyin;
  2933. }
  2934. // 取职位-城市 市??省
  2935. if (!empty($city) && is_array($city)) {
  2936. if (isset($city[1]) && !empty($city[1])) {
  2937. $city = District::where('id', $city[1])->first(['name']);
  2938. $job->city_name = $city->name ?? '';
  2939. } else if (isset($city[0]) && !empty($city[0])) {
  2940. $city = District::where('id', $city[0])->first(['name']);
  2941. $job->city_name = $city->name ?? '';
  2942. } else {
  2943. $job->city_name = '全国';
  2944. }
  2945. }
  2946. // 获取简历最后一级地区
  2947. if (isset($job->city_id) && !empty($job->city_id)) {
  2948. $city = District::where('id', $job->city_id)->first(['name']);
  2949. $job->hunt_cityname = $city->name ?? '';
  2950. }
  2951. // 组合详细地址
  2952. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2953. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2954. if (is_array($address_id) && !empty($address_id)) {
  2955. $address = District::whereIn('id', $address_id)
  2956. ->orderBy('level', 'asc')
  2957. ->get(['name'])
  2958. ->pluck('name')
  2959. ->implode('');
  2960. // $job->address_name = $address ?? '';
  2961. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2962. }
  2963. }
  2964. // 取行业
  2965. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2966. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2967. if (!empty($job->industry)) {
  2968. $query->where('hyid', $job->industry);
  2969. } else if (!empty($job->hy_id)) {
  2970. $query->where('hyid', $job->hy_id);
  2971. } else if (!empty($job->company_hy_id)) {
  2972. $query->where('hyid', $job->company_hy_id);
  2973. } else {
  2974. $query->where('hyid', $job->job_industry);
  2975. }
  2976. })->first(['hyname']);
  2977. $job->hy_name = $hy_name->hyname ?? '';
  2978. }
  2979. // 取职位类别
  2980. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2981. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2982. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2983. $job->zw_name = $zw_name->zwname ?? '';
  2984. }
  2985. // 取具体职位
  2986. 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))) {
  2987. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2988. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2989. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2990. }
  2991. // 取工作经验
  2992. if (isset($job->experience) && !empty($job->experience)) {
  2993. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2994. $job->experience_name = $experience->ename ?? '';
  2995. }
  2996. // 取学历
  2997. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2998. $education = $job->educational ?? $job->school_education;
  2999. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3000. $job->education_name = $education->ename ?? '';
  3001. }
  3002. // 语言
  3003. if (isset($job->language) && !empty($job->language)) {
  3004. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3005. $job->language_name = $language->ename ?? '';
  3006. }
  3007. // 薪资
  3008. if (isset($job->salary) && !empty($job->salary)) {
  3009. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3010. $job->salary_name = $salary->ename ?? '';
  3011. }
  3012. // 职位性质
  3013. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3014. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3015. $job->job_nature_name = $job_nature->ename ?? '';
  3016. }
  3017. // 公司规模
  3018. if (isset($job->company_size) && !empty($job->company_size)) {
  3019. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3020. $job->company_size_name = $company_size->ename ?? '';
  3021. }
  3022. // 公司性质
  3023. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3024. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3025. $job->company_nature_name = $company_nature->nature_name ?? '';
  3026. }
  3027. // $job->pinyin = $pinyin;
  3028. return $job;
  3029. });
  3030. }
  3031. /**
  3032. * 获取书籍模块
  3033. * @param array $data
  3034. * @return array
  3035. * */
  3036. public function getWebsiteBook(array $data): array
  3037. {
  3038. $input['id'] = $data['id'];
  3039. $input['website_id'] = $data['website_id'];
  3040. // 将 JSON 字符串转换为 PHP 数组
  3041. $data = json_decode($input['id'], true);
  3042. // 使用 array_map 处理每个元素
  3043. $result = array_map(function ($item) use ($input) {
  3044. // 检查parent元素是否存在且不是undefined
  3045. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3046. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3047. $website = [
  3048. 'website_id' => $input['website_id'],
  3049. ];
  3050. // 查询栏目名称
  3051. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3052. if (empty($category)) {
  3053. $parent_alias = '';
  3054. $parent_pinyin = null;
  3055. $imgBooks = [];
  3056. $textBooks = [];
  3057. } else {
  3058. $parent_alias = $category->alias ?? '';
  3059. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3060. // 查找子分类ID数组
  3061. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3062. array_push($childCategoryIds, $parentCatId);
  3063. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3064. if ($parentImgNum != 0) {
  3065. // 查询图片新闻
  3066. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3067. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3068. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3069. })
  3070. ->where('book.status', 2)
  3071. ->where('book.img_url', '!=', '')
  3072. ->where('book.website_id', $website['website_id'])
  3073. ->leftJoin('website_category', function ($join) use ($website) {
  3074. $join->on('book.cat_id', '=', 'website_category.category_id')
  3075. ->where('website_category.website_id', '=', $website['website_id']);
  3076. })
  3077. ->select(
  3078. 'book.id',
  3079. 'book.title',
  3080. 'book.img_url',
  3081. 'book.price',
  3082. 'book.market_price',
  3083. 'book.description',
  3084. 'book.cat_id',
  3085. 'book.description',
  3086. 'book.updated_at',
  3087. 'website_category.alias as category_name',
  3088. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3089. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3090. )
  3091. ->orderBy('updated_at', 'desc')
  3092. ->limit($parentImgNum)
  3093. ->get()->all();
  3094. // 查询文字新闻
  3095. }
  3096. if ($parentTextNum != 0) {
  3097. $textBooks = [];
  3098. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3099. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3100. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3101. })
  3102. ->where('book.status', 2)
  3103. ->where('book.website_id', $website['website_id'])
  3104. ->leftJoin('website_category', function ($join) use ($website) {
  3105. $join->on('book.cat_id', '=', 'website_category.category_id')
  3106. ->where('website_category.website_id', '=', $website['website_id']);
  3107. })
  3108. ->select(
  3109. 'book.id',
  3110. 'book.title',
  3111. 'book.img_url',
  3112. 'book.price',
  3113. 'book.market_price',
  3114. 'book.description',
  3115. 'book.cat_id',
  3116. 'book.description',
  3117. 'book.updated_at',
  3118. 'website_category.alias as category_name',
  3119. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3120. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3121. )
  3122. ->orderBy('updated_at', 'desc')
  3123. ->limit($parentTextNum)
  3124. ->get()->all();
  3125. }
  3126. }
  3127. }
  3128. $resultItem = [
  3129. 'alias' => $parent_alias ?? '',
  3130. 'category_id' => $parentCatId ?? 0,
  3131. 'pinyin' => $parent_pinyin ?? null,
  3132. 'imgnum' => $imgBooks ?? [],
  3133. 'textnum' => $textBooks ?? [],
  3134. ];
  3135. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3136. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3137. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3138. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3139. ->get()->all();
  3140. if (!empty($childCategory)) {
  3141. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3142. // 查询子栏目名称
  3143. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3144. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3145. ->first();
  3146. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3147. $childImgArticles = [];
  3148. $childTextArticles = [];
  3149. $resultItem['child'] = [];
  3150. } else {
  3151. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3152. // 查询子栏目图片新闻
  3153. $childImgArticles = Book::where('cat_id', $childCatId)
  3154. ->where('status', 2)
  3155. ->where('img_url', '!=', '')
  3156. ->where('book.website_id', $website['website_id'])
  3157. ->leftJoin('website_category', function ($join) use ($website) {
  3158. $join->on('book.cat_id', '=', 'website_category.category_id')
  3159. ->where('website_category.website_id', '=', $website['website_id']);
  3160. })
  3161. ->select(
  3162. 'book.id',
  3163. 'book.title',
  3164. 'book.img_url',
  3165. 'book.price',
  3166. 'book.market_price',
  3167. 'book.description',
  3168. 'book.cat_id',
  3169. 'book.description',
  3170. 'book.updated_at',
  3171. DB::raw("'$child_pinyin' as pinyin")
  3172. )
  3173. ->orderBy('updated_at', 'desc')
  3174. ->limit($childImgNum)
  3175. ->get()->all();
  3176. // 查询子栏目文字新闻
  3177. $childTextArticles = Book::where('cat_id', $childCatId)
  3178. ->where('status', 2)
  3179. ->where('book.website_id', $website['website_id'])
  3180. ->leftJoin('website_category', function ($join) use ($website) {
  3181. $join->on('book.cat_id', '=', 'website_category.category_id')
  3182. ->where('website_category.website_id', '=', $website['website_id']);
  3183. })
  3184. ->select(
  3185. 'book.id',
  3186. 'book.title',
  3187. 'book.img_url',
  3188. 'book.price',
  3189. 'book.market_price',
  3190. 'book.description',
  3191. 'book.cat_id',
  3192. 'book.description',
  3193. 'book.updated_at',
  3194. DB::raw("'$child_pinyin' as pinyin")
  3195. )
  3196. ->orderBy('updated_at', 'desc')
  3197. ->limit($childTextNum)
  3198. ->get()->all();
  3199. $resultItem['child'] = [
  3200. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3201. 'category_id' => $childCatId,
  3202. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3203. 'all_childcat' => $childCategory,
  3204. 'imgnum' => $childImgArticles,
  3205. 'textnum' => $childTextArticles,
  3206. ];
  3207. }
  3208. }
  3209. } else {
  3210. $resultItem['child'] = [];
  3211. }
  3212. return $resultItem;
  3213. }, $data);
  3214. return Result::success($result);
  3215. }
  3216. /**
  3217. * 获取书刊列表
  3218. * @param array $data
  3219. * @return array
  3220. * */
  3221. public function getWebsiteBookList(array $data): array
  3222. {
  3223. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3224. if (empty($web)) {
  3225. return Result::error("查询失败", 0);
  3226. }
  3227. $catid = $data['id'];
  3228. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3229. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3230. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3231. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3232. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3233. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3234. ->where('pid', $category['pid'])
  3235. ->select(
  3236. 'category_id',
  3237. 'alias',
  3238. 'aLIas_pinyin',
  3239. 'pid',
  3240. 'sort',
  3241. 'is_url',
  3242. 'web_url',
  3243. 'seo_title',
  3244. 'seo_keywords',
  3245. 'seo_description',
  3246. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3247. )
  3248. ->orderBy('sort')
  3249. ->get()->all();
  3250. if (empty($category)) {
  3251. return Result::error("查询失败", 0);
  3252. }
  3253. $query = Book::where('book.status', 2)
  3254. ->where('book.website_id', $data['website_id'])
  3255. ->where('book.cat_id', $catid)
  3256. ->select(
  3257. 'book.id',
  3258. 'book.title',
  3259. 'book.img_url',
  3260. 'book.description',
  3261. 'book.updated_at',
  3262. 'book.cat_id',
  3263. DB::raw("'$pinyin' as pinyin")
  3264. )
  3265. ->orderBy('book.updated_at', 'desc');
  3266. $count = $query->count();
  3267. $query = clone $query;
  3268. $Book = $query
  3269. ->limit($data['pageSize'])
  3270. ->offset(($data['page'] - 1) * $data['pageSize'])
  3271. ->get()->all();
  3272. $result = [
  3273. 'category' => $categorys,
  3274. 'books' => $Book,
  3275. 'count' => $count,
  3276. ];
  3277. // if(empty($result)){
  3278. // return Result::error("查询失败", 0);
  3279. // }
  3280. return Result::success($result);
  3281. }
  3282. /**
  3283. * 获取书刊详情
  3284. * @param array $data
  3285. * @return array
  3286. * */
  3287. public function getWebsiteBookInfo(array $data): array
  3288. {
  3289. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3290. if (empty($web)) {
  3291. return Result::error("查询失败", 0);
  3292. }
  3293. $book = Book::where('status', 2)
  3294. ->where('website_id', $data['website_id'])
  3295. ->where('id', $data['id'])
  3296. ->select(
  3297. 'book.*',
  3298. )
  3299. ->orderBy('updated_at', 'desc')
  3300. ->first();
  3301. if (empty($book)) {
  3302. return Result::error("查询失败", 0);
  3303. }
  3304. // 先查询当前分类的 pid
  3305. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3306. ->where('category_id', $book['cat_id'])
  3307. ->first(['pid', 'category_id']);
  3308. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3309. if (!empty($carpid)) {
  3310. if ($carpid->pid != 0) {
  3311. $pid = $carpid['pid'];
  3312. // $parent_pinyin = '';
  3313. } else {
  3314. $pid = $carpid['category_id'];
  3315. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3316. }
  3317. }
  3318. $categorys = $query->where('pid', $pid)
  3319. ->select(
  3320. 'category_id',
  3321. 'alias',
  3322. 'aLIas_pinyin',
  3323. 'pid',
  3324. 'sort',
  3325. 'is_url',
  3326. 'web_url',
  3327. 'category_arr_id as cat_arr_id',
  3328. )
  3329. ->orderBy('sort')
  3330. ->get();
  3331. $category = $this->processArticle($categorys, $data);
  3332. $result = [
  3333. 'category' => $category,
  3334. 'books' => $book,
  3335. ];
  3336. return Result::success($result);
  3337. }
  3338. /**
  3339. * 尝试
  3340. * @param array $data
  3341. * @return array
  3342. * */
  3343. public function test(array $data): array
  3344. {
  3345. $input['id'] = $data['id'];
  3346. $input['website_id'] = $data['website_id'];
  3347. // 将 JSON 字符串转换为 PHP 数组
  3348. $data = json_decode($input['id'], true);
  3349. $result = [];
  3350. $article = $data;
  3351. $result = array_map(function ($item) use ($input) {
  3352. $website = [
  3353. 'website_id' => $input['website_id'],
  3354. ];
  3355. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3356. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3357. $parent = [
  3358. 0 => $category['category_id'] ?? [],
  3359. 1 => $parentImgNum ?? [],
  3360. 2 => $parentTextNum ?? [],
  3361. ];
  3362. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3363. $child = [];
  3364. $resultItem = [
  3365. // 'alias' => $parent_alias ?? '',
  3366. 'category_id' => $parentCatId ?? 0,
  3367. 'pinyin' => $parentImgNum ?? null,
  3368. 'imgnum' => $parentTextNum ?? [],
  3369. // 'textnum' => $textArticles ?? [],
  3370. ];
  3371. return $parent;
  3372. }, $data);
  3373. return Result::success($result);
  3374. // });
  3375. }
  3376. /**
  3377. * 封装处理文章的路由问题
  3378. * */
  3379. function processArticle($article, $data)
  3380. {
  3381. return $article->map(function ($article) use ($data) {
  3382. $catid = $article->cat_arr_id ?? '';
  3383. $level = json_decode($catid, true);
  3384. $pinyin = '';
  3385. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3386. if (!empty($level) && is_array($level)) {
  3387. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3388. ->where('website_id', $data['website_id'])
  3389. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3390. ->get(['aLIas_pinyin'])
  3391. ->pluck('aLIas_pinyin')
  3392. ->implode('/');
  3393. } else {
  3394. $pinyin = '';
  3395. }
  3396. $article->pinyin = $pinyin;
  3397. return $article;
  3398. });
  3399. }
  3400. /**
  3401. * c端-获取招工招聘下拉选框
  3402. * @param array $data
  3403. * @return array
  3404. * */
  3405. public function getWebsiteJobSelect(array $data): array
  3406. {
  3407. $web = Website::where('id', $data['website_id'])->first();
  3408. if (empty($web)) {
  3409. return Result::error("该网站不存在", 0);
  3410. }
  3411. $hy = JobIndustry::get()->all();
  3412. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3413. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3414. $result = [
  3415. 'hy' => $hy,
  3416. 'zw' => $zw,
  3417. 'jtzw' => $jtzw,
  3418. ];
  3419. if (empty($result)) {
  3420. return Result::error("查询失败", 0);
  3421. }
  3422. return Result::success($result);
  3423. }
  3424. /**
  3425. * c端-获取招工招聘
  3426. * @param array $data
  3427. * @return array
  3428. * */
  3429. public function getWebsiteJob(array $data): array
  3430. {
  3431. $web = Website::where('id', $data['website_id'])->first();
  3432. if (empty($web)) {
  3433. return Result::error("该网站不存在", 0);
  3434. }
  3435. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3436. ->where('job_hunting.website_id', $data['website_id'])
  3437. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3438. $query->where(function ($q) use ($data) {
  3439. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3440. });
  3441. })
  3442. ->select(
  3443. 'job_hunting.id',
  3444. 'job_hunting.catid',
  3445. 'job_hunting.cat_arr_id',
  3446. 'job_hunting.job_name_get',
  3447. 'job_hunting.industry',
  3448. 'job_hunting.name',
  3449. 'job_hunting.sexy',
  3450. 'job_hunting.origin',
  3451. 'job_hunting.city_arr_id',
  3452. 'job_hunting.experience',
  3453. 'job_hunting.updated_at',
  3454. 'job_hunting.salary',
  3455. 'job_hunting.skillList',
  3456. 'job_hunting.slelf_evaluation',
  3457. )
  3458. ->orderBy('updated_at', 'desc')
  3459. ->limit($data['job1_num'])
  3460. ->get();
  3461. $web['website_id'] = $data['website_id'];
  3462. if (empty($job_hunting)) {
  3463. $job_huntings = "未查询到相关简历信息";
  3464. } else {
  3465. $job_huntings = $this->processJob($job_hunting, $web);
  3466. }
  3467. // 0:待审核 1:已通过 2:已拒绝
  3468. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3469. ->where('job_recruiting.website_id', $data['website_id'])
  3470. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3471. $query->where(function ($q) use ($data) {
  3472. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3473. });
  3474. })
  3475. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3476. ->select(
  3477. 'job_recruiting.id',
  3478. 'job_recruiting.catid',
  3479. 'job_recruiting.cat_arr_id',
  3480. 'job_recruiting.title',
  3481. 'job_recruiting.jtzw_id',
  3482. 'job_recruiting.hy_id',
  3483. 'job_recruiting.city_arr_id',
  3484. 'job_recruiting.due_data',
  3485. 'job_recruiting.updated_at',
  3486. 'job_recruiting.experience',
  3487. 'job_recruiting.educational',
  3488. 'job_recruiting.salary',
  3489. 'job_recruiting.zw_id',
  3490. 'job_company.business_name',
  3491. 'job_recruiting.keyword',
  3492. 'job_recruiting.description',
  3493. )
  3494. ->orderBy('updated_at', 'desc')
  3495. ->limit($data['job2_num'])
  3496. ->get();
  3497. if (empty($job_recruiting->toArray())) {
  3498. $job_recruitings = "未查询到相关职位信息";
  3499. } else {
  3500. $job_recruitings = $this->processJob($job_recruiting, $web);
  3501. }
  3502. $result = [
  3503. 'job_hunting' => $job_huntings,
  3504. 'job_recuiting' => $job_recruitings,
  3505. ];
  3506. return Result::success($result);
  3507. }
  3508. /**
  3509. * c端-获取招工招聘列表
  3510. * @param array $data
  3511. * @return array
  3512. * */
  3513. public function getWebsiteJobList(array $data): array
  3514. {
  3515. $recruit_where = [];
  3516. $hunt_where = [];
  3517. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3518. if (empty($web)) {
  3519. return Result::error("此网站不存在", 0);
  3520. }
  3521. $website_id['website_id'] = $data['website_id'];
  3522. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3523. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3524. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3525. }
  3526. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3527. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3528. }
  3529. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3530. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3531. }
  3532. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3533. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3534. }
  3535. $query = JobRecruiting::where('job_recruiting.status', 1)
  3536. ->where('job_recruiting.website_id', $data['website_id'])
  3537. ->where($recruit_where)
  3538. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3539. $query->where(function ($q) use ($data) {
  3540. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3541. });
  3542. })
  3543. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3544. $query->where(function ($q) use ($data) {
  3545. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3546. });
  3547. })
  3548. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3549. ->select(
  3550. 'job_recruiting.id',
  3551. 'job_recruiting.catid',
  3552. 'job_recruiting.hy_id',
  3553. 'job_recruiting.title',
  3554. 'job_recruiting.zw_id',
  3555. 'job_recruiting.educational',
  3556. 'job_recruiting.jtzw_id',
  3557. 'job_recruiting.city_arr_id',
  3558. 'job_recruiting.due_data',
  3559. 'job_recruiting.experience',
  3560. 'job_recruiting.cat_arr_id',
  3561. 'job_recruiting.updated_at',
  3562. 'job_company.business_name',
  3563. 'job_recruiting.keyword',
  3564. 'job_recruiting.description',
  3565. )
  3566. ->orderBy('job_recruiting.updated_at', 'desc');
  3567. $recruit_count = $query->count();
  3568. $query = clone $query;
  3569. $JobRecruiting = $query
  3570. ->offset(($data['page'] - 1) * $data['pageSize'])
  3571. ->limit($data['pageSize'])
  3572. ->get();
  3573. if (empty($JobRecruiting)) {
  3574. $JobRecruiting = "暂无相关职位信息";
  3575. } else {
  3576. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3577. }
  3578. }
  3579. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3580. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3581. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3582. }
  3583. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3584. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3585. }
  3586. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3587. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3588. }
  3589. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3590. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3591. }
  3592. $query = JobHunting::where('job_hunting.status', 2)
  3593. ->where('job_hunting.website_id', $data['website_id'])
  3594. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3595. ->where($hunt_where)
  3596. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3597. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3598. // })
  3599. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3600. $query->where(function ($q) use ($data) {
  3601. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3602. });
  3603. })
  3604. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3605. $query->where(function ($q) use ($data) {
  3606. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3607. });
  3608. })
  3609. ->select(
  3610. 'job_hunting.id',
  3611. 'job_hunting.catid',
  3612. 'job_hunting.sexy',
  3613. 'job_hunting.experience',
  3614. 'job_hunting.origin',
  3615. 'job_hunting.industry',
  3616. 'job_hunting.name',
  3617. 'job_hunting.job',
  3618. 'job_hunting.job_name_get',
  3619. 'job_hunting.city_arr_id',
  3620. 'job_hunting.cat_arr_id',
  3621. 'job_hunting.created_at',
  3622. 'job_hunting.updated_at',
  3623. 'job_position.zwname as job_name',
  3624. 'job_hunting.skillList',
  3625. 'job_hunting.slelf_evaluation',
  3626. )
  3627. ->orderBy('job_hunting.updated_at', 'desc');
  3628. $hunt_count = $query->count();
  3629. $query = clone $query;
  3630. $JobHunting = $query
  3631. ->offset(($data['page'] - 1) * $data['pageSize'])
  3632. ->limit($data['pageSize'])
  3633. ->get();
  3634. if (empty($JobHunting)) {
  3635. $JobRecruiting = "暂无相关简历信息";
  3636. } else {
  3637. $JobHunting = $this->processJob($JobHunting, $website_id);
  3638. }
  3639. }
  3640. $result = [
  3641. 'JobRecruiting' => $JobRecruiting ?? [],
  3642. 'recruit_count' => $recruit_count ?? 0,
  3643. 'JobHunting' => $JobHunting ?? [],
  3644. 'hunt_count' => $hunt_count ?? 0,
  3645. ];
  3646. return Result::success($result);
  3647. }
  3648. /**
  3649. * c端-获取招工招聘详情
  3650. * @param array $data
  3651. * @return array
  3652. * */
  3653. public function getWebsiteJobInfo(array $data): array
  3654. {
  3655. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3656. if (empty($web)) {
  3657. return Result::error("该网站不存在", 0);
  3658. }
  3659. $webid = [
  3660. 'website_id' => $data['website_id'],
  3661. ];
  3662. // 职位相关信息
  3663. if ($data['type'] == 1) {
  3664. $query = JobRecruiting::where('status', 1)
  3665. ->where('website_id', $data['website_id'])
  3666. ->select('*');
  3667. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3668. $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();
  3669. if (!empty($company)) {
  3670. $result['company'] = $this->processJob($company, $webid);
  3671. }
  3672. $other_job = JobRecruiting::where('status', 1)
  3673. ->where('website_id', $data['website_id'])
  3674. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3675. ->where('id', '!=', $data['id'])
  3676. ->where('user_id', '=', $job[0]['user_id'])
  3677. ->limit($data['pageSize'])
  3678. ->get();
  3679. if (!empty($other_job)) {
  3680. $result['other_job'] = $this->processJob($other_job, $webid);
  3681. }
  3682. } else {
  3683. // 简历相关信息
  3684. $job = JobHunting::where('job_hunting.status', 2)
  3685. ->where('job_hunting.website_id', $data['website_id'])
  3686. ->where('job_hunting.id', $data['id'])
  3687. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3688. ->select('job_hunting.*', 'user_name')
  3689. ->get();
  3690. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3691. if (!empty($resume->toArray())) {
  3692. $result['resume'] = 1;
  3693. } else {
  3694. $result['resume'] = 0;
  3695. }
  3696. }
  3697. if (empty($job->toArray())) {
  3698. return Result::error("id参数错误", 0);
  3699. }
  3700. if (!empty($job[0]['job_experience'])) {
  3701. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3702. if (!empty($job_experience)) {
  3703. // $hy = [];
  3704. foreach ($job_experience as $key => $value) {
  3705. // $id = $value['id'];
  3706. $hy[$key] = $value['job_industry'];
  3707. $zw_id[$key] = $value['job_typename'];
  3708. $jtzw_id[$key] = $value['job_name'];
  3709. }
  3710. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3711. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3712. // 先将关联表转换为索引数组,提高查找效率
  3713. $hyLookup = [];
  3714. foreach ($hy_table as $item) {
  3715. $hyLookup[$item['hyid']] = $item['hyname'];
  3716. }
  3717. $zwLookup = [];
  3718. foreach ($zw_table as $item) {
  3719. $zwLookup[$item['zwid']] = $item['zwname'];
  3720. }
  3721. foreach ($job_experience as $key => &$value) {
  3722. // 处理行业名称
  3723. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3724. $value['hy_name'] = $hyLookup[$hy[$key]];
  3725. }
  3726. // 处理职位名称
  3727. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3728. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3729. }
  3730. // 处理具体职位名称
  3731. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3732. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3733. }
  3734. }
  3735. // 释放引用,防止意外修改后续代码
  3736. unset($value);
  3737. }
  3738. $result['job_experience'] = $job_experience ?? [];
  3739. }
  3740. if (!empty($job[0]['education_experience'])) {
  3741. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3742. if (!empty($education_experience)) {
  3743. foreach ($education_experience as $key => $value) {
  3744. // $id = $value['id'];
  3745. $education[$key] = $value['school_education'];
  3746. }
  3747. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3748. // // 先将关联表转换为索引数组,提高查找效率
  3749. $educationLookup = [];
  3750. foreach ($education_table as $item) {
  3751. $educationLookup[$item['evalue']] = $item['ename'];
  3752. }
  3753. foreach ($education_experience as $key => &$value) {
  3754. // 处理学历名称
  3755. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3756. $value['education_name'] = $educationLookup[$education[$key]];
  3757. }
  3758. }
  3759. }
  3760. $result['education_experience'] = $job_experience ?? [];
  3761. }
  3762. $result['job'] = $this->processJob($job, $webid);
  3763. // // 返现对应的栏目
  3764. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3765. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3766. ->whereIn('category_id', $catid)
  3767. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3768. ->orderBy('pid')->get()->all();
  3769. if (!empty($category)) {
  3770. $result['category'] = $category;
  3771. }
  3772. $result['job'] = $job;
  3773. $result['job_experience'] = $job_experience ?? [];
  3774. $result['education_experience'] = $education_experience ?? [];
  3775. if (empty($result)) {
  3776. return Result::error("参数错误", 0);
  3777. }
  3778. return Result::success($result);
  3779. }
  3780. /**
  3781. * c端-申请职位
  3782. * @param array $data
  3783. * @return array
  3784. * */
  3785. public function getWebsiteJobApply(array $data): array
  3786. {
  3787. // 首先验证网站是否存在
  3788. // return Result::success($data);
  3789. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3790. if (empty($web)) {
  3791. return Result::error("该网站不存在", 0);
  3792. }
  3793. // 验证用户是否存在且为个人会员/管理员
  3794. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3795. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3796. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3797. return Result::error("用户不存在", 0);
  3798. }
  3799. // 去除重复元素和空元素,并保持原始顺序
  3800. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3801. return !empty($value);
  3802. }));
  3803. // 验证职位是否存在 1:审核通过
  3804. $recruiting = JobRecruiting::where('status', 1)
  3805. ->where('website_id', $data['website_id'])
  3806. ->whereIn('id', $data['recruit_id'])
  3807. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3808. if (empty($recruiting)) {
  3809. return Result::error("该职位不存在", 0);
  3810. }
  3811. // 简历是否存在
  3812. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3813. if (empty($hunt_id)) {
  3814. return Result::error("该简历不存在", 0);
  3815. }
  3816. $data['hunt_id'] = $hunt_id['hunt_id'];
  3817. // // 验证是否已投递过该职位
  3818. $apply = JobApply::where('user_id', $data['user_id'])
  3819. ->where('hunt_id', $data['hunt_id'])
  3820. ->where('website_id', $data['website_id'])
  3821. ->whereIn('recruit_id', $data['recruit_id'])
  3822. ->get(['recruit_id']);
  3823. if (!empty($apply->toArray())) {
  3824. return Result::error("您已投递过该职位!");
  3825. }
  3826. $insertData = array_map(function ($recruiting) use ($data) {
  3827. return [
  3828. 'user_id' => $data['user_id'],
  3829. 'hunt_id' => $data['hunt_id'],
  3830. 'website_id' => $data['website_id'],
  3831. 'recruit_id' => $recruiting['recruit_id'],
  3832. 'receiver_id' => $recruiting['receiver_id'],
  3833. 'status' => 1,
  3834. ];
  3835. }, $recruiting);
  3836. // 批量插入数据
  3837. $result = JobApply::insert($insertData);
  3838. if (empty($result)) {
  3839. return Result::error("投递失败", 0);
  3840. }
  3841. return Result::success($result);
  3842. }
  3843. /**
  3844. * 招工招聘-沟通简历
  3845. * @param array $data
  3846. * @return array
  3847. * */
  3848. public function getWebsiteJobResume(array $data): array
  3849. {
  3850. // 首先验证网站是否存在
  3851. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3852. if (empty($web)) {
  3853. return Result::error("该网站不存在", 0);
  3854. }
  3855. // return Result::success($data);
  3856. // 验证用户是否存在且为企业会员/管理员
  3857. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3858. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3859. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3860. return Result::error("用户不存在", 0);
  3861. }
  3862. // 去除重复元素和空元素,并保持原始顺序
  3863. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3864. return !empty($value);
  3865. }));
  3866. // 验证简历是否存在
  3867. $hunting = JobHunting::where('status', 2)
  3868. ->where('website_id', $data['website_id'])
  3869. ->whereIn('id', $data['hunt_id'])
  3870. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3871. if (empty($hunting)) {
  3872. return Result::error("该简历不存在", 0);
  3873. }
  3874. // 验证是否已沟通过该简历
  3875. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3876. ->where('recruit_id', $data['recruit_id'])
  3877. ->where('website_id', $data['website_id'])
  3878. ->whereIn('hunt_id', $data['hunt_id'])
  3879. ->get(['hunt_id']);
  3880. if (!empty($remuse->toArray())) {
  3881. return Result::error("您已沟通过该简历!");
  3882. }
  3883. // 准备要插入的数据数组
  3884. $insertData = array_map(function ($hunting) use ($data) {
  3885. return [
  3886. 'user_id' => $data['user_id'],
  3887. 'recruit_id' => $data['recruit_id'],
  3888. 'website_id' => $data['website_id'],
  3889. 'hunt_id' => $hunting['hunt_id'],
  3890. 'receiver_id' => $hunting['receiver_id'],
  3891. 'status' => 1,
  3892. ];
  3893. }, $hunting);
  3894. // 批量插入数据
  3895. $result = JobRemuse::insert($insertData);
  3896. if (empty($result)) {
  3897. return Result::error("沟通失败", 0);
  3898. }
  3899. return Result::success($result);
  3900. }
  3901. /**
  3902. * 招工招聘 -我的职位(企业会员)
  3903. * @param array $data
  3904. * @return array
  3905. */
  3906. public function getWebsiteJobRecruiting(array $data): array
  3907. {
  3908. $web = Website::where('id', $data['website_id'])->first('id');
  3909. if (empty($web)) {
  3910. return Result::error("该网站不存在", 0);
  3911. }
  3912. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3913. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3914. return Result::error("用户暂无权限!", 0);
  3915. }
  3916. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3917. $result = JobRecruiting::where('website_id', $data['website_id'])
  3918. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3919. $query->where('user_id', $user['id']);
  3920. })
  3921. ->where('status', 1)
  3922. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3923. ->orderBy('updated_at', 'desc')
  3924. ->limit($data['pageSize'])
  3925. ->get();
  3926. if (empty($result)) {
  3927. return Result::error("暂无相关职位信息", 0);
  3928. }
  3929. return Result::success($result);
  3930. }
  3931. /**
  3932. * c端 - 验证路由
  3933. * @param array $data
  3934. * @return array
  3935. */
  3936. /**
  3937. * c端 - 验证路由
  3938. * @param array $data
  3939. * @return array
  3940. */
  3941. public function checkWebsiteRoute(array $data): array
  3942. {
  3943. // 测试001111111222
  3944. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3945. if (empty($web)) {
  3946. return Result::error("该网站不存在", 0);
  3947. } elseif ($web['status'] != 1) {
  3948. return Result::error("网站已经关闭", 0);
  3949. }
  3950. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3951. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3952. // 验证路由是否存在
  3953. if (empty($whiteRouterInfo)) {
  3954. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3955. }
  3956. if (!empty($whiteRouterInfo)) {
  3957. return Result::success($whiteRouterInfo->toArray());
  3958. }
  3959. }
  3960. // 验证栏目路由
  3961. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3962. ->where('path', $data['all_route'])
  3963. ->get()->all();
  3964. if (count($last_category) == 0) {
  3965. return Result::error("该栏目不存在", 0);
  3966. }
  3967. if (count($last_category) > 1) {
  3968. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3969. }
  3970. if (count($last_category) == 1) {
  3971. $last_category = $last_category[0];
  3972. }
  3973. // return Result::success($last_category);
  3974. if (isset($data['id']) && !empty($data['id'])) {
  3975. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3976. switch ($last_category['type']) {
  3977. case 1:
  3978. // 文章
  3979. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3980. $article = Article::where('status', 1)
  3981. ->where('id', $data['id'])
  3982. ->where(function ($query) use ($data) {
  3983. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3984. ->orWhereNull("ignore_ids");
  3985. })
  3986. ->first(['catid']);
  3987. if (empty($article)) {
  3988. return Result::error("该文章不存在", 0);
  3989. }
  3990. // return Result::success($article);
  3991. break;
  3992. case 2:
  3993. // 商品
  3994. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3995. $article = Good::where('website_id', $data['website_id'])
  3996. ->where('status', 2)
  3997. ->where('id', $data['id'])
  3998. ->first(['cat_arr_id']);
  3999. if (empty($article)) {
  4000. return Result::error("该商品不存在", 0);
  4001. }
  4002. break;
  4003. case 3:
  4004. // 书刊信息
  4005. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4006. $article = Book::where('website_id', $data['website_id'])
  4007. ->where('status', 2)
  4008. ->where('id', $data['id'])
  4009. ->first(['id', 'cat_arr_id']);
  4010. if (empty($article)) {
  4011. return Result::error("该书刊不存在", 0);
  4012. }
  4013. break;
  4014. case 4:
  4015. // 招聘
  4016. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4017. $article = JobRecruiting::where('website_id', $data['website_id'])
  4018. ->where('status', 1)
  4019. ->where('id', $data['id'])
  4020. ->first(['cat_arr_id']);
  4021. if (empty($article)) {
  4022. return Result::error("该招聘不存在", 0);
  4023. }
  4024. break;
  4025. case 5:
  4026. // 求职
  4027. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4028. $article = JobHunting::where('website_id', $data['website_id'])
  4029. ->where('status', 2)
  4030. ->where('id', $data['id'])
  4031. ->first(['cat_arr_id']);
  4032. if (empty($article)) {
  4033. return Result::error("该求职不存在", 0);
  4034. }
  4035. break;
  4036. case 6:
  4037. // 企业
  4038. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4039. $article = Company::
  4040. // where('website_id', $data['website_id'])
  4041. // ->
  4042. where('status', 1)
  4043. ->where('id', $data['id'])
  4044. ->first(['cat_arr_id']);
  4045. if (empty($article)) {
  4046. return Result::error("该企业不存在", 0);
  4047. }
  4048. break;
  4049. case 7:
  4050. // 项目
  4051. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4052. $article = Project::where('website_id', $data['website_id'])
  4053. ->where('status', 1)
  4054. ->where('id', $data['id'])
  4055. ->first(['cat_arr_id']);
  4056. if (empty($article)) {
  4057. return Result::error("该项目不存在", 0);
  4058. }
  4059. break;
  4060. default:
  4061. return Result::error("该数据不存在", 0);
  4062. break;
  4063. }
  4064. // return Result::success($article);
  4065. // $catid =0 ;
  4066. if (!isset($article['cat_arr_id'])) {
  4067. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4068. } else {
  4069. $catidArray = json_decode($article['cat_arr_id'], true);
  4070. $catid = !empty($catidArray) ? end($catidArray) : null;
  4071. }
  4072. // return Result::success($catid);
  4073. // // return Result::success($article['cat_arr_id']);
  4074. if (empty($catid)) {
  4075. return Result::error("该栏目路径不存在", 0);
  4076. }
  4077. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4078. ->where('category_id', $catid)
  4079. ->first('path');
  4080. }
  4081. // else{
  4082. // // if ($last_category['pid'] != 0) {
  4083. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4084. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4085. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4086. // ->where('category_id',$catid)
  4087. // ->where('path',$data['all_route'])
  4088. // ->first('path');
  4089. // // } else {
  4090. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4091. // // }
  4092. // }
  4093. // return Result::success($path);
  4094. if (!empty($path) && $path['path'] != $data['all_route']) {
  4095. return Result::error('非法路径!');
  4096. } else {
  4097. return Result::success($last_category['path']);
  4098. }
  4099. }
  4100. /**
  4101. * 招工招聘 - 获取推荐职位
  4102. * @param array $data
  4103. * @return array
  4104. */
  4105. public function getWebsiteLevelJob(array $data): array
  4106. {
  4107. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4108. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4109. ->where('job_recruiting.status', 1)
  4110. ->where('job_level', $data['job_level'])
  4111. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4112. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4113. ->orderBy('job_recruiting.updated_at', 'desc')
  4114. ->limit($data['pageSize'])
  4115. ->get();
  4116. $web = ['website_id' => $data['website_id']];
  4117. if (!empty($job)) {
  4118. $result = $this->processJob($job, $web);
  4119. }
  4120. if (empty($result)) {
  4121. return Result::error("暂无相关职位信息", 0);
  4122. }
  4123. return Result::success($result);
  4124. }
  4125. /**
  4126. * 验证导航名称是否重复
  4127. * @return void
  4128. */
  4129. //20250226 产品列表
  4130. public function getGoodList(array $data): array
  4131. {
  4132. var_dump($data, '---------1-2--');
  4133. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4134. unset($data['user_type_id']);
  4135. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4136. $where = [];
  4137. if ($type_id != '10000') {
  4138. $where = [
  4139. 'good.user_id' => $user_id,
  4140. ];
  4141. }
  4142. //类型
  4143. if (isset($data['type_id']) && $data['type_id']) {
  4144. $where['good.type_id'] = $data['type_id'];
  4145. }
  4146. //名称
  4147. if (isset($data['name']) && $data['name']) {
  4148. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4149. }
  4150. //status
  4151. if (isset($data['status']) && $data['status'] != '') {
  4152. $where['good.status'] = $data['status'];
  4153. }
  4154. //status1
  4155. // if (isset($data['status1']) && $data['status1'] == 1) {
  4156. // $status1 = 1;
  4157. // }
  4158. $where1 = [];
  4159. //website_id
  4160. // if (isset($data['website_id']) && $data['website_id']) {
  4161. // $where1 = [
  4162. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4163. // ];
  4164. // }
  4165. // website_name
  4166. if (isset($data['website_name']) && $data['website_name']) {
  4167. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4168. }
  4169. // catid
  4170. if (isset($data['category_name']) && $data['category_name']) {
  4171. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4172. }
  4173. // $result = Good::where($where)
  4174. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4175. var_dump($where, '---------1---');
  4176. $result = Good::where($where)
  4177. ->when(!empty($where1), function ($query) use ($where1) {
  4178. return $query->where($where1);
  4179. })
  4180. //status 1待审核2已审核3已拒绝
  4181. ->when(isset($data['status1']), function ($query) {
  4182. return $query->whereIn('good.status', [1, 3]);
  4183. })
  4184. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4185. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4186. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4187. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4188. ->orderBy("updated_at", "desc")
  4189. ->limit($data['page_size'])
  4190. ->offset(($data['page'] - 1) * $data['page_size'])
  4191. ->get();
  4192. $count = Good::where($where)
  4193. ->when(!empty($where1), function ($query) use ($where1) {
  4194. return $query->where($where1);
  4195. })
  4196. //status 1待审核2已审核3已拒绝
  4197. ->when(isset($data['status1']), function ($query) {
  4198. return $query->whereIn('good.status', [1, 3]);
  4199. })
  4200. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4201. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4202. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4203. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4204. ->orderBy("updated_at", "desc")->count();
  4205. $data = [
  4206. 'rows' => $result->toArray(),
  4207. 'count' => $count,
  4208. ];
  4209. if (empty($result)) {
  4210. return Result::error("此栏目暂无相关产品", 0);
  4211. }
  4212. return Result::success($data);
  4213. }
  4214. public function getGoodInfo(array $data): array
  4215. {
  4216. $result = Good::where('id', $data['id'])->first();
  4217. if (empty($result)) {
  4218. return Result::error("此产品不存在", 0);
  4219. }
  4220. return Result::success($result);
  4221. }
  4222. public function addGood(array $data): array
  4223. {
  4224. // unset($data['city_arr_id']);
  4225. // unset($data['cat_arr_id']);
  4226. $data['city_id'] = end($data['city_arr_id']);
  4227. $data['catid'] = end($data['cat_arr_id']);
  4228. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4229. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4230. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4231. unset($data['imgUrl']); //大小写
  4232. if (isset($data['price']) && $data['price'] == '') {
  4233. $data['price'] = 0;
  4234. }
  4235. if ($data['imgurl'] == '') {
  4236. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4237. preg_match_all($reg, $data['detail'], $matches);
  4238. if (isset($matches[1][0])) {
  4239. //截取varchar240
  4240. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4241. }
  4242. }
  4243. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4244. //提取标题+内容中的关键词
  4245. $data['keyword'] = $data['name'];
  4246. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4247. Jieba::init(); // 初始化 jieba-php
  4248. Finalseg::init();
  4249. $segList = Jieba::cut($data['keyword']);
  4250. $segList1 = array_slice($segList, 0, 8);
  4251. $data['keyword'] = implode(',', $segList1);
  4252. }
  4253. if ($data['description'] == '') {
  4254. //提取内容中的描述
  4255. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4256. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4257. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4258. }
  4259. if ($data['status'] == 1) {
  4260. $this->sendMessage([
  4261. 'talk_type' => 200,
  4262. 'title' => $data['name'],
  4263. 'content' => '提交了审核',
  4264. 'messageType' => 3,
  4265. ]);
  4266. }
  4267. $result = Good::insert($data);
  4268. if (empty($result)) {
  4269. return Result::error("添加失败", 0);
  4270. }
  4271. return Result::success($result);
  4272. }
  4273. public function updateGood(array $data): array
  4274. {
  4275. $data['city_id'] = end($data['city_arr_id']);
  4276. $data['catid'] = end($data['cat_arr_id']);
  4277. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4278. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4279. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4280. //设置东八区
  4281. date_default_timezone_set('Asia/Shanghai');
  4282. $data['updated_at'] = date('Y-m-d H:i:s');
  4283. if (isset($data['price']) && $data['price'] == '') {
  4284. $data['price'] = 0;
  4285. }
  4286. if ($data['imgurl'] == '') {
  4287. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4288. preg_match_all($reg, $data['detail'], $matches);
  4289. if (isset($matches[1][0])) {
  4290. //截取varchar240
  4291. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4292. }
  4293. }
  4294. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4295. //提取标题+内容中的关键词
  4296. $data['keyword'] = $data['name'];
  4297. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4298. Jieba::init(); // 初始化 jieba-php
  4299. Finalseg::init();
  4300. $segList = Jieba::cut($data['keyword']);
  4301. $segList1 = array_slice($segList, 0, 8);
  4302. $data['keyword'] = implode(',', $segList1);
  4303. }
  4304. if ($data['description'] == '') {
  4305. //提取内容中的描述
  4306. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4307. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4308. }
  4309. if ($data['status'] == 1) {
  4310. $this->sendMessage([
  4311. 'talk_type' => 200,
  4312. 'title' => $data['name'],
  4313. 'content' => '提交了审核',
  4314. 'messageType' => 3,
  4315. ]);
  4316. }
  4317. $result = Good::where('id', $data['id'])->update($data);
  4318. if (empty($result)) {
  4319. return Result::error("更新失败", 0);
  4320. }
  4321. return Result::success($result);
  4322. }
  4323. public function delGood(array $data): array
  4324. {
  4325. $result = Good::where('id', $data['id'])->delete();
  4326. if (empty($result)) {
  4327. return Result::error("删除失败", 0);
  4328. }
  4329. return Result::success($result);
  4330. }
  4331. //20250226 产品列表
  4332. //20250306 求职信息
  4333. public function getJobHuntingList(array $data): array
  4334. {
  4335. $where = [];
  4336. if (isset($data['username']) && !empty($data['username'])) {
  4337. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4338. }
  4339. //status 1待审核2已审核3已拒绝
  4340. if (isset($data['status']) && $data['status'] != '') {
  4341. $where = [
  4342. 'job_hunting.status' => $data['status'],
  4343. ];
  4344. }
  4345. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4346. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4347. unset($data['type_id']);
  4348. if ($type_id != '10000') {
  4349. $where[] = ['job_hunting.user_id', '=', $user_id];
  4350. }
  4351. $result = JobHunting::where($where)
  4352. ->when(!empty($data['status1']), function ($query) use ($data) {
  4353. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4354. })
  4355. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4356. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4357. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4358. ->orderBy("updated_at", "desc")
  4359. ->limit($data['page_size'])
  4360. ->offset(($data['page'] - 1) * $data['page_size'])
  4361. ->get();
  4362. if (empty($result)) {
  4363. return Result::error("查询失败", 0);
  4364. }
  4365. $count = JobHunting::where($where)
  4366. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4367. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4368. ->count();
  4369. $data = [
  4370. 'rows' => $result->toArray(),
  4371. 'count' => $count,
  4372. ];
  4373. return Result::success($data);
  4374. }
  4375. public function getJobHuntingApply(array $data): array
  4376. {
  4377. var_dump($data, '-----------------test--------1-');
  4378. $where = [];
  4379. if (isset($data['username']) && !empty($data['username'])) {
  4380. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4381. }
  4382. if (isset($data['salary']) && !empty($data['salary'])) {
  4383. $where[] = [
  4384. 'job_hunting.salary',
  4385. '=',
  4386. $data['salary'],
  4387. ];
  4388. }
  4389. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4390. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4391. unset($data['type_id']);
  4392. if ($type_id != '10000') {
  4393. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4394. }
  4395. var_dump($where, '-----------------test---------');
  4396. $result = jobApply::where($where)
  4397. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4398. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4399. // })
  4400. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4401. ->where('job_enum.egroup', '=', 'income')
  4402. ->where('job_hunting.status', 2) //已审核
  4403. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4404. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4405. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4406. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4407. //职位----是申请职位
  4408. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4409. ->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')
  4410. ->orderBy("job_hunting.updated_at", "desc")
  4411. ->limit($data['page_size'])
  4412. ->offset(($data['page'] - 1) * $data['page_size'])
  4413. ->get();
  4414. if (empty($result)) {
  4415. return Result::error("查询失败", 0);
  4416. }
  4417. $count = jobApply::where($where)
  4418. ->where('job_enum.egroup', '=', 'income')
  4419. ->where('job_hunting.status', 2) //已审核
  4420. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4421. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4422. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4423. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4424. //职位----是申请职位
  4425. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4426. ->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')
  4427. ->count();
  4428. $data = [
  4429. 'rows' => $result->toArray(),
  4430. 'count' => $count,
  4431. ];
  4432. return Result::success($data);
  4433. }
  4434. public function addJobHunting(array $data): array
  4435. {
  4436. date_default_timezone_set('Asia/Shanghai');
  4437. unset($data['company_name']);
  4438. unset($data['job_industry']);
  4439. unset($data['job_name']);
  4440. unset($data['department']);
  4441. unset($data['job_timeList']);
  4442. unset($data['job_content']);
  4443. unset($data['job_typename']); //不知道这是啥,
  4444. $data['created_at'] = date('Y-m-d H:i:s');
  4445. $data['updated_at'] = date('Y-m-d H:i:s');
  4446. //根据用户 user_id 只能添加一次
  4447. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4448. if (!empty($result)) {
  4449. return Result::error("您已添加过求职信息", 0);
  4450. }
  4451. var_dump($result, '-----------------test---------');
  4452. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4453. if (is_string($data['city_arr_id'])) {
  4454. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4455. $cityArr = json_decode($data['city_arr_id'], true);
  4456. // 确保 $cityArr 是数组
  4457. if (is_array($cityArr)) {
  4458. $data['city_id'] = end($cityArr);
  4459. }
  4460. } else {
  4461. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4462. if (is_array($data['city_arr_id'])) {
  4463. $data['city_id'] = end($data['city_arr_id']);
  4464. }
  4465. }
  4466. }
  4467. // 处理求职所绑定栏目
  4468. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4469. if (is_string($data['cat_arr_id'])) {
  4470. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4471. // 先清理可能存在的无效 JSON 字符
  4472. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4473. $catArr = json_decode($cleanedCatArrStr, true);
  4474. // 检查 JSON 解码是否成功且结果是数组
  4475. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4476. $data['catid'] = end($catArr);
  4477. }
  4478. } else {
  4479. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4480. if (is_array($data['cat_arr_id'])) {
  4481. $data['catid'] = end($data['cat_arr_id']);
  4482. }
  4483. }
  4484. }
  4485. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4486. $this->sendMessage([
  4487. 'talk_type' => 600,
  4488. 'title' => $data['name'],
  4489. 'content' => '提交了审核',
  4490. 'messageType' => 11,
  4491. ]);
  4492. }
  4493. $result = JobHunting::create($data);
  4494. if (empty($result)) {
  4495. return Result::error("添加失败", 0);
  4496. }
  4497. return Result::success($result);
  4498. }
  4499. public function delJobHunting(array $data): array
  4500. {
  4501. $result = JobHunting::where('id', $data['id'])->delete();
  4502. if (empty($result)) {
  4503. return Result::error("删除失败", 0);
  4504. }
  4505. return Result::success($result);
  4506. }
  4507. public function updateJobHunting(array $data): array
  4508. {
  4509. //设置东八区
  4510. date_default_timezone_set('Asia/Shanghai');
  4511. unset($data['company_name']);
  4512. unset($data['job_industry']);
  4513. unset($data['job_name']);
  4514. unset($data['department']);
  4515. unset($data['job_timeList']);
  4516. unset($data['job_content']);
  4517. unset($data['job_typename']); //不知道这是啥,
  4518. $data['created_at'] = date('Y-m-d H:i:s');
  4519. $data['updated_at'] = date('Y-m-d H:i:s');
  4520. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4521. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4522. $cityArr = json_decode($data['city_arr_id'], true);
  4523. $data['city_id'] = end($cityArr);
  4524. } else {
  4525. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4526. $data['city_id'] = end($data['city_arr_id']);
  4527. }
  4528. // 处理求职所绑定栏目
  4529. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4530. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4531. $catArr = json_decode($data['cat_arr_id'], true);
  4532. $data['catid'] = end($catArr);
  4533. } else {
  4534. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4535. $data['catid'] = end($data['cat_arr_id']);
  4536. }
  4537. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4538. $this->sendMessage([
  4539. 'talk_type' => 600,
  4540. 'title' => $data['name'],
  4541. 'content' => '提交了审核',
  4542. 'messageType' => 11,
  4543. ]);
  4544. }
  4545. $result = JobHunting::where('id', $data['id'])->update($data);
  4546. if (empty($result)) {
  4547. return Result::error("更新失败", 0);
  4548. }
  4549. return Result::success($result);
  4550. }
  4551. public function getJobHuntingInfo(array $data): array
  4552. {
  4553. $result = JobHunting::where('id', $data['id'])->first();
  4554. if (empty($result)) {
  4555. return Result::error("查询失败", 0);
  4556. }
  4557. return Result::success($result);
  4558. }
  4559. public function getJobHuntingData(array $data): array
  4560. {
  4561. $jobEnum = JobEnum::get();
  4562. $jobIndustry = JobIndustry::get();
  4563. $jobNature = JobNature::get();
  4564. $jobPosition = JobPosition::get();
  4565. $data = [
  4566. 'jobEnum' => $jobEnum,
  4567. 'jobIndustry' => $jobIndustry,
  4568. 'jobNature' => $jobNature,
  4569. 'jobPosition' => $jobPosition,
  4570. ];
  4571. return Result::success($data);
  4572. }
  4573. public function delJobHuntingInfo(array $data): array
  4574. {
  4575. $result = JobHunting::where('id', $data['id'])->delete();
  4576. return Result::success();
  4577. }
  4578. //20250324 通知,公告,消息
  4579. public function delNotice(array $data): array
  4580. {
  4581. $result = Notice::where('id', $data['id'])->delete();
  4582. if ($result) {
  4583. return Result::success();
  4584. } else {
  4585. return Result::error("删除失败", 0);
  4586. }
  4587. }
  4588. public function getNoticeInfo(array $data): array
  4589. {
  4590. $result = Notice::where('id', $data['id'])->first();
  4591. // var_dump($result['re_user_ids'], '--------------------');
  4592. if (empty($result)) {
  4593. return Result::error("查询失败", 0);
  4594. }
  4595. return Result::success($result);
  4596. }
  4597. public function readNotice(array $data): array
  4598. {
  4599. $result = Notice::where('id', $data['id'])->first();
  4600. // var_dump($result['re_user_ids'], '--------------------');
  4601. if (empty($result)) {
  4602. return Result::error("查询失败", 0);
  4603. }
  4604. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4605. $re_user_ids = json_decode($result['re_user_ids'], true);
  4606. var_dump($re_user_ids, '--------------1---test---------');
  4607. var_dump($data, '--------------1---test---------');
  4608. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4609. //如果已经存在,就不再添加
  4610. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4611. $read_id = json_decode($result['read_id'], true);
  4612. if (!is_array($read_id)) {
  4613. $read_id = [];
  4614. }
  4615. if (!in_array($data['user_id'], $read_id)) {
  4616. $read_id[] = $data['user_id'];
  4617. $result['read_id'] = json_encode($read_id);
  4618. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4619. }
  4620. } else {
  4621. //如果不存在,就添加
  4622. $result['read_id'] = json_encode([$data['user_id']]);
  4623. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4624. }
  4625. }
  4626. return Result::success($result);
  4627. }
  4628. public function addNotice(array $data): array
  4629. {
  4630. date_default_timezone_set('Asia/Shanghai');
  4631. $data['created_at'] = date('Y-m-d H:i:s');
  4632. $data['updated_at'] = date('Y-m-d H:i:s');
  4633. // $data['level'] = "1,2,3,4,5";
  4634. $level = json_decode($data['level'], true);
  4635. $user_id = UserInfo::
  4636. //city_id不是null
  4637. whereNotNull('city_id')
  4638. ->whereNotNull('department_id')
  4639. ->where(function ($query) use ($data) {
  4640. $query->where(function ($subQuery) use ($data) {
  4641. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4642. });
  4643. })
  4644. ->where(function ($query) use ($data) {
  4645. $query->where(function ($subQuery) use ($data) {
  4646. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4647. });
  4648. })
  4649. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4650. $query->whereIn('level', $level);
  4651. })
  4652. ->pluck('user_id')->toArray();
  4653. $user_id = array_unique($user_id);
  4654. $chat_ids = $user_id;
  4655. $user_id = json_encode($user_id);
  4656. $data['re_user_ids'] = $user_id;
  4657. $this->sendMessage([
  4658. 'talk_type' => 700,
  4659. 'title' => $data['title'],
  4660. 'content' => '提交了审核',
  4661. 'messageType' => 5,
  4662. ]);
  4663. $result = Notice::insertGetId($data);
  4664. if (empty($result)) {
  4665. return Result::error("添加失败", 0);
  4666. }
  4667. return Result::success($result);
  4668. }
  4669. public function updateNotice(array $data): array
  4670. {
  4671. date_default_timezone_set('Asia/Shanghai');
  4672. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4673. $user_id = UserInfo::
  4674. //city_id不是null
  4675. whereNotNull('city_id')
  4676. ->whereNotNull('department_id')
  4677. ->where(function ($query) use ($data) {
  4678. $query->where(function ($subQuery) use ($data) {
  4679. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4680. });
  4681. })
  4682. ->where(function ($query) use ($data) {
  4683. $query->where(function ($subQuery) use ($data) {
  4684. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4685. });
  4686. })
  4687. ->pluck('user_id')->toArray();
  4688. $user_id = array_unique($user_id);
  4689. $user_id = json_encode($user_id);
  4690. $data['re_user_ids'] = $user_id;
  4691. $data['updated_at'] = date('Y-m-d H:i:s');
  4692. $this->sendMessage([
  4693. 'talk_type' => 700,
  4694. 'title' => $data['title'],
  4695. 'content' => '提交了审核',
  4696. 'messageType' => 5,
  4697. ]);
  4698. $result = Notice::where('id', $data['id'])->update($data);
  4699. return Result::success($result);
  4700. }
  4701. public function getNoticeList(array $data): array
  4702. {
  4703. $where = [];
  4704. //title
  4705. if (isset($data['title']) && !empty($data['title'])) {
  4706. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4707. }
  4708. //level
  4709. if (isset($data['level']) && !empty($data['level'])) {
  4710. $where[] = ['notice.level', '=', $data['level']];
  4711. }
  4712. //status
  4713. if (isset($data['status']) && !empty($data['status'])) {
  4714. $where[] = ['notice.status', '=', $data['status']];
  4715. }
  4716. //type
  4717. if (isset($data['type']) && !empty($data['type'])) {
  4718. $where[] = ['notice.type', '=', $data['type']];
  4719. }
  4720. var_dump($data, '------------11111-2----test---------');
  4721. if ($data['type_id'] == 10000) {
  4722. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4723. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4724. })
  4725. ->where($where)
  4726. ->orderBy('updated_at', 'desc')
  4727. ->limit($data['page_size'])
  4728. ->offset(($data['page'] - 1) * $data['page_size'])
  4729. ->get();
  4730. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4731. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4732. })
  4733. ->where($where)
  4734. ->orderBy('updated_at', 'desc')
  4735. ->count();
  4736. } else {
  4737. $result = Notice::where($where)
  4738. // ->where('user_id', $data['user_id'])
  4739. ->Where(function ($query) use ($data) {
  4740. $query->Where(function ($q) use ($data) {
  4741. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4742. ->orWhere('notice.user_id', $data['user_id']);
  4743. });
  4744. })
  4745. ->when(!empty($data['status1']), function ($query) use ($data) {
  4746. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4747. })
  4748. ->orderBy('updated_at', 'desc')
  4749. ->limit($data['page_size'])
  4750. ->offset(($data['page'] - 1) * $data['page_size'])
  4751. ->get();
  4752. $total = Notice::where($where)
  4753. ->when(!empty($data['status1']), function ($query) use ($data) {
  4754. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4755. })
  4756. // ->where('user_id', $data['user_id'])
  4757. ->Where(function ($query) use ($data) {
  4758. $query->Where(function ($q) use ($data) {
  4759. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4760. ->orWhere('notice.user_id', $data['user_id']);
  4761. });
  4762. })
  4763. ->count();
  4764. }
  4765. if (empty($result)) {
  4766. return Result::error("查询失败", 0);
  4767. }
  4768. $data = [
  4769. 'rows' => $result,
  4770. 'count' => $total,
  4771. ];
  4772. return Result::success($data);
  4773. }
  4774. public function noticeList(array $data): array
  4775. {
  4776. $where = [];
  4777. //title
  4778. if (isset($data['title']) && !empty($data['title'])) {
  4779. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4780. }
  4781. //level
  4782. if (isset($data['level']) && !empty($data['level'])) {
  4783. $where[] = ['notice.level', '=', $data['level']];
  4784. }
  4785. //status
  4786. if (isset($data['status']) && !empty($data['status'])) {
  4787. $where[] = ['notice.status', '=', $data['status']];
  4788. }
  4789. //type
  4790. if (isset($data['type']) && !empty($data['type'])) {
  4791. $where[] = ['notice.type', '=', $data['type']];
  4792. }
  4793. var_dump($data, '------------11111-2----test---------');
  4794. if ($data['type_id'] == 10000) {
  4795. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4796. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4797. })
  4798. ->where($where)
  4799. ->orderBy('updated_at', 'desc')
  4800. ->limit($data['page_size'])
  4801. ->offset(($data['page'] - 1) * $data['page_size'])
  4802. ->get();
  4803. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4804. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4805. })
  4806. ->where($where)
  4807. ->orderBy('updated_at', 'desc')
  4808. ->count();
  4809. } else {
  4810. $result = Notice::where($where)
  4811. // ->where('user_id', $data['user_id'])
  4812. ->Where(function ($query) use ($data) {
  4813. $query->Where(function ($q) use ($data) {
  4814. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4815. ->orWhere('notice.user_id', $data['user_id']);
  4816. });
  4817. })
  4818. ->when(!empty($data['status1']), function ($query) use ($data) {
  4819. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4820. })
  4821. ->orderBy('updated_at', 'desc')
  4822. ->limit($data['page_size'])
  4823. ->offset(($data['page'] - 1) * $data['page_size'])
  4824. ->get();
  4825. $total = Notice::where($where)
  4826. ->when(!empty($data['status1']), function ($query) use ($data) {
  4827. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4828. })
  4829. // ->where('user_id', $data['user_id'])
  4830. ->Where(function ($query) use ($data) {
  4831. $query->Where(function ($q) use ($data) {
  4832. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4833. ->orWhere('notice.user_id', $data['user_id']);
  4834. });
  4835. })
  4836. ->count();
  4837. }
  4838. if (empty($result)) {
  4839. return Result::error("查询失败", 0);
  4840. }
  4841. $data = [
  4842. 'rows' => $result,
  4843. 'count' => $total,
  4844. ];
  4845. return Result::success($data);
  4846. }
  4847. public function getNoticeDetail(array $data): array
  4848. {
  4849. $result = Notice::where('id', $data['id'])->first();
  4850. if (empty($result)) {
  4851. return Result::error("查询失败", 0);
  4852. }
  4853. return Result::success($result);
  4854. }
  4855. public function deleteNotice(array $data): array
  4856. {
  4857. $notice = Notice::where('id', $data['id'])->first();
  4858. if (empty($notice)) {
  4859. return Result::error("删除失败", 0);
  4860. }
  4861. $chat_group_id = $notice->group_id;
  4862. if ($chat_group_id) {
  4863. //删除群聊
  4864. ChatGroups::where('id', $chat_group_id)->delete();
  4865. //删除群成员
  4866. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4867. //删除群聊记录
  4868. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4869. }
  4870. $result = Notice::where('id', $data['id'])->delete();
  4871. return Result::success($result);
  4872. }
  4873. public function complaintList(array $data): array
  4874. {
  4875. var_dump($data, '---------1---------');
  4876. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4877. unset($data['type_id']);
  4878. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4879. $where = [];
  4880. if ($type_id != 10000 && empty($data['deal_user'])) {
  4881. // $where['complaint.user_id'] = $user_id;
  4882. }
  4883. if (!empty($data['title'])) {
  4884. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4885. }
  4886. if (!empty($data['department_id'])) {
  4887. $where['complaint.department_id'] = $data['department_id'];
  4888. }
  4889. if (!empty($data['deal'])) {
  4890. $where['complaint.deal'] = $data['deal'];
  4891. }
  4892. if (!empty($data['status'])) {
  4893. $where['complaint.status'] = $data['status'];
  4894. }
  4895. var_dump(!empty($data['deal_user']), '----------1');
  4896. var_dump($where, '----------2');
  4897. $result = Complaint::where($where)
  4898. ->when(!empty($data['status1']), function ($query) use ($data) {
  4899. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4900. })
  4901. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4902. //json re_user_ids data[user_id]是不是在里面
  4903. $query->Where(function ($q) use ($data) {
  4904. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4905. ->where('complaint.status', 2);
  4906. });
  4907. })
  4908. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4909. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4910. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4911. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4912. ->orderBy('updated_at', 'desc')
  4913. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4914. //sql输出
  4915. if (empty($result)) {
  4916. return Result::error("暂无投诉信息", 0);
  4917. }
  4918. // 取出数据
  4919. $rows = $result->items();
  4920. $count = $result->total();
  4921. $responseData = [
  4922. 'rows' => $rows,
  4923. 'count' => $count,
  4924. ];
  4925. return Result::success($responseData);
  4926. }
  4927. public function getComplaintList(array $data): array
  4928. {
  4929. var_dump($data, '00000001000000000000');
  4930. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4931. unset($data['type_id']);
  4932. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4933. $where = [];
  4934. if ($type_id != 10000 && empty($data['deal_user'])) {
  4935. $where['complaint.user_id'] = $user_id;
  4936. }
  4937. if (!empty($data['title'])) {
  4938. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4939. }
  4940. if (!empty($data['department_id'])) {
  4941. $where['complaint.department_id'] = $data['department_id'];
  4942. }
  4943. if (!empty($data['deal'])) {
  4944. $where['complaint.deal'] = $data['deal'];
  4945. }
  4946. if (!empty($data['status'])) {
  4947. $where['complaint.status'] = $data['status'];
  4948. }
  4949. var_dump(!empty($data['deal_user']), '----------1');
  4950. var_dump($where, '----------2');
  4951. $result = Complaint::where($where)
  4952. ->when(!empty($data['status1']), function ($query) use ($data) {
  4953. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4954. })
  4955. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4956. // //json re_user_ids data[user_id]是不是在里面
  4957. // $query->Where(function ($q) use ($data) {
  4958. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4959. // ->where('complaint.status', 2);
  4960. // });
  4961. // })
  4962. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4963. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4964. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4965. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4966. ->orderBy('updated_at', 'desc')
  4967. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4968. //sql输出
  4969. if (empty($result)) {
  4970. return Result::error("暂无投诉信息", 0);
  4971. }
  4972. // 取出数据
  4973. $rows = $result->items();
  4974. $count = $result->total();
  4975. $responseData = [
  4976. 'rows' => $rows,
  4977. 'count' => $count,
  4978. ];
  4979. return Result::success($responseData);
  4980. }
  4981. public function getComplaintInfo(array $data): array
  4982. {
  4983. $result = Complaint::where('id', $data['id'])->first();
  4984. if (empty($result)) {
  4985. return Result::error("查询失败", 0);
  4986. }
  4987. return Result::success($result);
  4988. }
  4989. public function readComplaint(array $data): array
  4990. {
  4991. $result = Complaint::where('id', $data['id'])->first();
  4992. if (empty($result)) {
  4993. return Result::error("查询失败", 0);
  4994. }
  4995. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4996. $re_user_ids = json_decode($result['re_user_ids'], true);
  4997. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4998. //如果已经存在,就不再添加
  4999. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5000. $read_id = json_decode($result['read_id'], true);
  5001. if (!is_array($read_id)) {
  5002. $read_id = [];
  5003. }
  5004. if (!in_array($data['user_id'], $read_id)) {
  5005. $read_id[] = $data['user_id'];
  5006. $result['read_id'] = json_encode($read_id);
  5007. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5008. }
  5009. } else {
  5010. //如果不存在,就添加
  5011. $result['read_id'] = json_encode([$data['user_id']]);
  5012. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5013. }
  5014. }
  5015. return Result::success($result);
  5016. }
  5017. public function addComplaint(array $data): array
  5018. {
  5019. date_default_timezone_set('Asia/Shanghai');
  5020. $data['created_at'] = date('Y-m-d H:i:s');
  5021. $data['updated_at'] = date('Y-m-d H:i:s');
  5022. $this->sendMessage([
  5023. 'talk_type' => 800,
  5024. 'title' => $data['title'],
  5025. 'content' => '提交了审核',
  5026. 'messageType' => 6,
  5027. ]);
  5028. $result = Complaint::create($data);
  5029. return Result::success($result);
  5030. }
  5031. public function updateComplaint(array $data): array
  5032. {
  5033. date_default_timezone_set('Asia/Shanghai');
  5034. $data['updated_at'] = date('Y-m-d H:i:s');
  5035. $user_id = $data['user_id'] ?? 0;
  5036. $type_id = $data['type_id'] ?? 0;
  5037. unset($data['user_id']);
  5038. unset($data['type_id']);
  5039. $this->sendMessage([
  5040. 'talk_type' => 800,
  5041. 'title' => $data['title'],
  5042. 'content' => '提交了审核',
  5043. 'messageType' => 6,
  5044. ]);
  5045. $result = Complaint::where('id', $data['id'])->update($data);
  5046. return Result::success($result);
  5047. }
  5048. public function deleteComplaint(array $data): array
  5049. {
  5050. $result = Complaint::where('id', $data['id'])->delete();
  5051. return Result::success($result);
  5052. }
  5053. public function getComplainInfo(array $data): array
  5054. {
  5055. $result = Complaint::where('id', $data['id'])->first();
  5056. if (empty($result)) {
  5057. return Result::error("查询失败", 0);
  5058. }
  5059. return Result::success($result);
  5060. }
  5061. public function updateComplaintStatus(array $data): array
  5062. {
  5063. date_default_timezone_set('Asia/Shanghai');
  5064. $data['updated_at'] = date('Y-m-d H:i:s');
  5065. $user_id = $data['user_id'] ?? 0;
  5066. $type_id = $data['type_id'] ?? 0;
  5067. unset($data['user_id']);
  5068. unset($data['type_id']);
  5069. //处理, 写入处理人
  5070. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5071. $data['real_deal_user'] = $user_id;
  5072. }
  5073. //如果是deal 23,则判断是不是处理人
  5074. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5075. $complaintInof = Complaint::where('id', $data['id'])
  5076. ->where('real_deal_user', $user_id)
  5077. ->first();
  5078. if (empty($complaintInof)) {
  5079. return Result::error("处理人错误", 0);
  5080. }
  5081. }
  5082. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5083. if ($data['status'] == 1) {
  5084. $this->sendMessage([
  5085. 'talk_type' => 800,
  5086. 'title' => $complaintInfo['title'],
  5087. 'content' => '提交了审核',
  5088. 'messageType' => 6,
  5089. ]);
  5090. }
  5091. if ($data['status'] == 2 && !isset($data['deal'])) {
  5092. $this->sendMessage([
  5093. 'talk_type' => 801,
  5094. 'title' => $complaintInfo['title'],
  5095. 'content' => '审核通过',
  5096. 'messageType' => 6,
  5097. 'user_id' => $complaintInfo['user_id'],
  5098. ]);
  5099. $this->sendMessage([
  5100. 'talk_type' => 802,
  5101. 'title' => $complaintInfo['title'],
  5102. 'content' => '待处理',
  5103. 'messageType' => 6,
  5104. 'user_id' => $complaintInfo['re_user_ids'],
  5105. ]);
  5106. }
  5107. if ($data['status'] == 3 && !isset($data['deal'])) {
  5108. $this->sendMessage([
  5109. 'talk_type' => 801,
  5110. 'title' => $complaintInfo['title'],
  5111. 'content' => '审核拒绝',
  5112. 'messageType' => 6,
  5113. 'user_id' => $complaintInfo['user_id'],
  5114. ]);
  5115. }
  5116. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5117. $this->sendMessage([
  5118. 'talk_type' => 802,
  5119. 'title' => $complaintInfo['title'],
  5120. 'content' => '处理中',
  5121. 'messageType' => 6,
  5122. 'user_id' => $complaintInfo['re_user_ids'],
  5123. ]);
  5124. }
  5125. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5126. $this->sendMessage([
  5127. 'talk_type' => 802,
  5128. 'title' => $complaintInfo['title'],
  5129. 'content' => '不予处理',
  5130. 'messageType' => 6,
  5131. 'user_id' => $complaintInfo['re_user_ids'],
  5132. ]);
  5133. }
  5134. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5135. $this->sendMessage([
  5136. 'talk_type' => 802,
  5137. 'title' => $complaintInfo['title'],
  5138. 'content' => '已完结',
  5139. 'messageType' => 6,
  5140. 'user_id' => $complaintInfo['re_user_ids'],
  5141. ]);
  5142. }
  5143. $result = complaint::where('id', $data['id'])->update($data);
  5144. return Result::success($result);
  5145. }
  5146. public function updateGoodStatus(array $data): array
  5147. {
  5148. $user_id = $data['user_id'] ?? 0;
  5149. $type_id = $data['type_id'] ?? 0;
  5150. unset($data['user_id']);
  5151. unset($data['type_id']);
  5152. $goodInfo = Good::where('id', $data['id'])->first();
  5153. if ($data['status'] == 2) {
  5154. $this->sendMessage([
  5155. 'talk_type' => 201,
  5156. 'title' => $goodInfo['name'],
  5157. 'content' => '审核通过',
  5158. 'messageType' => 3,
  5159. 'user_id' => $goodInfo['user_id'],
  5160. ]);
  5161. }
  5162. if ($data['status'] == 3) {
  5163. $this->sendMessage([
  5164. 'talk_type' => 201,
  5165. 'title' => $goodInfo['name'],
  5166. 'content' => '审核拒绝',
  5167. 'messageType' => 3,
  5168. 'user_id' => $goodInfo['user_id'],
  5169. ]);
  5170. }
  5171. if ($data['status'] == 1) {
  5172. $this->sendMessage([
  5173. 'talk_type' => 200,
  5174. 'title' => $goodInfo['name'],
  5175. 'content' => '提交了审核',
  5176. 'messageType' => 3,
  5177. ]);
  5178. }
  5179. $result = Good::where('id', $data['id'])->update($data);
  5180. return Result::success($result);
  5181. }
  5182. public function updateJobHuntingStatus(array $data): array
  5183. {
  5184. $user_id = $data['user_id'] ?? 0;
  5185. $type_id = $data['type_id'] ?? 0;
  5186. unset($data['user_id']);
  5187. unset($data['type_id']);
  5188. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5189. if ($data['status'] == 2) {
  5190. $this->sendMessage([
  5191. 'talk_type' => 601,
  5192. 'title' => $jogHuntingInfo['name'],
  5193. 'content' => '审核通过',
  5194. 'messageType' => 11,
  5195. 'user_id' => $jogHuntingInfo['user_id'],
  5196. ]);
  5197. }
  5198. if ($data['status'] == 3) {
  5199. $this->sendMessage([
  5200. 'talk_type' => 601,
  5201. 'title' => $jogHuntingInfo['name'],
  5202. 'content' => '审核拒绝',
  5203. 'messageType' => 11,
  5204. 'user_id' => $jogHuntingInfo['user_id'],
  5205. ]);
  5206. }
  5207. if ($data['status'] == 1) {
  5208. $this->sendMessage([
  5209. 'talk_type' => 600,
  5210. 'title' => $jogHuntingInfo['name'],
  5211. 'content' => '提交了审核',
  5212. 'messageType' => 11,
  5213. ]);
  5214. }
  5215. $result = JobHunting::where('id', $data['id'])->update($data);
  5216. return Result::success($result);
  5217. }
  5218. public function updateNoticeStatus(array $data): array
  5219. {
  5220. $user_id = $data['user_id'] ?? 0;
  5221. $type_id = $data['type_id'] ?? 0;
  5222. unset($data['user_id']);
  5223. unset($data['type_id']);
  5224. //查询公告
  5225. $notice = Notice::where('id', $data['id'])->first();
  5226. if (empty($notice)) {
  5227. return Result::error("公告不存在", 0);
  5228. }
  5229. //$chat_ids 去除掉$data['user_id']
  5230. $chat_ids = json_decode($notice['re_user_ids'], true);
  5231. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5232. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5233. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5234. //chat_group
  5235. $group_id = PublicData::uuid();
  5236. $groupData = [
  5237. 'id' => $group_id,
  5238. 'creator_id' => $notice['user_id'],
  5239. 'group_name' => $notice['group_name'] ?? '',
  5240. 'profile' => $notice['profile'] ?? 0,
  5241. ];
  5242. var_dump($groupData, '-----------------groupData-------');
  5243. $groupResult = ChatGroups::insertGetId($groupData);
  5244. var_dump($groupResult, '-----------------groupid-------');
  5245. $groupMemberData = [
  5246. 'id' => PublicData::uuid(),
  5247. 'user_id' => $notice['user_id'],
  5248. 'group_id' => $group_id,
  5249. 'leader' => 2,
  5250. ];
  5251. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5252. //插入群成员表
  5253. $groupMemberDataUser = [];
  5254. $chatData = [];
  5255. foreach ($chat_ids as $key => $value) {
  5256. $groupMemberDataUser[] = [
  5257. 'id' => PublicData::uuid(),
  5258. 'user_id' => $value,
  5259. 'group_id' => $group_id,
  5260. 'leader' => 1,
  5261. ];
  5262. $chatData[] = [
  5263. 'user_id' => $value,
  5264. 'msg_type' => 1,
  5265. 'receiver_id' => $group_id,
  5266. 'content' => '通过通知创建群聊',
  5267. 'group_receiver_id' => $notice['user_id'],
  5268. 'action' => 'recieved',
  5269. 'created_at' => date('Y-m-d H:i:s'),
  5270. ];
  5271. }
  5272. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5273. ChatGroupsMember::insert($groupMemberDataUser);
  5274. //插入一条管理员聊天记录
  5275. $chatData[] = [
  5276. 'user_id' => $notice['user_id'],
  5277. 'msg_type' => 1,
  5278. 'receiver_id' => $group_id,
  5279. 'content' => '通过通知创建群聊',
  5280. 'group_receiver_id' => $notice['user_id'],
  5281. 'action' => 'said',
  5282. 'created_at' => date('Y-m-d H:i:s'),
  5283. ];
  5284. var_dump($chatData, '-----------------chatData-------');
  5285. $chatResult = ChatRecords::insert($chatData);
  5286. //处理imp
  5287. $group = [
  5288. 'type' => 1,
  5289. 'name' => $notice['group_name'] ?? '',
  5290. 'profile' => '',
  5291. 'avatar' => '',
  5292. 'creator_id' => $notice['user_id'],
  5293. ];
  5294. $groupResult = GroupImp::insertGetId($group);
  5295. var_dump($groupResult, '获取imp group_id');
  5296. $groupMember = [
  5297. 'user_id' => $notice['user_id'],
  5298. 'group_id' => $groupResult,
  5299. 'leader' => 1,
  5300. 'join_time' => Date('Y-m-d H:i:s')
  5301. ];
  5302. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5303. $talk_session = [
  5304. 'user_id' => $notice['user_id'],
  5305. 'to_from_id' => $groupResult,
  5306. 'talk_mode' => 2,
  5307. 'created_at' => Date('Y-m-d H:i:s'),
  5308. 'updated_at' => Date('Y-m-d H:i:s'),
  5309. ];
  5310. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5311. //被通知人员处理
  5312. foreach ($chat_ids as $key => $value) {
  5313. $groupMemberdata[] = [
  5314. 'user_id' => $value,
  5315. 'group_id' => $groupResult,
  5316. 'leader' => 3,
  5317. 'join_time' => Date('Y-m-d H:i:s')
  5318. ];
  5319. $talk_sessionData[] = [
  5320. 'user_id' => $value,
  5321. 'to_from_id' => $groupResult,
  5322. 'talk_mode' => 2,
  5323. 'created_at' => Date('Y-m-d H:i:s'),
  5324. 'updated_at' => Date('Y-m-d H:i:s'),
  5325. ];
  5326. }
  5327. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5328. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5329. $group_id = $groupResult;
  5330. //更新result的 group_id
  5331. $data['group_id'] = $group_id;
  5332. Notice::where(['id' => $data['id']])->update($data);
  5333. }
  5334. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5335. //删除掉信息
  5336. GroupImp::where('id', $notice['group_id'])->delete();
  5337. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5338. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5339. foreach ($chat_ids as $key => $value) {
  5340. }
  5341. //聊天记录删除
  5342. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5343. $data['group_id'] = null;
  5344. Notice::where(['id' => $data['id']])->update($data);
  5345. }
  5346. $result = Notice::where('id', $data['id'])->update($data);
  5347. $noticeInfo = Notice::where('id', $data['id'])->first();
  5348. if ($data['status'] == 2) {
  5349. $this->sendMessage([
  5350. 'talk_type' => 701,
  5351. 'title' => $noticeInfo['title'],
  5352. 'content' => '审核通过',
  5353. 'messageType' => 3,
  5354. 'user_id' => $noticeInfo['user_id'],
  5355. ]);
  5356. }
  5357. if ($data['status'] == 3) {
  5358. $this->sendMessage([
  5359. 'talk_type' => 701,
  5360. 'title' => $noticeInfo['title'],
  5361. 'content' => '审核拒绝',
  5362. 'messageType' => 3,
  5363. 'user_id' => $noticeInfo['user_id'],
  5364. ]);
  5365. }
  5366. if ($data['status'] == 1) {
  5367. $this->sendMessage([
  5368. 'talk_type' => 700,
  5369. 'title' => $noticeInfo['title'],
  5370. 'content' => '提交了审核',
  5371. 'messageType' => 3,
  5372. ]);
  5373. }
  5374. return Result::success($result);
  5375. }
  5376. public function getDUser(array $data): array
  5377. {
  5378. if (!empty($data['ids'])) {
  5379. $user = User::whereIn('id', $data['ids'])->getall();
  5380. if (empty($user)) {
  5381. return Result::error('无数据', 0);
  5382. }
  5383. return Result::success($user);
  5384. }
  5385. $where = [];
  5386. if (!empty($data['department_id'])) {
  5387. $where['department_id'] = $data['department_id'];
  5388. }
  5389. if (!empty($data['city_id'])) {
  5390. $where['city_id'] = $data['city_id'];
  5391. }
  5392. $result = User::where('type_id', 2)
  5393. ->where('status', 1)
  5394. ->where($where)
  5395. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5396. ->get();
  5397. if (empty($result)) {
  5398. return Result::error("查询失败", 0);
  5399. }
  5400. return Result::success($result);
  5401. }
  5402. /**
  5403. * 验证导航名称是否重复
  5404. * @return void
  5405. */
  5406. public function checkCategoryName(array $data): array
  5407. {
  5408. $result = Category::when($data, function ($query) use ($data) {
  5409. if (isset($data['name']) && $data['name']) {
  5410. $query->where("name", $data['name']);
  5411. }
  5412. if (isset($data['id']) && $data['id']) {
  5413. $query->where("id", "!=", $data['id']);
  5414. }
  5415. })->first();
  5416. if ($result) {
  5417. return Result::error("已存在");
  5418. } else {
  5419. return Result::success();
  5420. }
  5421. }
  5422. //20250226 产品列表
  5423. // 20250306 -------招聘--------fr
  5424. /*
  5425. * 招聘列表
  5426. * */
  5427. public function getJobRecruitingList(array $data): array
  5428. {
  5429. $where = [];
  5430. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5431. if ($data['checkout'] == 0) {
  5432. $job_status = [0, 2];
  5433. } else {
  5434. $job_status = [1];
  5435. }
  5436. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5437. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5438. }
  5439. $user = User::where('id', $data['user_id'])->first();
  5440. if (empty($user)) {
  5441. return Result::error("用户不存在", 0);
  5442. }
  5443. // 3:企业会员
  5444. if ($user['type_id'] == 3) {
  5445. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5446. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5447. }
  5448. // 如果 $where 为空,则不添加 where 条件
  5449. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5450. return $query->where($where);
  5451. })
  5452. ->whereIn('job_recruiting.status', $job_status)
  5453. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5454. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5455. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5456. ->orderBy("updated_at", "desc")
  5457. ->offset(($data['page'] - 1) * $data['page_size'])
  5458. ->limit($data['page_size'])
  5459. ->get()
  5460. ->all();
  5461. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5462. return $query->where($where);
  5463. })
  5464. ->whereIn('job_recruiting.status', $job_status)
  5465. ->count();
  5466. if (empty($result)) {
  5467. return Result::error("暂无招聘信息", 0);
  5468. }
  5469. return Result::success($result);
  5470. }
  5471. /*
  5472. * 招聘信息添加
  5473. * */
  5474. public function addJobRecruiting(array $data): array
  5475. {
  5476. // var_dump('添加招聘进入news------data',$data);
  5477. // return Result::success($data);
  5478. $user = User::where('user.id', $data['user_id'])
  5479. ->where('user.status', 1)
  5480. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5481. ->select(
  5482. 'user.type_id',
  5483. 'user.mobile',
  5484. 'user.email',
  5485. 'user_info.business_name',
  5486. 'user_info.company_hy_id',
  5487. 'user_info.company_nature',
  5488. 'user_info.company_size',
  5489. 'user_info.introduction',
  5490. 'user_info.real_name',
  5491. 'user_info.company_url',
  5492. 'user_info.address_arr_id',
  5493. 'user_info.address'
  5494. )
  5495. ->first();
  5496. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5497. return Result::error("用户不存在", 0);
  5498. }
  5499. $web = Website::where('id', $data['website_id'])->first();
  5500. if (empty($web)) {
  5501. return Result::error("网站不存在", 0);
  5502. }
  5503. // var_dump('添加招聘进入news---user---user',$user);
  5504. // 处理招聘关键词
  5505. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5506. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5507. } else {
  5508. Jieba::init(); // 初始化 jieba-php
  5509. Finalseg::init();
  5510. $segList = Jieba::cut($data['title']);
  5511. $segList1 = array_slice($segList, 0, 8);
  5512. $data['keyword'] = implode(',', $segList1);
  5513. }
  5514. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5515. $content = $data['description'];
  5516. // 去除 <style> 和 <script> 标签及其内容
  5517. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5518. // 去除所有 HTML 标签
  5519. $content = strip_tags($content);
  5520. // 去除 HTML 实体
  5521. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5522. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5523. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5524. // 去除多余空白
  5525. $content = preg_replace('/\s+/u', '', $content);
  5526. // 截取 100 个字符
  5527. $data['seo_description'] = mb_substr($content, 0, 100);
  5528. }
  5529. // return Result::success($user);
  5530. $data['action_id'] = $data['user_id'] ?? null;
  5531. $data['user_type'] = $user['type_id'] ?? null;
  5532. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5533. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5534. $data['catid'] = end($data['cat_arr_id']);
  5535. } else {
  5536. $data['catid'] = 0;
  5537. }
  5538. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5539. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5540. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5541. // 公司地址 管理员必填
  5542. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5543. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5544. // 管理员-企业相关信息
  5545. $company = [
  5546. // 'user_id' => $data['user_id']?? null,
  5547. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5548. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5549. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5550. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5551. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5552. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5553. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5554. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5555. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5556. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5557. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5558. ];
  5559. //去掉相关企业信息
  5560. $job = array_diff_key($data, array_flip(array_keys($company)));
  5561. // var_dump('添加招聘进入news---job---user',$job);
  5562. Db::beginTransaction();
  5563. try {
  5564. // // 先添加职位相关信息
  5565. if ($user['type_id'] == 10000) {
  5566. $job['status'] = 1;
  5567. }
  5568. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5569. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5570. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5571. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5572. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5573. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5574. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5575. // return Result::success($job);
  5576. $jobId = JobRecruiting::insertGetId($job);
  5577. if (empty($jobId)) {
  5578. Db::rollBack();
  5579. return Result::error("添加失败");
  5580. }
  5581. // 添加公司信息
  5582. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5583. $company['job_id'] = $jobId;
  5584. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5585. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5586. if ($user['type_id'] == 10000) {
  5587. // 管理员添加企业信息
  5588. $companyId = JobCompany::insertGetId($company);
  5589. if (empty($companyId)) {
  5590. Db::rollBack();
  5591. return Result::error("添加失败");
  5592. }
  5593. } else {
  5594. // 企业会员添加企业信息
  5595. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5596. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5597. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5598. $company['job_id'] = $jobId;
  5599. $companyId = JobCompany::insertGetId($company);
  5600. if (empty($companyId)) {
  5601. Db::rollBack();
  5602. return Result::error("添加失败");
  5603. }
  5604. }
  5605. Db::commit();
  5606. $result = [
  5607. 'job_id' => $jobId,
  5608. 'company_id' => $companyId,
  5609. ];
  5610. return Result::success($result);
  5611. } catch (\Exception $e) {
  5612. Db::rollBack();
  5613. return Result::error($e->getMessage(), 0);
  5614. }
  5615. // return Result::success($result);
  5616. }
  5617. /*
  5618. * 获取招聘信息详情
  5619. * */
  5620. public function getJobRecruitingInfo(array $data): array
  5621. {
  5622. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5623. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5624. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5625. ->select(
  5626. 'job_recruiting.*',
  5627. 'website.website_name as website_name',
  5628. 'job_company.business_name',
  5629. 'job_company.company_hy_id',
  5630. 'job_company.company_size',
  5631. 'job_company.company_nature',
  5632. 'job_company.introduction',
  5633. 'job_company.real_name',
  5634. 'job_company.mobile',
  5635. 'job_company.company_url',
  5636. 'job_company.address_arr_id',
  5637. 'job_company.address',
  5638. 'job_company.email'
  5639. )
  5640. ->first();
  5641. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5642. if (!empty($cityId)) {
  5643. if (isset($cityId[1]) && $cityId[1] != null) {
  5644. $city = District::where('id', $cityId[1])->first(['name']);
  5645. } else {
  5646. $city = District::where('id', $cityId[0])->first(['name']);
  5647. }
  5648. $result['city'] = $city['name'] ?? '';
  5649. }
  5650. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5651. if (is_array($addressId) && !empty($addressId)) {
  5652. $address = District::whereIn('id', $addressId)
  5653. ->orderBy('level', 'asc')
  5654. ->get(['name'])
  5655. ->pluck('name')
  5656. ->implode('');
  5657. // $job->address_name = $address ?? '';
  5658. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5659. }
  5660. if (empty($result)) {
  5661. return Result::error("招聘信息不存在", 0);
  5662. }
  5663. // return Result::success($job);
  5664. return Result::success($result);
  5665. }
  5666. /*
  5667. * 修改招聘信息
  5668. * */
  5669. public function upJobRecruiting(array $data): array
  5670. {
  5671. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5672. // return Result::success($job);
  5673. if (empty($job)) {
  5674. return Result::error("招聘信息不存在", 0);
  5675. }
  5676. $user = User::where('id', $data['user_id'])->first();
  5677. // return Result::success($user);
  5678. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5679. return Result::error("用户不存在", 0);
  5680. }
  5681. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5682. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5683. }
  5684. // 处理招聘关键词
  5685. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5686. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5687. } else {
  5688. Jieba::init(); // 初始化 jieba-php
  5689. Finalseg::init();
  5690. $segList = Jieba::cut($data['title']);
  5691. $segList1 = array_slice($segList, 0, 8);
  5692. $data['keyword'] = implode(',', $segList1);
  5693. }
  5694. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5695. $content = $data['description'];
  5696. // 去除 <style> 和 <script> 标签及其内容
  5697. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5698. // 去除所有 HTML 标签
  5699. $content = strip_tags($content);
  5700. // 去除 HTML 实体
  5701. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5702. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5703. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5704. // 去除多余空白
  5705. $content = preg_replace('/\s+/u', '', $content);
  5706. // 截取 100 个字符
  5707. $data['seo_description'] = mb_substr($content, 0, 100);
  5708. }
  5709. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5710. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5711. $data['catid'] = end($data['cat_arr_id']);
  5712. } else {
  5713. }
  5714. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5715. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5716. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5717. // 公司地址 管理员必填
  5718. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5719. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5720. // 管理员-企业相关信息
  5721. $company = [
  5722. // 'user_id' => $data['user_id']?? null,
  5723. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5724. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5725. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5726. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5727. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5728. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5729. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5730. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5731. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5732. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5733. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5734. ];
  5735. //去掉相关企业信息
  5736. $data = array_diff_key($data, array_flip(array_keys($company)));
  5737. $jobId = $data['id'];
  5738. $web = $data['website_id'];
  5739. $data['action_id'] = $data['user_id'];
  5740. unset($data['user_id']);
  5741. unset($data['user_type']);
  5742. unset($data['id']);
  5743. unset($data['website_id']);
  5744. // return Result::success($data);
  5745. Db::beginTransaction();
  5746. try {
  5747. // 管理员修改招聘信息
  5748. if ($user['type_id'] == 10000) {
  5749. $data['website_id'] = $web;
  5750. $company['website_id'] = $data['website_id'];
  5751. $data['status'] = 1;
  5752. } else {
  5753. $data['status'] = 0;
  5754. }
  5755. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5756. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5757. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5758. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5759. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5760. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5761. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5762. // return Result::success($job);
  5763. // Db::rollBack();
  5764. // return Result::success($company);
  5765. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5766. $this->sendMessage([
  5767. 'talk_type' => 500,
  5768. 'title' => $data['title'],
  5769. 'content' => '提交了审核',
  5770. 'messageType' => 10,
  5771. ]);
  5772. }
  5773. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5774. if (empty($result['job'])) {
  5775. Db::rollBack();
  5776. return Result::error("修改招聘信息失败");
  5777. }
  5778. // 管理员修改企业相关信息
  5779. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5780. if (empty($result['company'])) {
  5781. Db::rollBack();
  5782. return Result::error("修改企业相关信息失败");
  5783. }
  5784. Db::commit();
  5785. // return Result::success($result);
  5786. } catch (\Exception $e) {
  5787. Db::rollBack();
  5788. return Result::error($e->getMessage(), 0);
  5789. }
  5790. return Result::success($result);
  5791. }
  5792. /*
  5793. * 招聘信息删除
  5794. * */
  5795. public function delJobRecruiting(array $data): array
  5796. {
  5797. $user = User::where('id', $data['user_id'])->first();
  5798. if (empty($user)) {
  5799. return Result::error("用户不存在", 0);
  5800. }
  5801. $job = JobRecruiting::where('id', $data['id'])->first();
  5802. if (empty($job)) {
  5803. return Result::error("招聘信息不存在", 0);
  5804. }
  5805. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5806. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5807. }
  5808. Db::beginTransaction();
  5809. try {
  5810. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5811. if (empty($result['job'])) {
  5812. Db::rollBack();
  5813. return Result::error("删除招聘信息失败");
  5814. }
  5815. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5816. if (empty($result['company'])) {
  5817. Db::rollBack();
  5818. return Result::error("删除企业相关信息失败");
  5819. }
  5820. Db::commit();
  5821. } catch (\Exception $e) {
  5822. Db::rollBack();
  5823. return Result::error($e->getMessage(), 0);
  5824. }
  5825. return Result::success($result);
  5826. }
  5827. /*
  5828. * 获取公司信息
  5829. * */
  5830. public function getJobCompany(array $data): array
  5831. {
  5832. $user = User::where('user.id', $data['user_id'])
  5833. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5834. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5835. ->first();
  5836. // return Result::success($user);
  5837. if (empty($user)) {
  5838. return Result::error("用户不存在", 0);
  5839. }
  5840. if ($user['type_id'] == 3) {
  5841. $result = [
  5842. // 'id' => 0,
  5843. 'user_id' => $data['user_id'],
  5844. 'website_id' => $data['website_id'],
  5845. 'business_name' => $user['business_name'], // 企业名称
  5846. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5847. 'company_nature' => $user['company_nature'], // 公司性质
  5848. 'company_size' => $user['company_size'], // 公司规模
  5849. 'introduction' => $user['introduction'], // 公司简介
  5850. 'real_name' => $user['real_name'], // 企业联系人
  5851. 'mobile' => $user['mobile'], // 企业联系电话
  5852. 'company_url' => $user['company_url'], // 企业网址
  5853. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5854. 'address' => $user['address'], // 企业地址
  5855. 'email' => $user['email'], // 企业邮箱
  5856. ];
  5857. } else {
  5858. return Result::error("用户类型错误", 0);
  5859. }
  5860. if (empty($result)) {
  5861. return Result::error("公司信息不存在", 0);
  5862. }
  5863. return Result::success($result);
  5864. }
  5865. /*
  5866. * 修改公司信息
  5867. * */
  5868. public function upJobCompany(array $data): array
  5869. {
  5870. // return Result::success($data);
  5871. $user = User::where('user.id', $data['user_id'])
  5872. ->where('user.status', 1)
  5873. ->select('user.user_name', 'user.type_id')
  5874. ->first();
  5875. if (empty($user)) {
  5876. return Result::error("用户不存在", 0);
  5877. }
  5878. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5879. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5880. $company = [
  5881. 'business_name' => $data['business_name'], // 企业名称
  5882. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5883. 'company_nature' => $data['company_nature'], // 公司性质
  5884. 'company_size' => $data['company_size'], // 公司规模
  5885. 'introduction' => $data['introduction'], // 公司简介
  5886. // 'real_name' => $data['real_name'], // 企业联系人
  5887. 'company_url' => $data['company_url'], // 企业网址
  5888. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5889. 'address' => $data['address'], // 企业详细地址
  5890. // 'email' => $data['email'], // 企业邮箱
  5891. ];
  5892. if ($user['type_id'] == 3) {
  5893. Db::beginTransaction();
  5894. try {
  5895. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5896. 'business_name' => $data['business_name'], // 企业名称
  5897. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5898. 'company_nature' => $data['company_nature'], // 公司性质
  5899. 'company_size' => $data['company_size'], // 公司规模
  5900. 'introduction' => $data['introduction'], // 公司简介
  5901. // 'real_name' => $data['real_name'], // 企业联系人
  5902. 'company_url' => $data['company_url'], // 企业网址
  5903. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5904. 'address' => $data['address'], // 企业详细地址
  5905. ]);
  5906. if (empty($result['userinfo'])) {
  5907. Db::rollBack();
  5908. return Result::error('修改企业会员信息失败!');
  5909. }
  5910. $result['user'] = User::where('id', $data['user_id'])->update([
  5911. 'email' => $data['email'], // 企业邮箱
  5912. ]);
  5913. if (empty($result['user'])) {
  5914. Db::rollBack();
  5915. return Result::error('修改个人中心信息失败!');
  5916. }
  5917. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5918. if (!empty($job_company)) {
  5919. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5920. if (empty($result['job_company'])) {
  5921. Db::rollBack();
  5922. return Result::error('修改企业会员信息失败!');
  5923. }
  5924. }
  5925. Db::commit();
  5926. return Result::success($result);
  5927. } catch (\Exception $e) {
  5928. Db::rollBack();
  5929. return Result::error($e->getMessage(), 0);
  5930. }
  5931. } else {
  5932. return Result::error("用户类型错误", 0);
  5933. }
  5934. }
  5935. /*
  5936. * 获取省-市
  5937. * */
  5938. public function getJobRecruitingArea(array $data): array
  5939. {
  5940. if (isset($data['pid']) && $data['pid'] != null) {
  5941. $result = District::where('pid', $data['pid'])->get()->all();
  5942. } else {
  5943. $result = District::where('level', 1)->get()->all();
  5944. }
  5945. if (empty($result)) {
  5946. return Result::error("暂无此省市", 0);
  5947. }
  5948. return Result::success($result);
  5949. }
  5950. /*
  5951. * 获取行业分类
  5952. * */
  5953. public function getIndustry(array $data): array
  5954. {
  5955. $result = JobIndustry::get()->all();
  5956. if (empty($result)) {
  5957. return Result::error("暂无行业分类", 0);
  5958. }
  5959. return Result::success($result);
  5960. }
  5961. /*
  5962. * 获取职位
  5963. * */
  5964. public function getPositionList(array $data): array
  5965. {
  5966. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5967. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5968. } else {
  5969. $result = JobPosition::where('zwpid', 0)->get()->all();
  5970. }
  5971. if (empty($result)) {
  5972. return Result::error("暂无此职位", 0);
  5973. }
  5974. return Result::success($result);
  5975. }
  5976. /*
  5977. * 获取工作性质-菜单
  5978. * */
  5979. public function getJobNature(array $data): array
  5980. {
  5981. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5982. if (empty($result)) {
  5983. return Result::error("暂无工作性质", 0);
  5984. }
  5985. return Result::success($result);
  5986. }
  5987. /*
  5988. * 获取工作经验-菜单
  5989. * */
  5990. public function getExperience(array $data): array
  5991. {
  5992. $result = JobEnum::where('egroup', 'years')->get()->all();
  5993. if (empty($result)) {
  5994. return Result::error("暂无工作经验", 0);
  5995. }
  5996. return Result::success($result);
  5997. }
  5998. /*
  5999. * 获取学历-菜单
  6000. * */
  6001. public function getEducation(array $data): array
  6002. {
  6003. $result = JobEnum::where('egroup', 'education')->get()->all();
  6004. if (empty($result)) {
  6005. return Result::error("暂无学历", 0);
  6006. }
  6007. return Result::success($result);
  6008. }
  6009. /*
  6010. * 获取薪资-菜单
  6011. * */
  6012. public function getSalary(array $data): array
  6013. {
  6014. $result = JobEnum::where('egroup', 'income')->get()->all();
  6015. if (empty($result)) {
  6016. return Result::error("暂无薪资", 0);
  6017. }
  6018. return Result::success($result);
  6019. }
  6020. /*
  6021. * 获取语言-菜单
  6022. * */
  6023. public function getLanguage(array $data): array
  6024. {
  6025. $result = JobEnum::where('egroup', 'language')->get()->all();
  6026. if (empty($result)) {
  6027. return Result::error("暂无语言", 0);
  6028. }
  6029. return Result::success($result);
  6030. }
  6031. /*
  6032. * 获取掌握程度-菜单
  6033. * */
  6034. public function getLevel(array $data): array
  6035. {
  6036. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6037. if (empty($result)) {
  6038. return Result::error("暂无工作性质", 0);
  6039. }
  6040. return Result::success($result);
  6041. }
  6042. // 公司信息
  6043. /*
  6044. * 获取公司性质-菜单
  6045. * */
  6046. public function getCompanyNature(array $data): array
  6047. {
  6048. $result = JobNature::get()->all();
  6049. if (empty($result)) {
  6050. return Result::error("暂无公司性质", 0);
  6051. }
  6052. return Result::success($result);
  6053. }
  6054. /*
  6055. * 获取公司规模-菜单
  6056. * */
  6057. public function getCompanySize(array $data): array
  6058. {
  6059. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6060. if (empty($result)) {
  6061. return Result::error("暂无公司规模", 0);
  6062. }
  6063. return Result::success($result);
  6064. }
  6065. /*
  6066. * 招聘信息审核
  6067. * */
  6068. public function checkJobRecruiting(array $data): array
  6069. {
  6070. $user = User::where('id', $data['user_id'])->first();
  6071. if (empty($user)) {
  6072. return Result::error("用户不存在", 0);
  6073. }
  6074. $job = JobRecruiting::where('id', $data['id'])->first();
  6075. if (empty($job)) {
  6076. return Result::error("招聘信息不存在", 0);
  6077. }
  6078. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6079. if ($user['type_id'] != 10000) {
  6080. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6081. }
  6082. // 驳回原因
  6083. if ($data['status'] == 2) {
  6084. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6085. }
  6086. $data['action_id'] = $data['user_id'];
  6087. unset($data['user_id']);
  6088. if ($data['status'] == 1) {
  6089. $this->sendMessage([
  6090. 'talk_type' => 501,
  6091. 'title' => $job['title'],
  6092. 'content' => '审核通过',
  6093. 'messageType' => 10,
  6094. 'user_id' => $job['user_id'],
  6095. ]);
  6096. }
  6097. if ($data['status'] == 2) {
  6098. $this->sendMessage([
  6099. 'talk_type' => 501,
  6100. 'title' => $job['title'],
  6101. 'content' => '审核拒绝',
  6102. 'messageType' => 10,
  6103. 'user_id' => $job['user_id'],
  6104. ]);
  6105. }
  6106. if ($data['status'] == 0) {
  6107. $this->sendMessage([
  6108. 'talk_type' => 500,
  6109. 'title' => $job['title'],
  6110. 'content' => '提交了审核',
  6111. 'messageType' => 10,
  6112. ]);
  6113. }
  6114. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6115. if (empty($result)) {
  6116. return Result::error("审核失败", 0);
  6117. }
  6118. return Result::success($result);
  6119. }
  6120. public function myApplyList(array $data): array
  6121. {
  6122. var_dump($data, '------参数');
  6123. $user = User::where('id', $data['user_id'])->first();
  6124. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6125. return Result::error("用户不存在", 0);
  6126. }
  6127. // 1:个人会员 职场机会
  6128. if ($user['type_id'] == 1) {
  6129. $where['user_id'] = $user['id'];
  6130. }
  6131. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6132. $query->where('user_id', $user['id']);
  6133. })
  6134. ->pluck('recruit_id');
  6135. $where = [];
  6136. if (isset($data['salary']) && $data['salary'] != null) {
  6137. $where['job_recruiting.salary'] = $data['salary'];
  6138. }
  6139. if (isset($data['experience']) && $data['experience'] != null) {
  6140. $where['job_recruiting.experience'] = $data['experience'];
  6141. }
  6142. if (isset($data['business_name']) && $data['business_name'] != null) {
  6143. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6144. }
  6145. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6146. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6147. ->where($where);
  6148. // ->count();
  6149. $count = $query->count();
  6150. $query = clone $query;
  6151. $job = $query
  6152. ->leftJoin('job_enum as income_enum', function ($join) {
  6153. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6154. ->where('income_enum.egroup', 'income');
  6155. })
  6156. ->leftJoin('job_enum as years_enum', function ($join) {
  6157. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6158. ->where('years_enum.egroup', 'years');
  6159. })
  6160. // ->where($where)
  6161. ->orderBy('job_recruiting.updated_at', 'desc')
  6162. ->select(
  6163. 'job_recruiting.id',
  6164. 'job_recruiting.title',
  6165. 'job_company.business_name',
  6166. 'income_enum.evalue as salary_evalue',
  6167. 'income_enum.ename as salary_ename',
  6168. 'years_enum.evalue as experience_evalue',
  6169. 'years_enum.ename as experience_ename',
  6170. 'job_recruiting.updated_at'
  6171. )
  6172. ->offset(($data['page'] - 1) * $data['pageSize'])
  6173. ->limit($data['pageSize'])
  6174. ->get()
  6175. ->all();
  6176. if (empty($job)) {
  6177. return Result::error("暂无招聘信息", 0);
  6178. }
  6179. $result = [
  6180. 'row' => $job,
  6181. 'count' => $count,
  6182. ];
  6183. return Result::success($result);
  6184. }
  6185. public function readJobApply(array $data): array
  6186. {
  6187. $result = JobApply::where('id', $data['id'])->first();
  6188. if (empty($result)) {
  6189. return Result::error("查询失败", 0);
  6190. }
  6191. $result = JobApply::where('id', $data['id'])->update([
  6192. 'status' => 2,
  6193. ]);
  6194. return Result::success($result);
  6195. }
  6196. /*
  6197. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6198. * */
  6199. public function getRecruitingList(array $data): array
  6200. {
  6201. $user = User::where('id', $data['user_id'])->first();
  6202. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6203. return Result::error("用户不存在", 0);
  6204. }
  6205. // 1:个人会员 职场机会
  6206. if ($user['type_id'] == 1) {
  6207. $where['user_id'] = $user['id'];
  6208. }
  6209. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6210. $query->where('receiver_id', $user['id']);
  6211. })
  6212. ->pluck('recruit_id');
  6213. // return Result::success($recruitingId);
  6214. $where = [];
  6215. if (isset($data['salary']) && $data['salary'] != null) {
  6216. $where['job_recruiting.salary'] = $data['salary'];
  6217. }
  6218. if (isset($data['experience']) && $data['experience'] != null) {
  6219. $where['job_recruiting.experience'] = $data['experience'];
  6220. }
  6221. if (isset($data['business_name']) && $data['business_name'] != null) {
  6222. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6223. }
  6224. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6225. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6226. ->where($where);
  6227. // ->count();
  6228. $count = $query->count();
  6229. $query = clone $query;
  6230. $job = $query
  6231. ->leftJoin('job_enum as income_enum', function ($join) {
  6232. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6233. ->where('income_enum.egroup', 'income');
  6234. })
  6235. ->leftJoin('job_enum as years_enum', function ($join) {
  6236. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6237. ->where('years_enum.egroup', 'years');
  6238. })
  6239. // ->where($where)
  6240. ->orderBy('job_recruiting.updated_at', 'desc')
  6241. ->select(
  6242. 'job_recruiting.id',
  6243. 'job_recruiting.title',
  6244. 'job_company.business_name',
  6245. 'income_enum.evalue as salary_evalue',
  6246. 'income_enum.ename as salary_ename',
  6247. 'years_enum.evalue as experience_evalue',
  6248. 'years_enum.ename as experience_ename',
  6249. 'job_recruiting.updated_at'
  6250. )
  6251. ->offset(($data['page'] - 1) * $data['pageSize'])
  6252. ->limit($data['pageSize'])
  6253. ->get()
  6254. ->all();
  6255. if (empty($job)) {
  6256. return Result::error("暂无招聘信息", 0);
  6257. }
  6258. $result = [
  6259. 'row' => $job,
  6260. 'count' => $count,
  6261. ];
  6262. return Result::success($result);
  6263. }
  6264. /*
  6265. * 获取企业会员-招聘信息列表
  6266. * */
  6267. public function getRecruitingInfo(array $data): array
  6268. {
  6269. $user = User::where('id', $data['user_id'])->first();
  6270. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6271. return Result::error("用户不存在", 0);
  6272. }
  6273. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6274. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6275. ->select(
  6276. 'job_recruiting.*',
  6277. 'job_company.business_name',
  6278. 'job_company.company_hy_id',
  6279. 'job_company.company_size',
  6280. 'job_company.company_nature',
  6281. 'job_company.introduction',
  6282. 'job_company.real_name',
  6283. 'job_company.mobile',
  6284. 'job_company.company_url',
  6285. 'job_company.address_arr_id',
  6286. 'job_company.address',
  6287. 'job_company.email'
  6288. )
  6289. ->get();
  6290. if (empty($recruiting)) {
  6291. return Result::error("暂无招聘信息", 0);
  6292. }
  6293. return Result::success($recruiting);
  6294. }
  6295. /*
  6296. * 获取企业会员-我的沟通
  6297. * */
  6298. public function getJobResumeList(array $data): array
  6299. {
  6300. $user = User::where('id', $data['user_id'])->first();
  6301. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6302. return Result::error("用户不存在", 0);
  6303. }
  6304. $where = [];
  6305. if (isset($data['salary']) && $data['salary'] != null) {
  6306. $where['job_hunting.salary'] = $data['salary'];
  6307. }
  6308. if (isset($data['user_name']) && $data['user_name'] != null) {
  6309. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6310. }
  6311. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6312. $query->where('job_resume.user_id', $user['id']);
  6313. })
  6314. ->when(!empty($where), function ($query) use ($where) {
  6315. $query->where($where);
  6316. })
  6317. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6318. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6319. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6320. ->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');
  6321. $count = $job->count();
  6322. if ($count == 0) {
  6323. return Result::error("暂无沟通记录", 0);
  6324. }
  6325. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6326. ->offset(($data['page'] - 1) * $data['pageSize'])
  6327. ->limit($data['pageSize'])
  6328. ->get();
  6329. if (empty($jobs)) {
  6330. return Result::error("暂无沟通记录", 0);
  6331. }
  6332. $result['row'] = $this->processJob($jobs, '');
  6333. $result['count'] = $count;
  6334. return Result::success($result);
  6335. }
  6336. public function readJobResume(array $data): array
  6337. {
  6338. $result = JobResume::where('id', $data['id'])->first();
  6339. if (empty($result)) {
  6340. return Result::error("查询失败", 0);
  6341. }
  6342. $result = JobResume::where('id', $data['id'])->update([
  6343. 'status' => 2,
  6344. ]);
  6345. return Result::success($result);
  6346. }
  6347. // 20250306 招聘
  6348. //20250422 书刊音像
  6349. public function addBook(array $data): array
  6350. {
  6351. $user_id = $data['user_id'] ?? 0;
  6352. $type_id = $data['type_id'] ?? 0;
  6353. // $website_id = $data['website_id'] ?? 0;
  6354. // unset($data['user_id']);
  6355. unset($data['type_id']);
  6356. // unset($data['website_id']);
  6357. //处理数组
  6358. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6359. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6360. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6361. if ($data['img_url'] == '') {
  6362. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6363. preg_match_all($reg, $data['detail'], $matches);
  6364. if (isset($matches[1][0])) {
  6365. //截取varchar240
  6366. $data['img_url'] = substr($matches[1][0], 0, 240);
  6367. }
  6368. }
  6369. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6370. //提取标题+内容中的关键词
  6371. $data['keyword'] = $data['title'];
  6372. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6373. Jieba::init(); // 初始化 jieba-php
  6374. Finalseg::init();
  6375. $segList = Jieba::cut($data['keyword']);
  6376. $segList1 = array_slice($segList, 0, 8);
  6377. $data['keyword'] = implode(',', $segList1);
  6378. }
  6379. if ($data['description'] == '') {
  6380. //提取内容中的描述
  6381. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6382. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6383. }
  6384. var_dump($data, '--');
  6385. if ($data['status'] == 1) {
  6386. $this->sendMessage([
  6387. 'talk_type' => 400,
  6388. 'title' => $data['title'],
  6389. 'content' => '提交了审核',
  6390. 'messageType' => 7,
  6391. ]);
  6392. }
  6393. $result = Book::insertGetId($data);
  6394. if (empty($result)) {
  6395. return Result::error("添加失败", 0);
  6396. }
  6397. return Result::success($result);
  6398. }
  6399. public function getBookList(array $data): array
  6400. {
  6401. $where = [];
  6402. if (!empty($data["title"])) {
  6403. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6404. }
  6405. if (!empty($data['website_name'])) {
  6406. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6407. }
  6408. if (!empty($data['status'])) {
  6409. $where[] = ['book.status', '=', $data['status']];
  6410. }
  6411. $user_id = $data['user_id'];
  6412. $type_id = $data['type_id'];
  6413. // $type_id = 4;
  6414. var_dump($type_id, '------1--------');
  6415. if ($type_id != 10000) {
  6416. $where[] = ['book.user_id', '=', $user_id];
  6417. }
  6418. var_dump(!empty($data['status1']), '=-===1');
  6419. $result = Book::where($where)
  6420. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6421. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6422. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6423. ->when(isset($data['status1']), function ($query) use ($data) {
  6424. $query->whereIn('book.status', [1, 3]);
  6425. })
  6426. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6427. ->orderBy("updated_at", "desc")
  6428. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6429. if (empty($result)) {
  6430. return Result::error("暂无数据", 0);
  6431. }
  6432. // 取出数据
  6433. $rows = $result->items();
  6434. $count = $result->total();
  6435. $responseData = [
  6436. 'rows' => $rows,
  6437. 'count' => $count,
  6438. ];
  6439. return Result::success($responseData);
  6440. }
  6441. public function deleteBook(array $data): array
  6442. {
  6443. $result = Book::where('id', $data['id'])->delete();
  6444. if (empty($result)) {
  6445. return Result::error("删除失败", 0);
  6446. }
  6447. return Result::success($result);
  6448. }
  6449. public function updateBook(array $data): array
  6450. {
  6451. // $user_id = $data['user_id'] ?? 0;
  6452. $type_id = $data['type_id'] ?? 0;
  6453. // $website_id = $data['website_id'] ?? 0;
  6454. unset($data['user_id']);
  6455. unset($data['type_id']);
  6456. // unset($data['website_id']);
  6457. //处理数组
  6458. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6459. if ($data['img_url'] == '') {
  6460. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6461. preg_match_all($reg, $data['detail'], $matches);
  6462. if (isset($matches[1][0])) {
  6463. //截取varchar240
  6464. $data['img_url'] = substr($matches[1][0], 0, 240);
  6465. }
  6466. }
  6467. if ($data['keyword'] == '') {
  6468. //提取标题+内容中的关键词
  6469. $data['keyword'] = $data['title'];
  6470. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6471. Jieba::init(); // 初始化 jieba-php
  6472. Finalseg::init();
  6473. $segList = Jieba::cut($data['keyword']);
  6474. $segList1 = array_slice($segList, 0, 8);
  6475. $data['keyword'] = implode(',', $segList1);
  6476. }
  6477. if ($data['description'] == '') {
  6478. //提取内容中的描述
  6479. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6480. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6481. }
  6482. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6483. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6484. if ($data['status'] == 1) {
  6485. $this->sendMessage([
  6486. 'talk_type' => 400,
  6487. 'title' => $data['title'],
  6488. 'content' => '提交了审核',
  6489. 'messageType' => 7,
  6490. ]);
  6491. }
  6492. $result = Book::where("id", $data["id"])->update($data);
  6493. if (empty($result)) {
  6494. return Result::error("更新失败", 0);
  6495. }
  6496. return Result::success($result);
  6497. }
  6498. public function getBookInfo(array $data): array
  6499. {
  6500. $result = Book::where("id", $data["id"])->first();
  6501. if (empty($result)) {
  6502. return Result::error("获取失败", 0);
  6503. }
  6504. return Result::success($result);
  6505. }
  6506. public function updateBookStatus(array $data): array
  6507. {
  6508. //审核
  6509. unset($data['user_id']);
  6510. $bookInfo = Book::where("id", $data["id"])->first();
  6511. var_dump($bookInfo, '----');
  6512. if ($data['status'] == 2) {
  6513. $this->sendMessage([
  6514. 'talk_type' => 401,
  6515. 'title' => $bookInfo['title'],
  6516. 'content' => '审核通过',
  6517. 'messageType' => 7,
  6518. 'user_id' => $bookInfo['user_id'],
  6519. ]);
  6520. }
  6521. if ($data['status'] == 3) {
  6522. $this->sendMessage([
  6523. 'talk_type' => 401,
  6524. 'title' => $bookInfo['title'],
  6525. 'content' => '审核拒绝',
  6526. 'messageType' => 7,
  6527. 'user_id' => $bookInfo['user_id'],
  6528. ]);
  6529. }
  6530. if ($data['status'] == 1) {
  6531. $this->sendMessage([
  6532. 'talk_type' => 400,
  6533. 'title' => $bookInfo['title'],
  6534. 'content' => '提交了审核',
  6535. 'messageType' => 7,
  6536. // 'user_id'=>$bookInfo['user_id'],
  6537. ]);
  6538. }
  6539. $result = Book::where("id", $data["id"])->update($data);
  6540. if (empty($result)) {
  6541. return Result::error("更新失败", 0);
  6542. }
  6543. return Result::success($result);
  6544. }
  6545. //20250422 书刊音像
  6546. /**
  6547. * 贴身宝贝
  6548. * @param array $data
  6549. * @return array
  6550. */
  6551. public function getWebsiteTsbb(array $data): array
  6552. {
  6553. $month = $data['month'] ?? date('m');
  6554. $day = $data['day'] ?? date('d');
  6555. // 使用缓存键
  6556. $cacheKey = "tsbb_data_{$month}_{$day}";
  6557. // 尝试从缓存获取数据
  6558. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6559. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6560. if ($cachedData = $cache->get($cacheKey)) {
  6561. return Result::success(unserialize($cachedData));
  6562. }
  6563. //查询老黄历
  6564. try {
  6565. $date = date('Y-m-d');
  6566. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6567. // 使用 curl 替代 file_get_contents
  6568. $ch = curl_init();
  6569. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6570. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6571. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6572. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6573. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6574. 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');
  6575. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6576. 'Accept: application/json',
  6577. 'Content-Type: application/json',
  6578. 'Referer: https://www.36jxs.com/'
  6579. ]);
  6580. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6581. curl_setopt($ch, CURLOPT_ENCODING, '');
  6582. $almanacResponse = curl_exec($ch);
  6583. var_dump("====:", $almanacResponse);
  6584. if (curl_errno($ch)) {
  6585. var_dump('Curl error:', curl_error($ch));
  6586. throw new \Exception('Curl error: ' . curl_error($ch));
  6587. }
  6588. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6589. curl_close($ch);
  6590. if ($almanacResponse === false) {
  6591. throw new \Exception('Failed to fetch almanac data');
  6592. }
  6593. $almanacData = json_decode($almanacResponse, true);
  6594. if (json_last_error() !== JSON_ERROR_NONE) {
  6595. throw new \Exception('Failed to parse almanac data');
  6596. }
  6597. $almanacInfo = $almanacData['data'] ?? [];
  6598. } catch (\Exception $e) {
  6599. var_dump('Exception:', $e->getMessage());
  6600. $almanacInfo = [];
  6601. }
  6602. // 获取历史上的今天数据
  6603. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6604. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6605. ->orderBy('year', 'asc')
  6606. ->select("title", "id", "year", DB::raw('1 as type'))
  6607. ->limit(16)
  6608. ->get();
  6609. // 获取节日数据 - 从今天开始获取未来4条
  6610. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6611. ->orderBy('showtime', 'asc')
  6612. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6613. ->limit(16)
  6614. ->get();
  6615. //说文解字
  6616. $chartacterList = Character::orderBy('updated_at', 'desc')
  6617. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6618. ->limit(6)
  6619. ->get();
  6620. //谜语沙龙
  6621. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6622. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6623. ->limit(4)
  6624. ->get();
  6625. //成语欣赏
  6626. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6627. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6628. ->limit(32)
  6629. ->get();
  6630. //名联赏析
  6631. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6632. ->select("id", "first", "second", DB::raw('6 as type'))
  6633. ->limit(6)
  6634. ->get();
  6635. // 获取分类文章数据
  6636. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6637. ->pluck('category_id')
  6638. ->toArray();
  6639. $articlesList = [];
  6640. foreach ($categoryIds as $catid) {
  6641. // 先查有图片的
  6642. $withImg = DB::table('article')
  6643. ->where('status', 1)
  6644. ->where('catid', $catid)
  6645. ->whereNotNull('imgurl')
  6646. ->where('imgurl', '!=', '')
  6647. ->orderBy('updated_at', 'desc')
  6648. ->limit(6)
  6649. ->get();
  6650. $count = $withImg->count();
  6651. if ($count < 6) {
  6652. // 不足6条再查无图片的补足
  6653. $withoutImg = DB::table('article')
  6654. ->where('status', 1)
  6655. ->where('catid', $catid)
  6656. ->where(function ($q) {
  6657. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6658. })
  6659. ->orderBy('updated_at', 'desc')
  6660. ->limit(6 - $count)
  6661. ->get();
  6662. $articles = $withImg->concat($withoutImg);
  6663. } else {
  6664. $articles = $withImg;
  6665. }
  6666. // 组装
  6667. $category = \App\Model\Category::find($catid);
  6668. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6669. $articlesList[] = [
  6670. 'category_name' => $category ? $category->name : '',
  6671. 'catid' => $catid,
  6672. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6673. 'type' => 100,
  6674. 'list' => $articles->map(function ($item) {
  6675. return [
  6676. 'id' => $item->id,
  6677. 'title' => $item->title,
  6678. 'imgurl' => $item->imgurl,
  6679. 'created_at' => $item->created_at
  6680. ];
  6681. })->values()
  6682. ];
  6683. }
  6684. $result = [
  6685. 'almanac' => $almanacInfo,
  6686. 'historyTodayList' => [
  6687. 'category_name' => '历史上的今天',
  6688. 'list' => $historyTodayList,
  6689. 'type' => 1
  6690. ],
  6691. 'festivalList' => [
  6692. 'category_name' => '节日预告',
  6693. 'list' => $festivalList,
  6694. 'type' => 2
  6695. ],
  6696. 'chartacterList' => [
  6697. 'category_name' => '说文解字',
  6698. 'list' => $chartacterList,
  6699. 'type' => 3
  6700. ],
  6701. 'coupletList' => [
  6702. 'category_name' => '名联赏析',
  6703. 'list' => $coupletList,
  6704. 'type' => 6
  6705. ],
  6706. 'riddletList' => [
  6707. 'category_name' => '谜语沙龙',
  6708. 'list' => $riddletList,
  6709. 'type' => 4
  6710. ],
  6711. 'idiomList' => [
  6712. 'category_name' => '成语欣赏',
  6713. 'list' => $idiomList,
  6714. 'type' => 5
  6715. ],
  6716. 'articlesList' => $articlesList
  6717. ];
  6718. // 缓存结果,设置1小时过期
  6719. $cache->set($cacheKey, serialize($result), 3600);
  6720. return Result::success($result);
  6721. }
  6722. /**
  6723. * 获取资讯列表
  6724. */
  6725. public function getWebsiteTsbbList(array $data): array
  6726. {
  6727. $page = $data['page'] ?? 1;
  6728. $pageSize = $data['pageSize'] ?? 10;
  6729. // 如果没有传入月份和日期,则使用今天的日期
  6730. $month = $data['month'] ?? date('m');
  6731. $day = $data['day'] ?? date('d');
  6732. $total = 0;
  6733. $result = [];
  6734. $data['type'] = intval($data['type']);
  6735. var_dump("接收参数:", $data);
  6736. switch ($data['type']) {
  6737. case 1:
  6738. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6739. // 当前月份之后的数据
  6740. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6741. // 或者当前月份且日期大于等于当前日期的数据
  6742. ->orWhere(function ($q) use ($month, $day) {
  6743. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6744. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6745. });
  6746. })
  6747. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6748. $total = $query->count();
  6749. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6750. ->offset(($page - 1) * $pageSize)
  6751. ->limit($pageSize)
  6752. ->get();
  6753. break;
  6754. case 2:
  6755. $query = Festival::where(function ($q) use ($month, $day) {
  6756. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6757. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6758. ->orWhere(function ($q) use ($month, $day) {
  6759. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6760. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6761. });
  6762. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6763. $total = $query->count();
  6764. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6765. ->offset(($page - 1) * $pageSize)
  6766. ->limit($pageSize)
  6767. ->get();
  6768. break;
  6769. case 3:
  6770. $query = Character::orderBy("updated_at", "desc");
  6771. $total = $query->count();
  6772. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6773. ->offset(($page - 1) * $pageSize)
  6774. ->limit($pageSize)
  6775. ->get();
  6776. break;
  6777. case 4:
  6778. $query = Riddle::orderBy("updated_at", "desc");
  6779. $total = $query->count();
  6780. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6781. ->offset(($page - 1) * $pageSize)
  6782. ->limit($pageSize)
  6783. ->get();
  6784. break;
  6785. case 5:
  6786. $query = Idiom::orderBy("updated_at", "desc");
  6787. $total = $query->count();
  6788. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6789. ->offset(($page - 1) * $pageSize)
  6790. ->limit($pageSize)
  6791. ->get();
  6792. break;
  6793. case 6:
  6794. $query = Couplet::orderBy("updated_at", "desc");
  6795. $total = $query->count();
  6796. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6797. ->offset(($page - 1) * $pageSize)
  6798. ->limit($pageSize)
  6799. ->get();
  6800. break;
  6801. default:
  6802. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6803. $total = $query->count();
  6804. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6805. ->offset(($page - 1) * $pageSize)
  6806. ->limit($pageSize)
  6807. ->get();
  6808. }
  6809. return Result::success([
  6810. 'list' => $result,
  6811. 'total' => $total,
  6812. 'page' => (int)$page,
  6813. 'pageSize' => (int)$pageSize,
  6814. 'month' => $month,
  6815. 'day' => $day
  6816. ]);
  6817. }
  6818. /**
  6819. * 1:历史上的今天
  6820. * 2:节日
  6821. * 3:文章
  6822. *
  6823. * 资讯详情信息
  6824. */
  6825. public function getWebsiteTsbbDetail(array $data): array
  6826. {
  6827. $data['type'] = intval($data['type']);
  6828. switch ($data['type']) {
  6829. case 1:
  6830. $result = HistoryToday::where("id", $data['id'])->first();
  6831. break;
  6832. case 2:
  6833. $result = Festival::where("id", $data['id'])->first();
  6834. break;
  6835. case 3:
  6836. $result = Character::where("id", $data['id'])->first();
  6837. break;
  6838. case 4:
  6839. $result = Riddle::where("id", $data['id'])->first();
  6840. break;
  6841. case 5:
  6842. $result = Idiom::where("id", $data['id'])->first();
  6843. break;
  6844. case 6:
  6845. $result = Couplet::where("id", $data['id'])->first();
  6846. break;
  6847. default:
  6848. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6849. break;
  6850. }
  6851. return Result::success($result);
  6852. }
  6853. /**
  6854. * 农网导航首页数据
  6855. */
  6856. public function getWebsiteNwHomeList(array $data): array
  6857. {
  6858. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6859. ->pluck('category_id')
  6860. ->toArray();
  6861. // 使用子查询优化
  6862. $articlesList = DB::table('article')
  6863. ->select([
  6864. 'article.id',
  6865. 'article.title',
  6866. 'article.imgurl',
  6867. 'article.created_at',
  6868. 'category.name as category_name',
  6869. 'category.id as category_id',
  6870. 'website_category.aLIas_pinyin as pinyin',
  6871. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6872. DB::raw('100 as type')
  6873. ])
  6874. ->join('category', 'article.catid', '=', 'category.id')
  6875. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6876. ->leftJoin('website_category as parent_wc', function ($join) {
  6877. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6878. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6879. })
  6880. ->where('website_category.website_id', $data['website_id'])
  6881. ->where('article.status', 1)
  6882. ->whereIn('category.id', $categoryIds)
  6883. ->orderBy('article.created_at', 'desc')
  6884. ->get()
  6885. ->groupBy('category_id')
  6886. ->map(function ($group) {
  6887. // 确保第一条数据有图片
  6888. $firstWithImage = $group->first(function ($item) {
  6889. return !empty($item->imgurl);
  6890. });
  6891. if ($firstWithImage) {
  6892. // 如果有带图片的文章,将其放在第一位
  6893. $group = $group->filter(function ($item) use ($firstWithImage) {
  6894. return $item->id !== $firstWithImage->id;
  6895. })->prepend($firstWithImage);
  6896. }
  6897. return [
  6898. 'category_name' => $group->first()->category_name,
  6899. 'catid' => $group->first()->category_id,
  6900. 'pinyin' => $group->first()->pinyin,
  6901. 'parent_pinyin' => $group->first()->parent_pinyin,
  6902. 'list' => $group->take(4)->map(function ($item) {
  6903. return [
  6904. 'id' => $item->id,
  6905. 'title' => $item->title,
  6906. ];
  6907. })->values()
  6908. ];
  6909. })
  6910. ->values()
  6911. ->toArray();
  6912. return Result::success($articlesList);
  6913. }
  6914. /**
  6915. * 企业管理
  6916. * @param array $data
  6917. * @return array
  6918. */
  6919. public function getCompanyList(array $data): array
  6920. {
  6921. // return Result::success($data);
  6922. $where = [];
  6923. $user = User::where('id', $data['user_id'])->first();
  6924. if (empty($user)) {
  6925. return Result::error('用户不存在!');
  6926. }
  6927. if ($user['type_id'] != 10000) {
  6928. $where['user_id'] = $data['user_id'];
  6929. }
  6930. if (isset($data['title']) && !empty($data['title'])) {
  6931. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6932. }
  6933. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6934. array_push($where, ['website.id', $data['website_id']]);
  6935. }
  6936. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6937. if ($data['ischeck'] == 1) {
  6938. if (isset($data['status']) && $data['status'] != '') {
  6939. array_push($where, ['company.status', $data['status']]);
  6940. $query = Company::where($where);
  6941. } else {
  6942. $query = Company::whereIn('company.status', [0, 2]);
  6943. }
  6944. } else {
  6945. $query = Company::where('company.status', 1);
  6946. }
  6947. }
  6948. $result = $query->where($where)
  6949. ->leftJoin('website_category', function ($query) {
  6950. $query->on('website_category.category_id', '=', 'company.category_id')
  6951. ->on('website_category.website_id', '=', 'company.website_id');
  6952. })
  6953. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6954. ->select(
  6955. 'company.id',
  6956. 'company.title',
  6957. 'company.website_id',
  6958. 'company.category_id',
  6959. 'website.website_name',
  6960. 'website_category.alias as category_name',
  6961. 'company.status',
  6962. 'company.updated_at',
  6963. 'company.user_id'
  6964. )
  6965. ->orderBy('company.updated_at', 'desc')
  6966. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6967. if ($result->isEmpty()) {
  6968. return Result::error("暂无企业", 0);
  6969. }
  6970. return Result::success($result);
  6971. }
  6972. /**
  6973. * 添加企业
  6974. * @param array $data
  6975. * @return array
  6976. */
  6977. public function addCompany(array $data): array
  6978. {
  6979. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6980. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6981. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6982. $data['cat_arr_id'] = json_encode($car_arr_id);
  6983. } else {
  6984. $data['cat_arr_id'] = '';
  6985. }
  6986. if ($data['imgurl'] == '') {
  6987. //content中提取图片第一个图,正则提取
  6988. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6989. preg_match_all($reg, $data['content'], $matches);
  6990. if (isset($matches[1][0])) {
  6991. //截取varchar240
  6992. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6993. }
  6994. }
  6995. if ($data['keyword'] == '') {
  6996. //提取标题+内容中的关键词
  6997. $data['keyword'] = $data['title'];
  6998. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6999. Jieba::init(); // 初始化 jieba-php
  7000. Finalseg::init();
  7001. $segList = Jieba::cut($data['keyword']);
  7002. $segList1 = array_slice($segList, 0, 8);
  7003. $data['keyword'] = implode(',', $segList1);
  7004. }
  7005. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7006. //提取内容中的描述
  7007. $content = $data['content'];
  7008. // 去除 <style> 和 <script> 标签及其内容
  7009. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7010. // 去除所有 HTML 标签
  7011. $content = strip_tags($content);
  7012. // 去除 HTML 实体
  7013. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7014. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7015. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7016. // 去除多余空白
  7017. $content = preg_replace('/\s+/u', '', $content);
  7018. // 截取 100 个字符
  7019. $data['introduce'] = mb_substr($content, 0, 100);
  7020. }
  7021. $user = User::where('id', $data['user_id'])->first();
  7022. if (empty($user)) {
  7023. return Result::error('用户不存在!');
  7024. }
  7025. if ($user['type_id'] == 10000) {
  7026. $data['status'] = 1;
  7027. }
  7028. if (isset($data['level']) && $data['level'] != null) {
  7029. $data['level'] = intval($data['level']);
  7030. } else {
  7031. $data['level'] = null;
  7032. }
  7033. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7034. $this->sendMessage([
  7035. 'talk_type' => 900,
  7036. 'title' => $data['title'],
  7037. 'content' => '提交了审核',
  7038. 'messageType' => 8,
  7039. ]);
  7040. }
  7041. $result = Company::insertGetId($data);
  7042. if ($result) {
  7043. return Result::success($result);
  7044. } else {
  7045. return Result::error('添加失败');
  7046. }
  7047. }
  7048. /**
  7049. * 更新企业
  7050. * @param array $data
  7051. * @return array
  7052. */
  7053. public function upCompany(array $data): array
  7054. {
  7055. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7056. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7057. $data['cat_arr_id'] = json_encode($car_arr_id);
  7058. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7059. } else {
  7060. $data['cat_arr_id'] = '';
  7061. }
  7062. if ($data['imgurl'] == '') {
  7063. //content中提取图片第一个图,正则提取
  7064. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7065. preg_match_all($reg, $data['content'], $matches);
  7066. if (isset($matches[1][0])) {
  7067. //截取varchar
  7068. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7069. }
  7070. }
  7071. if ($data['keyword'] == '') {
  7072. //提取标题+内容中的关键词
  7073. $data['keyword'] = $data['title'];
  7074. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7075. Jieba::init(); // 初始化 jieba-php
  7076. Finalseg::init();
  7077. $segList = Jieba::cut($data['keyword']);
  7078. $segList1 = array_slice($segList, 0, 8);
  7079. $data['keyword'] = implode(',', $segList1);
  7080. }
  7081. if ($data['introduce'] == '') {
  7082. //提取内容中的描述
  7083. $content = $data['content'];
  7084. // 去除 <style> 和 <script> 标签及其内容
  7085. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7086. // 去除所有 HTML 标签
  7087. $content = strip_tags($content);
  7088. // 去除 HTML 实体
  7089. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7090. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7091. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7092. // 去除多余空白
  7093. $content = preg_replace('/\s+/u', '', $content);
  7094. // 截取 100 个字符
  7095. $data['introduce'] = mb_substr($content, 0, 100);
  7096. }
  7097. if (isset($data['level']) && $data['level'] != null) {
  7098. $data['level'] = intval($data['level']);
  7099. } else {
  7100. $data['level'] = null;
  7101. }
  7102. $user = User::where('id', $data['user_id'])->first();
  7103. if (empty($user)) {
  7104. return Result::error('用户不存在!');
  7105. }
  7106. if ($user['type_id'] == 10000) {
  7107. $data['status'] = 1;
  7108. } else {
  7109. $data['status'] = 0;
  7110. }
  7111. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7112. $this->sendMessage([
  7113. 'talk_type' => 900,
  7114. 'title' => $data['title'],
  7115. 'content' => '提交了审核',
  7116. 'messageType' => 8,
  7117. ]);
  7118. }
  7119. $result = Company::where('id', $data['id'])->update($data);
  7120. if ($result) {
  7121. return Result::success($result);
  7122. } else {
  7123. return Result::error('修改失败');
  7124. }
  7125. }
  7126. /**
  7127. * 删除企业
  7128. * @param array $data
  7129. * @return array
  7130. */
  7131. public function delCompany(array $data): array
  7132. {
  7133. $result = Company::where('id', $data['id'])->delete();
  7134. if ($result) {
  7135. return Result::success($result);
  7136. } else {
  7137. return Result::error('删除失败');
  7138. }
  7139. }
  7140. /**
  7141. * 审核企业
  7142. * @param array $data
  7143. * @return array
  7144. */
  7145. public function checkCompany(array $data): array
  7146. {
  7147. $user = User::where('id', $data['user_id'])->first();
  7148. if (empty($user)) {
  7149. return Result::error('用户不存在!');
  7150. }
  7151. $company = Company::where('id', $data['id'])->first();
  7152. if (empty($company)) {
  7153. return Result::error('企业不存在!');
  7154. }
  7155. // 状态:0:未审核 1:已审核 2:已拒绝
  7156. if ($data['status'] == 2 || $data['status'] == '2') {
  7157. $this->sendMessage([
  7158. 'talk_type' => 901,
  7159. 'title' => $company['title'],
  7160. 'content' => '审核拒绝',
  7161. 'messageType' => 8,
  7162. 'user_id' => $company['user_id'],
  7163. ]);
  7164. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7165. } else {
  7166. if ($data['status'] == 1) {
  7167. $this->sendMessage([
  7168. 'talk_type' => 901,
  7169. 'title' => $company['title'],
  7170. 'content' => '审核通过',
  7171. 'messageType' => 8,
  7172. 'user_id' => $company['user_id'],
  7173. ]);
  7174. } else if ($data['status'] == 0) {
  7175. $this->sendMessage([
  7176. 'talk_type' => 900,
  7177. 'title' => $company['title'],
  7178. 'content' => '提交了审核',
  7179. 'messageType' => 8,
  7180. ]);
  7181. }
  7182. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7183. }
  7184. if (empty($result)) {
  7185. return Result::error('审核失败!');
  7186. } else {
  7187. return Result::success($result);
  7188. }
  7189. }
  7190. /**
  7191. * 获取企业信息
  7192. * @param array $data
  7193. * @return array
  7194. */
  7195. public function getCompanyInfo(array $data): array
  7196. {
  7197. $result = Company::where('id', $data['id'])->first();
  7198. $city_arr = json_decode($result['city_arr_id']);
  7199. $result['city_name'] = District::whereIn('id', $city_arr)
  7200. ->pluck('name')
  7201. ->implode('-');
  7202. if (empty($result)) {
  7203. return Result::error('企业不存在!');
  7204. } else {
  7205. return Result::success($result);
  7206. }
  7207. }
  7208. /**
  7209. * @param array $data
  7210. * @return array
  7211. */
  7212. public function getWebsiteCompany(array $data): array
  7213. {
  7214. $categorys = json_decode($data['id'], true);
  7215. $category_arr = $this->processArticlePro($data['website_id']);
  7216. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7217. $catiall = $category_arr['catiall'];
  7218. $categoryIds = $category_arr['categoryIds'];
  7219. // return Result::success($category_arr);
  7220. foreach ($categorys as $key => $value) {
  7221. if (array_key_exists('level', $value)) {
  7222. $parts = explode(',', $value['level']);
  7223. $level = $parts[0] ?? null;
  7224. $imgnum = $parts[1] ?? null;
  7225. $textnum = $parts[2] ?? null;
  7226. if (!empty($textnum) && $textnum > 0) {
  7227. $text_num = Company::where('level', $level)
  7228. ->whereIn('category_id', $categoryIds)
  7229. ->where('status', 1)
  7230. ->select(
  7231. 'company.id',
  7232. 'company.title',
  7233. 'company.description',
  7234. 'company.updated_at',
  7235. 'company.category_id',
  7236. 'company.cat_arr_id'
  7237. )
  7238. ->orderBy('updated_at', 'desc')
  7239. ->limit($textnum)
  7240. ->get()->all();
  7241. }
  7242. if (!empty($imgnum) && $imgnum > 0) {
  7243. $img_num = Company::where('level', $level)
  7244. ->whereIn('category_id', $categoryIds)
  7245. ->where('status', 1)
  7246. ->where('imgurl', '!=', '')
  7247. ->whereNotNull('imgurl')
  7248. ->select(
  7249. 'company.id',
  7250. 'company.title',
  7251. 'company.description',
  7252. 'company.updated_at',
  7253. 'company.imgurl as imgs',
  7254. 'company.category_id',
  7255. 'company.cat_arr_id'
  7256. )
  7257. ->orderBy('updated_at', 'desc')
  7258. ->limit($imgnum)
  7259. ->get()->all();
  7260. }
  7261. }
  7262. if (array_key_exists('id', $value)) {
  7263. $parts = explode(',', $value['id']);
  7264. $category_id = $parts[0] ?? null;
  7265. $imgnum = $parts[1] ?? null;
  7266. $textnum = $parts[2] ?? null;
  7267. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7268. if (!empty($textnum) && $textnum > 0) {
  7269. $text_num = Company::whereIn('category_id', $category_arr)
  7270. // ->where('website_id', $data['website_id'])
  7271. ->where('status', 1)
  7272. ->select(
  7273. 'company.id',
  7274. 'company.title',
  7275. 'company.description',
  7276. 'company.updated_at',
  7277. 'company.category_id',
  7278. 'company.cat_arr_id'
  7279. )
  7280. ->orderBy('updated_at', 'desc')
  7281. ->limit($textnum)
  7282. ->get()->all();
  7283. }
  7284. if (!empty($imgnum) && $imgnum > 0) {
  7285. $img_num = Company::whereIn('category_id', $category_arr)
  7286. // ->where('website_id', $data['website_id'])
  7287. ->where('status', 1)
  7288. ->where('imgurl', '!=', '')
  7289. ->whereNotNull('imgurl')
  7290. ->select(
  7291. 'company.id',
  7292. 'company.title',
  7293. 'company.description',
  7294. 'company.updated_at',
  7295. 'company.imgurl as imgs',
  7296. 'company.category_id',
  7297. 'company.cat_arr_id'
  7298. )
  7299. ->orderBy('updated_at', 'desc')
  7300. ->limit($imgnum)
  7301. ->get()->all();
  7302. }
  7303. }
  7304. if (!empty($text_num)) {
  7305. foreach ($text_num as $k => $v) {
  7306. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7307. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7308. }
  7309. }
  7310. if (!empty($img_num)) {
  7311. foreach ($img_num as $k => $v) {
  7312. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7313. $imgurl = json_decode($v['imgs'], true);
  7314. if (!empty($imgurl)) {
  7315. $img_num[$k]->imgurl = $imgurl[0];
  7316. }
  7317. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7318. }
  7319. }
  7320. $company[$key]['img_num'] = $img_num ?? [];
  7321. $company[$key]['text_num'] = $text_num ?? [];
  7322. }
  7323. if (empty($company)) {
  7324. return Result::error("暂无相关企业信息", 0);
  7325. }
  7326. return Result::success($company);
  7327. }
  7328. /**
  7329. * @param array $data
  7330. * @return array
  7331. */
  7332. public function getWebsiteCompanyList(array $data): array
  7333. {
  7334. $where['website_id'] = $data['website_id'];
  7335. $where['status'] = 1;
  7336. $categoryIds = [];
  7337. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7338. $category_id = $data['category_id'];
  7339. }
  7340. $category_arr = $this->processArticlePro($data['website_id']);
  7341. $categoryIds = $category_arr['categoryIds'];
  7342. // return Result::success($cat_1st_arr);
  7343. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7344. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7345. })
  7346. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7347. $query->whereIn('category_id', $categoryIds);
  7348. })
  7349. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7350. $query->where('category_id', $category_id);
  7351. })
  7352. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7353. ->orderBy('updated_at', 'desc')
  7354. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7355. if (empty($company)) {
  7356. return Result::error("暂无相关公司信息", 0);
  7357. }
  7358. $result = [
  7359. 'count' => $company->total(),
  7360. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7361. ];
  7362. return Result::success($result);
  7363. }
  7364. /**
  7365. * 获取项目列表
  7366. * @param array $data
  7367. * @return array
  7368. */
  7369. public function getProjectList(array $data): array
  7370. {
  7371. $where = [];
  7372. $user = User::where('id', $data['user_id'])->first();
  7373. if (empty($user)) {
  7374. return Result::error('用户不存在!');
  7375. }
  7376. if ($user->type_id != 10000) {
  7377. array_push($where, ['project.user_id', $data['user_id']]);
  7378. }
  7379. $query = Project::query();
  7380. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7381. array_push($where, ['project.website_id', $data['website_id']]);
  7382. }
  7383. if (isset($data['title']) && !empty($data['title'])) {
  7384. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7385. }
  7386. if ($data['status'] != 3) {
  7387. array_push($where, ['project.status', $data['status']]);
  7388. }
  7389. $query = Project::where($where)
  7390. ->when($data['status'] == 3, function ($query) {
  7391. $query->whereIn('project.status', [0, 2]);
  7392. });
  7393. $count = $query->clone()
  7394. ->count();
  7395. $rows = $query->clone()
  7396. ->leftJoin('website', 'project.website_id', 'website.id')
  7397. ->leftJoin('website_category', function ($join) {
  7398. $join->on('project.website_id', '=', 'website_category.website_id')
  7399. ->on('project.category_id', '=', 'website_category.category_id');
  7400. })
  7401. ->select(
  7402. 'project.id',
  7403. 'project.title',
  7404. 'project.updated_at',
  7405. 'project.status',
  7406. 'website.website_name',
  7407. 'website_category.alias as category_name',
  7408. 'project.website_id',
  7409. 'project.user_id'
  7410. )
  7411. ->orderBy('project.updated_at', 'desc')
  7412. ->offset(($data['page'] - 1) * $data['pageSize'])
  7413. ->limit($data['pageSize'])
  7414. ->get();
  7415. if ($rows->isEmpty()) {
  7416. return Result::error("暂无相关项目信息", 0);
  7417. }
  7418. $result = [
  7419. 'count' => $count,
  7420. 'rows' => $rows,
  7421. ];
  7422. return Result::success($result);
  7423. }
  7424. /**
  7425. * 添加项目
  7426. * @param array $data
  7427. * @return array
  7428. */
  7429. public function addProject(array $data): array
  7430. {
  7431. $user = User::where('id', $data['user_id'])->first();
  7432. if (empty($user)) {
  7433. return Result::error("暂无相关用户信息", 0);
  7434. }
  7435. if ($user->type_id == 10000) {
  7436. $data['status'] = 1;
  7437. } else {
  7438. $data['status'] = 0;
  7439. }
  7440. if ($data['keyword'] == '') {
  7441. //提取标题+内容中的关键词
  7442. $data['keyword'] = $data['title'];
  7443. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7444. Jieba::init(); // 初始化 jieba-php
  7445. Finalseg::init();
  7446. $segList = Jieba::cut($data['keyword']);
  7447. $segList1 = array_slice($segList, 0, 8);
  7448. $data['keyword'] = implode(',', $segList1);
  7449. }
  7450. if ($data['description'] == '') {
  7451. //提取内容中的描述
  7452. // var_dump(11111);
  7453. //提取内容中的描述
  7454. $content = $data['introduce'];
  7455. // 去除 <style> 和 <script> 标签及其内容
  7456. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7457. // 去除所有 HTML 标签
  7458. $content = strip_tags($content);
  7459. // 去除 HTML 实体
  7460. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7461. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7462. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7463. // 去除多余空白
  7464. $content = preg_replace('/\s+/u', '', $content);
  7465. // 截取 100 个字符
  7466. $data['description'] = mb_substr($content, 0, 100);
  7467. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7468. }
  7469. if ($data['status'] == 0) {
  7470. $this->sendMessage([
  7471. 'talk_type' => 1000,
  7472. 'title' => $data['title'],
  7473. 'content' => '提交了审核',
  7474. 'messageType' => 9,
  7475. ]);
  7476. }
  7477. $project = Project::insertGetId($data);
  7478. if (empty($project)) {
  7479. return Result::error("暂无相关项目信息", 0);
  7480. }
  7481. return Result::success($project);
  7482. }
  7483. /**
  7484. * 更新项目
  7485. * @param array $data
  7486. * @return array
  7487. */
  7488. public function upProject(array $data): array
  7489. {
  7490. $project = Project::where('id', $data['id'])->first();
  7491. if (empty($project)) {
  7492. return Result::error("暂无相关项目信息", 0);
  7493. }
  7494. $id = $data['id'];
  7495. unset($data['id']);
  7496. $user = User::where('id', $data['user_id'])->first();
  7497. if (empty($user)) {
  7498. return Result::error("暂无相关用户信息", 0);
  7499. }
  7500. if ($user->type_id == 10000) {
  7501. $data['status'] = 1;
  7502. } else {
  7503. $data['status'] = 0;
  7504. }
  7505. unset($data['user_id']);
  7506. if ($data['keyword'] == '') {
  7507. //提取标题+内容中的关键词
  7508. $data['keyword'] = $data['title'];
  7509. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7510. Jieba::init(); // 初始化 jieba-php
  7511. Finalseg::init();
  7512. $segList = Jieba::cut($data['keyword']);
  7513. $segList1 = array_slice($segList, 0, 8);
  7514. $data['keyword'] = implode(',', $segList1);
  7515. }
  7516. if ($data['description'] == '') {
  7517. //提取内容中的描述
  7518. // var_dump(11111);
  7519. //提取内容中的描述
  7520. $content = $data['introduce'];
  7521. // 去除 <style> 和 <script> 标签及其内容
  7522. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7523. // 去除所有 HTML 标签
  7524. $content = strip_tags($content);
  7525. // 去除 HTML 实体
  7526. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7527. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7528. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7529. // 去除多余空白
  7530. $content = preg_replace('/\s+/u', '', $content);
  7531. // 截取 100 个字符
  7532. $data['description'] = mb_substr($content, 0, 100);
  7533. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7534. }
  7535. if ($data['status'] == 0) {
  7536. $this->sendMessage([
  7537. 'talk_type' => 1000,
  7538. 'title' => $data['title'],
  7539. 'content' => '提交了审核',
  7540. 'messageType' => 9,
  7541. ]);
  7542. }
  7543. $result = Project::where('id', $id)->update($data);
  7544. if (empty($result)) {
  7545. return Result::error("更新失败", 0);
  7546. }
  7547. return Result::success($result);
  7548. }
  7549. /**
  7550. * 删除项目
  7551. * @param array $data
  7552. * @return array
  7553. */
  7554. public function delProject(array $data): array
  7555. {
  7556. $user = User::where('id', $data['user_id'])->first();
  7557. if (empty($user)) {
  7558. return Result::error("暂无相关用户信息", 0);
  7559. }
  7560. $project = Project::where('id', $data['id'])->first();
  7561. if (empty($project)) {
  7562. return Result::error("暂无相关项目信息", 0);
  7563. }
  7564. $result = Project::where('id', $data['id'])->delete();
  7565. if (empty($result)) {
  7566. return Result::error("删除失败", 0);
  7567. }
  7568. return Result::success($result);
  7569. }
  7570. /**
  7571. * 审核项目
  7572. * @param array $data
  7573. * @return array
  7574. */
  7575. public function checkProject(array $data): array
  7576. {
  7577. $user = User::where('id', $data['user_id'])->first();
  7578. if (empty($user)) {
  7579. return Result::error("暂无相关用户信息", 0);
  7580. }
  7581. // 0:未审核; 1:已审核; 2:已拒绝;
  7582. if ($user->type_id != 10000) {
  7583. if ($data['status'] == 1 || $data['status'] == 2) {
  7584. return Result::error("此用户权限不足", 0);
  7585. }
  7586. }
  7587. $project = Project::where('id', $data['id'])->first();
  7588. if (empty($project)) {
  7589. return Result::error("暂无相关项目信息", 0);
  7590. }
  7591. if ($data['status'] == 2) {
  7592. $this->sendMessage([
  7593. 'talk_type' => 1001,
  7594. 'title' => $project['title'],
  7595. 'content' => '审核拒绝',
  7596. 'messageType' => 9,
  7597. 'user_id' => $project['user_id'],
  7598. ]);
  7599. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7600. } else {
  7601. if ($data['status'] == 1) {
  7602. $this->sendMessage([
  7603. 'talk_type' => 1001,
  7604. 'title' => $project['title'],
  7605. 'content' => '审核通过',
  7606. 'messageType' => 9,
  7607. 'user_id' => $project['user_id'],
  7608. ]);
  7609. } else if ($data['status'] == 0) {
  7610. $this->sendMessage([
  7611. 'talk_type' => 1000,
  7612. 'title' => $project['title'],
  7613. 'content' => '提交了审核',
  7614. 'messageType' => 9,
  7615. ]);
  7616. }
  7617. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7618. }
  7619. if (empty($result)) {
  7620. return Result::error("审核失败", 0);
  7621. }
  7622. return Result::success($result);
  7623. }
  7624. /**
  7625. * 获取项目详情
  7626. * @param array $data
  7627. * @return array
  7628. */
  7629. public function getProjectInfo(array $data): array
  7630. {
  7631. $project = Project::where('id', $data['id'])->first();
  7632. if (empty($project)) {
  7633. return Result::error("暂无相关项目信息", 0);
  7634. }
  7635. return Result::success($project);
  7636. }
  7637. public function getWebsiteCompanyInfo(array $data): array
  7638. {
  7639. $company = Company::where('id', $data['id'])
  7640. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7641. ->where('status', 1)
  7642. // ->where('website_id', $data['website_id'])
  7643. ->select('company.*', 'job_industry.hyname as hy_name')
  7644. ->first();
  7645. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7646. switch ($company->jobnature_id) {
  7647. case null:
  7648. $company->jobnature_name = '';
  7649. break;
  7650. case 0:
  7651. $company->jobnature_name = '市场监督';
  7652. break;
  7653. case 1:
  7654. $company->jobnature_name = '信访纪检';
  7655. break;
  7656. case 2:
  7657. $company->jobnature_name = '公检法司';
  7658. break;
  7659. case 3:
  7660. $company->jobnature_name = '高关注机构';
  7661. break;
  7662. default:
  7663. $company->jobnature_name = '';
  7664. break;
  7665. }
  7666. $city_arr = $company->city_arr_id;
  7667. if (!empty($city_arr)) {
  7668. $city_arr = json_decode($city_arr, true);
  7669. $cityNames = District::whereIn('id', $city_arr)
  7670. ->pluck('name')
  7671. ->implode('-');
  7672. $company->city_name = $cityNames;
  7673. } else {
  7674. $company->city_name = '';
  7675. }
  7676. if (empty($company)) {
  7677. return Result::error("暂无相关公司信息", 0);
  7678. }
  7679. return Result::success($company);
  7680. }
  7681. public function getMSG(array $data): array
  7682. {
  7683. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7684. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7685. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7686. $result = [];
  7687. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7688. //最近的5篇已审的文章
  7689. $apply_articale = Article::where('status', 1)
  7690. ->where('admin_user_id', $user_id)
  7691. ->orderBy('updated_at', 'desc')
  7692. // ->limit(5)
  7693. ->get();
  7694. //获取5条用户的已审核商品
  7695. $good = Good::where('status', 2)
  7696. ->where('user_id', $user_id)
  7697. ->orderBy('updated_at', 'desc')
  7698. // ->limit(5)
  7699. ->get();
  7700. //获取5条用户待审核的公告
  7701. $notice = Notice::where('status', 2)
  7702. ->where('user_id', $user_id)
  7703. ->orderBy('updated_at', 'desc')
  7704. ->limit(5)->get();
  7705. //获取5条用户的待审核投诉
  7706. $complaint = Complaint::where('status', 2)
  7707. ->where('user_id', $user_id)
  7708. ->orderBy('updated_at', 'desc')
  7709. // ->limit(5)
  7710. ->get();
  7711. //获取5条用户的book
  7712. $book = Book::where('status', 2)
  7713. ->where('user_id', $user_id)
  7714. ->orderBy('updated_at', 'desc')
  7715. // ->limit(5)
  7716. ->get();
  7717. //获取5条用户的求职
  7718. //获取5条用户的求职 1
  7719. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7720. ->where('job_hunting.user_id', $user_id)
  7721. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7722. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7723. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7724. ->orderBy('updated_at', 'desc')
  7725. // ->limit(5)
  7726. ->get();
  7727. //获取5条用户的求职 2
  7728. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7729. ->where('job_recruiting.user_id', $user_id)
  7730. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7731. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7732. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7733. ->orderBy('updated_at', 'desc')
  7734. // ->limit(5)
  7735. ->get();
  7736. //人才库 1
  7737. $job_apply = JobApply::where('job_apply.status', 1)
  7738. ->where('job_apply.receiver_id', $user_id)
  7739. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7740. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7741. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7742. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7743. ->select('job_recruiting', 'job_recruiting.', '', '')
  7744. ->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')
  7745. ->orderBy('updated_at', 'desc')
  7746. // ->limit(5)
  7747. ->get();
  7748. // 职场机会 2
  7749. $job_resume = JobResume::where('job_resume.status', 1)
  7750. ->where('job_resume.receiver_id', $user_id)
  7751. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7752. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7753. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7754. ->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')
  7755. ->orderBy('updated_at', 'desc')
  7756. // ->limit(5)
  7757. ->get();
  7758. //获取5条用户待处理的投诉
  7759. $complaint_deal = Complaint::where('status', 2)
  7760. ->where('deal', 1)
  7761. ->whereJsonContains('re_user_ids', $user_id)
  7762. ->orderBy('updated_at', 'desc')
  7763. // ->limit(5)
  7764. ->get();
  7765. //获取 被通知者未读信息
  7766. $notice_unread = Notice::where('status', 2)
  7767. ->whereJsonContains('re_user_ids', $user_id)
  7768. //未读消息
  7769. ->where(function ($query) use ($user_id) {
  7770. $query->whereJsonDoesntContain('read_id', $user_id)
  7771. ->orWhereNull('read_id');
  7772. })
  7773. ->orderBy('updated_at', 'desc')
  7774. ->get();
  7775. $complaint_unread = Complaint::where('status', 2)
  7776. ->whereJsonContains('re_user_ids', $user_id)
  7777. //未读消息
  7778. ->where(function ($query) use ($user_id) {
  7779. $query->whereJsonDoesntContain('read_id', $user_id)
  7780. ->orWhereNull('read_id');
  7781. })
  7782. ->orderBy('updated_at', 'desc')
  7783. ->get();
  7784. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7785. $complany = Company::where('status', 1)
  7786. ->where('user_id', $user_id)
  7787. ->orderBy('updated_at', 'desc')
  7788. // ->limit(5)
  7789. ->get();
  7790. //获取5条单聊未读聊天消息
  7791. // $chat = ChatRecords::where('is_read', 0)
  7792. // ->where('user_id', $user_id)
  7793. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7794. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7795. // ->where('action', 'recieved')
  7796. // ->where('talk_type', 1)
  7797. // ->orderBy('created_at', 'desc')
  7798. // // ->limit(5)
  7799. // ->get();
  7800. //获取5条未读群聊信息
  7801. // $chat_group = ChatRecords::where('is_read', 0)
  7802. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7803. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7804. // ->where('user_id', $user_id)
  7805. // ->where('talk_type', 2)
  7806. // ->orderBy('created_at', 'desc')
  7807. // // ->limit(5)
  7808. // ->get();
  7809. //获取5条用户的待审核项目
  7810. $project = Project::where('status', 1)
  7811. ->where('user_id', $user_id)
  7812. ->orderBy('updated_at', 'desc')
  7813. // ->limit(5)
  7814. ->get();
  7815. // count($chat) + count($chat_group) +
  7816. $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)
  7817. + count($complany)
  7818. + count($project)
  7819. + count($notice_unread)
  7820. + count($complaint_unread)
  7821. // + count($chat) + count($chat_group)
  7822. ;
  7823. $result = [
  7824. 'apply_articale' => $apply_articale,
  7825. // 'chat' => $chat,
  7826. // 'chat_group' => $chat_group,
  7827. 'good' => $good,
  7828. 'notice' => $notice,
  7829. 'complaint' => $complaint,
  7830. 'book' => $book,
  7831. 'job_hunting' => $job_hunting,
  7832. 'job_recruiting' => $job_recruiting,
  7833. 'job_apply' => $job_apply,
  7834. 'job_resume' => $job_resume,
  7835. 'complaint_deal' => $complaint_deal,
  7836. 'complany' => $complany,
  7837. 'project' => $project,
  7838. 'notice_unread' => $notice_unread,
  7839. 'complaint_unread' => $complaint_unread,
  7840. 'count' => $count,
  7841. ];
  7842. } elseif ($type_id == 12) {
  7843. //最近的5篇已审的文章
  7844. $apply_articale = Article::where('status', 1)
  7845. ->where('admin_user_id', $user_id)
  7846. ->limit(5)->get();
  7847. //获取5条单聊未读聊天消息
  7848. $chat = ChatRecords::where('is_read', 0)
  7849. ->where('user_id', $user_id)
  7850. ->where('talk_type', 1)
  7851. ->orderBy('created_at', 'desc')
  7852. ->limit(5)->get();
  7853. //获取5条未读群聊信息
  7854. $chat_group = ChatRecords::where('is_read', 0)
  7855. ->where('user_id', $user_id)
  7856. ->where('talk_type', 2)
  7857. ->orderBy('created_at', 'desc')
  7858. ->limit(5)->get();
  7859. //获取5条用户的已审核商品
  7860. $good = Good::where('status', 2)
  7861. ->where('user_id', $user_id)
  7862. ->orderBy('updated_at', 'desc')
  7863. ->limit(5)->get();
  7864. //获取5条用户的book
  7865. $book = Book::where('status', 2)
  7866. ->where('user_id', $user_id)
  7867. ->orderBy('updated_at', 'desc')
  7868. ->limit(5)->get();
  7869. //获取5条用户的求职
  7870. //获取5条用户的求职 1
  7871. //count($chat) + count($chat_group)
  7872. $count = count($apply_articale) + count($good);
  7873. $result = [
  7874. 'apply_articale' => $apply_articale,
  7875. 'chat' => $chat,
  7876. 'chat_group' => $chat_group,
  7877. 'good' => $good,
  7878. 'book' => $book,
  7879. 'count' => $count,
  7880. ];
  7881. } elseif ($type_id == 13) {
  7882. //最近的5篇已审的文章
  7883. $apply_articale = Article::where('status', 1)
  7884. ->where('admin_user_id', $user_id)
  7885. ->limit(5)->get();
  7886. //获取5条单聊未读聊天消息
  7887. $chat = ChatRecords::where('is_read', 0)
  7888. ->where('user_id', $user_id)
  7889. ->where('talk_type', 1)
  7890. ->orderBy('created_at', 'desc')
  7891. ->limit(5)->get();
  7892. //获取5条未读群聊信息
  7893. $chat_group = ChatRecords::where('is_read', 0)
  7894. ->where('user_id', $user_id)
  7895. ->where('talk_type', 2)
  7896. ->orderBy('created_at', 'desc')
  7897. ->limit(5)->get();
  7898. //获取5条用户的已审核商品
  7899. $good = Good::where('status', 2)
  7900. ->where('user_id', $user_id)
  7901. ->orderBy('updated_at', 'desc')
  7902. ->limit(5)->get();
  7903. //count($chat) + count($chat_group) +
  7904. $count = count($apply_articale) + count($good);
  7905. $result = [
  7906. 'apply_articale' => $apply_articale,
  7907. 'chat' => $chat,
  7908. 'chat_group' => $chat_group,
  7909. 'good' => $good,
  7910. 'count' => $count,
  7911. ];
  7912. } elseif ($type_id == 14) {
  7913. //最近的5篇已审的文章
  7914. $apply_articale = Article::where('status', 1)
  7915. ->where('admin_user_id', $user_id)
  7916. // ->limit(5)
  7917. ->get();
  7918. //获取5条用户的已审核商品
  7919. $good = Good::where('status', 2)
  7920. ->where('user_id', $user_id)
  7921. ->orderBy('updated_at', 'desc')
  7922. // ->limit(5)
  7923. ->get();
  7924. $count = count($apply_articale) + count($good);
  7925. $result = [
  7926. 'apply_articale' => $apply_articale,
  7927. 'chat' => '',
  7928. 'chat_group' => '',
  7929. 'good' => $good,
  7930. 'count' => $count,
  7931. ];
  7932. } elseif ($type_id == 10000) {
  7933. //获取未审核的5篇文章
  7934. $apply_articale = Article::where('status', 0)
  7935. ->orderBy('updated_at', 'desc')
  7936. // ->limit(5)
  7937. ->get();
  7938. //获取5条单聊未读聊天消息
  7939. //获取5条单聊未读聊天消息
  7940. // $chat = ChatRecords::where('is_read', 0)
  7941. // ->where('user_id', $user_id)
  7942. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7943. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7944. // ->where('action', 'recieved')
  7945. // ->where('talk_type', 1)
  7946. // ->orderBy('created_at', 'desc')
  7947. // // ->limit(5)
  7948. // ->get();
  7949. // //获取5条未读群聊信息
  7950. // $chat_group = ChatRecords::where('is_read', 0)
  7951. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7952. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7953. // ->where('user_id', $user_id)
  7954. // ->where('talk_type', 2)
  7955. // ->orderBy('created_at', 'desc')
  7956. // // ->limit(5)
  7957. // ->get();
  7958. //获取5条用户的已审核商品
  7959. $good = Good::where('status', 1)
  7960. // ->where('user_id', $user_id)
  7961. ->orderBy('updated_at', 'desc')
  7962. // ->limit(5)
  7963. ->get();
  7964. //获取5条用户待审核的公告
  7965. $notice = Notice::where('status', 1)
  7966. ->orderBy('updated_at', 'desc')
  7967. // ->limit(5)
  7968. ->get();
  7969. //获取5条用户的待审核投诉
  7970. $complaint = Complaint::where('status', 1)
  7971. ->orderBy('updated_at', 'desc')
  7972. // ->limit(5)
  7973. ->get();
  7974. //获取5条用户的book
  7975. $book = Book::where('status', 1)
  7976. ->orderBy('updated_at', 'desc')
  7977. // ->limit(5)
  7978. ->get();
  7979. //获取5条用户的求职 1
  7980. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7981. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7982. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7983. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7984. ->orderBy('updated_at', 'desc')
  7985. // ->limit(5)
  7986. ->get();
  7987. //获取5条用户的求职 2
  7988. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7989. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7990. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7991. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7992. ->orderBy('updated_at', 'desc')
  7993. // ->limit(5)
  7994. ->get();
  7995. //人才库 1
  7996. $job_apply = JobApply::where('job_apply.status', 1)
  7997. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7998. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7999. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8000. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8001. ->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')
  8002. ->orderBy('updated_at', 'desc')
  8003. // ->limit(5)
  8004. ->get();
  8005. // 职场机会 2
  8006. $job_resume = JobResume::where('job_resume.status', 1)
  8007. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8008. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8009. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8010. ->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')
  8011. ->orderBy('updated_at', 'desc')
  8012. // ->limit(5)
  8013. ->get();
  8014. //待审核数据com pro
  8015. $complany = Company::where('status', 0)
  8016. ->orderBy('updated_at', 'desc')
  8017. // ->limit(5)
  8018. ->get();
  8019. $project = Project::where('status', 0)
  8020. ->orderBy('updated_at', 'desc')
  8021. // ->limit(5)
  8022. ->get();
  8023. $count =
  8024. // count($chat) +
  8025. // count($chat_group) +
  8026. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8027. // + count($job_apply)
  8028. // + count($job_resume)
  8029. + count($complany)
  8030. + count($project);
  8031. $result = [
  8032. 'apply_articale' => $apply_articale,
  8033. // 'chat' => $chat,
  8034. // 'chat_group' => $chat_group,
  8035. 'good' => $good,
  8036. 'notice' => $notice,
  8037. 'complaint' => $complaint,
  8038. 'book' => $book,
  8039. 'job_hunting' => $job_hunting,
  8040. 'job_recruiting' => $job_recruiting,
  8041. // 'job_apply' => $job_apply,
  8042. // 'job_resume' => $job_resume,
  8043. 'complany' => $complany,
  8044. 'project' => $project,
  8045. 'count' => $count,
  8046. ];
  8047. } elseif ($type_id == 20000) {
  8048. }
  8049. var_dump($type_id, '-----------------test---------');
  8050. return Result::success($result);
  8051. }
  8052. /**
  8053. * @param array $data
  8054. * @return array
  8055. */
  8056. public function getWebsiteProject(array $data): array
  8057. {
  8058. $categorys = json_decode($data['id'], true);
  8059. if (!empty($categorys)) {
  8060. $category_arr = $this->processArticlePro($data['website_id']);
  8061. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8062. $catiall = $category_arr['catiall'];
  8063. // return Result::success($catiall);
  8064. foreach ($categorys as $key => $val) {
  8065. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8066. $level = explode(',', $val['level'])[0];
  8067. $imgnum = explode(',', $val['level'])[1] ?? null;
  8068. $textnum = explode(',', $val['level'])[2] ?? null;
  8069. if ($level == 1) {
  8070. if (!empty($textnum) && $textnum > 0) {
  8071. $text_num = Project::where('level', $level)
  8072. ->where('website_id', $data['website_id'])
  8073. ->where('status', 1)
  8074. ->select(
  8075. 'project.id',
  8076. 'project.title',
  8077. 'project.description',
  8078. 'project.updated_at',
  8079. 'project.category_id',
  8080. 'project.cat_arr_id'
  8081. )
  8082. ->orderBy('updated_at', 'desc')
  8083. ->limit($textnum)
  8084. ->get()->all();
  8085. }
  8086. if (!empty($imgnum) && $imgnum > 0) {
  8087. $img_num = Project::where('level', $level)
  8088. ->where('website_id', $data['website_id'])
  8089. ->where('status', 1)
  8090. ->where('imgurl', '!=', '')
  8091. ->whereNotNull('imgurl')
  8092. ->select(
  8093. 'project.id',
  8094. 'project.title',
  8095. 'project.description',
  8096. 'project.updated_at',
  8097. 'project.imgurl as imgs',
  8098. 'project.category_id',
  8099. 'project.cat_arr_id'
  8100. )
  8101. ->orderBy('updated_at', 'desc')
  8102. ->limit($imgnum)
  8103. ->get()->all();
  8104. }
  8105. } else {
  8106. if (!empty($textnum) && $textnum > 0) {
  8107. $text_num = Project::where('website_id', $data['website_id'])
  8108. ->where('status', 1)
  8109. ->select(
  8110. 'project.id',
  8111. 'project.title',
  8112. 'project.description',
  8113. 'project.updated_at',
  8114. 'project.category_id',
  8115. 'project.cat_arr_id',
  8116. 'project.website_id',
  8117. 'project.updated_at',
  8118. 'project.created_at'
  8119. )
  8120. ->orderBy('updated_at', 'desc')
  8121. ->limit($textnum)
  8122. ->get()->all();
  8123. }
  8124. if (!empty($imgnum) && $imgnum > 0) {
  8125. $img_num = Project::where('website_id', $data['website_id'])
  8126. ->where('status', 1)
  8127. ->where('imgurl', '!=', '')
  8128. ->whereNotNull('imgurl')
  8129. ->select(
  8130. 'project.id',
  8131. 'project.title',
  8132. 'project.description',
  8133. 'project.updated_at',
  8134. 'project.imgurl as imgs',
  8135. 'project.category_id',
  8136. 'project.cat_arr_id'
  8137. )
  8138. ->orderBy('updated_at', 'desc')
  8139. ->limit($imgnum)
  8140. ->get()->all();
  8141. }
  8142. }
  8143. }
  8144. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8145. $category_ids = explode(',', $val['id'])[0];
  8146. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8147. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8148. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8149. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8150. $text_num = Project::whereIn('category_id', $category_arr)
  8151. ->where('website_id', $data['website_id'])
  8152. ->where('status', 1)
  8153. ->select(
  8154. 'project.id',
  8155. 'project.title',
  8156. 'project.description',
  8157. 'project.updated_at',
  8158. 'project.category_id',
  8159. 'project.cat_arr_id'
  8160. )
  8161. ->orderBy('updated_at', 'desc')
  8162. ->limit($cat_textnum)
  8163. ->get()->all();
  8164. }
  8165. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8166. $img_num = Project::whereIn('category_id', $category_arr)
  8167. ->where('website_id', $data['website_id'])
  8168. ->where('status', 1)
  8169. ->where('imgurl', '!=', '')
  8170. ->whereNotNull('imgurl')
  8171. ->select(
  8172. 'project.id',
  8173. 'project.title',
  8174. 'project.description',
  8175. 'project.updated_at',
  8176. 'project.imgurl as imgs',
  8177. 'project.category_id',
  8178. 'project.cat_arr_id'
  8179. )
  8180. ->orderBy('updated_at', 'desc')
  8181. ->limit($cat_imgnum)
  8182. ->get()->all();
  8183. }
  8184. }
  8185. if (!empty($img_num)) {
  8186. foreach ($img_num as $k => $v) {
  8187. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8188. $imgurl = json_decode($v['imgs'], true);
  8189. if (!empty($imgurl)) {
  8190. $img_num[$k]->imgurl = $imgurl[0];
  8191. }
  8192. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8193. }
  8194. }
  8195. if (!empty($text_num)) {
  8196. foreach ($text_num as $k => $v) {
  8197. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8198. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8199. }
  8200. }
  8201. $project[$key]['img_num'] = $img_num ?? [];
  8202. $project[$key]['text_num'] = $text_num ?? [];
  8203. }
  8204. }
  8205. if (empty($project)) {
  8206. return Result::error("暂无相关项目信息", 0);
  8207. }
  8208. return Result::success($project);
  8209. }
  8210. /**
  8211. * @param array $data
  8212. * @return array
  8213. */
  8214. public function getWebsiteProjectInfo(array $data): array
  8215. {
  8216. $project = Project::where('id', $data['id'])
  8217. ->where('status', 1)
  8218. ->where('website_id', $data['website_id'])
  8219. ->select('project.*')
  8220. ->first();
  8221. if (empty($project)) {
  8222. return Result::error("暂无相关项目信息", 0);
  8223. }
  8224. return Result::success($project);
  8225. }
  8226. /**
  8227. * @param array $data
  8228. * @return array
  8229. */
  8230. public function getWebsiteProjectList(array $data): array
  8231. {
  8232. $where = [];
  8233. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8234. $where['category_id'] = $data['category_id'];
  8235. }
  8236. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8237. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8238. }
  8239. $query = Project::where($where)
  8240. ->where('status', 1)
  8241. ->where('website_id', $data['website_id'])
  8242. ->select(
  8243. 'project.id',
  8244. 'project.title',
  8245. 'project.description',
  8246. 'project.imgurl as imgs',
  8247. 'project.category_id',
  8248. 'project.cat_arr_id'
  8249. )
  8250. ->orderBy('updated_at', 'desc');
  8251. $count = $query->count();
  8252. $project = $query->clone()
  8253. ->offset(($data['page'] - 1) * $data['pageSize'])
  8254. ->limit($data['pageSize'])
  8255. ->get()->all();
  8256. if (empty($project)) {
  8257. return Result::error("暂无相关项目信息", 0);
  8258. }
  8259. $categorys = $this->processArticlePro($data['website_id']);
  8260. $catiall = $categorys['catiall'];
  8261. foreach ($project as $key => $val) {
  8262. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8263. if (!empty($val['imgs'])) {
  8264. $imgurl = json_decode($val['imgs'], true);
  8265. if (!empty($imgurl)) {
  8266. $project[$key]->imgurl = $imgurl[0];
  8267. }
  8268. } else {
  8269. $project[$key]->imgurl = '';
  8270. }
  8271. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8272. }
  8273. $result = [
  8274. 'rows' => $project,
  8275. 'count' => $count,
  8276. ];
  8277. return Result::success($result);
  8278. }
  8279. /**
  8280. * @param array $data
  8281. * @return array
  8282. */
  8283. public function getWebsiteCategoryJob(array $data): array
  8284. {
  8285. $categorys = json_decode($data['id'], true);
  8286. if (!empty($categorys)) {
  8287. $category_arr = $this->processArticlePro($data['website_id']);
  8288. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8289. $catiall = $category_arr['catiall'];
  8290. foreach ($categorys as $key => $val) {
  8291. if (isset($val['id']) && !empty($val['id'])) {
  8292. $catid = explode(',', $val['id'])[0] ?? null;
  8293. $type = explode(',', $val['id'])[1] ?? null;
  8294. $textnum = explode(',', $val['id'])[2] ?? null;
  8295. }
  8296. // 4:招聘;5:求职;
  8297. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8298. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8299. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8300. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8301. ->where('job_recruiting.status', 1)
  8302. ->where('job_recruiting.website_id', $data['website_id'])
  8303. ->select(
  8304. 'job_recruiting.id',
  8305. 'job_recruiting.title',
  8306. 'job_company.business_name',
  8307. 'job_recruiting.updated_at',
  8308. 'job_recruiting.cat_arr_id',
  8309. 'job_recruiting.keyword',
  8310. 'job_recruiting.description'
  8311. )
  8312. ->orderBy('job_recruiting.updated_at', 'desc')
  8313. ->limit($textnum)
  8314. ->get()->all();
  8315. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8316. // 状态 审核状态,1待审核2已审核3已拒绝
  8317. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8318. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8319. ->where('job_hunting.status', 2)
  8320. ->where('job_hunting.website_id', $data['website_id'])
  8321. ->select(
  8322. 'job_hunting.id',
  8323. 'job_hunting.name',
  8324. 'job_hunting.cat_arr_id',
  8325. 'job_position.zwname as job_name',
  8326. 'job_hunting.updated_at',
  8327. 'job_hunting.keyword',
  8328. 'job_hunting.slelf_evaluation'
  8329. )
  8330. ->orderBy('updated_at', 'desc')
  8331. ->limit($textnum)
  8332. ->get()->all();
  8333. } else {
  8334. $job = [];
  8335. }
  8336. // var_dump($catid.'222uuuuuuu'.$key);
  8337. if (!empty($job)) {
  8338. foreach ($job as $k => $value) {
  8339. if (isset($value->cat_arr_id)) {
  8340. $catArr = json_decode($value->cat_arr_id, true);
  8341. $catId = end($catArr);
  8342. } else {
  8343. continue;
  8344. }
  8345. if (isset($catiall[$catId])) {
  8346. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8347. }
  8348. }
  8349. }
  8350. // var_dump($catid.'xxxxx'.$key);
  8351. $result[$key] = $job ?? [];
  8352. }
  8353. }
  8354. if (empty($result)) {
  8355. return Result::error("暂无相关分类信息", 0);
  8356. }
  8357. return Result::success($result);
  8358. }
  8359. /**
  8360. * 发送消息
  8361. * @param array $messageData
  8362. * @return void
  8363. */
  8364. public function sendMessage($messageData)
  8365. {
  8366. $msg = [
  8367. 'talk_type' => $messageData['talk_type'],
  8368. 'title' => $messageData['title'],
  8369. 'content' => $messageData['content'],
  8370. 'messageType' => $messageData['messageType'],
  8371. 'user_id' => $messageData['user_id'] ?? '',
  8372. 'time' => microtime(),
  8373. ];
  8374. $message = new MqProducer($msg);
  8375. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8376. $producer->produce($message);
  8377. }
  8378. /**
  8379. * 行业分类管理 ------1121
  8380. * @param array $data
  8381. * @return array
  8382. */
  8383. public function getJobIndustryList(array $data): array
  8384. {
  8385. $page = $data['page'] ?? 1;
  8386. $page_size = $data['page_size'] ?? 10;
  8387. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8388. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8389. } else {
  8390. $where = [];
  8391. }
  8392. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8393. $query->where([$where]); // 修复:将条件包装成二维数组
  8394. })
  8395. ->orderBy('updated_at', 'desc');
  8396. $count = $rs_query->count();
  8397. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8398. $result = [
  8399. 'count' => $count,
  8400. 'list' => $hy,
  8401. ];
  8402. if (empty($hy)) {
  8403. return Result::success('暂无数据');
  8404. }
  8405. return Result::success($result);
  8406. }
  8407. /**
  8408. * 添加行业分类
  8409. * @param array $data
  8410. * @return array
  8411. */
  8412. public function addJobIndustry(array $data): array
  8413. {
  8414. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8415. if (!empty($hy_name)) {
  8416. return Result::error('行业分类已存在');
  8417. }
  8418. $hy = JobIndustry::insertGetId($data);
  8419. if (empty($hy)) {
  8420. return Result::error('添加失败');
  8421. }
  8422. return Result::success($hy);
  8423. }
  8424. /**
  8425. * 更新行业分类
  8426. * @param array $data
  8427. * @return array
  8428. */
  8429. public function upJobIndustry(array $data): array
  8430. {
  8431. $hy_query = JobIndustry::get();
  8432. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8433. $hy_names = $hy_query->pluck('hyname')->toArray();
  8434. if (!in_array($data['hyid'], $hy_ids)) {
  8435. return Result::error('行业分类不存在');
  8436. }
  8437. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8438. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8439. // return Result::success($other_key_hy);
  8440. unset($hy_names[$other_key_hy]);
  8441. if (in_array($data['hyname'], $hy_names)) {
  8442. return Result::error('行业分类名称已存在');
  8443. }
  8444. }
  8445. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8446. if (empty($hy)) {
  8447. return Result::error('更新失败');
  8448. }
  8449. return Result::success($hy);
  8450. }
  8451. /**
  8452. * 删除行业分类
  8453. * @param array $data
  8454. * @return array
  8455. */
  8456. public function delJobIndustry(array $data): array
  8457. {
  8458. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8459. if (empty($hy_id)) {
  8460. return Result::error('行业分类不存在');
  8461. }
  8462. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8463. if (empty($hy)) {
  8464. return Result::error('删除失败');
  8465. }
  8466. return Result::success($hy);
  8467. }
  8468. /**
  8469. * 职位分类-列表
  8470. * @param array $data
  8471. * @return array
  8472. */
  8473. public function getJobPositionList(array $data): array
  8474. {
  8475. $page = $data['page'] ?? 1;
  8476. $page_size = $data['page_size'] ?? 10;
  8477. $where = [];
  8478. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8479. $zwids = JobPosition::where('zwpid', 0)
  8480. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8481. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8482. })
  8483. ->orderBy('updated_at', 'desc')
  8484. ->pluck('zwid')
  8485. // ->get()
  8486. ->toArray();
  8487. }
  8488. if (isset($data['childname']) && !empty($data['childname'])) {
  8489. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8490. ->when(!empty($data['childname']), function ($query) use ($data) {
  8491. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8492. })
  8493. ->orderBy('updated_at', 'desc')
  8494. ->pluck('zwpid')
  8495. // ->get()
  8496. ->toArray();
  8497. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8498. $child_zwids = array_intersect($zwids, $child_zwids);
  8499. }
  8500. $zwids = array_values(array_unique($child_zwids));
  8501. }
  8502. $zwids = $zwids ?? null;
  8503. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8504. $query->whereIn('zwid', $zwids);
  8505. })
  8506. ->where('zwpid', 0)
  8507. ->count();
  8508. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8509. $query->whereIn('zwid', $zwids);
  8510. })
  8511. ->where('zwpid', 0)
  8512. ->orderBy('updated_at', 'desc')
  8513. ->offset(($page - 1) * $page_size)
  8514. ->limit($page_size)->get()
  8515. ->map(function ($item) use ($data) {
  8516. $item->children = $item->where('zwpid', $item->zwid)
  8517. ->when(!empty($data['childname']), function ($query) use ($data) {
  8518. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8519. })
  8520. ->orderBy('updated_at', 'desc')
  8521. ->get();
  8522. return $item;
  8523. })
  8524. ->all();
  8525. $result = [
  8526. 'count' => $count,
  8527. 'list' => $position,
  8528. ];
  8529. if (empty($result)) {
  8530. return Result::success('暂无数据');
  8531. }
  8532. return Result::success($result);
  8533. }
  8534. /**
  8535. * 职位分类-添加
  8536. * @param array $data
  8537. * @return array
  8538. */
  8539. public function addJobPosition(array $data): array
  8540. {
  8541. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8542. ->where('zwname', $data['zwname'])->first(['zwid']);
  8543. if (!empty($zw_name)) {
  8544. return Result::error('职位分类已存在');
  8545. }
  8546. $zw = JobPosition::insertGetId($data);
  8547. if(empty($zw)){
  8548. return Result::error('添加失败');
  8549. }
  8550. return Result::success($zw);
  8551. }
  8552. /**
  8553. * 更新职位分类
  8554. * @param array $data
  8555. * @return array
  8556. */
  8557. public function upJobPosition(array $data): array
  8558. {
  8559. $zw_position = JobPosition::get();
  8560. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8561. return Result::error('职位分类不存在');
  8562. }
  8563. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8564. ->where('zwpid', $data['zwpid'])
  8565. ->where('zwname', $data['zwname'])->first();
  8566. if (!empty($zw_name)) {
  8567. return Result::error('职位分类已存在');
  8568. }
  8569. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8570. if (empty($result)) {
  8571. return Result::error('更新失败');
  8572. }
  8573. return Result::success($result);
  8574. }
  8575. /**
  8576. * 删除职位分类
  8577. * @param array $data
  8578. * @return array
  8579. */
  8580. public function delJobPosition(array $data): array
  8581. {
  8582. $zw_jobposition = JobPosition::get();
  8583. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8584. if (empty($zw_id)) {
  8585. return Result::error('职位分类不存在');
  8586. }
  8587. if($zw_id->zwpid == 0){
  8588. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8589. if(!empty($zw_job)){
  8590. return Result::error('请先删除子分类');
  8591. }
  8592. }
  8593. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8594. if (empty($result)) {
  8595. return Result::error('删除失败');
  8596. }
  8597. return Result::success($result);
  8598. }
  8599. }