NewsService.php 316 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602
  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. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  571. if (!$contentInsertId) {
  572. throw new \Exception('文章内容插入失败');
  573. }
  574. // ------c_show_time********add***2****
  575. // 直接使用当前系统时间,不再强制添加8小时
  576. $now = date('Y-m-d H:i:s');
  577. if($user_type == 10000 || $is_collect == 1){
  578. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  579. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  580. if (!isset($data['catid'])) {
  581. throw new \Exception('缺少必要字段:catid');
  582. }
  583. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  584. $web = WebsiteCategory::where('category_id', $data['catid'])
  585. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  586. ->select('website_id',
  587. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  588. ->get();
  589. // $id = 225; -----测试开启
  590. // 采集来的文章,错开时间在两小时之内发布
  591. if($user_type == 10000 && $is_collect == 1){
  592. $web_num = $web->where('is_core', '!=', 2)->count();
  593. $waiting_interval = 10;
  594. if($web_num > 12){
  595. // 若网站数量大于12个,则每个网站间隔时间取均值
  596. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  597. $waiting_interval = 120 / max(1, $web_num);
  598. }
  599. $time = 0;
  600. }else{
  601. // 非核心站与核心站----显示时间-----间隔
  602. $time = 20;
  603. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  604. $waiting_interval = 5;
  605. }
  606. // 将 Hyperf\Database\Model\Collection 转换为数组
  607. $webArray = $web->toArray();
  608. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  609. // 检查 $item 对象是否有 is_core 属性
  610. if (!isset($item['is_core'])) {
  611. throw new \Exception('$item 对象缺少 is_core 属性');
  612. }
  613. // 当 is_core 为 2 时,则表示此网站不存在
  614. if ($item['is_core'] == 2) {
  615. return null;
  616. }
  617. if($is_collect == 1){
  618. // 采集来的文章,错开时间在两小时之内发布
  619. // $time = 0;
  620. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  621. $time += $waiting_interval;
  622. }else if($item['is_core'] == 1){
  623. // 当 is_core 为 1 时,则表示此网站是核心站
  624. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  625. }else{
  626. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  627. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  628. if ($item['is_core'] == 0) {
  629. $time += $waiting_interval;
  630. }
  631. }
  632. return [
  633. 'article_id' => $id,
  634. 'website_id' => $item['website_id'],
  635. 'c_show_time' => $c_show_time,
  636. // 'is_core' => $item['is_core'],
  637. // 'time' => $time
  638. ];
  639. }, array_keys($webArray), $webArray)));
  640. // Db::commit();
  641. // return Result::success($article_ignore);
  642. if(!empty($article_ignore)){
  643. $article_ignores = ArticleIgnore::insert($article_ignore);
  644. if(!$article_ignores){
  645. throw new \Exception('c端展示时间插入失败');
  646. }
  647. }
  648. }
  649. // ------c_show_time********add***2****
  650. //处理投票
  651. if ($is_survey == 1) {
  652. //生成年月日时分秒+8位随机数
  653. $uuid = date('YmdHis') . rand(10000000, 99999999);
  654. var_dump($suvey_array, 'suvey_array________');
  655. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  656. var_dump($suveys_array, '---------------------1');
  657. var_dump($suvey_array, '---------------------2');
  658. $suvey_data = [];
  659. foreach ($suveys_array as $key => $value) {
  660. if ($value == '') {
  661. continue;
  662. }
  663. if (is_array($value)) {
  664. $suvey_data[] = [
  665. 'sur_id' => $uuid,
  666. 'art_id' => $id,
  667. 'website_id' => $website_id ?? 2,
  668. 'survey_name' => $survey_name,
  669. 'choice_name' => $value[1],
  670. 'is_other' => 1,
  671. 'other_id' => 0,
  672. 'results' => 0,
  673. ];
  674. } else {
  675. $suvey_data[] = [
  676. 'sur_id' => $uuid,
  677. 'art_id' => $id,
  678. 'website_id' => $website_id ?? 2,
  679. 'survey_name' => $survey_name,
  680. 'choice_name' => $value,
  681. 'is_other' => 0,
  682. 'other_id' => 0,
  683. 'results' => 0,
  684. ];
  685. }
  686. if (empty($suvey_data)) {
  687. throw new \Exception("投票数据为空");
  688. }
  689. }
  690. $result = ArticleSurvey::insert($suvey_data);
  691. if (!$result) {
  692. throw new \Exception("投票失败,ArticleSurvey插入失败");
  693. }
  694. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  695. if (!$result) {
  696. throw new \Exception("投票失败,更新主表失败");
  697. }
  698. }
  699. Db::commit();
  700. return Result::success(['id' => $id]);
  701. } catch (\Throwable $ex) {
  702. Db::rollBack();
  703. var_dump($ex->getMessage());
  704. return Result::error("创建失败", 0);
  705. }
  706. }
  707. /**
  708. * @param array $data
  709. * @return array
  710. */
  711. public function delArticle(array $data): array
  712. {
  713. // ------c_show_time********del*******
  714. Db::beginTransaction();
  715. try{
  716. $article = Article::where(['id' => $data['id']])->delete();
  717. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  718. if (!$article) {
  719. throw new \Exception("删除失败,文章删除失败");
  720. }
  721. //survey投票删除
  722. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  723. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  724. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  725. // 若文章详情删除失败,抛出异常
  726. if (!$article_data) {
  727. throw new \Exception("删除失败,文章详情删除失败");
  728. }
  729. Db::commit(); // 所有操作成功,提交事务
  730. }catch (\Throwable $ex) {
  731. Db::rollBack();
  732. var_dump($ex->getMessage());
  733. return Result::error("删除失败: " . $ex->getMessage(), 0);
  734. }
  735. // ------c_show_time********del*******
  736. if (!$article) {
  737. return Result::error("删除失败");
  738. }
  739. return Result::success($article);
  740. }
  741. /**
  742. * @param array $data
  743. * @return array
  744. */
  745. public function updateArticle(array $data): array
  746. {
  747. var_dump($data, '----------12-----------1');
  748. Db::beginTransaction();
  749. // ------c_show_time********up*******
  750. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  751. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  752. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  753. $web = WebsiteCategory::where('category_id', $data['catid'])
  754. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  755. ->select('website_id',
  756. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  757. ->get();
  758. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  759. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  760. $websiteIds = $web->pluck('website_id')->toArray();
  761. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  762. if($user_type == 0){
  763. throw new \Exception("用户类型不能为空");
  764. }
  765. if($user_type == 10000 ){
  766. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  767. $web = WebsiteCategory::where('category_id', $data['catid'])
  768. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  769. ->select('website_id',
  770. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
  771. ->get();
  772. // 非核心站与核心站----显示时间-----间隔
  773. $time = 20;
  774. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  775. $waiting_interval = 5;
  776. $webArray = $web->toArray();
  777. if(empty($webArray)){
  778. throw new \Exception('网站分类不存在');
  779. }
  780. // 直接使用当前系统时间,不再强制添加8小时
  781. $now = date('Y-m-d H:i:s');
  782. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  783. // 检查 $item 对象是否有 is_core 属性
  784. if (!isset($item['is_core'])) {
  785. throw new \Exception('$item 对象缺少 is_core 属性');
  786. }
  787. // 当 is_core 为 2 时,则表示此网站不存在
  788. if ($item['is_core'] == 2) {
  789. return null;
  790. }else if($item['is_core'] == 1){
  791. // 当 is_core 为 1 时,则表示此网站是核心站
  792. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  793. }else{
  794. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  795. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  796. if ($item['is_core'] == 0) {
  797. $time += $waiting_interval;
  798. }
  799. }
  800. return [
  801. 'article_id' => $data['id'],
  802. 'website_id' => $item['website_id'],
  803. 'c_show_time' => $c_show_time,
  804. ];
  805. }, array_keys($webArray), $webArray)));
  806. if(!empty($article_ignore)){
  807. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  808. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  809. $article_ignores = ArticleIgnore::upsert(
  810. $article_ignore,
  811. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  812. ['c_show_time'] // 需要更新的字段
  813. );
  814. if(!$article_ignores){
  815. throw new \Exception('c端展示时间插入失败');
  816. }
  817. }
  818. // Db::commit();
  819. // return Result::success($article_ignore);
  820. }
  821. // ------c_show_time********up*******
  822. unset($data['user_type']);
  823. // unset($data['web_site_id']);
  824. unset($data['nav_add_pool_id']);
  825. try {
  826. //处理投票
  827. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  828. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  829. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  830. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  831. unset($data['is_survey']);
  832. unset($data['survey_name']);
  833. unset($data['suvey_array']);
  834. unset($data['website_id']);
  835. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  836. if ($data['hits'] == '') {
  837. $data['hits'] = 0;
  838. }
  839. if ($data['is_original'] == '') {
  840. $data['is_original'] = 0;
  841. }
  842. if ($data['status'] == '') {
  843. $data['status'] = 0;
  844. }
  845. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  846. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  847. $articleData = $data;
  848. unset($articleData['content']);
  849. unset($articleData['status_name']);
  850. unset($articleData['name']);
  851. unset($articleData['content']);
  852. unset($articleData['pid_arr']);
  853. unset($articleData['pid']);
  854. //自动处理缩略图、关键字、描述
  855. if ($articleData['imgurl'] == '') {
  856. //如果没有图,设置level=0
  857. $levelArr = json_decode($articleData['level'], true);
  858. var_dump($levelArr, '----------levelArr-----------1');
  859. //content中提取图片第一个图,正则提取
  860. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  861. preg_match_all($reg, $data['content'], $matches);
  862. if (isset($matches[1][0])) {
  863. //截取varchar240
  864. // 截取到第一个<
  865. $articleData['imgurl'] = $matches[1][0];
  866. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  867. $pos = strpos($articleData['imgurl'], '"');
  868. if ($pos !== false) {
  869. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  870. }
  871. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  872. //如果有图,设置level=3
  873. if (!in_array(3, $levelArr)) {
  874. $levelArr[] = 3;
  875. }
  876. $articleData['level'] = json_encode($levelArr);
  877. } else {
  878. if (!in_array(0, $levelArr)) {
  879. $levelArr[] = 0;
  880. }
  881. $articleData['level'] = json_encode($levelArr);
  882. }
  883. }
  884. var_dump($articleData['level'], '----------$articleData[level]----------1');
  885. if ($articleData['keyword'] == '') {
  886. //提取标题+内容中的关键词
  887. $articleData['keyword'] = $data['title'];
  888. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  889. Jieba::init(); // 初始化 jieba-php
  890. Finalseg::init();
  891. $segList = Jieba::cut($articleData['keyword']);
  892. $segList1 = array_slice($segList, 0, 8);
  893. $articleData['keyword'] = implode(',', $segList1);
  894. }
  895. if ($articleData['introduce'] == '') {
  896. //提取内容中的描述
  897. $content = $data['content'];
  898. // 去除 <style> 和 <script> 标签及其内容
  899. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  900. // 去除所有 HTML 标签
  901. $content = strip_tags($content);
  902. // 去除 HTML 实体
  903. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  904. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  905. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  906. // 去除多余空白
  907. $content = preg_replace('/\s+/u', '', $content);
  908. // 截取 100 个字符
  909. $articleData['introduce'] = mb_substr($content, 0, 100);
  910. }
  911. if ($articleData['status'] == 0) {
  912. $this->sendMessage([
  913. 'talk_type' => 100,
  914. 'title' => $articleData['title'],
  915. 'content' => '提交了审核',
  916. 'messageType' => 2,
  917. ]);
  918. }
  919. $id = Article::where(['id' => $data['id']])->update($articleData);
  920. $articleDataContent = [
  921. 'content' => $data['content'],
  922. ];
  923. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  924. //处理投票
  925. $id = $data['id'];
  926. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  927. var_dump($suvey_array, 'suvey_array________delete');
  928. //处理投票
  929. if ($is_survey == 1) {
  930. //生成年月日时分秒+8位随机数
  931. $uuid = date('YmdHis') . rand(10000000, 99999999);
  932. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  933. var_dump($suveys_array, '---------------------1');
  934. $suvey_data = [];
  935. if (is_array($suveys_array)) {
  936. foreach ($suveys_array as $key => $value) {
  937. if ($value == '') {
  938. continue;
  939. }
  940. if (is_array($value)) {
  941. $suvey_data[] = [
  942. 'sur_id' => $uuid,
  943. 'art_id' => $id,
  944. 'website_id' => $website_id ?? 2,
  945. 'survey_name' => $survey_name,
  946. 'choice_name' => $value[1],
  947. 'is_other' => 1,
  948. 'other_id' => 0,
  949. 'results' => 0,
  950. ];
  951. } else {
  952. $suvey_data[] = [
  953. 'sur_id' => $uuid,
  954. 'art_id' => $id,
  955. 'website_id' => $website_id ?? 2,
  956. 'survey_name' => $survey_name,
  957. 'choice_name' => $value,
  958. 'is_other' => 0,
  959. 'other_id' => 0,
  960. 'results' => 0,
  961. ];
  962. }
  963. if (empty($suvey_data)) {
  964. throw new \Exception("投票数据为空");
  965. }
  966. }
  967. }
  968. $result = ArticleSurvey::insert($suvey_data);
  969. if (!$result) {
  970. throw new \Exception("投票失败");
  971. }
  972. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  973. if (!$result) {
  974. throw new \Exception("投票失败");
  975. }
  976. } else {
  977. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  978. }
  979. Db::commit();
  980. return Result::success([]);
  981. } catch (\Throwable $ex) {
  982. Db::rollBack();
  983. var_dump($ex->getMessage());
  984. return Result::error("更新失败" . $ex->getMessage(), 0);
  985. }
  986. }
  987. /**
  988. * 更新资讯状态
  989. * @param array $data
  990. * @return array
  991. */
  992. public function upArticleStatus(array $data): array
  993. {
  994. $articleData = Article::where(['id' => $data['id']])->first();
  995. //发送10次
  996. // for ($i = 0; $i < 10; $i++) {
  997. // $this->sendMessage([
  998. // 'talk_type' => 100,
  999. // 'title' => $i . $articleData['title'],
  1000. // 'content' => '审核通过',
  1001. // 'messageType' => 2,
  1002. // 'user_id' => $articleData['admin_user_id'],
  1003. // ]);
  1004. // }
  1005. // var_dump($data['status'], 'status');
  1006. // return Result::success();
  1007. if ($data['status'] == 1) {
  1008. $this->sendMessage([
  1009. 'talk_type' => 101,
  1010. 'title' => $articleData['title'],
  1011. 'content' => '审核通过',
  1012. 'messageType' => 2,
  1013. 'user_id' => $articleData['admin_user_id'],
  1014. ]);
  1015. }
  1016. if ($data['status'] == 2) {
  1017. $this->sendMessage([
  1018. 'talk_type' => 101,
  1019. 'title' => $articleData['title'],
  1020. 'content' => '审核拒绝',
  1021. 'messageType' => 2,
  1022. 'user_id' => $articleData['admin_user_id'],
  1023. ]);
  1024. }
  1025. if ($data['status'] == 0) {
  1026. $this->sendMessage([
  1027. 'talk_type' => 100,
  1028. 'title' => $articleData['title'],
  1029. 'content' => '提交了审核',
  1030. 'messageType' => 2,
  1031. ]);
  1032. }
  1033. $result = Article::where(['id' => $data['id']])->update($data);
  1034. // ------c_show_time********up_status*******
  1035. // 若是审核通过 则更新c_show_time
  1036. if($data['status'] == 1){
  1037. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1038. $web = Article::where('article.id',$data['id'])
  1039. ->leftJoin('website_category','article.catid','website_category.category_id')
  1040. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1041. ->select('website_id',
  1042. 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'))
  1043. ->get();
  1044. // 非核心站与核心站----显示时间-----间隔
  1045. $time = 20;
  1046. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1047. $waiting_interval = 5;
  1048. $webArray = $web->toArray();
  1049. if(empty($webArray)){
  1050. throw new \Exception('网站分类不存在');
  1051. }
  1052. // 直接使用当前系统时间,不再强制添加8小时
  1053. $now = date('Y-m-d H:i:s');
  1054. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1055. if(isset($data['ignore_ids'])){
  1056. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1057. if(in_array($item['website_id'], $ignore_website_ids)){
  1058. $is_ignore = 1;
  1059. }else{
  1060. $is_ignore = 0;
  1061. }
  1062. return [
  1063. 'article_id' => $data['id'],
  1064. 'website_id' => $item['website_id'],
  1065. 'is_ignore' => $is_ignore,
  1066. ];
  1067. }else{
  1068. // 检查 $item 对象是否有 is_core 属性
  1069. if (!isset($item['is_core'])) {
  1070. throw new \Exception('$item 对象缺少 is_core 属性');
  1071. }
  1072. // 当 is_core 为 2 时,则表示此网站不存在
  1073. if ($item['is_core'] == 2) {
  1074. return null;
  1075. }else if($item['is_core'] == 1){
  1076. // 当 is_core 为 1 时,则表示此网站是核心站
  1077. $c_show_time = $now;
  1078. }else{
  1079. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1080. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1081. if ($item['is_core'] == 0) {
  1082. $time += $waiting_interval;
  1083. }
  1084. }
  1085. return [
  1086. 'article_id' => $data['id'],
  1087. 'website_id' => $item['website_id'],
  1088. 'c_show_time' => $c_show_time,
  1089. ];
  1090. }
  1091. }, array_keys($webArray), $webArray)));
  1092. if(!empty($article_ignore) && !isset($data['ignore_ids'])){
  1093. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1094. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1095. $websiteIds = $web->pluck('website_id')->toArray();
  1096. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1097. $article_ignores = ArticleIgnore::upsert(
  1098. $article_ignore,
  1099. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1100. ['c_show_time'] // 需要更新的字段
  1101. );
  1102. if(!$article_ignores){
  1103. throw new \Exception('c端展示时间插入失败');
  1104. }
  1105. }
  1106. if(!empty($data['ignore_ids'])){
  1107. // return Result::success($article_ignore);
  1108. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1109. if(!empty($article_ignore)){
  1110. $article_ignores = ArticleIgnore::upsert(
  1111. $article_ignore,
  1112. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1113. ['is_ignore'] // 需要更新的字段
  1114. );
  1115. // if(!$article_ignores){
  1116. // throw new \Exception('屏蔽网站更新失败');
  1117. // }
  1118. }
  1119. }
  1120. }
  1121. // ------c_show_time********up_status*******
  1122. if ($result) {
  1123. return Result::success();
  1124. } else {
  1125. return Result::error("更新状态失败", 0);
  1126. }
  1127. }
  1128. /**
  1129. * 获取新闻详情
  1130. * @param array $data
  1131. * @return array
  1132. */
  1133. public function getArticleInfo(array $data): array
  1134. {
  1135. $where = [
  1136. 'article.id' => $data['id'],
  1137. // 'article.status' => 1,
  1138. ];
  1139. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1140. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1141. $info = $result;
  1142. // var_dump($info, 'info');
  1143. $info['survey_array'] = $articleSurvey;
  1144. if ($result) {
  1145. return Result::success($info);
  1146. } else {
  1147. return Result::error("查询失败", 0);
  1148. }
  1149. }
  1150. /**
  1151. * 获取头条新闻
  1152. * @param array $data
  1153. * @return array
  1154. */
  1155. public function getWebsiteArticlett(array $data): array
  1156. {
  1157. $website_id = $data['website_id'];
  1158. $website = Website::where('id', $data['website_id'])->first();
  1159. if (empty($website)) {
  1160. return Result::error("网站不存在", 0);
  1161. }
  1162. $categorys = $this->processArticlePro($website_id);
  1163. $catiall = $categorys['catiall'];
  1164. $categoryIds = $categorys['categoryIds'];
  1165. $where = [
  1166. 'status' => 1
  1167. ];
  1168. // $website_column = $website['column'];
  1169. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1170. $website_column = json_decode($website['website_column_arr_id'], true);
  1171. }
  1172. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1173. // return Result::success($diff_pid_categoryIds);
  1174. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1175. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1176. }
  1177. // $website_id = $data['website_id'];
  1178. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1179. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1180. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1181. switch ($data['level']) {
  1182. case 1:
  1183. case 2:
  1184. case 3:
  1185. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1186. $query = Article::where($where)
  1187. ->where('level', 'like', '%' . $data['level'] . '%')
  1188. ->orderBy('updated_at', 'desc');
  1189. break;
  1190. case 4: //最新资讯
  1191. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1192. break;
  1193. case 5: //资讯推荐
  1194. $query = Article::where($where)
  1195. ->where('updated_at', '>', $month);
  1196. break;
  1197. case 7: //资讯分类
  1198. if (isset($data['id']) && !empty($data['id'])) {
  1199. $keyword = Article::where('id', $data['id'])->value('keyword');
  1200. $keywordArray = explode(',', $keyword);
  1201. $whereL7 = [];
  1202. foreach ($keywordArray as $k => $v) {
  1203. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1204. }
  1205. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1206. break;
  1207. } else {
  1208. return Result::error("请输入资讯ID", 0);
  1209. break;
  1210. }
  1211. default:
  1212. break;
  1213. }
  1214. // $whereL7 = [];
  1215. // if(isset($data['id']) && !empty($data['id'])){
  1216. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1217. // $keywordArray = explode(',', $keyword);
  1218. // foreach ($keywordArray as $k => $v) {
  1219. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1220. // }
  1221. // }
  1222. // $query = Article::where($where)
  1223. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1224. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1225. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1226. // }
  1227. // if($data['level'] == 7){
  1228. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1229. // }
  1230. // if($data['level'] == 4){
  1231. // $query = $query->inRandomOrder()
  1232. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1233. // }
  1234. // if($data['level'] == 5){
  1235. // $query = $query->orderBy('updated_at','desc');
  1236. // }
  1237. // });
  1238. if ($data['textnum'] > 0) {
  1239. $query = clone $query;
  1240. $result['text'] = $query
  1241. ->whereIn('catid', $categoryIds)
  1242. ->leftJoinSub(function ($query) use ($website_id) {
  1243. $query->from('article_ignore')
  1244. ->where('website_id', $website_id);
  1245. }, 'article_ignore', function ($join) {
  1246. $join->on('article_ignore.article_id', '=', 'article.id');
  1247. })
  1248. ->where(function ($query) {
  1249. $query->whereNull('article_ignore.article_id')
  1250. ->orWhere(function ($subQuery) {
  1251. $subQuery->whereNotNull('article_ignore.article_id')
  1252. ->where('article_ignore.is_ignore', 0)
  1253. ->where(function ($subSubQuery) {
  1254. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1255. ->orWhereNull('article_ignore.c_show_time');
  1256. });
  1257. });
  1258. })
  1259. // ->where(function ($query) use ($website_id) {
  1260. // $query->whereNull('article_ignore.article_id')
  1261. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1262. // })
  1263. ->select(
  1264. 'article.id',
  1265. 'article.title',
  1266. 'article.author',
  1267. 'article.updated_at',
  1268. 'article.introduce',
  1269. 'article.islink',
  1270. 'article.linkurl',
  1271. 'article.copyfrom',
  1272. 'article.cat_arr_id',
  1273. 'article.catid',
  1274. 'article.level',
  1275. // 'article_ignore.is_ignore',
  1276. // 'article_ignore.c_show_time',
  1277. )
  1278. ->offset($data['placeid'])
  1279. ->limit($data['textnum'])
  1280. ->get()->all();
  1281. foreach ($result['text'] as $k => $v) {
  1282. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1283. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1284. }
  1285. }
  1286. if ($data['imgnum'] > 0) {
  1287. $query = clone $query;
  1288. if($data['textnum'] == 0){
  1289. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1290. $query->from('article_ignore')
  1291. ->where('website_id', $website_id);
  1292. }, 'article_ignore', function ($join) {
  1293. $join->on('article_ignore.article_id', '=', 'article.id');
  1294. })
  1295. ->where(function ($query) {
  1296. $query->whereNull('article_ignore.article_id')
  1297. ->orWhere(function ($subQuery) {
  1298. $subQuery->whereNotNull('article_ignore.article_id')
  1299. ->where('article_ignore.is_ignore', 0)
  1300. ->where(function ($subSubQuery) {
  1301. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1302. ->orWhereNull('article_ignore.c_show_time');
  1303. });
  1304. });
  1305. });
  1306. }
  1307. $result['img'] = $query
  1308. ->whereIn('catid', $categoryIds)
  1309. ->where('article.imgurl', '!=', '')
  1310. ->select(
  1311. 'article.id',
  1312. 'article.title',
  1313. 'article.imgurl',
  1314. 'article.author',
  1315. 'article.updated_at',
  1316. 'article.introduce',
  1317. 'article.islink',
  1318. 'article.linkurl',
  1319. 'article.copyfrom',
  1320. 'article.cat_arr_id',
  1321. 'article.catid',
  1322. 'article.level',
  1323. // 'article_ignore.is_ignore',
  1324. // 'article_ignore.c_show_time',
  1325. )
  1326. ->offset($data['placeid'])
  1327. ->limit($data['imgnum'])
  1328. ->get()->all();
  1329. foreach ($result['img'] as $k => $v) {
  1330. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1331. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1332. }
  1333. }
  1334. if (empty($result)) {
  1335. return Result::error("暂无相关资讯", 0);
  1336. }
  1337. return Result::success($result);
  1338. }
  1339. /**
  1340. * 获取模块新闻
  1341. * @param array $data
  1342. * @return array
  1343. */
  1344. public function getWebsiteModelArticles(array $data): array
  1345. {
  1346. $catid = $data['catid'];
  1347. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1348. $category = $category->toArray();
  1349. if (!empty($category)) {
  1350. $where = [
  1351. 'status' => 1,
  1352. 'catid' => $catid,
  1353. ];
  1354. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1355. // 1:文字新闻;2:轮播图;3:图文;
  1356. // 级别:0:未分类
  1357. // 3:推荐图片
  1358. if ($data['level'] == 1) {
  1359. $data['level'] = 0;
  1360. }
  1361. $result = Article::where($where)
  1362. ->where(function ($query) use ($data) {
  1363. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1364. ->orWhereNull("level")
  1365. ->orWhereRaw("level = '[]'");
  1366. })
  1367. ->leftJoinSub(function ($query) use ($data) {
  1368. $query->from('article_ignore')
  1369. ->where('website_id', $data['website_id']);
  1370. }, 'article_ignore', function ($join) {
  1371. $join->on('article_ignore.article_id', '=', 'article.id');
  1372. })
  1373. ->where(function ($query) {
  1374. $query->whereNull('article_ignore.article_id')
  1375. ->orWhere(function ($subQuery) {
  1376. $subQuery->whereNotNull('article_ignore.article_id')
  1377. ->where('article_ignore.is_ignore', 0)
  1378. ->where(function ($subSubQuery) {
  1379. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1380. ->orWhereNull('article_ignore.c_show_time');
  1381. });
  1382. });
  1383. })
  1384. // ->where(function ($query) use ($data) {
  1385. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1386. // ->orWhereNull("ignore_ids");
  1387. // })
  1388. ->orderBy("updated_at", "desc")
  1389. ->offset($placeid)
  1390. ->limit($data['pagesize'])
  1391. ->get();
  1392. if (empty($result)) {
  1393. return Result::error("此栏目暂无相关新闻", 0);
  1394. }
  1395. } else {
  1396. return Result::error("此网站暂无此栏目", 0);
  1397. }
  1398. return Result::success($result);
  1399. }
  1400. /**
  1401. *获取新闻列表
  1402. * @param array $data
  1403. * @return array
  1404. */
  1405. public function getWebsiteArticleList(array $data): array
  1406. {
  1407. // return Result::success($data);
  1408. $where[] = ['status', '=', 1];
  1409. $website_id = $data['website_id'];
  1410. $website = Website::where('id', $data['website_id'])->first();
  1411. if (empty($website)) {
  1412. return Result::error("网站不存在", 0);
  1413. }
  1414. // $website_column = $website['column'];
  1415. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1416. $website_column = json_decode($website['website_column_arr_id'], true);
  1417. }
  1418. $categorys = $this->processArticlePro($website_id);
  1419. $cat_1st_arr = $categorys['cat_1st_arr'];
  1420. $catiall = $categorys['catiall'];
  1421. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1422. // return Result::success($diff_pid_categoryIds);
  1423. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1424. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1425. }
  1426. if (isset($data['catid']) && !empty($data['catid'])) {
  1427. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1428. if (empty($category)) {
  1429. return Result::error("此网站暂无此栏目", 0);
  1430. }
  1431. array_push($where, ['catid', '=', $data['catid']]);
  1432. }
  1433. // return Result::success($where);
  1434. $query = Article::where($where)
  1435. ->leftJoinSub(function ($query) use ($website_id) {
  1436. $query->from('article_ignore')
  1437. ->where('website_id', $website_id);
  1438. }, 'article_ignore', function ($join) {
  1439. $join->on('article_ignore.article_id', '=', 'article.id');
  1440. })
  1441. ->where(function ($query) {
  1442. $query->whereNull('article_ignore.article_id')
  1443. ->orWhere(function ($subQuery) {
  1444. $subQuery->whereNotNull('article_ignore.article_id')
  1445. ->where('article_ignore.is_ignore', 0)
  1446. ->where(function ($subSubQuery) {
  1447. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1448. ->orWhereNull('article_ignore.c_show_time');
  1449. });
  1450. });
  1451. })
  1452. ->select(
  1453. 'article.id',
  1454. 'article.title',
  1455. 'article.imgurl',
  1456. 'article.author',
  1457. 'article.updated_at',
  1458. 'article.introduce',
  1459. 'article.islink',
  1460. 'article.linkurl',
  1461. 'article.copyfrom',
  1462. 'article.cat_arr_id',
  1463. 'article.catid'
  1464. );
  1465. $count = $query->count();
  1466. $rep = $query->orderBy("updated_at", "desc")
  1467. ->offset(($data['page'] - 1) * $data['pageSize'])
  1468. ->limit($data['pageSize'])
  1469. ->get()->all();
  1470. $categorys = $this->processArticlePro($website_id);
  1471. $cat_1st_arr = $categorys['cat_1st_arr'];
  1472. $catiall = $categorys['catiall'];
  1473. // $web['website_id'] = $data['website_id'];
  1474. foreach ($rep as $k => $v) {
  1475. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1476. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1477. }
  1478. // $rep = $this->processArticles($rep,$web);
  1479. $data = [
  1480. 'rows' => $rep,
  1481. 'count' => $count,
  1482. ];
  1483. if (empty($rep)) {
  1484. return Result::error("没有信息数据");
  1485. }
  1486. return Result::success($data);
  1487. }
  1488. /**
  1489. * 前端-获取新闻详情
  1490. * @param array $data
  1491. * @return array
  1492. */
  1493. public function selectWebsiteArticleInfo(array $data): array
  1494. {
  1495. $where = [
  1496. 'article.id' => $data['id'],
  1497. 'article.status' => 1,
  1498. ];
  1499. $result = Article::where($where)
  1500. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1501. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1502. // ->where(function ($query) use ($data) {
  1503. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1504. // ->orWhereNull("ignore_ids");
  1505. // })
  1506. ->leftJoinSub(function ($query) use ($data) {
  1507. $query->from('article_ignore')
  1508. ->where('website_id', $data['website_id']);
  1509. }, 'article_ignore', function ($join) {
  1510. $join->on('article_ignore.article_id', '=', 'article.id');
  1511. })
  1512. ->where(function ($query) {
  1513. $query->whereNull('article_ignore.article_id')
  1514. ->orWhere(function ($subQuery) {
  1515. $subQuery->whereNotNull('article_ignore.article_id')
  1516. ->where('article_ignore.is_ignore', 0)
  1517. ->where(function ($subSubQuery) {
  1518. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1519. ->orWhereNull('article_ignore.c_show_time');
  1520. });
  1521. });
  1522. })
  1523. ->select(
  1524. 'article.*',
  1525. 'article_data.content',
  1526. 'article_data.article_id',
  1527. 'article_extend.website_url',
  1528. 'article_extend.email',
  1529. 'article_extend.contacts',
  1530. 'article_extend.contacts_mobile',
  1531. 'article_extend.contacts_address',
  1532. 'article_extend.zip_code',
  1533. 'article_extend.enterprise_name'
  1534. )
  1535. ->first();
  1536. if (empty($result)) {
  1537. return Result::error("暂无此新闻!", 0);
  1538. }
  1539. if (!empty($result['publiced_at'])) {
  1540. $result['updated_at'] = $result['publiced_at'];
  1541. }
  1542. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1543. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1544. ->where('website_category.website_id', $data['website_id'])
  1545. ->where(['website_category.category_id' => $result['catid']])
  1546. ->first();
  1547. if (empty($category)) {
  1548. return Result::error("查询失败", 0);
  1549. }
  1550. //手动推荐文章
  1551. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1552. if (empty($commend_ids)) {
  1553. $commendArticle = [];
  1554. } else {
  1555. //去除不存在的文章ID
  1556. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1557. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1558. ->leftJoinSub(function ($query) use ($data) {
  1559. $query->from('article_ignore')
  1560. ->where('website_id', $data['website_id']);
  1561. }, 'article_ignore', function ($join) {
  1562. $join->on('article_ignore.article_id', '=', 'article.id');
  1563. })
  1564. ->where(function ($query) {
  1565. $query->whereNull('article_ignore.article_id')
  1566. ->orWhere(function ($subQuery) {
  1567. $subQuery->whereNotNull('article_ignore.article_id')
  1568. ->where('article_ignore.is_ignore', 0)
  1569. ->where(function ($subSubQuery) {
  1570. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1571. ->orWhereNull('article_ignore.c_show_time');
  1572. });
  1573. });
  1574. })
  1575. ->where('article.status', 1)
  1576. ->where('website_category.website_id', $data['website_id'])
  1577. ->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')
  1578. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1579. // ->orderBy('article.updated_at', 'desc')
  1580. ->limit(5)
  1581. ->get();
  1582. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1583. foreach ($commendArticle as $k => $v) {
  1584. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1585. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1586. $cat_arr_id = array_unique($cat_arr_id);
  1587. // 从website_category取出alias_pinyin
  1588. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1589. ->whereIn('category_id', $cat_arr_id)
  1590. ->pluck('alias_pinyin', 'category_id')
  1591. ->toArray();
  1592. // 将cat_arr_id的json转成路径/隔开
  1593. $path_parts = [];
  1594. foreach ($cat_arr_id as $cat_id) {
  1595. if (isset($cat_arr[$cat_id])) {
  1596. $path_parts[] = $cat_arr[$cat_id];
  1597. }
  1598. }
  1599. $v->alias_pinyin = implode('/', $path_parts);
  1600. } else {
  1601. $v->alias_pinyin = '';
  1602. }
  1603. }
  1604. }
  1605. $result['category_id'] = $category['category_id'];
  1606. $result['cat_name'] = $category['alias'];
  1607. $result['website_name'] = $category['website_name'] ?? "";
  1608. $result['suffix'] = $category['suffix'] ?? "";
  1609. $result['commendArticle'] = $commendArticle;
  1610. $result['commend_ids'] = $commend_ids;
  1611. return Result::success($result);
  1612. }
  1613. /**
  1614. * 前端-获取网站调查问卷
  1615. * @param array $data
  1616. * @return array
  1617. */
  1618. public function getWebsiteSurvey(array $data): array
  1619. {
  1620. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1621. $website = Website::where('id', $data['website_id'])->first();
  1622. if (empty($website)) {
  1623. return Result::error("暂无此网站", 0);
  1624. }
  1625. }
  1626. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1627. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1628. if (empty($article)) {
  1629. return Result::error("暂无此文章", 0);
  1630. }
  1631. // return Result::error($data,0);
  1632. $where['art_id'] = $data['art_id'];
  1633. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1634. } else {
  1635. $survey = Article::where(function ($query) {
  1636. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1637. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1638. })
  1639. ->where('status', 1)
  1640. ->where('is_survey', 1)
  1641. ->select('survey_id')
  1642. ->orderBy('updated_at', 'desc')
  1643. ->first();
  1644. if (empty($survey)) {
  1645. return Result::error("暂无调查问卷", 0);
  1646. }
  1647. $where['sur_id'] = $survey['survey_id'];
  1648. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1649. }
  1650. // return Result::success($where);
  1651. $result = ArticleSurvey::where($where)
  1652. ->where(function ($query) {
  1653. $query->where('is_other', 0)
  1654. ->orWhere(function ($subQuery) {
  1655. $subQuery->where('is_other', 1)
  1656. ->where('other_id', 0);
  1657. });
  1658. })
  1659. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1660. ->select('article_survey.*', 'article.survey_type')
  1661. ->get()->all();
  1662. if (empty($result)) {
  1663. return Result::error("此文章暂无调查问卷", 0);
  1664. }
  1665. return Result::success($result);
  1666. }
  1667. /**
  1668. * 前端-添加网站调查问卷选项
  1669. * @param array $data
  1670. * @return array
  1671. */
  1672. public function addWebsiteSurveyOption(array $data): array
  1673. {
  1674. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1675. $website = Website::where('id', $data['website_id'])->first();
  1676. if (empty($website)) {
  1677. return Result::error("暂无此网站", 0);
  1678. }
  1679. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1680. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1681. if (empty($survey)) {
  1682. return Result::error("此调查问卷不可添加选项", 0);
  1683. }
  1684. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1685. $choice = [
  1686. 'art_id' => $survey['art_id'],
  1687. 'website_id' => $data['website_id'],
  1688. 'survey_name' => $survey['survey_name'],
  1689. 'choice_name' => $data['choice_name'],
  1690. 'sur_id' => $survey['sur_id'],
  1691. 'is_other' => 1,
  1692. 'other_id' => $survey['id'],
  1693. ];
  1694. $result = ArticleSurvey::insertGetId($choice);
  1695. if (empty($result)) {
  1696. return Result::error("添加失败", 0);
  1697. }
  1698. return Result::success($result);
  1699. }
  1700. }
  1701. return Result::error("添加失败", 0);
  1702. }
  1703. return Result::error("添加失败", 0);
  1704. }
  1705. /**
  1706. * 前端-调查问卷投票
  1707. * @param array $data
  1708. * @return array
  1709. */
  1710. public function addWebsiteSurveyVote(array $data): array
  1711. {
  1712. // return Result::success($data);
  1713. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1714. $website = Website::where('id', $data['website_id'])->first();
  1715. if (empty($website)) {
  1716. return Result::error("暂无此网站", 0);
  1717. }
  1718. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1719. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1720. // return Result::success($survey);
  1721. if (empty($is_survey)) {
  1722. return Result::error("此调查问卷不存在", 0);
  1723. }
  1724. // return Result::success($survey);
  1725. // 调查问卷类型
  1726. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1727. //多选 若是json型则转化成数组类型
  1728. if (strpos($data['choice_id'], '[') === 0) {
  1729. $data['choice_id'] = json_decode($data['choice_id'], true);
  1730. } else {
  1731. // 单选 也转换成数组
  1732. $data['choice_id'] = [$data['choice_id']];
  1733. }
  1734. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1735. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1736. // ->where('website_id',$data['website_id'])
  1737. ->where('is_other', 1)
  1738. ->where('other_id', 0)
  1739. ->first();
  1740. if (!empty($other)) {
  1741. return Result::error("请选择已有的选项!", 0);
  1742. }
  1743. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1744. // ->where('website_id',$data['website_id'])
  1745. ->where('is_other', 1)
  1746. ->where('other_id', '!=', 0)
  1747. ->first();
  1748. // return Result::success($choice['other']);
  1749. $choice_id = $data['choice_id'];
  1750. if (!empty($choice['other'])) {
  1751. // array_push($data['choice_id'],$choice['other']['other_id']);
  1752. if (!empty($choice_id)) {
  1753. $key = array_search($choice['other']['id'], $choice_id);
  1754. if ($key !== false) {
  1755. unset($choice_id[$key]);
  1756. $choice_id = array_values($choice_id);
  1757. }
  1758. array_push($choice_id, $choice['other']['other_id']);
  1759. } else {
  1760. $choice_id[0] = $choice['other']['other_id'];
  1761. }
  1762. array_push($data['choice_id'], $choice['other']['other_id']);
  1763. }
  1764. // return Result::success($data);
  1765. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1766. // ->where('website_id',$data['website_id'])
  1767. ->increment('results', 1);
  1768. if (empty($choice)) {
  1769. return Result::error("请选择已有的选项!", 0);
  1770. }
  1771. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1772. // ->where('website_id',$data['website_id'])
  1773. ->where('other_id', 0)
  1774. ->get();
  1775. $survey['choice'] = $choice_id;
  1776. return Result::success($survey);
  1777. }
  1778. return Result::error("参数必填!");
  1779. }
  1780. return Result::error("此调查问卷不存在", 0);
  1781. }
  1782. return Result::error("参数必填!");
  1783. }
  1784. /**
  1785. * 后端-获取网站调查问卷列表
  1786. * @param array $data
  1787. * @return array
  1788. */
  1789. public function getSurveyList(array $data): array
  1790. {
  1791. $where = [];
  1792. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1793. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1794. }
  1795. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1796. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1797. }
  1798. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1799. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1800. }
  1801. // return Result::success($where);
  1802. if (!empty($where)) {
  1803. $query = Article::where($where)->where(function ($q) {
  1804. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1805. });
  1806. } else {
  1807. $query = Article::where(function ($q) {
  1808. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1809. });
  1810. }
  1811. $count = $query->count();
  1812. $survey = $query->orderByDesc('id')
  1813. ->limit($data['pageSize'])
  1814. ->offset(($data['page'] - 1) * $data['pageSize'])
  1815. ->get();
  1816. if (empty($survey->toArray())) {
  1817. return Result::error("暂无调查问卷!", 0);
  1818. }
  1819. $result = [
  1820. 'rows' => $survey,
  1821. 'count' => $count,
  1822. ];
  1823. return Result::success($result);
  1824. }
  1825. /**
  1826. * 后端-获取网站调查问卷详情
  1827. * @param array $data
  1828. * @return array
  1829. */
  1830. public function getSurveyInfo(array $data): array
  1831. {
  1832. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1833. $where = ['sur_id' => $data['sur_id']];
  1834. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1835. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1836. ->select('article_survey.*', 'article.survey_type')
  1837. ->get()->all();
  1838. if (empty($choose)) {
  1839. return Result::error("此调查问卷不存在", 0);
  1840. }
  1841. $resultsArray = array_column($choose, 'results');
  1842. $total = array_sum($resultsArray);
  1843. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1844. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1845. // $total = 0;
  1846. if (!empty($other)) {
  1847. $total = $total + $other['results'];
  1848. $other['choice_name'] = '(其他)';
  1849. if (!empty($others)) {
  1850. $other['hasChildren'] = true;
  1851. // array_push($other,['hasChildren','=',true]);
  1852. $other['children'] = $others;
  1853. $other_choices = [$other->toArray()];
  1854. $mer_choice = array_merge($choose, $other_choices);
  1855. $value_choice = array_values($mer_choice);
  1856. } else {
  1857. // return Result::error('1111');
  1858. $other_choices = [$other->toArray()];
  1859. $other_choices = array_merge($choose, $other_choices);
  1860. $value_choice = array_values($other_choices);
  1861. // return Result::success($result);
  1862. }
  1863. } else {
  1864. $value_choice = $choose;
  1865. }
  1866. $result = [
  1867. 'choose' => $value_choice,
  1868. 'total' => $total,
  1869. ];
  1870. }
  1871. return Result::success($result);
  1872. }
  1873. /**
  1874. * 前端-搜索新闻列表
  1875. * @param array $data
  1876. * @return array
  1877. */
  1878. public function selectWebsiteArticle(array $data): array
  1879. {
  1880. $website = Website::where('id', $data['website_id'])->first();
  1881. if (empty($website)) {
  1882. return Result::error("网站不存在", 0);
  1883. }
  1884. // $website_column = $website['column'];
  1885. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1886. $website_column = json_decode($website['website_column_arr_id'], true);
  1887. }
  1888. $website_id = $data['website_id'];
  1889. $categorys = $this->processArticlePro($website_id);
  1890. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1891. // return Result::success($diff_pid_categoryIds);
  1892. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1893. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1894. }
  1895. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1896. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1897. $catiall = $categorys['catiall'];
  1898. $categoryIds = $categorys['categoryIds'];
  1899. // return Result::success($categoryIds);
  1900. $query = Article::where('status', 1)
  1901. ->whereIn('catid', $categoryIds)
  1902. ->leftJoinSub(function ($query) use ($website_id) {
  1903. $query->from('article_ignore')
  1904. ->where('website_id', $website_id);
  1905. }, 'article_ignore', function ($join) {
  1906. $join->on('article_ignore.article_id', '=', 'article.id');
  1907. })
  1908. ->where(function ($query) {
  1909. $query->whereNull('article_ignore.article_id')
  1910. ->orWhere(function ($subQuery) {
  1911. $subQuery->whereNotNull('article_ignore.article_id')
  1912. ->where('article_ignore.is_ignore', 0)
  1913. ->where(function ($subSubQuery) {
  1914. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1915. ->orWhereNull('article_ignore.c_show_time');
  1916. });
  1917. });
  1918. });
  1919. // ->get()->all();
  1920. // return Result::success($query);
  1921. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1922. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1923. }
  1924. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1925. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1926. }
  1927. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1928. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1929. }
  1930. // 计算总数
  1931. $count = $query->count();
  1932. // return Result::success($count);
  1933. // 分页查询
  1934. $articles = $query
  1935. ->select(
  1936. 'article.id',
  1937. 'article.title',
  1938. 'article.imgurl',
  1939. 'article.author',
  1940. 'article.updated_at',
  1941. 'article.introduce',
  1942. 'article.islink',
  1943. 'article.linkurl',
  1944. 'article.copyfrom',
  1945. 'article.cat_arr_id',
  1946. 'article.catid',
  1947. 'article.department_arr_id',
  1948. 'article.city_arr_id',
  1949. // 'article_ignore.c_show_time',
  1950. // 'article_ignore.is_ignore'
  1951. )
  1952. ->orderBy("updated_at", "desc")
  1953. ->offset(($data['page'] - 1) * $data['pageSize'])
  1954. ->limit($data['pageSize'])
  1955. ->get();
  1956. // return Result::success($articles);
  1957. foreach ($articles as $k => $v) {
  1958. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1959. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1960. }
  1961. if (empty($articles)) {
  1962. return Result::error("没有符合条件的资讯数据");
  1963. }
  1964. $result = [
  1965. 'rows' => $articles,
  1966. 'count' => $count,
  1967. ];
  1968. return Result::success($result);
  1969. }
  1970. /**
  1971. * 模块新闻加强版
  1972. * @param array $data
  1973. * @return array
  1974. */
  1975. public function getWebsiteCatidArticle(array $data): array
  1976. {
  1977. $where = [
  1978. 'website_category.category_id' => $data['catid'],
  1979. 'website_category.website_id' => $data['website_id'],
  1980. ];
  1981. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1982. $child_catnum = $data['child_catnum'] ?? 1;
  1983. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1984. $childCategoryIds = array_column($category['child'], 'category_id');
  1985. if (empty($childCategoryIds)) {
  1986. return Result::error("暂无子栏目", 0);
  1987. }
  1988. $imgArticles = [];
  1989. $textArticles = [];
  1990. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1991. // 初始化子分类图片新闻和文字新闻数组
  1992. // 查询所有子级栏目的图文新闻
  1993. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1994. ->where(function ($query) use ($data) {
  1995. $query->where(function ($subQuery) use ($data) {
  1996. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1997. })->orWhereNull("ignore_ids");
  1998. })
  1999. ->where('status', 1)
  2000. ->where('imgurl', '!=', '')
  2001. ->select('*')
  2002. ->orderBy('updated_at', 'desc')
  2003. ->limit($data['child_imgnum'])
  2004. ->get();
  2005. }
  2006. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2007. // 查询所有子级栏目的文字新闻
  2008. $textArticles = Article::where('catid', $childCategoryIds[0])
  2009. ->where('status', 1)
  2010. ->where(function ($query) use ($data) {
  2011. $query->where(function ($subQuery) use ($data) {
  2012. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2013. })->orWhereNull("ignore_ids");
  2014. })
  2015. ->select('*')
  2016. ->orderBy('updated_at', 'desc')
  2017. ->limit($data['child_textnum'])
  2018. ->get();
  2019. }
  2020. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2021. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2022. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2023. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2024. return $child;
  2025. }, $category['child']);
  2026. }
  2027. // }
  2028. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2029. $category['img'] = WebsiteCategory::where($where)
  2030. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2031. ->where('article.status', 1)
  2032. ->where('article.imgurl', '!=', '')
  2033. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2034. ->orderBy('article.updated_at', 'desc')
  2035. ->limit($data['img_num'])
  2036. ->get();
  2037. }
  2038. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2039. $category['text'] = WebsiteCategory::where($where)
  2040. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2041. ->where('article.status', 1)
  2042. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2043. ->orderBy('article.updated_at', 'desc')
  2044. ->limit($data['text_num'])
  2045. ->get();
  2046. }
  2047. // $category = $category->get();
  2048. if (empty($category)) {
  2049. return Result::error("查询失败", 0);
  2050. }
  2051. return Result::success($category);
  2052. }
  2053. /**
  2054. * 模块新闻加强plus版
  2055. * @param array $data
  2056. * @return array
  2057. */
  2058. public function getWebsiteAllArticle(array $data): array
  2059. {
  2060. // return Result::success($data);
  2061. $time1 = microtime(true);
  2062. $wetbsite_id = $data['website_id'] ?? 2;
  2063. $data = json_decode($data['id'], true);
  2064. $website = Website::where('id', $wetbsite_id)->first();
  2065. if (empty($website)) {
  2066. return Result::error("网站不存在", 0);
  2067. }
  2068. // return Result::success($website);
  2069. $website_column = $website['website_column_arr_id'] ?? '[]';
  2070. $website_column = json_decode($website_column, true);
  2071. $categorys = $this->processArticlePro($wetbsite_id);
  2072. $cat_1st_arr = $categorys['cat_1st_arr'];
  2073. $catiall = $categorys['catiall'];
  2074. // return Result::success($catiall);
  2075. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2076. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2077. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2078. }
  2079. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2080. // return Result::success($categorys);
  2081. $parent_category = array_column($data, 'parent');
  2082. $parent_cat = [];
  2083. $child_category = array_column($data, 'child');
  2084. if (!empty($parent_category)) {
  2085. foreach ($parent_category as $key => $value) {
  2086. $arr = array_map('intval', explode(',', $value));
  2087. $parent_cat[$key] = $arr[0] ?? 0;
  2088. $parent_category = $arr[0] ?? 0;
  2089. $article_imgnum = $arr[1] ?? 0;
  2090. $article_textnum = $arr[2] ?? 0;
  2091. if ($parent_category != 0) {
  2092. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2093. // return Result::success($category_arr);
  2094. if ($article_imgnum != 0) {
  2095. $img_article = Article::whereIn('catid', $category_arr)
  2096. ->where('status', 1)
  2097. ->where('imgurl', '!=', '')
  2098. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2099. $query->from('article_ignore')
  2100. ->where('website_id', $wetbsite_id);
  2101. }, 'article_ignore', function ($join) {
  2102. $join->on('article_ignore.article_id', '=', 'article.id');
  2103. })
  2104. ->where(function ($query) {
  2105. $query->whereNull('article_ignore.article_id')
  2106. ->orWhere(function ($subQuery) {
  2107. $subQuery->whereNotNull('article_ignore.article_id')
  2108. ->where('article_ignore.is_ignore', 0)
  2109. ->where(function ($subSubQuery) {
  2110. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2111. ->orWhereNull('article_ignore.c_show_time');
  2112. });
  2113. });
  2114. })
  2115. ->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')
  2116. ->orderBy('updated_at', 'desc')
  2117. ->limit($article_imgnum)
  2118. ->get()->all();
  2119. foreach ($img_article as $k => $v) {
  2120. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2121. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2122. }
  2123. } else {
  2124. $img_article = [];
  2125. }
  2126. if ($article_textnum != 0) {
  2127. $text_article = Article::whereIn('catid', $category_arr)
  2128. ->where('status', 1)
  2129. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2130. $query->from('article_ignore')
  2131. ->where('website_id', $wetbsite_id);
  2132. }, 'article_ignore', function ($join) {
  2133. $join->on('article_ignore.article_id', '=', 'article.id');
  2134. })
  2135. ->where(function ($query) {
  2136. $query->whereNull('article_ignore.article_id')
  2137. ->orWhere(function ($subQuery) {
  2138. $subQuery->whereNotNull('article_ignore.article_id')
  2139. ->where('article_ignore.is_ignore', 0)
  2140. ->where(function ($subSubQuery) {
  2141. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2142. ->orWhereNull('article_ignore.c_show_time');
  2143. });
  2144. });
  2145. })
  2146. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2147. ->orderBy('updated_at', 'desc')
  2148. ->limit($article_textnum)
  2149. ->get()->all();
  2150. foreach ($text_article as $k => $v) {
  2151. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2152. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2153. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2154. }
  2155. } else {
  2156. $text_article = [];
  2157. }
  2158. $catiall[$parent_category]['imgnum'] = $img_article;
  2159. $catiall[$parent_category]['textnum'] = $text_article;
  2160. $parent[$key] = $catiall[$parent_category];
  2161. } else {
  2162. $parent[$key] = '';
  2163. }
  2164. }
  2165. }
  2166. if (!empty($child_category)) {
  2167. foreach ($child_category as $key => $value) {
  2168. $arr = array_map('intval', explode(',', $value));
  2169. $parent_category = $parent_cat[$key];
  2170. $child_category = $arr[0] ?? 0;
  2171. $article_imgnum = $arr[1] ?? 0;
  2172. $article_textnum = $arr[2] ?? 0;
  2173. if ($child_category != 0) {
  2174. $all_childcat = $cat_1st_arr[$parent_category];
  2175. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2176. // 从 $websiteInfoIndexed 中获取对应的数据
  2177. $info = $websiteInfoIndexed[$v];
  2178. // 返回一个包含所需信息的数组
  2179. return [
  2180. 'alias' => $info->alias,
  2181. 'category_id' => $info->category_id,
  2182. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2183. 'pid' => $info->pid,
  2184. 'type' => $info->type,
  2185. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2186. 'pinyin' => $info->pinyin,
  2187. ];
  2188. }, $all_childcat);
  2189. if ($article_imgnum != 0) {
  2190. $img_article = Article::where('catid', $child_category)
  2191. ->where('status', 1)
  2192. ->where('imgurl', '!=', '')
  2193. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2194. $query->from('article_ignore')
  2195. ->where('website_id', $wetbsite_id);
  2196. }, 'article_ignore', function ($join) {
  2197. $join->on('article_ignore.article_id', '=', 'article.id');
  2198. })
  2199. ->where(function ($query) {
  2200. $query->whereNull('article_ignore.article_id')
  2201. ->orWhere(function ($subQuery) {
  2202. $subQuery->whereNotNull('article_ignore.article_id')
  2203. ->where('article_ignore.is_ignore', 0)
  2204. ->where(function ($subSubQuery) {
  2205. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2206. ->orWhereNull('article_ignore.c_show_time');
  2207. });
  2208. });
  2209. })
  2210. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2211. ->orderBy('updated_at', 'desc')
  2212. ->limit($article_imgnum)
  2213. ->get()->all();
  2214. foreach ($img_article as $k => $v) {
  2215. // var_dump($v);
  2216. // var_dump($k);
  2217. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2218. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2219. }
  2220. } else {
  2221. $img_article = [];
  2222. }
  2223. if ($article_textnum != 0) {
  2224. $text_article = Article::where('catid', $child_category)
  2225. ->where('status', 1)
  2226. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2227. $query->from('article_ignore')
  2228. ->where('website_id', $wetbsite_id);
  2229. }, 'article_ignore', function ($join) {
  2230. $join->on('article_ignore.article_id', '=', 'article.id');
  2231. })
  2232. ->where(function ($query) {
  2233. $query->whereNull('article_ignore.article_id')
  2234. ->orWhere(function ($subQuery) {
  2235. $subQuery->whereNotNull('article_ignore.article_id')
  2236. ->where('article_ignore.is_ignore', 0)
  2237. ->where(function ($subSubQuery) {
  2238. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2239. ->orWhereNull('article_ignore.c_show_time');
  2240. });
  2241. });
  2242. })
  2243. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2244. ->orderBy('updated_at', 'desc')
  2245. ->limit($article_textnum)
  2246. ->get()->all();
  2247. foreach ($text_article as $k => $v) {
  2248. // var_dump($v);
  2249. // var_dump($k);
  2250. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2251. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2252. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2253. }
  2254. } else {
  2255. $text_article = [];
  2256. }
  2257. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2258. $catiall[$child_category]['imgnum'] = $img_article;
  2259. $catiall[$child_category]['textnum'] = $text_article;
  2260. $child[$key] = $catiall[$child_category];
  2261. // var_dump($pids);
  2262. } else {
  2263. $child[$key] = '';
  2264. }
  2265. }
  2266. }
  2267. foreach ($parent as $key => $value) {
  2268. $result[$key] = $value;
  2269. if (!empty($child[$key])) {
  2270. // var_dump($child[$key]);
  2271. $result[$key]['child'] = $child[$key];
  2272. // $value[$key]['child'] = $child[$key];
  2273. } else {
  2274. $result[$key]['child'] = [
  2275. "alias" => null,
  2276. "category_id" => null,
  2277. "type" => null,
  2278. "pinyin" => null,
  2279. "all_childcat" => [],
  2280. "imgnum" => [],
  2281. "textnum" => []
  2282. ];
  2283. }
  2284. }
  2285. return Result::success($result);
  2286. }
  2287. /**
  2288. * 辅助方法:获取文章列表
  2289. */
  2290. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2291. {
  2292. sleep(1);
  2293. $query = Article::where('article.status', 1)
  2294. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2295. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2296. ->where(function ($query) use ($website) {
  2297. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2298. })
  2299. ->leftJoin('website_category', function ($join) use ($website) {
  2300. $join->on('article.catid', '=', 'website_category.category_id')
  2301. ->where('website_category.website_id', '=', $website['website_id']);
  2302. })
  2303. ->select(
  2304. 'article.id',
  2305. 'article.title',
  2306. 'article.imgurl',
  2307. 'article.author',
  2308. 'article.updated_at',
  2309. 'article.introduce',
  2310. 'article.islink',
  2311. 'article.linkurl',
  2312. 'article.copyfrom',
  2313. 'article.cat_arr_id',
  2314. 'article.catid',
  2315. 'website_category.alias as category_name'
  2316. )
  2317. ->orderBy('updated_at', 'desc')
  2318. ->limit($limit);
  2319. // 如果是图片文章,添加图片URL条件
  2320. if ($isImageArticle) {
  2321. $query->where('imgurl', '!=', '');
  2322. } else {
  2323. // 文字文章不需要imgurl字段
  2324. $query->addSelect('article.introduce');
  2325. }
  2326. $articles = $query->get();
  2327. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2328. }
  2329. /**
  2330. * 乡村网-获取特殊新闻模块
  2331. * @param array $data
  2332. * @return array
  2333. */
  2334. public function getWebsiteArticles(array $data): array
  2335. {
  2336. $website_id = $data['website_id'];
  2337. $website = Website::where('id', $website_id)->first();
  2338. if (empty($website)) {
  2339. return Result::error("网站不存在", 0);
  2340. }
  2341. // return Result::success($website);
  2342. $website_column = $website['website_column_arr_id'] ?? '[]';
  2343. $website_column = json_decode($website_column, true);
  2344. $catids = json_decode($data['id'], true);
  2345. $parent_category = array_column($catids, 'parent');
  2346. if (!empty($parent_category) && is_array($parent_category)) {
  2347. $categorys = $this->processArticlePro($website_id);
  2348. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2349. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2350. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2351. }
  2352. $catiall = $categorys['catiall'];
  2353. $cat_1st_arr = $categorys['cat_1st_arr'];
  2354. // return Result::success($categorys);
  2355. foreach ($parent_category as $key => $value) {
  2356. $arr = array_map('intval', explode(',', $value));
  2357. $parent_category = $arr[0] ?? 0;
  2358. $article_imgnum = $arr[1] ?? 0;
  2359. $article_textnum = $arr[2] ?? 0;
  2360. if ($parent_category != 0) {
  2361. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2362. // return Result::success($category_arr);
  2363. if ($article_imgnum != 0) {
  2364. $img_article = Article::whereIn('article.catid', $category_arr)
  2365. ->where('article.status', 1)
  2366. ->where('article.imgurl', '!=', '')
  2367. ->leftJoinSub(function ($query) use ($website_id) {
  2368. $query->from('article_ignore')
  2369. ->where('website_id', $website_id);
  2370. }, 'article_ignore', function ($join) {
  2371. $join->on('article_ignore.article_id', '=', 'article.id');
  2372. })
  2373. ->where(function ($query) {
  2374. $query->whereNull('article_ignore.article_id')
  2375. ->orWhere(function ($subQuery) {
  2376. $subQuery->whereNotNull('article_ignore.article_id')
  2377. ->where('article_ignore.is_ignore', 0)
  2378. ->where(function ($subSubQuery) {
  2379. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2380. ->orWhereNull('article_ignore.c_show_time');
  2381. });
  2382. });
  2383. })
  2384. ->select(
  2385. 'article.id',
  2386. 'article.title',
  2387. 'article.imgurl',
  2388. 'article.author',
  2389. 'article.updated_at',
  2390. 'article.introduce',
  2391. 'article.islink',
  2392. 'article.linkurl',
  2393. 'article.copyfrom',
  2394. 'article.cat_arr_id',
  2395. 'article.catid as category_id'
  2396. )
  2397. ->orderBy('updated_at', 'desc')
  2398. ->limit($article_imgnum)
  2399. ->get()->all();
  2400. foreach ($img_article as $k => $v) {
  2401. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2402. // return Result::success($v);
  2403. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2404. }
  2405. } else {
  2406. $img_article = [];
  2407. }
  2408. if ($article_textnum != 0) {
  2409. $text_article = Article::whereIn('article.catid', $category_arr)
  2410. ->where('article.status', 1)
  2411. ->leftJoinSub(function ($query) use ($website_id) {
  2412. $query->from('article_ignore')
  2413. ->where('website_id', $website_id);
  2414. }, 'article_ignore', function ($join) {
  2415. $join->on('article_ignore.article_id', '=', 'article.id');
  2416. })
  2417. ->where(function ($query) {
  2418. $query->whereNull('article_ignore.article_id')
  2419. ->orWhere(function ($subQuery) {
  2420. $subQuery->whereNotNull('article_ignore.article_id')
  2421. ->where('article_ignore.is_ignore', 0)
  2422. ->where(function ($subSubQuery) {
  2423. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2424. ->orWhereNull('article_ignore.c_show_time');
  2425. });
  2426. });
  2427. })
  2428. ->select(
  2429. 'article.id',
  2430. 'article.title',
  2431. 'article.author',
  2432. 'article.updated_at',
  2433. 'article.introduce',
  2434. 'article.islink',
  2435. 'article.linkurl',
  2436. 'article.copyfrom',
  2437. 'article.cat_arr_id',
  2438. 'article.catid as category_id'
  2439. )
  2440. ->orderBy('updated_at', 'desc')
  2441. ->limit($article_textnum)
  2442. ->get()->all();
  2443. foreach ($text_article as $k => $v) {
  2444. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2445. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2446. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2447. }
  2448. } else {
  2449. $text_article = [];
  2450. }
  2451. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2452. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2453. $parent[$key] = $catiall[$parent_category];
  2454. } else {
  2455. $parent[$key] = [];
  2456. }
  2457. }
  2458. }
  2459. return Result::success($parent);
  2460. }
  2461. // 封装处理商品的路由问题
  2462. function processGoods($goods, $data)
  2463. {
  2464. return $goods->map(function ($good) use ($data) {
  2465. $catid = $good->catid ?? 0;
  2466. // $pinyin = '';
  2467. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2468. if (!empty($category->pid) && $category->pid != 0) {
  2469. $level = json_decode($category->category_arr_id, true);
  2470. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2471. ->whereIn('category_id', $level)
  2472. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2473. ->get(['aLIas_pinyin'])
  2474. ->pluck('aLIas_pinyin')
  2475. ->implode('/');
  2476. } else {
  2477. $pinyin = $category->aLIas_pinyin ?? '';
  2478. }
  2479. if (isset($good->city_id) && !empty($good->city_id)) {
  2480. $city = District::where('id', $good->city_id)->first(['name']);
  2481. $good->city_name = $city->name ?? '';
  2482. }
  2483. // 解析imgurl JSON并取第一条数据
  2484. $imgUrls = json_decode($good->imgurl, true);
  2485. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2486. $good->pinyin = $pinyin;
  2487. return $good;
  2488. });
  2489. }
  2490. /**
  2491. * 获取商城首页-根据栏目id
  2492. * @param array $data
  2493. * @return array
  2494. * */
  2495. function getWebsiteCatidshop(array $data): array
  2496. {
  2497. $input['catid'] = $data['catid'];
  2498. $input['website_id'] = $data['website_id'];
  2499. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2500. $result = array_map(function ($item) use ($input) {
  2501. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2502. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2503. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2504. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2505. if (empty($category) || $category->type != 2) {
  2506. return Result::error("暂无此栏目", 0);
  2507. } else {
  2508. $website['website_id'] = $input['website_id'];
  2509. $goods = Good::where('good.status', 2)
  2510. ->where('good.website_id', $website['website_id'])
  2511. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2512. ->select(
  2513. 'good.id',
  2514. 'good.name',
  2515. 'good.imgurl',
  2516. 'good.description',
  2517. 'good.updated_at',
  2518. 'good.catid',
  2519. 'good.type_id',
  2520. 'good.price',
  2521. 'good.com',
  2522. 'good.level',
  2523. 'good.unit'
  2524. )
  2525. ->orderBy('updated_at', 'desc')
  2526. ->offset($goodStart)
  2527. ->limit($goodNum);
  2528. $all_goods = $goods->get();
  2529. $all_goods = $this->processGoods($all_goods, $website);
  2530. }
  2531. return $all_goods ?? [];
  2532. }
  2533. }, $data);
  2534. return Result::success($result);
  2535. }
  2536. /**
  2537. * 获取商品模块
  2538. * @param array $data
  2539. * @return array
  2540. * */
  2541. public function getWebsiteshop(array $data): array
  2542. {
  2543. $input['id'] = $data['id'];
  2544. $input['website_id'] = $data['website_id'];
  2545. $catid = $data['catid'];
  2546. $data = json_decode($input['id'] ?? '', true) ?? [];
  2547. $result['goods'] = array_map(function ($item) use ($input) {
  2548. // 检查parent元素是否存在且不是undefined
  2549. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2550. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2551. $website = $input['website_id'];
  2552. $query = Good::where('good.status', 2)
  2553. ->where('good.website_id', $website);
  2554. switch ($Levelid) {
  2555. case 1:
  2556. case 2:
  2557. case 3:
  2558. $goods = $query->where(function ($q) use ($Levelid) {
  2559. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2560. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2561. });
  2562. break;
  2563. case 4:
  2564. $goods = $query;
  2565. break;
  2566. case 5:
  2567. $goods = $query->where('type_id', 1);
  2568. break;
  2569. case 6:
  2570. $goods = $query->where('type_id', 2);
  2571. break;
  2572. default:
  2573. return [];
  2574. }
  2575. $all_goods = $goods
  2576. ->select(
  2577. 'good.id',
  2578. 'good.name',
  2579. 'good.imgurl',
  2580. 'good.description',
  2581. 'good.updated_at',
  2582. 'good.catid',
  2583. 'good.type_id',
  2584. 'good.price',
  2585. 'good.level',
  2586. 'good.website_id'
  2587. )
  2588. ->orderBy('updated_at', 'desc')
  2589. ->offset($goodStart)
  2590. ->limit($goodNum)
  2591. ->get();
  2592. $web['website_id'] = $website;
  2593. $all_goods = $this->processGoods($all_goods, $web);
  2594. }
  2595. return $all_goods;
  2596. }, $data);
  2597. $website = $input['website_id'];
  2598. $result['article'] = Article::where(function ($query) use ($website) {
  2599. $query->where(function ($subQuery) use ($website) {
  2600. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2601. })->orWhereNull("ignore_ids");
  2602. })
  2603. ->where('catid', $catid)
  2604. ->where('article.status', 1)
  2605. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2606. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2607. ->orderBy('article.updated_at', 'desc')
  2608. ->first();
  2609. return Result::success($result);
  2610. }
  2611. /**
  2612. * 获取商品分类
  2613. * @param array $data
  2614. * @return array
  2615. * */
  2616. public function getWebsiteshopCat(array $data): array
  2617. {
  2618. $website = $data['website_id'];
  2619. $category = WebsiteCategory::where('website_id', $website)
  2620. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2621. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2622. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2623. ->orderBy('sort')
  2624. ->get();
  2625. $cat = $category->map(function ($item) use ($website) {
  2626. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2627. $pid = $item->pid ?? 0;
  2628. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2629. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2630. ->where('website_id', $website)
  2631. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2632. ->get(['aLIas_pinyin'])
  2633. ->pluck('aLIas_pinyin')
  2634. ->implode('/');
  2635. } else {
  2636. $pinyin = $item->aLIas_pinyin ?? '';
  2637. }
  2638. $item->pinyin = $pinyin;
  2639. });
  2640. if (empty($category)) {
  2641. return Result::error("栏目查询失败", 0);
  2642. }
  2643. $cat_tree = Result::buildMenuTree($category);
  2644. $web['website_id'] = $website;
  2645. $goods = Good::where('website_id', $website)
  2646. ->where('status', 2)
  2647. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2648. ->latest('updated_at')
  2649. ->offset(($data['page'] - 1) * $data['pageSize'])
  2650. ->limit($data['pageSize'])
  2651. ->get();
  2652. if (!empty($goods)) {
  2653. if ($goods->count() > 1 && !empty($goods)) {
  2654. $goods = $this->processGoods($goods, $web);
  2655. }
  2656. } else {
  2657. $goods = [];
  2658. }
  2659. $result = [
  2660. 'category' => $cat_tree,
  2661. 'goods' => $goods,
  2662. ];
  2663. // $resul['goods'] = $goods;
  2664. if (empty($result)) {
  2665. return Result::error("查询失败", 0);
  2666. }
  2667. return Result::success($result);
  2668. }
  2669. /*
  2670. * 获取商品列表
  2671. * @param array $data
  2672. * @return array
  2673. * */
  2674. public function getWebsiteshopList(array $data): array
  2675. {
  2676. // return Result::success($data);
  2677. $where = [
  2678. 'status' => 2,
  2679. 'website_id' => $data['website_id'],
  2680. ];
  2681. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2682. // return Result::error("查询失败", 0);
  2683. // }
  2684. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2685. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2686. $data['catid'] = $category->category_id ?? 0;
  2687. }
  2688. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2689. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2690. }
  2691. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2692. array_push($where, ['type_id', $data['type_id']]);
  2693. }
  2694. $query = Good::where($where)
  2695. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2696. $query->where(function ($q) use ($data) {
  2697. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2698. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2699. });
  2700. })
  2701. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2702. $query->where(function ($q) use ($data) {
  2703. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2704. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2705. });
  2706. })
  2707. ->select(
  2708. 'good.id',
  2709. 'good.name',
  2710. 'good.imgurl',
  2711. 'good.description',
  2712. 'good.updated_at',
  2713. 'good.com',
  2714. 'good.catid',
  2715. 'good.type_id',
  2716. 'good.website_id',
  2717. 'good.cat_arr_id',
  2718. 'good.created_at',
  2719. 'good.city_id'
  2720. )
  2721. ->latest('updated_at');
  2722. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2723. $result['count'] = $query->clone()->count();
  2724. $result['goods'] = $this->processGoods(
  2725. $query->clone()
  2726. ->offset(($data['page'] - 1) * $data['pageSize'])
  2727. ->limit($data['pageSize'])
  2728. ->get(),
  2729. $data
  2730. );
  2731. } else {
  2732. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2733. // 获取 type_id 为 1 的数据
  2734. $result['type1'] = $this->processGoods(
  2735. $query->clone()
  2736. ->where('type_id', 1)
  2737. ->offset(($data['page'] - 1) * $data['pageSize'])
  2738. ->limit($data['pageSize'])
  2739. ->get(),
  2740. $data
  2741. );
  2742. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2743. // 获取 type_id 为 2 的数据
  2744. $result['type2'] = $this->processGoods(
  2745. $query->clone()
  2746. ->where('type_id', 2)
  2747. ->offset(($data['page'] - 1) * $data['pageSize'])
  2748. ->limit($data['pageSize'])
  2749. ->get(),
  2750. $data
  2751. );
  2752. }
  2753. if (empty($result)) {
  2754. return Result::error("查询失败", 0);
  2755. }
  2756. return Result::success($result);
  2757. }
  2758. /**
  2759. * 获取商品详情
  2760. * @param array $data
  2761. * @return array
  2762. * */
  2763. public function getWebsiteshopInfo(array $data): array
  2764. {
  2765. $where = [
  2766. 'good.status' => 2,
  2767. 'good.website_id' => $data['website_id'],
  2768. 'good.id' => $data['id'],
  2769. ];
  2770. $goods = Good::where($where)
  2771. ->where('good.id', $data['id'])
  2772. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2773. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2774. ->first();
  2775. if (empty($goods)) {
  2776. return Result::error("查询失败", 0);
  2777. }
  2778. $goods->imgurl = json_decode($goods->imgurl, true);
  2779. return Result::success($goods);
  2780. }
  2781. /**
  2782. * plus pro 处理文章路由问题
  2783. */
  2784. function processArticlePro($website_id)
  2785. {
  2786. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2787. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2788. // // 取出category_id 对应的aLIas_pinyin
  2789. // $categoryIds = array_column($categorys, 'category_id');
  2790. // $categoryPIds = array_column($categorys, 'pid');
  2791. // $aliasPinyins = array_column($categorys, 'path');
  2792. // $alias = array_column($categorys, 'alias');
  2793. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2794. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2795. // // return Result::success($cat_arr);
  2796. // // $catiall = [];
  2797. // //一级所有子级的记录
  2798. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2799. // return [
  2800. // 'cat_1st_arr' => $cat_alias_arr,
  2801. // 'catiall' => $cat_arr,
  2802. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2803. // 'categoryIds' => $categoryIds,
  2804. // ];
  2805. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2806. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2807. // 取出category_id 对应的aLIas_pinyin
  2808. $categoryIds = array_column($categorys, 'category_id');
  2809. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2810. return $pid != 0;
  2811. })));
  2812. $category_path = array_column($categorys, 'path');
  2813. $cat_arr = array_combine($categoryIds, $category_path);
  2814. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2815. $catiall = [];
  2816. //一级所有子级的记录
  2817. $cat_1st_arr = [];
  2818. foreach ($categorys as $key => $value) {
  2819. // $category_arr_id = json_decode($value->category_arr_id);
  2820. // $pinyin_str = '';
  2821. // // 算出一级 并且算出子级
  2822. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2823. $cat_1st_arr[$value->pid][] = $value->category_id;
  2824. }
  2825. // foreach ($category_arr_id as $k => $v) {
  2826. // $pinyin_str .= $cat_arr[$v] . '/';
  2827. // }
  2828. // $pinyin_str = rtrim($pinyin_str, '/');
  2829. $catiall[$value->category_id]['alias'] = $value->alias;
  2830. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2831. $catiall[$value->category_id]['type'] = $value->type;
  2832. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2833. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2834. }
  2835. return [
  2836. 'cat_1st_arr' => $cat_1st_arr,
  2837. 'catiall' => $catiall,
  2838. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2839. 'categoryIds' => $categoryIds,
  2840. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2841. 'categoryPIds' => $categoryPIds,
  2842. ];
  2843. }
  2844. /**
  2845. * 封装处理文章的路由问题
  2846. * */
  2847. function processArticles($articles, $data)
  2848. {
  2849. // 检查 $articles 是否为数组或可迭代对象
  2850. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2851. return $articles->map(function ($article) use ($data) {
  2852. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2853. $catid = $article->cat_arr_id ?? '';
  2854. }
  2855. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2856. $catid = $article->category_arr_id ?? '';
  2857. }
  2858. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2859. $level = json_decode($catid, true);
  2860. if (!is_array($level)) {
  2861. return $article;
  2862. } else {
  2863. $level = array_map('intval', $level);
  2864. }
  2865. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2866. ->where($data)
  2867. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2868. ->pluck('aLIas_pinyin')
  2869. ->implode('/');
  2870. $article->pinyin = $pinyin ?? '';
  2871. return $article;
  2872. });
  2873. } else {
  2874. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2875. $catid = $articles->cat_arr_id ?? '';
  2876. $level = json_decode($catid, true);
  2877. if (!is_array($level)) {
  2878. return $articles;
  2879. } else {
  2880. $level = array_map('intval', $level);
  2881. }
  2882. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2883. ->where($data)
  2884. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2885. ->pluck('aLIas_pinyin')
  2886. ->implode('/');
  2887. $articles->pinyin = $pinyin ?? '';
  2888. return $articles;
  2889. }
  2890. }
  2891. // 封装处理由问题
  2892. function processJob($job, $data)
  2893. {
  2894. return $job->map(function ($job) use ($data) {
  2895. $category = $job->cat_arr_id ?? '';
  2896. $cityid = $job->city_arr_id ?? '';
  2897. $city = json_decode($cityid, true);
  2898. $pinyin = '';
  2899. $level = json_decode($category, true);
  2900. // 路由
  2901. if (!empty($level) && is_array($level)) {
  2902. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2903. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2904. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2905. ->get(['aLIas_pinyin'])
  2906. ->pluck('aLIas_pinyin')
  2907. ->implode('/');
  2908. if (empty($pinyin)) {
  2909. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2910. }
  2911. $job->pinyin = $pinyin;
  2912. }
  2913. // 取职位-城市 市??省
  2914. if (!empty($city) && is_array($city)) {
  2915. if (isset($city[1]) && !empty($city[1])) {
  2916. $city = District::where('id', $city[1])->first(['name']);
  2917. $job->city_name = $city->name ?? '';
  2918. } else if (isset($city[0]) && !empty($city[0])) {
  2919. $city = District::where('id', $city[0])->first(['name']);
  2920. $job->city_name = $city->name ?? '';
  2921. } else {
  2922. $job->city_name = '全国';
  2923. }
  2924. }
  2925. // 获取简历最后一级地区
  2926. if (isset($job->city_id) && !empty($job->city_id)) {
  2927. $city = District::where('id', $job->city_id)->first(['name']);
  2928. $job->hunt_cityname = $city->name ?? '';
  2929. }
  2930. // 组合详细地址
  2931. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2932. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2933. if (is_array($address_id) && !empty($address_id)) {
  2934. $address = District::whereIn('id', $address_id)
  2935. ->orderBy('level', 'asc')
  2936. ->get(['name'])
  2937. ->pluck('name')
  2938. ->implode('');
  2939. // $job->address_name = $address ?? '';
  2940. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2941. }
  2942. }
  2943. // 取行业
  2944. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2945. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2946. if (!empty($job->industry)) {
  2947. $query->where('hyid', $job->industry);
  2948. } else if (!empty($job->hy_id)) {
  2949. $query->where('hyid', $job->hy_id);
  2950. } else if (!empty($job->company_hy_id)) {
  2951. $query->where('hyid', $job->company_hy_id);
  2952. } else {
  2953. $query->where('hyid', $job->job_industry);
  2954. }
  2955. })->first(['hyname']);
  2956. $job->hy_name = $hy_name->hyname ?? '';
  2957. }
  2958. // 取职位类别
  2959. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2960. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2961. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2962. $job->zw_name = $zw_name->zwname ?? '';
  2963. }
  2964. // 取具体职位
  2965. 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))) {
  2966. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2967. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2968. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2969. }
  2970. // 取工作经验
  2971. if (isset($job->experience) && !empty($job->experience)) {
  2972. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2973. $job->experience_name = $experience->ename ?? '';
  2974. }
  2975. // 取学历
  2976. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2977. $education = $job->educational ?? $job->school_education;
  2978. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2979. $job->education_name = $education->ename ?? '';
  2980. }
  2981. // 语言
  2982. if (isset($job->language) && !empty($job->language)) {
  2983. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2984. $job->language_name = $language->ename ?? '';
  2985. }
  2986. // 薪资
  2987. if (isset($job->salary) && !empty($job->salary)) {
  2988. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2989. $job->salary_name = $salary->ename ?? '';
  2990. }
  2991. // 职位性质
  2992. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2993. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2994. $job->job_nature_name = $job_nature->ename ?? '';
  2995. }
  2996. // 公司规模
  2997. if (isset($job->company_size) && !empty($job->company_size)) {
  2998. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2999. $job->company_size_name = $company_size->ename ?? '';
  3000. }
  3001. // 公司性质
  3002. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3003. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3004. $job->company_nature_name = $company_nature->nature_name ?? '';
  3005. }
  3006. // $job->pinyin = $pinyin;
  3007. return $job;
  3008. });
  3009. }
  3010. /**
  3011. * 获取书籍模块
  3012. * @param array $data
  3013. * @return array
  3014. * */
  3015. public function getWebsiteBook(array $data): array
  3016. {
  3017. $input['id'] = $data['id'];
  3018. $input['website_id'] = $data['website_id'];
  3019. // 将 JSON 字符串转换为 PHP 数组
  3020. $data = json_decode($input['id'], true);
  3021. // 使用 array_map 处理每个元素
  3022. $result = array_map(function ($item) use ($input) {
  3023. // 检查parent元素是否存在且不是undefined
  3024. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3025. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3026. $website = [
  3027. 'website_id' => $input['website_id'],
  3028. ];
  3029. // 查询栏目名称
  3030. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3031. if (empty($category)) {
  3032. $parent_alias = '';
  3033. $parent_pinyin = null;
  3034. $imgBooks = [];
  3035. $textBooks = [];
  3036. } else {
  3037. $parent_alias = $category->alias ?? '';
  3038. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3039. // 查找子分类ID数组
  3040. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3041. array_push($childCategoryIds, $parentCatId);
  3042. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3043. if ($parentImgNum != 0) {
  3044. // 查询图片新闻
  3045. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3046. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3047. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3048. })
  3049. ->where('book.status', 2)
  3050. ->where('book.img_url', '!=', '')
  3051. ->where('book.website_id', $website['website_id'])
  3052. ->leftJoin('website_category', function ($join) use ($website) {
  3053. $join->on('book.cat_id', '=', 'website_category.category_id')
  3054. ->where('website_category.website_id', '=', $website['website_id']);
  3055. })
  3056. ->select(
  3057. 'book.id',
  3058. 'book.title',
  3059. 'book.img_url',
  3060. 'book.price',
  3061. 'book.market_price',
  3062. 'book.description',
  3063. 'book.cat_id',
  3064. 'book.description',
  3065. 'book.updated_at',
  3066. 'website_category.alias as category_name',
  3067. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3068. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3069. )
  3070. ->orderBy('updated_at', 'desc')
  3071. ->limit($parentImgNum)
  3072. ->get()->all();
  3073. // 查询文字新闻
  3074. }
  3075. if ($parentTextNum != 0) {
  3076. $textBooks = [];
  3077. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3078. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3079. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3080. })
  3081. ->where('book.status', 2)
  3082. ->where('book.website_id', $website['website_id'])
  3083. ->leftJoin('website_category', function ($join) use ($website) {
  3084. $join->on('book.cat_id', '=', 'website_category.category_id')
  3085. ->where('website_category.website_id', '=', $website['website_id']);
  3086. })
  3087. ->select(
  3088. 'book.id',
  3089. 'book.title',
  3090. 'book.img_url',
  3091. 'book.price',
  3092. 'book.market_price',
  3093. 'book.description',
  3094. 'book.cat_id',
  3095. 'book.description',
  3096. 'book.updated_at',
  3097. 'website_category.alias as category_name',
  3098. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3099. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3100. )
  3101. ->orderBy('updated_at', 'desc')
  3102. ->limit($parentTextNum)
  3103. ->get()->all();
  3104. }
  3105. }
  3106. }
  3107. $resultItem = [
  3108. 'alias' => $parent_alias ?? '',
  3109. 'category_id' => $parentCatId ?? 0,
  3110. 'pinyin' => $parent_pinyin ?? null,
  3111. 'imgnum' => $imgBooks ?? [],
  3112. 'textnum' => $textBooks ?? [],
  3113. ];
  3114. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3115. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3116. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3117. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3118. ->get()->all();
  3119. if (!empty($childCategory)) {
  3120. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3121. // 查询子栏目名称
  3122. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3123. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3124. ->first();
  3125. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3126. $childImgArticles = [];
  3127. $childTextArticles = [];
  3128. $resultItem['child'] = [];
  3129. } else {
  3130. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3131. // 查询子栏目图片新闻
  3132. $childImgArticles = Book::where('cat_id', $childCatId)
  3133. ->where('status', 2)
  3134. ->where('img_url', '!=', '')
  3135. ->where('book.website_id', $website['website_id'])
  3136. ->leftJoin('website_category', function ($join) use ($website) {
  3137. $join->on('book.cat_id', '=', 'website_category.category_id')
  3138. ->where('website_category.website_id', '=', $website['website_id']);
  3139. })
  3140. ->select(
  3141. 'book.id',
  3142. 'book.title',
  3143. 'book.img_url',
  3144. 'book.price',
  3145. 'book.market_price',
  3146. 'book.description',
  3147. 'book.cat_id',
  3148. 'book.description',
  3149. 'book.updated_at',
  3150. DB::raw("'$child_pinyin' as pinyin")
  3151. )
  3152. ->orderBy('updated_at', 'desc')
  3153. ->limit($childImgNum)
  3154. ->get()->all();
  3155. // 查询子栏目文字新闻
  3156. $childTextArticles = Book::where('cat_id', $childCatId)
  3157. ->where('status', 2)
  3158. ->where('book.website_id', $website['website_id'])
  3159. ->leftJoin('website_category', function ($join) use ($website) {
  3160. $join->on('book.cat_id', '=', 'website_category.category_id')
  3161. ->where('website_category.website_id', '=', $website['website_id']);
  3162. })
  3163. ->select(
  3164. 'book.id',
  3165. 'book.title',
  3166. 'book.img_url',
  3167. 'book.price',
  3168. 'book.market_price',
  3169. 'book.description',
  3170. 'book.cat_id',
  3171. 'book.description',
  3172. 'book.updated_at',
  3173. DB::raw("'$child_pinyin' as pinyin")
  3174. )
  3175. ->orderBy('updated_at', 'desc')
  3176. ->limit($childTextNum)
  3177. ->get()->all();
  3178. $resultItem['child'] = [
  3179. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3180. 'category_id' => $childCatId,
  3181. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3182. 'all_childcat' => $childCategory,
  3183. 'imgnum' => $childImgArticles,
  3184. 'textnum' => $childTextArticles,
  3185. ];
  3186. }
  3187. }
  3188. } else {
  3189. $resultItem['child'] = [];
  3190. }
  3191. return $resultItem;
  3192. }, $data);
  3193. return Result::success($result);
  3194. }
  3195. /**
  3196. * 获取书刊列表
  3197. * @param array $data
  3198. * @return array
  3199. * */
  3200. public function getWebsiteBookList(array $data): array
  3201. {
  3202. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3203. if (empty($web)) {
  3204. return Result::error("查询失败", 0);
  3205. }
  3206. $catid = $data['id'];
  3207. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3208. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3209. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3210. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3211. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3212. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3213. ->where('pid', $category['pid'])
  3214. ->select(
  3215. 'category_id',
  3216. 'alias',
  3217. 'aLIas_pinyin',
  3218. 'pid',
  3219. 'sort',
  3220. 'is_url',
  3221. 'web_url',
  3222. 'seo_title',
  3223. 'seo_keywords',
  3224. 'seo_description',
  3225. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3226. )
  3227. ->orderBy('sort')
  3228. ->get()->all();
  3229. if (empty($category)) {
  3230. return Result::error("查询失败", 0);
  3231. }
  3232. $query = Book::where('book.status', 2)
  3233. ->where('book.website_id', $data['website_id'])
  3234. ->where('book.cat_id', $catid)
  3235. ->select(
  3236. 'book.id',
  3237. 'book.title',
  3238. 'book.img_url',
  3239. 'book.description',
  3240. 'book.updated_at',
  3241. 'book.cat_id',
  3242. DB::raw("'$pinyin' as pinyin")
  3243. )
  3244. ->orderBy('book.updated_at', 'desc');
  3245. $count = $query->count();
  3246. $query = clone $query;
  3247. $Book = $query
  3248. ->limit($data['pageSize'])
  3249. ->offset(($data['page'] - 1) * $data['pageSize'])
  3250. ->get()->all();
  3251. $result = [
  3252. 'category' => $categorys,
  3253. 'books' => $Book,
  3254. 'count' => $count,
  3255. ];
  3256. // if(empty($result)){
  3257. // return Result::error("查询失败", 0);
  3258. // }
  3259. return Result::success($result);
  3260. }
  3261. /**
  3262. * 获取书刊详情
  3263. * @param array $data
  3264. * @return array
  3265. * */
  3266. public function getWebsiteBookInfo(array $data): array
  3267. {
  3268. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3269. if (empty($web)) {
  3270. return Result::error("查询失败", 0);
  3271. }
  3272. $book = Book::where('status', 2)
  3273. ->where('website_id', $data['website_id'])
  3274. ->where('id', $data['id'])
  3275. ->select(
  3276. 'book.*',
  3277. )
  3278. ->orderBy('updated_at', 'desc')
  3279. ->first();
  3280. if (empty($book)) {
  3281. return Result::error("查询失败", 0);
  3282. }
  3283. // 先查询当前分类的 pid
  3284. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3285. ->where('category_id', $book['cat_id'])
  3286. ->first(['pid', 'category_id']);
  3287. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3288. if (!empty($carpid)) {
  3289. if ($carpid->pid != 0) {
  3290. $pid = $carpid['pid'];
  3291. // $parent_pinyin = '';
  3292. } else {
  3293. $pid = $carpid['category_id'];
  3294. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3295. }
  3296. }
  3297. $categorys = $query->where('pid', $pid)
  3298. ->select(
  3299. 'category_id',
  3300. 'alias',
  3301. 'aLIas_pinyin',
  3302. 'pid',
  3303. 'sort',
  3304. 'is_url',
  3305. 'web_url',
  3306. 'category_arr_id as cat_arr_id',
  3307. )
  3308. ->orderBy('sort')
  3309. ->get();
  3310. $category = $this->processArticle($categorys, $data);
  3311. $result = [
  3312. 'category' => $category,
  3313. 'books' => $book,
  3314. ];
  3315. return Result::success($result);
  3316. }
  3317. /**
  3318. * 尝试
  3319. * @param array $data
  3320. * @return array
  3321. * */
  3322. public function test(array $data): array
  3323. {
  3324. $input['id'] = $data['id'];
  3325. $input['website_id'] = $data['website_id'];
  3326. // 将 JSON 字符串转换为 PHP 数组
  3327. $data = json_decode($input['id'], true);
  3328. $result = [];
  3329. $article = $data;
  3330. $result = array_map(function ($item) use ($input) {
  3331. $website = [
  3332. 'website_id' => $input['website_id'],
  3333. ];
  3334. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3335. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3336. $parent = [
  3337. 0 => $category['category_id'] ?? [],
  3338. 1 => $parentImgNum ?? [],
  3339. 2 => $parentTextNum ?? [],
  3340. ];
  3341. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3342. $child = [];
  3343. $resultItem = [
  3344. // 'alias' => $parent_alias ?? '',
  3345. 'category_id' => $parentCatId ?? 0,
  3346. 'pinyin' => $parentImgNum ?? null,
  3347. 'imgnum' => $parentTextNum ?? [],
  3348. // 'textnum' => $textArticles ?? [],
  3349. ];
  3350. return $parent;
  3351. }, $data);
  3352. return Result::success($result);
  3353. // });
  3354. }
  3355. /**
  3356. * 封装处理文章的路由问题
  3357. * */
  3358. function processArticle($article, $data)
  3359. {
  3360. return $article->map(function ($article) use ($data) {
  3361. $catid = $article->cat_arr_id ?? '';
  3362. $level = json_decode($catid, true);
  3363. $pinyin = '';
  3364. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3365. if (!empty($level) && is_array($level)) {
  3366. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3367. ->where('website_id', $data['website_id'])
  3368. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3369. ->get(['aLIas_pinyin'])
  3370. ->pluck('aLIas_pinyin')
  3371. ->implode('/');
  3372. } else {
  3373. $pinyin = '';
  3374. }
  3375. $article->pinyin = $pinyin;
  3376. return $article;
  3377. });
  3378. }
  3379. /**
  3380. * c端-获取招工招聘下拉选框
  3381. * @param array $data
  3382. * @return array
  3383. * */
  3384. public function getWebsiteJobSelect(array $data): array
  3385. {
  3386. $web = Website::where('id', $data['website_id'])->first();
  3387. if (empty($web)) {
  3388. return Result::error("该网站不存在", 0);
  3389. }
  3390. $hy = JobIndustry::get()->all();
  3391. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3392. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3393. $result = [
  3394. 'hy' => $hy,
  3395. 'zw' => $zw,
  3396. 'jtzw' => $jtzw,
  3397. ];
  3398. if (empty($result)) {
  3399. return Result::error("查询失败", 0);
  3400. }
  3401. return Result::success($result);
  3402. }
  3403. /**
  3404. * c端-获取招工招聘
  3405. * @param array $data
  3406. * @return array
  3407. * */
  3408. public function getWebsiteJob(array $data): array
  3409. {
  3410. $web = Website::where('id', $data['website_id'])->first();
  3411. if (empty($web)) {
  3412. return Result::error("该网站不存在", 0);
  3413. }
  3414. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3415. ->where('job_hunting.website_id', $data['website_id'])
  3416. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3417. $query->where(function ($q) use ($data) {
  3418. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3419. });
  3420. })
  3421. ->select(
  3422. 'job_hunting.id',
  3423. 'job_hunting.catid',
  3424. 'job_hunting.cat_arr_id',
  3425. 'job_hunting.job_name_get',
  3426. 'job_hunting.industry',
  3427. 'job_hunting.name',
  3428. 'job_hunting.sexy',
  3429. 'job_hunting.origin',
  3430. 'job_hunting.city_arr_id',
  3431. 'job_hunting.experience',
  3432. 'job_hunting.updated_at',
  3433. 'job_hunting.salary',
  3434. 'job_hunting.skillList',
  3435. 'job_hunting.slelf_evaluation',
  3436. )
  3437. ->orderBy('updated_at', 'desc')
  3438. ->limit($data['job1_num'])
  3439. ->get();
  3440. $web['website_id'] = $data['website_id'];
  3441. if (empty($job_hunting)) {
  3442. $job_huntings = "未查询到相关简历信息";
  3443. } else {
  3444. $job_huntings = $this->processJob($job_hunting, $web);
  3445. }
  3446. // 0:待审核 1:已通过 2:已拒绝
  3447. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3448. ->where('job_recruiting.website_id', $data['website_id'])
  3449. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3450. $query->where(function ($q) use ($data) {
  3451. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3452. });
  3453. })
  3454. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3455. ->select(
  3456. 'job_recruiting.id',
  3457. 'job_recruiting.catid',
  3458. 'job_recruiting.cat_arr_id',
  3459. 'job_recruiting.title',
  3460. 'job_recruiting.jtzw_id',
  3461. 'job_recruiting.hy_id',
  3462. 'job_recruiting.city_arr_id',
  3463. 'job_recruiting.due_data',
  3464. 'job_recruiting.updated_at',
  3465. 'job_recruiting.experience',
  3466. 'job_recruiting.educational',
  3467. 'job_recruiting.salary',
  3468. 'job_recruiting.zw_id',
  3469. 'job_company.business_name',
  3470. 'job_recruiting.keyword',
  3471. 'job_recruiting.description',
  3472. )
  3473. ->orderBy('updated_at', 'desc')
  3474. ->limit($data['job2_num'])
  3475. ->get();
  3476. if (empty($job_recruiting->toArray())) {
  3477. $job_recruitings = "未查询到相关职位信息";
  3478. } else {
  3479. $job_recruitings = $this->processJob($job_recruiting, $web);
  3480. }
  3481. $result = [
  3482. 'job_hunting' => $job_huntings,
  3483. 'job_recuiting' => $job_recruitings,
  3484. ];
  3485. return Result::success($result);
  3486. }
  3487. /**
  3488. * c端-获取招工招聘列表
  3489. * @param array $data
  3490. * @return array
  3491. * */
  3492. public function getWebsiteJobList(array $data): array
  3493. {
  3494. $recruit_where = [];
  3495. $hunt_where = [];
  3496. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3497. if (empty($web)) {
  3498. return Result::error("此网站不存在", 0);
  3499. }
  3500. $website_id['website_id'] = $data['website_id'];
  3501. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3502. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3503. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3504. }
  3505. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3506. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3507. }
  3508. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3509. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3510. }
  3511. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3512. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3513. }
  3514. $query = JobRecruiting::where('job_recruiting.status', 1)
  3515. ->where('job_recruiting.website_id', $data['website_id'])
  3516. ->where($recruit_where)
  3517. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3518. $query->where(function ($q) use ($data) {
  3519. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3520. });
  3521. })
  3522. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3523. $query->where(function ($q) use ($data) {
  3524. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3525. });
  3526. })
  3527. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3528. ->select(
  3529. 'job_recruiting.id',
  3530. 'job_recruiting.catid',
  3531. 'job_recruiting.hy_id',
  3532. 'job_recruiting.title',
  3533. 'job_recruiting.zw_id',
  3534. 'job_recruiting.educational',
  3535. 'job_recruiting.jtzw_id',
  3536. 'job_recruiting.city_arr_id',
  3537. 'job_recruiting.due_data',
  3538. 'job_recruiting.experience',
  3539. 'job_recruiting.cat_arr_id',
  3540. 'job_recruiting.updated_at',
  3541. 'job_company.business_name',
  3542. 'job_recruiting.keyword',
  3543. 'job_recruiting.description',
  3544. )
  3545. ->orderBy('job_recruiting.updated_at', 'desc');
  3546. $recruit_count = $query->count();
  3547. $query = clone $query;
  3548. $JobRecruiting = $query
  3549. ->offset(($data['page'] - 1) * $data['pageSize'])
  3550. ->limit($data['pageSize'])
  3551. ->get();
  3552. if (empty($JobRecruiting)) {
  3553. $JobRecruiting = "暂无相关职位信息";
  3554. } else {
  3555. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3556. }
  3557. }
  3558. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3559. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3560. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3561. }
  3562. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3563. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3564. }
  3565. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3566. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3567. }
  3568. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3569. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3570. }
  3571. $query = JobHunting::where('job_hunting.status', 2)
  3572. ->where('job_hunting.website_id', $data['website_id'])
  3573. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3574. ->where($hunt_where)
  3575. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3576. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3577. // })
  3578. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3579. $query->where(function ($q) use ($data) {
  3580. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3581. });
  3582. })
  3583. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3584. $query->where(function ($q) use ($data) {
  3585. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3586. });
  3587. })
  3588. ->select(
  3589. 'job_hunting.id',
  3590. 'job_hunting.catid',
  3591. 'job_hunting.sexy',
  3592. 'job_hunting.experience',
  3593. 'job_hunting.origin',
  3594. 'job_hunting.industry',
  3595. 'job_hunting.name',
  3596. 'job_hunting.job',
  3597. 'job_hunting.job_name_get',
  3598. 'job_hunting.city_arr_id',
  3599. 'job_hunting.cat_arr_id',
  3600. 'job_hunting.created_at',
  3601. 'job_hunting.updated_at',
  3602. 'job_position.zwname as job_name',
  3603. 'job_hunting.skillList',
  3604. 'job_hunting.slelf_evaluation',
  3605. )
  3606. ->orderBy('job_hunting.updated_at', 'desc');
  3607. $hunt_count = $query->count();
  3608. $query = clone $query;
  3609. $JobHunting = $query
  3610. ->offset(($data['page'] - 1) * $data['pageSize'])
  3611. ->limit($data['pageSize'])
  3612. ->get();
  3613. if (empty($JobHunting)) {
  3614. $JobRecruiting = "暂无相关简历信息";
  3615. } else {
  3616. $JobHunting = $this->processJob($JobHunting, $website_id);
  3617. }
  3618. }
  3619. $result = [
  3620. 'JobRecruiting' => $JobRecruiting ?? [],
  3621. 'recruit_count' => $recruit_count ?? 0,
  3622. 'JobHunting' => $JobHunting ?? [],
  3623. 'hunt_count' => $hunt_count ?? 0,
  3624. ];
  3625. return Result::success($result);
  3626. }
  3627. /**
  3628. * c端-获取招工招聘详情
  3629. * @param array $data
  3630. * @return array
  3631. * */
  3632. public function getWebsiteJobInfo(array $data): array
  3633. {
  3634. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3635. if (empty($web)) {
  3636. return Result::error("该网站不存在", 0);
  3637. }
  3638. $webid = [
  3639. 'website_id' => $data['website_id'],
  3640. ];
  3641. // 职位相关信息
  3642. if ($data['type'] == 1) {
  3643. $query = JobRecruiting::where('status', 1)
  3644. ->where('website_id', $data['website_id'])
  3645. ->select('*');
  3646. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3647. $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();
  3648. if (!empty($company)) {
  3649. $result['company'] = $this->processJob($company, $webid);
  3650. }
  3651. $other_job = JobRecruiting::where('status', 1)
  3652. ->where('website_id', $data['website_id'])
  3653. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3654. ->where('id', '!=', $data['id'])
  3655. ->where('user_id', '=', $job[0]['user_id'])
  3656. ->limit($data['pageSize'])
  3657. ->get();
  3658. if (!empty($other_job)) {
  3659. $result['other_job'] = $this->processJob($other_job, $webid);
  3660. }
  3661. } else {
  3662. // 简历相关信息
  3663. $job = JobHunting::where('job_hunting.status', 2)
  3664. ->where('job_hunting.website_id', $data['website_id'])
  3665. ->where('job_hunting.id', $data['id'])
  3666. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3667. ->select('job_hunting.*', 'user_name')
  3668. ->get();
  3669. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3670. if (!empty($resume->toArray())) {
  3671. $result['resume'] = 1;
  3672. } else {
  3673. $result['resume'] = 0;
  3674. }
  3675. }
  3676. if (empty($job->toArray())) {
  3677. return Result::error("id参数错误", 0);
  3678. }
  3679. if (!empty($job[0]['job_experience'])) {
  3680. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3681. if (!empty($job_experience)) {
  3682. // $hy = [];
  3683. foreach ($job_experience as $key => $value) {
  3684. // $id = $value['id'];
  3685. $hy[$key] = $value['job_industry'];
  3686. $zw_id[$key] = $value['job_typename'];
  3687. $jtzw_id[$key] = $value['job_name'];
  3688. }
  3689. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3690. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3691. // 先将关联表转换为索引数组,提高查找效率
  3692. $hyLookup = [];
  3693. foreach ($hy_table as $item) {
  3694. $hyLookup[$item['hyid']] = $item['hyname'];
  3695. }
  3696. $zwLookup = [];
  3697. foreach ($zw_table as $item) {
  3698. $zwLookup[$item['zwid']] = $item['zwname'];
  3699. }
  3700. foreach ($job_experience as $key => &$value) {
  3701. // 处理行业名称
  3702. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3703. $value['hy_name'] = $hyLookup[$hy[$key]];
  3704. }
  3705. // 处理职位名称
  3706. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3707. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3708. }
  3709. // 处理具体职位名称
  3710. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3711. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3712. }
  3713. }
  3714. // 释放引用,防止意外修改后续代码
  3715. unset($value);
  3716. }
  3717. $result['job_experience'] = $job_experience ?? [];
  3718. }
  3719. if (!empty($job[0]['education_experience'])) {
  3720. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3721. if (!empty($education_experience)) {
  3722. foreach ($education_experience as $key => $value) {
  3723. // $id = $value['id'];
  3724. $education[$key] = $value['school_education'];
  3725. }
  3726. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3727. // // 先将关联表转换为索引数组,提高查找效率
  3728. $educationLookup = [];
  3729. foreach ($education_table as $item) {
  3730. $educationLookup[$item['evalue']] = $item['ename'];
  3731. }
  3732. foreach ($education_experience as $key => &$value) {
  3733. // 处理学历名称
  3734. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3735. $value['education_name'] = $educationLookup[$education[$key]];
  3736. }
  3737. }
  3738. }
  3739. $result['education_experience'] = $job_experience ?? [];
  3740. }
  3741. $result['job'] = $this->processJob($job, $webid);
  3742. // // 返现对应的栏目
  3743. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3744. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3745. ->whereIn('category_id', $catid)
  3746. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3747. ->orderBy('pid')->get()->all();
  3748. if (!empty($category)) {
  3749. $result['category'] = $category;
  3750. }
  3751. $result['job'] = $job;
  3752. $result['job_experience'] = $job_experience ?? [];
  3753. $result['education_experience'] = $education_experience ?? [];
  3754. if (empty($result)) {
  3755. return Result::error("参数错误", 0);
  3756. }
  3757. return Result::success($result);
  3758. }
  3759. /**
  3760. * c端-申请职位
  3761. * @param array $data
  3762. * @return array
  3763. * */
  3764. public function getWebsiteJobApply(array $data): array
  3765. {
  3766. // 首先验证网站是否存在
  3767. // return Result::success($data);
  3768. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3769. if (empty($web)) {
  3770. return Result::error("该网站不存在", 0);
  3771. }
  3772. // 验证用户是否存在且为个人会员/管理员
  3773. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3774. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3775. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3776. return Result::error("用户不存在", 0);
  3777. }
  3778. // 去除重复元素和空元素,并保持原始顺序
  3779. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3780. return !empty($value);
  3781. }));
  3782. // 验证职位是否存在 1:审核通过
  3783. $recruiting = JobRecruiting::where('status', 1)
  3784. ->where('website_id', $data['website_id'])
  3785. ->whereIn('id', $data['recruit_id'])
  3786. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3787. if (empty($recruiting)) {
  3788. return Result::error("该职位不存在", 0);
  3789. }
  3790. // 简历是否存在
  3791. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3792. if (empty($hunt_id)) {
  3793. return Result::error("该简历不存在", 0);
  3794. }
  3795. $data['hunt_id'] = $hunt_id['hunt_id'];
  3796. // // 验证是否已投递过该职位
  3797. $apply = JobApply::where('user_id', $data['user_id'])
  3798. ->where('hunt_id', $data['hunt_id'])
  3799. ->where('website_id', $data['website_id'])
  3800. ->whereIn('recruit_id', $data['recruit_id'])
  3801. ->get(['recruit_id']);
  3802. if (!empty($apply->toArray())) {
  3803. return Result::error("您已投递过该职位!");
  3804. }
  3805. $insertData = array_map(function ($recruiting) use ($data) {
  3806. return [
  3807. 'user_id' => $data['user_id'],
  3808. 'hunt_id' => $data['hunt_id'],
  3809. 'website_id' => $data['website_id'],
  3810. 'recruit_id' => $recruiting['recruit_id'],
  3811. 'receiver_id' => $recruiting['receiver_id'],
  3812. 'status' => 1,
  3813. ];
  3814. }, $recruiting);
  3815. // 批量插入数据
  3816. $result = JobApply::insert($insertData);
  3817. if (empty($result)) {
  3818. return Result::error("投递失败", 0);
  3819. }
  3820. return Result::success($result);
  3821. }
  3822. /**
  3823. * 招工招聘-沟通简历
  3824. * @param array $data
  3825. * @return array
  3826. * */
  3827. public function getWebsiteJobResume(array $data): array
  3828. {
  3829. // 首先验证网站是否存在
  3830. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3831. if (empty($web)) {
  3832. return Result::error("该网站不存在", 0);
  3833. }
  3834. // return Result::success($data);
  3835. // 验证用户是否存在且为企业会员/管理员
  3836. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3837. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3838. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3839. return Result::error("用户不存在", 0);
  3840. }
  3841. // 去除重复元素和空元素,并保持原始顺序
  3842. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3843. return !empty($value);
  3844. }));
  3845. // 验证简历是否存在
  3846. $hunting = JobHunting::where('status', 2)
  3847. ->where('website_id', $data['website_id'])
  3848. ->whereIn('id', $data['hunt_id'])
  3849. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3850. if (empty($hunting)) {
  3851. return Result::error("该简历不存在", 0);
  3852. }
  3853. // 验证是否已沟通过该简历
  3854. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3855. ->where('recruit_id', $data['recruit_id'])
  3856. ->where('website_id', $data['website_id'])
  3857. ->whereIn('hunt_id', $data['hunt_id'])
  3858. ->get(['hunt_id']);
  3859. if (!empty($remuse->toArray())) {
  3860. return Result::error("您已沟通过该简历!");
  3861. }
  3862. // 准备要插入的数据数组
  3863. $insertData = array_map(function ($hunting) use ($data) {
  3864. return [
  3865. 'user_id' => $data['user_id'],
  3866. 'recruit_id' => $data['recruit_id'],
  3867. 'website_id' => $data['website_id'],
  3868. 'hunt_id' => $hunting['hunt_id'],
  3869. 'receiver_id' => $hunting['receiver_id'],
  3870. 'status' => 1,
  3871. ];
  3872. }, $hunting);
  3873. // 批量插入数据
  3874. $result = JobRemuse::insert($insertData);
  3875. if (empty($result)) {
  3876. return Result::error("沟通失败", 0);
  3877. }
  3878. return Result::success($result);
  3879. }
  3880. /**
  3881. * 招工招聘 -我的职位(企业会员)
  3882. * @param array $data
  3883. * @return array
  3884. */
  3885. public function getWebsiteJobRecruiting(array $data): array
  3886. {
  3887. $web = Website::where('id', $data['website_id'])->first('id');
  3888. if (empty($web)) {
  3889. return Result::error("该网站不存在", 0);
  3890. }
  3891. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3892. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3893. return Result::error("用户暂无权限!", 0);
  3894. }
  3895. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3896. $result = JobRecruiting::where('website_id', $data['website_id'])
  3897. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3898. $query->where('user_id', $user['id']);
  3899. })
  3900. ->where('status', 1)
  3901. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3902. ->orderBy('updated_at', 'desc')
  3903. ->limit($data['pageSize'])
  3904. ->get();
  3905. if (empty($result)) {
  3906. return Result::error("暂无相关职位信息", 0);
  3907. }
  3908. return Result::success($result);
  3909. }
  3910. /**
  3911. * c端 - 验证路由
  3912. * @param array $data
  3913. * @return array
  3914. */
  3915. /**
  3916. * c端 - 验证路由
  3917. * @param array $data
  3918. * @return array
  3919. */
  3920. public function checkWebsiteRoute(array $data): array
  3921. {
  3922. // 测试001111111222
  3923. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3924. if (empty($web)) {
  3925. return Result::error("该网站不存在", 0);
  3926. } elseif ($web['status'] != 1) {
  3927. return Result::error("网站已经关闭", 0);
  3928. }
  3929. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3930. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3931. // 验证路由是否存在
  3932. if (empty($whiteRouterInfo)) {
  3933. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3934. }
  3935. if (!empty($whiteRouterInfo)) {
  3936. return Result::success($whiteRouterInfo->toArray());
  3937. }
  3938. }
  3939. // 验证栏目路由
  3940. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3941. ->where('path', $data['all_route'])
  3942. ->get()->all();
  3943. if (count($last_category) == 0) {
  3944. return Result::error("该栏目不存在", 0);
  3945. }
  3946. if (count($last_category) > 1) {
  3947. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3948. }
  3949. if (count($last_category) == 1) {
  3950. $last_category = $last_category[0];
  3951. }
  3952. // return Result::success($last_category);
  3953. if (isset($data['id']) && !empty($data['id'])) {
  3954. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3955. switch ($last_category['type']) {
  3956. case 1:
  3957. // 文章
  3958. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3959. $article = Article::where('status', 1)
  3960. ->where('id', $data['id'])
  3961. ->where(function ($query) use ($data) {
  3962. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3963. ->orWhereNull("ignore_ids");
  3964. })
  3965. ->first(['catid']);
  3966. if (empty($article)) {
  3967. return Result::error("该文章不存在", 0);
  3968. }
  3969. // return Result::success($article);
  3970. break;
  3971. case 2:
  3972. // 商品
  3973. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3974. $article = Good::where('website_id', $data['website_id'])
  3975. ->where('status', 2)
  3976. ->where('id', $data['id'])
  3977. ->first(['cat_arr_id']);
  3978. if (empty($article)) {
  3979. return Result::error("该商品不存在", 0);
  3980. }
  3981. break;
  3982. case 3:
  3983. // 书刊信息
  3984. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3985. $article = Book::where('website_id', $data['website_id'])
  3986. ->where('status', 2)
  3987. ->where('id', $data['id'])
  3988. ->first(['id', 'cat_arr_id']);
  3989. if (empty($article)) {
  3990. return Result::error("该书刊不存在", 0);
  3991. }
  3992. break;
  3993. case 4:
  3994. // 招聘
  3995. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3996. $article = JobRecruiting::where('website_id', $data['website_id'])
  3997. ->where('status', 1)
  3998. ->where('id', $data['id'])
  3999. ->first(['cat_arr_id']);
  4000. if (empty($article)) {
  4001. return Result::error("该招聘不存在", 0);
  4002. }
  4003. break;
  4004. case 5:
  4005. // 求职
  4006. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4007. $article = JobHunting::where('website_id', $data['website_id'])
  4008. ->where('status', 2)
  4009. ->where('id', $data['id'])
  4010. ->first(['cat_arr_id']);
  4011. if (empty($article)) {
  4012. return Result::error("该求职不存在", 0);
  4013. }
  4014. break;
  4015. case 6:
  4016. // 企业
  4017. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4018. $article = Company::
  4019. // where('website_id', $data['website_id'])
  4020. // ->
  4021. where('status', 1)
  4022. ->where('id', $data['id'])
  4023. ->first(['cat_arr_id']);
  4024. if (empty($article)) {
  4025. return Result::error("该企业不存在", 0);
  4026. }
  4027. break;
  4028. case 7:
  4029. // 项目
  4030. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4031. $article = Project::where('website_id', $data['website_id'])
  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. default:
  4040. return Result::error("该数据不存在", 0);
  4041. break;
  4042. }
  4043. // return Result::success($article);
  4044. // $catid =0 ;
  4045. if (!isset($article['cat_arr_id'])) {
  4046. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4047. } else {
  4048. $catidArray = json_decode($article['cat_arr_id'], true);
  4049. $catid = !empty($catidArray) ? end($catidArray) : null;
  4050. }
  4051. // return Result::success($catid);
  4052. // // return Result::success($article['cat_arr_id']);
  4053. if (empty($catid)) {
  4054. return Result::error("该栏目路径不存在", 0);
  4055. }
  4056. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4057. ->where('category_id', $catid)
  4058. ->first('path');
  4059. }
  4060. // else{
  4061. // // if ($last_category['pid'] != 0) {
  4062. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4063. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4064. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4065. // ->where('category_id',$catid)
  4066. // ->where('path',$data['all_route'])
  4067. // ->first('path');
  4068. // // } else {
  4069. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4070. // // }
  4071. // }
  4072. // return Result::success($path);
  4073. if (!empty($path) && $path['path'] != $data['all_route']) {
  4074. return Result::error('非法路径!');
  4075. } else {
  4076. return Result::success($last_category['path']);
  4077. }
  4078. }
  4079. /**
  4080. * 招工招聘 - 获取推荐职位
  4081. * @param array $data
  4082. * @return array
  4083. */
  4084. public function getWebsiteLevelJob(array $data): array
  4085. {
  4086. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4087. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4088. ->where('job_recruiting.status', 1)
  4089. ->where('job_level', $data['job_level'])
  4090. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4091. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4092. ->orderBy('job_recruiting.updated_at', 'desc')
  4093. ->limit($data['pageSize'])
  4094. ->get();
  4095. $web = ['website_id' => $data['website_id']];
  4096. if (!empty($job)) {
  4097. $result = $this->processJob($job, $web);
  4098. }
  4099. if (empty($result)) {
  4100. return Result::error("暂无相关职位信息", 0);
  4101. }
  4102. return Result::success($result);
  4103. }
  4104. /**
  4105. * 验证导航名称是否重复
  4106. * @return void
  4107. */
  4108. //20250226 产品列表
  4109. public function getGoodList(array $data): array
  4110. {
  4111. var_dump($data, '---------1-2--');
  4112. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4113. unset($data['user_type_id']);
  4114. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4115. $where = [];
  4116. if ($type_id != '10000') {
  4117. $where = [
  4118. 'good.user_id' => $user_id,
  4119. ];
  4120. }
  4121. //类型
  4122. if (isset($data['type_id']) && $data['type_id']) {
  4123. $where['good.type_id'] = $data['type_id'];
  4124. }
  4125. //名称
  4126. if (isset($data['name']) && $data['name']) {
  4127. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4128. }
  4129. //status
  4130. if (isset($data['status']) && $data['status'] != '') {
  4131. $where['good.status'] = $data['status'];
  4132. }
  4133. //status1
  4134. // if (isset($data['status1']) && $data['status1'] == 1) {
  4135. // $status1 = 1;
  4136. // }
  4137. $where1 = [];
  4138. //website_id
  4139. // if (isset($data['website_id']) && $data['website_id']) {
  4140. // $where1 = [
  4141. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4142. // ];
  4143. // }
  4144. // website_name
  4145. if (isset($data['website_name']) && $data['website_name']) {
  4146. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4147. }
  4148. // catid
  4149. if (isset($data['category_name']) && $data['category_name']) {
  4150. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4151. }
  4152. // $result = Good::where($where)
  4153. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4154. var_dump($where, '---------1---');
  4155. $result = Good::where($where)
  4156. ->when(!empty($where1), function ($query) use ($where1) {
  4157. return $query->where($where1);
  4158. })
  4159. //status 1待审核2已审核3已拒绝
  4160. ->when(isset($data['status1']), function ($query) {
  4161. return $query->whereIn('good.status', [1, 3]);
  4162. })
  4163. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4164. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4165. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4166. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4167. ->orderBy("updated_at", "desc")
  4168. ->limit($data['page_size'])
  4169. ->offset(($data['page'] - 1) * $data['page_size'])
  4170. ->get();
  4171. $count = Good::where($where)
  4172. ->when(!empty($where1), function ($query) use ($where1) {
  4173. return $query->where($where1);
  4174. })
  4175. //status 1待审核2已审核3已拒绝
  4176. ->when(isset($data['status1']), function ($query) {
  4177. return $query->whereIn('good.status', [1, 3]);
  4178. })
  4179. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4180. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4181. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4182. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4183. ->orderBy("updated_at", "desc")->count();
  4184. $data = [
  4185. 'rows' => $result->toArray(),
  4186. 'count' => $count,
  4187. ];
  4188. if (empty($result)) {
  4189. return Result::error("此栏目暂无相关产品", 0);
  4190. }
  4191. return Result::success($data);
  4192. }
  4193. public function getGoodInfo(array $data): array
  4194. {
  4195. $result = Good::where('id', $data['id'])->first();
  4196. if (empty($result)) {
  4197. return Result::error("此产品不存在", 0);
  4198. }
  4199. return Result::success($result);
  4200. }
  4201. public function addGood(array $data): array
  4202. {
  4203. // unset($data['city_arr_id']);
  4204. // unset($data['cat_arr_id']);
  4205. $data['city_id'] = end($data['city_arr_id']);
  4206. $data['catid'] = end($data['cat_arr_id']);
  4207. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4208. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4209. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4210. unset($data['imgUrl']); //大小写
  4211. if (isset($data['price']) && $data['price'] == '') {
  4212. $data['price'] = 0;
  4213. }
  4214. if ($data['imgurl'] == '') {
  4215. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4216. preg_match_all($reg, $data['detail'], $matches);
  4217. if (isset($matches[1][0])) {
  4218. //截取varchar240
  4219. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4220. }
  4221. }
  4222. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4223. //提取标题+内容中的关键词
  4224. $data['keyword'] = $data['name'];
  4225. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4226. Jieba::init(); // 初始化 jieba-php
  4227. Finalseg::init();
  4228. $segList = Jieba::cut($data['keyword']);
  4229. $segList1 = array_slice($segList, 0, 8);
  4230. $data['keyword'] = implode(',', $segList1);
  4231. }
  4232. if ($data['description'] == '') {
  4233. //提取内容中的描述
  4234. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4235. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4236. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4237. }
  4238. if ($data['status'] == 1) {
  4239. $this->sendMessage([
  4240. 'talk_type' => 200,
  4241. 'title' => $data['name'],
  4242. 'content' => '提交了审核',
  4243. 'messageType' => 3,
  4244. ]);
  4245. }
  4246. $result = Good::insert($data);
  4247. if (empty($result)) {
  4248. return Result::error("添加失败", 0);
  4249. }
  4250. return Result::success($result);
  4251. }
  4252. public function updateGood(array $data): array
  4253. {
  4254. $data['city_id'] = end($data['city_arr_id']);
  4255. $data['catid'] = end($data['cat_arr_id']);
  4256. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4257. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4258. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4259. //设置东八区
  4260. date_default_timezone_set('Asia/Shanghai');
  4261. $data['updated_at'] = date('Y-m-d H:i:s');
  4262. if (isset($data['price']) && $data['price'] == '') {
  4263. $data['price'] = 0;
  4264. }
  4265. if ($data['imgurl'] == '') {
  4266. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4267. preg_match_all($reg, $data['detail'], $matches);
  4268. if (isset($matches[1][0])) {
  4269. //截取varchar240
  4270. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4271. }
  4272. }
  4273. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4274. //提取标题+内容中的关键词
  4275. $data['keyword'] = $data['name'];
  4276. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4277. Jieba::init(); // 初始化 jieba-php
  4278. Finalseg::init();
  4279. $segList = Jieba::cut($data['keyword']);
  4280. $segList1 = array_slice($segList, 0, 8);
  4281. $data['keyword'] = implode(',', $segList1);
  4282. }
  4283. if ($data['description'] == '') {
  4284. //提取内容中的描述
  4285. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4286. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4287. }
  4288. if ($data['status'] == 1) {
  4289. $this->sendMessage([
  4290. 'talk_type' => 200,
  4291. 'title' => $data['name'],
  4292. 'content' => '提交了审核',
  4293. 'messageType' => 3,
  4294. ]);
  4295. }
  4296. $result = Good::where('id', $data['id'])->update($data);
  4297. if (empty($result)) {
  4298. return Result::error("更新失败", 0);
  4299. }
  4300. return Result::success($result);
  4301. }
  4302. public function delGood(array $data): array
  4303. {
  4304. $result = Good::where('id', $data['id'])->delete();
  4305. if (empty($result)) {
  4306. return Result::error("删除失败", 0);
  4307. }
  4308. return Result::success($result);
  4309. }
  4310. //20250226 产品列表
  4311. //20250306 求职信息
  4312. public function getJobHuntingList(array $data): array
  4313. {
  4314. $where = [];
  4315. if (isset($data['username']) && !empty($data['username'])) {
  4316. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4317. }
  4318. //status 1待审核2已审核3已拒绝
  4319. if (isset($data['status']) && $data['status'] != '') {
  4320. $where = [
  4321. 'job_hunting.status' => $data['status'],
  4322. ];
  4323. }
  4324. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4325. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4326. unset($data['type_id']);
  4327. if ($type_id != '10000') {
  4328. $where[] = ['job_hunting.user_id', '=', $user_id];
  4329. }
  4330. $result = JobHunting::where($where)
  4331. ->when(!empty($data['status1']), function ($query) use ($data) {
  4332. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4333. })
  4334. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4335. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4336. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4337. ->orderBy("updated_at", "desc")
  4338. ->limit($data['page_size'])
  4339. ->offset(($data['page'] - 1) * $data['page_size'])
  4340. ->get();
  4341. if (empty($result)) {
  4342. return Result::error("查询失败", 0);
  4343. }
  4344. $count = JobHunting::where($where)
  4345. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4346. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4347. ->count();
  4348. $data = [
  4349. 'rows' => $result->toArray(),
  4350. 'count' => $count,
  4351. ];
  4352. return Result::success($data);
  4353. }
  4354. public function getJobHuntingApply(array $data): array
  4355. {
  4356. var_dump($data, '-----------------test--------1-');
  4357. $where = [];
  4358. if (isset($data['username']) && !empty($data['username'])) {
  4359. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4360. }
  4361. if (isset($data['salary']) && !empty($data['salary'])) {
  4362. $where[] = [
  4363. 'job_hunting.salary',
  4364. '=',
  4365. $data['salary'],
  4366. ];
  4367. }
  4368. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4369. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4370. unset($data['type_id']);
  4371. if ($type_id != '10000') {
  4372. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4373. }
  4374. var_dump($where, '-----------------test---------');
  4375. $result = jobApply::where($where)
  4376. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4377. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4378. // })
  4379. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4380. ->where('job_enum.egroup', '=', 'income')
  4381. ->where('job_hunting.status', 2) //已审核
  4382. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4383. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4384. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4385. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4386. //职位----是申请职位
  4387. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4388. ->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')
  4389. ->orderBy("job_hunting.updated_at", "desc")
  4390. ->limit($data['page_size'])
  4391. ->offset(($data['page'] - 1) * $data['page_size'])
  4392. ->get();
  4393. if (empty($result)) {
  4394. return Result::error("查询失败", 0);
  4395. }
  4396. $count = jobApply::where($where)
  4397. ->where('job_enum.egroup', '=', 'income')
  4398. ->where('job_hunting.status', 2) //已审核
  4399. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4400. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4401. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4402. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4403. //职位----是申请职位
  4404. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4405. ->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')
  4406. ->count();
  4407. $data = [
  4408. 'rows' => $result->toArray(),
  4409. 'count' => $count,
  4410. ];
  4411. return Result::success($data);
  4412. }
  4413. public function addJobHunting(array $data): array
  4414. {
  4415. date_default_timezone_set('Asia/Shanghai');
  4416. unset($data['company_name']);
  4417. unset($data['job_industry']);
  4418. unset($data['job_name']);
  4419. unset($data['department']);
  4420. unset($data['job_timeList']);
  4421. unset($data['job_content']);
  4422. unset($data['job_typename']); //不知道这是啥,
  4423. $data['created_at'] = date('Y-m-d H:i:s');
  4424. $data['updated_at'] = date('Y-m-d H:i:s');
  4425. //根据用户 user_id 只能添加一次
  4426. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4427. if (!empty($result)) {
  4428. return Result::error("您已添加过求职信息", 0);
  4429. }
  4430. var_dump($result, '-----------------test---------');
  4431. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4432. if (is_string($data['city_arr_id'])) {
  4433. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4434. $cityArr = json_decode($data['city_arr_id'], true);
  4435. // 确保 $cityArr 是数组
  4436. if (is_array($cityArr)) {
  4437. $data['city_id'] = end($cityArr);
  4438. }
  4439. } else {
  4440. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4441. if (is_array($data['city_arr_id'])) {
  4442. $data['city_id'] = end($data['city_arr_id']);
  4443. }
  4444. }
  4445. }
  4446. // 处理求职所绑定栏目
  4447. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4448. if (is_string($data['cat_arr_id'])) {
  4449. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4450. // 先清理可能存在的无效 JSON 字符
  4451. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4452. $catArr = json_decode($cleanedCatArrStr, true);
  4453. // 检查 JSON 解码是否成功且结果是数组
  4454. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4455. $data['catid'] = end($catArr);
  4456. }
  4457. } else {
  4458. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4459. if (is_array($data['cat_arr_id'])) {
  4460. $data['catid'] = end($data['cat_arr_id']);
  4461. }
  4462. }
  4463. }
  4464. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4465. $this->sendMessage([
  4466. 'talk_type' => 600,
  4467. 'title' => $data['name'],
  4468. 'content' => '提交了审核',
  4469. 'messageType' => 11,
  4470. ]);
  4471. }
  4472. $result = JobHunting::create($data);
  4473. if (empty($result)) {
  4474. return Result::error("添加失败", 0);
  4475. }
  4476. return Result::success($result);
  4477. }
  4478. public function delJobHunting(array $data): array
  4479. {
  4480. $result = JobHunting::where('id', $data['id'])->delete();
  4481. if (empty($result)) {
  4482. return Result::error("删除失败", 0);
  4483. }
  4484. return Result::success($result);
  4485. }
  4486. public function updateJobHunting(array $data): array
  4487. {
  4488. //设置东八区
  4489. date_default_timezone_set('Asia/Shanghai');
  4490. unset($data['company_name']);
  4491. unset($data['job_industry']);
  4492. unset($data['job_name']);
  4493. unset($data['department']);
  4494. unset($data['job_timeList']);
  4495. unset($data['job_content']);
  4496. unset($data['job_typename']); //不知道这是啥,
  4497. $data['created_at'] = date('Y-m-d H:i:s');
  4498. $data['updated_at'] = date('Y-m-d H:i:s');
  4499. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4500. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4501. $cityArr = json_decode($data['city_arr_id'], true);
  4502. $data['city_id'] = end($cityArr);
  4503. } else {
  4504. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4505. $data['city_id'] = end($data['city_arr_id']);
  4506. }
  4507. // 处理求职所绑定栏目
  4508. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4509. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4510. $catArr = json_decode($data['cat_arr_id'], true);
  4511. $data['catid'] = end($catArr);
  4512. } else {
  4513. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4514. $data['catid'] = end($data['cat_arr_id']);
  4515. }
  4516. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4517. $this->sendMessage([
  4518. 'talk_type' => 600,
  4519. 'title' => $data['name'],
  4520. 'content' => '提交了审核',
  4521. 'messageType' => 11,
  4522. ]);
  4523. }
  4524. $result = JobHunting::where('id', $data['id'])->update($data);
  4525. if (empty($result)) {
  4526. return Result::error("更新失败", 0);
  4527. }
  4528. return Result::success($result);
  4529. }
  4530. public function getJobHuntingInfo(array $data): array
  4531. {
  4532. $result = JobHunting::where('id', $data['id'])->first();
  4533. if (empty($result)) {
  4534. return Result::error("查询失败", 0);
  4535. }
  4536. return Result::success($result);
  4537. }
  4538. public function getJobHuntingData(array $data): array
  4539. {
  4540. $jobEnum = JobEnum::get();
  4541. $jobIndustry = JobIndustry::get();
  4542. $jobNature = JobNature::get();
  4543. $jobPosition = JobPosition::get();
  4544. $data = [
  4545. 'jobEnum' => $jobEnum,
  4546. 'jobIndustry' => $jobIndustry,
  4547. 'jobNature' => $jobNature,
  4548. 'jobPosition' => $jobPosition,
  4549. ];
  4550. return Result::success($data);
  4551. }
  4552. public function delJobHuntingInfo(array $data): array
  4553. {
  4554. $result = JobHunting::where('id', $data['id'])->delete();
  4555. return Result::success();
  4556. }
  4557. //20250324 通知,公告,消息
  4558. public function delNotice(array $data): array
  4559. {
  4560. $result = Notice::where('id', $data['id'])->delete();
  4561. if ($result) {
  4562. return Result::success();
  4563. } else {
  4564. return Result::error("删除失败", 0);
  4565. }
  4566. }
  4567. public function getNoticeInfo(array $data): array
  4568. {
  4569. $result = Notice::where('id', $data['id'])->first();
  4570. // var_dump($result['re_user_ids'], '--------------------');
  4571. if (empty($result)) {
  4572. return Result::error("查询失败", 0);
  4573. }
  4574. return Result::success($result);
  4575. }
  4576. public function readNotice(array $data): array
  4577. {
  4578. $result = Notice::where('id', $data['id'])->first();
  4579. // var_dump($result['re_user_ids'], '--------------------');
  4580. if (empty($result)) {
  4581. return Result::error("查询失败", 0);
  4582. }
  4583. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4584. $re_user_ids = json_decode($result['re_user_ids'], true);
  4585. var_dump($re_user_ids, '--------------1---test---------');
  4586. var_dump($data, '--------------1---test---------');
  4587. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4588. //如果已经存在,就不再添加
  4589. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4590. $read_id = json_decode($result['read_id'], true);
  4591. if (!is_array($read_id)) {
  4592. $read_id = [];
  4593. }
  4594. if (!in_array($data['user_id'], $read_id)) {
  4595. $read_id[] = $data['user_id'];
  4596. $result['read_id'] = json_encode($read_id);
  4597. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4598. }
  4599. } else {
  4600. //如果不存在,就添加
  4601. $result['read_id'] = json_encode([$data['user_id']]);
  4602. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4603. }
  4604. }
  4605. return Result::success($result);
  4606. }
  4607. public function addNotice(array $data): array
  4608. {
  4609. date_default_timezone_set('Asia/Shanghai');
  4610. $data['created_at'] = date('Y-m-d H:i:s');
  4611. $data['updated_at'] = date('Y-m-d H:i:s');
  4612. $user_id = UserInfo::
  4613. //city_id不是null
  4614. whereNotNull('city_id')
  4615. ->whereNotNull('department_id')
  4616. ->where(function ($query) use ($data) {
  4617. $query->where(function ($subQuery) use ($data) {
  4618. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4619. });
  4620. })
  4621. ->where(function ($query) use ($data) {
  4622. $query->where(function ($subQuery) use ($data) {
  4623. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4624. });
  4625. })
  4626. ->pluck('user_id')->toArray();
  4627. $user_id = array_unique($user_id);
  4628. $chat_ids = $user_id;
  4629. $user_id = json_encode($user_id);
  4630. $data['re_user_ids'] = $user_id;
  4631. $this->sendMessage([
  4632. 'talk_type' => 700,
  4633. 'title' => $data['title'],
  4634. 'content' => '提交了审核',
  4635. 'messageType' => 5,
  4636. ]);
  4637. $result = Notice::insertGetId($data);
  4638. if (empty($result)) {
  4639. return Result::error("添加失败", 0);
  4640. }
  4641. return Result::success($result);
  4642. }
  4643. public function updateNotice(array $data): array
  4644. {
  4645. date_default_timezone_set('Asia/Shanghai');
  4646. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4647. $user_id = UserInfo::
  4648. //city_id不是null
  4649. whereNotNull('city_id')
  4650. ->whereNotNull('department_id')
  4651. ->where(function ($query) use ($data) {
  4652. $query->where(function ($subQuery) use ($data) {
  4653. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4654. });
  4655. })
  4656. ->where(function ($query) use ($data) {
  4657. $query->where(function ($subQuery) use ($data) {
  4658. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4659. });
  4660. })
  4661. ->pluck('user_id')->toArray();
  4662. $user_id = array_unique($user_id);
  4663. $user_id = json_encode($user_id);
  4664. $data['re_user_ids'] = $user_id;
  4665. $data['updated_at'] = date('Y-m-d H:i:s');
  4666. $this->sendMessage([
  4667. 'talk_type' => 700,
  4668. 'title' => $data['title'],
  4669. 'content' => '提交了审核',
  4670. 'messageType' => 5,
  4671. ]);
  4672. $result = Notice::where('id', $data['id'])->update($data);
  4673. return Result::success($result);
  4674. }
  4675. public function getNoticeList(array $data): array
  4676. {
  4677. $where = [];
  4678. //title
  4679. if (isset($data['title']) && !empty($data['title'])) {
  4680. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4681. }
  4682. //level
  4683. if (isset($data['level']) && !empty($data['level'])) {
  4684. $where[] = ['notice.level', '=', $data['level']];
  4685. }
  4686. //status
  4687. if (isset($data['status']) && !empty($data['status'])) {
  4688. $where[] = ['notice.status', '=', $data['status']];
  4689. }
  4690. //type
  4691. if (isset($data['type']) && !empty($data['type'])) {
  4692. $where[] = ['notice.type', '=', $data['type']];
  4693. }
  4694. var_dump($data, '------------11111-2----test---------');
  4695. if ($data['type_id'] == 10000) {
  4696. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4697. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4698. })
  4699. ->where($where)
  4700. ->orderBy('updated_at', 'desc')
  4701. ->limit($data['page_size'])
  4702. ->offset(($data['page'] - 1) * $data['page_size'])
  4703. ->get();
  4704. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4705. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4706. })
  4707. ->where($where)
  4708. ->orderBy('updated_at', 'desc')
  4709. ->count();
  4710. } else {
  4711. $result = Notice::where($where)
  4712. // ->where('user_id', $data['user_id'])
  4713. ->Where(function ($query) use ($data) {
  4714. $query->Where(function ($q) use ($data) {
  4715. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4716. ->orWhere('notice.user_id', $data['user_id']);
  4717. });
  4718. })
  4719. ->when(!empty($data['status1']), function ($query) use ($data) {
  4720. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4721. })
  4722. ->orderBy('updated_at', 'desc')
  4723. ->limit($data['page_size'])
  4724. ->offset(($data['page'] - 1) * $data['page_size'])
  4725. ->get();
  4726. $total = Notice::where($where)
  4727. ->when(!empty($data['status1']), function ($query) use ($data) {
  4728. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4729. })
  4730. // ->where('user_id', $data['user_id'])
  4731. ->Where(function ($query) use ($data) {
  4732. $query->Where(function ($q) use ($data) {
  4733. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4734. ->orWhere('notice.user_id', $data['user_id']);
  4735. });
  4736. })
  4737. ->count();
  4738. }
  4739. if (empty($result)) {
  4740. return Result::error("查询失败", 0);
  4741. }
  4742. $data = [
  4743. 'rows' => $result,
  4744. 'count' => $total,
  4745. ];
  4746. return Result::success($data);
  4747. }
  4748. public function noticeList(array $data): array
  4749. {
  4750. $where = [];
  4751. //title
  4752. if (isset($data['title']) && !empty($data['title'])) {
  4753. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4754. }
  4755. //level
  4756. if (isset($data['level']) && !empty($data['level'])) {
  4757. $where[] = ['notice.level', '=', $data['level']];
  4758. }
  4759. //status
  4760. if (isset($data['status']) && !empty($data['status'])) {
  4761. $where[] = ['notice.status', '=', $data['status']];
  4762. }
  4763. //type
  4764. if (isset($data['type']) && !empty($data['type'])) {
  4765. $where[] = ['notice.type', '=', $data['type']];
  4766. }
  4767. var_dump($data, '------------11111-2----test---------');
  4768. if ($data['type_id'] == 10000) {
  4769. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4770. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4771. })
  4772. ->where($where)
  4773. ->orderBy('updated_at', 'desc')
  4774. ->limit($data['page_size'])
  4775. ->offset(($data['page'] - 1) * $data['page_size'])
  4776. ->get();
  4777. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4778. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4779. })
  4780. ->where($where)
  4781. ->orderBy('updated_at', 'desc')
  4782. ->count();
  4783. } else {
  4784. $result = Notice::where($where)
  4785. // ->where('user_id', $data['user_id'])
  4786. ->Where(function ($query) use ($data) {
  4787. $query->Where(function ($q) use ($data) {
  4788. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4789. ->orWhere('notice.user_id', $data['user_id']);
  4790. });
  4791. })
  4792. ->when(!empty($data['status1']), function ($query) use ($data) {
  4793. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4794. })
  4795. ->orderBy('updated_at', 'desc')
  4796. ->limit($data['page_size'])
  4797. ->offset(($data['page'] - 1) * $data['page_size'])
  4798. ->get();
  4799. $total = Notice::where($where)
  4800. ->when(!empty($data['status1']), function ($query) use ($data) {
  4801. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4802. })
  4803. // ->where('user_id', $data['user_id'])
  4804. ->Where(function ($query) use ($data) {
  4805. $query->Where(function ($q) use ($data) {
  4806. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4807. ->orWhere('notice.user_id', $data['user_id']);
  4808. });
  4809. })
  4810. ->count();
  4811. }
  4812. if (empty($result)) {
  4813. return Result::error("查询失败", 0);
  4814. }
  4815. $data = [
  4816. 'rows' => $result,
  4817. 'count' => $total,
  4818. ];
  4819. return Result::success($data);
  4820. }
  4821. public function getNoticeDetail(array $data): array
  4822. {
  4823. $result = Notice::where('id', $data['id'])->first();
  4824. if (empty($result)) {
  4825. return Result::error("查询失败", 0);
  4826. }
  4827. return Result::success($result);
  4828. }
  4829. public function deleteNotice(array $data): array
  4830. {
  4831. $notice = Notice::where('id', $data['id'])->first();
  4832. if (empty($notice)) {
  4833. return Result::error("删除失败", 0);
  4834. }
  4835. $chat_group_id = $notice->group_id;
  4836. if ($chat_group_id) {
  4837. //删除群聊
  4838. ChatGroups::where('id', $chat_group_id)->delete();
  4839. //删除群成员
  4840. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4841. //删除群聊记录
  4842. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4843. }
  4844. $result = Notice::where('id', $data['id'])->delete();
  4845. return Result::success($result);
  4846. }
  4847. public function complaintList(array $data): array
  4848. {
  4849. var_dump($data, '---------1---------');
  4850. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4851. unset($data['type_id']);
  4852. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4853. $where = [];
  4854. if ($type_id != 10000 && empty($data['deal_user'])) {
  4855. // $where['complaint.user_id'] = $user_id;
  4856. }
  4857. if (!empty($data['title'])) {
  4858. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4859. }
  4860. if (!empty($data['department_id'])) {
  4861. $where['complaint.department_id'] = $data['department_id'];
  4862. }
  4863. if (!empty($data['deal'])) {
  4864. $where['complaint.deal'] = $data['deal'];
  4865. }
  4866. if (!empty($data['status'])) {
  4867. $where['complaint.status'] = $data['status'];
  4868. }
  4869. var_dump(!empty($data['deal_user']), '----------1');
  4870. var_dump($where, '----------2');
  4871. $result = Complaint::where($where)
  4872. ->when(!empty($data['status1']), function ($query) use ($data) {
  4873. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4874. })
  4875. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4876. //json re_user_ids data[user_id]是不是在里面
  4877. $query->Where(function ($q) use ($data) {
  4878. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4879. ->where('complaint.status', 2);
  4880. });
  4881. })
  4882. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4883. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4884. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4885. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4886. ->orderBy('updated_at', 'desc')
  4887. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4888. //sql输出
  4889. if (empty($result)) {
  4890. return Result::error("暂无投诉信息", 0);
  4891. }
  4892. // 取出数据
  4893. $rows = $result->items();
  4894. $count = $result->total();
  4895. $responseData = [
  4896. 'rows' => $rows,
  4897. 'count' => $count,
  4898. ];
  4899. return Result::success($responseData);
  4900. }
  4901. public function getComplaintList(array $data): array
  4902. {
  4903. var_dump($data, '00000001000000000000');
  4904. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4905. unset($data['type_id']);
  4906. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4907. $where = [];
  4908. if ($type_id != 10000 && empty($data['deal_user'])) {
  4909. $where['complaint.user_id'] = $user_id;
  4910. }
  4911. if (!empty($data['title'])) {
  4912. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4913. }
  4914. if (!empty($data['department_id'])) {
  4915. $where['complaint.department_id'] = $data['department_id'];
  4916. }
  4917. if (!empty($data['deal'])) {
  4918. $where['complaint.deal'] = $data['deal'];
  4919. }
  4920. if (!empty($data['status'])) {
  4921. $where['complaint.status'] = $data['status'];
  4922. }
  4923. var_dump(!empty($data['deal_user']), '----------1');
  4924. var_dump($where, '----------2');
  4925. $result = Complaint::where($where)
  4926. ->when(!empty($data['status1']), function ($query) use ($data) {
  4927. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4928. })
  4929. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4930. // //json re_user_ids data[user_id]是不是在里面
  4931. // $query->Where(function ($q) use ($data) {
  4932. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4933. // ->where('complaint.status', 2);
  4934. // });
  4935. // })
  4936. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4937. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4938. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4939. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4940. ->orderBy('updated_at', 'desc')
  4941. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4942. //sql输出
  4943. if (empty($result)) {
  4944. return Result::error("暂无投诉信息", 0);
  4945. }
  4946. // 取出数据
  4947. $rows = $result->items();
  4948. $count = $result->total();
  4949. $responseData = [
  4950. 'rows' => $rows,
  4951. 'count' => $count,
  4952. ];
  4953. return Result::success($responseData);
  4954. }
  4955. public function getComplaintInfo(array $data): array
  4956. {
  4957. $result = Complaint::where('id', $data['id'])->first();
  4958. if (empty($result)) {
  4959. return Result::error("查询失败", 0);
  4960. }
  4961. return Result::success($result);
  4962. }
  4963. public function readComplaint(array $data): array
  4964. {
  4965. $result = Complaint::where('id', $data['id'])->first();
  4966. if (empty($result)) {
  4967. return Result::error("查询失败", 0);
  4968. }
  4969. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4970. $re_user_ids = json_decode($result['re_user_ids'], true);
  4971. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4972. //如果已经存在,就不再添加
  4973. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4974. $read_id = json_decode($result['read_id'], true);
  4975. if (!is_array($read_id)) {
  4976. $read_id = [];
  4977. }
  4978. if (!in_array($data['user_id'], $read_id)) {
  4979. $read_id[] = $data['user_id'];
  4980. $result['read_id'] = json_encode($read_id);
  4981. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4982. }
  4983. } else {
  4984. //如果不存在,就添加
  4985. $result['read_id'] = json_encode([$data['user_id']]);
  4986. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4987. }
  4988. }
  4989. return Result::success($result);
  4990. }
  4991. public function addComplaint(array $data): array
  4992. {
  4993. date_default_timezone_set('Asia/Shanghai');
  4994. $data['created_at'] = date('Y-m-d H:i:s');
  4995. $data['updated_at'] = date('Y-m-d H:i:s');
  4996. $this->sendMessage([
  4997. 'talk_type' => 800,
  4998. 'title' => $data['title'],
  4999. 'content' => '提交了审核',
  5000. 'messageType' => 6,
  5001. ]);
  5002. $result = Complaint::create($data);
  5003. return Result::success($result);
  5004. }
  5005. public function updateComplaint(array $data): array
  5006. {
  5007. date_default_timezone_set('Asia/Shanghai');
  5008. $data['updated_at'] = date('Y-m-d H:i:s');
  5009. $user_id = $data['user_id'] ?? 0;
  5010. $type_id = $data['type_id'] ?? 0;
  5011. unset($data['user_id']);
  5012. unset($data['type_id']);
  5013. $this->sendMessage([
  5014. 'talk_type' => 800,
  5015. 'title' => $data['title'],
  5016. 'content' => '提交了审核',
  5017. 'messageType' => 6,
  5018. ]);
  5019. $result = Complaint::where('id', $data['id'])->update($data);
  5020. return Result::success($result);
  5021. }
  5022. public function deleteComplaint(array $data): array
  5023. {
  5024. $result = Complaint::where('id', $data['id'])->delete();
  5025. return Result::success($result);
  5026. }
  5027. public function getComplainInfo(array $data): array
  5028. {
  5029. $result = Complaint::where('id', $data['id'])->first();
  5030. if (empty($result)) {
  5031. return Result::error("查询失败", 0);
  5032. }
  5033. return Result::success($result);
  5034. }
  5035. public function updateComplaintStatus(array $data): array
  5036. {
  5037. date_default_timezone_set('Asia/Shanghai');
  5038. $data['updated_at'] = date('Y-m-d H:i:s');
  5039. $user_id = $data['user_id'] ?? 0;
  5040. $type_id = $data['type_id'] ?? 0;
  5041. unset($data['user_id']);
  5042. unset($data['type_id']);
  5043. //处理, 写入处理人
  5044. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5045. $data['real_deal_user'] = $user_id;
  5046. }
  5047. //如果是deal 23,则判断是不是处理人
  5048. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5049. $complaintInof = Complaint::where('id', $data['id'])
  5050. ->where('real_deal_user', $user_id)
  5051. ->first();
  5052. if (empty($complaintInof)) {
  5053. return Result::error("处理人错误", 0);
  5054. }
  5055. }
  5056. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5057. if ($data['status'] == 1) {
  5058. $this->sendMessage([
  5059. 'talk_type' => 800,
  5060. 'title' => $complaintInfo['title'],
  5061. 'content' => '提交了审核',
  5062. 'messageType' => 6,
  5063. ]);
  5064. }
  5065. if ($data['status'] == 2 && !isset($data['deal'])) {
  5066. $this->sendMessage([
  5067. 'talk_type' => 801,
  5068. 'title' => $complaintInfo['title'],
  5069. 'content' => '审核通过',
  5070. 'messageType' => 6,
  5071. 'user_id' => $complaintInfo['user_id'],
  5072. ]);
  5073. $this->sendMessage([
  5074. 'talk_type' => 802,
  5075. 'title' => $complaintInfo['title'],
  5076. 'content' => '待处理',
  5077. 'messageType' => 6,
  5078. 'user_id' => $complaintInfo['re_user_ids'],
  5079. ]);
  5080. }
  5081. if ($data['status'] == 3 && !isset($data['deal'])) {
  5082. $this->sendMessage([
  5083. 'talk_type' => 801,
  5084. 'title' => $complaintInfo['title'],
  5085. 'content' => '审核拒绝',
  5086. 'messageType' => 6,
  5087. 'user_id' => $complaintInfo['user_id'],
  5088. ]);
  5089. }
  5090. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5091. $this->sendMessage([
  5092. 'talk_type' => 802,
  5093. 'title' => $complaintInfo['title'],
  5094. 'content' => '处理中',
  5095. 'messageType' => 6,
  5096. 'user_id' => $complaintInfo['re_user_ids'],
  5097. ]);
  5098. }
  5099. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5100. $this->sendMessage([
  5101. 'talk_type' => 802,
  5102. 'title' => $complaintInfo['title'],
  5103. 'content' => '不予处理',
  5104. 'messageType' => 6,
  5105. 'user_id' => $complaintInfo['re_user_ids'],
  5106. ]);
  5107. }
  5108. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5109. $this->sendMessage([
  5110. 'talk_type' => 802,
  5111. 'title' => $complaintInfo['title'],
  5112. 'content' => '已完结',
  5113. 'messageType' => 6,
  5114. 'user_id' => $complaintInfo['re_user_ids'],
  5115. ]);
  5116. }
  5117. $result = complaint::where('id', $data['id'])->update($data);
  5118. return Result::success($result);
  5119. }
  5120. public function updateGoodStatus(array $data): array
  5121. {
  5122. $user_id = $data['user_id'] ?? 0;
  5123. $type_id = $data['type_id'] ?? 0;
  5124. unset($data['user_id']);
  5125. unset($data['type_id']);
  5126. $goodInfo = Good::where('id', $data['id'])->first();
  5127. if ($data['status'] == 2) {
  5128. $this->sendMessage([
  5129. 'talk_type' => 201,
  5130. 'title' => $goodInfo['name'],
  5131. 'content' => '审核通过',
  5132. 'messageType' => 3,
  5133. 'user_id' => $goodInfo['user_id'],
  5134. ]);
  5135. }
  5136. if ($data['status'] == 3) {
  5137. $this->sendMessage([
  5138. 'talk_type' => 201,
  5139. 'title' => $goodInfo['name'],
  5140. 'content' => '审核拒绝',
  5141. 'messageType' => 3,
  5142. 'user_id' => $goodInfo['user_id'],
  5143. ]);
  5144. }
  5145. if ($data['status'] == 1) {
  5146. $this->sendMessage([
  5147. 'talk_type' => 200,
  5148. 'title' => $goodInfo['name'],
  5149. 'content' => '提交了审核',
  5150. 'messageType' => 3,
  5151. ]);
  5152. }
  5153. $result = Good::where('id', $data['id'])->update($data);
  5154. return Result::success($result);
  5155. }
  5156. public function updateJobHuntingStatus(array $data): array
  5157. {
  5158. $user_id = $data['user_id'] ?? 0;
  5159. $type_id = $data['type_id'] ?? 0;
  5160. unset($data['user_id']);
  5161. unset($data['type_id']);
  5162. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5163. if ($data['status'] == 2) {
  5164. $this->sendMessage([
  5165. 'talk_type' => 601,
  5166. 'title' => $jogHuntingInfo['name'],
  5167. 'content' => '审核通过',
  5168. 'messageType' => 11,
  5169. 'user_id' => $jogHuntingInfo['user_id'],
  5170. ]);
  5171. }
  5172. if ($data['status'] == 3) {
  5173. $this->sendMessage([
  5174. 'talk_type' => 601,
  5175. 'title' => $jogHuntingInfo['name'],
  5176. 'content' => '审核拒绝',
  5177. 'messageType' => 11,
  5178. 'user_id' => $jogHuntingInfo['user_id'],
  5179. ]);
  5180. }
  5181. if ($data['status'] == 1) {
  5182. $this->sendMessage([
  5183. 'talk_type' => 600,
  5184. 'title' => $jogHuntingInfo['name'],
  5185. 'content' => '提交了审核',
  5186. 'messageType' => 11,
  5187. ]);
  5188. }
  5189. $result = JobHunting::where('id', $data['id'])->update($data);
  5190. return Result::success($result);
  5191. }
  5192. public function updateNoticeStatus(array $data): array
  5193. {
  5194. $user_id = $data['user_id'] ?? 0;
  5195. $type_id = $data['type_id'] ?? 0;
  5196. unset($data['user_id']);
  5197. unset($data['type_id']);
  5198. //查询公告
  5199. $notice = Notice::where('id', $data['id'])->first();
  5200. if (empty($notice)) {
  5201. return Result::error("公告不存在", 0);
  5202. }
  5203. //$chat_ids 去除掉$data['user_id']
  5204. $chat_ids = json_decode($notice['re_user_ids'], true);
  5205. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5206. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5207. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5208. //chat_group
  5209. $group_id = PublicData::uuid();
  5210. $groupData = [
  5211. 'id' => $group_id,
  5212. 'creator_id' => $notice['user_id'],
  5213. 'group_name' => $notice['group_name'] ?? '',
  5214. 'profile' => $notice['profile'] ?? 0,
  5215. ];
  5216. var_dump($groupData, '-----------------groupData-------');
  5217. $groupResult = ChatGroups::insertGetId($groupData);
  5218. var_dump($groupResult, '-----------------groupid-------');
  5219. $groupMemberData = [
  5220. 'id' => PublicData::uuid(),
  5221. 'user_id' => $notice['user_id'],
  5222. 'group_id' => $group_id,
  5223. 'leader' => 2,
  5224. ];
  5225. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5226. //插入群成员表
  5227. $groupMemberDataUser = [];
  5228. $chatData = [];
  5229. foreach ($chat_ids as $key => $value) {
  5230. $groupMemberDataUser[] = [
  5231. 'id' => PublicData::uuid(),
  5232. 'user_id' => $value,
  5233. 'group_id' => $group_id,
  5234. 'leader' => 1,
  5235. ];
  5236. $chatData[] = [
  5237. 'user_id' => $value,
  5238. 'msg_type' => 1,
  5239. 'receiver_id' => $group_id,
  5240. 'content' => '通过通知创建群聊',
  5241. 'group_receiver_id' => $notice['user_id'],
  5242. 'action' => 'recieved',
  5243. 'created_at' => date('Y-m-d H:i:s'),
  5244. ];
  5245. }
  5246. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5247. ChatGroupsMember::insert($groupMemberDataUser);
  5248. //插入一条管理员聊天记录
  5249. $chatData[] = [
  5250. 'user_id' => $notice['user_id'],
  5251. 'msg_type' => 1,
  5252. 'receiver_id' => $group_id,
  5253. 'content' => '通过通知创建群聊',
  5254. 'group_receiver_id' => $notice['user_id'],
  5255. 'action' => 'said',
  5256. 'created_at' => date('Y-m-d H:i:s'),
  5257. ];
  5258. var_dump($chatData, '-----------------chatData-------');
  5259. $chatResult = ChatRecords::insert($chatData);
  5260. //处理imp
  5261. $group = [
  5262. 'type' => 1,
  5263. 'name' => $notice['group_name'] ?? '',
  5264. 'profile' => '',
  5265. 'avatar' => '',
  5266. 'creator_id' => $notice['user_id'],
  5267. ];
  5268. $groupResult = GroupImp::insertGetId($group);
  5269. var_dump($groupResult, '获取imp group_id');
  5270. $groupMember = [
  5271. 'user_id' => $notice['user_id'],
  5272. 'group_id' => $groupResult,
  5273. 'leader' => 1,
  5274. 'join_time' => Date('Y-m-d H:i:s')
  5275. ];
  5276. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5277. $talk_session = [
  5278. 'user_id' => $notice['user_id'],
  5279. 'to_from_id' => $groupResult,
  5280. 'talk_mode' => 2,
  5281. 'created_at' => Date('Y-m-d H:i:s'),
  5282. 'updated_at' => Date('Y-m-d H:i:s'),
  5283. ];
  5284. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5285. //被通知人员处理
  5286. foreach ($chat_ids as $key => $value) {
  5287. $groupMemberdata[] = [
  5288. 'user_id' => $value,
  5289. 'group_id' => $groupResult,
  5290. 'leader' => 3,
  5291. 'join_time' => Date('Y-m-d H:i:s')
  5292. ];
  5293. $talk_sessionData[] = [
  5294. 'user_id' => $value,
  5295. 'to_from_id' => $groupResult,
  5296. 'talk_mode' => 2,
  5297. 'created_at' => Date('Y-m-d H:i:s'),
  5298. 'updated_at' => Date('Y-m-d H:i:s'),
  5299. ];
  5300. }
  5301. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5302. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5303. $group_id = $groupResult;
  5304. //更新result的 group_id
  5305. $data['group_id'] = $group_id;
  5306. Notice::where(['id' => $data['id']])->update($data);
  5307. }
  5308. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5309. //删除掉信息
  5310. GroupImp::where('id', $notice['group_id'])->delete();
  5311. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5312. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5313. foreach ($chat_ids as $key => $value) {
  5314. }
  5315. //聊天记录删除
  5316. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5317. $data['group_id'] = null;
  5318. Notice::where(['id' => $data['id']])->update($data);
  5319. }
  5320. $result = Notice::where('id', $data['id'])->update($data);
  5321. $noticeInfo = Notice::where('id', $data['id'])->first();
  5322. if ($data['status'] == 2) {
  5323. $this->sendMessage([
  5324. 'talk_type' => 701,
  5325. 'title' => $noticeInfo['title'],
  5326. 'content' => '审核通过',
  5327. 'messageType' => 3,
  5328. 'user_id' => $noticeInfo['user_id'],
  5329. ]);
  5330. }
  5331. if ($data['status'] == 3) {
  5332. $this->sendMessage([
  5333. 'talk_type' => 701,
  5334. 'title' => $noticeInfo['title'],
  5335. 'content' => '审核拒绝',
  5336. 'messageType' => 3,
  5337. 'user_id' => $noticeInfo['user_id'],
  5338. ]);
  5339. }
  5340. if ($data['status'] == 1) {
  5341. $this->sendMessage([
  5342. 'talk_type' => 700,
  5343. 'title' => $noticeInfo['title'],
  5344. 'content' => '提交了审核',
  5345. 'messageType' => 3,
  5346. ]);
  5347. }
  5348. return Result::success($result);
  5349. }
  5350. public function getDUser(array $data): array
  5351. {
  5352. if (!empty($data['ids'])) {
  5353. $user = User::whereIn('id', $data['ids'])->getall();
  5354. if (empty($user)) {
  5355. return Result::error('无数据', 0);
  5356. }
  5357. return Result::success($user);
  5358. }
  5359. $where = [];
  5360. if (!empty($data['department_id'])) {
  5361. $where['department_id'] = $data['department_id'];
  5362. }
  5363. if (!empty($data['city_id'])) {
  5364. $where['city_id'] = $data['city_id'];
  5365. }
  5366. $result = User::where('type_id', 2)
  5367. ->where('status', 1)
  5368. ->where($where)
  5369. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5370. ->get();
  5371. if (empty($result)) {
  5372. return Result::error("查询失败", 0);
  5373. }
  5374. return Result::success($result);
  5375. }
  5376. /**
  5377. * 验证导航名称是否重复
  5378. * @return void
  5379. */
  5380. public function checkCategoryName(array $data): array
  5381. {
  5382. $result = Category::when($data, function ($query) use ($data) {
  5383. if (isset($data['name']) && $data['name']) {
  5384. $query->where("name", $data['name']);
  5385. }
  5386. if (isset($data['id']) && $data['id']) {
  5387. $query->where("id", "!=", $data['id']);
  5388. }
  5389. })->first();
  5390. if ($result) {
  5391. return Result::error("已存在");
  5392. } else {
  5393. return Result::success();
  5394. }
  5395. }
  5396. //20250226 产品列表
  5397. // 20250306 -------招聘--------fr
  5398. /*
  5399. * 招聘列表
  5400. * */
  5401. public function getJobRecruitingList(array $data): array
  5402. {
  5403. $where = [];
  5404. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5405. if ($data['checkout'] == 0) {
  5406. $job_status = [0, 2];
  5407. } else {
  5408. $job_status = [1];
  5409. }
  5410. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5411. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5412. }
  5413. $user = User::where('id', $data['user_id'])->first();
  5414. if (empty($user)) {
  5415. return Result::error("用户不存在", 0);
  5416. }
  5417. // 3:企业会员
  5418. if ($user['type_id'] == 3) {
  5419. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5420. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5421. }
  5422. // 如果 $where 为空,则不添加 where 条件
  5423. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5424. return $query->where($where);
  5425. })
  5426. ->whereIn('job_recruiting.status', $job_status)
  5427. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5428. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5429. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5430. ->orderBy("updated_at", "desc")
  5431. ->offset(($data['page'] - 1) * $data['page_size'])
  5432. ->limit($data['page_size'])
  5433. ->get()
  5434. ->all();
  5435. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5436. return $query->where($where);
  5437. })
  5438. ->whereIn('job_recruiting.status', $job_status)
  5439. ->count();
  5440. if (empty($result)) {
  5441. return Result::error("暂无招聘信息", 0);
  5442. }
  5443. return Result::success($result);
  5444. }
  5445. /*
  5446. * 招聘信息添加
  5447. * */
  5448. public function addJobRecruiting(array $data): array
  5449. {
  5450. // var_dump('添加招聘进入news------data',$data);
  5451. // return Result::success($data);
  5452. $user = User::where('user.id', $data['user_id'])
  5453. ->where('user.status', 1)
  5454. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5455. ->select(
  5456. 'user.type_id',
  5457. 'user.mobile',
  5458. 'user.email',
  5459. 'user_info.business_name',
  5460. 'user_info.company_hy_id',
  5461. 'user_info.company_nature',
  5462. 'user_info.company_size',
  5463. 'user_info.introduction',
  5464. 'user_info.real_name',
  5465. 'user_info.company_url',
  5466. 'user_info.address_arr_id',
  5467. 'user_info.address'
  5468. )
  5469. ->first();
  5470. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5471. return Result::error("用户不存在", 0);
  5472. }
  5473. $web = Website::where('id', $data['website_id'])->first();
  5474. if (empty($web)) {
  5475. return Result::error("网站不存在", 0);
  5476. }
  5477. // var_dump('添加招聘进入news---user---user',$user);
  5478. // 处理招聘关键词
  5479. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5480. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5481. } else {
  5482. Jieba::init(); // 初始化 jieba-php
  5483. Finalseg::init();
  5484. $segList = Jieba::cut($data['title']);
  5485. $segList1 = array_slice($segList, 0, 8);
  5486. $data['keyword'] = implode(',', $segList1);
  5487. }
  5488. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5489. $content = $data['description'];
  5490. // 去除 <style> 和 <script> 标签及其内容
  5491. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5492. // 去除所有 HTML 标签
  5493. $content = strip_tags($content);
  5494. // 去除 HTML 实体
  5495. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5496. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5497. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5498. // 去除多余空白
  5499. $content = preg_replace('/\s+/u', '', $content);
  5500. // 截取 100 个字符
  5501. $data['seo_description'] = mb_substr($content, 0, 100);
  5502. }
  5503. // return Result::success($user);
  5504. $data['action_id'] = $data['user_id'] ?? null;
  5505. $data['user_type'] = $user['type_id'] ?? null;
  5506. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5507. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5508. $data['catid'] = end($data['cat_arr_id']);
  5509. } else {
  5510. $data['catid'] = 0;
  5511. }
  5512. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5513. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5514. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5515. // 公司地址 管理员必填
  5516. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5517. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5518. // 管理员-企业相关信息
  5519. $company = [
  5520. // 'user_id' => $data['user_id']?? null,
  5521. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5522. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5523. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5524. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5525. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5526. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5527. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5528. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5529. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5530. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5531. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5532. ];
  5533. //去掉相关企业信息
  5534. $job = array_diff_key($data, array_flip(array_keys($company)));
  5535. // var_dump('添加招聘进入news---job---user',$job);
  5536. Db::beginTransaction();
  5537. try {
  5538. // // 先添加职位相关信息
  5539. if ($user['type_id'] == 10000) {
  5540. $job['status'] = 1;
  5541. }
  5542. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5543. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5544. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5545. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5546. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5547. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5548. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5549. // return Result::success($job);
  5550. $jobId = JobRecruiting::insertGetId($job);
  5551. if (empty($jobId)) {
  5552. Db::rollBack();
  5553. return Result::error("添加失败");
  5554. }
  5555. // 添加公司信息
  5556. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5557. $company['job_id'] = $jobId;
  5558. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5559. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5560. if ($user['type_id'] == 10000) {
  5561. // 管理员添加企业信息
  5562. $companyId = JobCompany::insertGetId($company);
  5563. if (empty($companyId)) {
  5564. Db::rollBack();
  5565. return Result::error("添加失败");
  5566. }
  5567. } else {
  5568. // 企业会员添加企业信息
  5569. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5570. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5571. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5572. $company['job_id'] = $jobId;
  5573. $companyId = JobCompany::insertGetId($company);
  5574. if (empty($companyId)) {
  5575. Db::rollBack();
  5576. return Result::error("添加失败");
  5577. }
  5578. }
  5579. Db::commit();
  5580. $result = [
  5581. 'job_id' => $jobId,
  5582. 'company_id' => $companyId,
  5583. ];
  5584. return Result::success($result);
  5585. } catch (\Exception $e) {
  5586. Db::rollBack();
  5587. return Result::error($e->getMessage(), 0);
  5588. }
  5589. // return Result::success($result);
  5590. }
  5591. /*
  5592. * 获取招聘信息详情
  5593. * */
  5594. public function getJobRecruitingInfo(array $data): array
  5595. {
  5596. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5597. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5598. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5599. ->select(
  5600. 'job_recruiting.*',
  5601. 'website.website_name as website_name',
  5602. 'job_company.business_name',
  5603. 'job_company.company_hy_id',
  5604. 'job_company.company_size',
  5605. 'job_company.company_nature',
  5606. 'job_company.introduction',
  5607. 'job_company.real_name',
  5608. 'job_company.mobile',
  5609. 'job_company.company_url',
  5610. 'job_company.address_arr_id',
  5611. 'job_company.address',
  5612. 'job_company.email'
  5613. )
  5614. ->first();
  5615. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5616. if (!empty($cityId)) {
  5617. if (isset($cityId[1]) && $cityId[1] != null) {
  5618. $city = District::where('id', $cityId[1])->first(['name']);
  5619. } else {
  5620. $city = District::where('id', $cityId[0])->first(['name']);
  5621. }
  5622. $result['city'] = $city['name'] ?? '';
  5623. }
  5624. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5625. if (is_array($addressId) && !empty($addressId)) {
  5626. $address = District::whereIn('id', $addressId)
  5627. ->orderBy('level', 'asc')
  5628. ->get(['name'])
  5629. ->pluck('name')
  5630. ->implode('');
  5631. // $job->address_name = $address ?? '';
  5632. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5633. }
  5634. if (empty($result)) {
  5635. return Result::error("招聘信息不存在", 0);
  5636. }
  5637. // return Result::success($job);
  5638. return Result::success($result);
  5639. }
  5640. /*
  5641. * 修改招聘信息
  5642. * */
  5643. public function upJobRecruiting(array $data): array
  5644. {
  5645. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5646. // return Result::success($job);
  5647. if (empty($job)) {
  5648. return Result::error("招聘信息不存在", 0);
  5649. }
  5650. $user = User::where('id', $data['user_id'])->first();
  5651. // return Result::success($user);
  5652. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5653. return Result::error("用户不存在", 0);
  5654. }
  5655. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5656. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5657. }
  5658. // 处理招聘关键词
  5659. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5660. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5661. } else {
  5662. Jieba::init(); // 初始化 jieba-php
  5663. Finalseg::init();
  5664. $segList = Jieba::cut($data['title']);
  5665. $segList1 = array_slice($segList, 0, 8);
  5666. $data['keyword'] = implode(',', $segList1);
  5667. }
  5668. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5669. $content = $data['description'];
  5670. // 去除 <style> 和 <script> 标签及其内容
  5671. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5672. // 去除所有 HTML 标签
  5673. $content = strip_tags($content);
  5674. // 去除 HTML 实体
  5675. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5676. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5677. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5678. // 去除多余空白
  5679. $content = preg_replace('/\s+/u', '', $content);
  5680. // 截取 100 个字符
  5681. $data['seo_description'] = mb_substr($content, 0, 100);
  5682. }
  5683. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5684. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5685. $data['catid'] = end($data['cat_arr_id']);
  5686. } else {
  5687. }
  5688. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5689. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5690. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5691. // 公司地址 管理员必填
  5692. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5693. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5694. // 管理员-企业相关信息
  5695. $company = [
  5696. // 'user_id' => $data['user_id']?? null,
  5697. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5698. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5699. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5700. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5701. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5702. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5703. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5704. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5705. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5706. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5707. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5708. ];
  5709. //去掉相关企业信息
  5710. $data = array_diff_key($data, array_flip(array_keys($company)));
  5711. $jobId = $data['id'];
  5712. $web = $data['website_id'];
  5713. $data['action_id'] = $data['user_id'];
  5714. unset($data['user_id']);
  5715. unset($data['user_type']);
  5716. unset($data['id']);
  5717. unset($data['website_id']);
  5718. // return Result::success($data);
  5719. Db::beginTransaction();
  5720. try {
  5721. // 管理员修改招聘信息
  5722. if ($user['type_id'] == 10000) {
  5723. $data['website_id'] = $web;
  5724. $company['website_id'] = $data['website_id'];
  5725. $data['status'] = 1;
  5726. } else {
  5727. $data['status'] = 0;
  5728. }
  5729. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5730. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5731. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5732. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5733. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5734. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5735. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5736. // return Result::success($job);
  5737. // Db::rollBack();
  5738. // return Result::success($company);
  5739. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5740. $this->sendMessage([
  5741. 'talk_type' => 500,
  5742. 'title' => $data['title'],
  5743. 'content' => '提交了审核',
  5744. 'messageType' => 10,
  5745. ]);
  5746. }
  5747. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5748. if (empty($result['job'])) {
  5749. Db::rollBack();
  5750. return Result::error("修改招聘信息失败");
  5751. }
  5752. // 管理员修改企业相关信息
  5753. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5754. if (empty($result['company'])) {
  5755. Db::rollBack();
  5756. return Result::error("修改企业相关信息失败");
  5757. }
  5758. Db::commit();
  5759. // return Result::success($result);
  5760. } catch (\Exception $e) {
  5761. Db::rollBack();
  5762. return Result::error($e->getMessage(), 0);
  5763. }
  5764. return Result::success($result);
  5765. }
  5766. /*
  5767. * 招聘信息删除
  5768. * */
  5769. public function delJobRecruiting(array $data): array
  5770. {
  5771. $user = User::where('id', $data['user_id'])->first();
  5772. if (empty($user)) {
  5773. return Result::error("用户不存在", 0);
  5774. }
  5775. $job = JobRecruiting::where('id', $data['id'])->first();
  5776. if (empty($job)) {
  5777. return Result::error("招聘信息不存在", 0);
  5778. }
  5779. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5780. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5781. }
  5782. Db::beginTransaction();
  5783. try {
  5784. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5785. if (empty($result['job'])) {
  5786. Db::rollBack();
  5787. return Result::error("删除招聘信息失败");
  5788. }
  5789. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5790. if (empty($result['company'])) {
  5791. Db::rollBack();
  5792. return Result::error("删除企业相关信息失败");
  5793. }
  5794. Db::commit();
  5795. } catch (\Exception $e) {
  5796. Db::rollBack();
  5797. return Result::error($e->getMessage(), 0);
  5798. }
  5799. return Result::success($result);
  5800. }
  5801. /*
  5802. * 获取公司信息
  5803. * */
  5804. public function getJobCompany(array $data): array
  5805. {
  5806. $user = User::where('user.id', $data['user_id'])
  5807. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5808. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5809. ->first();
  5810. // return Result::success($user);
  5811. if (empty($user)) {
  5812. return Result::error("用户不存在", 0);
  5813. }
  5814. if ($user['type_id'] == 3) {
  5815. $result = [
  5816. // 'id' => 0,
  5817. 'user_id' => $data['user_id'],
  5818. 'website_id' => $data['website_id'],
  5819. 'business_name' => $user['business_name'], // 企业名称
  5820. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5821. 'company_nature' => $user['company_nature'], // 公司性质
  5822. 'company_size' => $user['company_size'], // 公司规模
  5823. 'introduction' => $user['introduction'], // 公司简介
  5824. 'real_name' => $user['real_name'], // 企业联系人
  5825. 'mobile' => $user['mobile'], // 企业联系电话
  5826. 'company_url' => $user['company_url'], // 企业网址
  5827. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5828. 'address' => $user['address'], // 企业地址
  5829. 'email' => $user['email'], // 企业邮箱
  5830. ];
  5831. } else {
  5832. return Result::error("用户类型错误", 0);
  5833. }
  5834. if (empty($result)) {
  5835. return Result::error("公司信息不存在", 0);
  5836. }
  5837. return Result::success($result);
  5838. }
  5839. /*
  5840. * 修改公司信息
  5841. * */
  5842. public function upJobCompany(array $data): array
  5843. {
  5844. // return Result::success($data);
  5845. $user = User::where('user.id', $data['user_id'])
  5846. ->where('user.status', 1)
  5847. ->select('user.user_name', 'user.type_id')
  5848. ->first();
  5849. if (empty($user)) {
  5850. return Result::error("用户不存在", 0);
  5851. }
  5852. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5853. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5854. $company = [
  5855. 'business_name' => $data['business_name'], // 企业名称
  5856. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5857. 'company_nature' => $data['company_nature'], // 公司性质
  5858. 'company_size' => $data['company_size'], // 公司规模
  5859. 'introduction' => $data['introduction'], // 公司简介
  5860. // 'real_name' => $data['real_name'], // 企业联系人
  5861. 'company_url' => $data['company_url'], // 企业网址
  5862. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5863. 'address' => $data['address'], // 企业详细地址
  5864. // 'email' => $data['email'], // 企业邮箱
  5865. ];
  5866. if ($user['type_id'] == 3) {
  5867. Db::beginTransaction();
  5868. try {
  5869. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5870. 'business_name' => $data['business_name'], // 企业名称
  5871. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5872. 'company_nature' => $data['company_nature'], // 公司性质
  5873. 'company_size' => $data['company_size'], // 公司规模
  5874. 'introduction' => $data['introduction'], // 公司简介
  5875. // 'real_name' => $data['real_name'], // 企业联系人
  5876. 'company_url' => $data['company_url'], // 企业网址
  5877. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5878. 'address' => $data['address'], // 企业详细地址
  5879. ]);
  5880. if (empty($result['userinfo'])) {
  5881. Db::rollBack();
  5882. return Result::error('修改企业会员信息失败!');
  5883. }
  5884. $result['user'] = User::where('id', $data['user_id'])->update([
  5885. 'email' => $data['email'], // 企业邮箱
  5886. ]);
  5887. if (empty($result['user'])) {
  5888. Db::rollBack();
  5889. return Result::error('修改个人中心信息失败!');
  5890. }
  5891. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5892. if (!empty($job_company)) {
  5893. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5894. if (empty($result['job_company'])) {
  5895. Db::rollBack();
  5896. return Result::error('修改企业会员信息失败!');
  5897. }
  5898. }
  5899. Db::commit();
  5900. return Result::success($result);
  5901. } catch (\Exception $e) {
  5902. Db::rollBack();
  5903. return Result::error($e->getMessage(), 0);
  5904. }
  5905. } else {
  5906. return Result::error("用户类型错误", 0);
  5907. }
  5908. }
  5909. /*
  5910. * 获取省-市
  5911. * */
  5912. public function getJobRecruitingArea(array $data): array
  5913. {
  5914. if (isset($data['pid']) && $data['pid'] != null) {
  5915. $result = District::where('pid', $data['pid'])->get()->all();
  5916. } else {
  5917. $result = District::where('level', 1)->get()->all();
  5918. }
  5919. if (empty($result)) {
  5920. return Result::error("暂无此省市", 0);
  5921. }
  5922. return Result::success($result);
  5923. }
  5924. /*
  5925. * 获取行业分类
  5926. * */
  5927. public function getIndustry(array $data): array
  5928. {
  5929. $result = JobIndustry::get()->all();
  5930. if (empty($result)) {
  5931. return Result::error("暂无行业分类", 0);
  5932. }
  5933. return Result::success($result);
  5934. }
  5935. /*
  5936. * 获取职位
  5937. * */
  5938. public function getPositionList(array $data): array
  5939. {
  5940. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5941. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5942. } else {
  5943. $result = JobPosition::where('zwpid', 0)->get()->all();
  5944. }
  5945. if (empty($result)) {
  5946. return Result::error("暂无此职位", 0);
  5947. }
  5948. return Result::success($result);
  5949. }
  5950. /*
  5951. * 获取工作性质-菜单
  5952. * */
  5953. public function getJobNature(array $data): array
  5954. {
  5955. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5956. if (empty($result)) {
  5957. return Result::error("暂无工作性质", 0);
  5958. }
  5959. return Result::success($result);
  5960. }
  5961. /*
  5962. * 获取工作经验-菜单
  5963. * */
  5964. public function getExperience(array $data): array
  5965. {
  5966. $result = JobEnum::where('egroup', 'years')->get()->all();
  5967. if (empty($result)) {
  5968. return Result::error("暂无工作经验", 0);
  5969. }
  5970. return Result::success($result);
  5971. }
  5972. /*
  5973. * 获取学历-菜单
  5974. * */
  5975. public function getEducation(array $data): array
  5976. {
  5977. $result = JobEnum::where('egroup', 'education')->get()->all();
  5978. if (empty($result)) {
  5979. return Result::error("暂无学历", 0);
  5980. }
  5981. return Result::success($result);
  5982. }
  5983. /*
  5984. * 获取薪资-菜单
  5985. * */
  5986. public function getSalary(array $data): array
  5987. {
  5988. $result = JobEnum::where('egroup', 'income')->get()->all();
  5989. if (empty($result)) {
  5990. return Result::error("暂无薪资", 0);
  5991. }
  5992. return Result::success($result);
  5993. }
  5994. /*
  5995. * 获取语言-菜单
  5996. * */
  5997. public function getLanguage(array $data): array
  5998. {
  5999. $result = JobEnum::where('egroup', 'language')->get()->all();
  6000. if (empty($result)) {
  6001. return Result::error("暂无语言", 0);
  6002. }
  6003. return Result::success($result);
  6004. }
  6005. /*
  6006. * 获取掌握程度-菜单
  6007. * */
  6008. public function getLevel(array $data): array
  6009. {
  6010. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6011. if (empty($result)) {
  6012. return Result::error("暂无工作性质", 0);
  6013. }
  6014. return Result::success($result);
  6015. }
  6016. // 公司信息
  6017. /*
  6018. * 获取公司性质-菜单
  6019. * */
  6020. public function getCompanyNature(array $data): array
  6021. {
  6022. $result = JobNature::get()->all();
  6023. if (empty($result)) {
  6024. return Result::error("暂无公司性质", 0);
  6025. }
  6026. return Result::success($result);
  6027. }
  6028. /*
  6029. * 获取公司规模-菜单
  6030. * */
  6031. public function getCompanySize(array $data): array
  6032. {
  6033. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6034. if (empty($result)) {
  6035. return Result::error("暂无公司规模", 0);
  6036. }
  6037. return Result::success($result);
  6038. }
  6039. /*
  6040. * 招聘信息审核
  6041. * */
  6042. public function checkJobRecruiting(array $data): array
  6043. {
  6044. $user = User::where('id', $data['user_id'])->first();
  6045. if (empty($user)) {
  6046. return Result::error("用户不存在", 0);
  6047. }
  6048. $job = JobRecruiting::where('id', $data['id'])->first();
  6049. if (empty($job)) {
  6050. return Result::error("招聘信息不存在", 0);
  6051. }
  6052. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6053. if ($user['type_id'] != 10000) {
  6054. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6055. }
  6056. // 驳回原因
  6057. if ($data['status'] == 2) {
  6058. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6059. }
  6060. $data['action_id'] = $data['user_id'];
  6061. unset($data['user_id']);
  6062. if ($data['status'] == 1) {
  6063. $this->sendMessage([
  6064. 'talk_type' => 501,
  6065. 'title' => $job['title'],
  6066. 'content' => '审核通过',
  6067. 'messageType' => 10,
  6068. 'user_id' => $job['user_id'],
  6069. ]);
  6070. }
  6071. if ($data['status'] == 2) {
  6072. $this->sendMessage([
  6073. 'talk_type' => 501,
  6074. 'title' => $job['title'],
  6075. 'content' => '审核拒绝',
  6076. 'messageType' => 10,
  6077. 'user_id' => $job['user_id'],
  6078. ]);
  6079. }
  6080. if ($data['status'] == 0) {
  6081. $this->sendMessage([
  6082. 'talk_type' => 500,
  6083. 'title' => $job['title'],
  6084. 'content' => '提交了审核',
  6085. 'messageType' => 10,
  6086. ]);
  6087. }
  6088. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6089. if (empty($result)) {
  6090. return Result::error("审核失败", 0);
  6091. }
  6092. return Result::success($result);
  6093. }
  6094. public function myApplyList(array $data): array
  6095. {
  6096. var_dump($data, '------参数');
  6097. $user = User::where('id', $data['user_id'])->first();
  6098. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6099. return Result::error("用户不存在", 0);
  6100. }
  6101. // 1:个人会员 职场机会
  6102. if ($user['type_id'] == 1) {
  6103. $where['user_id'] = $user['id'];
  6104. }
  6105. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6106. $query->where('user_id', $user['id']);
  6107. })
  6108. ->pluck('recruit_id');
  6109. $where = [];
  6110. if (isset($data['salary']) && $data['salary'] != null) {
  6111. $where['job_recruiting.salary'] = $data['salary'];
  6112. }
  6113. if (isset($data['experience']) && $data['experience'] != null) {
  6114. $where['job_recruiting.experience'] = $data['experience'];
  6115. }
  6116. if (isset($data['business_name']) && $data['business_name'] != null) {
  6117. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6118. }
  6119. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6120. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6121. ->where($where);
  6122. // ->count();
  6123. $count = $query->count();
  6124. $query = clone $query;
  6125. $job = $query
  6126. ->leftJoin('job_enum as income_enum', function ($join) {
  6127. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6128. ->where('income_enum.egroup', 'income');
  6129. })
  6130. ->leftJoin('job_enum as years_enum', function ($join) {
  6131. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6132. ->where('years_enum.egroup', 'years');
  6133. })
  6134. // ->where($where)
  6135. ->orderBy('job_recruiting.updated_at', 'desc')
  6136. ->select(
  6137. 'job_recruiting.id',
  6138. 'job_recruiting.title',
  6139. 'job_company.business_name',
  6140. 'income_enum.evalue as salary_evalue',
  6141. 'income_enum.ename as salary_ename',
  6142. 'years_enum.evalue as experience_evalue',
  6143. 'years_enum.ename as experience_ename',
  6144. 'job_recruiting.updated_at'
  6145. )
  6146. ->offset(($data['page'] - 1) * $data['pageSize'])
  6147. ->limit($data['pageSize'])
  6148. ->get()
  6149. ->all();
  6150. if (empty($job)) {
  6151. return Result::error("暂无招聘信息", 0);
  6152. }
  6153. $result = [
  6154. 'row' => $job,
  6155. 'count' => $count,
  6156. ];
  6157. return Result::success($result);
  6158. }
  6159. public function readJobApply(array $data): array
  6160. {
  6161. $result = JobApply::where('id', $data['id'])->first();
  6162. if (empty($result)) {
  6163. return Result::error("查询失败", 0);
  6164. }
  6165. $result = JobApply::where('id', $data['id'])->update([
  6166. 'status' => 2,
  6167. ]);
  6168. return Result::success($result);
  6169. }
  6170. /*
  6171. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6172. * */
  6173. public function getRecruitingList(array $data): array
  6174. {
  6175. $user = User::where('id', $data['user_id'])->first();
  6176. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6177. return Result::error("用户不存在", 0);
  6178. }
  6179. // 1:个人会员 职场机会
  6180. if ($user['type_id'] == 1) {
  6181. $where['user_id'] = $user['id'];
  6182. }
  6183. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6184. $query->where('receiver_id', $user['id']);
  6185. })
  6186. ->pluck('recruit_id');
  6187. // return Result::success($recruitingId);
  6188. $where = [];
  6189. if (isset($data['salary']) && $data['salary'] != null) {
  6190. $where['job_recruiting.salary'] = $data['salary'];
  6191. }
  6192. if (isset($data['experience']) && $data['experience'] != null) {
  6193. $where['job_recruiting.experience'] = $data['experience'];
  6194. }
  6195. if (isset($data['business_name']) && $data['business_name'] != null) {
  6196. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6197. }
  6198. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6199. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6200. ->where($where);
  6201. // ->count();
  6202. $count = $query->count();
  6203. $query = clone $query;
  6204. $job = $query
  6205. ->leftJoin('job_enum as income_enum', function ($join) {
  6206. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6207. ->where('income_enum.egroup', 'income');
  6208. })
  6209. ->leftJoin('job_enum as years_enum', function ($join) {
  6210. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6211. ->where('years_enum.egroup', 'years');
  6212. })
  6213. // ->where($where)
  6214. ->orderBy('job_recruiting.updated_at', 'desc')
  6215. ->select(
  6216. 'job_recruiting.id',
  6217. 'job_recruiting.title',
  6218. 'job_company.business_name',
  6219. 'income_enum.evalue as salary_evalue',
  6220. 'income_enum.ename as salary_ename',
  6221. 'years_enum.evalue as experience_evalue',
  6222. 'years_enum.ename as experience_ename',
  6223. 'job_recruiting.updated_at'
  6224. )
  6225. ->offset(($data['page'] - 1) * $data['pageSize'])
  6226. ->limit($data['pageSize'])
  6227. ->get()
  6228. ->all();
  6229. if (empty($job)) {
  6230. return Result::error("暂无招聘信息", 0);
  6231. }
  6232. $result = [
  6233. 'row' => $job,
  6234. 'count' => $count,
  6235. ];
  6236. return Result::success($result);
  6237. }
  6238. /*
  6239. * 获取企业会员-招聘信息列表
  6240. * */
  6241. public function getRecruitingInfo(array $data): array
  6242. {
  6243. $user = User::where('id', $data['user_id'])->first();
  6244. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6245. return Result::error("用户不存在", 0);
  6246. }
  6247. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6248. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6249. ->select(
  6250. 'job_recruiting.*',
  6251. 'job_company.business_name',
  6252. 'job_company.company_hy_id',
  6253. 'job_company.company_size',
  6254. 'job_company.company_nature',
  6255. 'job_company.introduction',
  6256. 'job_company.real_name',
  6257. 'job_company.mobile',
  6258. 'job_company.company_url',
  6259. 'job_company.address_arr_id',
  6260. 'job_company.address',
  6261. 'job_company.email'
  6262. )
  6263. ->get();
  6264. if (empty($recruiting)) {
  6265. return Result::error("暂无招聘信息", 0);
  6266. }
  6267. return Result::success($recruiting);
  6268. }
  6269. /*
  6270. * 获取企业会员-我的沟通
  6271. * */
  6272. public function getJobResumeList(array $data): array
  6273. {
  6274. $user = User::where('id', $data['user_id'])->first();
  6275. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6276. return Result::error("用户不存在", 0);
  6277. }
  6278. $where = [];
  6279. if (isset($data['salary']) && $data['salary'] != null) {
  6280. $where['job_hunting.salary'] = $data['salary'];
  6281. }
  6282. if (isset($data['user_name']) && $data['user_name'] != null) {
  6283. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6284. }
  6285. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6286. $query->where('job_resume.user_id', $user['id']);
  6287. })
  6288. ->when(!empty($where), function ($query) use ($where) {
  6289. $query->where($where);
  6290. })
  6291. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6292. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6293. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6294. ->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');
  6295. $count = $job->count();
  6296. if ($count == 0) {
  6297. return Result::error("暂无沟通记录", 0);
  6298. }
  6299. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6300. ->offset(($data['page'] - 1) * $data['pageSize'])
  6301. ->limit($data['pageSize'])
  6302. ->get();
  6303. if (empty($jobs)) {
  6304. return Result::error("暂无沟通记录", 0);
  6305. }
  6306. $result['row'] = $this->processJob($jobs, '');
  6307. $result['count'] = $count;
  6308. return Result::success($result);
  6309. }
  6310. public function readJobResume(array $data): array
  6311. {
  6312. $result = JobResume::where('id', $data['id'])->first();
  6313. if (empty($result)) {
  6314. return Result::error("查询失败", 0);
  6315. }
  6316. $result = JobResume::where('id', $data['id'])->update([
  6317. 'status' => 2,
  6318. ]);
  6319. return Result::success($result);
  6320. }
  6321. // 20250306 招聘
  6322. //20250422 书刊音像
  6323. public function addBook(array $data): array
  6324. {
  6325. $user_id = $data['user_id'] ?? 0;
  6326. $type_id = $data['type_id'] ?? 0;
  6327. // $website_id = $data['website_id'] ?? 0;
  6328. // unset($data['user_id']);
  6329. unset($data['type_id']);
  6330. // unset($data['website_id']);
  6331. //处理数组
  6332. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6333. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6334. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6335. if ($data['img_url'] == '') {
  6336. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6337. preg_match_all($reg, $data['detail'], $matches);
  6338. if (isset($matches[1][0])) {
  6339. //截取varchar240
  6340. $data['img_url'] = substr($matches[1][0], 0, 240);
  6341. }
  6342. }
  6343. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6344. //提取标题+内容中的关键词
  6345. $data['keyword'] = $data['title'];
  6346. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6347. Jieba::init(); // 初始化 jieba-php
  6348. Finalseg::init();
  6349. $segList = Jieba::cut($data['keyword']);
  6350. $segList1 = array_slice($segList, 0, 8);
  6351. $data['keyword'] = implode(',', $segList1);
  6352. }
  6353. if ($data['description'] == '') {
  6354. //提取内容中的描述
  6355. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6356. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6357. }
  6358. var_dump($data, '--');
  6359. if ($data['status'] == 1) {
  6360. $this->sendMessage([
  6361. 'talk_type' => 400,
  6362. 'title' => $data['title'],
  6363. 'content' => '提交了审核',
  6364. 'messageType' => 7,
  6365. ]);
  6366. }
  6367. $result = Book::insertGetId($data);
  6368. if (empty($result)) {
  6369. return Result::error("添加失败", 0);
  6370. }
  6371. return Result::success($result);
  6372. }
  6373. public function getBookList(array $data): array
  6374. {
  6375. $where = [];
  6376. if (!empty($data["title"])) {
  6377. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6378. }
  6379. if (!empty($data['website_name'])) {
  6380. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6381. }
  6382. if (!empty($data['status'])) {
  6383. $where[] = ['book.status', '=', $data['status']];
  6384. }
  6385. $user_id = $data['user_id'];
  6386. $type_id = $data['type_id'];
  6387. // $type_id = 4;
  6388. var_dump($type_id, '------1--------');
  6389. if ($type_id != 10000) {
  6390. $where[] = ['book.user_id', '=', $user_id];
  6391. }
  6392. var_dump(!empty($data['status1']), '=-===1');
  6393. $result = Book::where($where)
  6394. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6395. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6396. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6397. ->when(isset($data['status1']), function ($query) use ($data) {
  6398. $query->whereIn('book.status', [1, 3]);
  6399. })
  6400. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6401. ->orderBy("updated_at", "desc")
  6402. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6403. if (empty($result)) {
  6404. return Result::error("暂无数据", 0);
  6405. }
  6406. // 取出数据
  6407. $rows = $result->items();
  6408. $count = $result->total();
  6409. $responseData = [
  6410. 'rows' => $rows,
  6411. 'count' => $count,
  6412. ];
  6413. return Result::success($responseData);
  6414. }
  6415. public function deleteBook(array $data): array
  6416. {
  6417. $result = Book::where('id', $data['id'])->delete();
  6418. if (empty($result)) {
  6419. return Result::error("删除失败", 0);
  6420. }
  6421. return Result::success($result);
  6422. }
  6423. public function updateBook(array $data): array
  6424. {
  6425. // $user_id = $data['user_id'] ?? 0;
  6426. $type_id = $data['type_id'] ?? 0;
  6427. // $website_id = $data['website_id'] ?? 0;
  6428. unset($data['user_id']);
  6429. unset($data['type_id']);
  6430. // unset($data['website_id']);
  6431. //处理数组
  6432. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6433. if ($data['img_url'] == '') {
  6434. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6435. preg_match_all($reg, $data['detail'], $matches);
  6436. if (isset($matches[1][0])) {
  6437. //截取varchar240
  6438. $data['img_url'] = substr($matches[1][0], 0, 240);
  6439. }
  6440. }
  6441. if ($data['keyword'] == '') {
  6442. //提取标题+内容中的关键词
  6443. $data['keyword'] = $data['title'];
  6444. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6445. Jieba::init(); // 初始化 jieba-php
  6446. Finalseg::init();
  6447. $segList = Jieba::cut($data['keyword']);
  6448. $segList1 = array_slice($segList, 0, 8);
  6449. $data['keyword'] = implode(',', $segList1);
  6450. }
  6451. if ($data['description'] == '') {
  6452. //提取内容中的描述
  6453. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6454. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6455. }
  6456. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6457. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6458. if ($data['status'] == 1) {
  6459. $this->sendMessage([
  6460. 'talk_type' => 400,
  6461. 'title' => $data['title'],
  6462. 'content' => '提交了审核',
  6463. 'messageType' => 7,
  6464. ]);
  6465. }
  6466. $result = Book::where("id", $data["id"])->update($data);
  6467. if (empty($result)) {
  6468. return Result::error("更新失败", 0);
  6469. }
  6470. return Result::success($result);
  6471. }
  6472. public function getBookInfo(array $data): array
  6473. {
  6474. $result = Book::where("id", $data["id"])->first();
  6475. if (empty($result)) {
  6476. return Result::error("获取失败", 0);
  6477. }
  6478. return Result::success($result);
  6479. }
  6480. public function updateBookStatus(array $data): array
  6481. {
  6482. //审核
  6483. unset($data['user_id']);
  6484. $bookInfo = Book::where("id", $data["id"])->first();
  6485. var_dump($bookInfo, '----');
  6486. if ($data['status'] == 2) {
  6487. $this->sendMessage([
  6488. 'talk_type' => 401,
  6489. 'title' => $bookInfo['title'],
  6490. 'content' => '审核通过',
  6491. 'messageType' => 7,
  6492. 'user_id' => $bookInfo['user_id'],
  6493. ]);
  6494. }
  6495. if ($data['status'] == 3) {
  6496. $this->sendMessage([
  6497. 'talk_type' => 401,
  6498. 'title' => $bookInfo['title'],
  6499. 'content' => '审核拒绝',
  6500. 'messageType' => 7,
  6501. 'user_id' => $bookInfo['user_id'],
  6502. ]);
  6503. }
  6504. if ($data['status'] == 1) {
  6505. $this->sendMessage([
  6506. 'talk_type' => 400,
  6507. 'title' => $bookInfo['title'],
  6508. 'content' => '提交了审核',
  6509. 'messageType' => 7,
  6510. // 'user_id'=>$bookInfo['user_id'],
  6511. ]);
  6512. }
  6513. $result = Book::where("id", $data["id"])->update($data);
  6514. if (empty($result)) {
  6515. return Result::error("更新失败", 0);
  6516. }
  6517. return Result::success($result);
  6518. }
  6519. //20250422 书刊音像
  6520. /**
  6521. * 贴身宝贝
  6522. * @param array $data
  6523. * @return array
  6524. */
  6525. public function getWebsiteTsbb(array $data): array
  6526. {
  6527. $month = $data['month'] ?? date('m');
  6528. $day = $data['day'] ?? date('d');
  6529. // 使用缓存键
  6530. $cacheKey = "tsbb_data_{$month}_{$day}";
  6531. // 尝试从缓存获取数据
  6532. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6533. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6534. if ($cachedData = $cache->get($cacheKey)) {
  6535. return Result::success(unserialize($cachedData));
  6536. }
  6537. //查询老黄历
  6538. try {
  6539. $date = date('Y-m-d');
  6540. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6541. // 使用 curl 替代 file_get_contents
  6542. $ch = curl_init();
  6543. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6544. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6545. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6546. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6547. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6548. 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');
  6549. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6550. 'Accept: application/json',
  6551. 'Content-Type: application/json',
  6552. 'Referer: https://www.36jxs.com/'
  6553. ]);
  6554. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6555. curl_setopt($ch, CURLOPT_ENCODING, '');
  6556. $almanacResponse = curl_exec($ch);
  6557. var_dump("====:", $almanacResponse);
  6558. if (curl_errno($ch)) {
  6559. var_dump('Curl error:', curl_error($ch));
  6560. throw new \Exception('Curl error: ' . curl_error($ch));
  6561. }
  6562. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6563. curl_close($ch);
  6564. if ($almanacResponse === false) {
  6565. throw new \Exception('Failed to fetch almanac data');
  6566. }
  6567. $almanacData = json_decode($almanacResponse, true);
  6568. if (json_last_error() !== JSON_ERROR_NONE) {
  6569. throw new \Exception('Failed to parse almanac data');
  6570. }
  6571. $almanacInfo = $almanacData['data'] ?? [];
  6572. } catch (\Exception $e) {
  6573. var_dump('Exception:', $e->getMessage());
  6574. $almanacInfo = [];
  6575. }
  6576. // 获取历史上的今天数据
  6577. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6578. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6579. ->orderBy('year', 'asc')
  6580. ->select("title", "id", "year", DB::raw('1 as type'))
  6581. ->limit(16)
  6582. ->get();
  6583. // 获取节日数据 - 从今天开始获取未来4条
  6584. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6585. ->orderBy('showtime', 'asc')
  6586. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6587. ->limit(16)
  6588. ->get();
  6589. //说文解字
  6590. $chartacterList = Character::orderBy('updated_at', 'desc')
  6591. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6592. ->limit(6)
  6593. ->get();
  6594. //谜语沙龙
  6595. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6596. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6597. ->limit(4)
  6598. ->get();
  6599. //成语欣赏
  6600. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6601. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6602. ->limit(32)
  6603. ->get();
  6604. //名联赏析
  6605. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6606. ->select("id", "first", "second", DB::raw('6 as type'))
  6607. ->limit(6)
  6608. ->get();
  6609. // 获取分类文章数据
  6610. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6611. ->pluck('category_id')
  6612. ->toArray();
  6613. $articlesList = [];
  6614. foreach ($categoryIds as $catid) {
  6615. // 先查有图片的
  6616. $withImg = DB::table('article')
  6617. ->where('status', 1)
  6618. ->where('catid', $catid)
  6619. ->whereNotNull('imgurl')
  6620. ->where('imgurl', '!=', '')
  6621. ->orderBy('updated_at', 'desc')
  6622. ->limit(6)
  6623. ->get();
  6624. $count = $withImg->count();
  6625. if ($count < 6) {
  6626. // 不足6条再查无图片的补足
  6627. $withoutImg = DB::table('article')
  6628. ->where('status', 1)
  6629. ->where('catid', $catid)
  6630. ->where(function ($q) {
  6631. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6632. })
  6633. ->orderBy('updated_at', 'desc')
  6634. ->limit(6 - $count)
  6635. ->get();
  6636. $articles = $withImg->concat($withoutImg);
  6637. } else {
  6638. $articles = $withImg;
  6639. }
  6640. // 组装
  6641. $category = \App\Model\Category::find($catid);
  6642. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6643. $articlesList[] = [
  6644. 'category_name' => $category ? $category->name : '',
  6645. 'catid' => $catid,
  6646. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6647. 'type' => 100,
  6648. 'list' => $articles->map(function ($item) {
  6649. return [
  6650. 'id' => $item->id,
  6651. 'title' => $item->title,
  6652. 'imgurl' => $item->imgurl,
  6653. 'created_at' => $item->created_at
  6654. ];
  6655. })->values()
  6656. ];
  6657. }
  6658. $result = [
  6659. 'almanac' => $almanacInfo,
  6660. 'historyTodayList' => [
  6661. 'category_name' => '历史上的今天',
  6662. 'list' => $historyTodayList,
  6663. 'type' => 1
  6664. ],
  6665. 'festivalList' => [
  6666. 'category_name' => '节日预告',
  6667. 'list' => $festivalList,
  6668. 'type' => 2
  6669. ],
  6670. 'chartacterList' => [
  6671. 'category_name' => '说文解字',
  6672. 'list' => $chartacterList,
  6673. 'type' => 3
  6674. ],
  6675. 'coupletList' => [
  6676. 'category_name' => '名联赏析',
  6677. 'list' => $coupletList,
  6678. 'type' => 6
  6679. ],
  6680. 'riddletList' => [
  6681. 'category_name' => '谜语沙龙',
  6682. 'list' => $riddletList,
  6683. 'type' => 4
  6684. ],
  6685. 'idiomList' => [
  6686. 'category_name' => '成语欣赏',
  6687. 'list' => $idiomList,
  6688. 'type' => 5
  6689. ],
  6690. 'articlesList' => $articlesList
  6691. ];
  6692. // 缓存结果,设置1小时过期
  6693. $cache->set($cacheKey, serialize($result), 3600);
  6694. return Result::success($result);
  6695. }
  6696. /**
  6697. * 获取资讯列表
  6698. */
  6699. public function getWebsiteTsbbList(array $data): array
  6700. {
  6701. $page = $data['page'] ?? 1;
  6702. $pageSize = $data['pageSize'] ?? 10;
  6703. // 如果没有传入月份和日期,则使用今天的日期
  6704. $month = $data['month'] ?? date('m');
  6705. $day = $data['day'] ?? date('d');
  6706. $total = 0;
  6707. $result = [];
  6708. $data['type'] = intval($data['type']);
  6709. var_dump("接收参数:", $data);
  6710. switch ($data['type']) {
  6711. case 1:
  6712. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6713. // 当前月份之后的数据
  6714. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6715. // 或者当前月份且日期大于等于当前日期的数据
  6716. ->orWhere(function ($q) use ($month, $day) {
  6717. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6718. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6719. });
  6720. })
  6721. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6722. $total = $query->count();
  6723. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6724. ->offset(($page - 1) * $pageSize)
  6725. ->limit($pageSize)
  6726. ->get();
  6727. break;
  6728. case 2:
  6729. $query = Festival::where(function ($q) use ($month, $day) {
  6730. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6731. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6732. ->orWhere(function ($q) use ($month, $day) {
  6733. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6734. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6735. });
  6736. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6737. $total = $query->count();
  6738. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6739. ->offset(($page - 1) * $pageSize)
  6740. ->limit($pageSize)
  6741. ->get();
  6742. break;
  6743. case 3:
  6744. $query = Character::orderBy("updated_at", "desc");
  6745. $total = $query->count();
  6746. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6747. ->offset(($page - 1) * $pageSize)
  6748. ->limit($pageSize)
  6749. ->get();
  6750. break;
  6751. case 4:
  6752. $query = Riddle::orderBy("updated_at", "desc");
  6753. $total = $query->count();
  6754. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6755. ->offset(($page - 1) * $pageSize)
  6756. ->limit($pageSize)
  6757. ->get();
  6758. break;
  6759. case 5:
  6760. $query = Idiom::orderBy("updated_at", "desc");
  6761. $total = $query->count();
  6762. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6763. ->offset(($page - 1) * $pageSize)
  6764. ->limit($pageSize)
  6765. ->get();
  6766. break;
  6767. case 6:
  6768. $query = Couplet::orderBy("updated_at", "desc");
  6769. $total = $query->count();
  6770. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6771. ->offset(($page - 1) * $pageSize)
  6772. ->limit($pageSize)
  6773. ->get();
  6774. break;
  6775. default:
  6776. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6777. $total = $query->count();
  6778. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6779. ->offset(($page - 1) * $pageSize)
  6780. ->limit($pageSize)
  6781. ->get();
  6782. }
  6783. return Result::success([
  6784. 'list' => $result,
  6785. 'total' => $total,
  6786. 'page' => (int)$page,
  6787. 'pageSize' => (int)$pageSize,
  6788. 'month' => $month,
  6789. 'day' => $day
  6790. ]);
  6791. }
  6792. /**
  6793. * 1:历史上的今天
  6794. * 2:节日
  6795. * 3:文章
  6796. *
  6797. * 资讯详情信息
  6798. */
  6799. public function getWebsiteTsbbDetail(array $data): array
  6800. {
  6801. $data['type'] = intval($data['type']);
  6802. switch ($data['type']) {
  6803. case 1:
  6804. $result = HistoryToday::where("id", $data['id'])->first();
  6805. break;
  6806. case 2:
  6807. $result = Festival::where("id", $data['id'])->first();
  6808. break;
  6809. case 3:
  6810. $result = Character::where("id", $data['id'])->first();
  6811. break;
  6812. case 4:
  6813. $result = Riddle::where("id", $data['id'])->first();
  6814. break;
  6815. case 5:
  6816. $result = Idiom::where("id", $data['id'])->first();
  6817. break;
  6818. case 6:
  6819. $result = Couplet::where("id", $data['id'])->first();
  6820. break;
  6821. default:
  6822. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6823. break;
  6824. }
  6825. return Result::success($result);
  6826. }
  6827. /**
  6828. * 农网导航首页数据
  6829. */
  6830. public function getWebsiteNwHomeList(array $data): array
  6831. {
  6832. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6833. ->pluck('category_id')
  6834. ->toArray();
  6835. // 使用子查询优化
  6836. $articlesList = DB::table('article')
  6837. ->select([
  6838. 'article.id',
  6839. 'article.title',
  6840. 'article.imgurl',
  6841. 'article.created_at',
  6842. 'category.name as category_name',
  6843. 'category.id as category_id',
  6844. 'website_category.aLIas_pinyin as pinyin',
  6845. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6846. DB::raw('100 as type')
  6847. ])
  6848. ->join('category', 'article.catid', '=', 'category.id')
  6849. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6850. ->leftJoin('website_category as parent_wc', function ($join) {
  6851. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6852. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6853. })
  6854. ->where('website_category.website_id', $data['website_id'])
  6855. ->where('article.status', 1)
  6856. ->whereIn('category.id', $categoryIds)
  6857. ->orderBy('article.created_at', 'desc')
  6858. ->get()
  6859. ->groupBy('category_id')
  6860. ->map(function ($group) {
  6861. // 确保第一条数据有图片
  6862. $firstWithImage = $group->first(function ($item) {
  6863. return !empty($item->imgurl);
  6864. });
  6865. if ($firstWithImage) {
  6866. // 如果有带图片的文章,将其放在第一位
  6867. $group = $group->filter(function ($item) use ($firstWithImage) {
  6868. return $item->id !== $firstWithImage->id;
  6869. })->prepend($firstWithImage);
  6870. }
  6871. return [
  6872. 'category_name' => $group->first()->category_name,
  6873. 'catid' => $group->first()->category_id,
  6874. 'pinyin' => $group->first()->pinyin,
  6875. 'parent_pinyin' => $group->first()->parent_pinyin,
  6876. 'list' => $group->take(4)->map(function ($item) {
  6877. return [
  6878. 'id' => $item->id,
  6879. 'title' => $item->title,
  6880. ];
  6881. })->values()
  6882. ];
  6883. })
  6884. ->values()
  6885. ->toArray();
  6886. return Result::success($articlesList);
  6887. }
  6888. /**
  6889. * 企业管理
  6890. * @param array $data
  6891. * @return array
  6892. */
  6893. public function getCompanyList(array $data): array
  6894. {
  6895. // return Result::success($data);
  6896. $where = [];
  6897. $user = User::where('id', $data['user_id'])->first();
  6898. if (empty($user)) {
  6899. return Result::error('用户不存在!');
  6900. }
  6901. if ($user['type_id'] != 10000) {
  6902. $where['user_id'] = $data['user_id'];
  6903. }
  6904. if (isset($data['title']) && !empty($data['title'])) {
  6905. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6906. }
  6907. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6908. array_push($where, ['website.id', $data['website_id']]);
  6909. }
  6910. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6911. if ($data['ischeck'] == 1) {
  6912. if (isset($data['status']) && $data['status'] != '') {
  6913. array_push($where, ['company.status', $data['status']]);
  6914. $query = Company::where($where);
  6915. } else {
  6916. $query = Company::whereIn('company.status', [0, 2]);
  6917. }
  6918. } else {
  6919. $query = Company::where('company.status', 1);
  6920. }
  6921. }
  6922. $result = $query->where($where)
  6923. ->leftJoin('website_category', function ($query) {
  6924. $query->on('website_category.category_id', '=', 'company.category_id')
  6925. ->on('website_category.website_id', '=', 'company.website_id');
  6926. })
  6927. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6928. ->select(
  6929. 'company.id',
  6930. 'company.title',
  6931. 'company.website_id',
  6932. 'company.category_id',
  6933. 'website.website_name',
  6934. 'website_category.alias as category_name',
  6935. 'company.status',
  6936. 'company.updated_at',
  6937. 'company.user_id'
  6938. )
  6939. ->orderBy('company.updated_at', 'desc')
  6940. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6941. if ($result->isEmpty()) {
  6942. return Result::error("暂无企业", 0);
  6943. }
  6944. return Result::success($result);
  6945. }
  6946. /**
  6947. * 添加企业
  6948. * @param array $data
  6949. * @return array
  6950. */
  6951. public function addCompany(array $data): array
  6952. {
  6953. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6954. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6955. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6956. $data['cat_arr_id'] = json_encode($car_arr_id);
  6957. } else {
  6958. $data['cat_arr_id'] = '';
  6959. }
  6960. if ($data['imgurl'] == '') {
  6961. //content中提取图片第一个图,正则提取
  6962. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6963. preg_match_all($reg, $data['content'], $matches);
  6964. if (isset($matches[1][0])) {
  6965. //截取varchar240
  6966. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6967. }
  6968. }
  6969. if ($data['keyword'] == '') {
  6970. //提取标题+内容中的关键词
  6971. $data['keyword'] = $data['title'];
  6972. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6973. Jieba::init(); // 初始化 jieba-php
  6974. Finalseg::init();
  6975. $segList = Jieba::cut($data['keyword']);
  6976. $segList1 = array_slice($segList, 0, 8);
  6977. $data['keyword'] = implode(',', $segList1);
  6978. }
  6979. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6980. //提取内容中的描述
  6981. $content = $data['content'];
  6982. // 去除 <style> 和 <script> 标签及其内容
  6983. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6984. // 去除所有 HTML 标签
  6985. $content = strip_tags($content);
  6986. // 去除 HTML 实体
  6987. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6988. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6989. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6990. // 去除多余空白
  6991. $content = preg_replace('/\s+/u', '', $content);
  6992. // 截取 100 个字符
  6993. $data['introduce'] = mb_substr($content, 0, 100);
  6994. }
  6995. $user = User::where('id', $data['user_id'])->first();
  6996. if (empty($user)) {
  6997. return Result::error('用户不存在!');
  6998. }
  6999. if ($user['type_id'] == 10000) {
  7000. $data['status'] = 1;
  7001. }
  7002. if (isset($data['level']) && $data['level'] != null) {
  7003. $data['level'] = intval($data['level']);
  7004. } else {
  7005. $data['level'] = null;
  7006. }
  7007. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7008. $this->sendMessage([
  7009. 'talk_type' => 900,
  7010. 'title' => $data['title'],
  7011. 'content' => '提交了审核',
  7012. 'messageType' => 8,
  7013. ]);
  7014. }
  7015. $result = Company::insertGetId($data);
  7016. if ($result) {
  7017. return Result::success($result);
  7018. } else {
  7019. return Result::error('添加失败');
  7020. }
  7021. }
  7022. /**
  7023. * 更新企业
  7024. * @param array $data
  7025. * @return array
  7026. */
  7027. public function upCompany(array $data): array
  7028. {
  7029. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7030. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7031. $data['cat_arr_id'] = json_encode($car_arr_id);
  7032. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7033. } else {
  7034. $data['cat_arr_id'] = '';
  7035. }
  7036. if ($data['imgurl'] == '') {
  7037. //content中提取图片第一个图,正则提取
  7038. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7039. preg_match_all($reg, $data['content'], $matches);
  7040. if (isset($matches[1][0])) {
  7041. //截取varchar
  7042. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7043. }
  7044. }
  7045. if ($data['keyword'] == '') {
  7046. //提取标题+内容中的关键词
  7047. $data['keyword'] = $data['title'];
  7048. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7049. Jieba::init(); // 初始化 jieba-php
  7050. Finalseg::init();
  7051. $segList = Jieba::cut($data['keyword']);
  7052. $segList1 = array_slice($segList, 0, 8);
  7053. $data['keyword'] = implode(',', $segList1);
  7054. }
  7055. if ($data['introduce'] == '') {
  7056. //提取内容中的描述
  7057. $content = $data['content'];
  7058. // 去除 <style> 和 <script> 标签及其内容
  7059. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7060. // 去除所有 HTML 标签
  7061. $content = strip_tags($content);
  7062. // 去除 HTML 实体
  7063. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7064. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7065. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7066. // 去除多余空白
  7067. $content = preg_replace('/\s+/u', '', $content);
  7068. // 截取 100 个字符
  7069. $data['introduce'] = mb_substr($content, 0, 100);
  7070. }
  7071. if (isset($data['level']) && $data['level'] != null) {
  7072. $data['level'] = intval($data['level']);
  7073. } else {
  7074. $data['level'] = null;
  7075. }
  7076. $user = User::where('id', $data['user_id'])->first();
  7077. if (empty($user)) {
  7078. return Result::error('用户不存在!');
  7079. }
  7080. if ($user['type_id'] == 10000) {
  7081. $data['status'] = 1;
  7082. } else {
  7083. $data['status'] = 0;
  7084. }
  7085. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7086. $this->sendMessage([
  7087. 'talk_type' => 900,
  7088. 'title' => $data['title'],
  7089. 'content' => '提交了审核',
  7090. 'messageType' => 8,
  7091. ]);
  7092. }
  7093. $result = Company::where('id', $data['id'])->update($data);
  7094. if ($result) {
  7095. return Result::success($result);
  7096. } else {
  7097. return Result::error('修改失败');
  7098. }
  7099. }
  7100. /**
  7101. * 删除企业
  7102. * @param array $data
  7103. * @return array
  7104. */
  7105. public function delCompany(array $data): array
  7106. {
  7107. $result = Company::where('id', $data['id'])->delete();
  7108. if ($result) {
  7109. return Result::success($result);
  7110. } else {
  7111. return Result::error('删除失败');
  7112. }
  7113. }
  7114. /**
  7115. * 审核企业
  7116. * @param array $data
  7117. * @return array
  7118. */
  7119. public function checkCompany(array $data): array
  7120. {
  7121. $user = User::where('id', $data['user_id'])->first();
  7122. if (empty($user)) {
  7123. return Result::error('用户不存在!');
  7124. }
  7125. $company = Company::where('id', $data['id'])->first();
  7126. if (empty($company)) {
  7127. return Result::error('企业不存在!');
  7128. }
  7129. // 状态:0:未审核 1:已审核 2:已拒绝
  7130. if ($data['status'] == 2 || $data['status'] == '2') {
  7131. $this->sendMessage([
  7132. 'talk_type' => 901,
  7133. 'title' => $company['title'],
  7134. 'content' => '审核拒绝',
  7135. 'messageType' => 8,
  7136. 'user_id' => $company['user_id'],
  7137. ]);
  7138. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7139. } else {
  7140. if ($data['status'] == 1) {
  7141. $this->sendMessage([
  7142. 'talk_type' => 901,
  7143. 'title' => $company['title'],
  7144. 'content' => '审核通过',
  7145. 'messageType' => 8,
  7146. 'user_id' => $company['user_id'],
  7147. ]);
  7148. } else if ($data['status'] == 0) {
  7149. $this->sendMessage([
  7150. 'talk_type' => 900,
  7151. 'title' => $company['title'],
  7152. 'content' => '提交了审核',
  7153. 'messageType' => 8,
  7154. ]);
  7155. }
  7156. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7157. }
  7158. if (empty($result)) {
  7159. return Result::error('审核失败!');
  7160. } else {
  7161. return Result::success($result);
  7162. }
  7163. }
  7164. /**
  7165. * 获取企业信息
  7166. * @param array $data
  7167. * @return array
  7168. */
  7169. public function getCompanyInfo(array $data): array
  7170. {
  7171. $result = Company::where('id', $data['id'])->first();
  7172. $city_arr = json_decode($result['city_arr_id']);
  7173. $result['city_name'] = District::whereIn('id', $city_arr)
  7174. ->pluck('name')
  7175. ->implode('-');
  7176. if (empty($result)) {
  7177. return Result::error('企业不存在!');
  7178. } else {
  7179. return Result::success($result);
  7180. }
  7181. }
  7182. /**
  7183. * @param array $data
  7184. * @return array
  7185. */
  7186. public function getWebsiteCompany(array $data): array
  7187. {
  7188. $categorys = json_decode($data['id'], true);
  7189. $category_arr = $this->processArticlePro($data['website_id']);
  7190. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7191. $catiall = $category_arr['catiall'];
  7192. $categoryIds = $category_arr['categoryIds'];
  7193. // return Result::success($category_arr);
  7194. foreach ($categorys as $key => $value) {
  7195. if (array_key_exists('level', $value)) {
  7196. $parts = explode(',', $value['level']);
  7197. $level = $parts[0] ?? null;
  7198. $imgnum = $parts[1] ?? null;
  7199. $textnum = $parts[2] ?? null;
  7200. if (!empty($textnum) && $textnum > 0) {
  7201. $text_num = Company::where('level', $level)
  7202. ->whereIn('category_id', $categoryIds)
  7203. ->where('status', 1)
  7204. ->select(
  7205. 'company.id',
  7206. 'company.title',
  7207. 'company.description',
  7208. 'company.updated_at',
  7209. 'company.category_id',
  7210. 'company.cat_arr_id'
  7211. )
  7212. ->orderBy('updated_at', 'desc')
  7213. ->limit($textnum)
  7214. ->get()->all();
  7215. }
  7216. if (!empty($imgnum) && $imgnum > 0) {
  7217. $img_num = Company::where('level', $level)
  7218. ->whereIn('category_id', $categoryIds)
  7219. ->where('status', 1)
  7220. ->where('imgurl', '!=', '')
  7221. ->whereNotNull('imgurl')
  7222. ->select(
  7223. 'company.id',
  7224. 'company.title',
  7225. 'company.description',
  7226. 'company.updated_at',
  7227. 'company.imgurl as imgs',
  7228. 'company.category_id',
  7229. 'company.cat_arr_id'
  7230. )
  7231. ->orderBy('updated_at', 'desc')
  7232. ->limit($imgnum)
  7233. ->get()->all();
  7234. }
  7235. }
  7236. if (array_key_exists('id', $value)) {
  7237. $parts = explode(',', $value['id']);
  7238. $category_id = $parts[0] ?? null;
  7239. $imgnum = $parts[1] ?? null;
  7240. $textnum = $parts[2] ?? null;
  7241. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7242. if (!empty($textnum) && $textnum > 0) {
  7243. $text_num = Company::whereIn('category_id', $category_arr)
  7244. // ->where('website_id', $data['website_id'])
  7245. ->where('status', 1)
  7246. ->select(
  7247. 'company.id',
  7248. 'company.title',
  7249. 'company.description',
  7250. 'company.updated_at',
  7251. 'company.category_id',
  7252. 'company.cat_arr_id'
  7253. )
  7254. ->orderBy('updated_at', 'desc')
  7255. ->limit($textnum)
  7256. ->get()->all();
  7257. }
  7258. if (!empty($imgnum) && $imgnum > 0) {
  7259. $img_num = Company::whereIn('category_id', $category_arr)
  7260. // ->where('website_id', $data['website_id'])
  7261. ->where('status', 1)
  7262. ->where('imgurl', '!=', '')
  7263. ->whereNotNull('imgurl')
  7264. ->select(
  7265. 'company.id',
  7266. 'company.title',
  7267. 'company.description',
  7268. 'company.updated_at',
  7269. 'company.imgurl as imgs',
  7270. 'company.category_id',
  7271. 'company.cat_arr_id'
  7272. )
  7273. ->orderBy('updated_at', 'desc')
  7274. ->limit($imgnum)
  7275. ->get()->all();
  7276. }
  7277. }
  7278. if (!empty($text_num)) {
  7279. foreach ($text_num as $k => $v) {
  7280. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7281. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7282. }
  7283. }
  7284. if (!empty($img_num)) {
  7285. foreach ($img_num as $k => $v) {
  7286. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7287. $imgurl = json_decode($v['imgs'], true);
  7288. if (!empty($imgurl)) {
  7289. $img_num[$k]->imgurl = $imgurl[0];
  7290. }
  7291. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7292. }
  7293. }
  7294. $company[$key]['img_num'] = $img_num ?? [];
  7295. $company[$key]['text_num'] = $text_num ?? [];
  7296. }
  7297. if (empty($company)) {
  7298. return Result::error("暂无相关企业信息", 0);
  7299. }
  7300. return Result::success($company);
  7301. }
  7302. /**
  7303. * @param array $data
  7304. * @return array
  7305. */
  7306. public function getWebsiteCompanyList(array $data): array
  7307. {
  7308. $where['website_id'] = $data['website_id'];
  7309. $where['status'] = 1;
  7310. $categoryIds = [];
  7311. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7312. $category_id = $data['category_id'];
  7313. }
  7314. $category_arr = $this->processArticlePro($data['website_id']);
  7315. $categoryIds = $category_arr['categoryIds'];
  7316. // return Result::success($cat_1st_arr);
  7317. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7318. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7319. })
  7320. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7321. $query->whereIn('category_id', $categoryIds);
  7322. })
  7323. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7324. $query->where('category_id', $category_id);
  7325. })
  7326. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7327. ->orderBy('updated_at', 'desc')
  7328. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7329. if (empty($company)) {
  7330. return Result::error("暂无相关公司信息", 0);
  7331. }
  7332. $result = [
  7333. 'count' => $company->total(),
  7334. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7335. ];
  7336. return Result::success($result);
  7337. }
  7338. /**
  7339. * 获取项目列表
  7340. * @param array $data
  7341. * @return array
  7342. */
  7343. public function getProjectList(array $data): array
  7344. {
  7345. $where = [];
  7346. $user = User::where('id', $data['user_id'])->first();
  7347. if (empty($user)) {
  7348. return Result::error('用户不存在!');
  7349. }
  7350. if ($user->type_id != 10000) {
  7351. array_push($where, ['project.user_id', $data['user_id']]);
  7352. }
  7353. $query = Project::query();
  7354. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7355. array_push($where, ['project.website_id', $data['website_id']]);
  7356. }
  7357. if (isset($data['title']) && !empty($data['title'])) {
  7358. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7359. }
  7360. if ($data['status'] != 3) {
  7361. array_push($where, ['project.status', $data['status']]);
  7362. }
  7363. $query = Project::where($where)
  7364. ->when($data['status'] == 3, function ($query) {
  7365. $query->whereIn('project.status', [0, 2]);
  7366. });
  7367. $count = $query->clone()
  7368. ->count();
  7369. $rows = $query->clone()
  7370. ->leftJoin('website', 'project.website_id', 'website.id')
  7371. ->leftJoin('website_category', function ($join) {
  7372. $join->on('project.website_id', '=', 'website_category.website_id')
  7373. ->on('project.category_id', '=', 'website_category.category_id');
  7374. })
  7375. ->select(
  7376. 'project.id',
  7377. 'project.title',
  7378. 'project.updated_at',
  7379. 'project.status',
  7380. 'website.website_name',
  7381. 'website_category.alias as category_name',
  7382. 'project.website_id',
  7383. 'project.user_id'
  7384. )
  7385. ->orderBy('project.updated_at', 'desc')
  7386. ->offset(($data['page'] - 1) * $data['pageSize'])
  7387. ->limit($data['pageSize'])
  7388. ->get();
  7389. if ($rows->isEmpty()) {
  7390. return Result::error("暂无相关项目信息", 0);
  7391. }
  7392. $result = [
  7393. 'count' => $count,
  7394. 'rows' => $rows,
  7395. ];
  7396. return Result::success($result);
  7397. }
  7398. /**
  7399. * 添加项目
  7400. * @param array $data
  7401. * @return array
  7402. */
  7403. public function addProject(array $data): array
  7404. {
  7405. $user = User::where('id', $data['user_id'])->first();
  7406. if (empty($user)) {
  7407. return Result::error("暂无相关用户信息", 0);
  7408. }
  7409. if ($user->type_id == 10000) {
  7410. $data['status'] = 1;
  7411. } else {
  7412. $data['status'] = 0;
  7413. }
  7414. if ($data['keyword'] == '') {
  7415. //提取标题+内容中的关键词
  7416. $data['keyword'] = $data['title'];
  7417. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7418. Jieba::init(); // 初始化 jieba-php
  7419. Finalseg::init();
  7420. $segList = Jieba::cut($data['keyword']);
  7421. $segList1 = array_slice($segList, 0, 8);
  7422. $data['keyword'] = implode(',', $segList1);
  7423. }
  7424. if ($data['description'] == '') {
  7425. //提取内容中的描述
  7426. // var_dump(11111);
  7427. //提取内容中的描述
  7428. $content = $data['introduce'];
  7429. // 去除 <style> 和 <script> 标签及其内容
  7430. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7431. // 去除所有 HTML 标签
  7432. $content = strip_tags($content);
  7433. // 去除 HTML 实体
  7434. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7435. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7436. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7437. // 去除多余空白
  7438. $content = preg_replace('/\s+/u', '', $content);
  7439. // 截取 100 个字符
  7440. $data['description'] = mb_substr($content, 0, 100);
  7441. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7442. }
  7443. if ($data['status'] == 0) {
  7444. $this->sendMessage([
  7445. 'talk_type' => 1000,
  7446. 'title' => $data['title'],
  7447. 'content' => '提交了审核',
  7448. 'messageType' => 9,
  7449. ]);
  7450. }
  7451. $project = Project::insertGetId($data);
  7452. if (empty($project)) {
  7453. return Result::error("暂无相关项目信息", 0);
  7454. }
  7455. return Result::success($project);
  7456. }
  7457. /**
  7458. * 更新项目
  7459. * @param array $data
  7460. * @return array
  7461. */
  7462. public function upProject(array $data): array
  7463. {
  7464. $project = Project::where('id', $data['id'])->first();
  7465. if (empty($project)) {
  7466. return Result::error("暂无相关项目信息", 0);
  7467. }
  7468. $id = $data['id'];
  7469. unset($data['id']);
  7470. $user = User::where('id', $data['user_id'])->first();
  7471. if (empty($user)) {
  7472. return Result::error("暂无相关用户信息", 0);
  7473. }
  7474. if ($user->type_id == 10000) {
  7475. $data['status'] = 1;
  7476. } else {
  7477. $data['status'] = 0;
  7478. }
  7479. unset($data['user_id']);
  7480. if ($data['keyword'] == '') {
  7481. //提取标题+内容中的关键词
  7482. $data['keyword'] = $data['title'];
  7483. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7484. Jieba::init(); // 初始化 jieba-php
  7485. Finalseg::init();
  7486. $segList = Jieba::cut($data['keyword']);
  7487. $segList1 = array_slice($segList, 0, 8);
  7488. $data['keyword'] = implode(',', $segList1);
  7489. }
  7490. if ($data['description'] == '') {
  7491. //提取内容中的描述
  7492. // var_dump(11111);
  7493. //提取内容中的描述
  7494. $content = $data['introduce'];
  7495. // 去除 <style> 和 <script> 标签及其内容
  7496. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7497. // 去除所有 HTML 标签
  7498. $content = strip_tags($content);
  7499. // 去除 HTML 实体
  7500. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7501. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7502. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7503. // 去除多余空白
  7504. $content = preg_replace('/\s+/u', '', $content);
  7505. // 截取 100 个字符
  7506. $data['description'] = mb_substr($content, 0, 100);
  7507. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7508. }
  7509. if ($data['status'] == 0) {
  7510. $this->sendMessage([
  7511. 'talk_type' => 1000,
  7512. 'title' => $data['title'],
  7513. 'content' => '提交了审核',
  7514. 'messageType' => 9,
  7515. ]);
  7516. }
  7517. $result = Project::where('id', $id)->update($data);
  7518. if (empty($result)) {
  7519. return Result::error("更新失败", 0);
  7520. }
  7521. return Result::success($result);
  7522. }
  7523. /**
  7524. * 删除项目
  7525. * @param array $data
  7526. * @return array
  7527. */
  7528. public function delProject(array $data): array
  7529. {
  7530. $user = User::where('id', $data['user_id'])->first();
  7531. if (empty($user)) {
  7532. return Result::error("暂无相关用户信息", 0);
  7533. }
  7534. $project = Project::where('id', $data['id'])->first();
  7535. if (empty($project)) {
  7536. return Result::error("暂无相关项目信息", 0);
  7537. }
  7538. $result = Project::where('id', $data['id'])->delete();
  7539. if (empty($result)) {
  7540. return Result::error("删除失败", 0);
  7541. }
  7542. return Result::success($result);
  7543. }
  7544. /**
  7545. * 审核项目
  7546. * @param array $data
  7547. * @return array
  7548. */
  7549. public function checkProject(array $data): array
  7550. {
  7551. $user = User::where('id', $data['user_id'])->first();
  7552. if (empty($user)) {
  7553. return Result::error("暂无相关用户信息", 0);
  7554. }
  7555. // 0:未审核; 1:已审核; 2:已拒绝;
  7556. if ($user->type_id != 10000) {
  7557. if ($data['status'] == 1 || $data['status'] == 2) {
  7558. return Result::error("此用户权限不足", 0);
  7559. }
  7560. }
  7561. $project = Project::where('id', $data['id'])->first();
  7562. if (empty($project)) {
  7563. return Result::error("暂无相关项目信息", 0);
  7564. }
  7565. if ($data['status'] == 2) {
  7566. $this->sendMessage([
  7567. 'talk_type' => 1001,
  7568. 'title' => $project['title'],
  7569. 'content' => '审核拒绝',
  7570. 'messageType' => 9,
  7571. 'user_id' => $project['user_id'],
  7572. ]);
  7573. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7574. } else {
  7575. if ($data['status'] == 1) {
  7576. $this->sendMessage([
  7577. 'talk_type' => 1001,
  7578. 'title' => $project['title'],
  7579. 'content' => '审核通过',
  7580. 'messageType' => 9,
  7581. 'user_id' => $project['user_id'],
  7582. ]);
  7583. } else if ($data['status'] == 0) {
  7584. $this->sendMessage([
  7585. 'talk_type' => 1000,
  7586. 'title' => $project['title'],
  7587. 'content' => '提交了审核',
  7588. 'messageType' => 9,
  7589. ]);
  7590. }
  7591. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7592. }
  7593. if (empty($result)) {
  7594. return Result::error("审核失败", 0);
  7595. }
  7596. return Result::success($result);
  7597. }
  7598. /**
  7599. * 获取项目详情
  7600. * @param array $data
  7601. * @return array
  7602. */
  7603. public function getProjectInfo(array $data): array
  7604. {
  7605. $project = Project::where('id', $data['id'])->first();
  7606. if (empty($project)) {
  7607. return Result::error("暂无相关项目信息", 0);
  7608. }
  7609. return Result::success($project);
  7610. }
  7611. public function getWebsiteCompanyInfo(array $data): array
  7612. {
  7613. $company = Company::where('id', $data['id'])
  7614. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7615. ->where('status', 1)
  7616. // ->where('website_id', $data['website_id'])
  7617. ->select('company.*', 'job_industry.hyname as hy_name')
  7618. ->first();
  7619. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7620. switch ($company->jobnature_id) {
  7621. case null:
  7622. $company->jobnature_name = '';
  7623. break;
  7624. case 0:
  7625. $company->jobnature_name = '市场监督';
  7626. break;
  7627. case 1:
  7628. $company->jobnature_name = '信访纪检';
  7629. break;
  7630. case 2:
  7631. $company->jobnature_name = '公检法司';
  7632. break;
  7633. case 3:
  7634. $company->jobnature_name = '高关注机构';
  7635. break;
  7636. default:
  7637. $company->jobnature_name = '';
  7638. break;
  7639. }
  7640. $city_arr = $company->city_arr_id;
  7641. if (!empty($city_arr)) {
  7642. $city_arr = json_decode($city_arr, true);
  7643. $cityNames = District::whereIn('id', $city_arr)
  7644. ->pluck('name')
  7645. ->implode('-');
  7646. $company->city_name = $cityNames;
  7647. } else {
  7648. $company->city_name = '';
  7649. }
  7650. if (empty($company)) {
  7651. return Result::error("暂无相关公司信息", 0);
  7652. }
  7653. return Result::success($company);
  7654. }
  7655. public function getMSG(array $data): array
  7656. {
  7657. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7658. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7659. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7660. $result = [];
  7661. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7662. //最近的5篇已审的文章
  7663. $apply_articale = Article::where('status', 1)
  7664. ->where('admin_user_id', $user_id)
  7665. ->orderBy('updated_at', 'desc')
  7666. // ->limit(5)
  7667. ->get();
  7668. //获取5条用户的已审核商品
  7669. $good = Good::where('status', 2)
  7670. ->where('user_id', $user_id)
  7671. ->orderBy('updated_at', 'desc')
  7672. // ->limit(5)
  7673. ->get();
  7674. //获取5条用户待审核的公告
  7675. $notice = Notice::where('status', 2)
  7676. ->where('user_id', $user_id)
  7677. ->orderBy('updated_at', 'desc')
  7678. ->limit(5)->get();
  7679. //获取5条用户的待审核投诉
  7680. $complaint = Complaint::where('status', 2)
  7681. ->where('user_id', $user_id)
  7682. ->orderBy('updated_at', 'desc')
  7683. // ->limit(5)
  7684. ->get();
  7685. //获取5条用户的book
  7686. $book = Book::where('status', 2)
  7687. ->where('user_id', $user_id)
  7688. ->orderBy('updated_at', 'desc')
  7689. // ->limit(5)
  7690. ->get();
  7691. //获取5条用户的求职
  7692. //获取5条用户的求职 1
  7693. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7694. ->where('job_hunting.user_id', $user_id)
  7695. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7696. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7697. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7698. ->orderBy('updated_at', 'desc')
  7699. // ->limit(5)
  7700. ->get();
  7701. //获取5条用户的求职 2
  7702. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7703. ->where('job_recruiting.user_id', $user_id)
  7704. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7705. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7706. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7707. ->orderBy('updated_at', 'desc')
  7708. // ->limit(5)
  7709. ->get();
  7710. //人才库 1
  7711. $job_apply = JobApply::where('job_apply.status', 1)
  7712. ->where('job_apply.receiver_id', $user_id)
  7713. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7714. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7715. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7716. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7717. ->select('job_recruiting', 'job_recruiting.', '', '')
  7718. ->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')
  7719. ->orderBy('updated_at', 'desc')
  7720. // ->limit(5)
  7721. ->get();
  7722. // 职场机会 2
  7723. $job_resume = JobResume::where('job_resume.status', 1)
  7724. ->where('job_resume.receiver_id', $user_id)
  7725. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7726. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7727. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7728. ->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')
  7729. ->orderBy('updated_at', 'desc')
  7730. // ->limit(5)
  7731. ->get();
  7732. //获取5条用户待处理的投诉
  7733. $complaint_deal = Complaint::where('status', 2)
  7734. ->where('deal', 1)
  7735. ->whereJsonContains('re_user_ids', $user_id)
  7736. ->orderBy('updated_at', 'desc')
  7737. // ->limit(5)
  7738. ->get();
  7739. //获取 被通知者未读信息
  7740. $notice_unread = Notice::where('status', 2)
  7741. ->whereJsonContains('re_user_ids', $user_id)
  7742. //未读消息
  7743. ->where(function ($query) use ($user_id) {
  7744. $query->whereJsonDoesntContain('read_id', $user_id)
  7745. ->orWhereNull('read_id');
  7746. })
  7747. ->orderBy('updated_at', 'desc')
  7748. ->get();
  7749. $complaint_unread = Complaint::where('status', 2)
  7750. ->whereJsonContains('re_user_ids', $user_id)
  7751. //未读消息
  7752. ->where(function ($query) use ($user_id) {
  7753. $query->whereJsonDoesntContain('read_id', $user_id)
  7754. ->orWhereNull('read_id');
  7755. })
  7756. ->orderBy('updated_at', 'desc')
  7757. ->get();
  7758. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7759. $complany = Company::where('status', 1)
  7760. ->where('user_id', $user_id)
  7761. ->orderBy('updated_at', 'desc')
  7762. // ->limit(5)
  7763. ->get();
  7764. //获取5条单聊未读聊天消息
  7765. // $chat = ChatRecords::where('is_read', 0)
  7766. // ->where('user_id', $user_id)
  7767. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7768. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7769. // ->where('action', 'recieved')
  7770. // ->where('talk_type', 1)
  7771. // ->orderBy('created_at', 'desc')
  7772. // // ->limit(5)
  7773. // ->get();
  7774. //获取5条未读群聊信息
  7775. // $chat_group = ChatRecords::where('is_read', 0)
  7776. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7777. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7778. // ->where('user_id', $user_id)
  7779. // ->where('talk_type', 2)
  7780. // ->orderBy('created_at', 'desc')
  7781. // // ->limit(5)
  7782. // ->get();
  7783. //获取5条用户的待审核项目
  7784. $project = Project::where('status', 1)
  7785. ->where('user_id', $user_id)
  7786. ->orderBy('updated_at', 'desc')
  7787. // ->limit(5)
  7788. ->get();
  7789. // count($chat) + count($chat_group) +
  7790. $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)
  7791. + count($complany)
  7792. + count($project)
  7793. + count($notice_unread)
  7794. + count($complaint_unread)
  7795. // + count($chat) + count($chat_group)
  7796. ;
  7797. $result = [
  7798. 'apply_articale' => $apply_articale,
  7799. // 'chat' => $chat,
  7800. // 'chat_group' => $chat_group,
  7801. 'good' => $good,
  7802. 'notice' => $notice,
  7803. 'complaint' => $complaint,
  7804. 'book' => $book,
  7805. 'job_hunting' => $job_hunting,
  7806. 'job_recruiting' => $job_recruiting,
  7807. 'job_apply' => $job_apply,
  7808. 'job_resume' => $job_resume,
  7809. 'complaint_deal' => $complaint_deal,
  7810. 'complany' => $complany,
  7811. 'project' => $project,
  7812. 'notice_unread' => $notice_unread,
  7813. 'complaint_unread' => $complaint_unread,
  7814. 'count' => $count,
  7815. ];
  7816. } elseif ($type_id == 12) {
  7817. //最近的5篇已审的文章
  7818. $apply_articale = Article::where('status', 1)
  7819. ->where('admin_user_id', $user_id)
  7820. ->limit(5)->get();
  7821. //获取5条单聊未读聊天消息
  7822. $chat = ChatRecords::where('is_read', 0)
  7823. ->where('user_id', $user_id)
  7824. ->where('talk_type', 1)
  7825. ->orderBy('created_at', 'desc')
  7826. ->limit(5)->get();
  7827. //获取5条未读群聊信息
  7828. $chat_group = ChatRecords::where('is_read', 0)
  7829. ->where('user_id', $user_id)
  7830. ->where('talk_type', 2)
  7831. ->orderBy('created_at', 'desc')
  7832. ->limit(5)->get();
  7833. //获取5条用户的已审核商品
  7834. $good = Good::where('status', 2)
  7835. ->where('user_id', $user_id)
  7836. ->orderBy('updated_at', 'desc')
  7837. ->limit(5)->get();
  7838. //获取5条用户的book
  7839. $book = Book::where('status', 2)
  7840. ->where('user_id', $user_id)
  7841. ->orderBy('updated_at', 'desc')
  7842. ->limit(5)->get();
  7843. //获取5条用户的求职
  7844. //获取5条用户的求职 1
  7845. //count($chat) + count($chat_group)
  7846. $count = count($apply_articale) + count($good);
  7847. $result = [
  7848. 'apply_articale' => $apply_articale,
  7849. 'chat' => $chat,
  7850. 'chat_group' => $chat_group,
  7851. 'good' => $good,
  7852. 'book' => $book,
  7853. 'count' => $count,
  7854. ];
  7855. } elseif ($type_id == 13) {
  7856. //最近的5篇已审的文章
  7857. $apply_articale = Article::where('status', 1)
  7858. ->where('admin_user_id', $user_id)
  7859. ->limit(5)->get();
  7860. //获取5条单聊未读聊天消息
  7861. $chat = ChatRecords::where('is_read', 0)
  7862. ->where('user_id', $user_id)
  7863. ->where('talk_type', 1)
  7864. ->orderBy('created_at', 'desc')
  7865. ->limit(5)->get();
  7866. //获取5条未读群聊信息
  7867. $chat_group = ChatRecords::where('is_read', 0)
  7868. ->where('user_id', $user_id)
  7869. ->where('talk_type', 2)
  7870. ->orderBy('created_at', 'desc')
  7871. ->limit(5)->get();
  7872. //获取5条用户的已审核商品
  7873. $good = Good::where('status', 2)
  7874. ->where('user_id', $user_id)
  7875. ->orderBy('updated_at', 'desc')
  7876. ->limit(5)->get();
  7877. //count($chat) + count($chat_group) +
  7878. $count = count($apply_articale) + count($good);
  7879. $result = [
  7880. 'apply_articale' => $apply_articale,
  7881. 'chat' => $chat,
  7882. 'chat_group' => $chat_group,
  7883. 'good' => $good,
  7884. 'count' => $count,
  7885. ];
  7886. } elseif ($type_id == 14) {
  7887. //最近的5篇已审的文章
  7888. $apply_articale = Article::where('status', 1)
  7889. ->where('admin_user_id', $user_id)
  7890. // ->limit(5)
  7891. ->get();
  7892. //获取5条用户的已审核商品
  7893. $good = Good::where('status', 2)
  7894. ->where('user_id', $user_id)
  7895. ->orderBy('updated_at', 'desc')
  7896. // ->limit(5)
  7897. ->get();
  7898. $count = count($apply_articale) + count($good);
  7899. $result = [
  7900. 'apply_articale' => $apply_articale,
  7901. 'chat' => '',
  7902. 'chat_group' => '',
  7903. 'good' => $good,
  7904. 'count' => $count,
  7905. ];
  7906. } elseif ($type_id == 10000) {
  7907. //获取未审核的5篇文章
  7908. $apply_articale = Article::where('status', 0)
  7909. ->orderBy('updated_at', 'desc')
  7910. // ->limit(5)
  7911. ->get();
  7912. //获取5条单聊未读聊天消息
  7913. //获取5条单聊未读聊天消息
  7914. // $chat = ChatRecords::where('is_read', 0)
  7915. // ->where('user_id', $user_id)
  7916. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7917. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7918. // ->where('action', 'recieved')
  7919. // ->where('talk_type', 1)
  7920. // ->orderBy('created_at', 'desc')
  7921. // // ->limit(5)
  7922. // ->get();
  7923. // //获取5条未读群聊信息
  7924. // $chat_group = ChatRecords::where('is_read', 0)
  7925. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7926. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7927. // ->where('user_id', $user_id)
  7928. // ->where('talk_type', 2)
  7929. // ->orderBy('created_at', 'desc')
  7930. // // ->limit(5)
  7931. // ->get();
  7932. //获取5条用户的已审核商品
  7933. $good = Good::where('status', 1)
  7934. // ->where('user_id', $user_id)
  7935. ->orderBy('updated_at', 'desc')
  7936. // ->limit(5)
  7937. ->get();
  7938. //获取5条用户待审核的公告
  7939. $notice = Notice::where('status', 1)
  7940. ->orderBy('updated_at', 'desc')
  7941. // ->limit(5)
  7942. ->get();
  7943. //获取5条用户的待审核投诉
  7944. $complaint = Complaint::where('status', 1)
  7945. ->orderBy('updated_at', 'desc')
  7946. // ->limit(5)
  7947. ->get();
  7948. //获取5条用户的book
  7949. $book = Book::where('status', 1)
  7950. ->orderBy('updated_at', 'desc')
  7951. // ->limit(5)
  7952. ->get();
  7953. //获取5条用户的求职 1
  7954. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7955. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7956. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7957. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7958. ->orderBy('updated_at', 'desc')
  7959. // ->limit(5)
  7960. ->get();
  7961. //获取5条用户的求职 2
  7962. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7963. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7964. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7965. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7966. ->orderBy('updated_at', 'desc')
  7967. // ->limit(5)
  7968. ->get();
  7969. //人才库 1
  7970. $job_apply = JobApply::where('job_apply.status', 1)
  7971. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7972. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7973. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7974. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7975. ->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')
  7976. ->orderBy('updated_at', 'desc')
  7977. // ->limit(5)
  7978. ->get();
  7979. // 职场机会 2
  7980. $job_resume = JobResume::where('job_resume.status', 1)
  7981. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7982. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7983. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7984. ->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')
  7985. ->orderBy('updated_at', 'desc')
  7986. // ->limit(5)
  7987. ->get();
  7988. //待审核数据com pro
  7989. $complany = Company::where('status', 0)
  7990. ->orderBy('updated_at', 'desc')
  7991. // ->limit(5)
  7992. ->get();
  7993. $project = Project::where('status', 0)
  7994. ->orderBy('updated_at', 'desc')
  7995. // ->limit(5)
  7996. ->get();
  7997. $count =
  7998. // count($chat) +
  7999. // count($chat_group) +
  8000. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8001. // + count($job_apply)
  8002. // + count($job_resume)
  8003. + count($complany)
  8004. + count($project);
  8005. $result = [
  8006. 'apply_articale' => $apply_articale,
  8007. // 'chat' => $chat,
  8008. // 'chat_group' => $chat_group,
  8009. 'good' => $good,
  8010. 'notice' => $notice,
  8011. 'complaint' => $complaint,
  8012. 'book' => $book,
  8013. 'job_hunting' => $job_hunting,
  8014. 'job_recruiting' => $job_recruiting,
  8015. // 'job_apply' => $job_apply,
  8016. // 'job_resume' => $job_resume,
  8017. 'complany' => $complany,
  8018. 'project' => $project,
  8019. 'count' => $count,
  8020. ];
  8021. } elseif ($type_id == 20000) {
  8022. }
  8023. var_dump($type_id, '-----------------test---------');
  8024. return Result::success($result);
  8025. }
  8026. /**
  8027. * @param array $data
  8028. * @return array
  8029. */
  8030. public function getWebsiteProject(array $data): array
  8031. {
  8032. $categorys = json_decode($data['id'], true);
  8033. if (!empty($categorys)) {
  8034. $category_arr = $this->processArticlePro($data['website_id']);
  8035. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8036. $catiall = $category_arr['catiall'];
  8037. // return Result::success($catiall);
  8038. foreach ($categorys as $key => $val) {
  8039. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8040. $level = explode(',', $val['level'])[0];
  8041. $imgnum = explode(',', $val['level'])[1] ?? null;
  8042. $textnum = explode(',', $val['level'])[2] ?? null;
  8043. if ($level == 1) {
  8044. if (!empty($textnum) && $textnum > 0) {
  8045. $text_num = Project::where('level', $level)
  8046. ->where('website_id', $data['website_id'])
  8047. ->where('status', 1)
  8048. ->select(
  8049. 'project.id',
  8050. 'project.title',
  8051. 'project.description',
  8052. 'project.updated_at',
  8053. 'project.category_id',
  8054. 'project.cat_arr_id'
  8055. )
  8056. ->orderBy('updated_at', 'desc')
  8057. ->limit($textnum)
  8058. ->get()->all();
  8059. }
  8060. if (!empty($imgnum) && $imgnum > 0) {
  8061. $img_num = Project::where('level', $level)
  8062. ->where('website_id', $data['website_id'])
  8063. ->where('status', 1)
  8064. ->where('imgurl', '!=', '')
  8065. ->whereNotNull('imgurl')
  8066. ->select(
  8067. 'project.id',
  8068. 'project.title',
  8069. 'project.description',
  8070. 'project.updated_at',
  8071. 'project.imgurl as imgs',
  8072. 'project.category_id',
  8073. 'project.cat_arr_id'
  8074. )
  8075. ->orderBy('updated_at', 'desc')
  8076. ->limit($imgnum)
  8077. ->get()->all();
  8078. }
  8079. } else {
  8080. if (!empty($textnum) && $textnum > 0) {
  8081. $text_num = Project::where('website_id', $data['website_id'])
  8082. ->where('status', 1)
  8083. ->select(
  8084. 'project.id',
  8085. 'project.title',
  8086. 'project.description',
  8087. 'project.updated_at',
  8088. 'project.category_id',
  8089. 'project.cat_arr_id',
  8090. 'project.website_id',
  8091. 'project.updated_at',
  8092. 'project.created_at'
  8093. )
  8094. ->orderBy('updated_at', 'desc')
  8095. ->limit($textnum)
  8096. ->get()->all();
  8097. }
  8098. if (!empty($imgnum) && $imgnum > 0) {
  8099. $img_num = Project::where('website_id', $data['website_id'])
  8100. ->where('status', 1)
  8101. ->where('imgurl', '!=', '')
  8102. ->whereNotNull('imgurl')
  8103. ->select(
  8104. 'project.id',
  8105. 'project.title',
  8106. 'project.description',
  8107. 'project.updated_at',
  8108. 'project.imgurl as imgs',
  8109. 'project.category_id',
  8110. 'project.cat_arr_id'
  8111. )
  8112. ->orderBy('updated_at', 'desc')
  8113. ->limit($imgnum)
  8114. ->get()->all();
  8115. }
  8116. }
  8117. }
  8118. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8119. $category_ids = explode(',', $val['id'])[0];
  8120. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8121. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8122. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8123. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8124. $text_num = Project::whereIn('category_id', $category_arr)
  8125. ->where('website_id', $data['website_id'])
  8126. ->where('status', 1)
  8127. ->select(
  8128. 'project.id',
  8129. 'project.title',
  8130. 'project.description',
  8131. 'project.updated_at',
  8132. 'project.category_id',
  8133. 'project.cat_arr_id'
  8134. )
  8135. ->orderBy('updated_at', 'desc')
  8136. ->limit($cat_textnum)
  8137. ->get()->all();
  8138. }
  8139. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8140. $img_num = Project::whereIn('category_id', $category_arr)
  8141. ->where('website_id', $data['website_id'])
  8142. ->where('status', 1)
  8143. ->where('imgurl', '!=', '')
  8144. ->whereNotNull('imgurl')
  8145. ->select(
  8146. 'project.id',
  8147. 'project.title',
  8148. 'project.description',
  8149. 'project.updated_at',
  8150. 'project.imgurl as imgs',
  8151. 'project.category_id',
  8152. 'project.cat_arr_id'
  8153. )
  8154. ->orderBy('updated_at', 'desc')
  8155. ->limit($cat_imgnum)
  8156. ->get()->all();
  8157. }
  8158. }
  8159. if (!empty($img_num)) {
  8160. foreach ($img_num as $k => $v) {
  8161. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8162. $imgurl = json_decode($v['imgs'], true);
  8163. if (!empty($imgurl)) {
  8164. $img_num[$k]->imgurl = $imgurl[0];
  8165. }
  8166. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8167. }
  8168. }
  8169. if (!empty($text_num)) {
  8170. foreach ($text_num as $k => $v) {
  8171. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8172. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8173. }
  8174. }
  8175. $project[$key]['img_num'] = $img_num ?? [];
  8176. $project[$key]['text_num'] = $text_num ?? [];
  8177. }
  8178. }
  8179. if (empty($project)) {
  8180. return Result::error("暂无相关项目信息", 0);
  8181. }
  8182. return Result::success($project);
  8183. }
  8184. /**
  8185. * @param array $data
  8186. * @return array
  8187. */
  8188. public function getWebsiteProjectInfo(array $data): array
  8189. {
  8190. $project = Project::where('id', $data['id'])
  8191. ->where('status', 1)
  8192. ->where('website_id', $data['website_id'])
  8193. ->select('project.*')
  8194. ->first();
  8195. if (empty($project)) {
  8196. return Result::error("暂无相关项目信息", 0);
  8197. }
  8198. return Result::success($project);
  8199. }
  8200. /**
  8201. * @param array $data
  8202. * @return array
  8203. */
  8204. public function getWebsiteProjectList(array $data): array
  8205. {
  8206. $where = [];
  8207. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8208. $where['category_id'] = $data['category_id'];
  8209. }
  8210. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8211. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8212. }
  8213. $query = Project::where($where)
  8214. ->where('status', 1)
  8215. ->where('website_id', $data['website_id'])
  8216. ->select(
  8217. 'project.id',
  8218. 'project.title',
  8219. 'project.description',
  8220. 'project.imgurl as imgs',
  8221. 'project.category_id',
  8222. 'project.cat_arr_id'
  8223. )
  8224. ->orderBy('updated_at', 'desc');
  8225. $count = $query->count();
  8226. $project = $query->clone()
  8227. ->offset(($data['page'] - 1) * $data['pageSize'])
  8228. ->limit($data['pageSize'])
  8229. ->get()->all();
  8230. if (empty($project)) {
  8231. return Result::error("暂无相关项目信息", 0);
  8232. }
  8233. $categorys = $this->processArticlePro($data['website_id']);
  8234. $catiall = $categorys['catiall'];
  8235. foreach ($project as $key => $val) {
  8236. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8237. if (!empty($val['imgs'])) {
  8238. $imgurl = json_decode($val['imgs'], true);
  8239. if (!empty($imgurl)) {
  8240. $project[$key]->imgurl = $imgurl[0];
  8241. }
  8242. } else {
  8243. $project[$key]->imgurl = '';
  8244. }
  8245. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8246. }
  8247. $result = [
  8248. 'rows' => $project,
  8249. 'count' => $count,
  8250. ];
  8251. return Result::success($result);
  8252. }
  8253. /**
  8254. * @param array $data
  8255. * @return array
  8256. */
  8257. public function getWebsiteCategoryJob(array $data): array
  8258. {
  8259. $categorys = json_decode($data['id'], true);
  8260. if (!empty($categorys)) {
  8261. $category_arr = $this->processArticlePro($data['website_id']);
  8262. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8263. $catiall = $category_arr['catiall'];
  8264. foreach ($categorys as $key => $val) {
  8265. if (isset($val['id']) && !empty($val['id'])) {
  8266. $catid = explode(',', $val['id'])[0] ?? null;
  8267. $type = explode(',', $val['id'])[1] ?? null;
  8268. $textnum = explode(',', $val['id'])[2] ?? null;
  8269. }
  8270. // 4:招聘;5:求职;
  8271. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8272. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8273. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8274. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8275. ->where('job_recruiting.status', 1)
  8276. ->where('job_recruiting.website_id', $data['website_id'])
  8277. ->select(
  8278. 'job_recruiting.id',
  8279. 'job_recruiting.title',
  8280. 'job_company.business_name',
  8281. 'job_recruiting.updated_at',
  8282. 'job_recruiting.cat_arr_id',
  8283. 'job_recruiting.keyword',
  8284. 'job_recruiting.description'
  8285. )
  8286. ->orderBy('job_recruiting.updated_at', 'desc')
  8287. ->limit($textnum)
  8288. ->get()->all();
  8289. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8290. // 状态 审核状态,1待审核2已审核3已拒绝
  8291. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8292. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8293. ->where('job_hunting.status', 2)
  8294. ->where('job_hunting.website_id', $data['website_id'])
  8295. ->select(
  8296. 'job_hunting.id',
  8297. 'job_hunting.name',
  8298. 'job_hunting.cat_arr_id',
  8299. 'job_position.zwname as job_name',
  8300. 'job_hunting.updated_at',
  8301. 'job_hunting.keyword',
  8302. 'job_hunting.slelf_evaluation'
  8303. )
  8304. ->orderBy('updated_at', 'desc')
  8305. ->limit($textnum)
  8306. ->get()->all();
  8307. } else {
  8308. $job = [];
  8309. }
  8310. // var_dump($catid.'222uuuuuuu'.$key);
  8311. if (!empty($job)) {
  8312. foreach ($job as $k => $value) {
  8313. if (isset($value->cat_arr_id)) {
  8314. $catArr = json_decode($value->cat_arr_id, true);
  8315. $catId = end($catArr);
  8316. } else {
  8317. continue;
  8318. }
  8319. if (isset($catiall[$catId])) {
  8320. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8321. }
  8322. }
  8323. }
  8324. // var_dump($catid.'xxxxx'.$key);
  8325. $result[$key] = $job ?? [];
  8326. }
  8327. }
  8328. if (empty($result)) {
  8329. return Result::error("暂无相关分类信息", 0);
  8330. }
  8331. return Result::success($result);
  8332. }
  8333. /**
  8334. * 发送消息
  8335. * @param array $messageData
  8336. * @return void
  8337. */
  8338. public function sendMessage($messageData)
  8339. {
  8340. $msg = [
  8341. 'talk_type' => $messageData['talk_type'],
  8342. 'title' => $messageData['title'],
  8343. 'content' => $messageData['content'],
  8344. 'messageType' => $messageData['messageType'],
  8345. 'user_id' => $messageData['user_id'] ?? '',
  8346. 'time' => microtime(),
  8347. ];
  8348. $message = new MqProducer($msg);
  8349. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8350. $producer->produce($message);
  8351. }
  8352. }