NewsService.php 322 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. // $rep = Article::where($where)
  396. // ->whereNotIn('article.status', [404])
  397. // ->when($status1, function ($query) use ($status1) {
  398. // if (isset($status1) && $status1) {
  399. // $query->whereIn('article.status', $status1);
  400. // }
  401. // })
  402. // ->leftJoin('category', 'article.catid', 'category.id')
  403. // ->leftJoin('website_category', function ($join) {
  404. // $join->on('article.web_site_id', '=', 'website_category.website_id')
  405. // ->on('article.catid', '=', 'website_category.category_id');
  406. // })
  407. // ->when($type_id != 10000 && !empty($data['website_id']), function ($query) use ($data) {
  408. // $query->leftJoin('article_ignore', function ($join) use ($data) {
  409. // $join->on('article.id', '=', 'article_ignore.article_id')
  410. // ->where('article_ignore.website_id', $data['website_id']);
  411. // });
  412. // })
  413. // ->select("article.*", "category.name as category_name", "website_category.alias",
  414. // Db::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time'))
  415. // ->orderBy("article.updated_at", "desc")
  416. // ->limit($data['pageSize'])
  417. // ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  418. //
  419. $query = Article::where($where)
  420. ->whereNotIn('article.status', [404])
  421. ->when($status1, function ($query) use ($status1) {
  422. if (isset($status1) && $status1) {
  423. $query->whereIn('article.status', $status1);
  424. }
  425. })
  426. ->leftJoin('category', 'article.catid', 'category.id')
  427. ->leftJoin('website_category', function ($join) {
  428. $join->on('article.web_site_id', '=', 'website_category.website_id')
  429. ->on('article.catid', '=', 'website_category.category_id');
  430. });
  431. if ($type_id != 10000 && !empty($data['website_id'])) {
  432. $query = $query
  433. ->leftJoin('article_ignore', function ($join) use ($data) {
  434. $join->on('article.id', '=', 'article_ignore.article_id')
  435. ->where('article_ignore.website_id', $data['website_id']);
  436. })
  437. ->select("article.*", "category.name as category_name", "website_category.alias",'article_ignore.c_show_time');
  438. } else {
  439. $query = $query
  440. ->select("article.*", "category.name as category_name", "website_category.alias");
  441. }
  442. $count = $query->count();
  443. $rep = $query
  444. ->orderBy("article.updated_at", "desc")
  445. ->limit($data['pageSize'])
  446. ->offset(($data['page'] - 1) * $data['pageSize'])
  447. ->get();
  448. $data = [
  449. 'rows' => $rep->toArray(),
  450. 'count' => $count,
  451. ];
  452. if (empty($rep)) {
  453. return Result::error("没有信息数据");
  454. }
  455. return Result::success($data);
  456. }
  457. /**
  458. * @param array $data
  459. * @return array
  460. */
  461. public function addArticle(array $data): array
  462. {
  463. var_dump($data, '----------12-----------1');
  464. // ------c_show_time********add***1****
  465. $is_collect = $data['is_collect'] ?? 0;
  466. $user_type = $data['user_type'];
  467. unset($data['is_collect']);
  468. unset($data['user_type']);
  469. // ------c_show_time********add***1****
  470. unset($data['nav_add_pool_id']);
  471. // unset($data['commend_id']);
  472. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  473. Db::beginTransaction();
  474. try {
  475. //处理投票
  476. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  477. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  478. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  479. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  480. unset($data['is_survey']);
  481. unset($data['survey_name']);
  482. unset($data['suvey_array']);
  483. // unset($data['website_id']);
  484. // unset($data['web_site_id']);
  485. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  486. if ($data['hits'] == '') {
  487. $data['hits'] = 0;
  488. }
  489. if ($data['is_original'] == '') {
  490. $data['is_original'] = 0;
  491. }
  492. if ($data['status'] == '') {
  493. $data['status'] = 0;
  494. }
  495. $articleData = $data;
  496. unset($articleData['content']);
  497. //自动处理缩略图、关键字、描述
  498. if ($articleData['imgurl'] == '') {
  499. //如果没有图,设置level=0
  500. $levelArr = json_decode($articleData['level'], true);
  501. var_dump($levelArr, '----------levelArr-----------1');
  502. //content中提取图片第一个图,正则提取
  503. // -------采集器相关优化-----
  504. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  505. if($is_collect == 1){
  506. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  507. }else{
  508. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  509. }
  510. // -------采集器相关优化-----
  511. preg_match_all($reg, $data['content'], $matches);
  512. if (isset($matches[1][0])) {
  513. //截取varchar240
  514. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  515. //如果有图,设置level=3
  516. if (!in_array(3, $levelArr)) {
  517. $levelArr[] = 3;
  518. }
  519. $articleData['level'] = json_encode($levelArr);
  520. } else {
  521. if (!in_array(0, $levelArr)) {
  522. $levelArr[] = 0;
  523. }
  524. $articleData['level'] = json_encode($levelArr);
  525. }
  526. }
  527. var_dump($articleData['level'], '----------$articleData[level]----------1');
  528. if ($articleData['keyword'] == '') {
  529. //提取标题+内容中的关键词
  530. $articleData['keyword'] = $data['title'];
  531. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  532. Jieba::init(); // 初始化 jieba-php
  533. Finalseg::init();
  534. $segList = Jieba::cut($articleData['keyword']);
  535. $segList1 = array_slice($segList, 0, 8);
  536. $articleData['keyword'] = implode(',', $segList1);
  537. }
  538. if ($articleData['introduce'] == '') {
  539. //提取内容中的描述
  540. $content = $data['content'];
  541. // 去除 <style> 和 <script> 标签及其内容
  542. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  543. // 去除所有 HTML 标签
  544. $content = strip_tags($content);
  545. // 去除 HTML 实体
  546. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  547. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  548. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  549. // 去除多余空白
  550. $content = preg_replace('/\s+/u', '', $content);
  551. // 截取 100 个字符
  552. $articleData['introduce'] = mb_substr($content, 0, 100);
  553. }
  554. if ($articleData['status'] == 0) {
  555. $this->sendMessage([
  556. 'talk_type' => 100,
  557. 'title' => $articleData['title'],
  558. 'content' => '提交了审核',
  559. 'messageType' => 2,
  560. ]);
  561. }
  562. $id = Article::insertGetId($articleData);
  563. if (!$id) {
  564. throw new \Exception('文章插入失败');
  565. }
  566. $articleDataContent = [
  567. 'article_id' => $id,
  568. 'content' => $data['content'],
  569. ];
  570. // 采集器中的文章内容,在添加时,去掉div标签
  571. if($is_collect == 1){
  572. // 采集来的文章,content中可能包含div标签,需要先移除
  573. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  574. $article_data = preg_replace($pattern, '', $data['content']);
  575. $$articleDataContent['content'] = $article_data;
  576. }
  577. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  578. if (!$contentInsertId) {
  579. throw new \Exception('文章内容插入失败');
  580. }
  581. // ------c_show_time********add***2****
  582. // 直接使用当前系统时间,不再强制添加8小时
  583. $now = date('Y-m-d H:i:s');
  584. if($user_type == 10000 || $is_collect == 1){
  585. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  586. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  587. if (!isset($data['catid'])) {
  588. throw new \Exception('缺少必要字段:catid');
  589. }
  590. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  591. $web = WebsiteCategory::where('category_id', $data['catid'])
  592. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  593. ->select('website_id',
  594. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  595. ->get();
  596. // $id = 225; -----测试开启
  597. // 采集来的文章,错开时间在两小时之内发布
  598. if($user_type == 10000 && $is_collect == 1){
  599. $web_num = $web->where('is_core', '!=', 2)->count();
  600. $waiting_interval = 10;
  601. if($web_num > 12){
  602. // 若网站数量大于12个,则每个网站间隔时间取均值
  603. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  604. $waiting_interval = 120 / max(1, $web_num);
  605. }
  606. $time = 0;
  607. }else{
  608. // 非核心站与核心站----显示时间-----间隔
  609. $time = 20;
  610. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  611. $waiting_interval = 5;
  612. }
  613. // 将 Hyperf\Database\Model\Collection 转换为数组
  614. $webArray = $web->toArray();
  615. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  616. // 检查 $item 对象是否有 is_core 属性
  617. if (!isset($item['is_core'])) {
  618. throw new \Exception('$item 对象缺少 is_core 属性');
  619. }
  620. // 当 is_core 为 2 时,则表示此网站不存在
  621. if ($item['is_core'] == 2) {
  622. return null;
  623. }
  624. if($is_collect == 1){
  625. // 采集来的文章,错开时间在两小时之内发布
  626. // $time = 0;
  627. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  628. $time += $waiting_interval;
  629. }else if($item['is_core'] == 1){
  630. // 当 is_core 为 1 时,则表示此网站是核心站
  631. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  632. }else{
  633. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  634. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  635. if ($item['is_core'] == 0) {
  636. $time += $waiting_interval;
  637. }
  638. }
  639. return [
  640. 'article_id' => $id,
  641. 'website_id' => $item['website_id'],
  642. 'c_show_time' => $c_show_time,
  643. // 'is_core' => $item['is_core'],
  644. // 'time' => $time
  645. ];
  646. }, array_keys($webArray), $webArray)));
  647. // Db::commit();
  648. // return Result::success($article_ignore);
  649. if(!empty($article_ignore)){
  650. $article_ignores = ArticleIgnore::insert($article_ignore);
  651. if(!$article_ignores){
  652. throw new \Exception('c端展示时间插入失败');
  653. }
  654. }
  655. }
  656. // ------c_show_time********add***2****
  657. //处理投票
  658. if ($is_survey == 1) {
  659. //生成年月日时分秒+8位随机数
  660. $uuid = date('YmdHis') . rand(10000000, 99999999);
  661. var_dump($suvey_array, 'suvey_array________');
  662. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  663. var_dump($suveys_array, '---------------------1');
  664. var_dump($suvey_array, '---------------------2');
  665. $suvey_data = [];
  666. foreach ($suveys_array as $key => $value) {
  667. if ($value == '') {
  668. continue;
  669. }
  670. if (is_array($value)) {
  671. $suvey_data[] = [
  672. 'sur_id' => $uuid,
  673. 'art_id' => $id,
  674. 'website_id' => $website_id ?? 2,
  675. 'survey_name' => $survey_name,
  676. 'choice_name' => $value[1],
  677. 'is_other' => 1,
  678. 'other_id' => 0,
  679. 'results' => 0,
  680. ];
  681. } else {
  682. $suvey_data[] = [
  683. 'sur_id' => $uuid,
  684. 'art_id' => $id,
  685. 'website_id' => $website_id ?? 2,
  686. 'survey_name' => $survey_name,
  687. 'choice_name' => $value,
  688. 'is_other' => 0,
  689. 'other_id' => 0,
  690. 'results' => 0,
  691. ];
  692. }
  693. if (empty($suvey_data)) {
  694. throw new \Exception("投票数据为空");
  695. }
  696. }
  697. $result = ArticleSurvey::insert($suvey_data);
  698. if (!$result) {
  699. throw new \Exception("投票失败,ArticleSurvey插入失败");
  700. }
  701. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  702. if (!$result) {
  703. throw new \Exception("投票失败,更新主表失败");
  704. }
  705. }
  706. Db::commit();
  707. return Result::success(['id' => $id]);
  708. } catch (\Throwable $ex) {
  709. Db::rollBack();
  710. var_dump($ex->getMessage());
  711. return Result::error("创建失败", 0);
  712. }
  713. }
  714. /**
  715. * @param array $data
  716. * @return array
  717. */
  718. public function delArticle(array $data): array
  719. {
  720. // ------c_show_time********del*******
  721. Db::beginTransaction();
  722. try{
  723. $article = Article::where(['id' => $data['id']])->delete();
  724. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  725. if (!$article) {
  726. throw new \Exception("删除失败,文章删除失败");
  727. }
  728. //survey投票删除
  729. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  730. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  731. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  732. // 若文章详情删除失败,抛出异常
  733. if (!$article_data) {
  734. throw new \Exception("删除失败,文章详情删除失败");
  735. }
  736. Db::commit(); // 所有操作成功,提交事务
  737. }catch (\Throwable $ex) {
  738. Db::rollBack();
  739. var_dump($ex->getMessage());
  740. return Result::error("删除失败: " . $ex->getMessage(), 0);
  741. }
  742. // ------c_show_time********del*******
  743. if (!$article) {
  744. return Result::error("删除失败");
  745. }
  746. return Result::success($article);
  747. }
  748. /**
  749. * @param array $data
  750. * @return array
  751. */
  752. public function updateArticle(array $data): array
  753. {
  754. var_dump($data, '----------12-----------1');
  755. Db::beginTransaction();
  756. // ------c_show_time********up*******
  757. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  758. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  759. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  760. $web = WebsiteCategory::where('category_id', $data['catid'])
  761. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  762. ->select('website_id',
  763. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  764. ->get();
  765. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  766. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  767. $websiteIds = $web->pluck('website_id')->toArray();
  768. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  769. if($user_type == 0){
  770. throw new \Exception("用户类型不能为空");
  771. }
  772. if($user_type == 10000 ){
  773. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  774. $web = WebsiteCategory::where('category_id', $data['catid'])
  775. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  776. ->select('website_id',
  777. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  778. ->get();
  779. // 非核心站与核心站----显示时间-----间隔
  780. $time = 20;
  781. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  782. $waiting_interval = 5;
  783. $webArray = $web->toArray();
  784. if(empty($webArray)){
  785. throw new \Exception('网站分类不存在');
  786. }
  787. // 直接使用当前系统时间,不再强制添加8小时
  788. $now = date('Y-m-d H:i:s');
  789. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  790. // 检查 $item 对象是否有 is_core 属性
  791. if (!isset($item['is_core'])) {
  792. throw new \Exception('$item 对象缺少 is_core 属性');
  793. }
  794. // 当 is_core 为 2 时,则表示此网站不存在
  795. if ($item['is_core'] == 2) {
  796. return null;
  797. }else if($item['is_core'] == 1){
  798. // 当 is_core 为 1 时,则表示此网站是核心站
  799. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  800. }else{
  801. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  802. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  803. if ($item['is_core'] == 0) {
  804. $time += $waiting_interval;
  805. }
  806. }
  807. return [
  808. 'article_id' => $data['id'],
  809. 'website_id' => $item['website_id'],
  810. 'c_show_time' => $c_show_time,
  811. ];
  812. }, array_keys($webArray), $webArray)));
  813. if(!empty($article_ignore)){
  814. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  815. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  816. $article_ignores = ArticleIgnore::upsert(
  817. $article_ignore,
  818. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  819. ['c_show_time'] // 需要更新的字段
  820. );
  821. if(!$article_ignores){
  822. throw new \Exception('c端展示时间插入失败');
  823. }
  824. }
  825. // Db::commit();
  826. // return Result::success($article_ignore);
  827. }
  828. // ------c_show_time********up*******
  829. unset($data['user_type']);
  830. // unset($data['web_site_id']);
  831. unset($data['nav_add_pool_id']);
  832. try {
  833. //处理投票
  834. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  835. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  836. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  837. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  838. unset($data['is_survey']);
  839. unset($data['survey_name']);
  840. unset($data['suvey_array']);
  841. unset($data['website_id']);
  842. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  843. if ($data['hits'] == '') {
  844. $data['hits'] = 0;
  845. }
  846. if ($data['is_original'] == '') {
  847. $data['is_original'] = 0;
  848. }
  849. if ($data['status'] == '') {
  850. $data['status'] = 0;
  851. }
  852. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  853. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  854. $articleData = $data;
  855. unset($articleData['content']);
  856. unset($articleData['status_name']);
  857. unset($articleData['name']);
  858. unset($articleData['content']);
  859. unset($articleData['pid_arr']);
  860. unset($articleData['pid']);
  861. //自动处理缩略图、关键字、描述
  862. if ($articleData['imgurl'] == '') {
  863. //如果没有图,设置level=0
  864. $levelArr = json_decode($articleData['level'], true);
  865. var_dump($levelArr, '----------levelArr-----------1');
  866. //content中提取图片第一个图,正则提取
  867. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  868. preg_match_all($reg, $data['content'], $matches);
  869. if (isset($matches[1][0])) {
  870. //截取varchar240
  871. // 截取到第一个<
  872. $articleData['imgurl'] = $matches[1][0];
  873. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  874. $pos = strpos($articleData['imgurl'], '"');
  875. if ($pos !== false) {
  876. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  877. }
  878. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  879. //如果有图,设置level=3
  880. if (!in_array(3, $levelArr)) {
  881. $levelArr[] = 3;
  882. }
  883. $articleData['level'] = json_encode($levelArr);
  884. } else {
  885. if (!in_array(0, $levelArr)) {
  886. $levelArr[] = 0;
  887. }
  888. $articleData['level'] = json_encode($levelArr);
  889. }
  890. }
  891. var_dump($articleData['level'], '----------$articleData[level]----------1');
  892. if ($articleData['keyword'] == '') {
  893. //提取标题+内容中的关键词
  894. $articleData['keyword'] = $data['title'];
  895. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  896. Jieba::init(); // 初始化 jieba-php
  897. Finalseg::init();
  898. $segList = Jieba::cut($articleData['keyword']);
  899. $segList1 = array_slice($segList, 0, 8);
  900. $articleData['keyword'] = implode(',', $segList1);
  901. }
  902. if ($articleData['introduce'] == '') {
  903. //提取内容中的描述
  904. $content = $data['content'];
  905. // 去除 <style> 和 <script> 标签及其内容
  906. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  907. // 去除所有 HTML 标签
  908. $content = strip_tags($content);
  909. // 去除 HTML 实体
  910. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  911. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  912. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  913. // 去除多余空白
  914. $content = preg_replace('/\s+/u', '', $content);
  915. // 截取 100 个字符
  916. $articleData['introduce'] = mb_substr($content, 0, 100);
  917. }
  918. if ($articleData['status'] == 0) {
  919. $this->sendMessage([
  920. 'talk_type' => 100,
  921. 'title' => $articleData['title'],
  922. 'content' => '提交了审核',
  923. 'messageType' => 2,
  924. ]);
  925. }
  926. $id = Article::where(['id' => $data['id']])->update($articleData);
  927. // $articleDataContent = [
  928. // 'content' => $data['content'],
  929. // ];
  930. // 采集来的文章,content中可能包含div标签,需要先移除
  931. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  932. $article_data = preg_replace($pattern, '', $data['content']);
  933. $articleDataContent['content'] = $article_data;
  934. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  935. //处理投票
  936. $id = $data['id'];
  937. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  938. var_dump($suvey_array, 'suvey_array________delete');
  939. //处理投票
  940. if ($is_survey == 1) {
  941. //生成年月日时分秒+8位随机数
  942. $uuid = date('YmdHis') . rand(10000000, 99999999);
  943. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  944. var_dump($suveys_array, '---------------------1');
  945. $suvey_data = [];
  946. if (is_array($suveys_array)) {
  947. foreach ($suveys_array as $key => $value) {
  948. if ($value == '') {
  949. continue;
  950. }
  951. if (is_array($value)) {
  952. $suvey_data[] = [
  953. 'sur_id' => $uuid,
  954. 'art_id' => $id,
  955. 'website_id' => $website_id ?? 2,
  956. 'survey_name' => $survey_name,
  957. 'choice_name' => $value[1],
  958. 'is_other' => 1,
  959. 'other_id' => 0,
  960. 'results' => 0,
  961. ];
  962. } else {
  963. $suvey_data[] = [
  964. 'sur_id' => $uuid,
  965. 'art_id' => $id,
  966. 'website_id' => $website_id ?? 2,
  967. 'survey_name' => $survey_name,
  968. 'choice_name' => $value,
  969. 'is_other' => 0,
  970. 'other_id' => 0,
  971. 'results' => 0,
  972. ];
  973. }
  974. if (empty($suvey_data)) {
  975. throw new \Exception("投票数据为空");
  976. }
  977. }
  978. }
  979. $result = ArticleSurvey::insert($suvey_data);
  980. if (!$result) {
  981. throw new \Exception("投票失败");
  982. }
  983. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  984. if (!$result) {
  985. throw new \Exception("投票失败");
  986. }
  987. } else {
  988. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  989. }
  990. Db::commit();
  991. return Result::success([]);
  992. } catch (\Throwable $ex) {
  993. Db::rollBack();
  994. var_dump($ex->getMessage());
  995. return Result::error("更新失败" . $ex->getMessage(), 0);
  996. }
  997. }
  998. /**
  999. * 更新资讯状态
  1000. * @param array $data
  1001. * @return array
  1002. */
  1003. public function upArticleStatus(array $data): array
  1004. {
  1005. $articleData = Article::where(['id' => $data['id']])->first();
  1006. //发送10次
  1007. // for ($i = 0; $i < 10; $i++) {
  1008. // $this->sendMessage([
  1009. // 'talk_type' => 100,
  1010. // 'title' => $i . $articleData['title'],
  1011. // 'content' => '审核通过',
  1012. // 'messageType' => 2,
  1013. // 'user_id' => $articleData['admin_user_id'],
  1014. // ]);
  1015. // }
  1016. // var_dump($data['status'], 'status');
  1017. // return Result::success();
  1018. if ($data['status'] == 1) {
  1019. $this->sendMessage([
  1020. 'talk_type' => 101,
  1021. 'title' => $articleData['title'],
  1022. 'content' => '审核通过',
  1023. 'messageType' => 2,
  1024. 'user_id' => $articleData['admin_user_id'],
  1025. ]);
  1026. }
  1027. if ($data['status'] == 2) {
  1028. $this->sendMessage([
  1029. 'talk_type' => 101,
  1030. 'title' => $articleData['title'],
  1031. 'content' => '审核拒绝',
  1032. 'messageType' => 2,
  1033. 'user_id' => $articleData['admin_user_id'],
  1034. ]);
  1035. }
  1036. if ($data['status'] == 0) {
  1037. $this->sendMessage([
  1038. 'talk_type' => 100,
  1039. 'title' => $articleData['title'],
  1040. 'content' => '提交了审核',
  1041. 'messageType' => 2,
  1042. ]);
  1043. }
  1044. $result = Article::where(['id' => $data['id']])->update($data);
  1045. // ------c_show_time********up_status*******
  1046. // 若是审核通过 则更新c_show_time
  1047. if($data['status'] == 1){
  1048. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1049. $web = Article::where('article.id',$data['id'])
  1050. ->leftJoin('website_category','article.catid','website_category.category_id')
  1051. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1052. ->select('website_id',
  1053. 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'))
  1054. ->get();
  1055. // 非核心站与核心站----显示时间-----间隔
  1056. $time = 20;
  1057. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1058. $waiting_interval = 5;
  1059. $webArray = $web->toArray();
  1060. if(empty($webArray)){
  1061. throw new \Exception('网站分类不存在');
  1062. }
  1063. // 直接使用当前系统时间,不再强制添加8小时
  1064. $now = date('Y-m-d H:i:s');
  1065. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1066. if(isset($data['ignore_ids'])){
  1067. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1068. if(in_array($item['website_id'], $ignore_website_ids)){
  1069. $is_ignore = 1;
  1070. }else{
  1071. $is_ignore = 0;
  1072. }
  1073. return [
  1074. 'article_id' => $data['id'],
  1075. 'website_id' => $item['website_id'],
  1076. 'is_ignore' => $is_ignore,
  1077. ];
  1078. }else{
  1079. // 检查 $item 对象是否有 is_core 属性
  1080. if (!isset($item['is_core'])) {
  1081. throw new \Exception('$item 对象缺少 is_core 属性');
  1082. }
  1083. // 当 is_core 为 2 时,则表示此网站不存在
  1084. if ($item['is_core'] == 2) {
  1085. return null;
  1086. }else if($item['is_core'] == 1){
  1087. // 当 is_core 为 1 时,则表示此网站是核心站
  1088. $c_show_time = $now;
  1089. }else{
  1090. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1091. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1092. if ($item['is_core'] == 0) {
  1093. $time += $waiting_interval;
  1094. }
  1095. }
  1096. return [
  1097. 'article_id' => $data['id'],
  1098. 'website_id' => $item['website_id'],
  1099. 'c_show_time' => $c_show_time,
  1100. ];
  1101. }
  1102. }, array_keys($webArray), $webArray)));
  1103. if(!empty($article_ignore) && !isset($data['ignore_ids'])){
  1104. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1105. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1106. $websiteIds = $web->pluck('website_id')->toArray();
  1107. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1108. $article_ignores = ArticleIgnore::upsert(
  1109. $article_ignore,
  1110. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1111. ['c_show_time'] // 需要更新的字段
  1112. );
  1113. if(!$article_ignores){
  1114. throw new \Exception('c端展示时间插入失败');
  1115. }
  1116. }
  1117. if(!empty($data['ignore_ids'])){
  1118. // return Result::success($article_ignore);
  1119. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1120. if(!empty($article_ignore)){
  1121. $article_ignores = ArticleIgnore::upsert(
  1122. $article_ignore,
  1123. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1124. ['is_ignore'] // 需要更新的字段
  1125. );
  1126. // if(!$article_ignores){
  1127. // throw new \Exception('屏蔽网站更新失败');
  1128. // }
  1129. }
  1130. }
  1131. }
  1132. // ------c_show_time********up_status*******
  1133. if ($result) {
  1134. return Result::success();
  1135. } else {
  1136. return Result::error("更新状态失败", 0);
  1137. }
  1138. }
  1139. /**
  1140. * 获取新闻详情
  1141. * @param array $data
  1142. * @return array
  1143. */
  1144. public function getArticleInfo(array $data): array
  1145. {
  1146. $where = [
  1147. 'article.id' => $data['id'],
  1148. // 'article.status' => 1,
  1149. ];
  1150. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1151. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1152. $info = $result;
  1153. // var_dump($info, 'info');
  1154. $info['survey_array'] = $articleSurvey;
  1155. if ($result) {
  1156. return Result::success($info);
  1157. } else {
  1158. return Result::error("查询失败", 0);
  1159. }
  1160. }
  1161. /**
  1162. * 获取头条新闻
  1163. * @param array $data
  1164. * @return array
  1165. */
  1166. public function getWebsiteArticlett(array $data): array
  1167. {
  1168. $website_id = $data['website_id'];
  1169. $website = Website::where('id', $data['website_id'])->first();
  1170. if (empty($website)) {
  1171. return Result::error("网站不存在", 0);
  1172. }
  1173. $categorys = $this->processArticlePro($website_id);
  1174. $catiall = $categorys['catiall'];
  1175. $categoryIds = $categorys['categoryIds'];
  1176. $where = [
  1177. 'status' => 1
  1178. ];
  1179. // $website_column = $website['column'];
  1180. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1181. $website_column = json_decode($website['website_column_arr_id'], true);
  1182. }
  1183. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1184. // return Result::success($diff_pid_categoryIds);
  1185. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1186. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1187. }
  1188. // $website_id = $data['website_id'];
  1189. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1190. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1191. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1192. switch ($data['level']) {
  1193. case 1:
  1194. case 2:
  1195. case 3:
  1196. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1197. $query = Article::where($where)
  1198. ->where('level', 'like', '%' . $data['level'] . '%')
  1199. ->orderBy('updated_at', 'desc');
  1200. break;
  1201. case 4: //最新资讯
  1202. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1203. break;
  1204. case 5: //资讯推荐
  1205. $query = Article::where($where)
  1206. ->where('updated_at', '>', $month);
  1207. break;
  1208. case 7: //资讯分类
  1209. if (isset($data['id']) && !empty($data['id'])) {
  1210. $keyword = Article::where('id', $data['id'])->value('keyword');
  1211. $keywordArray = explode(',', $keyword);
  1212. $whereL7 = [];
  1213. foreach ($keywordArray as $k => $v) {
  1214. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1215. }
  1216. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1217. break;
  1218. } else {
  1219. return Result::error("请输入资讯ID", 0);
  1220. break;
  1221. }
  1222. default:
  1223. break;
  1224. }
  1225. // $whereL7 = [];
  1226. // if(isset($data['id']) && !empty($data['id'])){
  1227. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1228. // $keywordArray = explode(',', $keyword);
  1229. // foreach ($keywordArray as $k => $v) {
  1230. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1231. // }
  1232. // }
  1233. // $query = Article::where($where)
  1234. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1235. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1236. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1237. // }
  1238. // if($data['level'] == 7){
  1239. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1240. // }
  1241. // if($data['level'] == 4){
  1242. // $query = $query->inRandomOrder()
  1243. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1244. // }
  1245. // if($data['level'] == 5){
  1246. // $query = $query->orderBy('updated_at','desc');
  1247. // }
  1248. // });
  1249. if ($data['textnum'] > 0) {
  1250. $query = clone $query;
  1251. $result['text'] = $query
  1252. ->whereIn('catid', $categoryIds)
  1253. ->leftJoinSub(function ($query) use ($website_id) {
  1254. $query->from('article_ignore')
  1255. ->where('website_id', $website_id);
  1256. }, 'article_ignore', function ($join) {
  1257. $join->on('article_ignore.article_id', '=', 'article.id');
  1258. })
  1259. ->where(function ($query) {
  1260. $query->whereNull('article_ignore.article_id')
  1261. ->orWhere(function ($subQuery) {
  1262. $subQuery->whereNotNull('article_ignore.article_id')
  1263. ->where('article_ignore.is_ignore', 0)
  1264. ->where(function ($subSubQuery) {
  1265. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1266. ->orWhereNull('article_ignore.c_show_time');
  1267. });
  1268. });
  1269. })
  1270. // ->where(function ($query) use ($website_id) {
  1271. // $query->whereNull('article_ignore.article_id')
  1272. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1273. // })
  1274. ->select(
  1275. 'article.id',
  1276. 'article.title',
  1277. 'article.author',
  1278. 'article.updated_at',
  1279. 'article.introduce',
  1280. 'article.islink',
  1281. 'article.linkurl',
  1282. 'article.copyfrom',
  1283. 'article.cat_arr_id',
  1284. 'article.catid',
  1285. 'article.level',
  1286. // 'article_ignore.is_ignore',
  1287. // 'article_ignore.c_show_time',
  1288. )
  1289. ->offset($data['placeid'])
  1290. ->limit($data['textnum'])
  1291. ->get()->all();
  1292. foreach ($result['text'] as $k => $v) {
  1293. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1294. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1295. }
  1296. }
  1297. if ($data['imgnum'] > 0) {
  1298. $query = clone $query;
  1299. if($data['textnum'] == 0){
  1300. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1301. $query->from('article_ignore')
  1302. ->where('website_id', $website_id);
  1303. }, 'article_ignore', function ($join) {
  1304. $join->on('article_ignore.article_id', '=', 'article.id');
  1305. })
  1306. ->where(function ($query) {
  1307. $query->whereNull('article_ignore.article_id')
  1308. ->orWhere(function ($subQuery) {
  1309. $subQuery->whereNotNull('article_ignore.article_id')
  1310. ->where('article_ignore.is_ignore', 0)
  1311. ->where(function ($subSubQuery) {
  1312. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1313. ->orWhereNull('article_ignore.c_show_time');
  1314. });
  1315. });
  1316. });
  1317. }
  1318. $result['img'] = $query
  1319. ->whereIn('catid', $categoryIds)
  1320. ->where('article.imgurl', '!=', '')
  1321. ->select(
  1322. 'article.id',
  1323. 'article.title',
  1324. 'article.imgurl',
  1325. 'article.author',
  1326. 'article.updated_at',
  1327. 'article.introduce',
  1328. 'article.islink',
  1329. 'article.linkurl',
  1330. 'article.copyfrom',
  1331. 'article.cat_arr_id',
  1332. 'article.catid',
  1333. 'article.level',
  1334. // 'article_ignore.is_ignore',
  1335. // 'article_ignore.c_show_time',
  1336. )
  1337. ->offset($data['placeid'])
  1338. ->limit($data['imgnum'])
  1339. ->get()->all();
  1340. foreach ($result['img'] as $k => $v) {
  1341. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1342. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1343. }
  1344. }
  1345. if (empty($result)) {
  1346. return Result::error("暂无相关资讯", 0);
  1347. }
  1348. return Result::success($result);
  1349. }
  1350. /**
  1351. * 获取模块新闻
  1352. * @param array $data
  1353. * @return array
  1354. */
  1355. public function getWebsiteModelArticles(array $data): array
  1356. {
  1357. $catid = $data['catid'];
  1358. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1359. $category = $category->toArray();
  1360. if (!empty($category)) {
  1361. $where = [
  1362. 'status' => 1,
  1363. 'catid' => $catid,
  1364. ];
  1365. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1366. // 1:文字新闻;2:轮播图;3:图文;
  1367. // 级别:0:未分类
  1368. // 3:推荐图片
  1369. if ($data['level'] == 1) {
  1370. $data['level'] = 0;
  1371. }
  1372. $result = Article::where($where)
  1373. ->where(function ($query) use ($data) {
  1374. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1375. ->orWhereNull("level")
  1376. ->orWhereRaw("level = '[]'");
  1377. })
  1378. ->leftJoinSub(function ($query) use ($data) {
  1379. $query->from('article_ignore')
  1380. ->where('website_id', $data['website_id']);
  1381. }, 'article_ignore', function ($join) {
  1382. $join->on('article_ignore.article_id', '=', 'article.id');
  1383. })
  1384. ->where(function ($query) {
  1385. $query->whereNull('article_ignore.article_id')
  1386. ->orWhere(function ($subQuery) {
  1387. $subQuery->whereNotNull('article_ignore.article_id')
  1388. ->where('article_ignore.is_ignore', 0)
  1389. ->where(function ($subSubQuery) {
  1390. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1391. ->orWhereNull('article_ignore.c_show_time');
  1392. });
  1393. });
  1394. })
  1395. // ->where(function ($query) use ($data) {
  1396. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1397. // ->orWhereNull("ignore_ids");
  1398. // })
  1399. ->orderBy("updated_at", "desc")
  1400. ->offset($placeid)
  1401. ->limit($data['pagesize'])
  1402. ->get();
  1403. if (empty($result)) {
  1404. return Result::error("此栏目暂无相关新闻", 0);
  1405. }
  1406. } else {
  1407. return Result::error("此网站暂无此栏目", 0);
  1408. }
  1409. return Result::success($result);
  1410. }
  1411. /**
  1412. *获取新闻列表
  1413. * @param array $data
  1414. * @return array
  1415. */
  1416. public function getWebsiteArticleList(array $data): array
  1417. {
  1418. // return Result::success($data);
  1419. $where[] = ['status', '=', 1];
  1420. $website_id = $data['website_id'];
  1421. $website = Website::where('id', $data['website_id'])->first();
  1422. if (empty($website)) {
  1423. return Result::error("网站不存在", 0);
  1424. }
  1425. // $website_column = $website['column'];
  1426. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1427. $website_column = json_decode($website['website_column_arr_id'], true);
  1428. }
  1429. $categorys = $this->processArticlePro($website_id);
  1430. $cat_1st_arr = $categorys['cat_1st_arr'];
  1431. $catiall = $categorys['catiall'];
  1432. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1433. // return Result::success($diff_pid_categoryIds);
  1434. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1435. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1436. }
  1437. if (isset($data['catid']) && !empty($data['catid'])) {
  1438. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1439. if (empty($category)) {
  1440. return Result::error("此网站暂无此栏目", 0);
  1441. }
  1442. array_push($where, ['catid', '=', $data['catid']]);
  1443. }
  1444. // return Result::success($where);
  1445. $query = Article::where($where)
  1446. ->leftJoinSub(function ($query) use ($website_id) {
  1447. $query->from('article_ignore')
  1448. ->where('website_id', $website_id);
  1449. }, 'article_ignore', function ($join) {
  1450. $join->on('article_ignore.article_id', '=', 'article.id');
  1451. })
  1452. ->where(function ($query) {
  1453. $query->whereNull('article_ignore.article_id')
  1454. ->orWhere(function ($subQuery) {
  1455. $subQuery->whereNotNull('article_ignore.article_id')
  1456. ->where('article_ignore.is_ignore', 0)
  1457. ->where(function ($subSubQuery) {
  1458. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1459. ->orWhereNull('article_ignore.c_show_time');
  1460. });
  1461. });
  1462. })
  1463. ->select(
  1464. 'article.id',
  1465. 'article.title',
  1466. 'article.imgurl',
  1467. 'article.author',
  1468. 'article.updated_at',
  1469. 'article.introduce',
  1470. 'article.islink',
  1471. 'article.linkurl',
  1472. 'article.copyfrom',
  1473. 'article.cat_arr_id',
  1474. 'article.catid'
  1475. );
  1476. $count = $query->count();
  1477. $rep = $query->orderBy("updated_at", "desc")
  1478. ->offset(($data['page'] - 1) * $data['pageSize'])
  1479. ->limit($data['pageSize'])
  1480. ->get()->all();
  1481. $categorys = $this->processArticlePro($website_id);
  1482. $cat_1st_arr = $categorys['cat_1st_arr'];
  1483. $catiall = $categorys['catiall'];
  1484. // $web['website_id'] = $data['website_id'];
  1485. foreach ($rep as $k => $v) {
  1486. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1487. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1488. }
  1489. // $rep = $this->processArticles($rep,$web);
  1490. $data = [
  1491. 'rows' => $rep,
  1492. 'count' => $count,
  1493. ];
  1494. if (empty($rep)) {
  1495. return Result::error("没有信息数据");
  1496. }
  1497. return Result::success($data);
  1498. }
  1499. /**
  1500. * 前端-获取新闻详情
  1501. * @param array $data
  1502. * @return array
  1503. */
  1504. public function selectWebsiteArticleInfo(array $data): array
  1505. {
  1506. $where = [
  1507. 'article.id' => $data['id'],
  1508. 'article.status' => 1,
  1509. ];
  1510. $result = Article::where($where)
  1511. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1512. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1513. // ->where(function ($query) use ($data) {
  1514. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1515. // ->orWhereNull("ignore_ids");
  1516. // })
  1517. ->leftJoinSub(function ($query) use ($data) {
  1518. $query->from('article_ignore')
  1519. ->where('website_id', $data['website_id']);
  1520. }, 'article_ignore', function ($join) {
  1521. $join->on('article_ignore.article_id', '=', 'article.id');
  1522. })
  1523. ->where(function ($query) {
  1524. $query->whereNull('article_ignore.article_id')
  1525. ->orWhere(function ($subQuery) {
  1526. $subQuery->whereNotNull('article_ignore.article_id')
  1527. ->where('article_ignore.is_ignore', 0)
  1528. ->where(function ($subSubQuery) {
  1529. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1530. ->orWhereNull('article_ignore.c_show_time');
  1531. });
  1532. });
  1533. })
  1534. ->select(
  1535. 'article.*',
  1536. 'article_data.content',
  1537. 'article_data.article_id',
  1538. 'article_extend.website_url',
  1539. 'article_extend.email',
  1540. 'article_extend.contacts',
  1541. 'article_extend.contacts_mobile',
  1542. 'article_extend.contacts_address',
  1543. 'article_extend.zip_code',
  1544. 'article_extend.enterprise_name'
  1545. )
  1546. ->first();
  1547. if (empty($result)) {
  1548. return Result::error("暂无此新闻!", 0);
  1549. }
  1550. if (!empty($result['publiced_at'])) {
  1551. $result['updated_at'] = $result['publiced_at'];
  1552. }
  1553. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1554. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1555. ->where('website_category.website_id', $data['website_id'])
  1556. ->where(['website_category.category_id' => $result['catid']])
  1557. ->first();
  1558. if (empty($category)) {
  1559. return Result::error("查询失败", 0);
  1560. }
  1561. //手动推荐文章
  1562. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1563. if (empty($commend_ids)) {
  1564. $commendArticle = [];
  1565. } else {
  1566. //去除不存在的文章ID
  1567. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1568. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1569. ->leftJoinSub(function ($query) use ($data) {
  1570. $query->from('article_ignore')
  1571. ->where('website_id', $data['website_id']);
  1572. }, 'article_ignore', function ($join) {
  1573. $join->on('article_ignore.article_id', '=', 'article.id');
  1574. })
  1575. ->where(function ($query) {
  1576. $query->whereNull('article_ignore.article_id')
  1577. ->orWhere(function ($subQuery) {
  1578. $subQuery->whereNotNull('article_ignore.article_id')
  1579. ->where('article_ignore.is_ignore', 0)
  1580. ->where(function ($subSubQuery) {
  1581. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1582. ->orWhereNull('article_ignore.c_show_time');
  1583. });
  1584. });
  1585. })
  1586. ->where('article.status', 1)
  1587. ->where('website_category.website_id', $data['website_id'])
  1588. ->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')
  1589. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1590. // ->orderBy('article.updated_at', 'desc')
  1591. ->limit(5)
  1592. ->get();
  1593. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1594. foreach ($commendArticle as $k => $v) {
  1595. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1596. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1597. $cat_arr_id = array_unique($cat_arr_id);
  1598. // 从website_category取出alias_pinyin
  1599. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1600. ->whereIn('category_id', $cat_arr_id)
  1601. ->pluck('alias_pinyin', 'category_id')
  1602. ->toArray();
  1603. // 将cat_arr_id的json转成路径/隔开
  1604. $path_parts = [];
  1605. foreach ($cat_arr_id as $cat_id) {
  1606. if (isset($cat_arr[$cat_id])) {
  1607. $path_parts[] = $cat_arr[$cat_id];
  1608. }
  1609. }
  1610. $v->alias_pinyin = implode('/', $path_parts);
  1611. } else {
  1612. $v->alias_pinyin = '';
  1613. }
  1614. }
  1615. }
  1616. $result['category_id'] = $category['category_id'];
  1617. $result['cat_name'] = $category['alias'];
  1618. $result['website_name'] = $category['website_name'] ?? "";
  1619. $result['suffix'] = $category['suffix'] ?? "";
  1620. $result['commendArticle'] = $commendArticle;
  1621. $result['commend_ids'] = $commend_ids;
  1622. return Result::success($result);
  1623. }
  1624. /**
  1625. * 前端-获取网站调查问卷
  1626. * @param array $data
  1627. * @return array
  1628. */
  1629. public function getWebsiteSurvey(array $data): array
  1630. {
  1631. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1632. $website = Website::where('id', $data['website_id'])->first();
  1633. if (empty($website)) {
  1634. return Result::error("暂无此网站", 0);
  1635. }
  1636. }
  1637. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1638. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1639. if (empty($article)) {
  1640. return Result::error("暂无此文章", 0);
  1641. }
  1642. // return Result::error($data,0);
  1643. $where['art_id'] = $data['art_id'];
  1644. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1645. } else {
  1646. $survey = Article::where(function ($query) {
  1647. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1648. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1649. })
  1650. ->where('status', 1)
  1651. ->where('is_survey', 1)
  1652. ->select('survey_id')
  1653. ->orderBy('updated_at', 'desc')
  1654. ->first();
  1655. if (empty($survey)) {
  1656. return Result::error("暂无调查问卷", 0);
  1657. }
  1658. $where['sur_id'] = $survey['survey_id'];
  1659. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1660. }
  1661. // return Result::success($where);
  1662. $result = ArticleSurvey::where($where)
  1663. ->where(function ($query) {
  1664. $query->where('is_other', 0)
  1665. ->orWhere(function ($subQuery) {
  1666. $subQuery->where('is_other', 1)
  1667. ->where('other_id', 0);
  1668. });
  1669. })
  1670. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1671. ->select('article_survey.*', 'article.survey_type')
  1672. ->get()->all();
  1673. if (empty($result)) {
  1674. return Result::error("此文章暂无调查问卷", 0);
  1675. }
  1676. return Result::success($result);
  1677. }
  1678. /**
  1679. * 前端-添加网站调查问卷选项
  1680. * @param array $data
  1681. * @return array
  1682. */
  1683. public function addWebsiteSurveyOption(array $data): array
  1684. {
  1685. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1686. $website = Website::where('id', $data['website_id'])->first();
  1687. if (empty($website)) {
  1688. return Result::error("暂无此网站", 0);
  1689. }
  1690. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1691. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1692. if (empty($survey)) {
  1693. return Result::error("此调查问卷不可添加选项", 0);
  1694. }
  1695. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1696. $choice = [
  1697. 'art_id' => $survey['art_id'],
  1698. 'website_id' => $data['website_id'],
  1699. 'survey_name' => $survey['survey_name'],
  1700. 'choice_name' => $data['choice_name'],
  1701. 'sur_id' => $survey['sur_id'],
  1702. 'is_other' => 1,
  1703. 'other_id' => $survey['id'],
  1704. ];
  1705. $result = ArticleSurvey::insertGetId($choice);
  1706. if (empty($result)) {
  1707. return Result::error("添加失败", 0);
  1708. }
  1709. return Result::success($result);
  1710. }
  1711. }
  1712. return Result::error("添加失败", 0);
  1713. }
  1714. return Result::error("添加失败", 0);
  1715. }
  1716. /**
  1717. * 前端-调查问卷投票
  1718. * @param array $data
  1719. * @return array
  1720. */
  1721. public function addWebsiteSurveyVote(array $data): array
  1722. {
  1723. // return Result::success($data);
  1724. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1725. $website = Website::where('id', $data['website_id'])->first();
  1726. if (empty($website)) {
  1727. return Result::error("暂无此网站", 0);
  1728. }
  1729. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1730. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1731. // return Result::success($survey);
  1732. if (empty($is_survey)) {
  1733. return Result::error("此调查问卷不存在", 0);
  1734. }
  1735. // return Result::success($survey);
  1736. // 调查问卷类型
  1737. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1738. //多选 若是json型则转化成数组类型
  1739. if (strpos($data['choice_id'], '[') === 0) {
  1740. $data['choice_id'] = json_decode($data['choice_id'], true);
  1741. } else {
  1742. // 单选 也转换成数组
  1743. $data['choice_id'] = [$data['choice_id']];
  1744. }
  1745. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1746. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1747. // ->where('website_id',$data['website_id'])
  1748. ->where('is_other', 1)
  1749. ->where('other_id', 0)
  1750. ->first();
  1751. if (!empty($other)) {
  1752. return Result::error("请选择已有的选项!", 0);
  1753. }
  1754. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1755. // ->where('website_id',$data['website_id'])
  1756. ->where('is_other', 1)
  1757. ->where('other_id', '!=', 0)
  1758. ->first();
  1759. // return Result::success($choice['other']);
  1760. $choice_id = $data['choice_id'];
  1761. if (!empty($choice['other'])) {
  1762. // array_push($data['choice_id'],$choice['other']['other_id']);
  1763. if (!empty($choice_id)) {
  1764. $key = array_search($choice['other']['id'], $choice_id);
  1765. if ($key !== false) {
  1766. unset($choice_id[$key]);
  1767. $choice_id = array_values($choice_id);
  1768. }
  1769. array_push($choice_id, $choice['other']['other_id']);
  1770. } else {
  1771. $choice_id[0] = $choice['other']['other_id'];
  1772. }
  1773. array_push($data['choice_id'], $choice['other']['other_id']);
  1774. }
  1775. // return Result::success($data);
  1776. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1777. // ->where('website_id',$data['website_id'])
  1778. ->increment('results', 1);
  1779. if (empty($choice)) {
  1780. return Result::error("请选择已有的选项!", 0);
  1781. }
  1782. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1783. // ->where('website_id',$data['website_id'])
  1784. ->where('other_id', 0)
  1785. ->get();
  1786. $survey['choice'] = $choice_id;
  1787. return Result::success($survey);
  1788. }
  1789. return Result::error("参数必填!");
  1790. }
  1791. return Result::error("此调查问卷不存在", 0);
  1792. }
  1793. return Result::error("参数必填!");
  1794. }
  1795. /**
  1796. * 后端-获取网站调查问卷列表
  1797. * @param array $data
  1798. * @return array
  1799. */
  1800. public function getSurveyList(array $data): array
  1801. {
  1802. $where = [];
  1803. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1804. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1805. }
  1806. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1807. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1808. }
  1809. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1810. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1811. }
  1812. // return Result::success($where);
  1813. if (!empty($where)) {
  1814. $query = Article::where($where)->where(function ($q) {
  1815. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1816. });
  1817. } else {
  1818. $query = Article::where(function ($q) {
  1819. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1820. });
  1821. }
  1822. $count = $query->count();
  1823. $survey = $query->orderByDesc('id')
  1824. ->limit($data['pageSize'])
  1825. ->offset(($data['page'] - 1) * $data['pageSize'])
  1826. ->get();
  1827. if (empty($survey->toArray())) {
  1828. return Result::error("暂无调查问卷!", 0);
  1829. }
  1830. $result = [
  1831. 'rows' => $survey,
  1832. 'count' => $count,
  1833. ];
  1834. return Result::success($result);
  1835. }
  1836. /**
  1837. * 后端-获取网站调查问卷详情
  1838. * @param array $data
  1839. * @return array
  1840. */
  1841. public function getSurveyInfo(array $data): array
  1842. {
  1843. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1844. $where = ['sur_id' => $data['sur_id']];
  1845. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1846. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1847. ->select('article_survey.*', 'article.survey_type')
  1848. ->get()->all();
  1849. if (empty($choose)) {
  1850. return Result::error("此调查问卷不存在", 0);
  1851. }
  1852. $resultsArray = array_column($choose, 'results');
  1853. $total = array_sum($resultsArray);
  1854. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1855. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1856. // $total = 0;
  1857. if (!empty($other)) {
  1858. $total = $total + $other['results'];
  1859. $other['choice_name'] = '(其他)';
  1860. if (!empty($others)) {
  1861. $other['hasChildren'] = true;
  1862. // array_push($other,['hasChildren','=',true]);
  1863. $other['children'] = $others;
  1864. $other_choices = [$other->toArray()];
  1865. $mer_choice = array_merge($choose, $other_choices);
  1866. $value_choice = array_values($mer_choice);
  1867. } else {
  1868. // return Result::error('1111');
  1869. $other_choices = [$other->toArray()];
  1870. $other_choices = array_merge($choose, $other_choices);
  1871. $value_choice = array_values($other_choices);
  1872. // return Result::success($result);
  1873. }
  1874. } else {
  1875. $value_choice = $choose;
  1876. }
  1877. $result = [
  1878. 'choose' => $value_choice,
  1879. 'total' => $total,
  1880. ];
  1881. }
  1882. return Result::success($result);
  1883. }
  1884. /**
  1885. * 前端-搜索新闻列表
  1886. * @param array $data
  1887. * @return array
  1888. */
  1889. public function selectWebsiteArticle(array $data): array
  1890. {
  1891. $website = Website::where('id', $data['website_id'])->first();
  1892. if (empty($website)) {
  1893. return Result::error("网站不存在", 0);
  1894. }
  1895. // $website_column = $website['column'];
  1896. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1897. $website_column = json_decode($website['website_column_arr_id'], true);
  1898. }
  1899. $website_id = $data['website_id'];
  1900. $categorys = $this->processArticlePro($website_id);
  1901. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1902. // return Result::success($diff_pid_categoryIds);
  1903. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1904. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1905. }
  1906. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1907. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1908. $catiall = $categorys['catiall'];
  1909. $categoryIds = $categorys['categoryIds'];
  1910. // return Result::success($categoryIds);
  1911. $query = Article::where('status', 1)
  1912. ->whereIn('catid', $categoryIds)
  1913. ->leftJoinSub(function ($query) use ($website_id) {
  1914. $query->from('article_ignore')
  1915. ->where('website_id', $website_id);
  1916. }, 'article_ignore', function ($join) {
  1917. $join->on('article_ignore.article_id', '=', 'article.id');
  1918. })
  1919. ->where(function ($query) {
  1920. $query->whereNull('article_ignore.article_id')
  1921. ->orWhere(function ($subQuery) {
  1922. $subQuery->whereNotNull('article_ignore.article_id')
  1923. ->where('article_ignore.is_ignore', 0)
  1924. ->where(function ($subSubQuery) {
  1925. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1926. ->orWhereNull('article_ignore.c_show_time');
  1927. });
  1928. });
  1929. });
  1930. // ->get()->all();
  1931. // return Result::success($query);
  1932. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1933. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1934. }
  1935. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1936. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1937. }
  1938. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1939. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1940. }
  1941. // 计算总数
  1942. $count = $query->count();
  1943. // return Result::success($count);
  1944. // 分页查询
  1945. $articles = $query
  1946. ->select(
  1947. 'article.id',
  1948. 'article.title',
  1949. 'article.imgurl',
  1950. 'article.author',
  1951. 'article.updated_at',
  1952. 'article.introduce',
  1953. 'article.islink',
  1954. 'article.linkurl',
  1955. 'article.copyfrom',
  1956. 'article.cat_arr_id',
  1957. 'article.catid',
  1958. 'article.department_arr_id',
  1959. 'article.city_arr_id',
  1960. // 'article_ignore.c_show_time',
  1961. // 'article_ignore.is_ignore'
  1962. )
  1963. ->orderBy("updated_at", "desc")
  1964. ->offset(($data['page'] - 1) * $data['pageSize'])
  1965. ->limit($data['pageSize'])
  1966. ->get();
  1967. // return Result::success($articles);
  1968. foreach ($articles as $k => $v) {
  1969. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1970. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1971. }
  1972. if (empty($articles)) {
  1973. return Result::error("没有符合条件的资讯数据");
  1974. }
  1975. $result = [
  1976. 'rows' => $articles,
  1977. 'count' => $count,
  1978. ];
  1979. return Result::success($result);
  1980. }
  1981. /**
  1982. * 模块新闻加强版
  1983. * @param array $data
  1984. * @return array
  1985. */
  1986. public function getWebsiteCatidArticle(array $data): array
  1987. {
  1988. $where = [
  1989. 'website_category.category_id' => $data['catid'],
  1990. 'website_category.website_id' => $data['website_id'],
  1991. ];
  1992. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1993. $child_catnum = $data['child_catnum'] ?? 1;
  1994. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1995. $childCategoryIds = array_column($category['child'], 'category_id');
  1996. if (empty($childCategoryIds)) {
  1997. return Result::error("暂无子栏目", 0);
  1998. }
  1999. $imgArticles = [];
  2000. $textArticles = [];
  2001. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2002. // 初始化子分类图片新闻和文字新闻数组
  2003. // 查询所有子级栏目的图文新闻
  2004. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2005. ->where(function ($query) use ($data) {
  2006. $query->where(function ($subQuery) use ($data) {
  2007. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2008. })->orWhereNull("ignore_ids");
  2009. })
  2010. ->where('status', 1)
  2011. ->where('imgurl', '!=', '')
  2012. ->select('*')
  2013. ->orderBy('updated_at', 'desc')
  2014. ->limit($data['child_imgnum'])
  2015. ->get();
  2016. }
  2017. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2018. // 查询所有子级栏目的文字新闻
  2019. $textArticles = Article::where('catid', $childCategoryIds[0])
  2020. ->where('status', 1)
  2021. ->where(function ($query) use ($data) {
  2022. $query->where(function ($subQuery) use ($data) {
  2023. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2024. })->orWhereNull("ignore_ids");
  2025. })
  2026. ->select('*')
  2027. ->orderBy('updated_at', 'desc')
  2028. ->limit($data['child_textnum'])
  2029. ->get();
  2030. }
  2031. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2032. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2033. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2034. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2035. return $child;
  2036. }, $category['child']);
  2037. }
  2038. // }
  2039. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2040. $category['img'] = WebsiteCategory::where($where)
  2041. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2042. ->where('article.status', 1)
  2043. ->where('article.imgurl', '!=', '')
  2044. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2045. ->orderBy('article.updated_at', 'desc')
  2046. ->limit($data['img_num'])
  2047. ->get();
  2048. }
  2049. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2050. $category['text'] = WebsiteCategory::where($where)
  2051. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2052. ->where('article.status', 1)
  2053. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2054. ->orderBy('article.updated_at', 'desc')
  2055. ->limit($data['text_num'])
  2056. ->get();
  2057. }
  2058. // $category = $category->get();
  2059. if (empty($category)) {
  2060. return Result::error("查询失败", 0);
  2061. }
  2062. return Result::success($category);
  2063. }
  2064. /**
  2065. * 模块新闻加强plus版
  2066. * @param array $data
  2067. * @return array
  2068. */
  2069. public function getWebsiteAllArticle(array $data): array
  2070. {
  2071. // return Result::success($data);
  2072. $time1 = microtime(true);
  2073. $wetbsite_id = $data['website_id'] ?? 2;
  2074. $data = json_decode($data['id'], true);
  2075. $website = Website::where('id', $wetbsite_id)->first();
  2076. if (empty($website)) {
  2077. return Result::error("网站不存在", 0);
  2078. }
  2079. // return Result::success($website);
  2080. $website_column = $website['website_column_arr_id'] ?? '[]';
  2081. $website_column = json_decode($website_column, true);
  2082. $categorys = $this->processArticlePro($wetbsite_id);
  2083. $cat_1st_arr = $categorys['cat_1st_arr'];
  2084. $catiall = $categorys['catiall'];
  2085. // return Result::success($catiall);
  2086. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2087. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2088. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2089. }
  2090. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2091. // return Result::success($categorys);
  2092. $parent_category = array_column($data, 'parent');
  2093. $parent_cat = [];
  2094. $child_category = array_column($data, 'child');
  2095. if (!empty($parent_category)) {
  2096. foreach ($parent_category as $key => $value) {
  2097. $arr = array_map('intval', explode(',', $value));
  2098. $parent_cat[$key] = $arr[0] ?? 0;
  2099. $parent_category = $arr[0] ?? 0;
  2100. $article_imgnum = $arr[1] ?? 0;
  2101. $article_textnum = $arr[2] ?? 0;
  2102. if ($parent_category != 0) {
  2103. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2104. // return Result::success($category_arr);
  2105. if ($article_imgnum != 0) {
  2106. $img_article = Article::whereIn('catid', $category_arr)
  2107. ->where('status', 1)
  2108. ->where('imgurl', '!=', '')
  2109. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2110. $query->from('article_ignore')
  2111. ->where('website_id', $wetbsite_id);
  2112. }, 'article_ignore', function ($join) {
  2113. $join->on('article_ignore.article_id', '=', 'article.id');
  2114. })
  2115. ->where(function ($query) {
  2116. $query->whereNull('article_ignore.article_id')
  2117. ->orWhere(function ($subQuery) {
  2118. $subQuery->whereNotNull('article_ignore.article_id')
  2119. ->where('article_ignore.is_ignore', 0)
  2120. ->where(function ($subSubQuery) {
  2121. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2122. ->orWhereNull('article_ignore.c_show_time');
  2123. });
  2124. });
  2125. })
  2126. ->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')
  2127. ->orderBy('updated_at', 'desc')
  2128. ->limit($article_imgnum)
  2129. ->get()->all();
  2130. foreach ($img_article as $k => $v) {
  2131. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2132. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2133. }
  2134. } else {
  2135. $img_article = [];
  2136. }
  2137. if ($article_textnum != 0) {
  2138. $text_article = Article::whereIn('catid', $category_arr)
  2139. ->where('status', 1)
  2140. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2141. $query->from('article_ignore')
  2142. ->where('website_id', $wetbsite_id);
  2143. }, 'article_ignore', function ($join) {
  2144. $join->on('article_ignore.article_id', '=', 'article.id');
  2145. })
  2146. ->where(function ($query) {
  2147. $query->whereNull('article_ignore.article_id')
  2148. ->orWhere(function ($subQuery) {
  2149. $subQuery->whereNotNull('article_ignore.article_id')
  2150. ->where('article_ignore.is_ignore', 0)
  2151. ->where(function ($subSubQuery) {
  2152. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2153. ->orWhereNull('article_ignore.c_show_time');
  2154. });
  2155. });
  2156. })
  2157. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2158. ->orderBy('updated_at', 'desc')
  2159. ->limit($article_textnum)
  2160. ->get()->all();
  2161. foreach ($text_article as $k => $v) {
  2162. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2163. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2164. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2165. }
  2166. } else {
  2167. $text_article = [];
  2168. }
  2169. $catiall[$parent_category]['imgnum'] = $img_article;
  2170. $catiall[$parent_category]['textnum'] = $text_article;
  2171. $parent[$key] = $catiall[$parent_category];
  2172. } else {
  2173. $parent[$key] = '';
  2174. }
  2175. }
  2176. }
  2177. if (!empty($child_category)) {
  2178. foreach ($child_category as $key => $value) {
  2179. $arr = array_map('intval', explode(',', $value));
  2180. $parent_category = $parent_cat[$key];
  2181. $child_category = $arr[0] ?? 0;
  2182. $article_imgnum = $arr[1] ?? 0;
  2183. $article_textnum = $arr[2] ?? 0;
  2184. if ($child_category != 0) {
  2185. $all_childcat = $cat_1st_arr[$parent_category];
  2186. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2187. // 从 $websiteInfoIndexed 中获取对应的数据
  2188. $info = $websiteInfoIndexed[$v];
  2189. // 返回一个包含所需信息的数组
  2190. return [
  2191. 'alias' => $info->alias,
  2192. 'category_id' => $info->category_id,
  2193. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2194. 'pid' => $info->pid,
  2195. 'type' => $info->type,
  2196. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2197. 'pinyin' => $info->pinyin,
  2198. ];
  2199. }, $all_childcat);
  2200. if ($article_imgnum != 0) {
  2201. $img_article = Article::where('catid', $child_category)
  2202. ->where('status', 1)
  2203. ->where('imgurl', '!=', '')
  2204. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2205. $query->from('article_ignore')
  2206. ->where('website_id', $wetbsite_id);
  2207. }, 'article_ignore', function ($join) {
  2208. $join->on('article_ignore.article_id', '=', 'article.id');
  2209. })
  2210. ->where(function ($query) {
  2211. $query->whereNull('article_ignore.article_id')
  2212. ->orWhere(function ($subQuery) {
  2213. $subQuery->whereNotNull('article_ignore.article_id')
  2214. ->where('article_ignore.is_ignore', 0)
  2215. ->where(function ($subSubQuery) {
  2216. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2217. ->orWhereNull('article_ignore.c_show_time');
  2218. });
  2219. });
  2220. })
  2221. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2222. ->orderBy('updated_at', 'desc')
  2223. ->limit($article_imgnum)
  2224. ->get()->all();
  2225. foreach ($img_article as $k => $v) {
  2226. // var_dump($v);
  2227. // var_dump($k);
  2228. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2229. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2230. }
  2231. } else {
  2232. $img_article = [];
  2233. }
  2234. if ($article_textnum != 0) {
  2235. $text_article = Article::where('catid', $child_category)
  2236. ->where('status', 1)
  2237. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2238. $query->from('article_ignore')
  2239. ->where('website_id', $wetbsite_id);
  2240. }, 'article_ignore', function ($join) {
  2241. $join->on('article_ignore.article_id', '=', 'article.id');
  2242. })
  2243. ->where(function ($query) {
  2244. $query->whereNull('article_ignore.article_id')
  2245. ->orWhere(function ($subQuery) {
  2246. $subQuery->whereNotNull('article_ignore.article_id')
  2247. ->where('article_ignore.is_ignore', 0)
  2248. ->where(function ($subSubQuery) {
  2249. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2250. ->orWhereNull('article_ignore.c_show_time');
  2251. });
  2252. });
  2253. })
  2254. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2255. ->orderBy('updated_at', 'desc')
  2256. ->limit($article_textnum)
  2257. ->get()->all();
  2258. foreach ($text_article as $k => $v) {
  2259. // var_dump($v);
  2260. // var_dump($k);
  2261. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2262. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2263. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2264. }
  2265. } else {
  2266. $text_article = [];
  2267. }
  2268. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2269. $catiall[$child_category]['imgnum'] = $img_article;
  2270. $catiall[$child_category]['textnum'] = $text_article;
  2271. $child[$key] = $catiall[$child_category];
  2272. // var_dump($pids);
  2273. } else {
  2274. $child[$key] = '';
  2275. }
  2276. }
  2277. }
  2278. foreach ($parent as $key => $value) {
  2279. $result[$key] = $value;
  2280. if (!empty($child[$key])) {
  2281. // var_dump($child[$key]);
  2282. $result[$key]['child'] = $child[$key];
  2283. // $value[$key]['child'] = $child[$key];
  2284. } else {
  2285. $result[$key]['child'] = [
  2286. "alias" => null,
  2287. "category_id" => null,
  2288. "type" => null,
  2289. "pinyin" => null,
  2290. "all_childcat" => [],
  2291. "imgnum" => [],
  2292. "textnum" => []
  2293. ];
  2294. }
  2295. }
  2296. return Result::success($result);
  2297. }
  2298. /**
  2299. * 辅助方法:获取文章列表
  2300. */
  2301. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2302. {
  2303. sleep(1);
  2304. $query = Article::where('article.status', 1)
  2305. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2306. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2307. ->where(function ($query) use ($website) {
  2308. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2309. })
  2310. ->leftJoin('website_category', function ($join) use ($website) {
  2311. $join->on('article.catid', '=', 'website_category.category_id')
  2312. ->where('website_category.website_id', '=', $website['website_id']);
  2313. })
  2314. ->select(
  2315. 'article.id',
  2316. 'article.title',
  2317. 'article.imgurl',
  2318. 'article.author',
  2319. 'article.updated_at',
  2320. 'article.introduce',
  2321. 'article.islink',
  2322. 'article.linkurl',
  2323. 'article.copyfrom',
  2324. 'article.cat_arr_id',
  2325. 'article.catid',
  2326. 'website_category.alias as category_name'
  2327. )
  2328. ->orderBy('updated_at', 'desc')
  2329. ->limit($limit);
  2330. // 如果是图片文章,添加图片URL条件
  2331. if ($isImageArticle) {
  2332. $query->where('imgurl', '!=', '');
  2333. } else {
  2334. // 文字文章不需要imgurl字段
  2335. $query->addSelect('article.introduce');
  2336. }
  2337. $articles = $query->get();
  2338. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2339. }
  2340. /**
  2341. * 乡村网-获取特殊新闻模块
  2342. * @param array $data
  2343. * @return array
  2344. */
  2345. public function getWebsiteArticles(array $data): array
  2346. {
  2347. $website_id = $data['website_id'];
  2348. $website = Website::where('id', $website_id)->first();
  2349. if (empty($website)) {
  2350. return Result::error("网站不存在", 0);
  2351. }
  2352. // return Result::success($website);
  2353. $website_column = $website['website_column_arr_id'] ?? '[]';
  2354. $website_column = json_decode($website_column, true);
  2355. $catids = json_decode($data['id'], true);
  2356. $parent_category = array_column($catids, 'parent');
  2357. if (!empty($parent_category) && is_array($parent_category)) {
  2358. $categorys = $this->processArticlePro($website_id);
  2359. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2360. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2361. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2362. }
  2363. $catiall = $categorys['catiall'];
  2364. $cat_1st_arr = $categorys['cat_1st_arr'];
  2365. // return Result::success($categorys);
  2366. foreach ($parent_category as $key => $value) {
  2367. $arr = array_map('intval', explode(',', $value));
  2368. $parent_category = $arr[0] ?? 0;
  2369. $article_imgnum = $arr[1] ?? 0;
  2370. $article_textnum = $arr[2] ?? 0;
  2371. if ($parent_category != 0) {
  2372. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2373. // return Result::success($category_arr);
  2374. if ($article_imgnum != 0) {
  2375. $img_article = Article::whereIn('article.catid', $category_arr)
  2376. ->where('article.status', 1)
  2377. ->where('article.imgurl', '!=', '')
  2378. ->leftJoinSub(function ($query) use ($website_id) {
  2379. $query->from('article_ignore')
  2380. ->where('website_id', $website_id);
  2381. }, 'article_ignore', function ($join) {
  2382. $join->on('article_ignore.article_id', '=', 'article.id');
  2383. })
  2384. ->where(function ($query) {
  2385. $query->whereNull('article_ignore.article_id')
  2386. ->orWhere(function ($subQuery) {
  2387. $subQuery->whereNotNull('article_ignore.article_id')
  2388. ->where('article_ignore.is_ignore', 0)
  2389. ->where(function ($subSubQuery) {
  2390. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2391. ->orWhereNull('article_ignore.c_show_time');
  2392. });
  2393. });
  2394. })
  2395. ->select(
  2396. 'article.id',
  2397. 'article.title',
  2398. 'article.imgurl',
  2399. 'article.author',
  2400. 'article.updated_at',
  2401. 'article.introduce',
  2402. 'article.islink',
  2403. 'article.linkurl',
  2404. 'article.copyfrom',
  2405. 'article.cat_arr_id',
  2406. 'article.catid as category_id'
  2407. )
  2408. ->orderBy('updated_at', 'desc')
  2409. ->limit($article_imgnum)
  2410. ->get()->all();
  2411. foreach ($img_article as $k => $v) {
  2412. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2413. // return Result::success($v);
  2414. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2415. }
  2416. } else {
  2417. $img_article = [];
  2418. }
  2419. if ($article_textnum != 0) {
  2420. $text_article = Article::whereIn('article.catid', $category_arr)
  2421. ->where('article.status', 1)
  2422. ->leftJoinSub(function ($query) use ($website_id) {
  2423. $query->from('article_ignore')
  2424. ->where('website_id', $website_id);
  2425. }, 'article_ignore', function ($join) {
  2426. $join->on('article_ignore.article_id', '=', 'article.id');
  2427. })
  2428. ->where(function ($query) {
  2429. $query->whereNull('article_ignore.article_id')
  2430. ->orWhere(function ($subQuery) {
  2431. $subQuery->whereNotNull('article_ignore.article_id')
  2432. ->where('article_ignore.is_ignore', 0)
  2433. ->where(function ($subSubQuery) {
  2434. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2435. ->orWhereNull('article_ignore.c_show_time');
  2436. });
  2437. });
  2438. })
  2439. ->select(
  2440. 'article.id',
  2441. 'article.title',
  2442. 'article.author',
  2443. 'article.updated_at',
  2444. 'article.introduce',
  2445. 'article.islink',
  2446. 'article.linkurl',
  2447. 'article.copyfrom',
  2448. 'article.cat_arr_id',
  2449. 'article.catid as category_id'
  2450. )
  2451. ->orderBy('updated_at', 'desc')
  2452. ->limit($article_textnum)
  2453. ->get()->all();
  2454. foreach ($text_article as $k => $v) {
  2455. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2456. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2457. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2458. }
  2459. } else {
  2460. $text_article = [];
  2461. }
  2462. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2463. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2464. $parent[$key] = $catiall[$parent_category];
  2465. } else {
  2466. $parent[$key] = [];
  2467. }
  2468. }
  2469. }
  2470. return Result::success($parent);
  2471. }
  2472. // 封装处理商品的路由问题
  2473. function processGoods($goods, $data)
  2474. {
  2475. return $goods->map(function ($good) use ($data) {
  2476. $catid = $good->catid ?? 0;
  2477. // $pinyin = '';
  2478. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2479. if (!empty($category->pid) && $category->pid != 0) {
  2480. $level = json_decode($category->category_arr_id, true);
  2481. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2482. ->whereIn('category_id', $level)
  2483. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2484. ->get(['aLIas_pinyin'])
  2485. ->pluck('aLIas_pinyin')
  2486. ->implode('/');
  2487. } else {
  2488. $pinyin = $category->aLIas_pinyin ?? '';
  2489. }
  2490. if (isset($good->city_id) && !empty($good->city_id)) {
  2491. $city = District::where('id', $good->city_id)->first(['name']);
  2492. $good->city_name = $city->name ?? '';
  2493. }
  2494. // 解析imgurl JSON并取第一条数据
  2495. $imgUrls = json_decode($good->imgurl, true);
  2496. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2497. $good->pinyin = $pinyin;
  2498. return $good;
  2499. });
  2500. }
  2501. /**
  2502. * 获取商城首页-根据栏目id
  2503. * @param array $data
  2504. * @return array
  2505. * */
  2506. function getWebsiteCatidshop(array $data): array
  2507. {
  2508. $input['catid'] = $data['catid'];
  2509. $input['website_id'] = $data['website_id'];
  2510. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2511. $result = array_map(function ($item) use ($input) {
  2512. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2513. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2514. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2515. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2516. if (empty($category) || $category->type != 2) {
  2517. return Result::error("暂无此栏目", 0);
  2518. } else {
  2519. $website['website_id'] = $input['website_id'];
  2520. $goods = Good::where('good.status', 2)
  2521. ->where('good.website_id', $website['website_id'])
  2522. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2523. ->select(
  2524. 'good.id',
  2525. 'good.name',
  2526. 'good.imgurl',
  2527. 'good.description',
  2528. 'good.updated_at',
  2529. 'good.catid',
  2530. 'good.type_id',
  2531. 'good.price',
  2532. 'good.com',
  2533. 'good.level',
  2534. 'good.unit'
  2535. )
  2536. ->orderBy('updated_at', 'desc')
  2537. ->offset($goodStart)
  2538. ->limit($goodNum);
  2539. $all_goods = $goods->get();
  2540. $all_goods = $this->processGoods($all_goods, $website);
  2541. }
  2542. return $all_goods ?? [];
  2543. }
  2544. }, $data);
  2545. return Result::success($result);
  2546. }
  2547. /**
  2548. * 获取商品模块
  2549. * @param array $data
  2550. * @return array
  2551. * */
  2552. public function getWebsiteshop(array $data): array
  2553. {
  2554. $input['id'] = $data['id'];
  2555. $input['website_id'] = $data['website_id'];
  2556. $catid = $data['catid'];
  2557. $data = json_decode($input['id'] ?? '', true) ?? [];
  2558. $result['goods'] = array_map(function ($item) use ($input) {
  2559. // 检查parent元素是否存在且不是undefined
  2560. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2561. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2562. $website = $input['website_id'];
  2563. $query = Good::where('good.status', 2)
  2564. ->where('good.website_id', $website);
  2565. switch ($Levelid) {
  2566. case 1:
  2567. case 2:
  2568. case 3:
  2569. $goods = $query->where(function ($q) use ($Levelid) {
  2570. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2571. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2572. });
  2573. break;
  2574. case 4:
  2575. $goods = $query;
  2576. break;
  2577. case 5:
  2578. $goods = $query->where('type_id', 1);
  2579. break;
  2580. case 6:
  2581. $goods = $query->where('type_id', 2);
  2582. break;
  2583. default:
  2584. return [];
  2585. }
  2586. $all_goods = $goods
  2587. ->select(
  2588. 'good.id',
  2589. 'good.name',
  2590. 'good.imgurl',
  2591. 'good.description',
  2592. 'good.updated_at',
  2593. 'good.catid',
  2594. 'good.type_id',
  2595. 'good.price',
  2596. 'good.level',
  2597. 'good.website_id'
  2598. )
  2599. ->orderBy('updated_at', 'desc')
  2600. ->offset($goodStart)
  2601. ->limit($goodNum)
  2602. ->get();
  2603. $web['website_id'] = $website;
  2604. $all_goods = $this->processGoods($all_goods, $web);
  2605. }
  2606. return $all_goods;
  2607. }, $data);
  2608. $website = $input['website_id'];
  2609. $result['article'] = Article::where(function ($query) use ($website) {
  2610. $query->where(function ($subQuery) use ($website) {
  2611. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2612. })->orWhereNull("ignore_ids");
  2613. })
  2614. ->where('catid', $catid)
  2615. ->where('article.status', 1)
  2616. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2617. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2618. ->orderBy('article.updated_at', 'desc')
  2619. ->first();
  2620. return Result::success($result);
  2621. }
  2622. /**
  2623. * 获取商品分类
  2624. * @param array $data
  2625. * @return array
  2626. * */
  2627. public function getWebsiteshopCat(array $data): array
  2628. {
  2629. $website = $data['website_id'];
  2630. $category = WebsiteCategory::where('website_id', $website)
  2631. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2632. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2633. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2634. ->orderBy('sort')
  2635. ->get();
  2636. $cat = $category->map(function ($item) use ($website) {
  2637. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2638. $pid = $item->pid ?? 0;
  2639. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2640. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2641. ->where('website_id', $website)
  2642. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2643. ->get(['aLIas_pinyin'])
  2644. ->pluck('aLIas_pinyin')
  2645. ->implode('/');
  2646. } else {
  2647. $pinyin = $item->aLIas_pinyin ?? '';
  2648. }
  2649. $item->pinyin = $pinyin;
  2650. });
  2651. if (empty($category)) {
  2652. return Result::error("栏目查询失败", 0);
  2653. }
  2654. $cat_tree = Result::buildMenuTree($category);
  2655. $web['website_id'] = $website;
  2656. $goods = Good::where('website_id', $website)
  2657. ->where('status', 2)
  2658. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2659. ->latest('updated_at')
  2660. ->offset(($data['page'] - 1) * $data['pageSize'])
  2661. ->limit($data['pageSize'])
  2662. ->get();
  2663. if (!empty($goods)) {
  2664. if ($goods->count() > 1 && !empty($goods)) {
  2665. $goods = $this->processGoods($goods, $web);
  2666. }
  2667. } else {
  2668. $goods = [];
  2669. }
  2670. $result = [
  2671. 'category' => $cat_tree,
  2672. 'goods' => $goods,
  2673. ];
  2674. // $resul['goods'] = $goods;
  2675. if (empty($result)) {
  2676. return Result::error("查询失败", 0);
  2677. }
  2678. return Result::success($result);
  2679. }
  2680. /*
  2681. * 获取商品列表
  2682. * @param array $data
  2683. * @return array
  2684. * */
  2685. public function getWebsiteshopList(array $data): array
  2686. {
  2687. // return Result::success($data);
  2688. $where = [
  2689. 'status' => 2,
  2690. 'website_id' => $data['website_id'],
  2691. ];
  2692. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2693. // return Result::error("查询失败", 0);
  2694. // }
  2695. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2696. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2697. $data['catid'] = $category->category_id ?? 0;
  2698. }
  2699. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2700. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2701. }
  2702. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2703. array_push($where, ['type_id', $data['type_id']]);
  2704. }
  2705. $query = Good::where($where)
  2706. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2707. $query->where(function ($q) use ($data) {
  2708. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2709. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2710. });
  2711. })
  2712. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2713. $query->where(function ($q) use ($data) {
  2714. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2715. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2716. });
  2717. })
  2718. ->select(
  2719. 'good.id',
  2720. 'good.name',
  2721. 'good.imgurl',
  2722. 'good.description',
  2723. 'good.updated_at',
  2724. 'good.com',
  2725. 'good.catid',
  2726. 'good.type_id',
  2727. 'good.website_id',
  2728. 'good.cat_arr_id',
  2729. 'good.created_at',
  2730. 'good.city_id'
  2731. )
  2732. ->latest('updated_at');
  2733. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2734. $result['count'] = $query->clone()->count();
  2735. $result['goods'] = $this->processGoods(
  2736. $query->clone()
  2737. ->offset(($data['page'] - 1) * $data['pageSize'])
  2738. ->limit($data['pageSize'])
  2739. ->get(),
  2740. $data
  2741. );
  2742. } else {
  2743. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2744. // 获取 type_id 为 1 的数据
  2745. $result['type1'] = $this->processGoods(
  2746. $query->clone()
  2747. ->where('type_id', 1)
  2748. ->offset(($data['page'] - 1) * $data['pageSize'])
  2749. ->limit($data['pageSize'])
  2750. ->get(),
  2751. $data
  2752. );
  2753. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2754. // 获取 type_id 为 2 的数据
  2755. $result['type2'] = $this->processGoods(
  2756. $query->clone()
  2757. ->where('type_id', 2)
  2758. ->offset(($data['page'] - 1) * $data['pageSize'])
  2759. ->limit($data['pageSize'])
  2760. ->get(),
  2761. $data
  2762. );
  2763. }
  2764. if (empty($result)) {
  2765. return Result::error("查询失败", 0);
  2766. }
  2767. return Result::success($result);
  2768. }
  2769. /**
  2770. * 获取商品详情
  2771. * @param array $data
  2772. * @return array
  2773. * */
  2774. public function getWebsiteshopInfo(array $data): array
  2775. {
  2776. $where = [
  2777. 'good.status' => 2,
  2778. 'good.website_id' => $data['website_id'],
  2779. 'good.id' => $data['id'],
  2780. ];
  2781. $goods = Good::where($where)
  2782. ->where('good.id', $data['id'])
  2783. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2784. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2785. ->first();
  2786. if (empty($goods)) {
  2787. return Result::error("查询失败", 0);
  2788. }
  2789. $goods->imgurl = json_decode($goods->imgurl, true);
  2790. return Result::success($goods);
  2791. }
  2792. /**
  2793. * plus pro 处理文章路由问题
  2794. */
  2795. function processArticlePro($website_id)
  2796. {
  2797. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2798. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2799. // // 取出category_id 对应的aLIas_pinyin
  2800. // $categoryIds = array_column($categorys, 'category_id');
  2801. // $categoryPIds = array_column($categorys, 'pid');
  2802. // $aliasPinyins = array_column($categorys, 'path');
  2803. // $alias = array_column($categorys, 'alias');
  2804. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2805. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2806. // // return Result::success($cat_arr);
  2807. // // $catiall = [];
  2808. // //一级所有子级的记录
  2809. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2810. // return [
  2811. // 'cat_1st_arr' => $cat_alias_arr,
  2812. // 'catiall' => $cat_arr,
  2813. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2814. // 'categoryIds' => $categoryIds,
  2815. // ];
  2816. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2817. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2818. // 取出category_id 对应的aLIas_pinyin
  2819. $categoryIds = array_column($categorys, 'category_id');
  2820. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2821. return $pid != 0;
  2822. })));
  2823. $category_path = array_column($categorys, 'path');
  2824. $cat_arr = array_combine($categoryIds, $category_path);
  2825. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2826. $catiall = [];
  2827. //一级所有子级的记录
  2828. $cat_1st_arr = [];
  2829. foreach ($categorys as $key => $value) {
  2830. // $category_arr_id = json_decode($value->category_arr_id);
  2831. // $pinyin_str = '';
  2832. // // 算出一级 并且算出子级
  2833. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2834. $cat_1st_arr[$value->pid][] = $value->category_id;
  2835. }
  2836. // foreach ($category_arr_id as $k => $v) {
  2837. // $pinyin_str .= $cat_arr[$v] . '/';
  2838. // }
  2839. // $pinyin_str = rtrim($pinyin_str, '/');
  2840. $catiall[$value->category_id]['alias'] = $value->alias;
  2841. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2842. $catiall[$value->category_id]['type'] = $value->type;
  2843. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2844. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2845. }
  2846. return [
  2847. 'cat_1st_arr' => $cat_1st_arr,
  2848. 'catiall' => $catiall,
  2849. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2850. 'categoryIds' => $categoryIds,
  2851. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2852. 'categoryPIds' => $categoryPIds,
  2853. ];
  2854. }
  2855. /**
  2856. * 封装处理文章的路由问题
  2857. * */
  2858. function processArticles($articles, $data)
  2859. {
  2860. // 检查 $articles 是否为数组或可迭代对象
  2861. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2862. return $articles->map(function ($article) use ($data) {
  2863. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2864. $catid = $article->cat_arr_id ?? '';
  2865. }
  2866. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2867. $catid = $article->category_arr_id ?? '';
  2868. }
  2869. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2870. $level = json_decode($catid, true);
  2871. if (!is_array($level)) {
  2872. return $article;
  2873. } else {
  2874. $level = array_map('intval', $level);
  2875. }
  2876. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2877. ->where($data)
  2878. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2879. ->pluck('aLIas_pinyin')
  2880. ->implode('/');
  2881. $article->pinyin = $pinyin ?? '';
  2882. return $article;
  2883. });
  2884. } else {
  2885. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2886. $catid = $articles->cat_arr_id ?? '';
  2887. $level = json_decode($catid, true);
  2888. if (!is_array($level)) {
  2889. return $articles;
  2890. } else {
  2891. $level = array_map('intval', $level);
  2892. }
  2893. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2894. ->where($data)
  2895. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2896. ->pluck('aLIas_pinyin')
  2897. ->implode('/');
  2898. $articles->pinyin = $pinyin ?? '';
  2899. return $articles;
  2900. }
  2901. }
  2902. // 封装处理由问题
  2903. function processJob($job, $data)
  2904. {
  2905. return $job->map(function ($job) use ($data) {
  2906. $category = $job->cat_arr_id ?? '';
  2907. $cityid = $job->city_arr_id ?? '';
  2908. $city = json_decode($cityid, true);
  2909. $pinyin = '';
  2910. $level = json_decode($category, true);
  2911. // 路由
  2912. if (!empty($level) && is_array($level)) {
  2913. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2914. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2915. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2916. ->get(['aLIas_pinyin'])
  2917. ->pluck('aLIas_pinyin')
  2918. ->implode('/');
  2919. if (empty($pinyin)) {
  2920. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2921. }
  2922. $job->pinyin = $pinyin;
  2923. }
  2924. // 取职位-城市 市??省
  2925. if (!empty($city) && is_array($city)) {
  2926. if (isset($city[1]) && !empty($city[1])) {
  2927. $city = District::where('id', $city[1])->first(['name']);
  2928. $job->city_name = $city->name ?? '';
  2929. } else if (isset($city[0]) && !empty($city[0])) {
  2930. $city = District::where('id', $city[0])->first(['name']);
  2931. $job->city_name = $city->name ?? '';
  2932. } else {
  2933. $job->city_name = '全国';
  2934. }
  2935. }
  2936. // 获取简历最后一级地区
  2937. if (isset($job->city_id) && !empty($job->city_id)) {
  2938. $city = District::where('id', $job->city_id)->first(['name']);
  2939. $job->hunt_cityname = $city->name ?? '';
  2940. }
  2941. // 组合详细地址
  2942. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2943. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2944. if (is_array($address_id) && !empty($address_id)) {
  2945. $address = District::whereIn('id', $address_id)
  2946. ->orderBy('level', 'asc')
  2947. ->get(['name'])
  2948. ->pluck('name')
  2949. ->implode('');
  2950. // $job->address_name = $address ?? '';
  2951. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2952. }
  2953. }
  2954. // 取行业
  2955. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2956. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2957. if (!empty($job->industry)) {
  2958. $query->where('hyid', $job->industry);
  2959. } else if (!empty($job->hy_id)) {
  2960. $query->where('hyid', $job->hy_id);
  2961. } else if (!empty($job->company_hy_id)) {
  2962. $query->where('hyid', $job->company_hy_id);
  2963. } else {
  2964. $query->where('hyid', $job->job_industry);
  2965. }
  2966. })->first(['hyname']);
  2967. $job->hy_name = $hy_name->hyname ?? '';
  2968. }
  2969. // 取职位类别
  2970. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2971. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2972. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2973. $job->zw_name = $zw_name->zwname ?? '';
  2974. }
  2975. // 取具体职位
  2976. 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))) {
  2977. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2978. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2979. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2980. }
  2981. // 取工作经验
  2982. if (isset($job->experience) && !empty($job->experience)) {
  2983. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2984. $job->experience_name = $experience->ename ?? '';
  2985. }
  2986. // 取学历
  2987. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2988. $education = $job->educational ?? $job->school_education;
  2989. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2990. $job->education_name = $education->ename ?? '';
  2991. }
  2992. // 语言
  2993. if (isset($job->language) && !empty($job->language)) {
  2994. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2995. $job->language_name = $language->ename ?? '';
  2996. }
  2997. // 薪资
  2998. if (isset($job->salary) && !empty($job->salary)) {
  2999. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3000. $job->salary_name = $salary->ename ?? '';
  3001. }
  3002. // 职位性质
  3003. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3004. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3005. $job->job_nature_name = $job_nature->ename ?? '';
  3006. }
  3007. // 公司规模
  3008. if (isset($job->company_size) && !empty($job->company_size)) {
  3009. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3010. $job->company_size_name = $company_size->ename ?? '';
  3011. }
  3012. // 公司性质
  3013. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3014. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3015. $job->company_nature_name = $company_nature->nature_name ?? '';
  3016. }
  3017. // $job->pinyin = $pinyin;
  3018. return $job;
  3019. });
  3020. }
  3021. /**
  3022. * 获取书籍模块
  3023. * @param array $data
  3024. * @return array
  3025. * */
  3026. public function getWebsiteBook(array $data): array
  3027. {
  3028. $input['id'] = $data['id'];
  3029. $input['website_id'] = $data['website_id'];
  3030. // 将 JSON 字符串转换为 PHP 数组
  3031. $data = json_decode($input['id'], true);
  3032. // 使用 array_map 处理每个元素
  3033. $result = array_map(function ($item) use ($input) {
  3034. // 检查parent元素是否存在且不是undefined
  3035. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3036. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3037. $website = [
  3038. 'website_id' => $input['website_id'],
  3039. ];
  3040. // 查询栏目名称
  3041. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3042. if (empty($category)) {
  3043. $parent_alias = '';
  3044. $parent_pinyin = null;
  3045. $imgBooks = [];
  3046. $textBooks = [];
  3047. } else {
  3048. $parent_alias = $category->alias ?? '';
  3049. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3050. // 查找子分类ID数组
  3051. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3052. array_push($childCategoryIds, $parentCatId);
  3053. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3054. if ($parentImgNum != 0) {
  3055. // 查询图片新闻
  3056. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3057. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3058. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3059. })
  3060. ->where('book.status', 2)
  3061. ->where('book.img_url', '!=', '')
  3062. ->where('book.website_id', $website['website_id'])
  3063. ->leftJoin('website_category', function ($join) use ($website) {
  3064. $join->on('book.cat_id', '=', 'website_category.category_id')
  3065. ->where('website_category.website_id', '=', $website['website_id']);
  3066. })
  3067. ->select(
  3068. 'book.id',
  3069. 'book.title',
  3070. 'book.img_url',
  3071. 'book.price',
  3072. 'book.market_price',
  3073. 'book.description',
  3074. 'book.cat_id',
  3075. 'book.description',
  3076. 'book.updated_at',
  3077. 'website_category.alias as category_name',
  3078. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3079. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3080. )
  3081. ->orderBy('updated_at', 'desc')
  3082. ->limit($parentImgNum)
  3083. ->get()->all();
  3084. // 查询文字新闻
  3085. }
  3086. if ($parentTextNum != 0) {
  3087. $textBooks = [];
  3088. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3089. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3090. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3091. })
  3092. ->where('book.status', 2)
  3093. ->where('book.website_id', $website['website_id'])
  3094. ->leftJoin('website_category', function ($join) use ($website) {
  3095. $join->on('book.cat_id', '=', 'website_category.category_id')
  3096. ->where('website_category.website_id', '=', $website['website_id']);
  3097. })
  3098. ->select(
  3099. 'book.id',
  3100. 'book.title',
  3101. 'book.img_url',
  3102. 'book.price',
  3103. 'book.market_price',
  3104. 'book.description',
  3105. 'book.cat_id',
  3106. 'book.description',
  3107. 'book.updated_at',
  3108. 'website_category.alias as category_name',
  3109. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3110. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3111. )
  3112. ->orderBy('updated_at', 'desc')
  3113. ->limit($parentTextNum)
  3114. ->get()->all();
  3115. }
  3116. }
  3117. }
  3118. $resultItem = [
  3119. 'alias' => $parent_alias ?? '',
  3120. 'category_id' => $parentCatId ?? 0,
  3121. 'pinyin' => $parent_pinyin ?? null,
  3122. 'imgnum' => $imgBooks ?? [],
  3123. 'textnum' => $textBooks ?? [],
  3124. ];
  3125. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3126. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3127. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3128. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3129. ->get()->all();
  3130. if (!empty($childCategory)) {
  3131. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3132. // 查询子栏目名称
  3133. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3134. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3135. ->first();
  3136. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3137. $childImgArticles = [];
  3138. $childTextArticles = [];
  3139. $resultItem['child'] = [];
  3140. } else {
  3141. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3142. // 查询子栏目图片新闻
  3143. $childImgArticles = Book::where('cat_id', $childCatId)
  3144. ->where('status', 2)
  3145. ->where('img_url', '!=', '')
  3146. ->where('book.website_id', $website['website_id'])
  3147. ->leftJoin('website_category', function ($join) use ($website) {
  3148. $join->on('book.cat_id', '=', 'website_category.category_id')
  3149. ->where('website_category.website_id', '=', $website['website_id']);
  3150. })
  3151. ->select(
  3152. 'book.id',
  3153. 'book.title',
  3154. 'book.img_url',
  3155. 'book.price',
  3156. 'book.market_price',
  3157. 'book.description',
  3158. 'book.cat_id',
  3159. 'book.description',
  3160. 'book.updated_at',
  3161. DB::raw("'$child_pinyin' as pinyin")
  3162. )
  3163. ->orderBy('updated_at', 'desc')
  3164. ->limit($childImgNum)
  3165. ->get()->all();
  3166. // 查询子栏目文字新闻
  3167. $childTextArticles = Book::where('cat_id', $childCatId)
  3168. ->where('status', 2)
  3169. ->where('book.website_id', $website['website_id'])
  3170. ->leftJoin('website_category', function ($join) use ($website) {
  3171. $join->on('book.cat_id', '=', 'website_category.category_id')
  3172. ->where('website_category.website_id', '=', $website['website_id']);
  3173. })
  3174. ->select(
  3175. 'book.id',
  3176. 'book.title',
  3177. 'book.img_url',
  3178. 'book.price',
  3179. 'book.market_price',
  3180. 'book.description',
  3181. 'book.cat_id',
  3182. 'book.description',
  3183. 'book.updated_at',
  3184. DB::raw("'$child_pinyin' as pinyin")
  3185. )
  3186. ->orderBy('updated_at', 'desc')
  3187. ->limit($childTextNum)
  3188. ->get()->all();
  3189. $resultItem['child'] = [
  3190. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3191. 'category_id' => $childCatId,
  3192. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3193. 'all_childcat' => $childCategory,
  3194. 'imgnum' => $childImgArticles,
  3195. 'textnum' => $childTextArticles,
  3196. ];
  3197. }
  3198. }
  3199. } else {
  3200. $resultItem['child'] = [];
  3201. }
  3202. return $resultItem;
  3203. }, $data);
  3204. return Result::success($result);
  3205. }
  3206. /**
  3207. * 获取书刊列表
  3208. * @param array $data
  3209. * @return array
  3210. * */
  3211. public function getWebsiteBookList(array $data): array
  3212. {
  3213. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3214. if (empty($web)) {
  3215. return Result::error("查询失败", 0);
  3216. }
  3217. $catid = $data['id'];
  3218. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3219. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3220. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3221. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3222. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3223. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3224. ->where('pid', $category['pid'])
  3225. ->select(
  3226. 'category_id',
  3227. 'alias',
  3228. 'aLIas_pinyin',
  3229. 'pid',
  3230. 'sort',
  3231. 'is_url',
  3232. 'web_url',
  3233. 'seo_title',
  3234. 'seo_keywords',
  3235. 'seo_description',
  3236. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3237. )
  3238. ->orderBy('sort')
  3239. ->get()->all();
  3240. if (empty($category)) {
  3241. return Result::error("查询失败", 0);
  3242. }
  3243. $query = Book::where('book.status', 2)
  3244. ->where('book.website_id', $data['website_id'])
  3245. ->where('book.cat_id', $catid)
  3246. ->select(
  3247. 'book.id',
  3248. 'book.title',
  3249. 'book.img_url',
  3250. 'book.description',
  3251. 'book.updated_at',
  3252. 'book.cat_id',
  3253. DB::raw("'$pinyin' as pinyin")
  3254. )
  3255. ->orderBy('book.updated_at', 'desc');
  3256. $count = $query->count();
  3257. $query = clone $query;
  3258. $Book = $query
  3259. ->limit($data['pageSize'])
  3260. ->offset(($data['page'] - 1) * $data['pageSize'])
  3261. ->get()->all();
  3262. $result = [
  3263. 'category' => $categorys,
  3264. 'books' => $Book,
  3265. 'count' => $count,
  3266. ];
  3267. // if(empty($result)){
  3268. // return Result::error("查询失败", 0);
  3269. // }
  3270. return Result::success($result);
  3271. }
  3272. /**
  3273. * 获取书刊详情
  3274. * @param array $data
  3275. * @return array
  3276. * */
  3277. public function getWebsiteBookInfo(array $data): array
  3278. {
  3279. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3280. if (empty($web)) {
  3281. return Result::error("查询失败", 0);
  3282. }
  3283. $book = Book::where('status', 2)
  3284. ->where('website_id', $data['website_id'])
  3285. ->where('id', $data['id'])
  3286. ->select(
  3287. 'book.*',
  3288. )
  3289. ->orderBy('updated_at', 'desc')
  3290. ->first();
  3291. if (empty($book)) {
  3292. return Result::error("查询失败", 0);
  3293. }
  3294. // 先查询当前分类的 pid
  3295. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3296. ->where('category_id', $book['cat_id'])
  3297. ->first(['pid', 'category_id']);
  3298. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3299. if (!empty($carpid)) {
  3300. if ($carpid->pid != 0) {
  3301. $pid = $carpid['pid'];
  3302. // $parent_pinyin = '';
  3303. } else {
  3304. $pid = $carpid['category_id'];
  3305. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3306. }
  3307. }
  3308. $categorys = $query->where('pid', $pid)
  3309. ->select(
  3310. 'category_id',
  3311. 'alias',
  3312. 'aLIas_pinyin',
  3313. 'pid',
  3314. 'sort',
  3315. 'is_url',
  3316. 'web_url',
  3317. 'category_arr_id as cat_arr_id',
  3318. )
  3319. ->orderBy('sort')
  3320. ->get();
  3321. $category = $this->processArticle($categorys, $data);
  3322. $result = [
  3323. 'category' => $category,
  3324. 'books' => $book,
  3325. ];
  3326. return Result::success($result);
  3327. }
  3328. /**
  3329. * 尝试
  3330. * @param array $data
  3331. * @return array
  3332. * */
  3333. public function test(array $data): array
  3334. {
  3335. $input['id'] = $data['id'];
  3336. $input['website_id'] = $data['website_id'];
  3337. // 将 JSON 字符串转换为 PHP 数组
  3338. $data = json_decode($input['id'], true);
  3339. $result = [];
  3340. $article = $data;
  3341. $result = array_map(function ($item) use ($input) {
  3342. $website = [
  3343. 'website_id' => $input['website_id'],
  3344. ];
  3345. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3346. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3347. $parent = [
  3348. 0 => $category['category_id'] ?? [],
  3349. 1 => $parentImgNum ?? [],
  3350. 2 => $parentTextNum ?? [],
  3351. ];
  3352. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3353. $child = [];
  3354. $resultItem = [
  3355. // 'alias' => $parent_alias ?? '',
  3356. 'category_id' => $parentCatId ?? 0,
  3357. 'pinyin' => $parentImgNum ?? null,
  3358. 'imgnum' => $parentTextNum ?? [],
  3359. // 'textnum' => $textArticles ?? [],
  3360. ];
  3361. return $parent;
  3362. }, $data);
  3363. return Result::success($result);
  3364. // });
  3365. }
  3366. /**
  3367. * 封装处理文章的路由问题
  3368. * */
  3369. function processArticle($article, $data)
  3370. {
  3371. return $article->map(function ($article) use ($data) {
  3372. $catid = $article->cat_arr_id ?? '';
  3373. $level = json_decode($catid, true);
  3374. $pinyin = '';
  3375. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3376. if (!empty($level) && is_array($level)) {
  3377. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3378. ->where('website_id', $data['website_id'])
  3379. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3380. ->get(['aLIas_pinyin'])
  3381. ->pluck('aLIas_pinyin')
  3382. ->implode('/');
  3383. } else {
  3384. $pinyin = '';
  3385. }
  3386. $article->pinyin = $pinyin;
  3387. return $article;
  3388. });
  3389. }
  3390. /**
  3391. * c端-获取招工招聘下拉选框
  3392. * @param array $data
  3393. * @return array
  3394. * */
  3395. public function getWebsiteJobSelect(array $data): array
  3396. {
  3397. $web = Website::where('id', $data['website_id'])->first();
  3398. if (empty($web)) {
  3399. return Result::error("该网站不存在", 0);
  3400. }
  3401. $hy = JobIndustry::get()->all();
  3402. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3403. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3404. $result = [
  3405. 'hy' => $hy,
  3406. 'zw' => $zw,
  3407. 'jtzw' => $jtzw,
  3408. ];
  3409. if (empty($result)) {
  3410. return Result::error("查询失败", 0);
  3411. }
  3412. return Result::success($result);
  3413. }
  3414. /**
  3415. * c端-获取招工招聘
  3416. * @param array $data
  3417. * @return array
  3418. * */
  3419. public function getWebsiteJob(array $data): array
  3420. {
  3421. $web = Website::where('id', $data['website_id'])->first();
  3422. if (empty($web)) {
  3423. return Result::error("该网站不存在", 0);
  3424. }
  3425. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3426. ->where('job_hunting.website_id', $data['website_id'])
  3427. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3428. $query->where(function ($q) use ($data) {
  3429. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3430. });
  3431. })
  3432. ->select(
  3433. 'job_hunting.id',
  3434. 'job_hunting.catid',
  3435. 'job_hunting.cat_arr_id',
  3436. 'job_hunting.job_name_get',
  3437. 'job_hunting.industry',
  3438. 'job_hunting.name',
  3439. 'job_hunting.sexy',
  3440. 'job_hunting.origin',
  3441. 'job_hunting.city_arr_id',
  3442. 'job_hunting.experience',
  3443. 'job_hunting.updated_at',
  3444. 'job_hunting.salary',
  3445. 'job_hunting.skillList',
  3446. 'job_hunting.slelf_evaluation',
  3447. )
  3448. ->orderBy('updated_at', 'desc')
  3449. ->limit($data['job1_num'])
  3450. ->get();
  3451. $web['website_id'] = $data['website_id'];
  3452. if (empty($job_hunting)) {
  3453. $job_huntings = "未查询到相关简历信息";
  3454. } else {
  3455. $job_huntings = $this->processJob($job_hunting, $web);
  3456. }
  3457. // 0:待审核 1:已通过 2:已拒绝
  3458. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3459. ->where('job_recruiting.website_id', $data['website_id'])
  3460. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3461. $query->where(function ($q) use ($data) {
  3462. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3463. });
  3464. })
  3465. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3466. ->select(
  3467. 'job_recruiting.id',
  3468. 'job_recruiting.catid',
  3469. 'job_recruiting.cat_arr_id',
  3470. 'job_recruiting.title',
  3471. 'job_recruiting.jtzw_id',
  3472. 'job_recruiting.hy_id',
  3473. 'job_recruiting.city_arr_id',
  3474. 'job_recruiting.due_data',
  3475. 'job_recruiting.updated_at',
  3476. 'job_recruiting.experience',
  3477. 'job_recruiting.educational',
  3478. 'job_recruiting.salary',
  3479. 'job_recruiting.zw_id',
  3480. 'job_company.business_name',
  3481. 'job_recruiting.keyword',
  3482. 'job_recruiting.description',
  3483. )
  3484. ->orderBy('updated_at', 'desc')
  3485. ->limit($data['job2_num'])
  3486. ->get();
  3487. if (empty($job_recruiting->toArray())) {
  3488. $job_recruitings = "未查询到相关职位信息";
  3489. } else {
  3490. $job_recruitings = $this->processJob($job_recruiting, $web);
  3491. }
  3492. $result = [
  3493. 'job_hunting' => $job_huntings,
  3494. 'job_recuiting' => $job_recruitings,
  3495. ];
  3496. return Result::success($result);
  3497. }
  3498. /**
  3499. * c端-获取招工招聘列表
  3500. * @param array $data
  3501. * @return array
  3502. * */
  3503. public function getWebsiteJobList(array $data): array
  3504. {
  3505. $recruit_where = [];
  3506. $hunt_where = [];
  3507. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3508. if (empty($web)) {
  3509. return Result::error("此网站不存在", 0);
  3510. }
  3511. $website_id['website_id'] = $data['website_id'];
  3512. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3513. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3514. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3515. }
  3516. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3517. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3518. }
  3519. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3520. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3521. }
  3522. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3523. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3524. }
  3525. $query = JobRecruiting::where('job_recruiting.status', 1)
  3526. ->where('job_recruiting.website_id', $data['website_id'])
  3527. ->where($recruit_where)
  3528. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3529. $query->where(function ($q) use ($data) {
  3530. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3531. });
  3532. })
  3533. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3534. $query->where(function ($q) use ($data) {
  3535. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3536. });
  3537. })
  3538. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3539. ->select(
  3540. 'job_recruiting.id',
  3541. 'job_recruiting.catid',
  3542. 'job_recruiting.hy_id',
  3543. 'job_recruiting.title',
  3544. 'job_recruiting.zw_id',
  3545. 'job_recruiting.educational',
  3546. 'job_recruiting.jtzw_id',
  3547. 'job_recruiting.city_arr_id',
  3548. 'job_recruiting.due_data',
  3549. 'job_recruiting.experience',
  3550. 'job_recruiting.cat_arr_id',
  3551. 'job_recruiting.updated_at',
  3552. 'job_company.business_name',
  3553. 'job_recruiting.keyword',
  3554. 'job_recruiting.description',
  3555. )
  3556. ->orderBy('job_recruiting.updated_at', 'desc');
  3557. $recruit_count = $query->count();
  3558. $query = clone $query;
  3559. $JobRecruiting = $query
  3560. ->offset(($data['page'] - 1) * $data['pageSize'])
  3561. ->limit($data['pageSize'])
  3562. ->get();
  3563. if (empty($JobRecruiting)) {
  3564. $JobRecruiting = "暂无相关职位信息";
  3565. } else {
  3566. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3567. }
  3568. }
  3569. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3570. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3571. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3572. }
  3573. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3574. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3575. }
  3576. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3577. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3578. }
  3579. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3580. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3581. }
  3582. $query = JobHunting::where('job_hunting.status', 2)
  3583. ->where('job_hunting.website_id', $data['website_id'])
  3584. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3585. ->where($hunt_where)
  3586. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3587. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3588. // })
  3589. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3590. $query->where(function ($q) use ($data) {
  3591. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3592. });
  3593. })
  3594. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3595. $query->where(function ($q) use ($data) {
  3596. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3597. });
  3598. })
  3599. ->select(
  3600. 'job_hunting.id',
  3601. 'job_hunting.catid',
  3602. 'job_hunting.sexy',
  3603. 'job_hunting.experience',
  3604. 'job_hunting.origin',
  3605. 'job_hunting.industry',
  3606. 'job_hunting.name',
  3607. 'job_hunting.job',
  3608. 'job_hunting.job_name_get',
  3609. 'job_hunting.city_arr_id',
  3610. 'job_hunting.cat_arr_id',
  3611. 'job_hunting.created_at',
  3612. 'job_hunting.updated_at',
  3613. 'job_position.zwname as job_name',
  3614. 'job_hunting.skillList',
  3615. 'job_hunting.slelf_evaluation',
  3616. )
  3617. ->orderBy('job_hunting.updated_at', 'desc');
  3618. $hunt_count = $query->count();
  3619. $query = clone $query;
  3620. $JobHunting = $query
  3621. ->offset(($data['page'] - 1) * $data['pageSize'])
  3622. ->limit($data['pageSize'])
  3623. ->get();
  3624. if (empty($JobHunting)) {
  3625. $JobRecruiting = "暂无相关简历信息";
  3626. } else {
  3627. $JobHunting = $this->processJob($JobHunting, $website_id);
  3628. }
  3629. }
  3630. $result = [
  3631. 'JobRecruiting' => $JobRecruiting ?? [],
  3632. 'recruit_count' => $recruit_count ?? 0,
  3633. 'JobHunting' => $JobHunting ?? [],
  3634. 'hunt_count' => $hunt_count ?? 0,
  3635. ];
  3636. return Result::success($result);
  3637. }
  3638. /**
  3639. * c端-获取招工招聘详情
  3640. * @param array $data
  3641. * @return array
  3642. * */
  3643. public function getWebsiteJobInfo(array $data): array
  3644. {
  3645. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3646. if (empty($web)) {
  3647. return Result::error("该网站不存在", 0);
  3648. }
  3649. $webid = [
  3650. 'website_id' => $data['website_id'],
  3651. ];
  3652. // 职位相关信息
  3653. if ($data['type'] == 1) {
  3654. $query = JobRecruiting::where('status', 1)
  3655. ->where('website_id', $data['website_id'])
  3656. ->select('*');
  3657. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3658. $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();
  3659. if (!empty($company)) {
  3660. $result['company'] = $this->processJob($company, $webid);
  3661. }
  3662. $other_job = JobRecruiting::where('status', 1)
  3663. ->where('website_id', $data['website_id'])
  3664. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3665. ->where('id', '!=', $data['id'])
  3666. ->where('user_id', '=', $job[0]['user_id'])
  3667. ->limit($data['pageSize'])
  3668. ->get();
  3669. if (!empty($other_job)) {
  3670. $result['other_job'] = $this->processJob($other_job, $webid);
  3671. }
  3672. } else {
  3673. // 简历相关信息
  3674. $job = JobHunting::where('job_hunting.status', 2)
  3675. ->where('job_hunting.website_id', $data['website_id'])
  3676. ->where('job_hunting.id', $data['id'])
  3677. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3678. ->select('job_hunting.*', 'user_name')
  3679. ->get();
  3680. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3681. if (!empty($resume->toArray())) {
  3682. $result['resume'] = 1;
  3683. } else {
  3684. $result['resume'] = 0;
  3685. }
  3686. }
  3687. if (empty($job->toArray())) {
  3688. return Result::error("id参数错误", 0);
  3689. }
  3690. if (!empty($job[0]['job_experience'])) {
  3691. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3692. if (!empty($job_experience)) {
  3693. // $hy = [];
  3694. foreach ($job_experience as $key => $value) {
  3695. // $id = $value['id'];
  3696. $hy[$key] = $value['job_industry'];
  3697. $zw_id[$key] = $value['job_typename'];
  3698. $jtzw_id[$key] = $value['job_name'];
  3699. }
  3700. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3701. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3702. // 先将关联表转换为索引数组,提高查找效率
  3703. $hyLookup = [];
  3704. foreach ($hy_table as $item) {
  3705. $hyLookup[$item['hyid']] = $item['hyname'];
  3706. }
  3707. $zwLookup = [];
  3708. foreach ($zw_table as $item) {
  3709. $zwLookup[$item['zwid']] = $item['zwname'];
  3710. }
  3711. foreach ($job_experience as $key => &$value) {
  3712. // 处理行业名称
  3713. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3714. $value['hy_name'] = $hyLookup[$hy[$key]];
  3715. }
  3716. // 处理职位名称
  3717. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3718. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3719. }
  3720. // 处理具体职位名称
  3721. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3722. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3723. }
  3724. }
  3725. // 释放引用,防止意外修改后续代码
  3726. unset($value);
  3727. }
  3728. $result['job_experience'] = $job_experience ?? [];
  3729. }
  3730. if (!empty($job[0]['education_experience'])) {
  3731. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3732. if (!empty($education_experience)) {
  3733. foreach ($education_experience as $key => $value) {
  3734. // $id = $value['id'];
  3735. $education[$key] = $value['school_education'];
  3736. }
  3737. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3738. // // 先将关联表转换为索引数组,提高查找效率
  3739. $educationLookup = [];
  3740. foreach ($education_table as $item) {
  3741. $educationLookup[$item['evalue']] = $item['ename'];
  3742. }
  3743. foreach ($education_experience as $key => &$value) {
  3744. // 处理学历名称
  3745. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3746. $value['education_name'] = $educationLookup[$education[$key]];
  3747. }
  3748. }
  3749. }
  3750. $result['education_experience'] = $job_experience ?? [];
  3751. }
  3752. $result['job'] = $this->processJob($job, $webid);
  3753. // // 返现对应的栏目
  3754. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3755. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3756. ->whereIn('category_id', $catid)
  3757. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3758. ->orderBy('pid')->get()->all();
  3759. if (!empty($category)) {
  3760. $result['category'] = $category;
  3761. }
  3762. $result['job'] = $job;
  3763. $result['job_experience'] = $job_experience ?? [];
  3764. $result['education_experience'] = $education_experience ?? [];
  3765. if (empty($result)) {
  3766. return Result::error("参数错误", 0);
  3767. }
  3768. return Result::success($result);
  3769. }
  3770. /**
  3771. * c端-申请职位
  3772. * @param array $data
  3773. * @return array
  3774. * */
  3775. public function getWebsiteJobApply(array $data): array
  3776. {
  3777. // 首先验证网站是否存在
  3778. // return Result::success($data);
  3779. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3780. if (empty($web)) {
  3781. return Result::error("该网站不存在", 0);
  3782. }
  3783. // 验证用户是否存在且为个人会员/管理员
  3784. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3785. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3786. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3787. return Result::error("用户不存在", 0);
  3788. }
  3789. // 去除重复元素和空元素,并保持原始顺序
  3790. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3791. return !empty($value);
  3792. }));
  3793. // 验证职位是否存在 1:审核通过
  3794. $recruiting = JobRecruiting::where('status', 1)
  3795. ->where('website_id', $data['website_id'])
  3796. ->whereIn('id', $data['recruit_id'])
  3797. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3798. if (empty($recruiting)) {
  3799. return Result::error("该职位不存在", 0);
  3800. }
  3801. // 简历是否存在
  3802. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3803. if (empty($hunt_id)) {
  3804. return Result::error("该简历不存在", 0);
  3805. }
  3806. $data['hunt_id'] = $hunt_id['hunt_id'];
  3807. // // 验证是否已投递过该职位
  3808. $apply = JobApply::where('user_id', $data['user_id'])
  3809. ->where('hunt_id', $data['hunt_id'])
  3810. ->where('website_id', $data['website_id'])
  3811. ->whereIn('recruit_id', $data['recruit_id'])
  3812. ->get(['recruit_id']);
  3813. if (!empty($apply->toArray())) {
  3814. return Result::error("您已投递过该职位!");
  3815. }
  3816. $insertData = array_map(function ($recruiting) use ($data) {
  3817. return [
  3818. 'user_id' => $data['user_id'],
  3819. 'hunt_id' => $data['hunt_id'],
  3820. 'website_id' => $data['website_id'],
  3821. 'recruit_id' => $recruiting['recruit_id'],
  3822. 'receiver_id' => $recruiting['receiver_id'],
  3823. 'status' => 1,
  3824. ];
  3825. }, $recruiting);
  3826. // 批量插入数据
  3827. $result = JobApply::insert($insertData);
  3828. if (empty($result)) {
  3829. return Result::error("投递失败", 0);
  3830. }
  3831. return Result::success($result);
  3832. }
  3833. /**
  3834. * 招工招聘-沟通简历
  3835. * @param array $data
  3836. * @return array
  3837. * */
  3838. public function getWebsiteJobResume(array $data): array
  3839. {
  3840. // 首先验证网站是否存在
  3841. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3842. if (empty($web)) {
  3843. return Result::error("该网站不存在", 0);
  3844. }
  3845. // return Result::success($data);
  3846. // 验证用户是否存在且为企业会员/管理员
  3847. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3848. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3849. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3850. return Result::error("用户不存在", 0);
  3851. }
  3852. // 去除重复元素和空元素,并保持原始顺序
  3853. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3854. return !empty($value);
  3855. }));
  3856. // 验证简历是否存在
  3857. $hunting = JobHunting::where('status', 2)
  3858. ->where('website_id', $data['website_id'])
  3859. ->whereIn('id', $data['hunt_id'])
  3860. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3861. if (empty($hunting)) {
  3862. return Result::error("该简历不存在", 0);
  3863. }
  3864. // 验证是否已沟通过该简历
  3865. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3866. ->where('recruit_id', $data['recruit_id'])
  3867. ->where('website_id', $data['website_id'])
  3868. ->whereIn('hunt_id', $data['hunt_id'])
  3869. ->get(['hunt_id']);
  3870. if (!empty($remuse->toArray())) {
  3871. return Result::error("您已沟通过该简历!");
  3872. }
  3873. // 准备要插入的数据数组
  3874. $insertData = array_map(function ($hunting) use ($data) {
  3875. return [
  3876. 'user_id' => $data['user_id'],
  3877. 'recruit_id' => $data['recruit_id'],
  3878. 'website_id' => $data['website_id'],
  3879. 'hunt_id' => $hunting['hunt_id'],
  3880. 'receiver_id' => $hunting['receiver_id'],
  3881. 'status' => 1,
  3882. ];
  3883. }, $hunting);
  3884. // 批量插入数据
  3885. $result = JobRemuse::insert($insertData);
  3886. if (empty($result)) {
  3887. return Result::error("沟通失败", 0);
  3888. }
  3889. return Result::success($result);
  3890. }
  3891. /**
  3892. * 招工招聘 -我的职位(企业会员)
  3893. * @param array $data
  3894. * @return array
  3895. */
  3896. public function getWebsiteJobRecruiting(array $data): array
  3897. {
  3898. $web = Website::where('id', $data['website_id'])->first('id');
  3899. if (empty($web)) {
  3900. return Result::error("该网站不存在", 0);
  3901. }
  3902. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3903. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3904. return Result::error("用户暂无权限!", 0);
  3905. }
  3906. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3907. $result = JobRecruiting::where('website_id', $data['website_id'])
  3908. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3909. $query->where('user_id', $user['id']);
  3910. })
  3911. ->where('status', 1)
  3912. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3913. ->orderBy('updated_at', 'desc')
  3914. ->limit($data['pageSize'])
  3915. ->get();
  3916. if (empty($result)) {
  3917. return Result::error("暂无相关职位信息", 0);
  3918. }
  3919. return Result::success($result);
  3920. }
  3921. /**
  3922. * c端 - 验证路由
  3923. * @param array $data
  3924. * @return array
  3925. */
  3926. /**
  3927. * c端 - 验证路由
  3928. * @param array $data
  3929. * @return array
  3930. */
  3931. public function checkWebsiteRoute(array $data): array
  3932. {
  3933. // 测试001111111222
  3934. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3935. if (empty($web)) {
  3936. return Result::error("该网站不存在", 0);
  3937. } elseif ($web['status'] != 1) {
  3938. return Result::error("网站已经关闭", 0);
  3939. }
  3940. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3941. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3942. // 验证路由是否存在
  3943. if (empty($whiteRouterInfo)) {
  3944. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3945. }
  3946. if (!empty($whiteRouterInfo)) {
  3947. return Result::success($whiteRouterInfo->toArray());
  3948. }
  3949. }
  3950. // 验证栏目路由
  3951. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3952. ->where('path', $data['all_route'])
  3953. ->get()->all();
  3954. if (count($last_category) == 0) {
  3955. return Result::error("该栏目不存在", 0);
  3956. }
  3957. if (count($last_category) > 1) {
  3958. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3959. }
  3960. if (count($last_category) == 1) {
  3961. $last_category = $last_category[0];
  3962. }
  3963. // return Result::success($last_category);
  3964. if (isset($data['id']) && !empty($data['id'])) {
  3965. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3966. switch ($last_category['type']) {
  3967. case 1:
  3968. // 文章
  3969. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3970. $article = Article::where('status', 1)
  3971. ->where('id', $data['id'])
  3972. ->where(function ($query) use ($data) {
  3973. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3974. ->orWhereNull("ignore_ids");
  3975. })
  3976. ->first(['catid']);
  3977. if (empty($article)) {
  3978. return Result::error("该文章不存在", 0);
  3979. }
  3980. // return Result::success($article);
  3981. break;
  3982. case 2:
  3983. // 商品
  3984. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3985. $article = Good::where('website_id', $data['website_id'])
  3986. ->where('status', 2)
  3987. ->where('id', $data['id'])
  3988. ->first(['cat_arr_id']);
  3989. if (empty($article)) {
  3990. return Result::error("该商品不存在", 0);
  3991. }
  3992. break;
  3993. case 3:
  3994. // 书刊信息
  3995. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3996. $article = Book::where('website_id', $data['website_id'])
  3997. ->where('status', 2)
  3998. ->where('id', $data['id'])
  3999. ->first(['id', 'cat_arr_id']);
  4000. if (empty($article)) {
  4001. return Result::error("该书刊不存在", 0);
  4002. }
  4003. break;
  4004. case 4:
  4005. // 招聘
  4006. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4007. $article = JobRecruiting::where('website_id', $data['website_id'])
  4008. ->where('status', 1)
  4009. ->where('id', $data['id'])
  4010. ->first(['cat_arr_id']);
  4011. if (empty($article)) {
  4012. return Result::error("该招聘不存在", 0);
  4013. }
  4014. break;
  4015. case 5:
  4016. // 求职
  4017. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4018. $article = JobHunting::where('website_id', $data['website_id'])
  4019. ->where('status', 2)
  4020. ->where('id', $data['id'])
  4021. ->first(['cat_arr_id']);
  4022. if (empty($article)) {
  4023. return Result::error("该求职不存在", 0);
  4024. }
  4025. break;
  4026. case 6:
  4027. // 企业
  4028. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4029. $article = Company::
  4030. // where('website_id', $data['website_id'])
  4031. // ->
  4032. where('status', 1)
  4033. ->where('id', $data['id'])
  4034. ->first(['cat_arr_id']);
  4035. if (empty($article)) {
  4036. return Result::error("该企业不存在", 0);
  4037. }
  4038. break;
  4039. case 7:
  4040. // 项目
  4041. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4042. $article = Project::where('website_id', $data['website_id'])
  4043. ->where('status', 1)
  4044. ->where('id', $data['id'])
  4045. ->first(['cat_arr_id']);
  4046. if (empty($article)) {
  4047. return Result::error("该项目不存在", 0);
  4048. }
  4049. break;
  4050. default:
  4051. return Result::error("该数据不存在", 0);
  4052. break;
  4053. }
  4054. // return Result::success($article);
  4055. // $catid =0 ;
  4056. if (!isset($article['cat_arr_id'])) {
  4057. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4058. } else {
  4059. $catidArray = json_decode($article['cat_arr_id'], true);
  4060. $catid = !empty($catidArray) ? end($catidArray) : null;
  4061. }
  4062. // return Result::success($catid);
  4063. // // return Result::success($article['cat_arr_id']);
  4064. if (empty($catid)) {
  4065. return Result::error("该栏目路径不存在", 0);
  4066. }
  4067. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4068. ->where('category_id', $catid)
  4069. ->first('path');
  4070. }
  4071. // else{
  4072. // // if ($last_category['pid'] != 0) {
  4073. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4074. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4075. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4076. // ->where('category_id',$catid)
  4077. // ->where('path',$data['all_route'])
  4078. // ->first('path');
  4079. // // } else {
  4080. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4081. // // }
  4082. // }
  4083. // return Result::success($path);
  4084. if (!empty($path) && $path['path'] != $data['all_route']) {
  4085. return Result::error('非法路径!');
  4086. } else {
  4087. return Result::success($last_category['path']);
  4088. }
  4089. }
  4090. /**
  4091. * 招工招聘 - 获取推荐职位
  4092. * @param array $data
  4093. * @return array
  4094. */
  4095. public function getWebsiteLevelJob(array $data): array
  4096. {
  4097. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4098. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4099. ->where('job_recruiting.status', 1)
  4100. ->where('job_level', $data['job_level'])
  4101. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4102. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4103. ->orderBy('job_recruiting.updated_at', 'desc')
  4104. ->limit($data['pageSize'])
  4105. ->get();
  4106. $web = ['website_id' => $data['website_id']];
  4107. if (!empty($job)) {
  4108. $result = $this->processJob($job, $web);
  4109. }
  4110. if (empty($result)) {
  4111. return Result::error("暂无相关职位信息", 0);
  4112. }
  4113. return Result::success($result);
  4114. }
  4115. /**
  4116. * 验证导航名称是否重复
  4117. * @return void
  4118. */
  4119. //20250226 产品列表
  4120. public function getGoodList(array $data): array
  4121. {
  4122. var_dump($data, '---------1-2--');
  4123. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4124. unset($data['user_type_id']);
  4125. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4126. $where = [];
  4127. if ($type_id != '10000') {
  4128. $where = [
  4129. 'good.user_id' => $user_id,
  4130. ];
  4131. }
  4132. //类型
  4133. if (isset($data['type_id']) && $data['type_id']) {
  4134. $where['good.type_id'] = $data['type_id'];
  4135. }
  4136. //名称
  4137. if (isset($data['name']) && $data['name']) {
  4138. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4139. }
  4140. //status
  4141. if (isset($data['status']) && $data['status'] != '') {
  4142. $where['good.status'] = $data['status'];
  4143. }
  4144. //status1
  4145. // if (isset($data['status1']) && $data['status1'] == 1) {
  4146. // $status1 = 1;
  4147. // }
  4148. $where1 = [];
  4149. //website_id
  4150. // if (isset($data['website_id']) && $data['website_id']) {
  4151. // $where1 = [
  4152. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4153. // ];
  4154. // }
  4155. // website_name
  4156. if (isset($data['website_name']) && $data['website_name']) {
  4157. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4158. }
  4159. // catid
  4160. if (isset($data['category_name']) && $data['category_name']) {
  4161. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4162. }
  4163. // $result = Good::where($where)
  4164. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4165. var_dump($where, '---------1---');
  4166. $result = Good::where($where)
  4167. ->when(!empty($where1), function ($query) use ($where1) {
  4168. return $query->where($where1);
  4169. })
  4170. //status 1待审核2已审核3已拒绝
  4171. ->when(isset($data['status1']), function ($query) {
  4172. return $query->whereIn('good.status', [1, 3]);
  4173. })
  4174. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4175. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4176. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4177. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4178. ->orderBy("updated_at", "desc")
  4179. ->limit($data['page_size'])
  4180. ->offset(($data['page'] - 1) * $data['page_size'])
  4181. ->get();
  4182. $count = Good::where($where)
  4183. ->when(!empty($where1), function ($query) use ($where1) {
  4184. return $query->where($where1);
  4185. })
  4186. //status 1待审核2已审核3已拒绝
  4187. ->when(isset($data['status1']), function ($query) {
  4188. return $query->whereIn('good.status', [1, 3]);
  4189. })
  4190. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4191. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4192. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4193. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4194. ->orderBy("updated_at", "desc")->count();
  4195. $data = [
  4196. 'rows' => $result->toArray(),
  4197. 'count' => $count,
  4198. ];
  4199. if (empty($result)) {
  4200. return Result::error("此栏目暂无相关产品", 0);
  4201. }
  4202. return Result::success($data);
  4203. }
  4204. public function getGoodInfo(array $data): array
  4205. {
  4206. $result = Good::where('id', $data['id'])->first();
  4207. if (empty($result)) {
  4208. return Result::error("此产品不存在", 0);
  4209. }
  4210. return Result::success($result);
  4211. }
  4212. public function addGood(array $data): array
  4213. {
  4214. // unset($data['city_arr_id']);
  4215. // unset($data['cat_arr_id']);
  4216. $data['city_id'] = end($data['city_arr_id']);
  4217. $data['catid'] = end($data['cat_arr_id']);
  4218. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4219. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4220. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4221. unset($data['imgUrl']); //大小写
  4222. if (isset($data['price']) && $data['price'] == '') {
  4223. $data['price'] = 0;
  4224. }
  4225. if ($data['imgurl'] == '') {
  4226. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4227. preg_match_all($reg, $data['detail'], $matches);
  4228. if (isset($matches[1][0])) {
  4229. //截取varchar240
  4230. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4231. }
  4232. }
  4233. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4234. //提取标题+内容中的关键词
  4235. $data['keyword'] = $data['name'];
  4236. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4237. Jieba::init(); // 初始化 jieba-php
  4238. Finalseg::init();
  4239. $segList = Jieba::cut($data['keyword']);
  4240. $segList1 = array_slice($segList, 0, 8);
  4241. $data['keyword'] = implode(',', $segList1);
  4242. }
  4243. if ($data['description'] == '') {
  4244. //提取内容中的描述
  4245. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4246. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4247. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4248. }
  4249. if ($data['status'] == 1) {
  4250. $this->sendMessage([
  4251. 'talk_type' => 200,
  4252. 'title' => $data['name'],
  4253. 'content' => '提交了审核',
  4254. 'messageType' => 3,
  4255. ]);
  4256. }
  4257. $result = Good::insert($data);
  4258. if (empty($result)) {
  4259. return Result::error("添加失败", 0);
  4260. }
  4261. return Result::success($result);
  4262. }
  4263. public function updateGood(array $data): array
  4264. {
  4265. $data['city_id'] = end($data['city_arr_id']);
  4266. $data['catid'] = end($data['cat_arr_id']);
  4267. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4268. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4269. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4270. //设置东八区
  4271. date_default_timezone_set('Asia/Shanghai');
  4272. $data['updated_at'] = date('Y-m-d H:i:s');
  4273. if (isset($data['price']) && $data['price'] == '') {
  4274. $data['price'] = 0;
  4275. }
  4276. if ($data['imgurl'] == '') {
  4277. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4278. preg_match_all($reg, $data['detail'], $matches);
  4279. if (isset($matches[1][0])) {
  4280. //截取varchar240
  4281. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4282. }
  4283. }
  4284. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4285. //提取标题+内容中的关键词
  4286. $data['keyword'] = $data['name'];
  4287. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4288. Jieba::init(); // 初始化 jieba-php
  4289. Finalseg::init();
  4290. $segList = Jieba::cut($data['keyword']);
  4291. $segList1 = array_slice($segList, 0, 8);
  4292. $data['keyword'] = implode(',', $segList1);
  4293. }
  4294. if ($data['description'] == '') {
  4295. //提取内容中的描述
  4296. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4297. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4298. }
  4299. if ($data['status'] == 1) {
  4300. $this->sendMessage([
  4301. 'talk_type' => 200,
  4302. 'title' => $data['name'],
  4303. 'content' => '提交了审核',
  4304. 'messageType' => 3,
  4305. ]);
  4306. }
  4307. $result = Good::where('id', $data['id'])->update($data);
  4308. if (empty($result)) {
  4309. return Result::error("更新失败", 0);
  4310. }
  4311. return Result::success($result);
  4312. }
  4313. public function delGood(array $data): array
  4314. {
  4315. $result = Good::where('id', $data['id'])->delete();
  4316. if (empty($result)) {
  4317. return Result::error("删除失败", 0);
  4318. }
  4319. return Result::success($result);
  4320. }
  4321. //20250226 产品列表
  4322. //20250306 求职信息
  4323. public function getJobHuntingList(array $data): array
  4324. {
  4325. $where = [];
  4326. if (isset($data['username']) && !empty($data['username'])) {
  4327. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4328. }
  4329. //status 1待审核2已审核3已拒绝
  4330. if (isset($data['status']) && $data['status'] != '') {
  4331. $where = [
  4332. 'job_hunting.status' => $data['status'],
  4333. ];
  4334. }
  4335. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4336. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4337. unset($data['type_id']);
  4338. if ($type_id != '10000') {
  4339. $where[] = ['job_hunting.user_id', '=', $user_id];
  4340. }
  4341. $result = JobHunting::where($where)
  4342. ->when(!empty($data['status1']), function ($query) use ($data) {
  4343. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4344. })
  4345. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4346. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4347. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4348. ->orderBy("updated_at", "desc")
  4349. ->limit($data['page_size'])
  4350. ->offset(($data['page'] - 1) * $data['page_size'])
  4351. ->get();
  4352. if (empty($result)) {
  4353. return Result::error("查询失败", 0);
  4354. }
  4355. $count = JobHunting::where($where)
  4356. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4357. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4358. ->count();
  4359. $data = [
  4360. 'rows' => $result->toArray(),
  4361. 'count' => $count,
  4362. ];
  4363. return Result::success($data);
  4364. }
  4365. public function getJobHuntingApply(array $data): array
  4366. {
  4367. var_dump($data, '-----------------test--------1-');
  4368. $where = [];
  4369. if (isset($data['username']) && !empty($data['username'])) {
  4370. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4371. }
  4372. if (isset($data['salary']) && !empty($data['salary'])) {
  4373. $where[] = [
  4374. 'job_hunting.salary',
  4375. '=',
  4376. $data['salary'],
  4377. ];
  4378. }
  4379. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4380. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4381. unset($data['type_id']);
  4382. if ($type_id != '10000') {
  4383. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4384. }
  4385. var_dump($where, '-----------------test---------');
  4386. $result = jobApply::where($where)
  4387. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4388. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4389. // })
  4390. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4391. ->where('job_enum.egroup', '=', 'income')
  4392. ->where('job_hunting.status', 2) //已审核
  4393. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4394. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4395. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4396. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4397. //职位----是申请职位
  4398. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4399. ->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')
  4400. ->orderBy("job_hunting.updated_at", "desc")
  4401. ->limit($data['page_size'])
  4402. ->offset(($data['page'] - 1) * $data['page_size'])
  4403. ->get();
  4404. if (empty($result)) {
  4405. return Result::error("查询失败", 0);
  4406. }
  4407. $count = jobApply::where($where)
  4408. ->where('job_enum.egroup', '=', 'income')
  4409. ->where('job_hunting.status', 2) //已审核
  4410. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4411. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4412. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4413. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4414. //职位----是申请职位
  4415. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4416. ->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')
  4417. ->count();
  4418. $data = [
  4419. 'rows' => $result->toArray(),
  4420. 'count' => $count,
  4421. ];
  4422. return Result::success($data);
  4423. }
  4424. public function addJobHunting(array $data): array
  4425. {
  4426. date_default_timezone_set('Asia/Shanghai');
  4427. unset($data['company_name']);
  4428. unset($data['job_industry']);
  4429. unset($data['job_name']);
  4430. unset($data['department']);
  4431. unset($data['job_timeList']);
  4432. unset($data['job_content']);
  4433. unset($data['job_typename']); //不知道这是啥,
  4434. $data['created_at'] = date('Y-m-d H:i:s');
  4435. $data['updated_at'] = date('Y-m-d H:i:s');
  4436. //根据用户 user_id 只能添加一次
  4437. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4438. if (!empty($result)) {
  4439. return Result::error("您已添加过求职信息", 0);
  4440. }
  4441. var_dump($result, '-----------------test---------');
  4442. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4443. if (is_string($data['city_arr_id'])) {
  4444. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4445. $cityArr = json_decode($data['city_arr_id'], true);
  4446. // 确保 $cityArr 是数组
  4447. if (is_array($cityArr)) {
  4448. $data['city_id'] = end($cityArr);
  4449. }
  4450. } else {
  4451. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4452. if (is_array($data['city_arr_id'])) {
  4453. $data['city_id'] = end($data['city_arr_id']);
  4454. }
  4455. }
  4456. }
  4457. // 处理求职所绑定栏目
  4458. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4459. if (is_string($data['cat_arr_id'])) {
  4460. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4461. // 先清理可能存在的无效 JSON 字符
  4462. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4463. $catArr = json_decode($cleanedCatArrStr, true);
  4464. // 检查 JSON 解码是否成功且结果是数组
  4465. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4466. $data['catid'] = end($catArr);
  4467. }
  4468. } else {
  4469. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4470. if (is_array($data['cat_arr_id'])) {
  4471. $data['catid'] = end($data['cat_arr_id']);
  4472. }
  4473. }
  4474. }
  4475. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4476. $this->sendMessage([
  4477. 'talk_type' => 600,
  4478. 'title' => $data['name'],
  4479. 'content' => '提交了审核',
  4480. 'messageType' => 11,
  4481. ]);
  4482. }
  4483. $result = JobHunting::create($data);
  4484. if (empty($result)) {
  4485. return Result::error("添加失败", 0);
  4486. }
  4487. return Result::success($result);
  4488. }
  4489. public function delJobHunting(array $data): array
  4490. {
  4491. $result = JobHunting::where('id', $data['id'])->delete();
  4492. if (empty($result)) {
  4493. return Result::error("删除失败", 0);
  4494. }
  4495. return Result::success($result);
  4496. }
  4497. public function updateJobHunting(array $data): array
  4498. {
  4499. //设置东八区
  4500. date_default_timezone_set('Asia/Shanghai');
  4501. unset($data['company_name']);
  4502. unset($data['job_industry']);
  4503. unset($data['job_name']);
  4504. unset($data['department']);
  4505. unset($data['job_timeList']);
  4506. unset($data['job_content']);
  4507. unset($data['job_typename']); //不知道这是啥,
  4508. $data['created_at'] = date('Y-m-d H:i:s');
  4509. $data['updated_at'] = date('Y-m-d H:i:s');
  4510. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4511. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4512. $cityArr = json_decode($data['city_arr_id'], true);
  4513. $data['city_id'] = end($cityArr);
  4514. } else {
  4515. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4516. $data['city_id'] = end($data['city_arr_id']);
  4517. }
  4518. // 处理求职所绑定栏目
  4519. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4520. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4521. $catArr = json_decode($data['cat_arr_id'], true);
  4522. $data['catid'] = end($catArr);
  4523. } else {
  4524. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4525. $data['catid'] = end($data['cat_arr_id']);
  4526. }
  4527. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4528. $this->sendMessage([
  4529. 'talk_type' => 600,
  4530. 'title' => $data['name'],
  4531. 'content' => '提交了审核',
  4532. 'messageType' => 11,
  4533. ]);
  4534. }
  4535. $result = JobHunting::where('id', $data['id'])->update($data);
  4536. if (empty($result)) {
  4537. return Result::error("更新失败", 0);
  4538. }
  4539. return Result::success($result);
  4540. }
  4541. public function getJobHuntingInfo(array $data): array
  4542. {
  4543. $result = JobHunting::where('id', $data['id'])->first();
  4544. if (empty($result)) {
  4545. return Result::error("查询失败", 0);
  4546. }
  4547. return Result::success($result);
  4548. }
  4549. public function getJobHuntingData(array $data): array
  4550. {
  4551. $jobEnum = JobEnum::get();
  4552. $jobIndustry = JobIndustry::get();
  4553. $jobNature = JobNature::get();
  4554. $jobPosition = JobPosition::get();
  4555. $data = [
  4556. 'jobEnum' => $jobEnum,
  4557. 'jobIndustry' => $jobIndustry,
  4558. 'jobNature' => $jobNature,
  4559. 'jobPosition' => $jobPosition,
  4560. ];
  4561. return Result::success($data);
  4562. }
  4563. public function delJobHuntingInfo(array $data): array
  4564. {
  4565. $result = JobHunting::where('id', $data['id'])->delete();
  4566. return Result::success();
  4567. }
  4568. //20250324 通知,公告,消息
  4569. public function delNotice(array $data): array
  4570. {
  4571. $result = Notice::where('id', $data['id'])->delete();
  4572. if ($result) {
  4573. return Result::success();
  4574. } else {
  4575. return Result::error("删除失败", 0);
  4576. }
  4577. }
  4578. public function getNoticeInfo(array $data): array
  4579. {
  4580. $result = Notice::where('id', $data['id'])->first();
  4581. // var_dump($result['re_user_ids'], '--------------------');
  4582. if (empty($result)) {
  4583. return Result::error("查询失败", 0);
  4584. }
  4585. return Result::success($result);
  4586. }
  4587. public function readNotice(array $data): array
  4588. {
  4589. $result = Notice::where('id', $data['id'])->first();
  4590. // var_dump($result['re_user_ids'], '--------------------');
  4591. if (empty($result)) {
  4592. return Result::error("查询失败", 0);
  4593. }
  4594. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4595. $re_user_ids = json_decode($result['re_user_ids'], true);
  4596. var_dump($re_user_ids, '--------------1---test---------');
  4597. var_dump($data, '--------------1---test---------');
  4598. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4599. //如果已经存在,就不再添加
  4600. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4601. $read_id = json_decode($result['read_id'], true);
  4602. if (!is_array($read_id)) {
  4603. $read_id = [];
  4604. }
  4605. if (!in_array($data['user_id'], $read_id)) {
  4606. $read_id[] = $data['user_id'];
  4607. $result['read_id'] = json_encode($read_id);
  4608. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4609. }
  4610. } else {
  4611. //如果不存在,就添加
  4612. $result['read_id'] = json_encode([$data['user_id']]);
  4613. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4614. }
  4615. }
  4616. return Result::success($result);
  4617. }
  4618. public function addNotice(array $data): array
  4619. {
  4620. date_default_timezone_set('Asia/Shanghai');
  4621. $data['created_at'] = date('Y-m-d H:i:s');
  4622. $data['updated_at'] = date('Y-m-d H:i:s');
  4623. $user_id = UserInfo::
  4624. //city_id不是null
  4625. whereNotNull('city_id')
  4626. ->whereNotNull('department_id')
  4627. ->where(function ($query) use ($data) {
  4628. $query->where(function ($subQuery) use ($data) {
  4629. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4630. });
  4631. })
  4632. ->where(function ($query) use ($data) {
  4633. $query->where(function ($subQuery) use ($data) {
  4634. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4635. });
  4636. })
  4637. ->pluck('user_id')->toArray();
  4638. $user_id = array_unique($user_id);
  4639. $chat_ids = $user_id;
  4640. $user_id = json_encode($user_id);
  4641. $data['re_user_ids'] = $user_id;
  4642. $this->sendMessage([
  4643. 'talk_type' => 700,
  4644. 'title' => $data['title'],
  4645. 'content' => '提交了审核',
  4646. 'messageType' => 5,
  4647. ]);
  4648. $result = Notice::insertGetId($data);
  4649. if (empty($result)) {
  4650. return Result::error("添加失败", 0);
  4651. }
  4652. return Result::success($result);
  4653. }
  4654. public function updateNotice(array $data): array
  4655. {
  4656. date_default_timezone_set('Asia/Shanghai');
  4657. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4658. $user_id = UserInfo::
  4659. //city_id不是null
  4660. whereNotNull('city_id')
  4661. ->whereNotNull('department_id')
  4662. ->where(function ($query) use ($data) {
  4663. $query->where(function ($subQuery) use ($data) {
  4664. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4665. });
  4666. })
  4667. ->where(function ($query) use ($data) {
  4668. $query->where(function ($subQuery) use ($data) {
  4669. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4670. });
  4671. })
  4672. ->pluck('user_id')->toArray();
  4673. $user_id = array_unique($user_id);
  4674. $user_id = json_encode($user_id);
  4675. $data['re_user_ids'] = $user_id;
  4676. $data['updated_at'] = date('Y-m-d H:i:s');
  4677. $this->sendMessage([
  4678. 'talk_type' => 700,
  4679. 'title' => $data['title'],
  4680. 'content' => '提交了审核',
  4681. 'messageType' => 5,
  4682. ]);
  4683. $result = Notice::where('id', $data['id'])->update($data);
  4684. return Result::success($result);
  4685. }
  4686. public function getNoticeList(array $data): array
  4687. {
  4688. $where = [];
  4689. //title
  4690. if (isset($data['title']) && !empty($data['title'])) {
  4691. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4692. }
  4693. //level
  4694. if (isset($data['level']) && !empty($data['level'])) {
  4695. $where[] = ['notice.level', '=', $data['level']];
  4696. }
  4697. //status
  4698. if (isset($data['status']) && !empty($data['status'])) {
  4699. $where[] = ['notice.status', '=', $data['status']];
  4700. }
  4701. //type
  4702. if (isset($data['type']) && !empty($data['type'])) {
  4703. $where[] = ['notice.type', '=', $data['type']];
  4704. }
  4705. var_dump($data, '------------11111-2----test---------');
  4706. if ($data['type_id'] == 10000) {
  4707. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4708. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4709. })
  4710. ->where($where)
  4711. ->orderBy('updated_at', 'desc')
  4712. ->limit($data['page_size'])
  4713. ->offset(($data['page'] - 1) * $data['page_size'])
  4714. ->get();
  4715. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4716. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4717. })
  4718. ->where($where)
  4719. ->orderBy('updated_at', 'desc')
  4720. ->count();
  4721. } else {
  4722. $result = Notice::where($where)
  4723. // ->where('user_id', $data['user_id'])
  4724. ->Where(function ($query) use ($data) {
  4725. $query->Where(function ($q) use ($data) {
  4726. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4727. ->orWhere('notice.user_id', $data['user_id']);
  4728. });
  4729. })
  4730. ->when(!empty($data['status1']), function ($query) use ($data) {
  4731. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4732. })
  4733. ->orderBy('updated_at', 'desc')
  4734. ->limit($data['page_size'])
  4735. ->offset(($data['page'] - 1) * $data['page_size'])
  4736. ->get();
  4737. $total = Notice::where($where)
  4738. ->when(!empty($data['status1']), function ($query) use ($data) {
  4739. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4740. })
  4741. // ->where('user_id', $data['user_id'])
  4742. ->Where(function ($query) use ($data) {
  4743. $query->Where(function ($q) use ($data) {
  4744. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4745. ->orWhere('notice.user_id', $data['user_id']);
  4746. });
  4747. })
  4748. ->count();
  4749. }
  4750. if (empty($result)) {
  4751. return Result::error("查询失败", 0);
  4752. }
  4753. $data = [
  4754. 'rows' => $result,
  4755. 'count' => $total,
  4756. ];
  4757. return Result::success($data);
  4758. }
  4759. public function noticeList(array $data): array
  4760. {
  4761. $where = [];
  4762. //title
  4763. if (isset($data['title']) && !empty($data['title'])) {
  4764. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4765. }
  4766. //level
  4767. if (isset($data['level']) && !empty($data['level'])) {
  4768. $where[] = ['notice.level', '=', $data['level']];
  4769. }
  4770. //status
  4771. if (isset($data['status']) && !empty($data['status'])) {
  4772. $where[] = ['notice.status', '=', $data['status']];
  4773. }
  4774. //type
  4775. if (isset($data['type']) && !empty($data['type'])) {
  4776. $where[] = ['notice.type', '=', $data['type']];
  4777. }
  4778. var_dump($data, '------------11111-2----test---------');
  4779. if ($data['type_id'] == 10000) {
  4780. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4781. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4782. })
  4783. ->where($where)
  4784. ->orderBy('updated_at', 'desc')
  4785. ->limit($data['page_size'])
  4786. ->offset(($data['page'] - 1) * $data['page_size'])
  4787. ->get();
  4788. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4789. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4790. })
  4791. ->where($where)
  4792. ->orderBy('updated_at', 'desc')
  4793. ->count();
  4794. } else {
  4795. $result = Notice::where($where)
  4796. // ->where('user_id', $data['user_id'])
  4797. ->Where(function ($query) use ($data) {
  4798. $query->Where(function ($q) use ($data) {
  4799. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4800. ->orWhere('notice.user_id', $data['user_id']);
  4801. });
  4802. })
  4803. ->when(!empty($data['status1']), function ($query) use ($data) {
  4804. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4805. })
  4806. ->orderBy('updated_at', 'desc')
  4807. ->limit($data['page_size'])
  4808. ->offset(($data['page'] - 1) * $data['page_size'])
  4809. ->get();
  4810. $total = Notice::where($where)
  4811. ->when(!empty($data['status1']), function ($query) use ($data) {
  4812. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4813. })
  4814. // ->where('user_id', $data['user_id'])
  4815. ->Where(function ($query) use ($data) {
  4816. $query->Where(function ($q) use ($data) {
  4817. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4818. ->orWhere('notice.user_id', $data['user_id']);
  4819. });
  4820. })
  4821. ->count();
  4822. }
  4823. if (empty($result)) {
  4824. return Result::error("查询失败", 0);
  4825. }
  4826. $data = [
  4827. 'rows' => $result,
  4828. 'count' => $total,
  4829. ];
  4830. return Result::success($data);
  4831. }
  4832. public function getNoticeDetail(array $data): array
  4833. {
  4834. $result = Notice::where('id', $data['id'])->first();
  4835. if (empty($result)) {
  4836. return Result::error("查询失败", 0);
  4837. }
  4838. return Result::success($result);
  4839. }
  4840. public function deleteNotice(array $data): array
  4841. {
  4842. $notice = Notice::where('id', $data['id'])->first();
  4843. if (empty($notice)) {
  4844. return Result::error("删除失败", 0);
  4845. }
  4846. $chat_group_id = $notice->group_id;
  4847. if ($chat_group_id) {
  4848. //删除群聊
  4849. ChatGroups::where('id', $chat_group_id)->delete();
  4850. //删除群成员
  4851. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4852. //删除群聊记录
  4853. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4854. }
  4855. $result = Notice::where('id', $data['id'])->delete();
  4856. return Result::success($result);
  4857. }
  4858. public function complaintList(array $data): array
  4859. {
  4860. var_dump($data, '---------1---------');
  4861. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4862. unset($data['type_id']);
  4863. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4864. $where = [];
  4865. if ($type_id != 10000 && empty($data['deal_user'])) {
  4866. // $where['complaint.user_id'] = $user_id;
  4867. }
  4868. if (!empty($data['title'])) {
  4869. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4870. }
  4871. if (!empty($data['department_id'])) {
  4872. $where['complaint.department_id'] = $data['department_id'];
  4873. }
  4874. if (!empty($data['deal'])) {
  4875. $where['complaint.deal'] = $data['deal'];
  4876. }
  4877. if (!empty($data['status'])) {
  4878. $where['complaint.status'] = $data['status'];
  4879. }
  4880. var_dump(!empty($data['deal_user']), '----------1');
  4881. var_dump($where, '----------2');
  4882. $result = Complaint::where($where)
  4883. ->when(!empty($data['status1']), function ($query) use ($data) {
  4884. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4885. })
  4886. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4887. //json re_user_ids data[user_id]是不是在里面
  4888. $query->Where(function ($q) use ($data) {
  4889. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4890. ->where('complaint.status', 2);
  4891. });
  4892. })
  4893. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4894. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4895. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4896. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4897. ->orderBy('updated_at', 'desc')
  4898. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4899. //sql输出
  4900. if (empty($result)) {
  4901. return Result::error("暂无投诉信息", 0);
  4902. }
  4903. // 取出数据
  4904. $rows = $result->items();
  4905. $count = $result->total();
  4906. $responseData = [
  4907. 'rows' => $rows,
  4908. 'count' => $count,
  4909. ];
  4910. return Result::success($responseData);
  4911. }
  4912. public function getComplaintList(array $data): array
  4913. {
  4914. var_dump($data, '00000001000000000000');
  4915. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4916. unset($data['type_id']);
  4917. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4918. $where = [];
  4919. if ($type_id != 10000 && empty($data['deal_user'])) {
  4920. $where['complaint.user_id'] = $user_id;
  4921. }
  4922. if (!empty($data['title'])) {
  4923. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4924. }
  4925. if (!empty($data['department_id'])) {
  4926. $where['complaint.department_id'] = $data['department_id'];
  4927. }
  4928. if (!empty($data['deal'])) {
  4929. $where['complaint.deal'] = $data['deal'];
  4930. }
  4931. if (!empty($data['status'])) {
  4932. $where['complaint.status'] = $data['status'];
  4933. }
  4934. var_dump(!empty($data['deal_user']), '----------1');
  4935. var_dump($where, '----------2');
  4936. $result = Complaint::where($where)
  4937. ->when(!empty($data['status1']), function ($query) use ($data) {
  4938. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4939. })
  4940. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4941. // //json re_user_ids data[user_id]是不是在里面
  4942. // $query->Where(function ($q) use ($data) {
  4943. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4944. // ->where('complaint.status', 2);
  4945. // });
  4946. // })
  4947. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4948. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4949. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4950. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4951. ->orderBy('updated_at', 'desc')
  4952. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4953. //sql输出
  4954. if (empty($result)) {
  4955. return Result::error("暂无投诉信息", 0);
  4956. }
  4957. // 取出数据
  4958. $rows = $result->items();
  4959. $count = $result->total();
  4960. $responseData = [
  4961. 'rows' => $rows,
  4962. 'count' => $count,
  4963. ];
  4964. return Result::success($responseData);
  4965. }
  4966. public function getComplaintInfo(array $data): array
  4967. {
  4968. $result = Complaint::where('id', $data['id'])->first();
  4969. if (empty($result)) {
  4970. return Result::error("查询失败", 0);
  4971. }
  4972. return Result::success($result);
  4973. }
  4974. public function readComplaint(array $data): array
  4975. {
  4976. $result = Complaint::where('id', $data['id'])->first();
  4977. if (empty($result)) {
  4978. return Result::error("查询失败", 0);
  4979. }
  4980. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4981. $re_user_ids = json_decode($result['re_user_ids'], true);
  4982. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4983. //如果已经存在,就不再添加
  4984. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4985. $read_id = json_decode($result['read_id'], true);
  4986. if (!is_array($read_id)) {
  4987. $read_id = [];
  4988. }
  4989. if (!in_array($data['user_id'], $read_id)) {
  4990. $read_id[] = $data['user_id'];
  4991. $result['read_id'] = json_encode($read_id);
  4992. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4993. }
  4994. } else {
  4995. //如果不存在,就添加
  4996. $result['read_id'] = json_encode([$data['user_id']]);
  4997. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4998. }
  4999. }
  5000. return Result::success($result);
  5001. }
  5002. public function addComplaint(array $data): array
  5003. {
  5004. date_default_timezone_set('Asia/Shanghai');
  5005. $data['created_at'] = date('Y-m-d H:i:s');
  5006. $data['updated_at'] = date('Y-m-d H:i:s');
  5007. $this->sendMessage([
  5008. 'talk_type' => 800,
  5009. 'title' => $data['title'],
  5010. 'content' => '提交了审核',
  5011. 'messageType' => 6,
  5012. ]);
  5013. $result = Complaint::create($data);
  5014. return Result::success($result);
  5015. }
  5016. public function updateComplaint(array $data): array
  5017. {
  5018. date_default_timezone_set('Asia/Shanghai');
  5019. $data['updated_at'] = date('Y-m-d H:i:s');
  5020. $user_id = $data['user_id'] ?? 0;
  5021. $type_id = $data['type_id'] ?? 0;
  5022. unset($data['user_id']);
  5023. unset($data['type_id']);
  5024. $this->sendMessage([
  5025. 'talk_type' => 800,
  5026. 'title' => $data['title'],
  5027. 'content' => '提交了审核',
  5028. 'messageType' => 6,
  5029. ]);
  5030. $result = Complaint::where('id', $data['id'])->update($data);
  5031. return Result::success($result);
  5032. }
  5033. public function deleteComplaint(array $data): array
  5034. {
  5035. $result = Complaint::where('id', $data['id'])->delete();
  5036. return Result::success($result);
  5037. }
  5038. public function getComplainInfo(array $data): array
  5039. {
  5040. $result = Complaint::where('id', $data['id'])->first();
  5041. if (empty($result)) {
  5042. return Result::error("查询失败", 0);
  5043. }
  5044. return Result::success($result);
  5045. }
  5046. public function updateComplaintStatus(array $data): array
  5047. {
  5048. date_default_timezone_set('Asia/Shanghai');
  5049. $data['updated_at'] = date('Y-m-d H:i:s');
  5050. $user_id = $data['user_id'] ?? 0;
  5051. $type_id = $data['type_id'] ?? 0;
  5052. unset($data['user_id']);
  5053. unset($data['type_id']);
  5054. //处理, 写入处理人
  5055. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5056. $data['real_deal_user'] = $user_id;
  5057. }
  5058. //如果是deal 23,则判断是不是处理人
  5059. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5060. $complaintInof = Complaint::where('id', $data['id'])
  5061. ->where('real_deal_user', $user_id)
  5062. ->first();
  5063. if (empty($complaintInof)) {
  5064. return Result::error("处理人错误", 0);
  5065. }
  5066. }
  5067. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5068. if ($data['status'] == 1) {
  5069. $this->sendMessage([
  5070. 'talk_type' => 800,
  5071. 'title' => $complaintInfo['title'],
  5072. 'content' => '提交了审核',
  5073. 'messageType' => 6,
  5074. ]);
  5075. }
  5076. if ($data['status'] == 2 && !isset($data['deal'])) {
  5077. $this->sendMessage([
  5078. 'talk_type' => 801,
  5079. 'title' => $complaintInfo['title'],
  5080. 'content' => '审核通过',
  5081. 'messageType' => 6,
  5082. 'user_id' => $complaintInfo['user_id'],
  5083. ]);
  5084. $this->sendMessage([
  5085. 'talk_type' => 802,
  5086. 'title' => $complaintInfo['title'],
  5087. 'content' => '待处理',
  5088. 'messageType' => 6,
  5089. 'user_id' => $complaintInfo['re_user_ids'],
  5090. ]);
  5091. }
  5092. if ($data['status'] == 3 && !isset($data['deal'])) {
  5093. $this->sendMessage([
  5094. 'talk_type' => 801,
  5095. 'title' => $complaintInfo['title'],
  5096. 'content' => '审核拒绝',
  5097. 'messageType' => 6,
  5098. 'user_id' => $complaintInfo['user_id'],
  5099. ]);
  5100. }
  5101. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5102. $this->sendMessage([
  5103. 'talk_type' => 802,
  5104. 'title' => $complaintInfo['title'],
  5105. 'content' => '处理中',
  5106. 'messageType' => 6,
  5107. 'user_id' => $complaintInfo['re_user_ids'],
  5108. ]);
  5109. }
  5110. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5111. $this->sendMessage([
  5112. 'talk_type' => 802,
  5113. 'title' => $complaintInfo['title'],
  5114. 'content' => '不予处理',
  5115. 'messageType' => 6,
  5116. 'user_id' => $complaintInfo['re_user_ids'],
  5117. ]);
  5118. }
  5119. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5120. $this->sendMessage([
  5121. 'talk_type' => 802,
  5122. 'title' => $complaintInfo['title'],
  5123. 'content' => '已完结',
  5124. 'messageType' => 6,
  5125. 'user_id' => $complaintInfo['re_user_ids'],
  5126. ]);
  5127. }
  5128. $result = complaint::where('id', $data['id'])->update($data);
  5129. return Result::success($result);
  5130. }
  5131. public function updateGoodStatus(array $data): array
  5132. {
  5133. $user_id = $data['user_id'] ?? 0;
  5134. $type_id = $data['type_id'] ?? 0;
  5135. unset($data['user_id']);
  5136. unset($data['type_id']);
  5137. $goodInfo = Good::where('id', $data['id'])->first();
  5138. if ($data['status'] == 2) {
  5139. $this->sendMessage([
  5140. 'talk_type' => 201,
  5141. 'title' => $goodInfo['name'],
  5142. 'content' => '审核通过',
  5143. 'messageType' => 3,
  5144. 'user_id' => $goodInfo['user_id'],
  5145. ]);
  5146. }
  5147. if ($data['status'] == 3) {
  5148. $this->sendMessage([
  5149. 'talk_type' => 201,
  5150. 'title' => $goodInfo['name'],
  5151. 'content' => '审核拒绝',
  5152. 'messageType' => 3,
  5153. 'user_id' => $goodInfo['user_id'],
  5154. ]);
  5155. }
  5156. if ($data['status'] == 1) {
  5157. $this->sendMessage([
  5158. 'talk_type' => 200,
  5159. 'title' => $goodInfo['name'],
  5160. 'content' => '提交了审核',
  5161. 'messageType' => 3,
  5162. ]);
  5163. }
  5164. $result = Good::where('id', $data['id'])->update($data);
  5165. return Result::success($result);
  5166. }
  5167. public function updateJobHuntingStatus(array $data): array
  5168. {
  5169. $user_id = $data['user_id'] ?? 0;
  5170. $type_id = $data['type_id'] ?? 0;
  5171. unset($data['user_id']);
  5172. unset($data['type_id']);
  5173. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5174. if ($data['status'] == 2) {
  5175. $this->sendMessage([
  5176. 'talk_type' => 601,
  5177. 'title' => $jogHuntingInfo['name'],
  5178. 'content' => '审核通过',
  5179. 'messageType' => 11,
  5180. 'user_id' => $jogHuntingInfo['user_id'],
  5181. ]);
  5182. }
  5183. if ($data['status'] == 3) {
  5184. $this->sendMessage([
  5185. 'talk_type' => 601,
  5186. 'title' => $jogHuntingInfo['name'],
  5187. 'content' => '审核拒绝',
  5188. 'messageType' => 11,
  5189. 'user_id' => $jogHuntingInfo['user_id'],
  5190. ]);
  5191. }
  5192. if ($data['status'] == 1) {
  5193. $this->sendMessage([
  5194. 'talk_type' => 600,
  5195. 'title' => $jogHuntingInfo['name'],
  5196. 'content' => '提交了审核',
  5197. 'messageType' => 11,
  5198. ]);
  5199. }
  5200. $result = JobHunting::where('id', $data['id'])->update($data);
  5201. return Result::success($result);
  5202. }
  5203. public function updateNoticeStatus(array $data): array
  5204. {
  5205. $user_id = $data['user_id'] ?? 0;
  5206. $type_id = $data['type_id'] ?? 0;
  5207. unset($data['user_id']);
  5208. unset($data['type_id']);
  5209. //查询公告
  5210. $notice = Notice::where('id', $data['id'])->first();
  5211. if (empty($notice)) {
  5212. return Result::error("公告不存在", 0);
  5213. }
  5214. //$chat_ids 去除掉$data['user_id']
  5215. $chat_ids = json_decode($notice['re_user_ids'], true);
  5216. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5217. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5218. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5219. //chat_group
  5220. $group_id = PublicData::uuid();
  5221. $groupData = [
  5222. 'id' => $group_id,
  5223. 'creator_id' => $notice['user_id'],
  5224. 'group_name' => $notice['group_name'] ?? '',
  5225. 'profile' => $notice['profile'] ?? 0,
  5226. ];
  5227. var_dump($groupData, '-----------------groupData-------');
  5228. $groupResult = ChatGroups::insertGetId($groupData);
  5229. var_dump($groupResult, '-----------------groupid-------');
  5230. $groupMemberData = [
  5231. 'id' => PublicData::uuid(),
  5232. 'user_id' => $notice['user_id'],
  5233. 'group_id' => $group_id,
  5234. 'leader' => 2,
  5235. ];
  5236. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5237. //插入群成员表
  5238. $groupMemberDataUser = [];
  5239. $chatData = [];
  5240. foreach ($chat_ids as $key => $value) {
  5241. $groupMemberDataUser[] = [
  5242. 'id' => PublicData::uuid(),
  5243. 'user_id' => $value,
  5244. 'group_id' => $group_id,
  5245. 'leader' => 1,
  5246. ];
  5247. $chatData[] = [
  5248. 'user_id' => $value,
  5249. 'msg_type' => 1,
  5250. 'receiver_id' => $group_id,
  5251. 'content' => '通过通知创建群聊',
  5252. 'group_receiver_id' => $notice['user_id'],
  5253. 'action' => 'recieved',
  5254. 'created_at' => date('Y-m-d H:i:s'),
  5255. ];
  5256. }
  5257. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5258. ChatGroupsMember::insert($groupMemberDataUser);
  5259. //插入一条管理员聊天记录
  5260. $chatData[] = [
  5261. 'user_id' => $notice['user_id'],
  5262. 'msg_type' => 1,
  5263. 'receiver_id' => $group_id,
  5264. 'content' => '通过通知创建群聊',
  5265. 'group_receiver_id' => $notice['user_id'],
  5266. 'action' => 'said',
  5267. 'created_at' => date('Y-m-d H:i:s'),
  5268. ];
  5269. var_dump($chatData, '-----------------chatData-------');
  5270. $chatResult = ChatRecords::insert($chatData);
  5271. //处理imp
  5272. $group = [
  5273. 'type' => 1,
  5274. 'name' => $notice['group_name'] ?? '',
  5275. 'profile' => '',
  5276. 'avatar' => '',
  5277. 'creator_id' => $notice['user_id'],
  5278. ];
  5279. $groupResult = GroupImp::insertGetId($group);
  5280. var_dump($groupResult, '获取imp group_id');
  5281. $groupMember = [
  5282. 'user_id' => $notice['user_id'],
  5283. 'group_id' => $groupResult,
  5284. 'leader' => 1,
  5285. 'join_time' => Date('Y-m-d H:i:s')
  5286. ];
  5287. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5288. $talk_session = [
  5289. 'user_id' => $notice['user_id'],
  5290. 'to_from_id' => $groupResult,
  5291. 'talk_mode' => 2,
  5292. 'created_at' => Date('Y-m-d H:i:s'),
  5293. 'updated_at' => Date('Y-m-d H:i:s'),
  5294. ];
  5295. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5296. //被通知人员处理
  5297. foreach ($chat_ids as $key => $value) {
  5298. $groupMemberdata[] = [
  5299. 'user_id' => $value,
  5300. 'group_id' => $groupResult,
  5301. 'leader' => 3,
  5302. 'join_time' => Date('Y-m-d H:i:s')
  5303. ];
  5304. $talk_sessionData[] = [
  5305. 'user_id' => $value,
  5306. 'to_from_id' => $groupResult,
  5307. 'talk_mode' => 2,
  5308. 'created_at' => Date('Y-m-d H:i:s'),
  5309. 'updated_at' => Date('Y-m-d H:i:s'),
  5310. ];
  5311. }
  5312. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5313. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5314. $group_id = $groupResult;
  5315. //更新result的 group_id
  5316. $data['group_id'] = $group_id;
  5317. Notice::where(['id' => $data['id']])->update($data);
  5318. }
  5319. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5320. //删除掉信息
  5321. GroupImp::where('id', $notice['group_id'])->delete();
  5322. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5323. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5324. foreach ($chat_ids as $key => $value) {
  5325. }
  5326. //聊天记录删除
  5327. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5328. $data['group_id'] = null;
  5329. Notice::where(['id' => $data['id']])->update($data);
  5330. }
  5331. $result = Notice::where('id', $data['id'])->update($data);
  5332. $noticeInfo = Notice::where('id', $data['id'])->first();
  5333. if ($data['status'] == 2) {
  5334. $this->sendMessage([
  5335. 'talk_type' => 701,
  5336. 'title' => $noticeInfo['title'],
  5337. 'content' => '审核通过',
  5338. 'messageType' => 3,
  5339. 'user_id' => $noticeInfo['user_id'],
  5340. ]);
  5341. }
  5342. if ($data['status'] == 3) {
  5343. $this->sendMessage([
  5344. 'talk_type' => 701,
  5345. 'title' => $noticeInfo['title'],
  5346. 'content' => '审核拒绝',
  5347. 'messageType' => 3,
  5348. 'user_id' => $noticeInfo['user_id'],
  5349. ]);
  5350. }
  5351. if ($data['status'] == 1) {
  5352. $this->sendMessage([
  5353. 'talk_type' => 700,
  5354. 'title' => $noticeInfo['title'],
  5355. 'content' => '提交了审核',
  5356. 'messageType' => 3,
  5357. ]);
  5358. }
  5359. return Result::success($result);
  5360. }
  5361. public function getDUser(array $data): array
  5362. {
  5363. if (!empty($data['ids'])) {
  5364. $user = User::whereIn('id', $data['ids'])->getall();
  5365. if (empty($user)) {
  5366. return Result::error('无数据', 0);
  5367. }
  5368. return Result::success($user);
  5369. }
  5370. $where = [];
  5371. if (!empty($data['department_id'])) {
  5372. $where['department_id'] = $data['department_id'];
  5373. }
  5374. if (!empty($data['city_id'])) {
  5375. $where['city_id'] = $data['city_id'];
  5376. }
  5377. $result = User::where('type_id', 2)
  5378. ->where('status', 1)
  5379. ->where($where)
  5380. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5381. ->get();
  5382. if (empty($result)) {
  5383. return Result::error("查询失败", 0);
  5384. }
  5385. return Result::success($result);
  5386. }
  5387. /**
  5388. * 验证导航名称是否重复
  5389. * @return void
  5390. */
  5391. public function checkCategoryName(array $data): array
  5392. {
  5393. $result = Category::when($data, function ($query) use ($data) {
  5394. if (isset($data['name']) && $data['name']) {
  5395. $query->where("name", $data['name']);
  5396. }
  5397. if (isset($data['id']) && $data['id']) {
  5398. $query->where("id", "!=", $data['id']);
  5399. }
  5400. })->first();
  5401. if ($result) {
  5402. return Result::error("已存在");
  5403. } else {
  5404. return Result::success();
  5405. }
  5406. }
  5407. //20250226 产品列表
  5408. // 20250306 -------招聘--------fr
  5409. /*
  5410. * 招聘列表
  5411. * */
  5412. public function getJobRecruitingList(array $data): array
  5413. {
  5414. $where = [];
  5415. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5416. if ($data['checkout'] == 0) {
  5417. $job_status = [0, 2];
  5418. } else {
  5419. $job_status = [1];
  5420. }
  5421. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5422. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5423. }
  5424. $user = User::where('id', $data['user_id'])->first();
  5425. if (empty($user)) {
  5426. return Result::error("用户不存在", 0);
  5427. }
  5428. // 3:企业会员
  5429. if ($user['type_id'] == 3) {
  5430. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5431. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5432. }
  5433. // 如果 $where 为空,则不添加 where 条件
  5434. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5435. return $query->where($where);
  5436. })
  5437. ->whereIn('job_recruiting.status', $job_status)
  5438. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5439. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5440. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5441. ->orderBy("updated_at", "desc")
  5442. ->offset(($data['page'] - 1) * $data['page_size'])
  5443. ->limit($data['page_size'])
  5444. ->get()
  5445. ->all();
  5446. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5447. return $query->where($where);
  5448. })
  5449. ->whereIn('job_recruiting.status', $job_status)
  5450. ->count();
  5451. if (empty($result)) {
  5452. return Result::error("暂无招聘信息", 0);
  5453. }
  5454. return Result::success($result);
  5455. }
  5456. /*
  5457. * 招聘信息添加
  5458. * */
  5459. public function addJobRecruiting(array $data): array
  5460. {
  5461. // var_dump('添加招聘进入news------data',$data);
  5462. // return Result::success($data);
  5463. $user = User::where('user.id', $data['user_id'])
  5464. ->where('user.status', 1)
  5465. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5466. ->select(
  5467. 'user.type_id',
  5468. 'user.mobile',
  5469. 'user.email',
  5470. 'user_info.business_name',
  5471. 'user_info.company_hy_id',
  5472. 'user_info.company_nature',
  5473. 'user_info.company_size',
  5474. 'user_info.introduction',
  5475. 'user_info.real_name',
  5476. 'user_info.company_url',
  5477. 'user_info.address_arr_id',
  5478. 'user_info.address'
  5479. )
  5480. ->first();
  5481. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5482. return Result::error("用户不存在", 0);
  5483. }
  5484. $web = Website::where('id', $data['website_id'])->first();
  5485. if (empty($web)) {
  5486. return Result::error("网站不存在", 0);
  5487. }
  5488. // var_dump('添加招聘进入news---user---user',$user);
  5489. // 处理招聘关键词
  5490. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5491. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5492. } else {
  5493. Jieba::init(); // 初始化 jieba-php
  5494. Finalseg::init();
  5495. $segList = Jieba::cut($data['title']);
  5496. $segList1 = array_slice($segList, 0, 8);
  5497. $data['keyword'] = implode(',', $segList1);
  5498. }
  5499. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5500. $content = $data['description'];
  5501. // 去除 <style> 和 <script> 标签及其内容
  5502. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5503. // 去除所有 HTML 标签
  5504. $content = strip_tags($content);
  5505. // 去除 HTML 实体
  5506. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5507. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5508. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5509. // 去除多余空白
  5510. $content = preg_replace('/\s+/u', '', $content);
  5511. // 截取 100 个字符
  5512. $data['seo_description'] = mb_substr($content, 0, 100);
  5513. }
  5514. // return Result::success($user);
  5515. $data['action_id'] = $data['user_id'] ?? null;
  5516. $data['user_type'] = $user['type_id'] ?? null;
  5517. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5518. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5519. $data['catid'] = end($data['cat_arr_id']);
  5520. } else {
  5521. $data['catid'] = 0;
  5522. }
  5523. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5524. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5525. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5526. // 公司地址 管理员必填
  5527. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5528. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5529. // 管理员-企业相关信息
  5530. $company = [
  5531. // 'user_id' => $data['user_id']?? null,
  5532. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5533. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5534. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5535. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5536. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5537. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5538. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5539. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5540. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5541. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5542. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5543. ];
  5544. //去掉相关企业信息
  5545. $job = array_diff_key($data, array_flip(array_keys($company)));
  5546. // var_dump('添加招聘进入news---job---user',$job);
  5547. Db::beginTransaction();
  5548. try {
  5549. // // 先添加职位相关信息
  5550. if ($user['type_id'] == 10000) {
  5551. $job['status'] = 1;
  5552. }
  5553. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5554. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5555. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5556. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5557. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5558. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5559. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5560. // return Result::success($job);
  5561. $jobId = JobRecruiting::insertGetId($job);
  5562. if (empty($jobId)) {
  5563. Db::rollBack();
  5564. return Result::error("添加失败");
  5565. }
  5566. // 添加公司信息
  5567. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5568. $company['job_id'] = $jobId;
  5569. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5570. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5571. if ($user['type_id'] == 10000) {
  5572. // 管理员添加企业信息
  5573. $companyId = JobCompany::insertGetId($company);
  5574. if (empty($companyId)) {
  5575. Db::rollBack();
  5576. return Result::error("添加失败");
  5577. }
  5578. } else {
  5579. // 企业会员添加企业信息
  5580. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5581. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5582. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5583. $company['job_id'] = $jobId;
  5584. $companyId = JobCompany::insertGetId($company);
  5585. if (empty($companyId)) {
  5586. Db::rollBack();
  5587. return Result::error("添加失败");
  5588. }
  5589. }
  5590. Db::commit();
  5591. $result = [
  5592. 'job_id' => $jobId,
  5593. 'company_id' => $companyId,
  5594. ];
  5595. return Result::success($result);
  5596. } catch (\Exception $e) {
  5597. Db::rollBack();
  5598. return Result::error($e->getMessage(), 0);
  5599. }
  5600. // return Result::success($result);
  5601. }
  5602. /*
  5603. * 获取招聘信息详情
  5604. * */
  5605. public function getJobRecruitingInfo(array $data): array
  5606. {
  5607. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5608. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5609. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5610. ->select(
  5611. 'job_recruiting.*',
  5612. 'website.website_name as website_name',
  5613. 'job_company.business_name',
  5614. 'job_company.company_hy_id',
  5615. 'job_company.company_size',
  5616. 'job_company.company_nature',
  5617. 'job_company.introduction',
  5618. 'job_company.real_name',
  5619. 'job_company.mobile',
  5620. 'job_company.company_url',
  5621. 'job_company.address_arr_id',
  5622. 'job_company.address',
  5623. 'job_company.email'
  5624. )
  5625. ->first();
  5626. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5627. if (!empty($cityId)) {
  5628. if (isset($cityId[1]) && $cityId[1] != null) {
  5629. $city = District::where('id', $cityId[1])->first(['name']);
  5630. } else {
  5631. $city = District::where('id', $cityId[0])->first(['name']);
  5632. }
  5633. $result['city'] = $city['name'] ?? '';
  5634. }
  5635. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5636. if (is_array($addressId) && !empty($addressId)) {
  5637. $address = District::whereIn('id', $addressId)
  5638. ->orderBy('level', 'asc')
  5639. ->get(['name'])
  5640. ->pluck('name')
  5641. ->implode('');
  5642. // $job->address_name = $address ?? '';
  5643. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5644. }
  5645. if (empty($result)) {
  5646. return Result::error("招聘信息不存在", 0);
  5647. }
  5648. // return Result::success($job);
  5649. return Result::success($result);
  5650. }
  5651. /*
  5652. * 修改招聘信息
  5653. * */
  5654. public function upJobRecruiting(array $data): array
  5655. {
  5656. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5657. // return Result::success($job);
  5658. if (empty($job)) {
  5659. return Result::error("招聘信息不存在", 0);
  5660. }
  5661. $user = User::where('id', $data['user_id'])->first();
  5662. // return Result::success($user);
  5663. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5664. return Result::error("用户不存在", 0);
  5665. }
  5666. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5667. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5668. }
  5669. // 处理招聘关键词
  5670. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5671. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5672. } else {
  5673. Jieba::init(); // 初始化 jieba-php
  5674. Finalseg::init();
  5675. $segList = Jieba::cut($data['title']);
  5676. $segList1 = array_slice($segList, 0, 8);
  5677. $data['keyword'] = implode(',', $segList1);
  5678. }
  5679. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5680. $content = $data['description'];
  5681. // 去除 <style> 和 <script> 标签及其内容
  5682. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5683. // 去除所有 HTML 标签
  5684. $content = strip_tags($content);
  5685. // 去除 HTML 实体
  5686. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5687. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5688. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5689. // 去除多余空白
  5690. $content = preg_replace('/\s+/u', '', $content);
  5691. // 截取 100 个字符
  5692. $data['seo_description'] = mb_substr($content, 0, 100);
  5693. }
  5694. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5695. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5696. $data['catid'] = end($data['cat_arr_id']);
  5697. } else {
  5698. }
  5699. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5700. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5701. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5702. // 公司地址 管理员必填
  5703. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5704. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5705. // 管理员-企业相关信息
  5706. $company = [
  5707. // 'user_id' => $data['user_id']?? null,
  5708. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5709. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5710. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5711. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5712. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5713. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5714. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5715. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5716. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5717. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5718. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5719. ];
  5720. //去掉相关企业信息
  5721. $data = array_diff_key($data, array_flip(array_keys($company)));
  5722. $jobId = $data['id'];
  5723. $web = $data['website_id'];
  5724. $data['action_id'] = $data['user_id'];
  5725. unset($data['user_id']);
  5726. unset($data['user_type']);
  5727. unset($data['id']);
  5728. unset($data['website_id']);
  5729. // return Result::success($data);
  5730. Db::beginTransaction();
  5731. try {
  5732. // 管理员修改招聘信息
  5733. if ($user['type_id'] == 10000) {
  5734. $data['website_id'] = $web;
  5735. $company['website_id'] = $data['website_id'];
  5736. $data['status'] = 1;
  5737. } else {
  5738. $data['status'] = 0;
  5739. }
  5740. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5741. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5742. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5743. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5744. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5745. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5746. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5747. // return Result::success($job);
  5748. // Db::rollBack();
  5749. // return Result::success($company);
  5750. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5751. $this->sendMessage([
  5752. 'talk_type' => 500,
  5753. 'title' => $data['title'],
  5754. 'content' => '提交了审核',
  5755. 'messageType' => 10,
  5756. ]);
  5757. }
  5758. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5759. if (empty($result['job'])) {
  5760. Db::rollBack();
  5761. return Result::error("修改招聘信息失败");
  5762. }
  5763. // 管理员修改企业相关信息
  5764. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5765. if (empty($result['company'])) {
  5766. Db::rollBack();
  5767. return Result::error("修改企业相关信息失败");
  5768. }
  5769. Db::commit();
  5770. // return Result::success($result);
  5771. } catch (\Exception $e) {
  5772. Db::rollBack();
  5773. return Result::error($e->getMessage(), 0);
  5774. }
  5775. return Result::success($result);
  5776. }
  5777. /*
  5778. * 招聘信息删除
  5779. * */
  5780. public function delJobRecruiting(array $data): array
  5781. {
  5782. $user = User::where('id', $data['user_id'])->first();
  5783. if (empty($user)) {
  5784. return Result::error("用户不存在", 0);
  5785. }
  5786. $job = JobRecruiting::where('id', $data['id'])->first();
  5787. if (empty($job)) {
  5788. return Result::error("招聘信息不存在", 0);
  5789. }
  5790. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5791. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5792. }
  5793. Db::beginTransaction();
  5794. try {
  5795. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5796. if (empty($result['job'])) {
  5797. Db::rollBack();
  5798. return Result::error("删除招聘信息失败");
  5799. }
  5800. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5801. if (empty($result['company'])) {
  5802. Db::rollBack();
  5803. return Result::error("删除企业相关信息失败");
  5804. }
  5805. Db::commit();
  5806. } catch (\Exception $e) {
  5807. Db::rollBack();
  5808. return Result::error($e->getMessage(), 0);
  5809. }
  5810. return Result::success($result);
  5811. }
  5812. /*
  5813. * 获取公司信息
  5814. * */
  5815. public function getJobCompany(array $data): array
  5816. {
  5817. $user = User::where('user.id', $data['user_id'])
  5818. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5819. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5820. ->first();
  5821. // return Result::success($user);
  5822. if (empty($user)) {
  5823. return Result::error("用户不存在", 0);
  5824. }
  5825. if ($user['type_id'] == 3) {
  5826. $result = [
  5827. // 'id' => 0,
  5828. 'user_id' => $data['user_id'],
  5829. 'website_id' => $data['website_id'],
  5830. 'business_name' => $user['business_name'], // 企业名称
  5831. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5832. 'company_nature' => $user['company_nature'], // 公司性质
  5833. 'company_size' => $user['company_size'], // 公司规模
  5834. 'introduction' => $user['introduction'], // 公司简介
  5835. 'real_name' => $user['real_name'], // 企业联系人
  5836. 'mobile' => $user['mobile'], // 企业联系电话
  5837. 'company_url' => $user['company_url'], // 企业网址
  5838. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5839. 'address' => $user['address'], // 企业地址
  5840. 'email' => $user['email'], // 企业邮箱
  5841. ];
  5842. } else {
  5843. return Result::error("用户类型错误", 0);
  5844. }
  5845. if (empty($result)) {
  5846. return Result::error("公司信息不存在", 0);
  5847. }
  5848. return Result::success($result);
  5849. }
  5850. /*
  5851. * 修改公司信息
  5852. * */
  5853. public function upJobCompany(array $data): array
  5854. {
  5855. // return Result::success($data);
  5856. $user = User::where('user.id', $data['user_id'])
  5857. ->where('user.status', 1)
  5858. ->select('user.user_name', 'user.type_id')
  5859. ->first();
  5860. if (empty($user)) {
  5861. return Result::error("用户不存在", 0);
  5862. }
  5863. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5864. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5865. $company = [
  5866. 'business_name' => $data['business_name'], // 企业名称
  5867. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5868. 'company_nature' => $data['company_nature'], // 公司性质
  5869. 'company_size' => $data['company_size'], // 公司规模
  5870. 'introduction' => $data['introduction'], // 公司简介
  5871. // 'real_name' => $data['real_name'], // 企业联系人
  5872. 'company_url' => $data['company_url'], // 企业网址
  5873. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5874. 'address' => $data['address'], // 企业详细地址
  5875. // 'email' => $data['email'], // 企业邮箱
  5876. ];
  5877. if ($user['type_id'] == 3) {
  5878. Db::beginTransaction();
  5879. try {
  5880. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  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. ]);
  5891. if (empty($result['userinfo'])) {
  5892. Db::rollBack();
  5893. return Result::error('修改企业会员信息失败!');
  5894. }
  5895. $result['user'] = User::where('id', $data['user_id'])->update([
  5896. 'email' => $data['email'], // 企业邮箱
  5897. ]);
  5898. if (empty($result['user'])) {
  5899. Db::rollBack();
  5900. return Result::error('修改个人中心信息失败!');
  5901. }
  5902. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5903. if (!empty($job_company)) {
  5904. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5905. if (empty($result['job_company'])) {
  5906. Db::rollBack();
  5907. return Result::error('修改企业会员信息失败!');
  5908. }
  5909. }
  5910. Db::commit();
  5911. return Result::success($result);
  5912. } catch (\Exception $e) {
  5913. Db::rollBack();
  5914. return Result::error($e->getMessage(), 0);
  5915. }
  5916. } else {
  5917. return Result::error("用户类型错误", 0);
  5918. }
  5919. }
  5920. /*
  5921. * 获取省-市
  5922. * */
  5923. public function getJobRecruitingArea(array $data): array
  5924. {
  5925. if (isset($data['pid']) && $data['pid'] != null) {
  5926. $result = District::where('pid', $data['pid'])->get()->all();
  5927. } else {
  5928. $result = District::where('level', 1)->get()->all();
  5929. }
  5930. if (empty($result)) {
  5931. return Result::error("暂无此省市", 0);
  5932. }
  5933. return Result::success($result);
  5934. }
  5935. /*
  5936. * 获取行业分类
  5937. * */
  5938. public function getIndustry(array $data): array
  5939. {
  5940. $result = JobIndustry::get()->all();
  5941. if (empty($result)) {
  5942. return Result::error("暂无行业分类", 0);
  5943. }
  5944. return Result::success($result);
  5945. }
  5946. /*
  5947. * 获取职位
  5948. * */
  5949. public function getPositionList(array $data): array
  5950. {
  5951. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5952. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5953. } else {
  5954. $result = JobPosition::where('zwpid', 0)->get()->all();
  5955. }
  5956. if (empty($result)) {
  5957. return Result::error("暂无此职位", 0);
  5958. }
  5959. return Result::success($result);
  5960. }
  5961. /*
  5962. * 获取工作性质-菜单
  5963. * */
  5964. public function getJobNature(array $data): array
  5965. {
  5966. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5967. if (empty($result)) {
  5968. return Result::error("暂无工作性质", 0);
  5969. }
  5970. return Result::success($result);
  5971. }
  5972. /*
  5973. * 获取工作经验-菜单
  5974. * */
  5975. public function getExperience(array $data): array
  5976. {
  5977. $result = JobEnum::where('egroup', 'years')->get()->all();
  5978. if (empty($result)) {
  5979. return Result::error("暂无工作经验", 0);
  5980. }
  5981. return Result::success($result);
  5982. }
  5983. /*
  5984. * 获取学历-菜单
  5985. * */
  5986. public function getEducation(array $data): array
  5987. {
  5988. $result = JobEnum::where('egroup', 'education')->get()->all();
  5989. if (empty($result)) {
  5990. return Result::error("暂无学历", 0);
  5991. }
  5992. return Result::success($result);
  5993. }
  5994. /*
  5995. * 获取薪资-菜单
  5996. * */
  5997. public function getSalary(array $data): array
  5998. {
  5999. $result = JobEnum::where('egroup', 'income')->get()->all();
  6000. if (empty($result)) {
  6001. return Result::error("暂无薪资", 0);
  6002. }
  6003. return Result::success($result);
  6004. }
  6005. /*
  6006. * 获取语言-菜单
  6007. * */
  6008. public function getLanguage(array $data): array
  6009. {
  6010. $result = JobEnum::where('egroup', 'language')->get()->all();
  6011. if (empty($result)) {
  6012. return Result::error("暂无语言", 0);
  6013. }
  6014. return Result::success($result);
  6015. }
  6016. /*
  6017. * 获取掌握程度-菜单
  6018. * */
  6019. public function getLevel(array $data): array
  6020. {
  6021. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6022. if (empty($result)) {
  6023. return Result::error("暂无工作性质", 0);
  6024. }
  6025. return Result::success($result);
  6026. }
  6027. // 公司信息
  6028. /*
  6029. * 获取公司性质-菜单
  6030. * */
  6031. public function getCompanyNature(array $data): array
  6032. {
  6033. $result = JobNature::get()->all();
  6034. if (empty($result)) {
  6035. return Result::error("暂无公司性质", 0);
  6036. }
  6037. return Result::success($result);
  6038. }
  6039. /*
  6040. * 获取公司规模-菜单
  6041. * */
  6042. public function getCompanySize(array $data): array
  6043. {
  6044. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6045. if (empty($result)) {
  6046. return Result::error("暂无公司规模", 0);
  6047. }
  6048. return Result::success($result);
  6049. }
  6050. /*
  6051. * 招聘信息审核
  6052. * */
  6053. public function checkJobRecruiting(array $data): array
  6054. {
  6055. $user = User::where('id', $data['user_id'])->first();
  6056. if (empty($user)) {
  6057. return Result::error("用户不存在", 0);
  6058. }
  6059. $job = JobRecruiting::where('id', $data['id'])->first();
  6060. if (empty($job)) {
  6061. return Result::error("招聘信息不存在", 0);
  6062. }
  6063. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6064. if ($user['type_id'] != 10000) {
  6065. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6066. }
  6067. // 驳回原因
  6068. if ($data['status'] == 2) {
  6069. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6070. }
  6071. $data['action_id'] = $data['user_id'];
  6072. unset($data['user_id']);
  6073. if ($data['status'] == 1) {
  6074. $this->sendMessage([
  6075. 'talk_type' => 501,
  6076. 'title' => $job['title'],
  6077. 'content' => '审核通过',
  6078. 'messageType' => 10,
  6079. 'user_id' => $job['user_id'],
  6080. ]);
  6081. }
  6082. if ($data['status'] == 2) {
  6083. $this->sendMessage([
  6084. 'talk_type' => 501,
  6085. 'title' => $job['title'],
  6086. 'content' => '审核拒绝',
  6087. 'messageType' => 10,
  6088. 'user_id' => $job['user_id'],
  6089. ]);
  6090. }
  6091. if ($data['status'] == 0) {
  6092. $this->sendMessage([
  6093. 'talk_type' => 500,
  6094. 'title' => $job['title'],
  6095. 'content' => '提交了审核',
  6096. 'messageType' => 10,
  6097. ]);
  6098. }
  6099. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6100. if (empty($result)) {
  6101. return Result::error("审核失败", 0);
  6102. }
  6103. return Result::success($result);
  6104. }
  6105. public function myApplyList(array $data): array
  6106. {
  6107. var_dump($data, '------参数');
  6108. $user = User::where('id', $data['user_id'])->first();
  6109. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6110. return Result::error("用户不存在", 0);
  6111. }
  6112. // 1:个人会员 职场机会
  6113. if ($user['type_id'] == 1) {
  6114. $where['user_id'] = $user['id'];
  6115. }
  6116. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6117. $query->where('user_id', $user['id']);
  6118. })
  6119. ->pluck('recruit_id');
  6120. $where = [];
  6121. if (isset($data['salary']) && $data['salary'] != null) {
  6122. $where['job_recruiting.salary'] = $data['salary'];
  6123. }
  6124. if (isset($data['experience']) && $data['experience'] != null) {
  6125. $where['job_recruiting.experience'] = $data['experience'];
  6126. }
  6127. if (isset($data['business_name']) && $data['business_name'] != null) {
  6128. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6129. }
  6130. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6131. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6132. ->where($where);
  6133. // ->count();
  6134. $count = $query->count();
  6135. $query = clone $query;
  6136. $job = $query
  6137. ->leftJoin('job_enum as income_enum', function ($join) {
  6138. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6139. ->where('income_enum.egroup', 'income');
  6140. })
  6141. ->leftJoin('job_enum as years_enum', function ($join) {
  6142. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6143. ->where('years_enum.egroup', 'years');
  6144. })
  6145. // ->where($where)
  6146. ->orderBy('job_recruiting.updated_at', 'desc')
  6147. ->select(
  6148. 'job_recruiting.id',
  6149. 'job_recruiting.title',
  6150. 'job_company.business_name',
  6151. 'income_enum.evalue as salary_evalue',
  6152. 'income_enum.ename as salary_ename',
  6153. 'years_enum.evalue as experience_evalue',
  6154. 'years_enum.ename as experience_ename',
  6155. 'job_recruiting.updated_at'
  6156. )
  6157. ->offset(($data['page'] - 1) * $data['pageSize'])
  6158. ->limit($data['pageSize'])
  6159. ->get()
  6160. ->all();
  6161. if (empty($job)) {
  6162. return Result::error("暂无招聘信息", 0);
  6163. }
  6164. $result = [
  6165. 'row' => $job,
  6166. 'count' => $count,
  6167. ];
  6168. return Result::success($result);
  6169. }
  6170. public function readJobApply(array $data): array
  6171. {
  6172. $result = JobApply::where('id', $data['id'])->first();
  6173. if (empty($result)) {
  6174. return Result::error("查询失败", 0);
  6175. }
  6176. $result = JobApply::where('id', $data['id'])->update([
  6177. 'status' => 2,
  6178. ]);
  6179. return Result::success($result);
  6180. }
  6181. /*
  6182. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6183. * */
  6184. public function getRecruitingList(array $data): array
  6185. {
  6186. $user = User::where('id', $data['user_id'])->first();
  6187. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6188. return Result::error("用户不存在", 0);
  6189. }
  6190. // 1:个人会员 职场机会
  6191. if ($user['type_id'] == 1) {
  6192. $where['user_id'] = $user['id'];
  6193. }
  6194. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6195. $query->where('receiver_id', $user['id']);
  6196. })
  6197. ->pluck('recruit_id');
  6198. // return Result::success($recruitingId);
  6199. $where = [];
  6200. if (isset($data['salary']) && $data['salary'] != null) {
  6201. $where['job_recruiting.salary'] = $data['salary'];
  6202. }
  6203. if (isset($data['experience']) && $data['experience'] != null) {
  6204. $where['job_recruiting.experience'] = $data['experience'];
  6205. }
  6206. if (isset($data['business_name']) && $data['business_name'] != null) {
  6207. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6208. }
  6209. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6210. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6211. ->where($where);
  6212. // ->count();
  6213. $count = $query->count();
  6214. $query = clone $query;
  6215. $job = $query
  6216. ->leftJoin('job_enum as income_enum', function ($join) {
  6217. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6218. ->where('income_enum.egroup', 'income');
  6219. })
  6220. ->leftJoin('job_enum as years_enum', function ($join) {
  6221. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6222. ->where('years_enum.egroup', 'years');
  6223. })
  6224. // ->where($where)
  6225. ->orderBy('job_recruiting.updated_at', 'desc')
  6226. ->select(
  6227. 'job_recruiting.id',
  6228. 'job_recruiting.title',
  6229. 'job_company.business_name',
  6230. 'income_enum.evalue as salary_evalue',
  6231. 'income_enum.ename as salary_ename',
  6232. 'years_enum.evalue as experience_evalue',
  6233. 'years_enum.ename as experience_ename',
  6234. 'job_recruiting.updated_at'
  6235. )
  6236. ->offset(($data['page'] - 1) * $data['pageSize'])
  6237. ->limit($data['pageSize'])
  6238. ->get()
  6239. ->all();
  6240. if (empty($job)) {
  6241. return Result::error("暂无招聘信息", 0);
  6242. }
  6243. $result = [
  6244. 'row' => $job,
  6245. 'count' => $count,
  6246. ];
  6247. return Result::success($result);
  6248. }
  6249. /*
  6250. * 获取企业会员-招聘信息列表
  6251. * */
  6252. public function getRecruitingInfo(array $data): array
  6253. {
  6254. $user = User::where('id', $data['user_id'])->first();
  6255. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6256. return Result::error("用户不存在", 0);
  6257. }
  6258. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6259. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6260. ->select(
  6261. 'job_recruiting.*',
  6262. 'job_company.business_name',
  6263. 'job_company.company_hy_id',
  6264. 'job_company.company_size',
  6265. 'job_company.company_nature',
  6266. 'job_company.introduction',
  6267. 'job_company.real_name',
  6268. 'job_company.mobile',
  6269. 'job_company.company_url',
  6270. 'job_company.address_arr_id',
  6271. 'job_company.address',
  6272. 'job_company.email'
  6273. )
  6274. ->get();
  6275. if (empty($recruiting)) {
  6276. return Result::error("暂无招聘信息", 0);
  6277. }
  6278. return Result::success($recruiting);
  6279. }
  6280. /*
  6281. * 获取企业会员-我的沟通
  6282. * */
  6283. public function getJobResumeList(array $data): array
  6284. {
  6285. $user = User::where('id', $data['user_id'])->first();
  6286. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6287. return Result::error("用户不存在", 0);
  6288. }
  6289. $where = [];
  6290. if (isset($data['salary']) && $data['salary'] != null) {
  6291. $where['job_hunting.salary'] = $data['salary'];
  6292. }
  6293. if (isset($data['user_name']) && $data['user_name'] != null) {
  6294. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6295. }
  6296. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6297. $query->where('job_resume.user_id', $user['id']);
  6298. })
  6299. ->when(!empty($where), function ($query) use ($where) {
  6300. $query->where($where);
  6301. })
  6302. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6303. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6304. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6305. ->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');
  6306. $count = $job->count();
  6307. if ($count == 0) {
  6308. return Result::error("暂无沟通记录", 0);
  6309. }
  6310. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6311. ->offset(($data['page'] - 1) * $data['pageSize'])
  6312. ->limit($data['pageSize'])
  6313. ->get();
  6314. if (empty($jobs)) {
  6315. return Result::error("暂无沟通记录", 0);
  6316. }
  6317. $result['row'] = $this->processJob($jobs, '');
  6318. $result['count'] = $count;
  6319. return Result::success($result);
  6320. }
  6321. public function readJobResume(array $data): array
  6322. {
  6323. $result = JobResume::where('id', $data['id'])->first();
  6324. if (empty($result)) {
  6325. return Result::error("查询失败", 0);
  6326. }
  6327. $result = JobResume::where('id', $data['id'])->update([
  6328. 'status' => 2,
  6329. ]);
  6330. return Result::success($result);
  6331. }
  6332. // 20250306 招聘
  6333. //20250422 书刊音像
  6334. public function addBook(array $data): array
  6335. {
  6336. $user_id = $data['user_id'] ?? 0;
  6337. $type_id = $data['type_id'] ?? 0;
  6338. // $website_id = $data['website_id'] ?? 0;
  6339. // unset($data['user_id']);
  6340. unset($data['type_id']);
  6341. // unset($data['website_id']);
  6342. //处理数组
  6343. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6344. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6345. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6346. if ($data['img_url'] == '') {
  6347. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6348. preg_match_all($reg, $data['detail'], $matches);
  6349. if (isset($matches[1][0])) {
  6350. //截取varchar240
  6351. $data['img_url'] = substr($matches[1][0], 0, 240);
  6352. }
  6353. }
  6354. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6355. //提取标题+内容中的关键词
  6356. $data['keyword'] = $data['title'];
  6357. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6358. Jieba::init(); // 初始化 jieba-php
  6359. Finalseg::init();
  6360. $segList = Jieba::cut($data['keyword']);
  6361. $segList1 = array_slice($segList, 0, 8);
  6362. $data['keyword'] = implode(',', $segList1);
  6363. }
  6364. if ($data['description'] == '') {
  6365. //提取内容中的描述
  6366. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6367. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6368. }
  6369. var_dump($data, '--');
  6370. if ($data['status'] == 1) {
  6371. $this->sendMessage([
  6372. 'talk_type' => 400,
  6373. 'title' => $data['title'],
  6374. 'content' => '提交了审核',
  6375. 'messageType' => 7,
  6376. ]);
  6377. }
  6378. $result = Book::insertGetId($data);
  6379. if (empty($result)) {
  6380. return Result::error("添加失败", 0);
  6381. }
  6382. return Result::success($result);
  6383. }
  6384. public function getBookList(array $data): array
  6385. {
  6386. $where = [];
  6387. if (!empty($data["title"])) {
  6388. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6389. }
  6390. if (!empty($data['website_name'])) {
  6391. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6392. }
  6393. if (!empty($data['status'])) {
  6394. $where[] = ['book.status', '=', $data['status']];
  6395. }
  6396. $user_id = $data['user_id'];
  6397. $type_id = $data['type_id'];
  6398. // $type_id = 4;
  6399. var_dump($type_id, '------1--------');
  6400. if ($type_id != 10000) {
  6401. $where[] = ['book.user_id', '=', $user_id];
  6402. }
  6403. var_dump(!empty($data['status1']), '=-===1');
  6404. $result = Book::where($where)
  6405. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6406. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6407. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6408. ->when(isset($data['status1']), function ($query) use ($data) {
  6409. $query->whereIn('book.status', [1, 3]);
  6410. })
  6411. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6412. ->orderBy("updated_at", "desc")
  6413. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6414. if (empty($result)) {
  6415. return Result::error("暂无数据", 0);
  6416. }
  6417. // 取出数据
  6418. $rows = $result->items();
  6419. $count = $result->total();
  6420. $responseData = [
  6421. 'rows' => $rows,
  6422. 'count' => $count,
  6423. ];
  6424. return Result::success($responseData);
  6425. }
  6426. public function deleteBook(array $data): array
  6427. {
  6428. $result = Book::where('id', $data['id'])->delete();
  6429. if (empty($result)) {
  6430. return Result::error("删除失败", 0);
  6431. }
  6432. return Result::success($result);
  6433. }
  6434. public function updateBook(array $data): array
  6435. {
  6436. // $user_id = $data['user_id'] ?? 0;
  6437. $type_id = $data['type_id'] ?? 0;
  6438. // $website_id = $data['website_id'] ?? 0;
  6439. unset($data['user_id']);
  6440. unset($data['type_id']);
  6441. // unset($data['website_id']);
  6442. //处理数组
  6443. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6444. if ($data['img_url'] == '') {
  6445. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6446. preg_match_all($reg, $data['detail'], $matches);
  6447. if (isset($matches[1][0])) {
  6448. //截取varchar240
  6449. $data['img_url'] = substr($matches[1][0], 0, 240);
  6450. }
  6451. }
  6452. if ($data['keyword'] == '') {
  6453. //提取标题+内容中的关键词
  6454. $data['keyword'] = $data['title'];
  6455. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6456. Jieba::init(); // 初始化 jieba-php
  6457. Finalseg::init();
  6458. $segList = Jieba::cut($data['keyword']);
  6459. $segList1 = array_slice($segList, 0, 8);
  6460. $data['keyword'] = implode(',', $segList1);
  6461. }
  6462. if ($data['description'] == '') {
  6463. //提取内容中的描述
  6464. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6465. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6466. }
  6467. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6468. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6469. if ($data['status'] == 1) {
  6470. $this->sendMessage([
  6471. 'talk_type' => 400,
  6472. 'title' => $data['title'],
  6473. 'content' => '提交了审核',
  6474. 'messageType' => 7,
  6475. ]);
  6476. }
  6477. $result = Book::where("id", $data["id"])->update($data);
  6478. if (empty($result)) {
  6479. return Result::error("更新失败", 0);
  6480. }
  6481. return Result::success($result);
  6482. }
  6483. public function getBookInfo(array $data): array
  6484. {
  6485. $result = Book::where("id", $data["id"])->first();
  6486. if (empty($result)) {
  6487. return Result::error("获取失败", 0);
  6488. }
  6489. return Result::success($result);
  6490. }
  6491. public function updateBookStatus(array $data): array
  6492. {
  6493. //审核
  6494. unset($data['user_id']);
  6495. $bookInfo = Book::where("id", $data["id"])->first();
  6496. var_dump($bookInfo, '----');
  6497. if ($data['status'] == 2) {
  6498. $this->sendMessage([
  6499. 'talk_type' => 401,
  6500. 'title' => $bookInfo['title'],
  6501. 'content' => '审核通过',
  6502. 'messageType' => 7,
  6503. 'user_id' => $bookInfo['user_id'],
  6504. ]);
  6505. }
  6506. if ($data['status'] == 3) {
  6507. $this->sendMessage([
  6508. 'talk_type' => 401,
  6509. 'title' => $bookInfo['title'],
  6510. 'content' => '审核拒绝',
  6511. 'messageType' => 7,
  6512. 'user_id' => $bookInfo['user_id'],
  6513. ]);
  6514. }
  6515. if ($data['status'] == 1) {
  6516. $this->sendMessage([
  6517. 'talk_type' => 400,
  6518. 'title' => $bookInfo['title'],
  6519. 'content' => '提交了审核',
  6520. 'messageType' => 7,
  6521. // 'user_id'=>$bookInfo['user_id'],
  6522. ]);
  6523. }
  6524. $result = Book::where("id", $data["id"])->update($data);
  6525. if (empty($result)) {
  6526. return Result::error("更新失败", 0);
  6527. }
  6528. return Result::success($result);
  6529. }
  6530. //20250422 书刊音像
  6531. /**
  6532. * 贴身宝贝
  6533. * @param array $data
  6534. * @return array
  6535. */
  6536. public function getWebsiteTsbb(array $data): array
  6537. {
  6538. $month = $data['month'] ?? date('m');
  6539. $day = $data['day'] ?? date('d');
  6540. // 使用缓存键
  6541. $cacheKey = "tsbb_data_{$month}_{$day}";
  6542. // 尝试从缓存获取数据
  6543. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6544. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6545. if ($cachedData = $cache->get($cacheKey)) {
  6546. return Result::success(unserialize($cachedData));
  6547. }
  6548. //查询老黄历
  6549. try {
  6550. $date = date('Y-m-d');
  6551. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6552. // 使用 curl 替代 file_get_contents
  6553. $ch = curl_init();
  6554. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6555. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6556. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6557. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6558. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6559. 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');
  6560. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6561. 'Accept: application/json',
  6562. 'Content-Type: application/json',
  6563. 'Referer: https://www.36jxs.com/'
  6564. ]);
  6565. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6566. curl_setopt($ch, CURLOPT_ENCODING, '');
  6567. $almanacResponse = curl_exec($ch);
  6568. var_dump("====:", $almanacResponse);
  6569. if (curl_errno($ch)) {
  6570. var_dump('Curl error:', curl_error($ch));
  6571. throw new \Exception('Curl error: ' . curl_error($ch));
  6572. }
  6573. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6574. curl_close($ch);
  6575. if ($almanacResponse === false) {
  6576. throw new \Exception('Failed to fetch almanac data');
  6577. }
  6578. $almanacData = json_decode($almanacResponse, true);
  6579. if (json_last_error() !== JSON_ERROR_NONE) {
  6580. throw new \Exception('Failed to parse almanac data');
  6581. }
  6582. $almanacInfo = $almanacData['data'] ?? [];
  6583. } catch (\Exception $e) {
  6584. var_dump('Exception:', $e->getMessage());
  6585. $almanacInfo = [];
  6586. }
  6587. // 获取历史上的今天数据
  6588. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6589. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6590. ->orderBy('year', 'asc')
  6591. ->select("title", "id", "year", DB::raw('1 as type'))
  6592. ->limit(16)
  6593. ->get();
  6594. // 获取节日数据 - 从今天开始获取未来4条
  6595. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6596. ->orderBy('showtime', 'asc')
  6597. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6598. ->limit(16)
  6599. ->get();
  6600. //说文解字
  6601. $chartacterList = Character::orderBy('updated_at', 'desc')
  6602. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6603. ->limit(6)
  6604. ->get();
  6605. //谜语沙龙
  6606. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6607. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6608. ->limit(4)
  6609. ->get();
  6610. //成语欣赏
  6611. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6612. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6613. ->limit(32)
  6614. ->get();
  6615. //名联赏析
  6616. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6617. ->select("id", "first", "second", DB::raw('6 as type'))
  6618. ->limit(6)
  6619. ->get();
  6620. // 获取分类文章数据
  6621. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6622. ->pluck('category_id')
  6623. ->toArray();
  6624. $articlesList = [];
  6625. foreach ($categoryIds as $catid) {
  6626. // 先查有图片的
  6627. $withImg = DB::table('article')
  6628. ->where('status', 1)
  6629. ->where('catid', $catid)
  6630. ->whereNotNull('imgurl')
  6631. ->where('imgurl', '!=', '')
  6632. ->orderBy('updated_at', 'desc')
  6633. ->limit(6)
  6634. ->get();
  6635. $count = $withImg->count();
  6636. if ($count < 6) {
  6637. // 不足6条再查无图片的补足
  6638. $withoutImg = DB::table('article')
  6639. ->where('status', 1)
  6640. ->where('catid', $catid)
  6641. ->where(function ($q) {
  6642. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6643. })
  6644. ->orderBy('updated_at', 'desc')
  6645. ->limit(6 - $count)
  6646. ->get();
  6647. $articles = $withImg->concat($withoutImg);
  6648. } else {
  6649. $articles = $withImg;
  6650. }
  6651. // 组装
  6652. $category = \App\Model\Category::find($catid);
  6653. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6654. $articlesList[] = [
  6655. 'category_name' => $category ? $category->name : '',
  6656. 'catid' => $catid,
  6657. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6658. 'type' => 100,
  6659. 'list' => $articles->map(function ($item) {
  6660. return [
  6661. 'id' => $item->id,
  6662. 'title' => $item->title,
  6663. 'imgurl' => $item->imgurl,
  6664. 'created_at' => $item->created_at
  6665. ];
  6666. })->values()
  6667. ];
  6668. }
  6669. $result = [
  6670. 'almanac' => $almanacInfo,
  6671. 'historyTodayList' => [
  6672. 'category_name' => '历史上的今天',
  6673. 'list' => $historyTodayList,
  6674. 'type' => 1
  6675. ],
  6676. 'festivalList' => [
  6677. 'category_name' => '节日预告',
  6678. 'list' => $festivalList,
  6679. 'type' => 2
  6680. ],
  6681. 'chartacterList' => [
  6682. 'category_name' => '说文解字',
  6683. 'list' => $chartacterList,
  6684. 'type' => 3
  6685. ],
  6686. 'coupletList' => [
  6687. 'category_name' => '名联赏析',
  6688. 'list' => $coupletList,
  6689. 'type' => 6
  6690. ],
  6691. 'riddletList' => [
  6692. 'category_name' => '谜语沙龙',
  6693. 'list' => $riddletList,
  6694. 'type' => 4
  6695. ],
  6696. 'idiomList' => [
  6697. 'category_name' => '成语欣赏',
  6698. 'list' => $idiomList,
  6699. 'type' => 5
  6700. ],
  6701. 'articlesList' => $articlesList
  6702. ];
  6703. // 缓存结果,设置1小时过期
  6704. $cache->set($cacheKey, serialize($result), 3600);
  6705. return Result::success($result);
  6706. }
  6707. /**
  6708. * 获取资讯列表
  6709. */
  6710. public function getWebsiteTsbbList(array $data): array
  6711. {
  6712. $page = $data['page'] ?? 1;
  6713. $pageSize = $data['pageSize'] ?? 10;
  6714. // 如果没有传入月份和日期,则使用今天的日期
  6715. $month = $data['month'] ?? date('m');
  6716. $day = $data['day'] ?? date('d');
  6717. $total = 0;
  6718. $result = [];
  6719. $data['type'] = intval($data['type']);
  6720. var_dump("接收参数:", $data);
  6721. switch ($data['type']) {
  6722. case 1:
  6723. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6724. // 当前月份之后的数据
  6725. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6726. // 或者当前月份且日期大于等于当前日期的数据
  6727. ->orWhere(function ($q) use ($month, $day) {
  6728. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6729. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6730. });
  6731. })
  6732. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6733. $total = $query->count();
  6734. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6735. ->offset(($page - 1) * $pageSize)
  6736. ->limit($pageSize)
  6737. ->get();
  6738. break;
  6739. case 2:
  6740. $query = Festival::where(function ($q) use ($month, $day) {
  6741. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6742. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6743. ->orWhere(function ($q) use ($month, $day) {
  6744. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6745. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6746. });
  6747. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6748. $total = $query->count();
  6749. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6750. ->offset(($page - 1) * $pageSize)
  6751. ->limit($pageSize)
  6752. ->get();
  6753. break;
  6754. case 3:
  6755. $query = Character::orderBy("updated_at", "desc");
  6756. $total = $query->count();
  6757. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6758. ->offset(($page - 1) * $pageSize)
  6759. ->limit($pageSize)
  6760. ->get();
  6761. break;
  6762. case 4:
  6763. $query = Riddle::orderBy("updated_at", "desc");
  6764. $total = $query->count();
  6765. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6766. ->offset(($page - 1) * $pageSize)
  6767. ->limit($pageSize)
  6768. ->get();
  6769. break;
  6770. case 5:
  6771. $query = Idiom::orderBy("updated_at", "desc");
  6772. $total = $query->count();
  6773. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6774. ->offset(($page - 1) * $pageSize)
  6775. ->limit($pageSize)
  6776. ->get();
  6777. break;
  6778. case 6:
  6779. $query = Couplet::orderBy("updated_at", "desc");
  6780. $total = $query->count();
  6781. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6782. ->offset(($page - 1) * $pageSize)
  6783. ->limit($pageSize)
  6784. ->get();
  6785. break;
  6786. default:
  6787. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6788. $total = $query->count();
  6789. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6790. ->offset(($page - 1) * $pageSize)
  6791. ->limit($pageSize)
  6792. ->get();
  6793. }
  6794. return Result::success([
  6795. 'list' => $result,
  6796. 'total' => $total,
  6797. 'page' => (int)$page,
  6798. 'pageSize' => (int)$pageSize,
  6799. 'month' => $month,
  6800. 'day' => $day
  6801. ]);
  6802. }
  6803. /**
  6804. * 1:历史上的今天
  6805. * 2:节日
  6806. * 3:文章
  6807. *
  6808. * 资讯详情信息
  6809. */
  6810. public function getWebsiteTsbbDetail(array $data): array
  6811. {
  6812. $data['type'] = intval($data['type']);
  6813. switch ($data['type']) {
  6814. case 1:
  6815. $result = HistoryToday::where("id", $data['id'])->first();
  6816. break;
  6817. case 2:
  6818. $result = Festival::where("id", $data['id'])->first();
  6819. break;
  6820. case 3:
  6821. $result = Character::where("id", $data['id'])->first();
  6822. break;
  6823. case 4:
  6824. $result = Riddle::where("id", $data['id'])->first();
  6825. break;
  6826. case 5:
  6827. $result = Idiom::where("id", $data['id'])->first();
  6828. break;
  6829. case 6:
  6830. $result = Couplet::where("id", $data['id'])->first();
  6831. break;
  6832. default:
  6833. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6834. break;
  6835. }
  6836. return Result::success($result);
  6837. }
  6838. /**
  6839. * 农网导航首页数据
  6840. */
  6841. public function getWebsiteNwHomeList(array $data): array
  6842. {
  6843. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6844. ->pluck('category_id')
  6845. ->toArray();
  6846. // 使用子查询优化
  6847. $articlesList = DB::table('article')
  6848. ->select([
  6849. 'article.id',
  6850. 'article.title',
  6851. 'article.imgurl',
  6852. 'article.created_at',
  6853. 'category.name as category_name',
  6854. 'category.id as category_id',
  6855. 'website_category.aLIas_pinyin as pinyin',
  6856. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6857. DB::raw('100 as type')
  6858. ])
  6859. ->join('category', 'article.catid', '=', 'category.id')
  6860. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6861. ->leftJoin('website_category as parent_wc', function ($join) {
  6862. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6863. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6864. })
  6865. ->where('website_category.website_id', $data['website_id'])
  6866. ->where('article.status', 1)
  6867. ->whereIn('category.id', $categoryIds)
  6868. ->orderBy('article.created_at', 'desc')
  6869. ->get()
  6870. ->groupBy('category_id')
  6871. ->map(function ($group) {
  6872. // 确保第一条数据有图片
  6873. $firstWithImage = $group->first(function ($item) {
  6874. return !empty($item->imgurl);
  6875. });
  6876. if ($firstWithImage) {
  6877. // 如果有带图片的文章,将其放在第一位
  6878. $group = $group->filter(function ($item) use ($firstWithImage) {
  6879. return $item->id !== $firstWithImage->id;
  6880. })->prepend($firstWithImage);
  6881. }
  6882. return [
  6883. 'category_name' => $group->first()->category_name,
  6884. 'catid' => $group->first()->category_id,
  6885. 'pinyin' => $group->first()->pinyin,
  6886. 'parent_pinyin' => $group->first()->parent_pinyin,
  6887. 'list' => $group->take(4)->map(function ($item) {
  6888. return [
  6889. 'id' => $item->id,
  6890. 'title' => $item->title,
  6891. ];
  6892. })->values()
  6893. ];
  6894. })
  6895. ->values()
  6896. ->toArray();
  6897. return Result::success($articlesList);
  6898. }
  6899. /**
  6900. * 企业管理
  6901. * @param array $data
  6902. * @return array
  6903. */
  6904. public function getCompanyList(array $data): array
  6905. {
  6906. // return Result::success($data);
  6907. $where = [];
  6908. $user = User::where('id', $data['user_id'])->first();
  6909. if (empty($user)) {
  6910. return Result::error('用户不存在!');
  6911. }
  6912. if ($user['type_id'] != 10000) {
  6913. $where['user_id'] = $data['user_id'];
  6914. }
  6915. if (isset($data['title']) && !empty($data['title'])) {
  6916. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6917. }
  6918. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6919. array_push($where, ['website.id', $data['website_id']]);
  6920. }
  6921. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6922. if ($data['ischeck'] == 1) {
  6923. if (isset($data['status']) && $data['status'] != '') {
  6924. array_push($where, ['company.status', $data['status']]);
  6925. $query = Company::where($where);
  6926. } else {
  6927. $query = Company::whereIn('company.status', [0, 2]);
  6928. }
  6929. } else {
  6930. $query = Company::where('company.status', 1);
  6931. }
  6932. }
  6933. $result = $query->where($where)
  6934. ->leftJoin('website_category', function ($query) {
  6935. $query->on('website_category.category_id', '=', 'company.category_id')
  6936. ->on('website_category.website_id', '=', 'company.website_id');
  6937. })
  6938. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6939. ->select(
  6940. 'company.id',
  6941. 'company.title',
  6942. 'company.website_id',
  6943. 'company.category_id',
  6944. 'website.website_name',
  6945. 'website_category.alias as category_name',
  6946. 'company.status',
  6947. 'company.updated_at',
  6948. 'company.user_id'
  6949. )
  6950. ->orderBy('company.updated_at', 'desc')
  6951. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6952. if ($result->isEmpty()) {
  6953. return Result::error("暂无企业", 0);
  6954. }
  6955. return Result::success($result);
  6956. }
  6957. /**
  6958. * 添加企业
  6959. * @param array $data
  6960. * @return array
  6961. */
  6962. public function addCompany(array $data): array
  6963. {
  6964. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6965. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6966. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6967. $data['cat_arr_id'] = json_encode($car_arr_id);
  6968. } else {
  6969. $data['cat_arr_id'] = '';
  6970. }
  6971. if ($data['imgurl'] == '') {
  6972. //content中提取图片第一个图,正则提取
  6973. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6974. preg_match_all($reg, $data['content'], $matches);
  6975. if (isset($matches[1][0])) {
  6976. //截取varchar240
  6977. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6978. }
  6979. }
  6980. if ($data['keyword'] == '') {
  6981. //提取标题+内容中的关键词
  6982. $data['keyword'] = $data['title'];
  6983. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6984. Jieba::init(); // 初始化 jieba-php
  6985. Finalseg::init();
  6986. $segList = Jieba::cut($data['keyword']);
  6987. $segList1 = array_slice($segList, 0, 8);
  6988. $data['keyword'] = implode(',', $segList1);
  6989. }
  6990. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6991. //提取内容中的描述
  6992. $content = $data['content'];
  6993. // 去除 <style> 和 <script> 标签及其内容
  6994. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6995. // 去除所有 HTML 标签
  6996. $content = strip_tags($content);
  6997. // 去除 HTML 实体
  6998. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6999. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7000. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7001. // 去除多余空白
  7002. $content = preg_replace('/\s+/u', '', $content);
  7003. // 截取 100 个字符
  7004. $data['introduce'] = mb_substr($content, 0, 100);
  7005. }
  7006. $user = User::where('id', $data['user_id'])->first();
  7007. if (empty($user)) {
  7008. return Result::error('用户不存在!');
  7009. }
  7010. if ($user['type_id'] == 10000) {
  7011. $data['status'] = 1;
  7012. }
  7013. if (isset($data['level']) && $data['level'] != null) {
  7014. $data['level'] = intval($data['level']);
  7015. } else {
  7016. $data['level'] = null;
  7017. }
  7018. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7019. $this->sendMessage([
  7020. 'talk_type' => 900,
  7021. 'title' => $data['title'],
  7022. 'content' => '提交了审核',
  7023. 'messageType' => 8,
  7024. ]);
  7025. }
  7026. $result = Company::insertGetId($data);
  7027. if ($result) {
  7028. return Result::success($result);
  7029. } else {
  7030. return Result::error('添加失败');
  7031. }
  7032. }
  7033. /**
  7034. * 更新企业
  7035. * @param array $data
  7036. * @return array
  7037. */
  7038. public function upCompany(array $data): array
  7039. {
  7040. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7041. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7042. $data['cat_arr_id'] = json_encode($car_arr_id);
  7043. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7044. } else {
  7045. $data['cat_arr_id'] = '';
  7046. }
  7047. if ($data['imgurl'] == '') {
  7048. //content中提取图片第一个图,正则提取
  7049. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7050. preg_match_all($reg, $data['content'], $matches);
  7051. if (isset($matches[1][0])) {
  7052. //截取varchar
  7053. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7054. }
  7055. }
  7056. if ($data['keyword'] == '') {
  7057. //提取标题+内容中的关键词
  7058. $data['keyword'] = $data['title'];
  7059. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7060. Jieba::init(); // 初始化 jieba-php
  7061. Finalseg::init();
  7062. $segList = Jieba::cut($data['keyword']);
  7063. $segList1 = array_slice($segList, 0, 8);
  7064. $data['keyword'] = implode(',', $segList1);
  7065. }
  7066. if ($data['introduce'] == '') {
  7067. //提取内容中的描述
  7068. $content = $data['content'];
  7069. // 去除 <style> 和 <script> 标签及其内容
  7070. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7071. // 去除所有 HTML 标签
  7072. $content = strip_tags($content);
  7073. // 去除 HTML 实体
  7074. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7075. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7076. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7077. // 去除多余空白
  7078. $content = preg_replace('/\s+/u', '', $content);
  7079. // 截取 100 个字符
  7080. $data['introduce'] = mb_substr($content, 0, 100);
  7081. }
  7082. if (isset($data['level']) && $data['level'] != null) {
  7083. $data['level'] = intval($data['level']);
  7084. } else {
  7085. $data['level'] = null;
  7086. }
  7087. $user = User::where('id', $data['user_id'])->first();
  7088. if (empty($user)) {
  7089. return Result::error('用户不存在!');
  7090. }
  7091. if ($user['type_id'] == 10000) {
  7092. $data['status'] = 1;
  7093. } else {
  7094. $data['status'] = 0;
  7095. }
  7096. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7097. $this->sendMessage([
  7098. 'talk_type' => 900,
  7099. 'title' => $data['title'],
  7100. 'content' => '提交了审核',
  7101. 'messageType' => 8,
  7102. ]);
  7103. }
  7104. $result = Company::where('id', $data['id'])->update($data);
  7105. if ($result) {
  7106. return Result::success($result);
  7107. } else {
  7108. return Result::error('修改失败');
  7109. }
  7110. }
  7111. /**
  7112. * 删除企业
  7113. * @param array $data
  7114. * @return array
  7115. */
  7116. public function delCompany(array $data): array
  7117. {
  7118. $result = Company::where('id', $data['id'])->delete();
  7119. if ($result) {
  7120. return Result::success($result);
  7121. } else {
  7122. return Result::error('删除失败');
  7123. }
  7124. }
  7125. /**
  7126. * 审核企业
  7127. * @param array $data
  7128. * @return array
  7129. */
  7130. public function checkCompany(array $data): array
  7131. {
  7132. $user = User::where('id', $data['user_id'])->first();
  7133. if (empty($user)) {
  7134. return Result::error('用户不存在!');
  7135. }
  7136. $company = Company::where('id', $data['id'])->first();
  7137. if (empty($company)) {
  7138. return Result::error('企业不存在!');
  7139. }
  7140. // 状态:0:未审核 1:已审核 2:已拒绝
  7141. if ($data['status'] == 2 || $data['status'] == '2') {
  7142. $this->sendMessage([
  7143. 'talk_type' => 901,
  7144. 'title' => $company['title'],
  7145. 'content' => '审核拒绝',
  7146. 'messageType' => 8,
  7147. 'user_id' => $company['user_id'],
  7148. ]);
  7149. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7150. } else {
  7151. if ($data['status'] == 1) {
  7152. $this->sendMessage([
  7153. 'talk_type' => 901,
  7154. 'title' => $company['title'],
  7155. 'content' => '审核通过',
  7156. 'messageType' => 8,
  7157. 'user_id' => $company['user_id'],
  7158. ]);
  7159. } else if ($data['status'] == 0) {
  7160. $this->sendMessage([
  7161. 'talk_type' => 900,
  7162. 'title' => $company['title'],
  7163. 'content' => '提交了审核',
  7164. 'messageType' => 8,
  7165. ]);
  7166. }
  7167. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7168. }
  7169. if (empty($result)) {
  7170. return Result::error('审核失败!');
  7171. } else {
  7172. return Result::success($result);
  7173. }
  7174. }
  7175. /**
  7176. * 获取企业信息
  7177. * @param array $data
  7178. * @return array
  7179. */
  7180. public function getCompanyInfo(array $data): array
  7181. {
  7182. $result = Company::where('id', $data['id'])->first();
  7183. $city_arr = json_decode($result['city_arr_id']);
  7184. $result['city_name'] = District::whereIn('id', $city_arr)
  7185. ->pluck('name')
  7186. ->implode('-');
  7187. if (empty($result)) {
  7188. return Result::error('企业不存在!');
  7189. } else {
  7190. return Result::success($result);
  7191. }
  7192. }
  7193. /**
  7194. * @param array $data
  7195. * @return array
  7196. */
  7197. public function getWebsiteCompany(array $data): array
  7198. {
  7199. $categorys = json_decode($data['id'], true);
  7200. $category_arr = $this->processArticlePro($data['website_id']);
  7201. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7202. $catiall = $category_arr['catiall'];
  7203. $categoryIds = $category_arr['categoryIds'];
  7204. // return Result::success($category_arr);
  7205. foreach ($categorys as $key => $value) {
  7206. if (array_key_exists('level', $value)) {
  7207. $parts = explode(',', $value['level']);
  7208. $level = $parts[0] ?? null;
  7209. $imgnum = $parts[1] ?? null;
  7210. $textnum = $parts[2] ?? null;
  7211. if (!empty($textnum) && $textnum > 0) {
  7212. $text_num = Company::where('level', $level)
  7213. ->whereIn('category_id', $categoryIds)
  7214. ->where('status', 1)
  7215. ->select(
  7216. 'company.id',
  7217. 'company.title',
  7218. 'company.description',
  7219. 'company.updated_at',
  7220. 'company.category_id',
  7221. 'company.cat_arr_id'
  7222. )
  7223. ->orderBy('updated_at', 'desc')
  7224. ->limit($textnum)
  7225. ->get()->all();
  7226. }
  7227. if (!empty($imgnum) && $imgnum > 0) {
  7228. $img_num = Company::where('level', $level)
  7229. ->whereIn('category_id', $categoryIds)
  7230. ->where('status', 1)
  7231. ->where('imgurl', '!=', '')
  7232. ->whereNotNull('imgurl')
  7233. ->select(
  7234. 'company.id',
  7235. 'company.title',
  7236. 'company.description',
  7237. 'company.updated_at',
  7238. 'company.imgurl as imgs',
  7239. 'company.category_id',
  7240. 'company.cat_arr_id'
  7241. )
  7242. ->orderBy('updated_at', 'desc')
  7243. ->limit($imgnum)
  7244. ->get()->all();
  7245. }
  7246. }
  7247. if (array_key_exists('id', $value)) {
  7248. $parts = explode(',', $value['id']);
  7249. $category_id = $parts[0] ?? null;
  7250. $imgnum = $parts[1] ?? null;
  7251. $textnum = $parts[2] ?? null;
  7252. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7253. if (!empty($textnum) && $textnum > 0) {
  7254. $text_num = Company::whereIn('category_id', $category_arr)
  7255. // ->where('website_id', $data['website_id'])
  7256. ->where('status', 1)
  7257. ->select(
  7258. 'company.id',
  7259. 'company.title',
  7260. 'company.description',
  7261. 'company.updated_at',
  7262. 'company.category_id',
  7263. 'company.cat_arr_id'
  7264. )
  7265. ->orderBy('updated_at', 'desc')
  7266. ->limit($textnum)
  7267. ->get()->all();
  7268. }
  7269. if (!empty($imgnum) && $imgnum > 0) {
  7270. $img_num = Company::whereIn('category_id', $category_arr)
  7271. // ->where('website_id', $data['website_id'])
  7272. ->where('status', 1)
  7273. ->where('imgurl', '!=', '')
  7274. ->whereNotNull('imgurl')
  7275. ->select(
  7276. 'company.id',
  7277. 'company.title',
  7278. 'company.description',
  7279. 'company.updated_at',
  7280. 'company.imgurl as imgs',
  7281. 'company.category_id',
  7282. 'company.cat_arr_id'
  7283. )
  7284. ->orderBy('updated_at', 'desc')
  7285. ->limit($imgnum)
  7286. ->get()->all();
  7287. }
  7288. }
  7289. if (!empty($text_num)) {
  7290. foreach ($text_num as $k => $v) {
  7291. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7292. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7293. }
  7294. }
  7295. if (!empty($img_num)) {
  7296. foreach ($img_num as $k => $v) {
  7297. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7298. $imgurl = json_decode($v['imgs'], true);
  7299. if (!empty($imgurl)) {
  7300. $img_num[$k]->imgurl = $imgurl[0];
  7301. }
  7302. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7303. }
  7304. }
  7305. $company[$key]['img_num'] = $img_num ?? [];
  7306. $company[$key]['text_num'] = $text_num ?? [];
  7307. }
  7308. if (empty($company)) {
  7309. return Result::error("暂无相关企业信息", 0);
  7310. }
  7311. return Result::success($company);
  7312. }
  7313. /**
  7314. * @param array $data
  7315. * @return array
  7316. */
  7317. public function getWebsiteCompanyList(array $data): array
  7318. {
  7319. $where['website_id'] = $data['website_id'];
  7320. $where['status'] = 1;
  7321. $categoryIds = [];
  7322. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7323. $category_id = $data['category_id'];
  7324. }
  7325. $category_arr = $this->processArticlePro($data['website_id']);
  7326. $categoryIds = $category_arr['categoryIds'];
  7327. // return Result::success($cat_1st_arr);
  7328. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7329. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7330. })
  7331. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7332. $query->whereIn('category_id', $categoryIds);
  7333. })
  7334. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7335. $query->where('category_id', $category_id);
  7336. })
  7337. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7338. ->orderBy('updated_at', 'desc')
  7339. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7340. if (empty($company)) {
  7341. return Result::error("暂无相关公司信息", 0);
  7342. }
  7343. $result = [
  7344. 'count' => $company->total(),
  7345. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7346. ];
  7347. return Result::success($result);
  7348. }
  7349. /**
  7350. * 获取项目列表
  7351. * @param array $data
  7352. * @return array
  7353. */
  7354. public function getProjectList(array $data): array
  7355. {
  7356. $where = [];
  7357. $user = User::where('id', $data['user_id'])->first();
  7358. if (empty($user)) {
  7359. return Result::error('用户不存在!');
  7360. }
  7361. if ($user->type_id != 10000) {
  7362. array_push($where, ['project.user_id', $data['user_id']]);
  7363. }
  7364. $query = Project::query();
  7365. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7366. array_push($where, ['project.website_id', $data['website_id']]);
  7367. }
  7368. if (isset($data['title']) && !empty($data['title'])) {
  7369. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7370. }
  7371. if ($data['status'] != 3) {
  7372. array_push($where, ['project.status', $data['status']]);
  7373. }
  7374. $query = Project::where($where)
  7375. ->when($data['status'] == 3, function ($query) {
  7376. $query->whereIn('project.status', [0, 2]);
  7377. });
  7378. $count = $query->clone()
  7379. ->count();
  7380. $rows = $query->clone()
  7381. ->leftJoin('website', 'project.website_id', 'website.id')
  7382. ->leftJoin('website_category', function ($join) {
  7383. $join->on('project.website_id', '=', 'website_category.website_id')
  7384. ->on('project.category_id', '=', 'website_category.category_id');
  7385. })
  7386. ->select(
  7387. 'project.id',
  7388. 'project.title',
  7389. 'project.updated_at',
  7390. 'project.status',
  7391. 'website.website_name',
  7392. 'website_category.alias as category_name',
  7393. 'project.website_id',
  7394. 'project.user_id'
  7395. )
  7396. ->orderBy('project.updated_at', 'desc')
  7397. ->offset(($data['page'] - 1) * $data['pageSize'])
  7398. ->limit($data['pageSize'])
  7399. ->get();
  7400. if ($rows->isEmpty()) {
  7401. return Result::error("暂无相关项目信息", 0);
  7402. }
  7403. $result = [
  7404. 'count' => $count,
  7405. 'rows' => $rows,
  7406. ];
  7407. return Result::success($result);
  7408. }
  7409. /**
  7410. * 添加项目
  7411. * @param array $data
  7412. * @return array
  7413. */
  7414. public function addProject(array $data): array
  7415. {
  7416. $user = User::where('id', $data['user_id'])->first();
  7417. if (empty($user)) {
  7418. return Result::error("暂无相关用户信息", 0);
  7419. }
  7420. if ($user->type_id == 10000) {
  7421. $data['status'] = 1;
  7422. } else {
  7423. $data['status'] = 0;
  7424. }
  7425. if ($data['keyword'] == '') {
  7426. //提取标题+内容中的关键词
  7427. $data['keyword'] = $data['title'];
  7428. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7429. Jieba::init(); // 初始化 jieba-php
  7430. Finalseg::init();
  7431. $segList = Jieba::cut($data['keyword']);
  7432. $segList1 = array_slice($segList, 0, 8);
  7433. $data['keyword'] = implode(',', $segList1);
  7434. }
  7435. if ($data['description'] == '') {
  7436. //提取内容中的描述
  7437. // var_dump(11111);
  7438. //提取内容中的描述
  7439. $content = $data['introduce'];
  7440. // 去除 <style> 和 <script> 标签及其内容
  7441. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7442. // 去除所有 HTML 标签
  7443. $content = strip_tags($content);
  7444. // 去除 HTML 实体
  7445. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7446. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7447. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7448. // 去除多余空白
  7449. $content = preg_replace('/\s+/u', '', $content);
  7450. // 截取 100 个字符
  7451. $data['description'] = mb_substr($content, 0, 100);
  7452. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7453. }
  7454. if ($data['status'] == 0) {
  7455. $this->sendMessage([
  7456. 'talk_type' => 1000,
  7457. 'title' => $data['title'],
  7458. 'content' => '提交了审核',
  7459. 'messageType' => 9,
  7460. ]);
  7461. }
  7462. $project = Project::insertGetId($data);
  7463. if (empty($project)) {
  7464. return Result::error("暂无相关项目信息", 0);
  7465. }
  7466. return Result::success($project);
  7467. }
  7468. /**
  7469. * 更新项目
  7470. * @param array $data
  7471. * @return array
  7472. */
  7473. public function upProject(array $data): array
  7474. {
  7475. $project = Project::where('id', $data['id'])->first();
  7476. if (empty($project)) {
  7477. return Result::error("暂无相关项目信息", 0);
  7478. }
  7479. $id = $data['id'];
  7480. unset($data['id']);
  7481. $user = User::where('id', $data['user_id'])->first();
  7482. if (empty($user)) {
  7483. return Result::error("暂无相关用户信息", 0);
  7484. }
  7485. if ($user->type_id == 10000) {
  7486. $data['status'] = 1;
  7487. } else {
  7488. $data['status'] = 0;
  7489. }
  7490. unset($data['user_id']);
  7491. if ($data['keyword'] == '') {
  7492. //提取标题+内容中的关键词
  7493. $data['keyword'] = $data['title'];
  7494. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7495. Jieba::init(); // 初始化 jieba-php
  7496. Finalseg::init();
  7497. $segList = Jieba::cut($data['keyword']);
  7498. $segList1 = array_slice($segList, 0, 8);
  7499. $data['keyword'] = implode(',', $segList1);
  7500. }
  7501. if ($data['description'] == '') {
  7502. //提取内容中的描述
  7503. // var_dump(11111);
  7504. //提取内容中的描述
  7505. $content = $data['introduce'];
  7506. // 去除 <style> 和 <script> 标签及其内容
  7507. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7508. // 去除所有 HTML 标签
  7509. $content = strip_tags($content);
  7510. // 去除 HTML 实体
  7511. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7512. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7513. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7514. // 去除多余空白
  7515. $content = preg_replace('/\s+/u', '', $content);
  7516. // 截取 100 个字符
  7517. $data['description'] = mb_substr($content, 0, 100);
  7518. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7519. }
  7520. if ($data['status'] == 0) {
  7521. $this->sendMessage([
  7522. 'talk_type' => 1000,
  7523. 'title' => $data['title'],
  7524. 'content' => '提交了审核',
  7525. 'messageType' => 9,
  7526. ]);
  7527. }
  7528. $result = Project::where('id', $id)->update($data);
  7529. if (empty($result)) {
  7530. return Result::error("更新失败", 0);
  7531. }
  7532. return Result::success($result);
  7533. }
  7534. /**
  7535. * 删除项目
  7536. * @param array $data
  7537. * @return array
  7538. */
  7539. public function delProject(array $data): array
  7540. {
  7541. $user = User::where('id', $data['user_id'])->first();
  7542. if (empty($user)) {
  7543. return Result::error("暂无相关用户信息", 0);
  7544. }
  7545. $project = Project::where('id', $data['id'])->first();
  7546. if (empty($project)) {
  7547. return Result::error("暂无相关项目信息", 0);
  7548. }
  7549. $result = Project::where('id', $data['id'])->delete();
  7550. if (empty($result)) {
  7551. return Result::error("删除失败", 0);
  7552. }
  7553. return Result::success($result);
  7554. }
  7555. /**
  7556. * 审核项目
  7557. * @param array $data
  7558. * @return array
  7559. */
  7560. public function checkProject(array $data): array
  7561. {
  7562. $user = User::where('id', $data['user_id'])->first();
  7563. if (empty($user)) {
  7564. return Result::error("暂无相关用户信息", 0);
  7565. }
  7566. // 0:未审核; 1:已审核; 2:已拒绝;
  7567. if ($user->type_id != 10000) {
  7568. if ($data['status'] == 1 || $data['status'] == 2) {
  7569. return Result::error("此用户权限不足", 0);
  7570. }
  7571. }
  7572. $project = Project::where('id', $data['id'])->first();
  7573. if (empty($project)) {
  7574. return Result::error("暂无相关项目信息", 0);
  7575. }
  7576. if ($data['status'] == 2) {
  7577. $this->sendMessage([
  7578. 'talk_type' => 1001,
  7579. 'title' => $project['title'],
  7580. 'content' => '审核拒绝',
  7581. 'messageType' => 9,
  7582. 'user_id' => $project['user_id'],
  7583. ]);
  7584. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7585. } else {
  7586. if ($data['status'] == 1) {
  7587. $this->sendMessage([
  7588. 'talk_type' => 1001,
  7589. 'title' => $project['title'],
  7590. 'content' => '审核通过',
  7591. 'messageType' => 9,
  7592. 'user_id' => $project['user_id'],
  7593. ]);
  7594. } else if ($data['status'] == 0) {
  7595. $this->sendMessage([
  7596. 'talk_type' => 1000,
  7597. 'title' => $project['title'],
  7598. 'content' => '提交了审核',
  7599. 'messageType' => 9,
  7600. ]);
  7601. }
  7602. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7603. }
  7604. if (empty($result)) {
  7605. return Result::error("审核失败", 0);
  7606. }
  7607. return Result::success($result);
  7608. }
  7609. /**
  7610. * 获取项目详情
  7611. * @param array $data
  7612. * @return array
  7613. */
  7614. public function getProjectInfo(array $data): array
  7615. {
  7616. $project = Project::where('id', $data['id'])->first();
  7617. if (empty($project)) {
  7618. return Result::error("暂无相关项目信息", 0);
  7619. }
  7620. return Result::success($project);
  7621. }
  7622. public function getWebsiteCompanyInfo(array $data): array
  7623. {
  7624. $company = Company::where('id', $data['id'])
  7625. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7626. ->where('status', 1)
  7627. // ->where('website_id', $data['website_id'])
  7628. ->select('company.*', 'job_industry.hyname as hy_name')
  7629. ->first();
  7630. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7631. switch ($company->jobnature_id) {
  7632. case null:
  7633. $company->jobnature_name = '';
  7634. break;
  7635. case 0:
  7636. $company->jobnature_name = '市场监督';
  7637. break;
  7638. case 1:
  7639. $company->jobnature_name = '信访纪检';
  7640. break;
  7641. case 2:
  7642. $company->jobnature_name = '公检法司';
  7643. break;
  7644. case 3:
  7645. $company->jobnature_name = '高关注机构';
  7646. break;
  7647. default:
  7648. $company->jobnature_name = '';
  7649. break;
  7650. }
  7651. $city_arr = $company->city_arr_id;
  7652. if (!empty($city_arr)) {
  7653. $city_arr = json_decode($city_arr, true);
  7654. $cityNames = District::whereIn('id', $city_arr)
  7655. ->pluck('name')
  7656. ->implode('-');
  7657. $company->city_name = $cityNames;
  7658. } else {
  7659. $company->city_name = '';
  7660. }
  7661. if (empty($company)) {
  7662. return Result::error("暂无相关公司信息", 0);
  7663. }
  7664. return Result::success($company);
  7665. }
  7666. public function getMSG(array $data): array
  7667. {
  7668. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7669. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7670. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7671. $result = [];
  7672. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7673. //最近的5篇已审的文章
  7674. $apply_articale = Article::where('status', 1)
  7675. ->where('admin_user_id', $user_id)
  7676. ->orderBy('updated_at', 'desc')
  7677. // ->limit(5)
  7678. ->get();
  7679. //获取5条用户的已审核商品
  7680. $good = Good::where('status', 2)
  7681. ->where('user_id', $user_id)
  7682. ->orderBy('updated_at', 'desc')
  7683. // ->limit(5)
  7684. ->get();
  7685. //获取5条用户待审核的公告
  7686. $notice = Notice::where('status', 2)
  7687. ->where('user_id', $user_id)
  7688. ->orderBy('updated_at', 'desc')
  7689. ->limit(5)->get();
  7690. //获取5条用户的待审核投诉
  7691. $complaint = Complaint::where('status', 2)
  7692. ->where('user_id', $user_id)
  7693. ->orderBy('updated_at', 'desc')
  7694. // ->limit(5)
  7695. ->get();
  7696. //获取5条用户的book
  7697. $book = Book::where('status', 2)
  7698. ->where('user_id', $user_id)
  7699. ->orderBy('updated_at', 'desc')
  7700. // ->limit(5)
  7701. ->get();
  7702. //获取5条用户的求职
  7703. //获取5条用户的求职 1
  7704. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7705. ->where('job_hunting.user_id', $user_id)
  7706. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7707. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7708. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7709. ->orderBy('updated_at', 'desc')
  7710. // ->limit(5)
  7711. ->get();
  7712. //获取5条用户的求职 2
  7713. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7714. ->where('job_recruiting.user_id', $user_id)
  7715. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7716. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7717. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7718. ->orderBy('updated_at', 'desc')
  7719. // ->limit(5)
  7720. ->get();
  7721. //人才库 1
  7722. $job_apply = JobApply::where('job_apply.status', 1)
  7723. ->where('job_apply.receiver_id', $user_id)
  7724. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7725. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7726. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7727. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7728. ->select('job_recruiting', 'job_recruiting.', '', '')
  7729. ->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')
  7730. ->orderBy('updated_at', 'desc')
  7731. // ->limit(5)
  7732. ->get();
  7733. // 职场机会 2
  7734. $job_resume = JobResume::where('job_resume.status', 1)
  7735. ->where('job_resume.receiver_id', $user_id)
  7736. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7737. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7738. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7739. ->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')
  7740. ->orderBy('updated_at', 'desc')
  7741. // ->limit(5)
  7742. ->get();
  7743. //获取5条用户待处理的投诉
  7744. $complaint_deal = Complaint::where('status', 2)
  7745. ->where('deal', 1)
  7746. ->whereJsonContains('re_user_ids', $user_id)
  7747. ->orderBy('updated_at', 'desc')
  7748. // ->limit(5)
  7749. ->get();
  7750. //获取 被通知者未读信息
  7751. $notice_unread = Notice::where('status', 2)
  7752. ->whereJsonContains('re_user_ids', $user_id)
  7753. //未读消息
  7754. ->where(function ($query) use ($user_id) {
  7755. $query->whereJsonDoesntContain('read_id', $user_id)
  7756. ->orWhereNull('read_id');
  7757. })
  7758. ->orderBy('updated_at', 'desc')
  7759. ->get();
  7760. $complaint_unread = Complaint::where('status', 2)
  7761. ->whereJsonContains('re_user_ids', $user_id)
  7762. //未读消息
  7763. ->where(function ($query) use ($user_id) {
  7764. $query->whereJsonDoesntContain('read_id', $user_id)
  7765. ->orWhereNull('read_id');
  7766. })
  7767. ->orderBy('updated_at', 'desc')
  7768. ->get();
  7769. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7770. $complany = Company::where('status', 1)
  7771. ->where('user_id', $user_id)
  7772. ->orderBy('updated_at', 'desc')
  7773. // ->limit(5)
  7774. ->get();
  7775. //获取5条单聊未读聊天消息
  7776. // $chat = ChatRecords::where('is_read', 0)
  7777. // ->where('user_id', $user_id)
  7778. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7779. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7780. // ->where('action', 'recieved')
  7781. // ->where('talk_type', 1)
  7782. // ->orderBy('created_at', 'desc')
  7783. // // ->limit(5)
  7784. // ->get();
  7785. //获取5条未读群聊信息
  7786. // $chat_group = ChatRecords::where('is_read', 0)
  7787. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7788. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7789. // ->where('user_id', $user_id)
  7790. // ->where('talk_type', 2)
  7791. // ->orderBy('created_at', 'desc')
  7792. // // ->limit(5)
  7793. // ->get();
  7794. //获取5条用户的待审核项目
  7795. $project = Project::where('status', 1)
  7796. ->where('user_id', $user_id)
  7797. ->orderBy('updated_at', 'desc')
  7798. // ->limit(5)
  7799. ->get();
  7800. // count($chat) + count($chat_group) +
  7801. $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)
  7802. + count($complany)
  7803. + count($project)
  7804. + count($notice_unread)
  7805. + count($complaint_unread)
  7806. // + count($chat) + count($chat_group)
  7807. ;
  7808. $result = [
  7809. 'apply_articale' => $apply_articale,
  7810. // 'chat' => $chat,
  7811. // 'chat_group' => $chat_group,
  7812. 'good' => $good,
  7813. 'notice' => $notice,
  7814. 'complaint' => $complaint,
  7815. 'book' => $book,
  7816. 'job_hunting' => $job_hunting,
  7817. 'job_recruiting' => $job_recruiting,
  7818. 'job_apply' => $job_apply,
  7819. 'job_resume' => $job_resume,
  7820. 'complaint_deal' => $complaint_deal,
  7821. 'complany' => $complany,
  7822. 'project' => $project,
  7823. 'notice_unread' => $notice_unread,
  7824. 'complaint_unread' => $complaint_unread,
  7825. 'count' => $count,
  7826. ];
  7827. } elseif ($type_id == 12) {
  7828. //最近的5篇已审的文章
  7829. $apply_articale = Article::where('status', 1)
  7830. ->where('admin_user_id', $user_id)
  7831. ->limit(5)->get();
  7832. //获取5条单聊未读聊天消息
  7833. $chat = ChatRecords::where('is_read', 0)
  7834. ->where('user_id', $user_id)
  7835. ->where('talk_type', 1)
  7836. ->orderBy('created_at', 'desc')
  7837. ->limit(5)->get();
  7838. //获取5条未读群聊信息
  7839. $chat_group = ChatRecords::where('is_read', 0)
  7840. ->where('user_id', $user_id)
  7841. ->where('talk_type', 2)
  7842. ->orderBy('created_at', 'desc')
  7843. ->limit(5)->get();
  7844. //获取5条用户的已审核商品
  7845. $good = Good::where('status', 2)
  7846. ->where('user_id', $user_id)
  7847. ->orderBy('updated_at', 'desc')
  7848. ->limit(5)->get();
  7849. //获取5条用户的book
  7850. $book = Book::where('status', 2)
  7851. ->where('user_id', $user_id)
  7852. ->orderBy('updated_at', 'desc')
  7853. ->limit(5)->get();
  7854. //获取5条用户的求职
  7855. //获取5条用户的求职 1
  7856. //count($chat) + count($chat_group)
  7857. $count = count($apply_articale) + count($good);
  7858. $result = [
  7859. 'apply_articale' => $apply_articale,
  7860. 'chat' => $chat,
  7861. 'chat_group' => $chat_group,
  7862. 'good' => $good,
  7863. 'book' => $book,
  7864. 'count' => $count,
  7865. ];
  7866. } elseif ($type_id == 13) {
  7867. //最近的5篇已审的文章
  7868. $apply_articale = Article::where('status', 1)
  7869. ->where('admin_user_id', $user_id)
  7870. ->limit(5)->get();
  7871. //获取5条单聊未读聊天消息
  7872. $chat = ChatRecords::where('is_read', 0)
  7873. ->where('user_id', $user_id)
  7874. ->where('talk_type', 1)
  7875. ->orderBy('created_at', 'desc')
  7876. ->limit(5)->get();
  7877. //获取5条未读群聊信息
  7878. $chat_group = ChatRecords::where('is_read', 0)
  7879. ->where('user_id', $user_id)
  7880. ->where('talk_type', 2)
  7881. ->orderBy('created_at', 'desc')
  7882. ->limit(5)->get();
  7883. //获取5条用户的已审核商品
  7884. $good = Good::where('status', 2)
  7885. ->where('user_id', $user_id)
  7886. ->orderBy('updated_at', 'desc')
  7887. ->limit(5)->get();
  7888. //count($chat) + count($chat_group) +
  7889. $count = count($apply_articale) + count($good);
  7890. $result = [
  7891. 'apply_articale' => $apply_articale,
  7892. 'chat' => $chat,
  7893. 'chat_group' => $chat_group,
  7894. 'good' => $good,
  7895. 'count' => $count,
  7896. ];
  7897. } elseif ($type_id == 14) {
  7898. //最近的5篇已审的文章
  7899. $apply_articale = Article::where('status', 1)
  7900. ->where('admin_user_id', $user_id)
  7901. // ->limit(5)
  7902. ->get();
  7903. //获取5条用户的已审核商品
  7904. $good = Good::where('status', 2)
  7905. ->where('user_id', $user_id)
  7906. ->orderBy('updated_at', 'desc')
  7907. // ->limit(5)
  7908. ->get();
  7909. $count = count($apply_articale) + count($good);
  7910. $result = [
  7911. 'apply_articale' => $apply_articale,
  7912. 'chat' => '',
  7913. 'chat_group' => '',
  7914. 'good' => $good,
  7915. 'count' => $count,
  7916. ];
  7917. } elseif ($type_id == 10000) {
  7918. //获取未审核的5篇文章
  7919. $apply_articale = Article::where('status', 0)
  7920. ->orderBy('updated_at', 'desc')
  7921. // ->limit(5)
  7922. ->get();
  7923. //获取5条单聊未读聊天消息
  7924. //获取5条单聊未读聊天消息
  7925. // $chat = ChatRecords::where('is_read', 0)
  7926. // ->where('user_id', $user_id)
  7927. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7928. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7929. // ->where('action', 'recieved')
  7930. // ->where('talk_type', 1)
  7931. // ->orderBy('created_at', 'desc')
  7932. // // ->limit(5)
  7933. // ->get();
  7934. // //获取5条未读群聊信息
  7935. // $chat_group = ChatRecords::where('is_read', 0)
  7936. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7937. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7938. // ->where('user_id', $user_id)
  7939. // ->where('talk_type', 2)
  7940. // ->orderBy('created_at', 'desc')
  7941. // // ->limit(5)
  7942. // ->get();
  7943. //获取5条用户的已审核商品
  7944. $good = Good::where('status', 1)
  7945. // ->where('user_id', $user_id)
  7946. ->orderBy('updated_at', 'desc')
  7947. // ->limit(5)
  7948. ->get();
  7949. //获取5条用户待审核的公告
  7950. $notice = Notice::where('status', 1)
  7951. ->orderBy('updated_at', 'desc')
  7952. // ->limit(5)
  7953. ->get();
  7954. //获取5条用户的待审核投诉
  7955. $complaint = Complaint::where('status', 1)
  7956. ->orderBy('updated_at', 'desc')
  7957. // ->limit(5)
  7958. ->get();
  7959. //获取5条用户的book
  7960. $book = Book::where('status', 1)
  7961. ->orderBy('updated_at', 'desc')
  7962. // ->limit(5)
  7963. ->get();
  7964. //获取5条用户的求职 1
  7965. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7966. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7967. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7968. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7969. ->orderBy('updated_at', 'desc')
  7970. // ->limit(5)
  7971. ->get();
  7972. //获取5条用户的求职 2
  7973. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7974. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7975. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7976. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7977. ->orderBy('updated_at', 'desc')
  7978. // ->limit(5)
  7979. ->get();
  7980. //人才库 1
  7981. $job_apply = JobApply::where('job_apply.status', 1)
  7982. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7983. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7984. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7985. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7986. ->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')
  7987. ->orderBy('updated_at', 'desc')
  7988. // ->limit(5)
  7989. ->get();
  7990. // 职场机会 2
  7991. $job_resume = JobResume::where('job_resume.status', 1)
  7992. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7993. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7994. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7995. ->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')
  7996. ->orderBy('updated_at', 'desc')
  7997. // ->limit(5)
  7998. ->get();
  7999. //待审核数据com pro
  8000. $complany = Company::where('status', 0)
  8001. ->orderBy('updated_at', 'desc')
  8002. // ->limit(5)
  8003. ->get();
  8004. $project = Project::where('status', 0)
  8005. ->orderBy('updated_at', 'desc')
  8006. // ->limit(5)
  8007. ->get();
  8008. $count =
  8009. // count($chat) +
  8010. // count($chat_group) +
  8011. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8012. // + count($job_apply)
  8013. // + count($job_resume)
  8014. + count($complany)
  8015. + count($project);
  8016. $result = [
  8017. 'apply_articale' => $apply_articale,
  8018. // 'chat' => $chat,
  8019. // 'chat_group' => $chat_group,
  8020. 'good' => $good,
  8021. 'notice' => $notice,
  8022. 'complaint' => $complaint,
  8023. 'book' => $book,
  8024. 'job_hunting' => $job_hunting,
  8025. 'job_recruiting' => $job_recruiting,
  8026. // 'job_apply' => $job_apply,
  8027. // 'job_resume' => $job_resume,
  8028. 'complany' => $complany,
  8029. 'project' => $project,
  8030. 'count' => $count,
  8031. ];
  8032. } elseif ($type_id == 20000) {
  8033. }
  8034. var_dump($type_id, '-----------------test---------');
  8035. return Result::success($result);
  8036. }
  8037. /**
  8038. * @param array $data
  8039. * @return array
  8040. */
  8041. public function getWebsiteProject(array $data): array
  8042. {
  8043. $categorys = json_decode($data['id'], true);
  8044. if (!empty($categorys)) {
  8045. $category_arr = $this->processArticlePro($data['website_id']);
  8046. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8047. $catiall = $category_arr['catiall'];
  8048. // return Result::success($catiall);
  8049. foreach ($categorys as $key => $val) {
  8050. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8051. $level = explode(',', $val['level'])[0];
  8052. $imgnum = explode(',', $val['level'])[1] ?? null;
  8053. $textnum = explode(',', $val['level'])[2] ?? null;
  8054. if ($level == 1) {
  8055. if (!empty($textnum) && $textnum > 0) {
  8056. $text_num = Project::where('level', $level)
  8057. ->where('website_id', $data['website_id'])
  8058. ->where('status', 1)
  8059. ->select(
  8060. 'project.id',
  8061. 'project.title',
  8062. 'project.description',
  8063. 'project.updated_at',
  8064. 'project.category_id',
  8065. 'project.cat_arr_id'
  8066. )
  8067. ->orderBy('updated_at', 'desc')
  8068. ->limit($textnum)
  8069. ->get()->all();
  8070. }
  8071. if (!empty($imgnum) && $imgnum > 0) {
  8072. $img_num = Project::where('level', $level)
  8073. ->where('website_id', $data['website_id'])
  8074. ->where('status', 1)
  8075. ->where('imgurl', '!=', '')
  8076. ->whereNotNull('imgurl')
  8077. ->select(
  8078. 'project.id',
  8079. 'project.title',
  8080. 'project.description',
  8081. 'project.updated_at',
  8082. 'project.imgurl as imgs',
  8083. 'project.category_id',
  8084. 'project.cat_arr_id'
  8085. )
  8086. ->orderBy('updated_at', 'desc')
  8087. ->limit($imgnum)
  8088. ->get()->all();
  8089. }
  8090. } else {
  8091. if (!empty($textnum) && $textnum > 0) {
  8092. $text_num = Project::where('website_id', $data['website_id'])
  8093. ->where('status', 1)
  8094. ->select(
  8095. 'project.id',
  8096. 'project.title',
  8097. 'project.description',
  8098. 'project.updated_at',
  8099. 'project.category_id',
  8100. 'project.cat_arr_id',
  8101. 'project.website_id',
  8102. 'project.updated_at',
  8103. 'project.created_at'
  8104. )
  8105. ->orderBy('updated_at', 'desc')
  8106. ->limit($textnum)
  8107. ->get()->all();
  8108. }
  8109. if (!empty($imgnum) && $imgnum > 0) {
  8110. $img_num = Project::where('website_id', $data['website_id'])
  8111. ->where('status', 1)
  8112. ->where('imgurl', '!=', '')
  8113. ->whereNotNull('imgurl')
  8114. ->select(
  8115. 'project.id',
  8116. 'project.title',
  8117. 'project.description',
  8118. 'project.updated_at',
  8119. 'project.imgurl as imgs',
  8120. 'project.category_id',
  8121. 'project.cat_arr_id'
  8122. )
  8123. ->orderBy('updated_at', 'desc')
  8124. ->limit($imgnum)
  8125. ->get()->all();
  8126. }
  8127. }
  8128. }
  8129. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8130. $category_ids = explode(',', $val['id'])[0];
  8131. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8132. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8133. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8134. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8135. $text_num = Project::whereIn('category_id', $category_arr)
  8136. ->where('website_id', $data['website_id'])
  8137. ->where('status', 1)
  8138. ->select(
  8139. 'project.id',
  8140. 'project.title',
  8141. 'project.description',
  8142. 'project.updated_at',
  8143. 'project.category_id',
  8144. 'project.cat_arr_id'
  8145. )
  8146. ->orderBy('updated_at', 'desc')
  8147. ->limit($cat_textnum)
  8148. ->get()->all();
  8149. }
  8150. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8151. $img_num = Project::whereIn('category_id', $category_arr)
  8152. ->where('website_id', $data['website_id'])
  8153. ->where('status', 1)
  8154. ->where('imgurl', '!=', '')
  8155. ->whereNotNull('imgurl')
  8156. ->select(
  8157. 'project.id',
  8158. 'project.title',
  8159. 'project.description',
  8160. 'project.updated_at',
  8161. 'project.imgurl as imgs',
  8162. 'project.category_id',
  8163. 'project.cat_arr_id'
  8164. )
  8165. ->orderBy('updated_at', 'desc')
  8166. ->limit($cat_imgnum)
  8167. ->get()->all();
  8168. }
  8169. }
  8170. if (!empty($img_num)) {
  8171. foreach ($img_num as $k => $v) {
  8172. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8173. $imgurl = json_decode($v['imgs'], true);
  8174. if (!empty($imgurl)) {
  8175. $img_num[$k]->imgurl = $imgurl[0];
  8176. }
  8177. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8178. }
  8179. }
  8180. if (!empty($text_num)) {
  8181. foreach ($text_num as $k => $v) {
  8182. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8183. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8184. }
  8185. }
  8186. $project[$key]['img_num'] = $img_num ?? [];
  8187. $project[$key]['text_num'] = $text_num ?? [];
  8188. }
  8189. }
  8190. if (empty($project)) {
  8191. return Result::error("暂无相关项目信息", 0);
  8192. }
  8193. return Result::success($project);
  8194. }
  8195. /**
  8196. * @param array $data
  8197. * @return array
  8198. */
  8199. public function getWebsiteProjectInfo(array $data): array
  8200. {
  8201. $project = Project::where('id', $data['id'])
  8202. ->where('status', 1)
  8203. ->where('website_id', $data['website_id'])
  8204. ->select('project.*')
  8205. ->first();
  8206. if (empty($project)) {
  8207. return Result::error("暂无相关项目信息", 0);
  8208. }
  8209. return Result::success($project);
  8210. }
  8211. /**
  8212. * @param array $data
  8213. * @return array
  8214. */
  8215. public function getWebsiteProjectList(array $data): array
  8216. {
  8217. $where = [];
  8218. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8219. $where['category_id'] = $data['category_id'];
  8220. }
  8221. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8222. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8223. }
  8224. $query = Project::where($where)
  8225. ->where('status', 1)
  8226. ->where('website_id', $data['website_id'])
  8227. ->select(
  8228. 'project.id',
  8229. 'project.title',
  8230. 'project.description',
  8231. 'project.imgurl as imgs',
  8232. 'project.category_id',
  8233. 'project.cat_arr_id'
  8234. )
  8235. ->orderBy('updated_at', 'desc');
  8236. $count = $query->count();
  8237. $project = $query->clone()
  8238. ->offset(($data['page'] - 1) * $data['pageSize'])
  8239. ->limit($data['pageSize'])
  8240. ->get()->all();
  8241. if (empty($project)) {
  8242. return Result::error("暂无相关项目信息", 0);
  8243. }
  8244. $categorys = $this->processArticlePro($data['website_id']);
  8245. $catiall = $categorys['catiall'];
  8246. foreach ($project as $key => $val) {
  8247. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8248. if (!empty($val['imgs'])) {
  8249. $imgurl = json_decode($val['imgs'], true);
  8250. if (!empty($imgurl)) {
  8251. $project[$key]->imgurl = $imgurl[0];
  8252. }
  8253. } else {
  8254. $project[$key]->imgurl = '';
  8255. }
  8256. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8257. }
  8258. $result = [
  8259. 'rows' => $project,
  8260. 'count' => $count,
  8261. ];
  8262. return Result::success($result);
  8263. }
  8264. /**
  8265. * @param array $data
  8266. * @return array
  8267. */
  8268. public function getWebsiteCategoryJob(array $data): array
  8269. {
  8270. $categorys = json_decode($data['id'], true);
  8271. if (!empty($categorys)) {
  8272. $category_arr = $this->processArticlePro($data['website_id']);
  8273. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8274. $catiall = $category_arr['catiall'];
  8275. foreach ($categorys as $key => $val) {
  8276. if (isset($val['id']) && !empty($val['id'])) {
  8277. $catid = explode(',', $val['id'])[0] ?? null;
  8278. $type = explode(',', $val['id'])[1] ?? null;
  8279. $textnum = explode(',', $val['id'])[2] ?? null;
  8280. }
  8281. // 4:招聘;5:求职;
  8282. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8283. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8284. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8285. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8286. ->where('job_recruiting.status', 1)
  8287. ->where('job_recruiting.website_id', $data['website_id'])
  8288. ->select(
  8289. 'job_recruiting.id',
  8290. 'job_recruiting.title',
  8291. 'job_company.business_name',
  8292. 'job_recruiting.updated_at',
  8293. 'job_recruiting.cat_arr_id',
  8294. 'job_recruiting.keyword',
  8295. 'job_recruiting.description'
  8296. )
  8297. ->orderBy('job_recruiting.updated_at', 'desc')
  8298. ->limit($textnum)
  8299. ->get()->all();
  8300. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8301. // 状态 审核状态,1待审核2已审核3已拒绝
  8302. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8303. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8304. ->where('job_hunting.status', 2)
  8305. ->where('job_hunting.website_id', $data['website_id'])
  8306. ->select(
  8307. 'job_hunting.id',
  8308. 'job_hunting.name',
  8309. 'job_hunting.cat_arr_id',
  8310. 'job_position.zwname as job_name',
  8311. 'job_hunting.updated_at',
  8312. 'job_hunting.keyword',
  8313. 'job_hunting.slelf_evaluation'
  8314. )
  8315. ->orderBy('updated_at', 'desc')
  8316. ->limit($textnum)
  8317. ->get()->all();
  8318. } else {
  8319. $job = [];
  8320. }
  8321. // var_dump($catid.'222uuuuuuu'.$key);
  8322. if (!empty($job)) {
  8323. foreach ($job as $k => $value) {
  8324. if (isset($value->cat_arr_id)) {
  8325. $catArr = json_decode($value->cat_arr_id, true);
  8326. $catId = end($catArr);
  8327. } else {
  8328. continue;
  8329. }
  8330. if (isset($catiall[$catId])) {
  8331. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8332. }
  8333. }
  8334. }
  8335. // var_dump($catid.'xxxxx'.$key);
  8336. $result[$key] = $job ?? [];
  8337. }
  8338. }
  8339. if (empty($result)) {
  8340. return Result::error("暂无相关分类信息", 0);
  8341. }
  8342. return Result::success($result);
  8343. }
  8344. /**
  8345. * 发送消息
  8346. * @param array $messageData
  8347. * @return void
  8348. */
  8349. public function sendMessage($messageData)
  8350. {
  8351. $msg = [
  8352. 'talk_type' => $messageData['talk_type'],
  8353. 'title' => $messageData['title'],
  8354. 'content' => $messageData['content'],
  8355. 'messageType' => $messageData['messageType'],
  8356. 'user_id' => $messageData['user_id'] ?? '',
  8357. 'time' => microtime(),
  8358. ];
  8359. $message = new MqProducer($msg);
  8360. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8361. $producer->produce($message);
  8362. }
  8363. /**
  8364. * 行业分类管理 ------1121
  8365. * @param array $data
  8366. * @return array
  8367. */
  8368. public function getJobIndustryList(array $data):array
  8369. {
  8370. $page = $data['page'] ?? 1;
  8371. $page_size = $data['page_size'] ?? 10;
  8372. if(isset($data['hyname']) && !empty($data['hyname'])){
  8373. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8374. }else{
  8375. $where = [];
  8376. }
  8377. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8378. $query->where([$where]); // 修复:将条件包装成二维数组
  8379. })
  8380. ->orderBy('updated_at', 'desc');
  8381. $count = $rs_query->count();
  8382. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8383. $result = [
  8384. 'count' => $count,
  8385. 'list' => $hy,
  8386. ];
  8387. if(empty($hy)){
  8388. return Result::success('暂无数据');
  8389. }
  8390. return Result::success($result);
  8391. }
  8392. /**
  8393. * 添加行业分类
  8394. * @param array $data
  8395. * @return array
  8396. */
  8397. public function addJobIndustry(array $data):array
  8398. {
  8399. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8400. if(!empty($hy_name)){
  8401. return Result::error('行业分类已存在');
  8402. }
  8403. $hy = JobIndustry::insertGetId($data);
  8404. if(empty($hy)){
  8405. return Result::error('添加失败');
  8406. }
  8407. return Result::success($hy);
  8408. }
  8409. /**
  8410. * 更新行业分类
  8411. * @param array $data
  8412. * @return array
  8413. */
  8414. public function upJobIndustry(array $data):array
  8415. {
  8416. $hy_query = JobIndustry::get();
  8417. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8418. $hy_names = $hy_query->pluck('hyname')->toArray();
  8419. if(!in_array($data['hyid'], $hy_ids)){
  8420. return Result::error('行业分类不存在');
  8421. }
  8422. if(isset($data['hyname']) && !empty($data['hyname'])){
  8423. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8424. // return Result::success($other_key_hy);
  8425. unset($hy_names[$other_key_hy]);
  8426. if(in_array($data['hyname'], $hy_names)){
  8427. return Result::error('行业分类名称已存在');
  8428. }
  8429. }
  8430. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8431. if(empty($hy)){
  8432. return Result::error('更新失败');
  8433. }
  8434. return Result::success($hy);
  8435. }
  8436. /**
  8437. * 删除行业分类
  8438. * @param array $data
  8439. * @return array
  8440. */
  8441. public function delJobIndustry(array $data):array
  8442. {
  8443. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8444. if(empty($hy_id)){
  8445. return Result::error('行业分类不存在');
  8446. }
  8447. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8448. if(empty($hy)){
  8449. return Result::error('删除失败');
  8450. }
  8451. return Result::success($hy);
  8452. }
  8453. /**
  8454. * 职位分类-列表
  8455. * @param array $data
  8456. * @return array
  8457. */
  8458. public function getJobPositionList(array $data):array
  8459. {
  8460. $page = $data['page'] ?? 1;
  8461. $page_size = $data['page_size'] ?? 10;
  8462. if(isset($data['zwname']) && !empty($data['zwname'])){
  8463. $where = ['zwname', 'like', '%' . $data['zwname'] . '%'];
  8464. }else{
  8465. $where = [];
  8466. }
  8467. if($data['is_pid'] == 0){
  8468. $zwids = JobPosition::where('zwpid', 0)
  8469. ->when(!empty($where), function ($query) use ($where) {
  8470. $query->where([$where]); // 修复:将条件包装成二维数组
  8471. })
  8472. ->orderBy('updated_at', 'desc')
  8473. ->pluck('zwid');
  8474. }else{
  8475. $zwids = JobPosition::where('zwpid', '!=', 0)
  8476. ->when(!empty($where), function ($query) use ($where) {
  8477. $query->where([$where]); // 修复:将条件包装成二维数组
  8478. })
  8479. ->orderBy('updated_at', 'desc')
  8480. ->pluck('zwpid');
  8481. $zwids = array_values(array_unique($zwids->toArray()));
  8482. }
  8483. // return Result::success($rs_query);
  8484. $count = JobPosition::whereIn('zwid', $zwids)->count();
  8485. $position = JobPosition::whereIn('zwid', $zwids)
  8486. ->offset(($page - 1) * $page_size)
  8487. ->limit($page_size)->get()
  8488. ->map(function ($item) use ($data, $where) {
  8489. $item->children = $item->where('zwpid', $item->zwid)
  8490. ->when(!empty($where) && $data['is_pid'] == 1, function ($query) use ($where) {
  8491. $query->where([$where]); // 修复:将条件包装成二维数组
  8492. })
  8493. ->get();
  8494. return $item;
  8495. })
  8496. ->all();
  8497. $result = [
  8498. 'count' => $count,
  8499. 'list' => $position,
  8500. ];
  8501. if(empty($result)){
  8502. return Result::success('暂无数据');
  8503. }
  8504. return Result::success($result);
  8505. }
  8506. }