NewsService.php 295 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  69. class NewsService implements NewsServiceInterface
  70. {
  71. #[Inject]
  72. protected Redis $redis;
  73. /**
  74. * 获取导航池列表
  75. * @param array $data
  76. * @return array
  77. */
  78. public function getCategoryList(array $data): array
  79. {
  80. $search = $data['name'] ?? '';
  81. $page = (int)($data['page'] ?? 1);
  82. $perPage = (int)($data['pageSize'] ?? 10);
  83. // 1. 查出所有匹配的分类id
  84. if ($search) {
  85. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  86. if (empty($matchedIds)) {
  87. return Result::success(['rows' => [], 'total' => 0]);
  88. }
  89. // 2. 递归查所有父级,直到一级分类
  90. $idsStr = implode(',', $matchedIds);
  91. $sql = "
  92. WITH RECURSIVE parents AS (
  93. SELECT * FROM category WHERE id IN ($idsStr)
  94. UNION ALL
  95. SELECT c.* FROM category c
  96. INNER JOIN parents p ON c.id = p.pid
  97. )
  98. SELECT * FROM parents
  99. ";
  100. $parents = Db::select($sql);
  101. $parentIds = [];
  102. foreach ($parents as $row) {
  103. if ($row->pid == 0) {
  104. $parentIds[] = $row->id;
  105. }
  106. }
  107. $parentIds = array_unique($parentIds);
  108. } else {
  109. // 没有搜索,一级分类就是根
  110. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  111. }
  112. // 3. 一级分类分页
  113. $total = count($parentIds);
  114. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  115. if (empty($parentIds)) {
  116. return Result::success(['rows' => [], 'total' => $total]);
  117. }
  118. // 4. 递归查所有子孙
  119. $idsStr = implode(',', $parentIds);
  120. $sql = "
  121. WITH RECURSIVE subcategories AS (
  122. SELECT * FROM category WHERE id IN ($idsStr)
  123. UNION ALL
  124. SELECT c.* FROM category c
  125. INNER JOIN subcategories s ON c.pid = s.id
  126. )
  127. SELECT * FROM subcategories ORDER BY updated_at DESC
  128. ";
  129. $allCategories = Db::select($sql);
  130. // 5. 组装树结构
  131. $categoryMap = [];
  132. foreach ($allCategories as $cat) {
  133. $cat = (array)$cat;
  134. $cat['children'] = [];
  135. $categoryMap[$cat['id']] = $cat;
  136. }
  137. foreach ($categoryMap as $id => &$cat) {
  138. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  139. $categoryMap[$cat['pid']]['children'][] = &$cat;
  140. }
  141. }
  142. unset($cat);
  143. $categoryTree = [];
  144. foreach ($parentIds as $id) {
  145. if (isset($categoryMap[$id])) {
  146. $categoryTree[] = $categoryMap[$id];
  147. }
  148. }
  149. return Result::success([
  150. 'rows' => $categoryTree,
  151. 'total' => $total,
  152. ]);
  153. }
  154. private function findMatchedCategories($search)
  155. {
  156. if ($search) {
  157. return Category::where('name', 'like', "%{$search}%")
  158. ->orderBy('updated_at', 'desc')
  159. ->get();
  160. }
  161. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  162. ->get();
  163. }
  164. private function findAllParents($categories)
  165. {
  166. $allCategories = [];
  167. foreach ($categories as $category) {
  168. $parentId = $category->pid;
  169. while ($parentId > 0) {
  170. $parent = Category::find($parentId);
  171. if ($parent) {
  172. $allCategories[$parent->id] = $parent;
  173. $parentId = $parent->pid;
  174. } else {
  175. break;
  176. }
  177. }
  178. $allCategories[$category->id] = $category;
  179. }
  180. return array_values($allCategories);
  181. }
  182. private function buildCategoryTree($category, $allRequiredCategories)
  183. {
  184. $categoryData = $category->toArray();
  185. $children = [];
  186. foreach ($allRequiredCategories as $c) {
  187. if ($c->pid === $category->id) {
  188. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  189. }
  190. }
  191. if (!empty($children)) {
  192. $categoryData['children'] = $children;
  193. }
  194. return $categoryData;
  195. }
  196. public function myCategoryList(array $data): array
  197. {
  198. $sszq = $data['sszq'] ?? '';
  199. unset($data['sszq']);
  200. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  201. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  202. $where[] = [
  203. 'pid',
  204. '=',
  205. $data['pid'],
  206. ];
  207. if (isset($data['name'])) {
  208. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  209. }
  210. var_dump($where);
  211. //根据分类id,从category表中取出分类信息
  212. $result = Category::where($where)
  213. ->whereIn('category.id', $catorytids)
  214. ->select('category.*', 'category.id as category_id')->get();
  215. if (empty($result)) {
  216. return Result::error("没有栏目数据");
  217. }
  218. return Result::success($result);
  219. }
  220. /**
  221. * @param array $data
  222. * @return array
  223. */
  224. public function categoryList(array $data): array
  225. {
  226. $where[] = [
  227. 'pid',
  228. '=',
  229. $data['pid']
  230. ];
  231. if (isset($data['name'])) {
  232. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  233. }
  234. var_dump($where);
  235. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  236. if (empty($result)) {
  237. return Result::error("没有栏目数据");
  238. }
  239. return Result::success($result);
  240. }
  241. /**
  242. * @param array $data
  243. * @return array
  244. */
  245. public function addCategory(array $data): array
  246. {
  247. if (isset($data['id'])) {
  248. unset($data['id']);
  249. }
  250. $id = Category::insertGetId($data);
  251. if (empty($id)) {
  252. return Result::error("添加失败");
  253. }
  254. return Result::success(['id' => $id]);
  255. }
  256. /**
  257. * @param array $data
  258. * @return array
  259. */
  260. public function delCategory(array $data): array
  261. {
  262. Db::beginTransaction();
  263. try {
  264. $categoryList = Category::where(['pid' => $data['id']])->get();
  265. if ($categoryList->toArray()) {
  266. Db::rollBack();
  267. return Result::error("分类下面有子分类不能删除");
  268. }
  269. $articleList = Article::where(['catid' => $data['id']])->get();
  270. if ($articleList->toArray()) {
  271. Db::rollBack();
  272. return Result::error("分类下面有资讯不能删除");
  273. }
  274. $result = Category::where($data)->delete();
  275. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  276. if (!$result) {
  277. Db::rollBack();
  278. return Result::error("删除失败");
  279. }
  280. Db::commit();
  281. return Result::success($result);
  282. } catch (\Exception $e) {
  283. Db::rollBack();
  284. return Result::error("删除失败" . $e->getMessage());
  285. }
  286. }
  287. /**
  288. * @param array $data
  289. * @return array
  290. */
  291. public function updateCategory(array $data): array
  292. {
  293. $where = [
  294. 'id' => $data['id'],
  295. ];
  296. $result = Category::where($where)->update($data);
  297. if ($result) {
  298. return Result::success($result);
  299. } else {
  300. return Result::error("更新失败");
  301. }
  302. }
  303. /**
  304. * 获取导航池信息
  305. * @param array $data
  306. * @return array
  307. */
  308. public function getCategoryInfo(array $data): array
  309. {
  310. $where = [
  311. 'id' => $data['id'],
  312. ];
  313. $result = Category::where($where)->first();
  314. if ($result) {
  315. return Result::success($result);
  316. } else {
  317. return Result::error("更新失败");
  318. }
  319. }
  320. public function getArticleCommend(array $data): array
  321. {
  322. $where = [
  323. 'website_id' => $data['website_id'],
  324. ];
  325. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  326. var_dump($ids);
  327. if (empty($ids)) {
  328. return Result::error("没有推荐数据");
  329. }
  330. //id
  331. $whereArticle = [];
  332. if (isset($data['id'])) {
  333. $whereArticle['id'] = $data['id'];
  334. }
  335. //title like
  336. if (isset($data['title'])) {
  337. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  338. }
  339. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  340. ->where($whereArticle)
  341. ->orderBy('id', 'desc')
  342. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  343. if ($article) {
  344. $data = [
  345. 'rows' => $article->items(),
  346. 'count' => $article->total(),
  347. ];
  348. return Result::success($data);
  349. } else {
  350. return Result::error("获取失败失败");
  351. }
  352. }
  353. /**
  354. * @param array $data
  355. * @return array
  356. */
  357. public function getArticleList(array $data): array
  358. {
  359. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  360. $type_id = $data['type_id'];
  361. unset($data['type_id']);
  362. $user_id = $data['user_id'];
  363. unset($data['user_id']);
  364. $where = [];
  365. $status1 = [];
  366. if (isset($data['id']) && $data['id']) {
  367. array_push($where, ['article.id', '=', $data['id']]);
  368. }
  369. if (isset($data['title']) && $data['title']) {
  370. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  371. }
  372. if (isset($data['category_name']) && $data['category_name']) {
  373. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  374. }
  375. if (isset($data['catid']) && $data['catid']) {
  376. array_push($where, ['article.catid', '=', $data['catid']]);
  377. }
  378. if (isset($data['author']) && $data['author']) {
  379. array_push($where, ['article.author', '=', $data['author']]);
  380. }
  381. if (isset($data['islink']) && $data['islink'] !== "") {
  382. array_push($where, ['article.islink', '=', $data['islink']]);
  383. }
  384. if (isset($data['status']) && $data['status'] !== "") {
  385. array_push($where, ['article.status', '=', $data['status']]);
  386. }
  387. if (isset($data['status1'])) {
  388. $status1 = json_decode(($data['status1']));
  389. }
  390. //不是管理员展示个人数据;
  391. if ($type_id != 10000) {
  392. $where[] = ['article.admin_user_id', '=', $user_id];
  393. }
  394. $rep = Article::where($where)
  395. ->whereNotIn('article.status', [404])
  396. ->when($status1, function ($query) use ($status1) {
  397. if (isset($status1) && $status1) {
  398. $query->whereIn('article.status', $status1);
  399. }
  400. })
  401. ->leftJoin('category', 'article.catid', 'category.id')
  402. ->leftJoin('website_category', function ($join) {
  403. $join->on('article.web_site_id', '=', 'website_category.website_id')
  404. ->on('article.catid', '=', 'website_category.category_id');
  405. })
  406. ->select("article.*", "category.name as category_name", "website_category.alias")
  407. ->orderBy("article.updated_at", "desc")
  408. ->limit($data['pageSize'])
  409. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  410. $count = Article::where($where)->whereNotIn('article.status', [404])
  411. ->when($status1, function ($query) use ($status1) {
  412. if (isset($status1) && $status1) {
  413. $query->whereIn('article.status', $status1);
  414. }
  415. })
  416. ->leftJoin('category', 'article.catid', 'category.id')->count();
  417. $data = [
  418. 'rows' => $rep->toArray(),
  419. 'count' => $count,
  420. ];
  421. if (empty($rep)) {
  422. return Result::error("没有信息数据");
  423. }
  424. return Result::success($data);
  425. }
  426. /**
  427. * @param array $data
  428. * @return array
  429. */
  430. public function addArticle(array $data): array
  431. {
  432. var_dump($data, '----------12-----------1');
  433. unset($data['user_type']);
  434. unset($data['nav_add_pool_id']);
  435. // unset($data['commend_id']);
  436. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  437. Db::beginTransaction();
  438. try {
  439. //处理投票
  440. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  441. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  442. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  443. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  444. unset($data['is_survey']);
  445. unset($data['survey_name']);
  446. unset($data['suvey_array']);
  447. // unset($data['website_id']);
  448. // unset($data['web_site_id']);
  449. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  450. if ($data['hits'] == '') {
  451. $data['hits'] = 0;
  452. }
  453. if ($data['is_original'] == '') {
  454. $data['is_original'] = 0;
  455. }
  456. if ($data['status'] == '') {
  457. $data['status'] = 0;
  458. }
  459. $articleData = $data;
  460. unset($articleData['content']);
  461. //自动处理缩略图、关键字、描述
  462. if ($articleData['imgurl'] == '') {
  463. //如果没有图,设置level=0
  464. $levelArr = json_decode($articleData['level'], true);
  465. var_dump($levelArr, '----------levelArr-----------1');
  466. //content中提取图片第一个图,正则提取
  467. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  468. preg_match_all($reg, $data['content'], $matches);
  469. if (isset($matches[1][0])) {
  470. //截取varchar240
  471. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  472. //如果有图,设置level=3
  473. if (!in_array(3, $levelArr)) {
  474. $levelArr[] = 3;
  475. }
  476. $articleData['level'] = json_encode($levelArr);
  477. } else {
  478. if (!in_array(0, $levelArr)) {
  479. $levelArr[] = 0;
  480. }
  481. $articleData['level'] = json_encode($levelArr);
  482. }
  483. }
  484. var_dump($articleData['level'], '----------$articleData[level]----------1');
  485. if ($articleData['keyword'] == '') {
  486. //提取标题+内容中的关键词
  487. $articleData['keyword'] = $data['title'];
  488. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  489. Jieba::init(); // 初始化 jieba-php
  490. Finalseg::init();
  491. $segList = Jieba::cut($articleData['keyword']);
  492. $segList1 = array_slice($segList, 0, 8);
  493. $articleData['keyword'] = implode(',', $segList1);
  494. }
  495. if ($articleData['introduce'] == '') {
  496. //提取内容中的描述
  497. $content = $data['content'];
  498. // 去除 <style> 和 <script> 标签及其内容
  499. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  500. // 去除所有 HTML 标签
  501. $content = strip_tags($content);
  502. // 去除 HTML 实体
  503. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  504. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  505. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  506. // 去除多余空白
  507. $content = preg_replace('/\s+/u', '', $content);
  508. // 截取 100 个字符
  509. $articleData['introduce'] = mb_substr($content, 0, 100);
  510. }
  511. if ($articleData['status'] == 0) {
  512. $this->sendMessage([
  513. 'talk_type' => 100,
  514. 'title' => $articleData['title'],
  515. 'content' => '提交了审核',
  516. 'messageType' => 2,
  517. ]);
  518. }
  519. $id = Article::insertGetId($articleData);
  520. $articleDataContent = [
  521. 'article_id' => $id,
  522. 'content' => $data['content'],
  523. ];
  524. ArticleData::insertGetId($articleDataContent);
  525. //处理投票
  526. if ($is_survey == 1) {
  527. //生成年月日时分秒+8位随机数
  528. $uuid = date('YmdHis') . rand(10000000, 99999999);
  529. var_dump($suvey_array, 'suvey_array________');
  530. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  531. var_dump($suveys_array, '---------------------1');
  532. var_dump($suvey_array, '---------------------2');
  533. $suvey_data = [];
  534. foreach ($suveys_array as $key => $value) {
  535. if ($value == '') {
  536. continue;
  537. }
  538. if (is_array($value)) {
  539. $suvey_data[] = [
  540. 'sur_id' => $uuid,
  541. 'art_id' => $id,
  542. 'website_id' => $website_id ?? 2,
  543. 'survey_name' => $survey_name,
  544. 'choice_name' => $value[1],
  545. 'is_other' => 1,
  546. 'other_id' => 0,
  547. 'results' => 0,
  548. ];
  549. } else {
  550. $suvey_data[] = [
  551. 'sur_id' => $uuid,
  552. 'art_id' => $id,
  553. 'website_id' => $website_id ?? 2,
  554. 'survey_name' => $survey_name,
  555. 'choice_name' => $value,
  556. 'is_other' => 0,
  557. 'other_id' => 0,
  558. 'results' => 0,
  559. ];
  560. }
  561. if (empty($suvey_data)) {
  562. throw new \Exception("投票数据为空");
  563. }
  564. }
  565. $result = ArticleSurvey::insert($suvey_data);
  566. if (!$result) {
  567. throw new \Exception("投票失败,ArticleSurvey插入失败");
  568. }
  569. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  570. if (!$result) {
  571. throw new \Exception("投票失败,更新主表失败");
  572. }
  573. }
  574. Db::commit();
  575. return Result::success(['id' => $id]);
  576. } catch (\Throwable $ex) {
  577. Db::rollBack();
  578. var_dump($ex->getMessage());
  579. return Result::error("创建失败", 0);
  580. }
  581. }
  582. /**
  583. * @param array $data
  584. * @return array
  585. */
  586. public function delArticle(array $data): array
  587. {
  588. $result = Article::where($data)->delete();
  589. //survey投票删除
  590. articleSurvey::where(['art_id' => $data['id']])->delete();
  591. if (!$result) {
  592. return Result::error("删除失败");
  593. }
  594. return Result::success($result);
  595. }
  596. /**
  597. * @param array $data
  598. * @return array
  599. */
  600. public function updateArticle(array $data): array
  601. {
  602. var_dump($data, '----------12-----------1');
  603. Db::beginTransaction();
  604. unset($data['user_type']);
  605. // unset($data['web_site_id']);
  606. unset($data['nav_add_pool_id']);
  607. try {
  608. //处理投票
  609. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  610. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  611. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  612. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  613. unset($data['is_survey']);
  614. unset($data['survey_name']);
  615. unset($data['suvey_array']);
  616. unset($data['website_id']);
  617. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  618. if ($data['hits'] == '') {
  619. $data['hits'] = 0;
  620. }
  621. if ($data['is_original'] == '') {
  622. $data['is_original'] = 0;
  623. }
  624. if ($data['status'] == '') {
  625. $data['status'] = 0;
  626. }
  627. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  628. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  629. $articleData = $data;
  630. unset($articleData['content']);
  631. unset($articleData['status_name']);
  632. unset($articleData['name']);
  633. unset($articleData['content']);
  634. unset($articleData['pid_arr']);
  635. unset($articleData['pid']);
  636. //自动处理缩略图、关键字、描述
  637. if ($articleData['imgurl'] == '') {
  638. //如果没有图,设置level=0
  639. $levelArr = json_decode($articleData['level'], true);
  640. var_dump($levelArr, '----------levelArr-----------1');
  641. //content中提取图片第一个图,正则提取
  642. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  643. preg_match_all($reg, $data['content'], $matches);
  644. if (isset($matches[1][0])) {
  645. //截取varchar240
  646. // 截取到第一个<
  647. $articleData['imgurl'] = $matches[1][0];
  648. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  649. $pos = strpos($articleData['imgurl'], '"');
  650. if ($pos !== false) {
  651. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  652. }
  653. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  654. //如果有图,设置level=3
  655. if (!in_array(3, $levelArr)) {
  656. $levelArr[] = 3;
  657. }
  658. $articleData['level'] = json_encode($levelArr);
  659. } else {
  660. if (!in_array(0, $levelArr)) {
  661. $levelArr[] = 0;
  662. }
  663. $articleData['level'] = json_encode($levelArr);
  664. }
  665. }
  666. var_dump($articleData['level'], '----------$articleData[level]----------1');
  667. if ($articleData['keyword'] == '') {
  668. //提取标题+内容中的关键词
  669. $articleData['keyword'] = $data['title'];
  670. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  671. Jieba::init(); // 初始化 jieba-php
  672. Finalseg::init();
  673. $segList = Jieba::cut($articleData['keyword']);
  674. $segList1 = array_slice($segList, 0, 8);
  675. $articleData['keyword'] = implode(',', $segList1);
  676. }
  677. if ($articleData['introduce'] == '') {
  678. //提取内容中的描述
  679. $content = $data['content'];
  680. // 去除 <style> 和 <script> 标签及其内容
  681. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  682. // 去除所有 HTML 标签
  683. $content = strip_tags($content);
  684. // 去除 HTML 实体
  685. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  686. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  687. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  688. // 去除多余空白
  689. $content = preg_replace('/\s+/u', '', $content);
  690. // 截取 100 个字符
  691. $articleData['introduce'] = mb_substr($content, 0, 100);
  692. }
  693. if ($articleData['status'] == 0) {
  694. $this->sendMessage([
  695. 'talk_type' => 100,
  696. 'title' => $articleData['title'],
  697. 'content' => '提交了审核',
  698. 'messageType' => 2,
  699. ]);
  700. }
  701. $id = Article::where(['id' => $data['id']])->update($articleData);
  702. $articleDataContent = [
  703. 'content' => $data['content'],
  704. ];
  705. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  706. //处理投票
  707. $id = $data['id'];
  708. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  709. var_dump($suvey_array, 'suvey_array________delete');
  710. //处理投票
  711. if ($is_survey == 1) {
  712. //生成年月日时分秒+8位随机数
  713. $uuid = date('YmdHis') . rand(10000000, 99999999);
  714. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  715. var_dump($suveys_array, '---------------------1');
  716. $suvey_data = [];
  717. if (is_array($suveys_array)) {
  718. foreach ($suveys_array as $key => $value) {
  719. if ($value == '') {
  720. continue;
  721. }
  722. if (is_array($value)) {
  723. $suvey_data[] = [
  724. 'sur_id' => $uuid,
  725. 'art_id' => $id,
  726. 'website_id' => $website_id ?? 2,
  727. 'survey_name' => $survey_name,
  728. 'choice_name' => $value[1],
  729. 'is_other' => 1,
  730. 'other_id' => 0,
  731. 'results' => 0,
  732. ];
  733. } else {
  734. $suvey_data[] = [
  735. 'sur_id' => $uuid,
  736. 'art_id' => $id,
  737. 'website_id' => $website_id ?? 2,
  738. 'survey_name' => $survey_name,
  739. 'choice_name' => $value,
  740. 'is_other' => 0,
  741. 'other_id' => 0,
  742. 'results' => 0,
  743. ];
  744. }
  745. if (empty($suvey_data)) {
  746. throw new \Exception("投票数据为空");
  747. }
  748. }
  749. }
  750. $result = ArticleSurvey::insert($suvey_data);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  755. if (!$result) {
  756. throw new \Exception("投票失败");
  757. }
  758. } else {
  759. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  760. }
  761. Db::commit();
  762. return Result::success([]);
  763. } catch (\Throwable $ex) {
  764. Db::rollBack();
  765. var_dump($ex->getMessage());
  766. return Result::error("更新失败" . $ex->getMessage(), 0);
  767. }
  768. }
  769. /**
  770. * 更新资讯状态
  771. * @param array $data
  772. * @return array
  773. */
  774. public function upArticleStatus(array $data): array
  775. {
  776. $articleData = Article::where(['id' => $data['id']])->first();
  777. //发送10次
  778. // for ($i = 0; $i < 10; $i++) {
  779. // $this->sendMessage([
  780. // 'talk_type' => 100,
  781. // 'title' => $i . $articleData['title'],
  782. // 'content' => '审核通过',
  783. // 'messageType' => 2,
  784. // 'user_id' => $articleData['admin_user_id'],
  785. // ]);
  786. // }
  787. // var_dump($data['status'], 'status');
  788. // return Result::success();
  789. if ($data['status'] == 1) {
  790. $this->sendMessage([
  791. 'talk_type' => 101,
  792. 'title' => $articleData['title'],
  793. 'content' => '审核通过',
  794. 'messageType' => 2,
  795. 'user_id' => $articleData['admin_user_id'],
  796. ]);
  797. }
  798. if ($data['status'] == 2) {
  799. $this->sendMessage([
  800. 'talk_type' => 101,
  801. 'title' => $articleData['title'],
  802. 'content' => '审核拒绝',
  803. 'messageType' => 2,
  804. 'user_id' => $articleData['admin_user_id'],
  805. ]);
  806. }
  807. if ($data['status'] == 0) {
  808. $this->sendMessage([
  809. 'talk_type' => 100,
  810. 'title' => $articleData['title'],
  811. 'content' => '提交了审核',
  812. 'messageType' => 2,
  813. ]);
  814. }
  815. $result = Article::where(['id' => $data['id']])->update($data);
  816. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  817. //article_ignore 表插入数据 db操作
  818. //转成数组
  819. //删掉数据重新写入
  820. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  821. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  822. $insert_data = [];
  823. foreach ($website_ids as $key => $value) {
  824. $insert_data[] = [
  825. 'article_id' => $data['id'],
  826. 'website_id' => $value,
  827. ];
  828. }
  829. DB::table('article_ignore')->insert($insert_data);
  830. }
  831. if ($result) {
  832. return Result::success();
  833. } else {
  834. return Result::error("更新状态失败", 0);
  835. }
  836. }
  837. /**
  838. * 获取新闻详情
  839. * @param array $data
  840. * @return array
  841. */
  842. public function getArticleInfo(array $data): array
  843. {
  844. $where = [
  845. 'article.id' => $data['id'],
  846. // 'article.status' => 1,
  847. ];
  848. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  849. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  850. $info = $result;
  851. // var_dump($info, 'info');
  852. $info['survey_array'] = $articleSurvey;
  853. if ($result) {
  854. return Result::success($info);
  855. } else {
  856. return Result::error("查询失败", 0);
  857. }
  858. }
  859. /**
  860. * 获取头条新闻
  861. * @param array $data
  862. * @return array
  863. */
  864. public function getWebsiteArticlett(array $data): array
  865. {
  866. $website_id = $data['website_id'];
  867. $website = Website::where('id', $data['website_id'])->first();
  868. if (empty($website)) {
  869. return Result::error("网站不存在", 0);
  870. }
  871. $categorys = $this->processArticlePro($website_id);
  872. $catiall = $categorys['catiall'];
  873. $categoryIds = $categorys['categoryIds'];
  874. $where = [
  875. 'status' => 1
  876. ];
  877. // $website_column = $website['column'];
  878. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  879. $website_column = json_decode($website['website_column_arr_id'], true);
  880. }
  881. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  882. // return Result::success($diff_pid_categoryIds);
  883. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  884. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  885. }
  886. // $website_id = $data['website_id'];
  887. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  888. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  889. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  890. switch ($data['level']) {
  891. case 1:
  892. case 2:
  893. case 3:
  894. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  895. $query = Article::where($where)
  896. ->where('level', 'like', '%' . $data['level'] . '%')
  897. ->orderBy('updated_at', 'desc');
  898. break;
  899. case 4: //最新资讯
  900. $query = Article::where($where)->orderBy('updated_at', 'desc');
  901. break;
  902. case 5: //资讯推荐
  903. $query = Article::where($where)
  904. ->where('updated_at', '>', $month);
  905. break;
  906. case 7: //资讯分类
  907. if (isset($data['id']) && !empty($data['id'])) {
  908. $keyword = Article::where('id', $data['id'])->value('keyword');
  909. $keywordArray = explode(',', $keyword);
  910. $whereL7 = [];
  911. foreach ($keywordArray as $k => $v) {
  912. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  913. }
  914. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  915. break;
  916. } else {
  917. return Result::error("请输入资讯ID", 0);
  918. break;
  919. }
  920. default:
  921. break;
  922. }
  923. // $whereL7 = [];
  924. // if(isset($data['id']) && !empty($data['id'])){
  925. // $keyword = Article::where('id', $data['id'])->value('keyword');
  926. // $keywordArray = explode(',', $keyword);
  927. // foreach ($keywordArray as $k => $v) {
  928. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  929. // }
  930. // }
  931. // $query = Article::where($where)
  932. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  933. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  934. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  935. // }
  936. // if($data['level'] == 7){
  937. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  938. // }
  939. // if($data['level'] == 4){
  940. // $query = $query->inRandomOrder()
  941. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  942. // }
  943. // if($data['level'] == 5){
  944. // $query = $query->orderBy('updated_at','desc');
  945. // }
  946. // });
  947. if ($data['textnum'] > 0) {
  948. $query = clone $query;
  949. $result['text'] = $query
  950. ->whereIn('catid', $categoryIds)
  951. ->leftJoinSub(function ($query) use ($website_id) {
  952. $query->from('article_ignore')
  953. ->where('website_id', $website_id);
  954. }, 'article_ignore', function ($join) {
  955. $join->on('article_ignore.article_id', '=', 'article.id');
  956. })
  957. ->where(function ($query) use ($website_id) {
  958. $query->whereNull('article_ignore.article_id')
  959. ->orWhere('article_ignore.website_id', '!=', $website_id);
  960. })
  961. ->select(
  962. 'article.id',
  963. 'article.title',
  964. 'article.author',
  965. 'article.updated_at',
  966. 'article.introduce',
  967. 'article.islink',
  968. 'article.linkurl',
  969. 'article.copyfrom',
  970. 'article.cat_arr_id',
  971. 'article.catid',
  972. 'article.level'
  973. )
  974. ->offset($data['placeid'])
  975. ->limit($data['textnum'])
  976. ->get()->all();
  977. foreach ($result['text'] as $k => $v) {
  978. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  979. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  980. }
  981. }
  982. if ($data['imgnum'] > 0) {
  983. $query = clone $query;
  984. $result['img'] = $query
  985. ->whereIn('catid', $categoryIds)
  986. ->where('article.imgurl', '!=', '')
  987. ->select(
  988. 'article.id',
  989. 'article.title',
  990. 'article.imgurl',
  991. 'article.author',
  992. 'article.updated_at',
  993. 'article.introduce',
  994. 'article.islink',
  995. 'article.linkurl',
  996. 'article.copyfrom',
  997. 'article.cat_arr_id',
  998. 'article.catid',
  999. 'article.level'
  1000. )
  1001. ->offset($data['placeid'])
  1002. ->limit($data['imgnum'])
  1003. ->get()->all();
  1004. foreach ($result['img'] as $k => $v) {
  1005. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1006. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1007. }
  1008. }
  1009. if (empty($result)) {
  1010. return Result::error("暂无相关资讯", 0);
  1011. }
  1012. return Result::success($result);
  1013. }
  1014. /**
  1015. * 获取模块新闻
  1016. * @param array $data
  1017. * @return array
  1018. */
  1019. public function getWebsiteModelArticles(array $data): array
  1020. {
  1021. $catid = $data['catid'];
  1022. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1023. $category = $category->toArray();
  1024. if (!empty($category)) {
  1025. $where = [
  1026. 'status' => 1,
  1027. 'catid' => $catid,
  1028. ];
  1029. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1030. // 1:文字新闻;2:轮播图;3:图文;
  1031. // 级别:0:未分类
  1032. // 3:推荐图片
  1033. if ($data['level'] == 1) {
  1034. $data['level'] = 0;
  1035. }
  1036. $result = Article::where($where)
  1037. ->where(function ($query) use ($data) {
  1038. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1039. ->orWhereNull("level")
  1040. ->orWhereRaw("level = '[]'");
  1041. })
  1042. ->where(function ($query) use ($data) {
  1043. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1044. ->orWhereNull("ignore_ids");
  1045. })
  1046. ->orderBy("updated_at", "desc")
  1047. ->offset($placeid)
  1048. ->limit($data['pagesize'])
  1049. ->get();
  1050. if (empty($result)) {
  1051. return Result::error("此栏目暂无相关新闻", 0);
  1052. }
  1053. } else {
  1054. return Result::error("此网站暂无此栏目", 0);
  1055. }
  1056. return Result::success($result);
  1057. }
  1058. /**
  1059. *获取新闻列表
  1060. * @param array $data
  1061. * @return array
  1062. */
  1063. public function getWebsiteArticleList(array $data): array
  1064. {
  1065. // return Result::success($data);
  1066. $where[] = ['status', '=', 1];
  1067. $website_id = $data['website_id'];
  1068. $website = Website::where('id', $data['website_id'])->first();
  1069. if (empty($website)) {
  1070. return Result::error("网站不存在", 0);
  1071. }
  1072. // $website_column = $website['column'];
  1073. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1074. $website_column = json_decode($website['website_column_arr_id'], true);
  1075. }
  1076. $categorys = $this->processArticlePro($website_id);
  1077. $cat_1st_arr = $categorys['cat_1st_arr'];
  1078. $catiall = $categorys['catiall'];
  1079. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1080. // return Result::success($diff_pid_categoryIds);
  1081. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1082. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1083. }
  1084. if (isset($data['catid']) && !empty($data['catid'])) {
  1085. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1086. if (empty($category)) {
  1087. return Result::error("此网站暂无此栏目", 0);
  1088. }
  1089. array_push($where, ['catid', '=', $data['catid']]);
  1090. }
  1091. // return Result::success($where);
  1092. $query = Article::where($where)
  1093. ->leftJoinSub(function ($query) use ($website_id) {
  1094. $query->from('article_ignore')
  1095. ->where('website_id', $website_id);
  1096. }, 'article_ignore', function ($join) {
  1097. $join->on('article_ignore.article_id', '=', 'article.id');
  1098. })
  1099. ->where(function ($query) use ($website_id) {
  1100. $query->whereNull('article_ignore.article_id')
  1101. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1102. })
  1103. ->select(
  1104. 'article.id',
  1105. 'article.title',
  1106. 'article.imgurl',
  1107. 'article.author',
  1108. 'article.updated_at',
  1109. 'article.introduce',
  1110. 'article.islink',
  1111. 'article.linkurl',
  1112. 'article.copyfrom',
  1113. 'article.cat_arr_id',
  1114. 'article.catid'
  1115. );
  1116. $count = $query->count();
  1117. $rep = $query->orderBy("updated_at", "desc")
  1118. ->offset(($data['page'] - 1) * $data['pageSize'])
  1119. ->limit($data['pageSize'])
  1120. ->get()->all();
  1121. $categorys = $this->processArticlePro($website_id);
  1122. $cat_1st_arr = $categorys['cat_1st_arr'];
  1123. $catiall = $categorys['catiall'];
  1124. // $web['website_id'] = $data['website_id'];
  1125. foreach ($rep as $k => $v) {
  1126. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1127. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1128. }
  1129. // $rep = $this->processArticles($rep,$web);
  1130. $data = [
  1131. 'rows' => $rep,
  1132. 'count' => $count,
  1133. ];
  1134. if (empty($rep)) {
  1135. return Result::error("没有信息数据");
  1136. }
  1137. return Result::success($data);
  1138. }
  1139. /**
  1140. * 前端-获取新闻详情
  1141. * @param array $data
  1142. * @return array
  1143. */
  1144. public function selectWebsiteArticleInfo(array $data): array
  1145. {
  1146. $where = [
  1147. 'article.id' => $data['id'],
  1148. 'article.status' => 1,
  1149. ];
  1150. $result = Article::where($where)
  1151. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1152. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1153. ->where(function ($query) use ($data) {
  1154. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1155. ->orWhereNull("ignore_ids");
  1156. })
  1157. ->select(
  1158. 'article.*',
  1159. 'article_data.content',
  1160. 'article_data.article_id',
  1161. 'article_extend.website_url',
  1162. 'article_extend.email',
  1163. 'article_extend.contacts',
  1164. 'article_extend.contacts_mobile',
  1165. 'article_extend.contacts_address',
  1166. 'article_extend.zip_code',
  1167. 'article_extend.enterprise_name'
  1168. )
  1169. ->first();
  1170. if (empty($result)) {
  1171. return Result::error("暂无此新闻!", 0);
  1172. }
  1173. if (!empty($result['publiced_at'])) {
  1174. $result['updated_at'] = $result['publiced_at'];
  1175. }
  1176. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1177. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1178. ->where('website_category.website_id', $data['website_id'])
  1179. ->where(['website_category.category_id' => $result['catid']])
  1180. ->first();
  1181. if (empty($category)) {
  1182. return Result::error("查询失败", 0);
  1183. }
  1184. //手动推荐文章
  1185. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1186. if (empty($commend_ids)) {
  1187. $commendArticle = [];
  1188. } else {
  1189. //去除不存在的文章ID
  1190. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1191. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1192. ->where('article.status', 1)
  1193. ->where('website_category.website_id', $data['website_id'])
  1194. ->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')
  1195. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1196. // ->orderBy('article.updated_at', 'desc')
  1197. ->limit(5)
  1198. ->get();
  1199. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1200. foreach ($commendArticle as $k => $v) {
  1201. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1202. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1203. $cat_arr_id = array_unique($cat_arr_id);
  1204. // 从website_category取出alias_pinyin
  1205. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1206. ->whereIn('category_id', $cat_arr_id)
  1207. ->pluck('alias_pinyin', 'category_id')
  1208. ->toArray();
  1209. // 将cat_arr_id的json转成路径/隔开
  1210. $path_parts = [];
  1211. foreach ($cat_arr_id as $cat_id) {
  1212. if (isset($cat_arr[$cat_id])) {
  1213. $path_parts[] = $cat_arr[$cat_id];
  1214. }
  1215. }
  1216. $v->alias_pinyin = implode('/', $path_parts);
  1217. } else {
  1218. $v->alias_pinyin = '';
  1219. }
  1220. }
  1221. }
  1222. $result['category_id'] = $category['category_id'];
  1223. $result['cat_name'] = $category['alias'];
  1224. $result['website_name'] = $category['website_name'] ?? "";
  1225. $result['suffix'] = $category['suffix'] ?? "";
  1226. $result['commendArticle'] = $commendArticle;
  1227. $result['commend_ids'] = $commend_ids;
  1228. return Result::success($result);
  1229. }
  1230. /**
  1231. * 前端-获取网站调查问卷
  1232. * @param array $data
  1233. * @return array
  1234. */
  1235. public function getWebsiteSurvey(array $data): array
  1236. {
  1237. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1238. $website = Website::where('id', $data['website_id'])->first();
  1239. if (empty($website)) {
  1240. return Result::error("暂无此网站", 0);
  1241. }
  1242. }
  1243. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1244. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1245. if (empty($article)) {
  1246. return Result::error("暂无此文章", 0);
  1247. }
  1248. // return Result::error($data,0);
  1249. $where['art_id'] = $data['art_id'];
  1250. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1251. } else {
  1252. $survey = Article::where(function ($query) {
  1253. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1254. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1255. })
  1256. ->where('status', 1)
  1257. ->where('is_survey', 1)
  1258. ->select('survey_id')
  1259. ->orderBy('updated_at', 'desc')
  1260. ->first();
  1261. if (empty($survey)) {
  1262. return Result::error("暂无调查问卷", 0);
  1263. }
  1264. $where['sur_id'] = $survey['survey_id'];
  1265. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1266. }
  1267. // return Result::success($where);
  1268. $result = ArticleSurvey::where($where)
  1269. ->where(function ($query) {
  1270. $query->where('is_other', 0)
  1271. ->orWhere(function ($subQuery) {
  1272. $subQuery->where('is_other', 1)
  1273. ->where('other_id', 0);
  1274. });
  1275. })
  1276. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1277. ->select('article_survey.*', 'article.survey_type')
  1278. ->get()->all();
  1279. if (empty($result)) {
  1280. return Result::error("此文章暂无调查问卷", 0);
  1281. }
  1282. return Result::success($result);
  1283. }
  1284. /**
  1285. * 前端-添加网站调查问卷选项
  1286. * @param array $data
  1287. * @return array
  1288. */
  1289. public function addWebsiteSurveyOption(array $data): array
  1290. {
  1291. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1292. $website = Website::where('id', $data['website_id'])->first();
  1293. if (empty($website)) {
  1294. return Result::error("暂无此网站", 0);
  1295. }
  1296. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1297. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1298. if (empty($survey)) {
  1299. return Result::error("此调查问卷不可添加选项", 0);
  1300. }
  1301. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1302. $choice = [
  1303. 'art_id' => $survey['art_id'],
  1304. 'website_id' => $data['website_id'],
  1305. 'survey_name' => $survey['survey_name'],
  1306. 'choice_name' => $data['choice_name'],
  1307. 'sur_id' => $survey['sur_id'],
  1308. 'is_other' => 1,
  1309. 'other_id' => $survey['id'],
  1310. ];
  1311. $result = ArticleSurvey::insertGetId($choice);
  1312. if (empty($result)) {
  1313. return Result::error("添加失败", 0);
  1314. }
  1315. return Result::success($result);
  1316. }
  1317. }
  1318. return Result::error("添加失败", 0);
  1319. }
  1320. return Result::error("添加失败", 0);
  1321. }
  1322. /**
  1323. * 前端-调查问卷投票
  1324. * @param array $data
  1325. * @return array
  1326. */
  1327. public function addWebsiteSurveyVote(array $data): array
  1328. {
  1329. // return Result::success($data);
  1330. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1331. $website = Website::where('id', $data['website_id'])->first();
  1332. if (empty($website)) {
  1333. return Result::error("暂无此网站", 0);
  1334. }
  1335. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1336. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1337. // return Result::success($survey);
  1338. if (empty($is_survey)) {
  1339. return Result::error("此调查问卷不存在", 0);
  1340. }
  1341. // return Result::success($survey);
  1342. // 调查问卷类型
  1343. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1344. //多选 若是json型则转化成数组类型
  1345. if (strpos($data['choice_id'], '[') === 0) {
  1346. $data['choice_id'] = json_decode($data['choice_id'], true);
  1347. } else {
  1348. // 单选 也转换成数组
  1349. $data['choice_id'] = [$data['choice_id']];
  1350. }
  1351. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1352. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1353. // ->where('website_id',$data['website_id'])
  1354. ->where('is_other', 1)
  1355. ->where('other_id', 0)
  1356. ->first();
  1357. if (!empty($other)) {
  1358. return Result::error("请选择已有的选项!", 0);
  1359. }
  1360. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1361. // ->where('website_id',$data['website_id'])
  1362. ->where('is_other', 1)
  1363. ->where('other_id', '!=', 0)
  1364. ->first();
  1365. // return Result::success($choice['other']);
  1366. $choice_id = $data['choice_id'];
  1367. if (!empty($choice['other'])) {
  1368. // array_push($data['choice_id'],$choice['other']['other_id']);
  1369. if (!empty($choice_id)) {
  1370. $key = array_search($choice['other']['id'], $choice_id);
  1371. if ($key !== false) {
  1372. unset($choice_id[$key]);
  1373. $choice_id = array_values($choice_id);
  1374. }
  1375. array_push($choice_id, $choice['other']['other_id']);
  1376. } else {
  1377. $choice_id[0] = $choice['other']['other_id'];
  1378. }
  1379. array_push($data['choice_id'], $choice['other']['other_id']);
  1380. }
  1381. // return Result::success($data);
  1382. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1383. // ->where('website_id',$data['website_id'])
  1384. ->increment('results', 1);
  1385. if (empty($choice)) {
  1386. return Result::error("请选择已有的选项!", 0);
  1387. }
  1388. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1389. // ->where('website_id',$data['website_id'])
  1390. ->where('other_id', 0)
  1391. ->get();
  1392. $survey['choice'] = $choice_id;
  1393. return Result::success($survey);
  1394. }
  1395. return Result::error("参数必填!");
  1396. }
  1397. return Result::error("此调查问卷不存在", 0);
  1398. }
  1399. return Result::error("参数必填!");
  1400. }
  1401. /**
  1402. * 后端-获取网站调查问卷列表
  1403. * @param array $data
  1404. * @return array
  1405. */
  1406. public function getSurveyList(array $data): array
  1407. {
  1408. $where = [];
  1409. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1410. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1411. }
  1412. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1413. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1414. }
  1415. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1416. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1417. }
  1418. // return Result::success($where);
  1419. if (!empty($where)) {
  1420. $query = Article::where($where)->where(function ($q) {
  1421. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1422. });
  1423. } else {
  1424. $query = Article::where(function ($q) {
  1425. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1426. });
  1427. }
  1428. $count = $query->count();
  1429. $survey = $query->orderByDesc('id')
  1430. ->limit($data['pageSize'])
  1431. ->offset(($data['page'] - 1) * $data['pageSize'])
  1432. ->get();
  1433. if (empty($survey->toArray())) {
  1434. return Result::error("暂无调查问卷!", 0);
  1435. }
  1436. $result = [
  1437. 'rows' => $survey,
  1438. 'count' => $count,
  1439. ];
  1440. return Result::success($result);
  1441. }
  1442. /**
  1443. * 后端-获取网站调查问卷详情
  1444. * @param array $data
  1445. * @return array
  1446. */
  1447. public function getSurveyInfo(array $data): array
  1448. {
  1449. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1450. $where = ['sur_id' => $data['sur_id']];
  1451. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1452. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1453. ->select('article_survey.*', 'article.survey_type')
  1454. ->get()->all();
  1455. if (empty($choose)) {
  1456. return Result::error("此调查问卷不存在", 0);
  1457. }
  1458. $resultsArray = array_column($choose, 'results');
  1459. $total = array_sum($resultsArray);
  1460. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1461. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1462. // $total = 0;
  1463. if (!empty($other)) {
  1464. $total = $total + $other['results'];
  1465. $other['choice_name'] = '(其他)';
  1466. if (!empty($others)) {
  1467. $other['hasChildren'] = true;
  1468. // array_push($other,['hasChildren','=',true]);
  1469. $other['children'] = $others;
  1470. $other_choices = [$other->toArray()];
  1471. $mer_choice = array_merge($choose, $other_choices);
  1472. $value_choice = array_values($mer_choice);
  1473. } else {
  1474. // return Result::error('1111');
  1475. $other_choices = [$other->toArray()];
  1476. $other_choices = array_merge($choose, $other_choices);
  1477. $value_choice = array_values($other_choices);
  1478. // return Result::success($result);
  1479. }
  1480. } else {
  1481. $value_choice = $choose;
  1482. }
  1483. $result = [
  1484. 'choose' => $value_choice,
  1485. 'total' => $total,
  1486. ];
  1487. }
  1488. return Result::success($result);
  1489. }
  1490. /**
  1491. * 前端-搜索新闻列表
  1492. * @param array $data
  1493. * @return array
  1494. */
  1495. public function selectWebsiteArticle(array $data): array
  1496. {
  1497. $website = Website::where('id', $data['website_id'])->first();
  1498. if (empty($website)) {
  1499. return Result::error("网站不存在", 0);
  1500. }
  1501. // $website_column = $website['column'];
  1502. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1503. $website_column = json_decode($website['website_column_arr_id'], true);
  1504. }
  1505. $website_id = $data['website_id'];
  1506. $categorys = $this->processArticlePro($website_id);
  1507. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1508. // return Result::success($diff_pid_categoryIds);
  1509. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1510. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1511. }
  1512. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1513. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1514. $catiall = $categorys['catiall'];
  1515. $categoryIds = $categorys['categoryIds'];
  1516. // return Result::success($categoryIds);
  1517. $query = Article::where('status', 1)
  1518. ->whereIn('catid', $categoryIds)
  1519. ->leftJoinSub(function ($query) use ($website_id) {
  1520. $query->from('article_ignore')
  1521. ->where('website_id', $website_id);
  1522. }, 'article_ignore', function ($join) {
  1523. $join->on('article_ignore.article_id', '=', 'article.id');
  1524. })
  1525. ->where(function ($query) use ($website_id) {
  1526. $query->whereNull('article_ignore.article_id')
  1527. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1528. });
  1529. // ->get()->all();
  1530. // return Result::success($query);
  1531. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1532. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1533. }
  1534. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1535. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1536. }
  1537. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1538. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1539. }
  1540. // 计算总数
  1541. $count = $query->count();
  1542. // return Result::success($count);
  1543. // 分页查询
  1544. $articles = $query
  1545. ->select(
  1546. 'article.id',
  1547. 'article.title',
  1548. 'article.imgurl',
  1549. 'article.author',
  1550. 'article.updated_at',
  1551. 'article.introduce',
  1552. 'article.islink',
  1553. 'article.linkurl',
  1554. 'article.copyfrom',
  1555. 'article.cat_arr_id',
  1556. 'article.catid',
  1557. 'article.department_arr_id',
  1558. 'article.city_arr_id',
  1559. )
  1560. ->orderBy("updated_at", "desc")
  1561. ->offset(($data['page'] - 1) * $data['pageSize'])
  1562. ->limit($data['pageSize'])
  1563. ->get();
  1564. // return Result::success($articles);
  1565. foreach ($articles as $k => $v) {
  1566. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1567. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1568. }
  1569. if (empty($articles)) {
  1570. return Result::error("没有符合条件的资讯数据");
  1571. }
  1572. $result = [
  1573. 'rows' => $articles,
  1574. 'count' => $count,
  1575. ];
  1576. return Result::success($result);
  1577. }
  1578. /**
  1579. * 模块新闻加强版
  1580. * @param array $data
  1581. * @return array
  1582. */
  1583. public function getWebsiteCatidArticle(array $data): array
  1584. {
  1585. $where = [
  1586. 'website_category.category_id' => $data['catid'],
  1587. 'website_category.website_id' => $data['website_id'],
  1588. ];
  1589. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1590. $child_catnum = $data['child_catnum'] ?? 1;
  1591. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1592. $childCategoryIds = array_column($category['child'], 'category_id');
  1593. if (empty($childCategoryIds)) {
  1594. return Result::error("暂无子栏目", 0);
  1595. }
  1596. $imgArticles = [];
  1597. $textArticles = [];
  1598. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1599. // 初始化子分类图片新闻和文字新闻数组
  1600. // 查询所有子级栏目的图文新闻
  1601. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1602. ->where(function ($query) use ($data) {
  1603. $query->where(function ($subQuery) use ($data) {
  1604. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1605. })->orWhereNull("ignore_ids");
  1606. })
  1607. ->where('status', 1)
  1608. ->where('imgurl', '!=', '')
  1609. ->select('*')
  1610. ->orderBy('updated_at', 'desc')
  1611. ->limit($data['child_imgnum'])
  1612. ->get();
  1613. }
  1614. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1615. // 查询所有子级栏目的文字新闻
  1616. $textArticles = Article::where('catid', $childCategoryIds[0])
  1617. ->where('status', 1)
  1618. ->where(function ($query) use ($data) {
  1619. $query->where(function ($subQuery) use ($data) {
  1620. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1621. })->orWhereNull("ignore_ids");
  1622. })
  1623. ->select('*')
  1624. ->orderBy('updated_at', 'desc')
  1625. ->limit($data['child_textnum'])
  1626. ->get();
  1627. }
  1628. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1629. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1630. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1631. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1632. return $child;
  1633. }, $category['child']);
  1634. }
  1635. // }
  1636. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1637. $category['img'] = WebsiteCategory::where($where)
  1638. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1639. ->where('article.status', 1)
  1640. ->where('article.imgurl', '!=', '')
  1641. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1642. ->orderBy('article.updated_at', 'desc')
  1643. ->limit($data['img_num'])
  1644. ->get();
  1645. }
  1646. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1647. $category['text'] = WebsiteCategory::where($where)
  1648. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1649. ->where('article.status', 1)
  1650. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1651. ->orderBy('article.updated_at', 'desc')
  1652. ->limit($data['text_num'])
  1653. ->get();
  1654. }
  1655. // $category = $category->get();
  1656. if (empty($category)) {
  1657. return Result::error("查询失败", 0);
  1658. }
  1659. return Result::success($category);
  1660. }
  1661. /**
  1662. * 模块新闻加强plus版
  1663. * @param array $data
  1664. * @return array
  1665. */
  1666. public function getWebsiteAllArticle(array $data): array
  1667. {
  1668. // return Result::success($data);
  1669. $time1 = microtime(true);
  1670. $wetbsite_id = $data['website_id'] ?? 2;
  1671. $data = json_decode($data['id'], true);
  1672. $website = Website::where('id', $wetbsite_id)->first();
  1673. if (empty($website)) {
  1674. return Result::error("网站不存在", 0);
  1675. }
  1676. // return Result::success($website);
  1677. $website_column = $website['website_column_arr_id'] ?? '[]';
  1678. $website_column = json_decode($website_column, true);
  1679. $categorys = $this->processArticlePro($wetbsite_id);
  1680. $cat_1st_arr = $categorys['cat_1st_arr'];
  1681. $catiall = $categorys['catiall'];
  1682. // return Result::success($catiall);
  1683. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1684. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1685. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1686. }
  1687. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1688. // return Result::success($categorys);
  1689. $parent_category = array_column($data, 'parent');
  1690. $parent_cat = [];
  1691. $child_category = array_column($data, 'child');
  1692. if (!empty($parent_category)) {
  1693. foreach ($parent_category as $key => $value) {
  1694. $arr = array_map('intval', explode(',', $value));
  1695. $parent_cat[$key] = $arr[0] ?? 0;
  1696. $parent_category = $arr[0] ?? 0;
  1697. $article_imgnum = $arr[1] ?? 0;
  1698. $article_textnum = $arr[2] ?? 0;
  1699. if ($parent_category != 0) {
  1700. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1701. // return Result::success($category_arr);
  1702. if ($article_imgnum != 0) {
  1703. $img_article = Article::whereIn('catid', $category_arr)
  1704. ->where('status', 1)
  1705. ->where('imgurl', '!=', '')
  1706. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1707. $query->from('article_ignore')
  1708. ->where('website_id', $wetbsite_id);
  1709. }, 'article_ignore', function ($join) {
  1710. $join->on('article_ignore.article_id', '=', 'article.id');
  1711. })
  1712. ->where(function ($query) use ($wetbsite_id) {
  1713. $query->whereNull('article_ignore.article_id')
  1714. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1715. })
  1716. ->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')
  1717. ->orderBy('updated_at', 'desc')
  1718. ->limit($article_imgnum)
  1719. ->get()->all();
  1720. foreach ($img_article as $k => $v) {
  1721. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1722. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1723. }
  1724. } else {
  1725. $img_article = [];
  1726. }
  1727. if ($article_textnum != 0) {
  1728. $text_article = Article::whereIn('catid', $category_arr)
  1729. ->where('status', 1)
  1730. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1731. $query->from('article_ignore')
  1732. ->where('website_id', $wetbsite_id);
  1733. }, 'article_ignore', function ($join) {
  1734. $join->on('article_ignore.article_id', '=', 'article.id');
  1735. })
  1736. ->where(function ($query) use ($wetbsite_id) {
  1737. $query->whereNull('article_ignore.article_id')
  1738. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1739. })
  1740. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1741. ->orderBy('updated_at', 'desc')
  1742. ->limit($article_textnum)
  1743. ->get()->all();
  1744. foreach ($text_article as $k => $v) {
  1745. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1746. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1747. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1748. }
  1749. } else {
  1750. $text_article = [];
  1751. }
  1752. $catiall[$parent_category]['imgnum'] = $img_article;
  1753. $catiall[$parent_category]['textnum'] = $text_article;
  1754. $parent[$key] = $catiall[$parent_category];
  1755. } else {
  1756. $parent[$key] = '';
  1757. }
  1758. }
  1759. }
  1760. if (!empty($child_category)) {
  1761. foreach ($child_category as $key => $value) {
  1762. $arr = array_map('intval', explode(',', $value));
  1763. $parent_category = $parent_cat[$key];
  1764. $child_category = $arr[0] ?? 0;
  1765. $article_imgnum = $arr[1] ?? 0;
  1766. $article_textnum = $arr[2] ?? 0;
  1767. if ($child_category != 0) {
  1768. $all_childcat = $cat_1st_arr[$parent_category];
  1769. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1770. // 从 $websiteInfoIndexed 中获取对应的数据
  1771. $info = $websiteInfoIndexed[$v];
  1772. // 返回一个包含所需信息的数组
  1773. return [
  1774. 'alias' => $info->alias,
  1775. 'category_id' => $info->category_id,
  1776. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1777. 'pid' => $info->pid,
  1778. 'type' => $info->type,
  1779. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1780. 'pinyin' => $info->pinyin,
  1781. ];
  1782. }, $all_childcat);
  1783. if ($article_imgnum != 0) {
  1784. $img_article = Article::where('catid', $child_category)
  1785. ->where('status', 1)
  1786. ->where('imgurl', '!=', '')
  1787. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1788. $query->from('article_ignore')
  1789. ->where('website_id', $wetbsite_id);
  1790. }, 'article_ignore', function ($join) {
  1791. $join->on('article_ignore.article_id', '=', 'article.id');
  1792. })
  1793. ->where(function ($query) use ($wetbsite_id) {
  1794. $query->whereNull('article_ignore.article_id')
  1795. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1796. })
  1797. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1798. ->orderBy('updated_at', 'desc')
  1799. ->limit($article_imgnum)
  1800. ->get()->all();
  1801. foreach ($img_article as $k => $v) {
  1802. // var_dump($v);
  1803. // var_dump($k);
  1804. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1805. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1806. }
  1807. } else {
  1808. $img_article = [];
  1809. }
  1810. if ($article_textnum != 0) {
  1811. $text_article = Article::where('catid', $child_category)
  1812. ->where('status', 1)
  1813. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1814. $query->from('article_ignore')
  1815. ->where('website_id', $wetbsite_id);
  1816. }, 'article_ignore', function ($join) {
  1817. $join->on('article_ignore.article_id', '=', 'article.id');
  1818. })
  1819. ->where(function ($query) use ($wetbsite_id) {
  1820. $query->whereNull('article_ignore.article_id')
  1821. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1822. })
  1823. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1824. ->orderBy('updated_at', 'desc')
  1825. ->limit($article_textnum)
  1826. ->get()->all();
  1827. foreach ($text_article as $k => $v) {
  1828. // var_dump($v);
  1829. // var_dump($k);
  1830. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1831. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1832. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1833. }
  1834. } else {
  1835. $text_article = [];
  1836. }
  1837. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1838. $catiall[$child_category]['imgnum'] = $img_article;
  1839. $catiall[$child_category]['textnum'] = $text_article;
  1840. $child[$key] = $catiall[$child_category];
  1841. // var_dump($pids);
  1842. } else {
  1843. $child[$key] = '';
  1844. }
  1845. }
  1846. }
  1847. foreach ($parent as $key => $value) {
  1848. $result[$key] = $value;
  1849. if (!empty($child[$key])) {
  1850. // var_dump($child[$key]);
  1851. $result[$key]['child'] = $child[$key];
  1852. // $value[$key]['child'] = $child[$key];
  1853. } else {
  1854. $result[$key]['child'] = [
  1855. "alias" => null,
  1856. "category_id" => null,
  1857. "type" => null,
  1858. "pinyin" => null,
  1859. "all_childcat" => [],
  1860. "imgnum" => [],
  1861. "textnum" => []
  1862. ];
  1863. }
  1864. }
  1865. return Result::success($result);
  1866. }
  1867. /**
  1868. * 辅助方法:获取文章列表
  1869. */
  1870. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1871. {
  1872. sleep(1);
  1873. $query = Article::where('article.status', 1)
  1874. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1875. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1876. ->where(function ($query) use ($website) {
  1877. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1878. })
  1879. ->leftJoin('website_category', function ($join) use ($website) {
  1880. $join->on('article.catid', '=', 'website_category.category_id')
  1881. ->where('website_category.website_id', '=', $website['website_id']);
  1882. })
  1883. ->select(
  1884. 'article.id',
  1885. 'article.title',
  1886. 'article.imgurl',
  1887. 'article.author',
  1888. 'article.updated_at',
  1889. 'article.introduce',
  1890. 'article.islink',
  1891. 'article.linkurl',
  1892. 'article.copyfrom',
  1893. 'article.cat_arr_id',
  1894. 'article.catid',
  1895. 'website_category.alias as category_name'
  1896. )
  1897. ->orderBy('updated_at', 'desc')
  1898. ->limit($limit);
  1899. // 如果是图片文章,添加图片URL条件
  1900. if ($isImageArticle) {
  1901. $query->where('imgurl', '!=', '');
  1902. } else {
  1903. // 文字文章不需要imgurl字段
  1904. $query->addSelect('article.introduce');
  1905. }
  1906. $articles = $query->get();
  1907. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1908. }
  1909. /**
  1910. * 乡村网-获取特殊新闻模块
  1911. * @param array $data
  1912. * @return array
  1913. */
  1914. public function getWebsiteArticles(array $data): array
  1915. {
  1916. $website_id = $data['website_id'];
  1917. $website = Website::where('id', $website_id)->first();
  1918. if (empty($website)) {
  1919. return Result::error("网站不存在", 0);
  1920. }
  1921. // return Result::success($website);
  1922. $website_column = $website['website_column_arr_id'] ?? '[]';
  1923. $website_column = json_decode($website_column, true);
  1924. $catids = json_decode($data['id'], true);
  1925. $parent_category = array_column($catids, 'parent');
  1926. if (!empty($parent_category) && is_array($parent_category)) {
  1927. $categorys = $this->processArticlePro($website_id);
  1928. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1929. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1930. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1931. }
  1932. $catiall = $categorys['catiall'];
  1933. $cat_1st_arr = $categorys['cat_1st_arr'];
  1934. // return Result::success($categorys);
  1935. foreach ($parent_category as $key => $value) {
  1936. $arr = array_map('intval', explode(',', $value));
  1937. $parent_category = $arr[0] ?? 0;
  1938. $article_imgnum = $arr[1] ?? 0;
  1939. $article_textnum = $arr[2] ?? 0;
  1940. if ($parent_category != 0) {
  1941. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1942. // return Result::success($category_arr);
  1943. if ($article_imgnum != 0) {
  1944. $img_article = Article::whereIn('catid', $category_arr)
  1945. ->where('status', 1)
  1946. ->where('imgurl', '!=', '')
  1947. ->leftJoinSub(function ($query) use ($website_id) {
  1948. $query->from('article_ignore')
  1949. ->where('website_id', $website_id);
  1950. }, 'article_ignore', function ($join) {
  1951. $join->on('article_ignore.article_id', '=', 'article.id');
  1952. })
  1953. ->where(function ($query) use ($website_id) {
  1954. $query->whereNull('article_ignore.article_id')
  1955. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1956. })
  1957. ->select(
  1958. 'id',
  1959. 'title',
  1960. 'imgurl',
  1961. 'author',
  1962. 'updated_at',
  1963. 'introduce',
  1964. 'islink',
  1965. 'linkurl',
  1966. 'copyfrom',
  1967. 'cat_arr_id',
  1968. 'catid as category_id'
  1969. )
  1970. ->orderBy('updated_at', 'desc')
  1971. ->limit($article_imgnum)
  1972. ->get()->all();
  1973. foreach ($img_article as $k => $v) {
  1974. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1975. // return Result::success($v);
  1976. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1977. }
  1978. } else {
  1979. $img_article = [];
  1980. }
  1981. if ($article_textnum != 0) {
  1982. $text_article = Article::whereIn('catid', $category_arr)
  1983. ->where('status', 1)
  1984. ->leftJoinSub(function ($query) use ($website_id) {
  1985. $query->from('article_ignore')
  1986. ->where('website_id', $website_id);
  1987. }, 'article_ignore', function ($join) {
  1988. $join->on('article_ignore.article_id', '=', 'article.id');
  1989. })
  1990. ->where(function ($query) use ($website_id) {
  1991. $query->whereNull('article_ignore.article_id')
  1992. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1993. })
  1994. ->select(
  1995. 'id',
  1996. 'title',
  1997. 'author',
  1998. 'updated_at',
  1999. 'introduce',
  2000. 'islink',
  2001. 'linkurl',
  2002. 'copyfrom',
  2003. 'cat_arr_id',
  2004. 'catid as category_id'
  2005. )
  2006. ->orderBy('updated_at', 'desc')
  2007. ->limit($article_textnum)
  2008. ->get()->all();
  2009. foreach ($text_article as $k => $v) {
  2010. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2011. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2012. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2013. }
  2014. } else {
  2015. $text_article = [];
  2016. }
  2017. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2018. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2019. $parent[$key] = $catiall[$parent_category];
  2020. } else {
  2021. $parent[$key] = [];
  2022. }
  2023. }
  2024. }
  2025. return Result::success($parent);
  2026. }
  2027. // 封装处理商品的路由问题
  2028. function processGoods($goods, $data)
  2029. {
  2030. return $goods->map(function ($good) use ($data) {
  2031. $catid = $good->catid ?? 0;
  2032. // $pinyin = '';
  2033. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2034. if (!empty($category->pid) && $category->pid != 0) {
  2035. $level = json_decode($category->category_arr_id, true);
  2036. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2037. ->whereIn('category_id', $level)
  2038. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2039. ->get(['aLIas_pinyin'])
  2040. ->pluck('aLIas_pinyin')
  2041. ->implode('/');
  2042. } else {
  2043. $pinyin = $category->aLIas_pinyin ?? '';
  2044. }
  2045. if (isset($good->city_id) && !empty($good->city_id)) {
  2046. $city = District::where('id', $good->city_id)->first(['name']);
  2047. $good->city_name = $city->name ?? '';
  2048. }
  2049. // 解析imgurl JSON并取第一条数据
  2050. $imgUrls = json_decode($good->imgurl, true);
  2051. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2052. $good->pinyin = $pinyin;
  2053. return $good;
  2054. });
  2055. }
  2056. /**
  2057. * 获取商城首页-根据栏目id
  2058. * @param array $data
  2059. * @return array
  2060. * */
  2061. function getWebsiteCatidshop(array $data): array
  2062. {
  2063. $input['catid'] = $data['catid'];
  2064. $input['website_id'] = $data['website_id'];
  2065. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2066. $result = array_map(function ($item) use ($input) {
  2067. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2068. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2069. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2070. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2071. if (empty($category) || $category->type != 2) {
  2072. return Result::error("暂无此栏目", 0);
  2073. } else {
  2074. $website['website_id'] = $input['website_id'];
  2075. $goods = Good::where('good.status', 2)
  2076. ->where('good.website_id', $website['website_id'])
  2077. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2078. ->select(
  2079. 'good.id',
  2080. 'good.name',
  2081. 'good.imgurl',
  2082. 'good.description',
  2083. 'good.updated_at',
  2084. 'good.catid',
  2085. 'good.type_id',
  2086. 'good.price',
  2087. 'good.com',
  2088. 'good.level',
  2089. 'good.unit'
  2090. )
  2091. ->orderBy('updated_at', 'desc')
  2092. ->offset($goodStart)
  2093. ->limit($goodNum);
  2094. $all_goods = $goods->get();
  2095. $all_goods = $this->processGoods($all_goods, $website);
  2096. }
  2097. return $all_goods ?? [];
  2098. }
  2099. }, $data);
  2100. return Result::success($result);
  2101. }
  2102. /**
  2103. * 获取商品模块
  2104. * @param array $data
  2105. * @return array
  2106. * */
  2107. public function getWebsiteshop(array $data): array
  2108. {
  2109. $input['id'] = $data['id'];
  2110. $input['website_id'] = $data['website_id'];
  2111. $catid = $data['catid'];
  2112. $data = json_decode($input['id'] ?? '', true) ?? [];
  2113. $result['goods'] = array_map(function ($item) use ($input) {
  2114. // 检查parent元素是否存在且不是undefined
  2115. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2116. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2117. $website = $input['website_id'];
  2118. $query = Good::where('good.status', 2)
  2119. ->where('good.website_id', $website);
  2120. switch ($Levelid) {
  2121. case 1:
  2122. case 2:
  2123. case 3:
  2124. $goods = $query->where(function ($q) use ($Levelid) {
  2125. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2126. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2127. });
  2128. break;
  2129. case 4:
  2130. $goods = $query;
  2131. break;
  2132. case 5:
  2133. $goods = $query->where('type_id', 1);
  2134. break;
  2135. case 6:
  2136. $goods = $query->where('type_id', 2);
  2137. break;
  2138. default:
  2139. return [];
  2140. }
  2141. $all_goods = $goods
  2142. ->select(
  2143. 'good.id',
  2144. 'good.name',
  2145. 'good.imgurl',
  2146. 'good.description',
  2147. 'good.updated_at',
  2148. 'good.catid',
  2149. 'good.type_id',
  2150. 'good.price',
  2151. 'good.level',
  2152. 'good.website_id'
  2153. )
  2154. ->orderBy('updated_at', 'desc')
  2155. ->offset($goodStart)
  2156. ->limit($goodNum)
  2157. ->get();
  2158. $web['website_id'] = $website;
  2159. $all_goods = $this->processGoods($all_goods, $web);
  2160. }
  2161. return $all_goods;
  2162. }, $data);
  2163. $website = $input['website_id'];
  2164. $result['article'] = Article::where(function ($query) use ($website) {
  2165. $query->where(function ($subQuery) use ($website) {
  2166. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2167. })->orWhereNull("ignore_ids");
  2168. })
  2169. ->where('catid', $catid)
  2170. ->where('article.status', 1)
  2171. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2172. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2173. ->orderBy('article.updated_at', 'desc')
  2174. ->first();
  2175. return Result::success($result);
  2176. }
  2177. /**
  2178. * 获取商品分类
  2179. * @param array $data
  2180. * @return array
  2181. * */
  2182. public function getWebsiteshopCat(array $data): array
  2183. {
  2184. $website = $data['website_id'];
  2185. $category = WebsiteCategory::where('website_id', $website)
  2186. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2187. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2188. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2189. ->orderBy('sort')
  2190. ->get();
  2191. $cat = $category->map(function ($item) use ($website) {
  2192. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2193. $pid = $item->pid ?? 0;
  2194. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2195. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2196. ->where('website_id', $website)
  2197. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2198. ->get(['aLIas_pinyin'])
  2199. ->pluck('aLIas_pinyin')
  2200. ->implode('/');
  2201. } else {
  2202. $pinyin = $item->aLIas_pinyin ?? '';
  2203. }
  2204. $item->pinyin = $pinyin;
  2205. });
  2206. if (empty($category)) {
  2207. return Result::error("栏目查询失败", 0);
  2208. }
  2209. $cat_tree = Result::buildMenuTree($category);
  2210. $web['website_id'] = $website;
  2211. $goods = Good::where('website_id', $website)
  2212. ->where('status', 2)
  2213. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2214. ->latest('updated_at')
  2215. ->offset(($data['page'] - 1) * $data['pageSize'])
  2216. ->limit($data['pageSize'])
  2217. ->get();
  2218. if (!empty($goods)) {
  2219. if ($goods->count() > 1 && !empty($goods)) {
  2220. $goods = $this->processGoods($goods, $web);
  2221. }
  2222. } else {
  2223. $goods = [];
  2224. }
  2225. $result = [
  2226. 'category' => $cat_tree,
  2227. 'goods' => $goods,
  2228. ];
  2229. // $resul['goods'] = $goods;
  2230. if (empty($result)) {
  2231. return Result::error("查询失败", 0);
  2232. }
  2233. return Result::success($result);
  2234. }
  2235. /*
  2236. * 获取商品列表
  2237. * @param array $data
  2238. * @return array
  2239. * */
  2240. public function getWebsiteshopList(array $data): array
  2241. {
  2242. // return Result::success($data);
  2243. $where = [
  2244. 'status' => 2,
  2245. 'website_id' => $data['website_id'],
  2246. ];
  2247. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2248. // return Result::error("查询失败", 0);
  2249. // }
  2250. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2251. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2252. $data['catid'] = $category->category_id ?? 0;
  2253. }
  2254. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2255. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2256. }
  2257. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2258. array_push($where, ['type_id', $data['type_id']]);
  2259. }
  2260. $query = Good::where($where)
  2261. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2262. $query->where(function ($q) use ($data) {
  2263. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2264. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2265. });
  2266. })
  2267. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2268. $query->where(function ($q) use ($data) {
  2269. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2270. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2271. });
  2272. })
  2273. ->select(
  2274. 'good.id',
  2275. 'good.name',
  2276. 'good.imgurl',
  2277. 'good.description',
  2278. 'good.updated_at',
  2279. 'good.com',
  2280. 'good.catid',
  2281. 'good.type_id',
  2282. 'good.website_id',
  2283. 'good.cat_arr_id',
  2284. 'good.created_at',
  2285. 'good.city_id'
  2286. )
  2287. ->latest('updated_at');
  2288. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2289. $result['count'] = $query->clone()->count();
  2290. $result['goods'] = $this->processGoods(
  2291. $query->clone()
  2292. ->offset(($data['page'] - 1) * $data['pageSize'])
  2293. ->limit($data['pageSize'])
  2294. ->get(),
  2295. $data
  2296. );
  2297. } else {
  2298. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2299. // 获取 type_id 为 1 的数据
  2300. $result['type1'] = $this->processGoods(
  2301. $query->clone()
  2302. ->where('type_id', 1)
  2303. ->offset(($data['page'] - 1) * $data['pageSize'])
  2304. ->limit($data['pageSize'])
  2305. ->get(),
  2306. $data
  2307. );
  2308. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2309. // 获取 type_id 为 2 的数据
  2310. $result['type2'] = $this->processGoods(
  2311. $query->clone()
  2312. ->where('type_id', 2)
  2313. ->offset(($data['page'] - 1) * $data['pageSize'])
  2314. ->limit($data['pageSize'])
  2315. ->get(),
  2316. $data
  2317. );
  2318. }
  2319. if (empty($result)) {
  2320. return Result::error("查询失败", 0);
  2321. }
  2322. return Result::success($result);
  2323. }
  2324. /**
  2325. * 获取商品详情
  2326. * @param array $data
  2327. * @return array
  2328. * */
  2329. public function getWebsiteshopInfo(array $data): array
  2330. {
  2331. $where = [
  2332. 'good.status' => 2,
  2333. 'good.website_id' => $data['website_id'],
  2334. 'good.id' => $data['id'],
  2335. ];
  2336. $goods = Good::where($where)
  2337. ->where('good.id', $data['id'])
  2338. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2339. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2340. ->first();
  2341. if (empty($goods)) {
  2342. return Result::error("查询失败", 0);
  2343. }
  2344. $goods->imgurl = json_decode($goods->imgurl, true);
  2345. return Result::success($goods);
  2346. }
  2347. /**
  2348. * plus pro 处理文章路由问题
  2349. */
  2350. function processArticlePro($website_id)
  2351. {
  2352. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2353. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2354. // // 取出category_id 对应的aLIas_pinyin
  2355. // $categoryIds = array_column($categorys, 'category_id');
  2356. // $categoryPIds = array_column($categorys, 'pid');
  2357. // $aliasPinyins = array_column($categorys, 'path');
  2358. // $alias = array_column($categorys, 'alias');
  2359. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2360. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2361. // // return Result::success($cat_arr);
  2362. // // $catiall = [];
  2363. // //一级所有子级的记录
  2364. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2365. // return [
  2366. // 'cat_1st_arr' => $cat_alias_arr,
  2367. // 'catiall' => $cat_arr,
  2368. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2369. // 'categoryIds' => $categoryIds,
  2370. // ];
  2371. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2372. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2373. // 取出category_id 对应的aLIas_pinyin
  2374. $categoryIds = array_column($categorys, 'category_id');
  2375. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2376. return $pid != 0;
  2377. })));
  2378. $category_path = array_column($categorys, 'path');
  2379. $cat_arr = array_combine($categoryIds, $category_path);
  2380. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2381. $catiall = [];
  2382. //一级所有子级的记录
  2383. $cat_1st_arr = [];
  2384. foreach ($categorys as $key => $value) {
  2385. // $category_arr_id = json_decode($value->category_arr_id);
  2386. // $pinyin_str = '';
  2387. // // 算出一级 并且算出子级
  2388. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2389. $cat_1st_arr[$value->pid][] = $value->category_id;
  2390. }
  2391. // foreach ($category_arr_id as $k => $v) {
  2392. // $pinyin_str .= $cat_arr[$v] . '/';
  2393. // }
  2394. // $pinyin_str = rtrim($pinyin_str, '/');
  2395. $catiall[$value->category_id]['alias'] = $value->alias;
  2396. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2397. $catiall[$value->category_id]['type'] = $value->type;
  2398. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2399. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2400. }
  2401. return [
  2402. 'cat_1st_arr' => $cat_1st_arr,
  2403. 'catiall' => $catiall,
  2404. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2405. 'categoryIds' => $categoryIds,
  2406. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2407. 'categoryPIds' => $categoryPIds,
  2408. ];
  2409. }
  2410. /**
  2411. * 封装处理文章的路由问题
  2412. * */
  2413. function processArticles($articles, $data)
  2414. {
  2415. // 检查 $articles 是否为数组或可迭代对象
  2416. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2417. return $articles->map(function ($article) use ($data) {
  2418. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2419. $catid = $article->cat_arr_id ?? '';
  2420. }
  2421. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2422. $catid = $article->category_arr_id ?? '';
  2423. }
  2424. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2425. $level = json_decode($catid, true);
  2426. if (!is_array($level)) {
  2427. return $article;
  2428. } else {
  2429. $level = array_map('intval', $level);
  2430. }
  2431. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2432. ->where($data)
  2433. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2434. ->pluck('aLIas_pinyin')
  2435. ->implode('/');
  2436. $article->pinyin = $pinyin ?? '';
  2437. return $article;
  2438. });
  2439. } else {
  2440. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2441. $catid = $articles->cat_arr_id ?? '';
  2442. $level = json_decode($catid, true);
  2443. if (!is_array($level)) {
  2444. return $articles;
  2445. } else {
  2446. $level = array_map('intval', $level);
  2447. }
  2448. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2449. ->where($data)
  2450. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2451. ->pluck('aLIas_pinyin')
  2452. ->implode('/');
  2453. $articles->pinyin = $pinyin ?? '';
  2454. return $articles;
  2455. }
  2456. }
  2457. // 封装处理由问题
  2458. function processJob($job, $data)
  2459. {
  2460. return $job->map(function ($job) use ($data) {
  2461. $category = $job->cat_arr_id ?? '';
  2462. $cityid = $job->city_arr_id ?? '';
  2463. $city = json_decode($cityid, true);
  2464. $pinyin = '';
  2465. $level = json_decode($category, true);
  2466. // 路由
  2467. if (!empty($level) && is_array($level)) {
  2468. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2469. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2470. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2471. ->get(['aLIas_pinyin'])
  2472. ->pluck('aLIas_pinyin')
  2473. ->implode('/');
  2474. if (empty($pinyin)) {
  2475. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2476. }
  2477. $job->pinyin = $pinyin;
  2478. }
  2479. // 取职位-城市 市??省
  2480. if (!empty($city) && is_array($city)) {
  2481. if (isset($city[1]) && !empty($city[1])) {
  2482. $city = District::where('id', $city[1])->first(['name']);
  2483. $job->city_name = $city->name ?? '';
  2484. } else if (isset($city[0]) && !empty($city[0])) {
  2485. $city = District::where('id', $city[0])->first(['name']);
  2486. $job->city_name = $city->name ?? '';
  2487. } else {
  2488. $job->city_name = '全国';
  2489. }
  2490. }
  2491. // 获取简历最后一级地区
  2492. if (isset($job->city_id) && !empty($job->city_id)) {
  2493. $city = District::where('id', $job->city_id)->first(['name']);
  2494. $job->hunt_cityname = $city->name ?? '';
  2495. }
  2496. // 组合详细地址
  2497. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2498. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2499. if (is_array($address_id) && !empty($address_id)) {
  2500. $address = District::whereIn('id', $address_id)
  2501. ->orderBy('level', 'asc')
  2502. ->get(['name'])
  2503. ->pluck('name')
  2504. ->implode('');
  2505. // $job->address_name = $address ?? '';
  2506. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2507. }
  2508. }
  2509. // 取行业
  2510. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2511. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2512. if (!empty($job->industry)) {
  2513. $query->where('hyid', $job->industry);
  2514. } else if (!empty($job->hy_id)) {
  2515. $query->where('hyid', $job->hy_id);
  2516. } else if (!empty($job->company_hy_id)) {
  2517. $query->where('hyid', $job->company_hy_id);
  2518. } else {
  2519. $query->where('hyid', $job->job_industry);
  2520. }
  2521. })->first(['hyname']);
  2522. $job->hy_name = $hy_name->hyname ?? '';
  2523. }
  2524. // 取职位类别
  2525. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2526. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2527. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2528. $job->zw_name = $zw_name->zwname ?? '';
  2529. }
  2530. // 取具体职位
  2531. 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))) {
  2532. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2533. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2534. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2535. }
  2536. // 取工作经验
  2537. if (isset($job->experience) && !empty($job->experience)) {
  2538. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2539. $job->experience_name = $experience->ename ?? '';
  2540. }
  2541. // 取学历
  2542. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2543. $education = $job->educational ?? $job->school_education;
  2544. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2545. $job->education_name = $education->ename ?? '';
  2546. }
  2547. // 语言
  2548. if (isset($job->language) && !empty($job->language)) {
  2549. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2550. $job->language_name = $language->ename ?? '';
  2551. }
  2552. // 薪资
  2553. if (isset($job->salary) && !empty($job->salary)) {
  2554. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2555. $job->salary_name = $salary->ename ?? '';
  2556. }
  2557. // 职位性质
  2558. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2559. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2560. $job->job_nature_name = $job_nature->ename ?? '';
  2561. }
  2562. // 公司规模
  2563. if (isset($job->company_size) && !empty($job->company_size)) {
  2564. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2565. $job->company_size_name = $company_size->ename ?? '';
  2566. }
  2567. // 公司性质
  2568. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2569. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2570. $job->company_nature_name = $company_nature->nature_name ?? '';
  2571. }
  2572. // $job->pinyin = $pinyin;
  2573. return $job;
  2574. });
  2575. }
  2576. /**
  2577. * 获取书籍模块
  2578. * @param array $data
  2579. * @return array
  2580. * */
  2581. public function getWebsiteBook(array $data): array
  2582. {
  2583. $input['id'] = $data['id'];
  2584. $input['website_id'] = $data['website_id'];
  2585. // 将 JSON 字符串转换为 PHP 数组
  2586. $data = json_decode($input['id'], true);
  2587. // 使用 array_map 处理每个元素
  2588. $result = array_map(function ($item) use ($input) {
  2589. // 检查parent元素是否存在且不是undefined
  2590. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2591. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2592. $website = [
  2593. 'website_id' => $input['website_id'],
  2594. ];
  2595. // 查询栏目名称
  2596. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2597. if (empty($category)) {
  2598. $parent_alias = '';
  2599. $parent_pinyin = null;
  2600. $imgBooks = [];
  2601. $textBooks = [];
  2602. } else {
  2603. $parent_alias = $category->alias ?? '';
  2604. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2605. // 查找子分类ID数组
  2606. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2607. array_push($childCategoryIds, $parentCatId);
  2608. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2609. if ($parentImgNum != 0) {
  2610. // 查询图片新闻
  2611. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2612. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2613. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2614. })
  2615. ->where('book.status', 2)
  2616. ->where('book.img_url', '!=', '')
  2617. ->where('book.website_id', $website['website_id'])
  2618. ->leftJoin('website_category', function ($join) use ($website) {
  2619. $join->on('book.cat_id', '=', 'website_category.category_id')
  2620. ->where('website_category.website_id', '=', $website['website_id']);
  2621. })
  2622. ->select(
  2623. 'book.id',
  2624. 'book.title',
  2625. 'book.img_url',
  2626. 'book.price',
  2627. 'book.market_price',
  2628. 'book.description',
  2629. 'book.cat_id',
  2630. 'book.description',
  2631. 'book.updated_at',
  2632. 'website_category.alias as category_name',
  2633. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2634. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2635. )
  2636. ->orderBy('updated_at', 'desc')
  2637. ->limit($parentImgNum)
  2638. ->get()->all();
  2639. // 查询文字新闻
  2640. }
  2641. if ($parentTextNum != 0) {
  2642. $textBooks = [];
  2643. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2644. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2645. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2646. })
  2647. ->where('book.status', 2)
  2648. ->where('book.website_id', $website['website_id'])
  2649. ->leftJoin('website_category', function ($join) use ($website) {
  2650. $join->on('book.cat_id', '=', 'website_category.category_id')
  2651. ->where('website_category.website_id', '=', $website['website_id']);
  2652. })
  2653. ->select(
  2654. 'book.id',
  2655. 'book.title',
  2656. 'book.img_url',
  2657. 'book.price',
  2658. 'book.market_price',
  2659. 'book.description',
  2660. 'book.cat_id',
  2661. 'book.description',
  2662. 'book.updated_at',
  2663. 'website_category.alias as category_name',
  2664. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2665. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2666. )
  2667. ->orderBy('updated_at', 'desc')
  2668. ->limit($parentTextNum)
  2669. ->get()->all();
  2670. }
  2671. }
  2672. }
  2673. $resultItem = [
  2674. 'alias' => $parent_alias ?? '',
  2675. 'category_id' => $parentCatId ?? 0,
  2676. 'pinyin' => $parent_pinyin ?? null,
  2677. 'imgnum' => $imgBooks ?? [],
  2678. 'textnum' => $textBooks ?? [],
  2679. ];
  2680. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2681. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2682. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2683. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2684. ->get()->all();
  2685. if (!empty($childCategory)) {
  2686. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2687. // 查询子栏目名称
  2688. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2689. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2690. ->first();
  2691. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2692. $childImgArticles = [];
  2693. $childTextArticles = [];
  2694. $resultItem['child'] = [];
  2695. } else {
  2696. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2697. // 查询子栏目图片新闻
  2698. $childImgArticles = Book::where('cat_id', $childCatId)
  2699. ->where('status', 2)
  2700. ->where('img_url', '!=', '')
  2701. ->where('book.website_id', $website['website_id'])
  2702. ->leftJoin('website_category', function ($join) use ($website) {
  2703. $join->on('book.cat_id', '=', 'website_category.category_id')
  2704. ->where('website_category.website_id', '=', $website['website_id']);
  2705. })
  2706. ->select(
  2707. 'book.id',
  2708. 'book.title',
  2709. 'book.img_url',
  2710. 'book.price',
  2711. 'book.market_price',
  2712. 'book.description',
  2713. 'book.cat_id',
  2714. 'book.description',
  2715. 'book.updated_at',
  2716. DB::raw("'$child_pinyin' as pinyin")
  2717. )
  2718. ->orderBy('updated_at', 'desc')
  2719. ->limit($childImgNum)
  2720. ->get()->all();
  2721. // 查询子栏目文字新闻
  2722. $childTextArticles = Book::where('cat_id', $childCatId)
  2723. ->where('status', 2)
  2724. ->where('book.website_id', $website['website_id'])
  2725. ->leftJoin('website_category', function ($join) use ($website) {
  2726. $join->on('book.cat_id', '=', 'website_category.category_id')
  2727. ->where('website_category.website_id', '=', $website['website_id']);
  2728. })
  2729. ->select(
  2730. 'book.id',
  2731. 'book.title',
  2732. 'book.img_url',
  2733. 'book.price',
  2734. 'book.market_price',
  2735. 'book.description',
  2736. 'book.cat_id',
  2737. 'book.description',
  2738. 'book.updated_at',
  2739. DB::raw("'$child_pinyin' as pinyin")
  2740. )
  2741. ->orderBy('updated_at', 'desc')
  2742. ->limit($childTextNum)
  2743. ->get()->all();
  2744. $resultItem['child'] = [
  2745. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2746. 'category_id' => $childCatId,
  2747. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2748. 'all_childcat' => $childCategory,
  2749. 'imgnum' => $childImgArticles,
  2750. 'textnum' => $childTextArticles,
  2751. ];
  2752. }
  2753. }
  2754. } else {
  2755. $resultItem['child'] = [];
  2756. }
  2757. return $resultItem;
  2758. }, $data);
  2759. return Result::success($result);
  2760. }
  2761. /**
  2762. * 获取书刊列表
  2763. * @param array $data
  2764. * @return array
  2765. * */
  2766. public function getWebsiteBookList(array $data): array
  2767. {
  2768. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2769. if (empty($web)) {
  2770. return Result::error("查询失败", 0);
  2771. }
  2772. $catid = $data['id'];
  2773. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2774. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2775. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2776. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2777. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2778. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2779. ->where('pid', $category['pid'])
  2780. ->select(
  2781. 'category_id',
  2782. 'alias',
  2783. 'aLIas_pinyin',
  2784. 'pid',
  2785. 'sort',
  2786. 'is_url',
  2787. 'web_url',
  2788. 'seo_title',
  2789. 'seo_keywords',
  2790. 'seo_description',
  2791. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2792. )
  2793. ->orderBy('sort')
  2794. ->get()->all();
  2795. if (empty($category)) {
  2796. return Result::error("查询失败", 0);
  2797. }
  2798. $query = Book::where('book.status', 2)
  2799. ->where('book.website_id', $data['website_id'])
  2800. ->where('book.cat_id', $catid)
  2801. ->select(
  2802. 'book.id',
  2803. 'book.title',
  2804. 'book.img_url',
  2805. 'book.description',
  2806. 'book.updated_at',
  2807. 'book.cat_id',
  2808. DB::raw("'$pinyin' as pinyin")
  2809. )
  2810. ->orderBy('book.updated_at', 'desc');
  2811. $count = $query->count();
  2812. $query = clone $query;
  2813. $Book = $query
  2814. ->limit($data['pageSize'])
  2815. ->offset(($data['page'] - 1) * $data['pageSize'])
  2816. ->get()->all();
  2817. $result = [
  2818. 'category' => $categorys,
  2819. 'books' => $Book,
  2820. 'count' => $count,
  2821. ];
  2822. // if(empty($result)){
  2823. // return Result::error("查询失败", 0);
  2824. // }
  2825. return Result::success($result);
  2826. }
  2827. /**
  2828. * 获取书刊详情
  2829. * @param array $data
  2830. * @return array
  2831. * */
  2832. public function getWebsiteBookInfo(array $data): array
  2833. {
  2834. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2835. if (empty($web)) {
  2836. return Result::error("查询失败", 0);
  2837. }
  2838. $book = Book::where('status', 2)
  2839. ->where('website_id', $data['website_id'])
  2840. ->where('id', $data['id'])
  2841. ->select(
  2842. 'book.*',
  2843. )
  2844. ->orderBy('updated_at', 'desc')
  2845. ->first();
  2846. if (empty($book)) {
  2847. return Result::error("查询失败", 0);
  2848. }
  2849. // 先查询当前分类的 pid
  2850. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2851. ->where('category_id', $book['cat_id'])
  2852. ->first(['pid', 'category_id']);
  2853. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2854. if (!empty($carpid)) {
  2855. if ($carpid->pid != 0) {
  2856. $pid = $carpid['pid'];
  2857. // $parent_pinyin = '';
  2858. } else {
  2859. $pid = $carpid['category_id'];
  2860. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2861. }
  2862. }
  2863. $categorys = $query->where('pid', $pid)
  2864. ->select(
  2865. 'category_id',
  2866. 'alias',
  2867. 'aLIas_pinyin',
  2868. 'pid',
  2869. 'sort',
  2870. 'is_url',
  2871. 'web_url',
  2872. 'category_arr_id as cat_arr_id',
  2873. )
  2874. ->orderBy('sort')
  2875. ->get();
  2876. $category = $this->processArticle($categorys, $data);
  2877. $result = [
  2878. 'category' => $category,
  2879. 'books' => $book,
  2880. ];
  2881. return Result::success($result);
  2882. }
  2883. /**
  2884. * 尝试
  2885. * @param array $data
  2886. * @return array
  2887. * */
  2888. public function test(array $data): array
  2889. {
  2890. $input['id'] = $data['id'];
  2891. $input['website_id'] = $data['website_id'];
  2892. // 将 JSON 字符串转换为 PHP 数组
  2893. $data = json_decode($input['id'], true);
  2894. $result = [];
  2895. $article = $data;
  2896. $result = array_map(function ($item) use ($input) {
  2897. $website = [
  2898. 'website_id' => $input['website_id'],
  2899. ];
  2900. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2901. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2902. $parent = [
  2903. 0 => $category['category_id'] ?? [],
  2904. 1 => $parentImgNum ?? [],
  2905. 2 => $parentTextNum ?? [],
  2906. ];
  2907. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2908. $child = [];
  2909. $resultItem = [
  2910. // 'alias' => $parent_alias ?? '',
  2911. 'category_id' => $parentCatId ?? 0,
  2912. 'pinyin' => $parentImgNum ?? null,
  2913. 'imgnum' => $parentTextNum ?? [],
  2914. // 'textnum' => $textArticles ?? [],
  2915. ];
  2916. return $parent;
  2917. }, $data);
  2918. return Result::success($result);
  2919. // });
  2920. }
  2921. /**
  2922. * 封装处理文章的路由问题
  2923. * */
  2924. function processArticle($article, $data)
  2925. {
  2926. return $article->map(function ($article) use ($data) {
  2927. $catid = $article->cat_arr_id ?? '';
  2928. $level = json_decode($catid, true);
  2929. $pinyin = '';
  2930. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2931. if (!empty($level) && is_array($level)) {
  2932. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2933. ->where('website_id', $data['website_id'])
  2934. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2935. ->get(['aLIas_pinyin'])
  2936. ->pluck('aLIas_pinyin')
  2937. ->implode('/');
  2938. } else {
  2939. $pinyin = '';
  2940. }
  2941. $article->pinyin = $pinyin;
  2942. return $article;
  2943. });
  2944. }
  2945. /**
  2946. * c端-获取招工招聘下拉选框
  2947. * @param array $data
  2948. * @return array
  2949. * */
  2950. public function getWebsiteJobSelect(array $data): array
  2951. {
  2952. $web = Website::where('id', $data['website_id'])->first();
  2953. if (empty($web)) {
  2954. return Result::error("该网站不存在", 0);
  2955. }
  2956. $hy = JobIndustry::get()->all();
  2957. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2958. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2959. $result = [
  2960. 'hy' => $hy,
  2961. 'zw' => $zw,
  2962. 'jtzw' => $jtzw,
  2963. ];
  2964. if (empty($result)) {
  2965. return Result::error("查询失败", 0);
  2966. }
  2967. return Result::success($result);
  2968. }
  2969. /**
  2970. * c端-获取招工招聘
  2971. * @param array $data
  2972. * @return array
  2973. * */
  2974. public function getWebsiteJob(array $data): array
  2975. {
  2976. $web = Website::where('id', $data['website_id'])->first();
  2977. if (empty($web)) {
  2978. return Result::error("该网站不存在", 0);
  2979. }
  2980. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2981. ->where('job_hunting.website_id', $data['website_id'])
  2982. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2983. $query->where(function ($q) use ($data) {
  2984. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2985. });
  2986. })
  2987. ->select(
  2988. 'job_hunting.id',
  2989. 'job_hunting.catid',
  2990. 'job_hunting.cat_arr_id',
  2991. 'job_hunting.job_name_get',
  2992. 'job_hunting.industry',
  2993. 'job_hunting.name',
  2994. 'job_hunting.sexy',
  2995. 'job_hunting.origin',
  2996. 'job_hunting.city_arr_id',
  2997. 'job_hunting.experience',
  2998. 'job_hunting.updated_at',
  2999. 'job_hunting.salary',
  3000. 'job_hunting.skillList',
  3001. 'job_hunting.slelf_evaluation',
  3002. )
  3003. ->orderBy('updated_at', 'desc')
  3004. ->limit($data['job1_num'])
  3005. ->get();
  3006. $web['website_id'] = $data['website_id'];
  3007. if (empty($job_hunting)) {
  3008. $job_huntings = "未查询到相关简历信息";
  3009. } else {
  3010. $job_huntings = $this->processJob($job_hunting, $web);
  3011. }
  3012. // 0:待审核 1:已通过 2:已拒绝
  3013. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3014. ->where('job_recruiting.website_id', $data['website_id'])
  3015. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3016. $query->where(function ($q) use ($data) {
  3017. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3018. });
  3019. })
  3020. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3021. ->select(
  3022. 'job_recruiting.id',
  3023. 'job_recruiting.catid',
  3024. 'job_recruiting.cat_arr_id',
  3025. 'job_recruiting.title',
  3026. 'job_recruiting.jtzw_id',
  3027. 'job_recruiting.hy_id',
  3028. 'job_recruiting.city_arr_id',
  3029. 'job_recruiting.due_data',
  3030. 'job_recruiting.updated_at',
  3031. 'job_recruiting.experience',
  3032. 'job_recruiting.educational',
  3033. 'job_recruiting.salary',
  3034. 'job_recruiting.zw_id',
  3035. 'job_company.business_name',
  3036. 'job_recruiting.keyword',
  3037. 'job_recruiting.description',
  3038. )
  3039. ->orderBy('updated_at', 'desc')
  3040. ->limit($data['job2_num'])
  3041. ->get();
  3042. if (empty($job_recruiting->toArray())) {
  3043. $job_recruitings = "未查询到相关职位信息";
  3044. } else {
  3045. $job_recruitings = $this->processJob($job_recruiting, $web);
  3046. }
  3047. $result = [
  3048. 'job_hunting' => $job_huntings,
  3049. 'job_recuiting' => $job_recruitings,
  3050. ];
  3051. return Result::success($result);
  3052. }
  3053. /**
  3054. * c端-获取招工招聘列表
  3055. * @param array $data
  3056. * @return array
  3057. * */
  3058. public function getWebsiteJobList(array $data): array
  3059. {
  3060. $recruit_where = [];
  3061. $hunt_where = [];
  3062. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3063. if (empty($web)) {
  3064. return Result::error("此网站不存在", 0);
  3065. }
  3066. $website_id['website_id'] = $data['website_id'];
  3067. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3068. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3069. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3070. }
  3071. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3072. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3073. }
  3074. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3075. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3076. }
  3077. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3078. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3079. }
  3080. $query = JobRecruiting::where('job_recruiting.status', 1)
  3081. ->where('job_recruiting.website_id', $data['website_id'])
  3082. ->where($recruit_where)
  3083. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3084. $query->where(function ($q) use ($data) {
  3085. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3086. });
  3087. })
  3088. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3089. $query->where(function ($q) use ($data) {
  3090. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3091. });
  3092. })
  3093. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3094. ->select(
  3095. 'job_recruiting.id',
  3096. 'job_recruiting.catid',
  3097. 'job_recruiting.hy_id',
  3098. 'job_recruiting.title',
  3099. 'job_recruiting.zw_id',
  3100. 'job_recruiting.educational',
  3101. 'job_recruiting.jtzw_id',
  3102. 'job_recruiting.city_arr_id',
  3103. 'job_recruiting.due_data',
  3104. 'job_recruiting.experience',
  3105. 'job_recruiting.cat_arr_id',
  3106. 'job_recruiting.updated_at',
  3107. 'job_company.business_name',
  3108. 'job_recruiting.keyword',
  3109. 'job_recruiting.description',
  3110. )
  3111. ->orderBy('job_recruiting.updated_at', 'desc');
  3112. $recruit_count = $query->count();
  3113. $query = clone $query;
  3114. $JobRecruiting = $query
  3115. ->offset(($data['page'] - 1) * $data['pageSize'])
  3116. ->limit($data['pageSize'])
  3117. ->get();
  3118. if (empty($JobRecruiting)) {
  3119. $JobRecruiting = "暂无相关职位信息";
  3120. } else {
  3121. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3122. }
  3123. }
  3124. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3125. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3126. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3127. }
  3128. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3129. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3130. }
  3131. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3132. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3133. }
  3134. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3135. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3136. }
  3137. $query = JobHunting::where('job_hunting.status', 2)
  3138. ->where('job_hunting.website_id', $data['website_id'])
  3139. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3140. ->where($hunt_where)
  3141. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3142. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3143. // })
  3144. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3145. $query->where(function ($q) use ($data) {
  3146. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3147. });
  3148. })
  3149. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3150. $query->where(function ($q) use ($data) {
  3151. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3152. });
  3153. })
  3154. ->select(
  3155. 'job_hunting.id',
  3156. 'job_hunting.catid',
  3157. 'job_hunting.sexy',
  3158. 'job_hunting.experience',
  3159. 'job_hunting.origin',
  3160. 'job_hunting.industry',
  3161. 'job_hunting.name',
  3162. 'job_hunting.job',
  3163. 'job_hunting.job_name_get',
  3164. 'job_hunting.city_arr_id',
  3165. 'job_hunting.cat_arr_id',
  3166. 'job_hunting.created_at',
  3167. 'job_hunting.updated_at',
  3168. 'job_position.zwname as job_name',
  3169. 'job_hunting.skillList',
  3170. 'job_hunting.slelf_evaluation',
  3171. )
  3172. ->orderBy('job_hunting.updated_at', 'desc');
  3173. $hunt_count = $query->count();
  3174. $query = clone $query;
  3175. $JobHunting = $query
  3176. ->offset(($data['page'] - 1) * $data['pageSize'])
  3177. ->limit($data['pageSize'])
  3178. ->get();
  3179. if (empty($JobHunting)) {
  3180. $JobRecruiting = "暂无相关简历信息";
  3181. } else {
  3182. $JobHunting = $this->processJob($JobHunting, $website_id);
  3183. }
  3184. }
  3185. $result = [
  3186. 'JobRecruiting' => $JobRecruiting ?? [],
  3187. 'recruit_count' => $recruit_count ?? 0,
  3188. 'JobHunting' => $JobHunting ?? [],
  3189. 'hunt_count' => $hunt_count ?? 0,
  3190. ];
  3191. return Result::success($result);
  3192. }
  3193. /**
  3194. * c端-获取招工招聘详情
  3195. * @param array $data
  3196. * @return array
  3197. * */
  3198. public function getWebsiteJobInfo(array $data): array
  3199. {
  3200. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3201. if (empty($web)) {
  3202. return Result::error("该网站不存在", 0);
  3203. }
  3204. $webid = [
  3205. 'website_id' => $data['website_id'],
  3206. ];
  3207. // 职位相关信息
  3208. if ($data['type'] == 1) {
  3209. $query = JobRecruiting::where('status', 1)
  3210. ->where('website_id', $data['website_id'])
  3211. ->select('*');
  3212. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3213. $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();
  3214. if (!empty($company)) {
  3215. $result['company'] = $this->processJob($company, $webid);
  3216. }
  3217. $other_job = JobRecruiting::where('status', 1)
  3218. ->where('website_id', $data['website_id'])
  3219. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3220. ->where('id', '!=', $data['id'])
  3221. ->where('user_id', '=', $job[0]['user_id'])
  3222. ->limit($data['pageSize'])
  3223. ->get();
  3224. if (!empty($other_job)) {
  3225. $result['other_job'] = $this->processJob($other_job, $webid);
  3226. }
  3227. } else {
  3228. // 简历相关信息
  3229. $job = JobHunting::where('job_hunting.status', 2)
  3230. ->where('job_hunting.website_id', $data['website_id'])
  3231. ->where('job_hunting.id', $data['id'])
  3232. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3233. ->select('job_hunting.*', 'user_name')
  3234. ->get();
  3235. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3236. if (!empty($resume->toArray())) {
  3237. $result['resume'] = 1;
  3238. } else {
  3239. $result['resume'] = 0;
  3240. }
  3241. }
  3242. if (empty($job->toArray())) {
  3243. return Result::error("id参数错误", 0);
  3244. }
  3245. if (!empty($job[0]['job_experience'])) {
  3246. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3247. if (!empty($job_experience)) {
  3248. // $hy = [];
  3249. foreach ($job_experience as $key => $value) {
  3250. // $id = $value['id'];
  3251. $hy[$key] = $value['job_industry'];
  3252. $zw_id[$key] = $value['job_typename'];
  3253. $jtzw_id[$key] = $value['job_name'];
  3254. }
  3255. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3256. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3257. // 先将关联表转换为索引数组,提高查找效率
  3258. $hyLookup = [];
  3259. foreach ($hy_table as $item) {
  3260. $hyLookup[$item['hyid']] = $item['hyname'];
  3261. }
  3262. $zwLookup = [];
  3263. foreach ($zw_table as $item) {
  3264. $zwLookup[$item['zwid']] = $item['zwname'];
  3265. }
  3266. foreach ($job_experience as $key => &$value) {
  3267. // 处理行业名称
  3268. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3269. $value['hy_name'] = $hyLookup[$hy[$key]];
  3270. }
  3271. // 处理职位名称
  3272. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3273. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3274. }
  3275. // 处理具体职位名称
  3276. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3277. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3278. }
  3279. }
  3280. // 释放引用,防止意外修改后续代码
  3281. unset($value);
  3282. }
  3283. $result['job_experience'] = $job_experience ?? [];
  3284. }
  3285. if (!empty($job[0]['education_experience'])) {
  3286. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3287. if (!empty($education_experience)) {
  3288. foreach ($education_experience as $key => $value) {
  3289. // $id = $value['id'];
  3290. $education[$key] = $value['school_education'];
  3291. }
  3292. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3293. // // 先将关联表转换为索引数组,提高查找效率
  3294. $educationLookup = [];
  3295. foreach ($education_table as $item) {
  3296. $educationLookup[$item['evalue']] = $item['ename'];
  3297. }
  3298. foreach ($education_experience as $key => &$value) {
  3299. // 处理学历名称
  3300. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3301. $value['education_name'] = $educationLookup[$education[$key]];
  3302. }
  3303. }
  3304. }
  3305. $result['education_experience'] = $job_experience ?? [];
  3306. }
  3307. $result['job'] = $this->processJob($job, $webid);
  3308. // // 返现对应的栏目
  3309. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3310. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3311. ->whereIn('category_id', $catid)
  3312. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3313. ->orderBy('pid')->get()->all();
  3314. if (!empty($category)) {
  3315. $result['category'] = $category;
  3316. }
  3317. $result['job'] = $job;
  3318. $result['job_experience'] = $job_experience ?? [];
  3319. $result['education_experience'] = $education_experience ?? [];
  3320. if (empty($result)) {
  3321. return Result::error("参数错误", 0);
  3322. }
  3323. return Result::success($result);
  3324. }
  3325. /**
  3326. * c端-申请职位
  3327. * @param array $data
  3328. * @return array
  3329. * */
  3330. public function getWebsiteJobApply(array $data): array
  3331. {
  3332. // 首先验证网站是否存在
  3333. // return Result::success($data);
  3334. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3335. if (empty($web)) {
  3336. return Result::error("该网站不存在", 0);
  3337. }
  3338. // 验证用户是否存在且为个人会员/管理员
  3339. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3340. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3341. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3342. return Result::error("用户不存在", 0);
  3343. }
  3344. // 去除重复元素和空元素,并保持原始顺序
  3345. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3346. return !empty($value);
  3347. }));
  3348. // 验证职位是否存在 1:审核通过
  3349. $recruiting = JobRecruiting::where('status', 1)
  3350. ->where('website_id', $data['website_id'])
  3351. ->whereIn('id', $data['recruit_id'])
  3352. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3353. if (empty($recruiting)) {
  3354. return Result::error("该职位不存在", 0);
  3355. }
  3356. // 简历是否存在
  3357. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3358. if (empty($hunt_id)) {
  3359. return Result::error("该简历不存在", 0);
  3360. }
  3361. $data['hunt_id'] = $hunt_id['hunt_id'];
  3362. // // 验证是否已投递过该职位
  3363. $apply = JobApply::where('user_id', $data['user_id'])
  3364. ->where('hunt_id', $data['hunt_id'])
  3365. ->where('website_id', $data['website_id'])
  3366. ->whereIn('recruit_id', $data['recruit_id'])
  3367. ->get(['recruit_id']);
  3368. if (!empty($apply->toArray())) {
  3369. return Result::error("您已投递过该职位!");
  3370. }
  3371. $insertData = array_map(function ($recruiting) use ($data) {
  3372. return [
  3373. 'user_id' => $data['user_id'],
  3374. 'hunt_id' => $data['hunt_id'],
  3375. 'website_id' => $data['website_id'],
  3376. 'recruit_id' => $recruiting['recruit_id'],
  3377. 'receiver_id' => $recruiting['receiver_id'],
  3378. 'status' => 1,
  3379. ];
  3380. }, $recruiting);
  3381. // 批量插入数据
  3382. $result = JobApply::insert($insertData);
  3383. if (empty($result)) {
  3384. return Result::error("投递失败", 0);
  3385. }
  3386. return Result::success($result);
  3387. }
  3388. /**
  3389. * 招工招聘-沟通简历
  3390. * @param array $data
  3391. * @return array
  3392. * */
  3393. public function getWebsiteJobResume(array $data): array
  3394. {
  3395. // 首先验证网站是否存在
  3396. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3397. if (empty($web)) {
  3398. return Result::error("该网站不存在", 0);
  3399. }
  3400. // return Result::success($data);
  3401. // 验证用户是否存在且为企业会员/管理员
  3402. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3403. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3404. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3405. return Result::error("用户不存在", 0);
  3406. }
  3407. // 去除重复元素和空元素,并保持原始顺序
  3408. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3409. return !empty($value);
  3410. }));
  3411. // 验证简历是否存在
  3412. $hunting = JobHunting::where('status', 2)
  3413. ->where('website_id', $data['website_id'])
  3414. ->whereIn('id', $data['hunt_id'])
  3415. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3416. if (empty($hunting)) {
  3417. return Result::error("该简历不存在", 0);
  3418. }
  3419. // 验证是否已沟通过该简历
  3420. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3421. ->where('recruit_id', $data['recruit_id'])
  3422. ->where('website_id', $data['website_id'])
  3423. ->whereIn('hunt_id', $data['hunt_id'])
  3424. ->get(['hunt_id']);
  3425. if (!empty($remuse->toArray())) {
  3426. return Result::error("您已沟通过该简历!");
  3427. }
  3428. // 准备要插入的数据数组
  3429. $insertData = array_map(function ($hunting) use ($data) {
  3430. return [
  3431. 'user_id' => $data['user_id'],
  3432. 'recruit_id' => $data['recruit_id'],
  3433. 'website_id' => $data['website_id'],
  3434. 'hunt_id' => $hunting['hunt_id'],
  3435. 'receiver_id' => $hunting['receiver_id'],
  3436. 'status' => 1,
  3437. ];
  3438. }, $hunting);
  3439. // 批量插入数据
  3440. $result = JobRemuse::insert($insertData);
  3441. if (empty($result)) {
  3442. return Result::error("沟通失败", 0);
  3443. }
  3444. return Result::success($result);
  3445. }
  3446. /**
  3447. * 招工招聘 -我的职位(企业会员)
  3448. * @param array $data
  3449. * @return array
  3450. */
  3451. public function getWebsiteJobRecruiting(array $data): array
  3452. {
  3453. $web = Website::where('id', $data['website_id'])->first('id');
  3454. if (empty($web)) {
  3455. return Result::error("该网站不存在", 0);
  3456. }
  3457. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3458. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3459. return Result::error("用户暂无权限!", 0);
  3460. }
  3461. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3462. $result = JobRecruiting::where('website_id', $data['website_id'])
  3463. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3464. $query->where('user_id', $user['id']);
  3465. })
  3466. ->where('status', 1)
  3467. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3468. ->orderBy('updated_at', 'desc')
  3469. ->limit($data['pageSize'])
  3470. ->get();
  3471. if (empty($result)) {
  3472. return Result::error("暂无相关职位信息", 0);
  3473. }
  3474. return Result::success($result);
  3475. }
  3476. /**
  3477. * c端 - 验证路由
  3478. * @param array $data
  3479. * @return array
  3480. */
  3481. /**
  3482. * c端 - 验证路由
  3483. * @param array $data
  3484. * @return array
  3485. */
  3486. public function checkWebsiteRoute(array $data): array
  3487. {
  3488. // 测试001111111222
  3489. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3490. if (empty($web)) {
  3491. return Result::error("该网站不存在", 0);
  3492. } elseif ($web['status'] != 1) {
  3493. return Result::error("网站已经关闭", 0);
  3494. }
  3495. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3496. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3497. // 验证路由是否存在
  3498. if (empty($whiteRouterInfo)) {
  3499. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3500. }
  3501. if (!empty($whiteRouterInfo)) {
  3502. return Result::success($whiteRouterInfo->toArray());
  3503. }
  3504. }
  3505. // 验证栏目路由
  3506. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3507. ->where('path', $data['all_route'])
  3508. ->get()->all();
  3509. if (count($last_category) == 0) {
  3510. return Result::error("该栏目不存在", 0);
  3511. }
  3512. if (count($last_category) > 1) {
  3513. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3514. }
  3515. if (count($last_category) == 1) {
  3516. $last_category = $last_category[0];
  3517. }
  3518. // return Result::success($last_category);
  3519. if (isset($data['id']) && !empty($data['id'])) {
  3520. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3521. switch ($last_category['type']) {
  3522. case 1:
  3523. // 文章
  3524. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3525. $article = Article::where('status', 1)
  3526. ->where('id', $data['id'])
  3527. ->where(function ($query) use ($data) {
  3528. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3529. ->orWhereNull("ignore_ids");
  3530. })
  3531. ->first(['catid']);
  3532. if (empty($article)) {
  3533. return Result::error("该文章不存在", 0);
  3534. }
  3535. // return Result::success($article);
  3536. break;
  3537. case 2:
  3538. // 商品
  3539. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3540. $article = Good::where('website_id', $data['website_id'])
  3541. ->where('status', 2)
  3542. ->where('id', $data['id'])
  3543. ->first(['cat_arr_id']);
  3544. if (empty($article)) {
  3545. return Result::error("该商品不存在", 0);
  3546. }
  3547. break;
  3548. case 3:
  3549. // 书刊信息
  3550. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3551. $article = Book::where('website_id', $data['website_id'])
  3552. ->where('status', 2)
  3553. ->where('id', $data['id'])
  3554. ->first(['id', 'cat_arr_id']);
  3555. if (empty($article)) {
  3556. return Result::error("该书刊不存在", 0);
  3557. }
  3558. break;
  3559. case 4:
  3560. // 招聘
  3561. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3562. $article = JobRecruiting::where('website_id', $data['website_id'])
  3563. ->where('status', 1)
  3564. ->where('id', $data['id'])
  3565. ->first(['cat_arr_id']);
  3566. if (empty($article)) {
  3567. return Result::error("该招聘不存在", 0);
  3568. }
  3569. break;
  3570. case 5:
  3571. // 求职
  3572. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3573. $article = JobHunting::where('website_id', $data['website_id'])
  3574. ->where('status', 2)
  3575. ->where('id', $data['id'])
  3576. ->first(['cat_arr_id']);
  3577. if (empty($article)) {
  3578. return Result::error("该求职不存在", 0);
  3579. }
  3580. break;
  3581. case 6:
  3582. // 企业
  3583. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3584. $article = Company::
  3585. // where('website_id', $data['website_id'])
  3586. // ->
  3587. where('status', 1)
  3588. ->where('id', $data['id'])
  3589. ->first(['cat_arr_id']);
  3590. if (empty($article)) {
  3591. return Result::error("该企业不存在", 0);
  3592. }
  3593. break;
  3594. case 7:
  3595. // 项目
  3596. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3597. $article = Project::where('website_id', $data['website_id'])
  3598. ->where('status', 1)
  3599. ->where('id', $data['id'])
  3600. ->first(['cat_arr_id']);
  3601. if (empty($article)) {
  3602. return Result::error("该项目不存在", 0);
  3603. }
  3604. break;
  3605. default:
  3606. return Result::error("该数据不存在", 0);
  3607. break;
  3608. }
  3609. // return Result::success($article);
  3610. // $catid =0 ;
  3611. if (!isset($article['cat_arr_id'])) {
  3612. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3613. } else {
  3614. $catidArray = json_decode($article['cat_arr_id'], true);
  3615. $catid = !empty($catidArray) ? end($catidArray) : null;
  3616. }
  3617. // return Result::success($catid);
  3618. // // return Result::success($article['cat_arr_id']);
  3619. if (empty($catid)) {
  3620. return Result::error("该栏目路径不存在", 0);
  3621. }
  3622. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3623. ->where('category_id', $catid)
  3624. ->first('path');
  3625. }
  3626. // else{
  3627. // // if ($last_category['pid'] != 0) {
  3628. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3629. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3630. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3631. // ->where('category_id',$catid)
  3632. // ->where('path',$data['all_route'])
  3633. // ->first('path');
  3634. // // } else {
  3635. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3636. // // }
  3637. // }
  3638. // return Result::success($path);
  3639. if (!empty($path) && $path['path'] != $data['all_route']) {
  3640. return Result::error('非法路径!');
  3641. } else {
  3642. return Result::success($last_category['path']);
  3643. }
  3644. }
  3645. /**
  3646. * 招工招聘 - 获取推荐职位
  3647. * @param array $data
  3648. * @return array
  3649. */
  3650. public function getWebsiteLevelJob(array $data): array
  3651. {
  3652. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3653. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3654. ->where('job_recruiting.status', 1)
  3655. ->where('job_level', $data['job_level'])
  3656. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3657. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3658. ->orderBy('job_recruiting.updated_at', 'desc')
  3659. ->limit($data['pageSize'])
  3660. ->get();
  3661. $web = ['website_id' => $data['website_id']];
  3662. if (!empty($job)) {
  3663. $result = $this->processJob($job, $web);
  3664. }
  3665. if (empty($result)) {
  3666. return Result::error("暂无相关职位信息", 0);
  3667. }
  3668. return Result::success($result);
  3669. }
  3670. /**
  3671. * 验证导航名称是否重复
  3672. * @return void
  3673. */
  3674. //20250226 产品列表
  3675. public function getGoodList(array $data): array
  3676. {
  3677. var_dump($data, '---------1-2--');
  3678. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3679. unset($data['user_type_id']);
  3680. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3681. $where = [];
  3682. if ($type_id != '10000') {
  3683. $where = [
  3684. 'good.user_id' => $user_id,
  3685. ];
  3686. }
  3687. //类型
  3688. if (isset($data['type_id']) && $data['type_id']) {
  3689. $where['good.type_id'] = $data['type_id'];
  3690. }
  3691. //名称
  3692. if (isset($data['name']) && $data['name']) {
  3693. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3694. }
  3695. //status
  3696. if (isset($data['status']) && $data['status'] != '') {
  3697. $where['good.status'] = $data['status'];
  3698. }
  3699. //status1
  3700. // if (isset($data['status1']) && $data['status1'] == 1) {
  3701. // $status1 = 1;
  3702. // }
  3703. $where1 = [];
  3704. //website_id
  3705. // if (isset($data['website_id']) && $data['website_id']) {
  3706. // $where1 = [
  3707. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3708. // ];
  3709. // }
  3710. // website_name
  3711. if (isset($data['website_name']) && $data['website_name']) {
  3712. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3713. }
  3714. // catid
  3715. if (isset($data['category_name']) && $data['category_name']) {
  3716. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3717. }
  3718. // $result = Good::where($where)
  3719. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3720. var_dump($where, '---------1---');
  3721. $result = Good::where($where)
  3722. ->when(!empty($where1), function ($query) use ($where1) {
  3723. return $query->where($where1);
  3724. })
  3725. //status 1待审核2已审核3已拒绝
  3726. ->when(isset($data['status1']), function ($query) {
  3727. return $query->whereIn('good.status', [1, 3]);
  3728. })
  3729. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3730. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3731. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3732. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3733. ->orderBy("updated_at", "desc")
  3734. ->limit($data['page_size'])
  3735. ->offset(($data['page'] - 1) * $data['page_size'])
  3736. ->get();
  3737. $count = Good::where($where)
  3738. ->when(!empty($where1), function ($query) use ($where1) {
  3739. return $query->where($where1);
  3740. })
  3741. //status 1待审核2已审核3已拒绝
  3742. ->when(isset($data['status1']), function ($query) {
  3743. return $query->whereIn('good.status', [1, 3]);
  3744. })
  3745. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3746. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3747. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3748. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3749. ->orderBy("updated_at", "desc")->count();
  3750. $data = [
  3751. 'rows' => $result->toArray(),
  3752. 'count' => $count,
  3753. ];
  3754. if (empty($result)) {
  3755. return Result::error("此栏目暂无相关产品", 0);
  3756. }
  3757. return Result::success($data);
  3758. }
  3759. public function getGoodInfo(array $data): array
  3760. {
  3761. $result = Good::where('id', $data['id'])->first();
  3762. if (empty($result)) {
  3763. return Result::error("此产品不存在", 0);
  3764. }
  3765. return Result::success($result);
  3766. }
  3767. public function addGood(array $data): array
  3768. {
  3769. // unset($data['city_arr_id']);
  3770. // unset($data['cat_arr_id']);
  3771. $data['city_id'] = end($data['city_arr_id']);
  3772. $data['catid'] = end($data['cat_arr_id']);
  3773. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3774. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3775. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3776. unset($data['imgUrl']); //大小写
  3777. if (isset($data['price']) && $data['price'] == '') {
  3778. $data['price'] = 0;
  3779. }
  3780. if ($data['imgurl'] == '') {
  3781. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3782. preg_match_all($reg, $data['detail'], $matches);
  3783. if (isset($matches[1][0])) {
  3784. //截取varchar240
  3785. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3786. }
  3787. }
  3788. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3789. //提取标题+内容中的关键词
  3790. $data['keyword'] = $data['name'];
  3791. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3792. Jieba::init(); // 初始化 jieba-php
  3793. Finalseg::init();
  3794. $segList = Jieba::cut($data['keyword']);
  3795. $segList1 = array_slice($segList, 0, 8);
  3796. $data['keyword'] = implode(',', $segList1);
  3797. }
  3798. if ($data['description'] == '') {
  3799. //提取内容中的描述
  3800. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3801. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3802. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3803. }
  3804. if ($data['status'] == 1) {
  3805. $this->sendMessage([
  3806. 'talk_type' => 200,
  3807. 'title' => $data['name'],
  3808. 'content' => '提交了审核',
  3809. 'messageType' => 3,
  3810. ]);
  3811. }
  3812. $result = Good::insert($data);
  3813. if (empty($result)) {
  3814. return Result::error("添加失败", 0);
  3815. }
  3816. return Result::success($result);
  3817. }
  3818. public function updateGood(array $data): array
  3819. {
  3820. $data['city_id'] = end($data['city_arr_id']);
  3821. $data['catid'] = end($data['cat_arr_id']);
  3822. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3823. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3824. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3825. //设置东八区
  3826. date_default_timezone_set('Asia/Shanghai');
  3827. $data['updated_at'] = date('Y-m-d H:i:s');
  3828. if (isset($data['price']) && $data['price'] == '') {
  3829. $data['price'] = 0;
  3830. }
  3831. if ($data['imgurl'] == '') {
  3832. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3833. preg_match_all($reg, $data['detail'], $matches);
  3834. if (isset($matches[1][0])) {
  3835. //截取varchar240
  3836. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3837. }
  3838. }
  3839. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3840. //提取标题+内容中的关键词
  3841. $data['keyword'] = $data['name'];
  3842. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3843. Jieba::init(); // 初始化 jieba-php
  3844. Finalseg::init();
  3845. $segList = Jieba::cut($data['keyword']);
  3846. $segList1 = array_slice($segList, 0, 8);
  3847. $data['keyword'] = implode(',', $segList1);
  3848. }
  3849. if ($data['description'] == '') {
  3850. //提取内容中的描述
  3851. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3852. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3853. }
  3854. if ($data['status'] == 1) {
  3855. $this->sendMessage([
  3856. 'talk_type' => 200,
  3857. 'title' => $data['name'],
  3858. 'content' => '提交了审核',
  3859. 'messageType' => 3,
  3860. ]);
  3861. }
  3862. $result = Good::where('id', $data['id'])->update($data);
  3863. if (empty($result)) {
  3864. return Result::error("更新失败", 0);
  3865. }
  3866. return Result::success($result);
  3867. }
  3868. public function delGood(array $data): array
  3869. {
  3870. $result = Good::where('id', $data['id'])->delete();
  3871. if (empty($result)) {
  3872. return Result::error("删除失败", 0);
  3873. }
  3874. return Result::success($result);
  3875. }
  3876. //20250226 产品列表
  3877. //20250306 求职信息
  3878. public function getJobHuntingList(array $data): array
  3879. {
  3880. $where = [];
  3881. if (isset($data['username']) && !empty($data['username'])) {
  3882. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3883. }
  3884. //status 1待审核2已审核3已拒绝
  3885. if (isset($data['status']) && $data['status'] != '') {
  3886. $where = [
  3887. 'job_hunting.status' => $data['status'],
  3888. ];
  3889. }
  3890. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3891. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3892. unset($data['type_id']);
  3893. if ($type_id != '10000') {
  3894. $where[] = ['job_hunting.user_id', '=', $user_id];
  3895. }
  3896. $result = JobHunting::where($where)
  3897. ->when(!empty($data['status1']), function ($query) use ($data) {
  3898. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3899. })
  3900. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3901. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3902. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3903. ->orderBy("updated_at", "desc")
  3904. ->limit($data['page_size'])
  3905. ->offset(($data['page'] - 1) * $data['page_size'])
  3906. ->get();
  3907. if (empty($result)) {
  3908. return Result::error("查询失败", 0);
  3909. }
  3910. $count = JobHunting::where($where)
  3911. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3912. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3913. ->count();
  3914. $data = [
  3915. 'rows' => $result->toArray(),
  3916. 'count' => $count,
  3917. ];
  3918. return Result::success($data);
  3919. }
  3920. public function getJobHuntingApply(array $data): array
  3921. {
  3922. var_dump($data, '-----------------test--------1-');
  3923. $where = [];
  3924. if (isset($data['username']) && !empty($data['username'])) {
  3925. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3926. }
  3927. if (isset($data['salary']) && !empty($data['salary'])) {
  3928. $where[] = [
  3929. 'job_hunting.salary',
  3930. '=',
  3931. $data['salary'],
  3932. ];
  3933. }
  3934. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3935. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3936. unset($data['type_id']);
  3937. if ($type_id != '10000') {
  3938. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3939. }
  3940. var_dump($where, '-----------------test---------');
  3941. $result = jobApply::where($where)
  3942. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3943. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3944. // })
  3945. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3946. ->where('job_enum.egroup', '=', 'income')
  3947. ->where('job_hunting.status', 2) //已审核
  3948. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3949. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3950. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3951. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3952. //职位----是申请职位
  3953. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3954. ->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')
  3955. ->orderBy("job_hunting.updated_at", "desc")
  3956. ->limit($data['page_size'])
  3957. ->offset(($data['page'] - 1) * $data['page_size'])
  3958. ->get();
  3959. if (empty($result)) {
  3960. return Result::error("查询失败", 0);
  3961. }
  3962. $count = jobApply::where($where)
  3963. ->where('job_enum.egroup', '=', 'income')
  3964. ->where('job_hunting.status', 2) //已审核
  3965. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3966. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3967. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3968. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3969. //职位----是申请职位
  3970. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3971. ->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')
  3972. ->count();
  3973. $data = [
  3974. 'rows' => $result->toArray(),
  3975. 'count' => $count,
  3976. ];
  3977. return Result::success($data);
  3978. }
  3979. public function addJobHunting(array $data): array
  3980. {
  3981. date_default_timezone_set('Asia/Shanghai');
  3982. unset($data['company_name']);
  3983. unset($data['job_industry']);
  3984. unset($data['job_name']);
  3985. unset($data['department']);
  3986. unset($data['job_timeList']);
  3987. unset($data['job_content']);
  3988. unset($data['job_typename']); //不知道这是啥,
  3989. $data['created_at'] = date('Y-m-d H:i:s');
  3990. $data['updated_at'] = date('Y-m-d H:i:s');
  3991. //根据用户 user_id 只能添加一次
  3992. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3993. if (!empty($result)) {
  3994. return Result::error("您已添加过求职信息", 0);
  3995. }
  3996. var_dump($result, '-----------------test---------');
  3997. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  3998. if (is_string($data['city_arr_id'])) {
  3999. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4000. $cityArr = json_decode($data['city_arr_id'], true);
  4001. // 确保 $cityArr 是数组
  4002. if (is_array($cityArr)) {
  4003. $data['city_id'] = end($cityArr);
  4004. }
  4005. } else {
  4006. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4007. if (is_array($data['city_arr_id'])) {
  4008. $data['city_id'] = end($data['city_arr_id']);
  4009. }
  4010. }
  4011. }
  4012. // 处理求职所绑定栏目
  4013. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4014. if (is_string($data['cat_arr_id'])) {
  4015. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4016. // 先清理可能存在的无效 JSON 字符
  4017. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4018. $catArr = json_decode($cleanedCatArrStr, true);
  4019. // 检查 JSON 解码是否成功且结果是数组
  4020. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4021. $data['catid'] = end($catArr);
  4022. }
  4023. } else {
  4024. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4025. if (is_array($data['cat_arr_id'])) {
  4026. $data['catid'] = end($data['cat_arr_id']);
  4027. }
  4028. }
  4029. }
  4030. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4031. $this->sendMessage([
  4032. 'talk_type' => 600,
  4033. 'title' => $data['name'],
  4034. 'content' => '提交了审核',
  4035. 'messageType' => 11,
  4036. ]);
  4037. }
  4038. $result = JobHunting::create($data);
  4039. if (empty($result)) {
  4040. return Result::error("添加失败", 0);
  4041. }
  4042. return Result::success($result);
  4043. }
  4044. public function delJobHunting(array $data): array
  4045. {
  4046. $result = JobHunting::where('id', $data['id'])->delete();
  4047. if (empty($result)) {
  4048. return Result::error("删除失败", 0);
  4049. }
  4050. return Result::success($result);
  4051. }
  4052. public function updateJobHunting(array $data): array
  4053. {
  4054. //设置东八区
  4055. date_default_timezone_set('Asia/Shanghai');
  4056. unset($data['company_name']);
  4057. unset($data['job_industry']);
  4058. unset($data['job_name']);
  4059. unset($data['department']);
  4060. unset($data['job_timeList']);
  4061. unset($data['job_content']);
  4062. unset($data['job_typename']); //不知道这是啥,
  4063. $data['created_at'] = date('Y-m-d H:i:s');
  4064. $data['updated_at'] = date('Y-m-d H:i:s');
  4065. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4066. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4067. $cityArr = json_decode($data['city_arr_id'], true);
  4068. $data['city_id'] = end($cityArr);
  4069. } else {
  4070. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4071. $data['city_id'] = end($data['city_arr_id']);
  4072. }
  4073. // 处理求职所绑定栏目
  4074. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4075. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4076. $catArr = json_decode($data['cat_arr_id'], true);
  4077. $data['catid'] = end($catArr);
  4078. } else {
  4079. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4080. $data['catid'] = end($data['cat_arr_id']);
  4081. }
  4082. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4083. $this->sendMessage([
  4084. 'talk_type' => 600,
  4085. 'title' => $data['name'],
  4086. 'content' => '提交了审核',
  4087. 'messageType' => 11,
  4088. ]);
  4089. }
  4090. $result = JobHunting::where('id', $data['id'])->update($data);
  4091. if (empty($result)) {
  4092. return Result::error("更新失败", 0);
  4093. }
  4094. return Result::success($result);
  4095. }
  4096. public function getJobHuntingInfo(array $data): array
  4097. {
  4098. $result = JobHunting::where('id', $data['id'])->first();
  4099. if (empty($result)) {
  4100. return Result::error("查询失败", 0);
  4101. }
  4102. return Result::success($result);
  4103. }
  4104. public function getJobHuntingData(array $data): array
  4105. {
  4106. $jobEnum = JobEnum::get();
  4107. $jobIndustry = JobIndustry::get();
  4108. $jobNature = JobNature::get();
  4109. $jobPosition = JobPosition::get();
  4110. $data = [
  4111. 'jobEnum' => $jobEnum,
  4112. 'jobIndustry' => $jobIndustry,
  4113. 'jobNature' => $jobNature,
  4114. 'jobPosition' => $jobPosition,
  4115. ];
  4116. return Result::success($data);
  4117. }
  4118. public function delJobHuntingInfo(array $data): array
  4119. {
  4120. $result = JobHunting::where('id', $data['id'])->delete();
  4121. return Result::success();
  4122. }
  4123. //20250324 通知,公告,消息
  4124. public function delNotice(array $data): array
  4125. {
  4126. $result = Notice::where('id', $data['id'])->delete();
  4127. if ($result) {
  4128. return Result::success();
  4129. } else {
  4130. return Result::error("删除失败", 0);
  4131. }
  4132. }
  4133. public function getNoticeInfo(array $data): array
  4134. {
  4135. $result = Notice::where('id', $data['id'])->first();
  4136. // var_dump($result['re_user_ids'], '--------------------');
  4137. if (empty($result)) {
  4138. return Result::error("查询失败", 0);
  4139. }
  4140. return Result::success($result);
  4141. }
  4142. public function readNotice(array $data): array
  4143. {
  4144. $result = Notice::where('id', $data['id'])->first();
  4145. // var_dump($result['re_user_ids'], '--------------------');
  4146. if (empty($result)) {
  4147. return Result::error("查询失败", 0);
  4148. }
  4149. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4150. $re_user_ids = json_decode($result['re_user_ids'], true);
  4151. var_dump($re_user_ids, '--------------1---test---------');
  4152. var_dump($data, '--------------1---test---------');
  4153. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4154. //如果已经存在,就不再添加
  4155. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4156. $read_id = json_decode($result['read_id'], true);
  4157. if (!is_array($read_id)) {
  4158. $read_id = [];
  4159. }
  4160. if (!in_array($data['user_id'], $read_id)) {
  4161. $read_id[] = $data['user_id'];
  4162. $result['read_id'] = json_encode($read_id);
  4163. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4164. }
  4165. } else {
  4166. //如果不存在,就添加
  4167. $result['read_id'] = json_encode([$data['user_id']]);
  4168. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4169. }
  4170. }
  4171. return Result::success($result);
  4172. }
  4173. public function addNotice(array $data): array
  4174. {
  4175. date_default_timezone_set('Asia/Shanghai');
  4176. $data['created_at'] = date('Y-m-d H:i:s');
  4177. $data['updated_at'] = date('Y-m-d H:i:s');
  4178. $user_id = UserInfo::
  4179. //city_id不是null
  4180. whereNotNull('city_id')
  4181. ->whereNotNull('department_id')
  4182. ->where(function ($query) use ($data) {
  4183. $query->where(function ($subQuery) use ($data) {
  4184. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4185. });
  4186. })
  4187. ->where(function ($query) use ($data) {
  4188. $query->where(function ($subQuery) use ($data) {
  4189. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4190. });
  4191. })
  4192. ->pluck('user_id')->toArray();
  4193. $user_id = array_unique($user_id);
  4194. $chat_ids = $user_id;
  4195. $user_id = json_encode($user_id);
  4196. $data['re_user_ids'] = $user_id;
  4197. $this->sendMessage([
  4198. 'talk_type' => 700,
  4199. 'title' => $data['title'],
  4200. 'content' => '提交了审核',
  4201. 'messageType' => 5,
  4202. ]);
  4203. $result = Notice::insertGetId($data);
  4204. if (empty($result)) {
  4205. return Result::error("添加失败", 0);
  4206. }
  4207. return Result::success($result);
  4208. }
  4209. public function updateNotice(array $data): array
  4210. {
  4211. date_default_timezone_set('Asia/Shanghai');
  4212. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4213. $user_id = UserInfo::
  4214. //city_id不是null
  4215. whereNotNull('city_id')
  4216. ->whereNotNull('department_id')
  4217. ->where(function ($query) use ($data) {
  4218. $query->where(function ($subQuery) use ($data) {
  4219. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4220. });
  4221. })
  4222. ->where(function ($query) use ($data) {
  4223. $query->where(function ($subQuery) use ($data) {
  4224. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4225. });
  4226. })
  4227. ->pluck('user_id')->toArray();
  4228. $user_id = array_unique($user_id);
  4229. $user_id = json_encode($user_id);
  4230. $data['re_user_ids'] = $user_id;
  4231. $data['updated_at'] = date('Y-m-d H:i:s');
  4232. $this->sendMessage([
  4233. 'talk_type' => 700,
  4234. 'title' => $data['title'],
  4235. 'content' => '提交了审核',
  4236. 'messageType' => 5,
  4237. ]);
  4238. $result = Notice::where('id', $data['id'])->update($data);
  4239. return Result::success($result);
  4240. }
  4241. public function getNoticeList(array $data): array
  4242. {
  4243. $where = [];
  4244. //title
  4245. if (isset($data['title']) && !empty($data['title'])) {
  4246. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4247. }
  4248. //level
  4249. if (isset($data['level']) && !empty($data['level'])) {
  4250. $where[] = ['notice.level', '=', $data['level']];
  4251. }
  4252. //status
  4253. if (isset($data['status']) && !empty($data['status'])) {
  4254. $where[] = ['notice.status', '=', $data['status']];
  4255. }
  4256. //type
  4257. if (isset($data['type']) && !empty($data['type'])) {
  4258. $where[] = ['notice.type', '=', $data['type']];
  4259. }
  4260. var_dump($data, '------------11111-2----test---------');
  4261. if ($data['type_id'] == 10000) {
  4262. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4263. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4264. })
  4265. ->where($where)
  4266. ->orderBy('updated_at', 'desc')
  4267. ->limit($data['page_size'])
  4268. ->offset(($data['page'] - 1) * $data['page_size'])
  4269. ->get();
  4270. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4271. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4272. })
  4273. ->where($where)
  4274. ->orderBy('updated_at', 'desc')
  4275. ->count();
  4276. } else {
  4277. $result = Notice::where($where)
  4278. // ->where('user_id', $data['user_id'])
  4279. ->Where(function ($query) use ($data) {
  4280. $query->Where(function ($q) use ($data) {
  4281. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4282. ->orWhere('notice.user_id', $data['user_id']);
  4283. });
  4284. })
  4285. ->when(!empty($data['status1']), function ($query) use ($data) {
  4286. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4287. })
  4288. ->orderBy('updated_at', 'desc')
  4289. ->limit($data['page_size'])
  4290. ->offset(($data['page'] - 1) * $data['page_size'])
  4291. ->get();
  4292. $total = Notice::where($where)
  4293. ->when(!empty($data['status1']), function ($query) use ($data) {
  4294. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4295. })
  4296. // ->where('user_id', $data['user_id'])
  4297. ->Where(function ($query) use ($data) {
  4298. $query->Where(function ($q) use ($data) {
  4299. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4300. ->orWhere('notice.user_id', $data['user_id']);
  4301. });
  4302. })
  4303. ->count();
  4304. }
  4305. if (empty($result)) {
  4306. return Result::error("查询失败", 0);
  4307. }
  4308. $data = [
  4309. 'rows' => $result,
  4310. 'count' => $total,
  4311. ];
  4312. return Result::success($data);
  4313. }
  4314. public function noticeList(array $data): array
  4315. {
  4316. $where = [];
  4317. //title
  4318. if (isset($data['title']) && !empty($data['title'])) {
  4319. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4320. }
  4321. //level
  4322. if (isset($data['level']) && !empty($data['level'])) {
  4323. $where[] = ['notice.level', '=', $data['level']];
  4324. }
  4325. //status
  4326. if (isset($data['status']) && !empty($data['status'])) {
  4327. $where[] = ['notice.status', '=', $data['status']];
  4328. }
  4329. //type
  4330. if (isset($data['type']) && !empty($data['type'])) {
  4331. $where[] = ['notice.type', '=', $data['type']];
  4332. }
  4333. var_dump($data, '------------11111-2----test---------');
  4334. if ($data['type_id'] == 10000) {
  4335. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4336. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4337. })
  4338. ->where($where)
  4339. ->orderBy('updated_at', 'desc')
  4340. ->limit($data['page_size'])
  4341. ->offset(($data['page'] - 1) * $data['page_size'])
  4342. ->get();
  4343. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4344. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4345. })
  4346. ->where($where)
  4347. ->orderBy('updated_at', 'desc')
  4348. ->count();
  4349. } else {
  4350. $result = Notice::where($where)
  4351. // ->where('user_id', $data['user_id'])
  4352. ->Where(function ($query) use ($data) {
  4353. $query->Where(function ($q) use ($data) {
  4354. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4355. ->orWhere('notice.user_id', $data['user_id']);
  4356. });
  4357. })
  4358. ->when(!empty($data['status1']), function ($query) use ($data) {
  4359. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4360. })
  4361. ->orderBy('updated_at', 'desc')
  4362. ->limit($data['page_size'])
  4363. ->offset(($data['page'] - 1) * $data['page_size'])
  4364. ->get();
  4365. $total = Notice::where($where)
  4366. ->when(!empty($data['status1']), function ($query) use ($data) {
  4367. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4368. })
  4369. // ->where('user_id', $data['user_id'])
  4370. ->Where(function ($query) use ($data) {
  4371. $query->Where(function ($q) use ($data) {
  4372. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4373. ->orWhere('notice.user_id', $data['user_id']);
  4374. });
  4375. })
  4376. ->count();
  4377. }
  4378. if (empty($result)) {
  4379. return Result::error("查询失败", 0);
  4380. }
  4381. $data = [
  4382. 'rows' => $result,
  4383. 'count' => $total,
  4384. ];
  4385. return Result::success($data);
  4386. }
  4387. public function getNoticeDetail(array $data): array
  4388. {
  4389. $result = Notice::where('id', $data['id'])->first();
  4390. if (empty($result)) {
  4391. return Result::error("查询失败", 0);
  4392. }
  4393. return Result::success($result);
  4394. }
  4395. public function deleteNotice(array $data): array
  4396. {
  4397. $notice = Notice::where('id', $data['id'])->first();
  4398. if (empty($notice)) {
  4399. return Result::error("删除失败", 0);
  4400. }
  4401. $chat_group_id = $notice->group_id;
  4402. if ($chat_group_id) {
  4403. //删除群聊
  4404. ChatGroups::where('id', $chat_group_id)->delete();
  4405. //删除群成员
  4406. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4407. //删除群聊记录
  4408. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4409. }
  4410. $result = Notice::where('id', $data['id'])->delete();
  4411. return Result::success($result);
  4412. }
  4413. public function complaintList(array $data): array
  4414. {
  4415. var_dump($data, '---------1---------');
  4416. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4417. unset($data['type_id']);
  4418. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4419. $where = [];
  4420. if ($type_id != 10000 && empty($data['deal_user'])) {
  4421. // $where['complaint.user_id'] = $user_id;
  4422. }
  4423. if (!empty($data['title'])) {
  4424. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4425. }
  4426. if (!empty($data['department_id'])) {
  4427. $where['complaint.department_id'] = $data['department_id'];
  4428. }
  4429. if (!empty($data['deal'])) {
  4430. $where['complaint.deal'] = $data['deal'];
  4431. }
  4432. if (!empty($data['status'])) {
  4433. $where['complaint.status'] = $data['status'];
  4434. }
  4435. var_dump(!empty($data['deal_user']), '----------1');
  4436. var_dump($where, '----------2');
  4437. $result = Complaint::where($where)
  4438. ->when(!empty($data['status1']), function ($query) use ($data) {
  4439. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4440. })
  4441. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4442. //json re_user_ids data[user_id]是不是在里面
  4443. $query->Where(function ($q) use ($data) {
  4444. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4445. ->where('complaint.status', 2);
  4446. });
  4447. })
  4448. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4449. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4450. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4451. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4452. ->orderBy('updated_at', 'desc')
  4453. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4454. //sql输出
  4455. if (empty($result)) {
  4456. return Result::error("暂无投诉信息", 0);
  4457. }
  4458. // 取出数据
  4459. $rows = $result->items();
  4460. $count = $result->total();
  4461. $responseData = [
  4462. 'rows' => $rows,
  4463. 'count' => $count,
  4464. ];
  4465. return Result::success($responseData);
  4466. }
  4467. public function getComplaintList(array $data): array
  4468. {
  4469. var_dump($data, '00000001000000000000');
  4470. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4471. unset($data['type_id']);
  4472. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4473. $where = [];
  4474. if ($type_id != 10000 && empty($data['deal_user'])) {
  4475. $where['complaint.user_id'] = $user_id;
  4476. }
  4477. if (!empty($data['title'])) {
  4478. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4479. }
  4480. if (!empty($data['department_id'])) {
  4481. $where['complaint.department_id'] = $data['department_id'];
  4482. }
  4483. if (!empty($data['deal'])) {
  4484. $where['complaint.deal'] = $data['deal'];
  4485. }
  4486. if (!empty($data['status'])) {
  4487. $where['complaint.status'] = $data['status'];
  4488. }
  4489. var_dump(!empty($data['deal_user']), '----------1');
  4490. var_dump($where, '----------2');
  4491. $result = Complaint::where($where)
  4492. ->when(!empty($data['status1']), function ($query) use ($data) {
  4493. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4494. })
  4495. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4496. // //json re_user_ids data[user_id]是不是在里面
  4497. // $query->Where(function ($q) use ($data) {
  4498. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4499. // ->where('complaint.status', 2);
  4500. // });
  4501. // })
  4502. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4503. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4504. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4505. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4506. ->orderBy('updated_at', 'desc')
  4507. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4508. //sql输出
  4509. if (empty($result)) {
  4510. return Result::error("暂无投诉信息", 0);
  4511. }
  4512. // 取出数据
  4513. $rows = $result->items();
  4514. $count = $result->total();
  4515. $responseData = [
  4516. 'rows' => $rows,
  4517. 'count' => $count,
  4518. ];
  4519. return Result::success($responseData);
  4520. }
  4521. public function getComplaintInfo(array $data): array
  4522. {
  4523. $result = Complaint::where('id', $data['id'])->first();
  4524. if (empty($result)) {
  4525. return Result::error("查询失败", 0);
  4526. }
  4527. return Result::success($result);
  4528. }
  4529. public function readComplaint(array $data): array
  4530. {
  4531. $result = Complaint::where('id', $data['id'])->first();
  4532. if (empty($result)) {
  4533. return Result::error("查询失败", 0);
  4534. }
  4535. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4536. $re_user_ids = json_decode($result['re_user_ids'], true);
  4537. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4538. //如果已经存在,就不再添加
  4539. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4540. $read_id = json_decode($result['read_id'], true);
  4541. if (!is_array($read_id)) {
  4542. $read_id = [];
  4543. }
  4544. if (!in_array($data['user_id'], $read_id)) {
  4545. $read_id[] = $data['user_id'];
  4546. $result['read_id'] = json_encode($read_id);
  4547. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4548. }
  4549. } else {
  4550. //如果不存在,就添加
  4551. $result['read_id'] = json_encode([$data['user_id']]);
  4552. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4553. }
  4554. }
  4555. return Result::success($result);
  4556. }
  4557. public function addComplaint(array $data): array
  4558. {
  4559. date_default_timezone_set('Asia/Shanghai');
  4560. $data['created_at'] = date('Y-m-d H:i:s');
  4561. $data['updated_at'] = date('Y-m-d H:i:s');
  4562. $this->sendMessage([
  4563. 'talk_type' => 800,
  4564. 'title' => $data['title'],
  4565. 'content' => '提交了审核',
  4566. 'messageType' => 6,
  4567. ]);
  4568. $result = Complaint::create($data);
  4569. return Result::success($result);
  4570. }
  4571. public function updateComplaint(array $data): array
  4572. {
  4573. date_default_timezone_set('Asia/Shanghai');
  4574. $data['updated_at'] = date('Y-m-d H:i:s');
  4575. $user_id = $data['user_id'] ?? 0;
  4576. $type_id = $data['type_id'] ?? 0;
  4577. unset($data['user_id']);
  4578. unset($data['type_id']);
  4579. $this->sendMessage([
  4580. 'talk_type' => 800,
  4581. 'title' => $data['title'],
  4582. 'content' => '提交了审核',
  4583. 'messageType' => 6,
  4584. ]);
  4585. $result = Complaint::where('id', $data['id'])->update($data);
  4586. return Result::success($result);
  4587. }
  4588. public function deleteComplaint(array $data): array
  4589. {
  4590. $result = Complaint::where('id', $data['id'])->delete();
  4591. return Result::success($result);
  4592. }
  4593. public function getComplainInfo(array $data): array
  4594. {
  4595. $result = Complaint::where('id', $data['id'])->first();
  4596. if (empty($result)) {
  4597. return Result::error("查询失败", 0);
  4598. }
  4599. return Result::success($result);
  4600. }
  4601. public function updateComplaintStatus(array $data): array
  4602. {
  4603. date_default_timezone_set('Asia/Shanghai');
  4604. $data['updated_at'] = date('Y-m-d H:i:s');
  4605. $user_id = $data['user_id'] ?? 0;
  4606. $type_id = $data['type_id'] ?? 0;
  4607. unset($data['user_id']);
  4608. unset($data['type_id']);
  4609. //处理, 写入处理人
  4610. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4611. $data['real_deal_user'] = $user_id;
  4612. }
  4613. //如果是deal 23,则判断是不是处理人
  4614. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4615. $complaintInof = Complaint::where('id', $data['id'])
  4616. ->where('real_deal_user', $user_id)
  4617. ->first();
  4618. if (empty($complaintInof)) {
  4619. return Result::error("处理人错误", 0);
  4620. }
  4621. }
  4622. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4623. if ($data['status'] == 1) {
  4624. $this->sendMessage([
  4625. 'talk_type' => 800,
  4626. 'title' => $complaintInfo['title'],
  4627. 'content' => '提交了审核',
  4628. 'messageType' => 6,
  4629. ]);
  4630. }
  4631. if ($data['status'] == 2 && !isset($data['deal'])) {
  4632. $this->sendMessage([
  4633. 'talk_type' => 801,
  4634. 'title' => $complaintInfo['title'],
  4635. 'content' => '审核通过',
  4636. 'messageType' => 6,
  4637. 'user_id' => $complaintInfo['user_id'],
  4638. ]);
  4639. $this->sendMessage([
  4640. 'talk_type' => 802,
  4641. 'title' => $complaintInfo['title'],
  4642. 'content' => '待处理',
  4643. 'messageType' => 6,
  4644. 'user_id' => $complaintInfo['re_user_ids'],
  4645. ]);
  4646. }
  4647. if ($data['status'] == 3 && !isset($data['deal'])) {
  4648. $this->sendMessage([
  4649. 'talk_type' => 801,
  4650. 'title' => $complaintInfo['title'],
  4651. 'content' => '审核拒绝',
  4652. 'messageType' => 6,
  4653. 'user_id' => $complaintInfo['user_id'],
  4654. ]);
  4655. }
  4656. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4657. $this->sendMessage([
  4658. 'talk_type' => 802,
  4659. 'title' => $complaintInfo['title'],
  4660. 'content' => '处理中',
  4661. 'messageType' => 6,
  4662. 'user_id' => $complaintInfo['re_user_ids'],
  4663. ]);
  4664. }
  4665. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4666. $this->sendMessage([
  4667. 'talk_type' => 802,
  4668. 'title' => $complaintInfo['title'],
  4669. 'content' => '不予处理',
  4670. 'messageType' => 6,
  4671. 'user_id' => $complaintInfo['re_user_ids'],
  4672. ]);
  4673. }
  4674. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4675. $this->sendMessage([
  4676. 'talk_type' => 802,
  4677. 'title' => $complaintInfo['title'],
  4678. 'content' => '已完结',
  4679. 'messageType' => 6,
  4680. 'user_id' => $complaintInfo['re_user_ids'],
  4681. ]);
  4682. }
  4683. $result = complaint::where('id', $data['id'])->update($data);
  4684. return Result::success($result);
  4685. }
  4686. public function updateGoodStatus(array $data): array
  4687. {
  4688. $user_id = $data['user_id'] ?? 0;
  4689. $type_id = $data['type_id'] ?? 0;
  4690. unset($data['user_id']);
  4691. unset($data['type_id']);
  4692. $goodInfo = Good::where('id', $data['id'])->first();
  4693. if ($data['status'] == 2) {
  4694. $this->sendMessage([
  4695. 'talk_type' => 201,
  4696. 'title' => $goodInfo['name'],
  4697. 'content' => '审核通过',
  4698. 'messageType' => 3,
  4699. 'user_id' => $goodInfo['user_id'],
  4700. ]);
  4701. }
  4702. if ($data['status'] == 3) {
  4703. $this->sendMessage([
  4704. 'talk_type' => 201,
  4705. 'title' => $goodInfo['name'],
  4706. 'content' => '审核拒绝',
  4707. 'messageType' => 3,
  4708. 'user_id' => $goodInfo['user_id'],
  4709. ]);
  4710. }
  4711. if ($data['status'] == 1) {
  4712. $this->sendMessage([
  4713. 'talk_type' => 200,
  4714. 'title' => $goodInfo['name'],
  4715. 'content' => '提交了审核',
  4716. 'messageType' => 3,
  4717. ]);
  4718. }
  4719. $result = Good::where('id', $data['id'])->update($data);
  4720. return Result::success($result);
  4721. }
  4722. public function updateJobHuntingStatus(array $data): array
  4723. {
  4724. $user_id = $data['user_id'] ?? 0;
  4725. $type_id = $data['type_id'] ?? 0;
  4726. unset($data['user_id']);
  4727. unset($data['type_id']);
  4728. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4729. if ($data['status'] == 2) {
  4730. $this->sendMessage([
  4731. 'talk_type' => 601,
  4732. 'title' => $jogHuntingInfo['name'],
  4733. 'content' => '审核通过',
  4734. 'messageType' => 11,
  4735. 'user_id' => $jogHuntingInfo['user_id'],
  4736. ]);
  4737. }
  4738. if ($data['status'] == 3) {
  4739. $this->sendMessage([
  4740. 'talk_type' => 601,
  4741. 'title' => $jogHuntingInfo['name'],
  4742. 'content' => '审核拒绝',
  4743. 'messageType' => 11,
  4744. 'user_id' => $jogHuntingInfo['user_id'],
  4745. ]);
  4746. }
  4747. if ($data['status'] == 1) {
  4748. $this->sendMessage([
  4749. 'talk_type' => 600,
  4750. 'title' => $jogHuntingInfo['name'],
  4751. 'content' => '提交了审核',
  4752. 'messageType' => 11,
  4753. ]);
  4754. }
  4755. $result = JobHunting::where('id', $data['id'])->update($data);
  4756. return Result::success($result);
  4757. }
  4758. public function updateNoticeStatus(array $data): array
  4759. {
  4760. $user_id = $data['user_id'] ?? 0;
  4761. $type_id = $data['type_id'] ?? 0;
  4762. unset($data['user_id']);
  4763. unset($data['type_id']);
  4764. //查询公告
  4765. $notice = Notice::where('id', $data['id'])->first();
  4766. if (empty($notice)) {
  4767. return Result::error("公告不存在", 0);
  4768. }
  4769. //$chat_ids 去除掉$data['user_id']
  4770. $chat_ids = json_decode($notice['re_user_ids'], true);
  4771. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4772. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4773. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  4774. //chat_group
  4775. $group_id = PublicData::uuid();
  4776. $groupData = [
  4777. 'id' => $group_id,
  4778. 'creator_id' => $notice['user_id'],
  4779. 'group_name' => $notice['group_name'] ?? '',
  4780. 'profile' => $notice['profile'] ?? 0,
  4781. ];
  4782. var_dump($groupData, '-----------------groupData-------');
  4783. $groupResult = ChatGroups::insertGetId($groupData);
  4784. var_dump($groupResult, '-----------------groupid-------');
  4785. $groupMemberData = [
  4786. 'id' => PublicData::uuid(),
  4787. 'user_id' => $notice['user_id'],
  4788. 'group_id' => $group_id,
  4789. 'leader' => 2,
  4790. ];
  4791. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4792. //插入群成员表
  4793. $groupMemberDataUser = [];
  4794. $chatData = [];
  4795. foreach ($chat_ids as $key => $value) {
  4796. $groupMemberDataUser[] = [
  4797. 'id' => PublicData::uuid(),
  4798. 'user_id' => $value,
  4799. 'group_id' => $group_id,
  4800. 'leader' => 1,
  4801. ];
  4802. $chatData[] = [
  4803. 'user_id' => $value,
  4804. 'msg_type' => 1,
  4805. 'receiver_id' => $group_id,
  4806. 'content' => '通过通知创建群聊',
  4807. 'group_receiver_id' => $notice['user_id'],
  4808. 'action' => 'recieved',
  4809. 'created_at' => date('Y-m-d H:i:s'),
  4810. ];
  4811. }
  4812. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4813. ChatGroupsMember::insert($groupMemberDataUser);
  4814. //插入一条管理员聊天记录
  4815. $chatData[] = [
  4816. 'user_id' => $notice['user_id'],
  4817. 'msg_type' => 1,
  4818. 'receiver_id' => $group_id,
  4819. 'content' => '通过通知创建群聊',
  4820. 'group_receiver_id' => $notice['user_id'],
  4821. 'action' => 'said',
  4822. 'created_at' => date('Y-m-d H:i:s'),
  4823. ];
  4824. var_dump($chatData, '-----------------chatData-------');
  4825. $chatResult = ChatRecords::insert($chatData);
  4826. //处理imp
  4827. $group = [
  4828. 'type' => 1,
  4829. 'name' => $notice['group_name'] ?? '',
  4830. 'profile' => '',
  4831. 'avatar' => '',
  4832. 'creator_id' => $notice['user_id'],
  4833. ];
  4834. $groupResult = GroupImp::insertGetId($group);
  4835. var_dump($groupResult, '获取imp group_id');
  4836. $groupMember = [
  4837. 'user_id' => $notice['user_id'],
  4838. 'group_id' => $groupResult,
  4839. 'leader' => 1,
  4840. 'join_time' => Date('Y-m-d H:i:s')
  4841. ];
  4842. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  4843. $talk_session = [
  4844. 'user_id' => $notice['user_id'],
  4845. 'to_from_id' => $groupResult,
  4846. 'talk_mode' => 2,
  4847. 'created_at' => Date('Y-m-d H:i:s'),
  4848. 'updated_at' => Date('Y-m-d H:i:s'),
  4849. ];
  4850. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  4851. //被通知人员处理
  4852. foreach ($chat_ids as $key => $value) {
  4853. $groupMemberdata[] = [
  4854. 'user_id' => $value,
  4855. 'group_id' => $groupResult,
  4856. 'leader' => 3,
  4857. 'join_time' => Date('Y-m-d H:i:s')
  4858. ];
  4859. $talk_sessionData[] = [
  4860. 'user_id' => $value,
  4861. 'to_from_id' => $groupResult,
  4862. 'talk_mode' => 2,
  4863. 'created_at' => Date('Y-m-d H:i:s'),
  4864. 'updated_at' => Date('Y-m-d H:i:s'),
  4865. ];
  4866. }
  4867. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  4868. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  4869. $group_id = $groupResult;
  4870. //更新result的 group_id
  4871. $data['group_id'] = $group_id;
  4872. Notice::where(['id' => $data['id']])->update($data);
  4873. }
  4874. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  4875. //删除掉信息
  4876. GroupImp::where('id', $notice['group_id'])->delete();
  4877. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  4878. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  4879. foreach ($chat_ids as $key => $value) {
  4880. }
  4881. //聊天记录删除
  4882. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  4883. $data['group_id'] = null;
  4884. Notice::where(['id' => $data['id']])->update($data);
  4885. }
  4886. $result = Notice::where('id', $data['id'])->update($data);
  4887. $noticeInfo = Notice::where('id', $data['id'])->first();
  4888. if ($data['status'] == 2) {
  4889. $this->sendMessage([
  4890. 'talk_type' => 701,
  4891. 'title' => $noticeInfo['title'],
  4892. 'content' => '审核通过',
  4893. 'messageType' => 3,
  4894. 'user_id' => $noticeInfo['user_id'],
  4895. ]);
  4896. }
  4897. if ($data['status'] == 3) {
  4898. $this->sendMessage([
  4899. 'talk_type' => 701,
  4900. 'title' => $noticeInfo['title'],
  4901. 'content' => '审核拒绝',
  4902. 'messageType' => 3,
  4903. 'user_id' => $noticeInfo['user_id'],
  4904. ]);
  4905. }
  4906. if ($data['status'] == 1) {
  4907. $this->sendMessage([
  4908. 'talk_type' => 700,
  4909. 'title' => $noticeInfo['title'],
  4910. 'content' => '提交了审核',
  4911. 'messageType' => 3,
  4912. ]);
  4913. }
  4914. return Result::success($result);
  4915. }
  4916. public function getDUser(array $data): array
  4917. {
  4918. if (!empty($data['ids'])) {
  4919. $user = User::whereIn('id', $data['ids'])->getall();
  4920. if (empty($user)) {
  4921. return Result::error('无数据', 0);
  4922. }
  4923. return Result::success($user);
  4924. }
  4925. $where = [];
  4926. if (!empty($data['department_id'])) {
  4927. $where['department_id'] = $data['department_id'];
  4928. }
  4929. if (!empty($data['city_id'])) {
  4930. $where['city_id'] = $data['city_id'];
  4931. }
  4932. $result = User::where('type_id', 2)
  4933. ->where('status', 1)
  4934. ->where($where)
  4935. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4936. ->get();
  4937. if (empty($result)) {
  4938. return Result::error("查询失败", 0);
  4939. }
  4940. return Result::success($result);
  4941. }
  4942. /**
  4943. * 验证导航名称是否重复
  4944. * @return void
  4945. */
  4946. public function checkCategoryName(array $data): array
  4947. {
  4948. $result = Category::when($data, function ($query) use ($data) {
  4949. if (isset($data['name']) && $data['name']) {
  4950. $query->where("name", $data['name']);
  4951. }
  4952. if (isset($data['id']) && $data['id']) {
  4953. $query->where("id", "!=", $data['id']);
  4954. }
  4955. })->first();
  4956. if ($result) {
  4957. return Result::error("已存在");
  4958. } else {
  4959. return Result::success();
  4960. }
  4961. }
  4962. //20250226 产品列表
  4963. // 20250306 -------招聘--------fr
  4964. /*
  4965. * 招聘列表
  4966. * */
  4967. public function getJobRecruitingList(array $data): array
  4968. {
  4969. $where = [];
  4970. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4971. if ($data['checkout'] == 0) {
  4972. $job_status = [0, 2];
  4973. } else {
  4974. $job_status = [1];
  4975. }
  4976. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4977. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4978. }
  4979. $user = User::where('id', $data['user_id'])->first();
  4980. if (empty($user)) {
  4981. return Result::error("用户不存在", 0);
  4982. }
  4983. // 3:企业会员
  4984. if ($user['type_id'] == 3) {
  4985. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4986. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4987. }
  4988. // 如果 $where 为空,则不添加 where 条件
  4989. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4990. return $query->where($where);
  4991. })
  4992. ->whereIn('job_recruiting.status', $job_status)
  4993. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4994. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4995. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4996. ->orderBy("updated_at", "desc")
  4997. ->offset(($data['page'] - 1) * $data['page_size'])
  4998. ->limit($data['page_size'])
  4999. ->get()
  5000. ->all();
  5001. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5002. return $query->where($where);
  5003. })
  5004. ->whereIn('job_recruiting.status', $job_status)
  5005. ->count();
  5006. if (empty($result)) {
  5007. return Result::error("暂无招聘信息", 0);
  5008. }
  5009. return Result::success($result);
  5010. }
  5011. /*
  5012. * 招聘信息添加
  5013. * */
  5014. public function addJobRecruiting(array $data): array
  5015. {
  5016. // var_dump('添加招聘进入news------data',$data);
  5017. // return Result::success($data);
  5018. $user = User::where('user.id', $data['user_id'])
  5019. ->where('user.status', 1)
  5020. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5021. ->select(
  5022. 'user.type_id',
  5023. 'user.mobile',
  5024. 'user.email',
  5025. 'user_info.business_name',
  5026. 'user_info.company_hy_id',
  5027. 'user_info.company_nature',
  5028. 'user_info.company_size',
  5029. 'user_info.introduction',
  5030. 'user_info.real_name',
  5031. 'user_info.company_url',
  5032. 'user_info.address_arr_id',
  5033. 'user_info.address'
  5034. )
  5035. ->first();
  5036. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5037. return Result::error("用户不存在", 0);
  5038. }
  5039. $web = Website::where('id', $data['website_id'])->first();
  5040. if (empty($web)) {
  5041. return Result::error("网站不存在", 0);
  5042. }
  5043. // var_dump('添加招聘进入news---user---user',$user);
  5044. // 处理招聘关键词
  5045. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5046. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5047. } else {
  5048. Jieba::init(); // 初始化 jieba-php
  5049. Finalseg::init();
  5050. $segList = Jieba::cut($data['title']);
  5051. $segList1 = array_slice($segList, 0, 8);
  5052. $data['keyword'] = implode(',', $segList1);
  5053. }
  5054. if(!isset($data['eso_description']) || empty($data['eso_description'])){
  5055. $content = $data['description'];
  5056. // 去除 <style> 和 <script> 标签及其内容
  5057. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5058. // 去除所有 HTML 标签
  5059. $content = strip_tags($content);
  5060. // 去除 HTML 实体
  5061. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5062. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5063. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5064. // 去除多余空白
  5065. $content = preg_replace('/\s+/u', '', $content);
  5066. // 截取 100 个字符
  5067. $data['eso_descriprion'] = mb_substr($content, 0, 100);
  5068. }
  5069. // return Result::success($user);
  5070. $data['action_id'] = $data['user_id'] ?? null;
  5071. $data['user_type'] = $user['type_id'] ?? null;
  5072. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5073. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5074. $data['catid'] = end($data['cat_arr_id']);
  5075. } else {
  5076. $data['catid'] = 0;
  5077. }
  5078. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5079. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5080. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5081. // 公司地址 管理员必填
  5082. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5083. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5084. // 管理员-企业相关信息
  5085. $company = [
  5086. // 'user_id' => $data['user_id']?? null,
  5087. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5088. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5089. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5090. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5091. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5092. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5093. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5094. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5095. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5096. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5097. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5098. ];
  5099. //去掉相关企业信息
  5100. $job = array_diff_key($data, array_flip(array_keys($company)));
  5101. // var_dump('添加招聘进入news---job---user',$job);
  5102. Db::beginTransaction();
  5103. try {
  5104. // // 先添加职位相关信息
  5105. if ($user['type_id'] == 10000) {
  5106. $job['status'] = 1;
  5107. }
  5108. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5109. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5110. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5111. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5112. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5113. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5114. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5115. // return Result::success($job);
  5116. $jobId = JobRecruiting::insertGetId($job);
  5117. if (empty($jobId)) {
  5118. Db::rollBack();
  5119. return Result::error("添加失败");
  5120. }
  5121. // 添加公司信息
  5122. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5123. $company['job_id'] = $jobId;
  5124. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5125. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5126. if ($user['type_id'] == 10000) {
  5127. // 管理员添加企业信息
  5128. $companyId = JobCompany::insertGetId($company);
  5129. if (empty($companyId)) {
  5130. Db::rollBack();
  5131. return Result::error("添加失败");
  5132. }
  5133. } else {
  5134. // 企业会员添加企业信息
  5135. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5136. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5137. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5138. $company['job_id'] = $jobId;
  5139. $companyId = JobCompany::insertGetId($company);
  5140. if (empty($companyId)) {
  5141. Db::rollBack();
  5142. return Result::error("添加失败");
  5143. }
  5144. }
  5145. Db::commit();
  5146. $result = [
  5147. 'job_id' => $jobId,
  5148. 'company_id' => $companyId,
  5149. ];
  5150. return Result::success($result);
  5151. } catch (\Exception $e) {
  5152. Db::rollBack();
  5153. return Result::error($e->getMessage(), 0);
  5154. }
  5155. // return Result::success($result);
  5156. }
  5157. /*
  5158. * 获取招聘信息详情
  5159. * */
  5160. public function getJobRecruitingInfo(array $data): array
  5161. {
  5162. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5163. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5164. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5165. ->select(
  5166. 'job_recruiting.*',
  5167. 'website.website_name as website_name',
  5168. 'job_company.business_name',
  5169. 'job_company.company_hy_id',
  5170. 'job_company.company_size',
  5171. 'job_company.company_nature',
  5172. 'job_company.introduction',
  5173. 'job_company.real_name',
  5174. 'job_company.mobile',
  5175. 'job_company.company_url',
  5176. 'job_company.address_arr_id',
  5177. 'job_company.address',
  5178. 'job_company.email'
  5179. )
  5180. ->first();
  5181. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5182. if (!empty($cityId)) {
  5183. if (isset($cityId[1]) && $cityId[1] != null) {
  5184. $city = District::where('id', $cityId[1])->first(['name']);
  5185. } else {
  5186. $city = District::where('id', $cityId[0])->first(['name']);
  5187. }
  5188. $result['city'] = $city['name'] ?? '';
  5189. }
  5190. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5191. if (is_array($addressId) && !empty($addressId)) {
  5192. $address = District::whereIn('id', $addressId)
  5193. ->orderBy('level', 'asc')
  5194. ->get(['name'])
  5195. ->pluck('name')
  5196. ->implode('');
  5197. // $job->address_name = $address ?? '';
  5198. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5199. }
  5200. if (empty($result)) {
  5201. return Result::error("招聘信息不存在", 0);
  5202. }
  5203. // return Result::success($job);
  5204. return Result::success($result);
  5205. }
  5206. /*
  5207. * 修改招聘信息
  5208. * */
  5209. public function upJobRecruiting(array $data): array
  5210. {
  5211. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5212. // return Result::success($job);
  5213. if (empty($job)) {
  5214. return Result::error("招聘信息不存在", 0);
  5215. }
  5216. $user = User::where('id', $data['user_id'])->first();
  5217. // return Result::success($user);
  5218. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5219. return Result::error("用户不存在", 0);
  5220. }
  5221. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5222. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5223. }
  5224. // 处理招聘关键词
  5225. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5226. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5227. } else {
  5228. Jieba::init(); // 初始化 jieba-php
  5229. Finalseg::init();
  5230. $segList = Jieba::cut($data['title']);
  5231. $segList1 = array_slice($segList, 0, 8);
  5232. $data['keyword'] = implode(',', $segList1);
  5233. }
  5234. if(!isset($data['eso_description']) || empty($data['eso_description'])){
  5235. $content = $data['description'];
  5236. // 去除 <style> 和 <script> 标签及其内容
  5237. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5238. // 去除所有 HTML 标签
  5239. $content = strip_tags($content);
  5240. // 去除 HTML 实体
  5241. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5242. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5243. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5244. // 去除多余空白
  5245. $content = preg_replace('/\s+/u', '', $content);
  5246. // 截取 100 个字符
  5247. $data['eso_descriprion'] = mb_substr($content, 0, 100);
  5248. }
  5249. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5250. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5251. $data['catid'] = end($data['cat_arr_id']);
  5252. } else {
  5253. }
  5254. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5255. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5256. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5257. // 公司地址 管理员必填
  5258. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5259. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5260. // 管理员-企业相关信息
  5261. $company = [
  5262. // 'user_id' => $data['user_id']?? null,
  5263. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5264. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5265. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5266. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5267. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5268. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5269. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5270. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5271. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5272. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5273. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5274. ];
  5275. //去掉相关企业信息
  5276. $data = array_diff_key($data, array_flip(array_keys($company)));
  5277. $jobId = $data['id'];
  5278. $web = $data['website_id'];
  5279. $data['action_id'] = $data['user_id'];
  5280. unset($data['user_id']);
  5281. unset($data['user_type']);
  5282. unset($data['id']);
  5283. unset($data['website_id']);
  5284. // return Result::success($data);
  5285. Db::beginTransaction();
  5286. try {
  5287. // 管理员修改招聘信息
  5288. if ($user['type_id'] == 10000) {
  5289. $data['website_id'] = $web;
  5290. $company['website_id'] = $data['website_id'];
  5291. $data['status'] = 1;
  5292. } else {
  5293. $data['status'] = 0;
  5294. }
  5295. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5296. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5297. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5298. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5299. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5300. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5301. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5302. // return Result::success($job);
  5303. // Db::rollBack();
  5304. // return Result::success($company);
  5305. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5306. $this->sendMessage([
  5307. 'talk_type' => 500,
  5308. 'title' => $data['title'],
  5309. 'content' => '提交了审核',
  5310. 'messageType' => 10,
  5311. ]);
  5312. }
  5313. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5314. if (empty($result['job'])) {
  5315. Db::rollBack();
  5316. return Result::error("修改招聘信息失败");
  5317. }
  5318. // 管理员修改企业相关信息
  5319. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5320. if (empty($result['company'])) {
  5321. Db::rollBack();
  5322. return Result::error("修改企业相关信息失败");
  5323. }
  5324. Db::commit();
  5325. // return Result::success($result);
  5326. } catch (\Exception $e) {
  5327. Db::rollBack();
  5328. return Result::error($e->getMessage(), 0);
  5329. }
  5330. return Result::success($result);
  5331. }
  5332. /*
  5333. * 招聘信息删除
  5334. * */
  5335. public function delJobRecruiting(array $data): array
  5336. {
  5337. $user = User::where('id', $data['user_id'])->first();
  5338. if (empty($user)) {
  5339. return Result::error("用户不存在", 0);
  5340. }
  5341. $job = JobRecruiting::where('id', $data['id'])->first();
  5342. if (empty($job)) {
  5343. return Result::error("招聘信息不存在", 0);
  5344. }
  5345. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5346. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5347. }
  5348. Db::beginTransaction();
  5349. try {
  5350. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5351. if (empty($result['job'])) {
  5352. Db::rollBack();
  5353. return Result::error("删除招聘信息失败");
  5354. }
  5355. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5356. if (empty($result['company'])) {
  5357. Db::rollBack();
  5358. return Result::error("删除企业相关信息失败");
  5359. }
  5360. Db::commit();
  5361. } catch (\Exception $e) {
  5362. Db::rollBack();
  5363. return Result::error($e->getMessage(), 0);
  5364. }
  5365. return Result::success($result);
  5366. }
  5367. /*
  5368. * 获取公司信息
  5369. * */
  5370. public function getJobCompany(array $data): array
  5371. {
  5372. $user = User::where('user.id', $data['user_id'])
  5373. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5374. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5375. ->first();
  5376. // return Result::success($user);
  5377. if (empty($user)) {
  5378. return Result::error("用户不存在", 0);
  5379. }
  5380. if ($user['type_id'] == 3) {
  5381. $result = [
  5382. // 'id' => 0,
  5383. 'user_id' => $data['user_id'],
  5384. 'website_id' => $data['website_id'],
  5385. 'business_name' => $user['business_name'], // 企业名称
  5386. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5387. 'company_nature' => $user['company_nature'], // 公司性质
  5388. 'company_size' => $user['company_size'], // 公司规模
  5389. 'introduction' => $user['introduction'], // 公司简介
  5390. 'real_name' => $user['real_name'], // 企业联系人
  5391. 'mobile' => $user['mobile'], // 企业联系电话
  5392. 'company_url' => $user['company_url'], // 企业网址
  5393. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5394. 'address' => $user['address'], // 企业地址
  5395. 'email' => $user['email'], // 企业邮箱
  5396. ];
  5397. } else {
  5398. return Result::error("用户类型错误", 0);
  5399. }
  5400. if (empty($result)) {
  5401. return Result::error("公司信息不存在", 0);
  5402. }
  5403. return Result::success($result);
  5404. }
  5405. /*
  5406. * 修改公司信息
  5407. * */
  5408. public function upJobCompany(array $data): array
  5409. {
  5410. // return Result::success($data);
  5411. $user = User::where('user.id', $data['user_id'])
  5412. ->where('user.status', 1)
  5413. ->select('user.user_name', 'user.type_id')
  5414. ->first();
  5415. if (empty($user)) {
  5416. return Result::error("用户不存在", 0);
  5417. }
  5418. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5419. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5420. $company = [
  5421. 'business_name' => $data['business_name'], // 企业名称
  5422. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5423. 'company_nature' => $data['company_nature'], // 公司性质
  5424. 'company_size' => $data['company_size'], // 公司规模
  5425. 'introduction' => $data['introduction'], // 公司简介
  5426. // 'real_name' => $data['real_name'], // 企业联系人
  5427. 'company_url' => $data['company_url'], // 企业网址
  5428. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5429. 'address' => $data['address'], // 企业详细地址
  5430. // 'email' => $data['email'], // 企业邮箱
  5431. ];
  5432. if ($user['type_id'] == 3) {
  5433. Db::beginTransaction();
  5434. try {
  5435. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5436. 'business_name' => $data['business_name'], // 企业名称
  5437. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5438. 'company_nature' => $data['company_nature'], // 公司性质
  5439. 'company_size' => $data['company_size'], // 公司规模
  5440. 'introduction' => $data['introduction'], // 公司简介
  5441. // 'real_name' => $data['real_name'], // 企业联系人
  5442. 'company_url' => $data['company_url'], // 企业网址
  5443. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5444. 'address' => $data['address'], // 企业详细地址
  5445. ]);
  5446. if (empty($result['userinfo'])) {
  5447. Db::rollBack();
  5448. return Result::error('修改企业会员信息失败!');
  5449. }
  5450. $result['user'] = User::where('id', $data['user_id'])->update([
  5451. 'email' => $data['email'], // 企业邮箱
  5452. ]);
  5453. if (empty($result['user'])) {
  5454. Db::rollBack();
  5455. return Result::error('修改个人中心信息失败!');
  5456. }
  5457. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5458. if (!empty($job_company)) {
  5459. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5460. if (empty($result['job_company'])) {
  5461. Db::rollBack();
  5462. return Result::error('修改企业会员信息失败!');
  5463. }
  5464. }
  5465. Db::commit();
  5466. return Result::success($result);
  5467. } catch (\Exception $e) {
  5468. Db::rollBack();
  5469. return Result::error($e->getMessage(), 0);
  5470. }
  5471. } else {
  5472. return Result::error("用户类型错误", 0);
  5473. }
  5474. }
  5475. /*
  5476. * 获取省-市
  5477. * */
  5478. public function getJobRecruitingArea(array $data): array
  5479. {
  5480. if (isset($data['pid']) && $data['pid'] != null) {
  5481. $result = District::where('pid', $data['pid'])->get()->all();
  5482. } else {
  5483. $result = District::where('level', 1)->get()->all();
  5484. }
  5485. if (empty($result)) {
  5486. return Result::error("暂无此省市", 0);
  5487. }
  5488. return Result::success($result);
  5489. }
  5490. /*
  5491. * 获取行业分类
  5492. * */
  5493. public function getIndustry(array $data): array
  5494. {
  5495. $result = JobIndustry::get()->all();
  5496. if (empty($result)) {
  5497. return Result::error("暂无行业分类", 0);
  5498. }
  5499. return Result::success($result);
  5500. }
  5501. /*
  5502. * 获取职位
  5503. * */
  5504. public function getPositionList(array $data): array
  5505. {
  5506. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5507. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5508. } else {
  5509. $result = JobPosition::where('zwpid', 0)->get()->all();
  5510. }
  5511. if (empty($result)) {
  5512. return Result::error("暂无此职位", 0);
  5513. }
  5514. return Result::success($result);
  5515. }
  5516. /*
  5517. * 获取工作性质-菜单
  5518. * */
  5519. public function getJobNature(array $data): array
  5520. {
  5521. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5522. if (empty($result)) {
  5523. return Result::error("暂无工作性质", 0);
  5524. }
  5525. return Result::success($result);
  5526. }
  5527. /*
  5528. * 获取工作经验-菜单
  5529. * */
  5530. public function getExperience(array $data): array
  5531. {
  5532. $result = JobEnum::where('egroup', 'years')->get()->all();
  5533. if (empty($result)) {
  5534. return Result::error("暂无工作经验", 0);
  5535. }
  5536. return Result::success($result);
  5537. }
  5538. /*
  5539. * 获取学历-菜单
  5540. * */
  5541. public function getEducation(array $data): array
  5542. {
  5543. $result = JobEnum::where('egroup', 'education')->get()->all();
  5544. if (empty($result)) {
  5545. return Result::error("暂无学历", 0);
  5546. }
  5547. return Result::success($result);
  5548. }
  5549. /*
  5550. * 获取薪资-菜单
  5551. * */
  5552. public function getSalary(array $data): array
  5553. {
  5554. $result = JobEnum::where('egroup', 'income')->get()->all();
  5555. if (empty($result)) {
  5556. return Result::error("暂无薪资", 0);
  5557. }
  5558. return Result::success($result);
  5559. }
  5560. /*
  5561. * 获取语言-菜单
  5562. * */
  5563. public function getLanguage(array $data): array
  5564. {
  5565. $result = JobEnum::where('egroup', 'language')->get()->all();
  5566. if (empty($result)) {
  5567. return Result::error("暂无语言", 0);
  5568. }
  5569. return Result::success($result);
  5570. }
  5571. /*
  5572. * 获取掌握程度-菜单
  5573. * */
  5574. public function getLevel(array $data): array
  5575. {
  5576. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5577. if (empty($result)) {
  5578. return Result::error("暂无工作性质", 0);
  5579. }
  5580. return Result::success($result);
  5581. }
  5582. // 公司信息
  5583. /*
  5584. * 获取公司性质-菜单
  5585. * */
  5586. public function getCompanyNature(array $data): array
  5587. {
  5588. $result = JobNature::get()->all();
  5589. if (empty($result)) {
  5590. return Result::error("暂无公司性质", 0);
  5591. }
  5592. return Result::success($result);
  5593. }
  5594. /*
  5595. * 获取公司规模-菜单
  5596. * */
  5597. public function getCompanySize(array $data): array
  5598. {
  5599. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5600. if (empty($result)) {
  5601. return Result::error("暂无公司规模", 0);
  5602. }
  5603. return Result::success($result);
  5604. }
  5605. /*
  5606. * 招聘信息审核
  5607. * */
  5608. public function checkJobRecruiting(array $data): array
  5609. {
  5610. $user = User::where('id', $data['user_id'])->first();
  5611. if (empty($user)) {
  5612. return Result::error("用户不存在", 0);
  5613. }
  5614. $job = JobRecruiting::where('id', $data['id'])->first();
  5615. if (empty($job)) {
  5616. return Result::error("招聘信息不存在", 0);
  5617. }
  5618. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5619. if ($user['type_id'] != 10000) {
  5620. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5621. }
  5622. // 驳回原因
  5623. if ($data['status'] == 2) {
  5624. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5625. }
  5626. $data['action_id'] = $data['user_id'];
  5627. unset($data['user_id']);
  5628. if ($data['status'] == 1) {
  5629. $this->sendMessage([
  5630. 'talk_type' => 501,
  5631. 'title' => $job['title'],
  5632. 'content' => '审核通过',
  5633. 'messageType' => 10,
  5634. 'user_id' => $job['user_id'],
  5635. ]);
  5636. }
  5637. if ($data['status'] == 2) {
  5638. $this->sendMessage([
  5639. 'talk_type' => 501,
  5640. 'title' => $job['title'],
  5641. 'content' => '审核拒绝',
  5642. 'messageType' => 10,
  5643. 'user_id' => $job['user_id'],
  5644. ]);
  5645. }
  5646. if ($data['status'] == 0) {
  5647. $this->sendMessage([
  5648. 'talk_type' => 500,
  5649. 'title' => $job['title'],
  5650. 'content' => '提交了审核',
  5651. 'messageType' => 10,
  5652. ]);
  5653. }
  5654. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5655. if (empty($result)) {
  5656. return Result::error("审核失败", 0);
  5657. }
  5658. return Result::success($result);
  5659. }
  5660. public function myApplyList(array $data): array
  5661. {
  5662. var_dump($data, '------参数');
  5663. $user = User::where('id', $data['user_id'])->first();
  5664. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5665. return Result::error("用户不存在", 0);
  5666. }
  5667. // 1:个人会员 职场机会
  5668. if ($user['type_id'] == 1) {
  5669. $where['user_id'] = $user['id'];
  5670. }
  5671. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5672. $query->where('user_id', $user['id']);
  5673. })
  5674. ->pluck('recruit_id');
  5675. $where = [];
  5676. if (isset($data['salary']) && $data['salary'] != null) {
  5677. $where['job_recruiting.salary'] = $data['salary'];
  5678. }
  5679. if (isset($data['experience']) && $data['experience'] != null) {
  5680. $where['job_recruiting.experience'] = $data['experience'];
  5681. }
  5682. if (isset($data['business_name']) && $data['business_name'] != null) {
  5683. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5684. }
  5685. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5686. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5687. ->where($where);
  5688. // ->count();
  5689. $count = $query->count();
  5690. $query = clone $query;
  5691. $job = $query
  5692. ->leftJoin('job_enum as income_enum', function ($join) {
  5693. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5694. ->where('income_enum.egroup', 'income');
  5695. })
  5696. ->leftJoin('job_enum as years_enum', function ($join) {
  5697. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5698. ->where('years_enum.egroup', 'years');
  5699. })
  5700. // ->where($where)
  5701. ->orderBy('job_recruiting.updated_at', 'desc')
  5702. ->select(
  5703. 'job_recruiting.id',
  5704. 'job_recruiting.title',
  5705. 'job_company.business_name',
  5706. 'income_enum.evalue as salary_evalue',
  5707. 'income_enum.ename as salary_ename',
  5708. 'years_enum.evalue as experience_evalue',
  5709. 'years_enum.ename as experience_ename',
  5710. 'job_recruiting.updated_at'
  5711. )
  5712. ->offset(($data['page'] - 1) * $data['pageSize'])
  5713. ->limit($data['pageSize'])
  5714. ->get()
  5715. ->all();
  5716. if (empty($job)) {
  5717. return Result::error("暂无招聘信息", 0);
  5718. }
  5719. $result = [
  5720. 'row' => $job,
  5721. 'count' => $count,
  5722. ];
  5723. return Result::success($result);
  5724. }
  5725. public function readJobApply(array $data): array
  5726. {
  5727. $result = JobApply::where('id', $data['id'])->first();
  5728. if (empty($result)) {
  5729. return Result::error("查询失败", 0);
  5730. }
  5731. $result = JobApply::where('id', $data['id'])->update([
  5732. 'status' => 2,
  5733. ]);
  5734. return Result::success($result);
  5735. }
  5736. /*
  5737. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5738. * */
  5739. public function getRecruitingList(array $data): array
  5740. {
  5741. $user = User::where('id', $data['user_id'])->first();
  5742. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5743. return Result::error("用户不存在", 0);
  5744. }
  5745. // 1:个人会员 职场机会
  5746. if ($user['type_id'] == 1) {
  5747. $where['user_id'] = $user['id'];
  5748. }
  5749. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5750. $query->where('receiver_id', $user['id']);
  5751. })
  5752. ->pluck('recruit_id');
  5753. // return Result::success($recruitingId);
  5754. $where = [];
  5755. if (isset($data['salary']) && $data['salary'] != null) {
  5756. $where['job_recruiting.salary'] = $data['salary'];
  5757. }
  5758. if (isset($data['experience']) && $data['experience'] != null) {
  5759. $where['job_recruiting.experience'] = $data['experience'];
  5760. }
  5761. if (isset($data['business_name']) && $data['business_name'] != null) {
  5762. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5763. }
  5764. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5765. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5766. ->where($where);
  5767. // ->count();
  5768. $count = $query->count();
  5769. $query = clone $query;
  5770. $job = $query
  5771. ->leftJoin('job_enum as income_enum', function ($join) {
  5772. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5773. ->where('income_enum.egroup', 'income');
  5774. })
  5775. ->leftJoin('job_enum as years_enum', function ($join) {
  5776. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5777. ->where('years_enum.egroup', 'years');
  5778. })
  5779. // ->where($where)
  5780. ->orderBy('job_recruiting.updated_at', 'desc')
  5781. ->select(
  5782. 'job_recruiting.id',
  5783. 'job_recruiting.title',
  5784. 'job_company.business_name',
  5785. 'income_enum.evalue as salary_evalue',
  5786. 'income_enum.ename as salary_ename',
  5787. 'years_enum.evalue as experience_evalue',
  5788. 'years_enum.ename as experience_ename',
  5789. 'job_recruiting.updated_at'
  5790. )
  5791. ->offset(($data['page'] - 1) * $data['pageSize'])
  5792. ->limit($data['pageSize'])
  5793. ->get()
  5794. ->all();
  5795. if (empty($job)) {
  5796. return Result::error("暂无招聘信息", 0);
  5797. }
  5798. $result = [
  5799. 'row' => $job,
  5800. 'count' => $count,
  5801. ];
  5802. return Result::success($result);
  5803. }
  5804. /*
  5805. * 获取企业会员-招聘信息列表
  5806. * */
  5807. public function getRecruitingInfo(array $data): array
  5808. {
  5809. $user = User::where('id', $data['user_id'])->first();
  5810. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5811. return Result::error("用户不存在", 0);
  5812. }
  5813. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5814. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5815. ->select(
  5816. 'job_recruiting.*',
  5817. 'job_company.business_name',
  5818. 'job_company.company_hy_id',
  5819. 'job_company.company_size',
  5820. 'job_company.company_nature',
  5821. 'job_company.introduction',
  5822. 'job_company.real_name',
  5823. 'job_company.mobile',
  5824. 'job_company.company_url',
  5825. 'job_company.address_arr_id',
  5826. 'job_company.address',
  5827. 'job_company.email'
  5828. )
  5829. ->get();
  5830. if (empty($recruiting)) {
  5831. return Result::error("暂无招聘信息", 0);
  5832. }
  5833. return Result::success($recruiting);
  5834. }
  5835. /*
  5836. * 获取企业会员-我的沟通
  5837. * */
  5838. public function getJobResumeList(array $data): array
  5839. {
  5840. $user = User::where('id', $data['user_id'])->first();
  5841. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5842. return Result::error("用户不存在", 0);
  5843. }
  5844. $where = [];
  5845. if (isset($data['salary']) && $data['salary'] != null) {
  5846. $where['job_hunting.salary'] = $data['salary'];
  5847. }
  5848. if (isset($data['user_name']) && $data['user_name'] != null) {
  5849. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5850. }
  5851. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5852. $query->where('job_resume.user_id', $user['id']);
  5853. })
  5854. ->when(!empty($where), function ($query) use ($where) {
  5855. $query->where($where);
  5856. })
  5857. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5858. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5859. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5860. ->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');
  5861. $count = $job->count();
  5862. if ($count == 0) {
  5863. return Result::error("暂无沟通记录", 0);
  5864. }
  5865. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5866. ->offset(($data['page'] - 1) * $data['pageSize'])
  5867. ->limit($data['pageSize'])
  5868. ->get();
  5869. if (empty($jobs)) {
  5870. return Result::error("暂无沟通记录", 0);
  5871. }
  5872. $result['row'] = $this->processJob($jobs, '');
  5873. $result['count'] = $count;
  5874. return Result::success($result);
  5875. }
  5876. public function readJobResume(array $data): array
  5877. {
  5878. $result = JobResume::where('id', $data['id'])->first();
  5879. if (empty($result)) {
  5880. return Result::error("查询失败", 0);
  5881. }
  5882. $result = JobResume::where('id', $data['id'])->update([
  5883. 'status' => 2,
  5884. ]);
  5885. return Result::success($result);
  5886. }
  5887. // 20250306 招聘
  5888. //20250422 书刊音像
  5889. public function addBook(array $data): array
  5890. {
  5891. $user_id = $data['user_id'] ?? 0;
  5892. $type_id = $data['type_id'] ?? 0;
  5893. // $website_id = $data['website_id'] ?? 0;
  5894. // unset($data['user_id']);
  5895. unset($data['type_id']);
  5896. // unset($data['website_id']);
  5897. //处理数组
  5898. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5899. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5900. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5901. if ($data['img_url'] == '') {
  5902. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5903. preg_match_all($reg, $data['detail'], $matches);
  5904. if (isset($matches[1][0])) {
  5905. //截取varchar240
  5906. $data['img_url'] = substr($matches[1][0], 0, 240);
  5907. }
  5908. }
  5909. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5910. //提取标题+内容中的关键词
  5911. $data['keyword'] = $data['title'];
  5912. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5913. Jieba::init(); // 初始化 jieba-php
  5914. Finalseg::init();
  5915. $segList = Jieba::cut($data['keyword']);
  5916. $segList1 = array_slice($segList, 0, 8);
  5917. $data['keyword'] = implode(',', $segList1);
  5918. }
  5919. if ($data['description'] == '') {
  5920. //提取内容中的描述
  5921. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5922. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5923. }
  5924. var_dump($data, '--');
  5925. if ($data['status'] == 1) {
  5926. $this->sendMessage([
  5927. 'talk_type' => 400,
  5928. 'title' => $data['title'],
  5929. 'content' => '提交了审核',
  5930. 'messageType' => 7,
  5931. ]);
  5932. }
  5933. $result = Book::insertGetId($data);
  5934. if (empty($result)) {
  5935. return Result::error("添加失败", 0);
  5936. }
  5937. return Result::success($result);
  5938. }
  5939. public function getBookList(array $data): array
  5940. {
  5941. $where = [];
  5942. if (!empty($data["title"])) {
  5943. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5944. }
  5945. if (!empty($data['website_name'])) {
  5946. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5947. }
  5948. if (!empty($data['status'])) {
  5949. $where[] = ['book.status', '=', $data['status']];
  5950. }
  5951. $user_id = $data['user_id'];
  5952. $type_id = $data['type_id'];
  5953. // $type_id = 4;
  5954. var_dump($type_id, '------1--------');
  5955. if ($type_id != 10000) {
  5956. $where[] = ['book.user_id', '=', $user_id];
  5957. }
  5958. var_dump(!empty($data['status1']), '=-===1');
  5959. $result = Book::where($where)
  5960. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5961. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5962. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5963. ->when(isset($data['status1']), function ($query) use ($data) {
  5964. $query->whereIn('book.status', [1, 3]);
  5965. })
  5966. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5967. ->orderBy("updated_at", "desc")
  5968. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5969. if (empty($result)) {
  5970. return Result::error("暂无数据", 0);
  5971. }
  5972. // 取出数据
  5973. $rows = $result->items();
  5974. $count = $result->total();
  5975. $responseData = [
  5976. 'rows' => $rows,
  5977. 'count' => $count,
  5978. ];
  5979. return Result::success($responseData);
  5980. }
  5981. public function deleteBook(array $data): array
  5982. {
  5983. $result = Book::where('id', $data['id'])->delete();
  5984. if (empty($result)) {
  5985. return Result::error("删除失败", 0);
  5986. }
  5987. return Result::success($result);
  5988. }
  5989. public function updateBook(array $data): array
  5990. {
  5991. // $user_id = $data['user_id'] ?? 0;
  5992. $type_id = $data['type_id'] ?? 0;
  5993. // $website_id = $data['website_id'] ?? 0;
  5994. unset($data['user_id']);
  5995. unset($data['type_id']);
  5996. // unset($data['website_id']);
  5997. //处理数组
  5998. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5999. if ($data['img_url'] == '') {
  6000. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6001. preg_match_all($reg, $data['detail'], $matches);
  6002. if (isset($matches[1][0])) {
  6003. //截取varchar240
  6004. $data['img_url'] = substr($matches[1][0], 0, 240);
  6005. }
  6006. }
  6007. if ($data['keyword'] == '') {
  6008. //提取标题+内容中的关键词
  6009. $data['keyword'] = $data['title'];
  6010. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6011. Jieba::init(); // 初始化 jieba-php
  6012. Finalseg::init();
  6013. $segList = Jieba::cut($data['keyword']);
  6014. $segList1 = array_slice($segList, 0, 8);
  6015. $data['keyword'] = implode(',', $segList1);
  6016. }
  6017. if ($data['description'] == '') {
  6018. //提取内容中的描述
  6019. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6020. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6021. }
  6022. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6023. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6024. if ($data['status'] == 1) {
  6025. $this->sendMessage([
  6026. 'talk_type' => 400,
  6027. 'title' => $data['title'],
  6028. 'content' => '提交了审核',
  6029. 'messageType' => 7,
  6030. ]);
  6031. }
  6032. $result = Book::where("id", $data["id"])->update($data);
  6033. if (empty($result)) {
  6034. return Result::error("更新失败", 0);
  6035. }
  6036. return Result::success($result);
  6037. }
  6038. public function getBookInfo(array $data): array
  6039. {
  6040. $result = Book::where("id", $data["id"])->first();
  6041. if (empty($result)) {
  6042. return Result::error("获取失败", 0);
  6043. }
  6044. return Result::success($result);
  6045. }
  6046. public function updateBookStatus(array $data): array
  6047. {
  6048. //审核
  6049. unset($data['user_id']);
  6050. $bookInfo = Book::where("id", $data["id"])->first();
  6051. var_dump($bookInfo, '----');
  6052. if ($data['status'] == 2) {
  6053. $this->sendMessage([
  6054. 'talk_type' => 401,
  6055. 'title' => $bookInfo['title'],
  6056. 'content' => '审核通过',
  6057. 'messageType' => 7,
  6058. 'user_id' => $bookInfo['user_id'],
  6059. ]);
  6060. }
  6061. if ($data['status'] == 3) {
  6062. $this->sendMessage([
  6063. 'talk_type' => 401,
  6064. 'title' => $bookInfo['title'],
  6065. 'content' => '审核拒绝',
  6066. 'messageType' => 7,
  6067. 'user_id' => $bookInfo['user_id'],
  6068. ]);
  6069. }
  6070. if ($data['status'] == 1) {
  6071. $this->sendMessage([
  6072. 'talk_type' => 400,
  6073. 'title' => $bookInfo['title'],
  6074. 'content' => '提交了审核',
  6075. 'messageType' => 7,
  6076. // 'user_id'=>$bookInfo['user_id'],
  6077. ]);
  6078. }
  6079. $result = Book::where("id", $data["id"])->update($data);
  6080. if (empty($result)) {
  6081. return Result::error("更新失败", 0);
  6082. }
  6083. return Result::success($result);
  6084. }
  6085. //20250422 书刊音像
  6086. /**
  6087. * 贴身宝贝
  6088. * @param array $data
  6089. * @return array
  6090. */
  6091. public function getWebsiteTsbb(array $data): array
  6092. {
  6093. $month = $data['month'] ?? date('m');
  6094. $day = $data['day'] ?? date('d');
  6095. // 使用缓存键
  6096. $cacheKey = "tsbb_data_{$month}_{$day}";
  6097. // 尝试从缓存获取数据
  6098. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6099. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6100. if ($cachedData = $cache->get($cacheKey)) {
  6101. return Result::success(unserialize($cachedData));
  6102. }
  6103. //查询老黄历
  6104. try {
  6105. $date = date('Y-m-d');
  6106. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6107. // 使用 curl 替代 file_get_contents
  6108. $ch = curl_init();
  6109. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6110. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6111. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6112. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6113. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6114. 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');
  6115. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6116. 'Accept: application/json',
  6117. 'Content-Type: application/json',
  6118. 'Referer: https://www.36jxs.com/'
  6119. ]);
  6120. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6121. curl_setopt($ch, CURLOPT_ENCODING, '');
  6122. $almanacResponse = curl_exec($ch);
  6123. var_dump("====:", $almanacResponse);
  6124. if (curl_errno($ch)) {
  6125. var_dump('Curl error:', curl_error($ch));
  6126. throw new \Exception('Curl error: ' . curl_error($ch));
  6127. }
  6128. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6129. curl_close($ch);
  6130. if ($almanacResponse === false) {
  6131. throw new \Exception('Failed to fetch almanac data');
  6132. }
  6133. $almanacData = json_decode($almanacResponse, true);
  6134. if (json_last_error() !== JSON_ERROR_NONE) {
  6135. throw new \Exception('Failed to parse almanac data');
  6136. }
  6137. $almanacInfo = $almanacData['data'] ?? [];
  6138. } catch (\Exception $e) {
  6139. var_dump('Exception:', $e->getMessage());
  6140. $almanacInfo = [];
  6141. }
  6142. // 获取历史上的今天数据
  6143. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6144. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6145. ->orderBy('year', 'asc')
  6146. ->select("title", "id", "year", DB::raw('1 as type'))
  6147. ->limit(16)
  6148. ->get();
  6149. // 获取节日数据 - 从今天开始获取未来4条
  6150. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6151. ->orderBy('showtime', 'asc')
  6152. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6153. ->limit(16)
  6154. ->get();
  6155. //说文解字
  6156. $chartacterList = Character::orderBy('updated_at', 'desc')
  6157. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6158. ->limit(6)
  6159. ->get();
  6160. //谜语沙龙
  6161. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6162. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6163. ->limit(4)
  6164. ->get();
  6165. //成语欣赏
  6166. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6167. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6168. ->limit(32)
  6169. ->get();
  6170. //名联赏析
  6171. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6172. ->select("id", "first", "second", DB::raw('6 as type'))
  6173. ->limit(6)
  6174. ->get();
  6175. // 获取分类文章数据
  6176. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6177. ->pluck('category_id')
  6178. ->toArray();
  6179. $articlesList = [];
  6180. foreach ($categoryIds as $catid) {
  6181. // 先查有图片的
  6182. $withImg = DB::table('article')
  6183. ->where('status', 1)
  6184. ->where('catid', $catid)
  6185. ->whereNotNull('imgurl')
  6186. ->where('imgurl', '!=', '')
  6187. ->orderBy('updated_at', 'desc')
  6188. ->limit(6)
  6189. ->get();
  6190. $count = $withImg->count();
  6191. if ($count < 6) {
  6192. // 不足6条再查无图片的补足
  6193. $withoutImg = DB::table('article')
  6194. ->where('status', 1)
  6195. ->where('catid', $catid)
  6196. ->where(function ($q) {
  6197. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6198. })
  6199. ->orderBy('updated_at', 'desc')
  6200. ->limit(6 - $count)
  6201. ->get();
  6202. $articles = $withImg->concat($withoutImg);
  6203. } else {
  6204. $articles = $withImg;
  6205. }
  6206. // 组装
  6207. $category = \App\Model\Category::find($catid);
  6208. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6209. $articlesList[] = [
  6210. 'category_name' => $category ? $category->name : '',
  6211. 'catid' => $catid,
  6212. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6213. 'type' => 100,
  6214. 'list' => $articles->map(function ($item) {
  6215. return [
  6216. 'id' => $item->id,
  6217. 'title' => $item->title,
  6218. 'imgurl' => $item->imgurl,
  6219. 'created_at' => $item->created_at
  6220. ];
  6221. })->values()
  6222. ];
  6223. }
  6224. $result = [
  6225. 'almanac' => $almanacInfo,
  6226. 'historyTodayList' => [
  6227. 'category_name' => '历史上的今天',
  6228. 'list' => $historyTodayList,
  6229. 'type' => 1
  6230. ],
  6231. 'festivalList' => [
  6232. 'category_name' => '节日预告',
  6233. 'list' => $festivalList,
  6234. 'type' => 2
  6235. ],
  6236. 'chartacterList' => [
  6237. 'category_name' => '说文解字',
  6238. 'list' => $chartacterList,
  6239. 'type' => 3
  6240. ],
  6241. 'coupletList' => [
  6242. 'category_name' => '名联赏析',
  6243. 'list' => $coupletList,
  6244. 'type' => 6
  6245. ],
  6246. 'riddletList' => [
  6247. 'category_name' => '谜语沙龙',
  6248. 'list' => $riddletList,
  6249. 'type' => 4
  6250. ],
  6251. 'idiomList' => [
  6252. 'category_name' => '成语欣赏',
  6253. 'list' => $idiomList,
  6254. 'type' => 5
  6255. ],
  6256. 'articlesList' => $articlesList
  6257. ];
  6258. // 缓存结果,设置1小时过期
  6259. $cache->set($cacheKey, serialize($result), 3600);
  6260. return Result::success($result);
  6261. }
  6262. /**
  6263. * 获取资讯列表
  6264. */
  6265. public function getWebsiteTsbbList(array $data): array
  6266. {
  6267. $page = $data['page'] ?? 1;
  6268. $pageSize = $data['pageSize'] ?? 10;
  6269. // 如果没有传入月份和日期,则使用今天的日期
  6270. $month = $data['month'] ?? date('m');
  6271. $day = $data['day'] ?? date('d');
  6272. $total = 0;
  6273. $result = [];
  6274. $data['type'] = intval($data['type']);
  6275. var_dump("接收参数:", $data);
  6276. switch ($data['type']) {
  6277. case 1:
  6278. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6279. // 当前月份之后的数据
  6280. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6281. // 或者当前月份且日期大于等于当前日期的数据
  6282. ->orWhere(function ($q) use ($month, $day) {
  6283. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6284. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6285. });
  6286. })
  6287. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6288. $total = $query->count();
  6289. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6290. ->offset(($page - 1) * $pageSize)
  6291. ->limit($pageSize)
  6292. ->get();
  6293. break;
  6294. case 2:
  6295. $query = Festival::where(function ($q) use ($month, $day) {
  6296. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6297. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6298. ->orWhere(function ($q) use ($month, $day) {
  6299. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6300. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6301. });
  6302. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6303. $total = $query->count();
  6304. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6305. ->offset(($page - 1) * $pageSize)
  6306. ->limit($pageSize)
  6307. ->get();
  6308. break;
  6309. case 3:
  6310. $query = Character::orderBy("updated_at", "desc");
  6311. $total = $query->count();
  6312. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6313. ->offset(($page - 1) * $pageSize)
  6314. ->limit($pageSize)
  6315. ->get();
  6316. break;
  6317. case 4:
  6318. $query = Riddle::orderBy("updated_at", "desc");
  6319. $total = $query->count();
  6320. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6321. ->offset(($page - 1) * $pageSize)
  6322. ->limit($pageSize)
  6323. ->get();
  6324. break;
  6325. case 5:
  6326. $query = Idiom::orderBy("updated_at", "desc");
  6327. $total = $query->count();
  6328. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6329. ->offset(($page - 1) * $pageSize)
  6330. ->limit($pageSize)
  6331. ->get();
  6332. break;
  6333. case 6:
  6334. $query = Couplet::orderBy("updated_at", "desc");
  6335. $total = $query->count();
  6336. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6337. ->offset(($page - 1) * $pageSize)
  6338. ->limit($pageSize)
  6339. ->get();
  6340. break;
  6341. default:
  6342. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6343. $total = $query->count();
  6344. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6345. ->offset(($page - 1) * $pageSize)
  6346. ->limit($pageSize)
  6347. ->get();
  6348. }
  6349. return Result::success([
  6350. 'list' => $result,
  6351. 'total' => $total,
  6352. 'page' => (int)$page,
  6353. 'pageSize' => (int)$pageSize,
  6354. 'month' => $month,
  6355. 'day' => $day
  6356. ]);
  6357. }
  6358. /**
  6359. * 1:历史上的今天
  6360. * 2:节日
  6361. * 3:文章
  6362. *
  6363. * 资讯详情信息
  6364. */
  6365. public function getWebsiteTsbbDetail(array $data): array
  6366. {
  6367. $data['type'] = intval($data['type']);
  6368. switch ($data['type']) {
  6369. case 1:
  6370. $result = HistoryToday::where("id", $data['id'])->first();
  6371. break;
  6372. case 2:
  6373. $result = Festival::where("id", $data['id'])->first();
  6374. break;
  6375. case 3:
  6376. $result = Character::where("id", $data['id'])->first();
  6377. break;
  6378. case 4:
  6379. $result = Riddle::where("id", $data['id'])->first();
  6380. break;
  6381. case 5:
  6382. $result = Idiom::where("id", $data['id'])->first();
  6383. break;
  6384. case 6:
  6385. $result = Couplet::where("id", $data['id'])->first();
  6386. break;
  6387. default:
  6388. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6389. break;
  6390. }
  6391. return Result::success($result);
  6392. }
  6393. /**
  6394. * 农网导航首页数据
  6395. */
  6396. public function getWebsiteNwHomeList(array $data): array
  6397. {
  6398. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6399. ->pluck('category_id')
  6400. ->toArray();
  6401. // 使用子查询优化
  6402. $articlesList = DB::table('article')
  6403. ->select([
  6404. 'article.id',
  6405. 'article.title',
  6406. 'article.imgurl',
  6407. 'article.created_at',
  6408. 'category.name as category_name',
  6409. 'category.id as category_id',
  6410. 'website_category.aLIas_pinyin as pinyin',
  6411. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6412. DB::raw('100 as type')
  6413. ])
  6414. ->join('category', 'article.catid', '=', 'category.id')
  6415. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6416. ->leftJoin('website_category as parent_wc', function ($join) {
  6417. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6418. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6419. })
  6420. ->where('website_category.website_id', $data['website_id'])
  6421. ->where('article.status', 1)
  6422. ->whereIn('category.id', $categoryIds)
  6423. ->orderBy('article.created_at', 'desc')
  6424. ->get()
  6425. ->groupBy('category_id')
  6426. ->map(function ($group) {
  6427. // 确保第一条数据有图片
  6428. $firstWithImage = $group->first(function ($item) {
  6429. return !empty($item->imgurl);
  6430. });
  6431. if ($firstWithImage) {
  6432. // 如果有带图片的文章,将其放在第一位
  6433. $group = $group->filter(function ($item) use ($firstWithImage) {
  6434. return $item->id !== $firstWithImage->id;
  6435. })->prepend($firstWithImage);
  6436. }
  6437. return [
  6438. 'category_name' => $group->first()->category_name,
  6439. 'catid' => $group->first()->category_id,
  6440. 'pinyin' => $group->first()->pinyin,
  6441. 'parent_pinyin' => $group->first()->parent_pinyin,
  6442. 'list' => $group->take(4)->map(function ($item) {
  6443. return [
  6444. 'id' => $item->id,
  6445. 'title' => $item->title,
  6446. ];
  6447. })->values()
  6448. ];
  6449. })
  6450. ->values()
  6451. ->toArray();
  6452. return Result::success($articlesList);
  6453. }
  6454. /**
  6455. * 企业管理
  6456. * @param array $data
  6457. * @return array
  6458. */
  6459. public function getCompanyList(array $data): array
  6460. {
  6461. // return Result::success($data);
  6462. $where = [];
  6463. $user = User::where('id', $data['user_id'])->first();
  6464. if (empty($user)) {
  6465. return Result::error('用户不存在!');
  6466. }
  6467. if ($user['type_id'] != 10000) {
  6468. $where['user_id'] = $data['user_id'];
  6469. }
  6470. if (isset($data['title']) && !empty($data['title'])) {
  6471. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6472. }
  6473. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6474. array_push($where, ['website.id', $data['website_id']]);
  6475. }
  6476. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6477. if ($data['ischeck'] == 1) {
  6478. if (isset($data['status']) && $data['status'] != '') {
  6479. array_push($where, ['company.status', $data['status']]);
  6480. $query = Company::where($where);
  6481. } else {
  6482. $query = Company::whereIn('company.status', [0, 2]);
  6483. }
  6484. } else {
  6485. $query = Company::where('company.status', 1);
  6486. }
  6487. }
  6488. $result = $query->where($where)
  6489. ->leftJoin('website_category', function ($query) {
  6490. $query->on('website_category.category_id', '=', 'company.category_id')
  6491. ->on('website_category.website_id', '=', 'company.website_id');
  6492. })
  6493. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6494. ->select(
  6495. 'company.id',
  6496. 'company.title',
  6497. 'company.website_id',
  6498. 'company.category_id',
  6499. 'website.website_name',
  6500. 'website_category.alias as category_name',
  6501. 'company.status',
  6502. 'company.updated_at',
  6503. 'company.user_id'
  6504. )
  6505. ->orderBy('company.updated_at', 'desc')
  6506. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6507. if ($result->isEmpty()) {
  6508. return Result::error("暂无企业", 0);
  6509. }
  6510. return Result::success($result);
  6511. }
  6512. /**
  6513. * 添加企业
  6514. * @param array $data
  6515. * @return array
  6516. */
  6517. public function addCompany(array $data): array
  6518. {
  6519. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6520. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6521. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6522. $data['cat_arr_id'] = json_encode($car_arr_id);
  6523. } else {
  6524. $data['cat_arr_id'] = '';
  6525. }
  6526. if ($data['imgurl'] == '') {
  6527. //content中提取图片第一个图,正则提取
  6528. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6529. preg_match_all($reg, $data['content'], $matches);
  6530. if (isset($matches[1][0])) {
  6531. //截取varchar240
  6532. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6533. }
  6534. }
  6535. if ($data['keyword'] == '') {
  6536. //提取标题+内容中的关键词
  6537. $data['keyword'] = $data['title'];
  6538. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6539. Jieba::init(); // 初始化 jieba-php
  6540. Finalseg::init();
  6541. $segList = Jieba::cut($data['keyword']);
  6542. $segList1 = array_slice($segList, 0, 8);
  6543. $data['keyword'] = implode(',', $segList1);
  6544. }
  6545. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6546. //提取内容中的描述
  6547. $content = $data['content'];
  6548. // 去除 <style> 和 <script> 标签及其内容
  6549. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6550. // 去除所有 HTML 标签
  6551. $content = strip_tags($content);
  6552. // 去除 HTML 实体
  6553. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6554. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6555. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6556. // 去除多余空白
  6557. $content = preg_replace('/\s+/u', '', $content);
  6558. // 截取 100 个字符
  6559. $data['introduce'] = mb_substr($content, 0, 100);
  6560. }
  6561. $user = User::where('id', $data['user_id'])->first();
  6562. if (empty($user)) {
  6563. return Result::error('用户不存在!');
  6564. }
  6565. if ($user['type_id'] == 10000) {
  6566. $data['status'] = 1;
  6567. }
  6568. if (isset($data['level']) && $data['level'] != null) {
  6569. $data['level'] = intval($data['level']);
  6570. } else {
  6571. $data['level'] = null;
  6572. }
  6573. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6574. $this->sendMessage([
  6575. 'talk_type' => 900,
  6576. 'title' => $data['title'],
  6577. 'content' => '提交了审核',
  6578. 'messageType' => 8,
  6579. ]);
  6580. }
  6581. $result = Company::insertGetId($data);
  6582. if ($result) {
  6583. return Result::success($result);
  6584. } else {
  6585. return Result::error('添加失败');
  6586. }
  6587. }
  6588. /**
  6589. * 更新企业
  6590. * @param array $data
  6591. * @return array
  6592. */
  6593. public function upCompany(array $data): array
  6594. {
  6595. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6596. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6597. $data['cat_arr_id'] = json_encode($car_arr_id);
  6598. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6599. } else {
  6600. $data['cat_arr_id'] = '';
  6601. }
  6602. if ($data['imgurl'] == '') {
  6603. //content中提取图片第一个图,正则提取
  6604. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6605. preg_match_all($reg, $data['content'], $matches);
  6606. if (isset($matches[1][0])) {
  6607. //截取varchar
  6608. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6609. }
  6610. }
  6611. if ($data['keyword'] == '') {
  6612. //提取标题+内容中的关键词
  6613. $data['keyword'] = $data['title'];
  6614. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6615. Jieba::init(); // 初始化 jieba-php
  6616. Finalseg::init();
  6617. $segList = Jieba::cut($data['keyword']);
  6618. $segList1 = array_slice($segList, 0, 8);
  6619. $data['keyword'] = implode(',', $segList1);
  6620. }
  6621. if ($data['introduce'] == '') {
  6622. //提取内容中的描述
  6623. $content = $data['content'];
  6624. // 去除 <style> 和 <script> 标签及其内容
  6625. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6626. // 去除所有 HTML 标签
  6627. $content = strip_tags($content);
  6628. // 去除 HTML 实体
  6629. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6630. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6631. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6632. // 去除多余空白
  6633. $content = preg_replace('/\s+/u', '', $content);
  6634. // 截取 100 个字符
  6635. $data['introduce'] = mb_substr($content, 0, 100);
  6636. }
  6637. if (isset($data['level']) && $data['level'] != null) {
  6638. $data['level'] = intval($data['level']);
  6639. } else {
  6640. $data['level'] = null;
  6641. }
  6642. $user = User::where('id', $data['user_id'])->first();
  6643. if (empty($user)) {
  6644. return Result::error('用户不存在!');
  6645. }
  6646. if ($user['type_id'] == 10000) {
  6647. $data['status'] = 1;
  6648. } else {
  6649. $data['status'] = 0;
  6650. }
  6651. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6652. $this->sendMessage([
  6653. 'talk_type' => 900,
  6654. 'title' => $data['title'],
  6655. 'content' => '提交了审核',
  6656. 'messageType' => 8,
  6657. ]);
  6658. }
  6659. $result = Company::where('id', $data['id'])->update($data);
  6660. if ($result) {
  6661. return Result::success($result);
  6662. } else {
  6663. return Result::error('修改失败');
  6664. }
  6665. }
  6666. /**
  6667. * 删除企业
  6668. * @param array $data
  6669. * @return array
  6670. */
  6671. public function delCompany(array $data): array
  6672. {
  6673. $result = Company::where('id', $data['id'])->delete();
  6674. if ($result) {
  6675. return Result::success($result);
  6676. } else {
  6677. return Result::error('删除失败');
  6678. }
  6679. }
  6680. /**
  6681. * 审核企业
  6682. * @param array $data
  6683. * @return array
  6684. */
  6685. public function checkCompany(array $data): array
  6686. {
  6687. $user = User::where('id', $data['user_id'])->first();
  6688. if (empty($user)) {
  6689. return Result::error('用户不存在!');
  6690. }
  6691. $company = Company::where('id', $data['id'])->first();
  6692. if (empty($company)) {
  6693. return Result::error('企业不存在!');
  6694. }
  6695. // 状态:0:未审核 1:已审核 2:已拒绝
  6696. if ($data['status'] == 2 || $data['status'] == '2') {
  6697. $this->sendMessage([
  6698. 'talk_type' => 901,
  6699. 'title' => $company['title'],
  6700. 'content' => '审核拒绝',
  6701. 'messageType' => 8,
  6702. 'user_id' => $company['user_id'],
  6703. ]);
  6704. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6705. } else {
  6706. if ($data['status'] == 1) {
  6707. $this->sendMessage([
  6708. 'talk_type' => 901,
  6709. 'title' => $company['title'],
  6710. 'content' => '审核通过',
  6711. 'messageType' => 8,
  6712. 'user_id' => $company['user_id'],
  6713. ]);
  6714. } else if ($data['status'] == 0) {
  6715. $this->sendMessage([
  6716. 'talk_type' => 900,
  6717. 'title' => $company['title'],
  6718. 'content' => '提交了审核',
  6719. 'messageType' => 8,
  6720. ]);
  6721. }
  6722. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6723. }
  6724. if (empty($result)) {
  6725. return Result::error('审核失败!');
  6726. } else {
  6727. return Result::success($result);
  6728. }
  6729. }
  6730. /**
  6731. * 获取企业信息
  6732. * @param array $data
  6733. * @return array
  6734. */
  6735. public function getCompanyInfo(array $data): array
  6736. {
  6737. $result = Company::where('id', $data['id'])->first();
  6738. $city_arr = json_decode($result['city_arr_id']);
  6739. $result['city_name'] = District::whereIn('id', $city_arr)
  6740. ->pluck('name')
  6741. ->implode('-');
  6742. if (empty($result)) {
  6743. return Result::error('企业不存在!');
  6744. } else {
  6745. return Result::success($result);
  6746. }
  6747. }
  6748. /**
  6749. * @param array $data
  6750. * @return array
  6751. */
  6752. public function getWebsiteCompany(array $data): array
  6753. {
  6754. $categorys = json_decode($data['id'], true);
  6755. $category_arr = $this->processArticlePro($data['website_id']);
  6756. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6757. $catiall = $category_arr['catiall'];
  6758. $categoryIds = $category_arr['categoryIds'];
  6759. // return Result::success($category_arr);
  6760. foreach ($categorys as $key => $value) {
  6761. if (array_key_exists('level', $value)) {
  6762. $parts = explode(',', $value['level']);
  6763. $level = $parts[0] ?? null;
  6764. $imgnum = $parts[1] ?? null;
  6765. $textnum = $parts[2] ?? null;
  6766. if (!empty($textnum) && $textnum > 0) {
  6767. $text_num = Company::where('level', $level)
  6768. ->whereIn('category_id', $categoryIds)
  6769. ->where('status', 1)
  6770. ->select(
  6771. 'company.id',
  6772. 'company.title',
  6773. 'company.description',
  6774. 'company.updated_at',
  6775. 'company.category_id',
  6776. 'company.cat_arr_id'
  6777. )
  6778. ->orderBy('updated_at', 'desc')
  6779. ->limit($textnum)
  6780. ->get()->all();
  6781. }
  6782. if (!empty($imgnum) && $imgnum > 0) {
  6783. $img_num = Company::where('level', $level)
  6784. ->whereIn('category_id', $categoryIds)
  6785. ->where('status', 1)
  6786. ->where('imgurl', '!=', '')
  6787. ->whereNotNull('imgurl')
  6788. ->select(
  6789. 'company.id',
  6790. 'company.title',
  6791. 'company.description',
  6792. 'company.updated_at',
  6793. 'company.imgurl as imgs',
  6794. 'company.category_id',
  6795. 'company.cat_arr_id'
  6796. )
  6797. ->orderBy('updated_at', 'desc')
  6798. ->limit($imgnum)
  6799. ->get()->all();
  6800. }
  6801. }
  6802. if (array_key_exists('id', $value)) {
  6803. $parts = explode(',', $value['id']);
  6804. $category_id = $parts[0] ?? null;
  6805. $imgnum = $parts[1] ?? null;
  6806. $textnum = $parts[2] ?? null;
  6807. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6808. if (!empty($textnum) && $textnum > 0) {
  6809. $text_num = Company::whereIn('category_id', $category_arr)
  6810. // ->where('website_id', $data['website_id'])
  6811. ->where('status', 1)
  6812. ->select(
  6813. 'company.id',
  6814. 'company.title',
  6815. 'company.description',
  6816. 'company.updated_at',
  6817. 'company.category_id',
  6818. 'company.cat_arr_id'
  6819. )
  6820. ->orderBy('updated_at', 'desc')
  6821. ->limit($textnum)
  6822. ->get()->all();
  6823. }
  6824. if (!empty($imgnum) && $imgnum > 0) {
  6825. $img_num = Company::whereIn('category_id', $category_arr)
  6826. // ->where('website_id', $data['website_id'])
  6827. ->where('status', 1)
  6828. ->where('imgurl', '!=', '')
  6829. ->whereNotNull('imgurl')
  6830. ->select(
  6831. 'company.id',
  6832. 'company.title',
  6833. 'company.description',
  6834. 'company.updated_at',
  6835. 'company.imgurl as imgs',
  6836. 'company.category_id',
  6837. 'company.cat_arr_id'
  6838. )
  6839. ->orderBy('updated_at', 'desc')
  6840. ->limit($imgnum)
  6841. ->get()->all();
  6842. }
  6843. }
  6844. if (!empty($text_num)) {
  6845. foreach ($text_num as $k => $v) {
  6846. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6847. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6848. }
  6849. }
  6850. if (!empty($img_num)) {
  6851. foreach ($img_num as $k => $v) {
  6852. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6853. $imgurl = json_decode($v['imgs'], true);
  6854. if (!empty($imgurl)) {
  6855. $img_num[$k]->imgurl = $imgurl[0];
  6856. }
  6857. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6858. }
  6859. }
  6860. $company[$key]['img_num'] = $img_num ?? [];
  6861. $company[$key]['text_num'] = $text_num ?? [];
  6862. }
  6863. if (empty($company)) {
  6864. return Result::error("暂无相关企业信息", 0);
  6865. }
  6866. return Result::success($company);
  6867. }
  6868. /**
  6869. * @param array $data
  6870. * @return array
  6871. */
  6872. public function getWebsiteCompanyList(array $data): array
  6873. {
  6874. $where['website_id'] = $data['website_id'];
  6875. $where['status'] = 1;
  6876. $categoryIds = [];
  6877. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6878. $category_id = $data['category_id'];
  6879. }
  6880. $category_arr = $this->processArticlePro($data['website_id']);
  6881. $categoryIds = $category_arr['categoryIds'];
  6882. // return Result::success($cat_1st_arr);
  6883. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6884. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6885. })
  6886. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6887. $query->whereIn('category_id', $categoryIds);
  6888. })
  6889. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6890. $query->where('category_id', $category_id);
  6891. })
  6892. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6893. ->orderBy('updated_at', 'desc')
  6894. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6895. if (empty($company)) {
  6896. return Result::error("暂无相关公司信息", 0);
  6897. }
  6898. $result = [
  6899. 'count' => $company->total(),
  6900. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6901. ];
  6902. return Result::success($result);
  6903. }
  6904. /**
  6905. * 获取项目列表
  6906. * @param array $data
  6907. * @return array
  6908. */
  6909. public function getProjectList(array $data): array
  6910. {
  6911. $where = [];
  6912. $user = User::where('id', $data['user_id'])->first();
  6913. if (empty($user)) {
  6914. return Result::error('用户不存在!');
  6915. }
  6916. if ($user->type_id != 10000) {
  6917. array_push($where, ['project.user_id', $data['user_id']]);
  6918. }
  6919. $query = Project::query();
  6920. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6921. array_push($where, ['project.website_id', $data['website_id']]);
  6922. }
  6923. if (isset($data['title']) && !empty($data['title'])) {
  6924. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6925. }
  6926. if ($data['status'] != 3) {
  6927. array_push($where, ['project.status', $data['status']]);
  6928. }
  6929. $query = Project::where($where)
  6930. ->when($data['status'] == 3, function ($query) {
  6931. $query->whereIn('project.status', [0, 2]);
  6932. });
  6933. $count = $query->clone()
  6934. ->count();
  6935. $rows = $query->clone()
  6936. ->leftJoin('website', 'project.website_id', 'website.id')
  6937. ->leftJoin('website_category', function ($join) {
  6938. $join->on('project.website_id', '=', 'website_category.website_id')
  6939. ->on('project.category_id', '=', 'website_category.category_id');
  6940. })
  6941. ->select(
  6942. 'project.id',
  6943. 'project.title',
  6944. 'project.updated_at',
  6945. 'project.status',
  6946. 'website.website_name',
  6947. 'website_category.alias as category_name',
  6948. 'project.website_id',
  6949. 'project.user_id'
  6950. )
  6951. ->orderBy('project.updated_at', 'desc')
  6952. ->offset(($data['page'] - 1) * $data['pageSize'])
  6953. ->limit($data['pageSize'])
  6954. ->get();
  6955. if ($rows->isEmpty()) {
  6956. return Result::error("暂无相关项目信息", 0);
  6957. }
  6958. $result = [
  6959. 'count' => $count,
  6960. 'rows' => $rows,
  6961. ];
  6962. return Result::success($result);
  6963. }
  6964. /**
  6965. * 添加项目
  6966. * @param array $data
  6967. * @return array
  6968. */
  6969. public function addProject(array $data): array
  6970. {
  6971. $user = User::where('id', $data['user_id'])->first();
  6972. if (empty($user)) {
  6973. return Result::error("暂无相关用户信息", 0);
  6974. }
  6975. if ($user->type_id == 10000) {
  6976. $data['status'] = 1;
  6977. } else {
  6978. $data['status'] = 0;
  6979. }
  6980. if ($data['keyword'] == '') {
  6981. //提取标题+内容中的关键词
  6982. $data['keyword'] = $data['title'];
  6983. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6984. Jieba::init(); // 初始化 jieba-php
  6985. Finalseg::init();
  6986. $segList = Jieba::cut($data['keyword']);
  6987. $segList1 = array_slice($segList, 0, 8);
  6988. $data['keyword'] = implode(',', $segList1);
  6989. }
  6990. if ($data['description'] == '') {
  6991. //提取内容中的描述
  6992. // var_dump(11111);
  6993. //提取内容中的描述
  6994. $content = $data['introduce'];
  6995. // 去除 <style> 和 <script> 标签及其内容
  6996. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6997. // 去除所有 HTML 标签
  6998. $content = strip_tags($content);
  6999. // 去除 HTML 实体
  7000. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7001. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7002. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7003. // 去除多余空白
  7004. $content = preg_replace('/\s+/u', '', $content);
  7005. // 截取 100 个字符
  7006. $data['description'] = mb_substr($content, 0, 100);
  7007. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7008. }
  7009. if ($data['status'] == 0) {
  7010. $this->sendMessage([
  7011. 'talk_type' => 1000,
  7012. 'title' => $data['title'],
  7013. 'content' => '提交了审核',
  7014. 'messageType' => 9,
  7015. ]);
  7016. }
  7017. $project = Project::insertGetId($data);
  7018. if (empty($project)) {
  7019. return Result::error("暂无相关项目信息", 0);
  7020. }
  7021. return Result::success($project);
  7022. }
  7023. /**
  7024. * 更新项目
  7025. * @param array $data
  7026. * @return array
  7027. */
  7028. public function upProject(array $data): array
  7029. {
  7030. $project = Project::where('id', $data['id'])->first();
  7031. if (empty($project)) {
  7032. return Result::error("暂无相关项目信息", 0);
  7033. }
  7034. $id = $data['id'];
  7035. unset($data['id']);
  7036. $user = User::where('id', $data['user_id'])->first();
  7037. if (empty($user)) {
  7038. return Result::error("暂无相关用户信息", 0);
  7039. }
  7040. if ($user->type_id == 10000) {
  7041. $data['status'] = 1;
  7042. } else {
  7043. $data['status'] = 0;
  7044. }
  7045. unset($data['user_id']);
  7046. if ($data['keyword'] == '') {
  7047. //提取标题+内容中的关键词
  7048. $data['keyword'] = $data['title'];
  7049. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7050. Jieba::init(); // 初始化 jieba-php
  7051. Finalseg::init();
  7052. $segList = Jieba::cut($data['keyword']);
  7053. $segList1 = array_slice($segList, 0, 8);
  7054. $data['keyword'] = implode(',', $segList1);
  7055. }
  7056. if ($data['description'] == '') {
  7057. //提取内容中的描述
  7058. // var_dump(11111);
  7059. //提取内容中的描述
  7060. $content = $data['introduce'];
  7061. // 去除 <style> 和 <script> 标签及其内容
  7062. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7063. // 去除所有 HTML 标签
  7064. $content = strip_tags($content);
  7065. // 去除 HTML 实体
  7066. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7067. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7068. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7069. // 去除多余空白
  7070. $content = preg_replace('/\s+/u', '', $content);
  7071. // 截取 100 个字符
  7072. $data['description'] = mb_substr($content, 0, 100);
  7073. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7074. }
  7075. if ($data['status'] == 0) {
  7076. $this->sendMessage([
  7077. 'talk_type' => 1000,
  7078. 'title' => $data['title'],
  7079. 'content' => '提交了审核',
  7080. 'messageType' => 9,
  7081. ]);
  7082. }
  7083. $result = Project::where('id', $id)->update($data);
  7084. if (empty($result)) {
  7085. return Result::error("更新失败", 0);
  7086. }
  7087. return Result::success($result);
  7088. }
  7089. /**
  7090. * 删除项目
  7091. * @param array $data
  7092. * @return array
  7093. */
  7094. public function delProject(array $data): array
  7095. {
  7096. $user = User::where('id', $data['user_id'])->first();
  7097. if (empty($user)) {
  7098. return Result::error("暂无相关用户信息", 0);
  7099. }
  7100. $project = Project::where('id', $data['id'])->first();
  7101. if (empty($project)) {
  7102. return Result::error("暂无相关项目信息", 0);
  7103. }
  7104. $result = Project::where('id', $data['id'])->delete();
  7105. if (empty($result)) {
  7106. return Result::error("删除失败", 0);
  7107. }
  7108. return Result::success($result);
  7109. }
  7110. /**
  7111. * 审核项目
  7112. * @param array $data
  7113. * @return array
  7114. */
  7115. public function checkProject(array $data): array
  7116. {
  7117. $user = User::where('id', $data['user_id'])->first();
  7118. if (empty($user)) {
  7119. return Result::error("暂无相关用户信息", 0);
  7120. }
  7121. // 0:未审核; 1:已审核; 2:已拒绝;
  7122. if ($user->type_id != 10000) {
  7123. if ($data['status'] == 1 || $data['status'] == 2) {
  7124. return Result::error("此用户权限不足", 0);
  7125. }
  7126. }
  7127. $project = Project::where('id', $data['id'])->first();
  7128. if (empty($project)) {
  7129. return Result::error("暂无相关项目信息", 0);
  7130. }
  7131. if ($data['status'] == 2) {
  7132. $this->sendMessage([
  7133. 'talk_type' => 1001,
  7134. 'title' => $project['title'],
  7135. 'content' => '审核拒绝',
  7136. 'messageType' => 9,
  7137. 'user_id' => $project['user_id'],
  7138. ]);
  7139. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7140. } else {
  7141. if ($data['status'] == 1) {
  7142. $this->sendMessage([
  7143. 'talk_type' => 1001,
  7144. 'title' => $project['title'],
  7145. 'content' => '审核通过',
  7146. 'messageType' => 9,
  7147. 'user_id' => $project['user_id'],
  7148. ]);
  7149. } else if ($data['status'] == 0) {
  7150. $this->sendMessage([
  7151. 'talk_type' => 1000,
  7152. 'title' => $project['title'],
  7153. 'content' => '提交了审核',
  7154. 'messageType' => 9,
  7155. ]);
  7156. }
  7157. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7158. }
  7159. if (empty($result)) {
  7160. return Result::error("审核失败", 0);
  7161. }
  7162. return Result::success($result);
  7163. }
  7164. /**
  7165. * 获取项目详情
  7166. * @param array $data
  7167. * @return array
  7168. */
  7169. public function getProjectInfo(array $data): array
  7170. {
  7171. $project = Project::where('id', $data['id'])->first();
  7172. if (empty($project)) {
  7173. return Result::error("暂无相关项目信息", 0);
  7174. }
  7175. return Result::success($project);
  7176. }
  7177. public function getWebsiteCompanyInfo(array $data): array
  7178. {
  7179. $company = Company::where('id', $data['id'])
  7180. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7181. ->where('status', 1)
  7182. // ->where('website_id', $data['website_id'])
  7183. ->select('company.*', 'job_industry.hyname as hy_name')
  7184. ->first();
  7185. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7186. switch ($company->jobnature_id) {
  7187. case null:
  7188. $company->jobnature_name = '';
  7189. break;
  7190. case 0:
  7191. $company->jobnature_name = '市场监督';
  7192. break;
  7193. case 1:
  7194. $company->jobnature_name = '信访纪检';
  7195. break;
  7196. case 2:
  7197. $company->jobnature_name = '公检法司';
  7198. break;
  7199. case 3:
  7200. $company->jobnature_name = '高关注机构';
  7201. break;
  7202. default:
  7203. $company->jobnature_name = '';
  7204. break;
  7205. }
  7206. $city_arr = $company->city_arr_id;
  7207. if (!empty($city_arr)) {
  7208. $city_arr = json_decode($city_arr, true);
  7209. $cityNames = District::whereIn('id', $city_arr)
  7210. ->pluck('name')
  7211. ->implode('-');
  7212. $company->city_name = $cityNames;
  7213. } else {
  7214. $company->city_name = '';
  7215. }
  7216. if (empty($company)) {
  7217. return Result::error("暂无相关公司信息", 0);
  7218. }
  7219. return Result::success($company);
  7220. }
  7221. public function getMSG(array $data): array
  7222. {
  7223. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7224. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7225. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7226. $result = [];
  7227. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7228. //最近的5篇已审的文章
  7229. $apply_articale = Article::where('status', 1)
  7230. ->where('admin_user_id', $user_id)
  7231. ->orderBy('updated_at', 'desc')
  7232. // ->limit(5)
  7233. ->get();
  7234. //获取5条用户的已审核商品
  7235. $good = Good::where('status', 2)
  7236. ->where('user_id', $user_id)
  7237. ->orderBy('updated_at', 'desc')
  7238. // ->limit(5)
  7239. ->get();
  7240. //获取5条用户待审核的公告
  7241. $notice = Notice::where('status', 2)
  7242. ->where('user_id', $user_id)
  7243. ->orderBy('updated_at', 'desc')
  7244. ->limit(5)->get();
  7245. //获取5条用户的待审核投诉
  7246. $complaint = Complaint::where('status', 2)
  7247. ->where('user_id', $user_id)
  7248. ->orderBy('updated_at', 'desc')
  7249. // ->limit(5)
  7250. ->get();
  7251. //获取5条用户的book
  7252. $book = Book::where('status', 2)
  7253. ->where('user_id', $user_id)
  7254. ->orderBy('updated_at', 'desc')
  7255. // ->limit(5)
  7256. ->get();
  7257. //获取5条用户的求职
  7258. //获取5条用户的求职 1
  7259. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7260. ->where('job_hunting.user_id', $user_id)
  7261. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7262. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7263. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7264. ->orderBy('updated_at', 'desc')
  7265. // ->limit(5)
  7266. ->get();
  7267. //获取5条用户的求职 2
  7268. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7269. ->where('job_recruiting.user_id', $user_id)
  7270. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7271. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7272. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7273. ->orderBy('updated_at', 'desc')
  7274. // ->limit(5)
  7275. ->get();
  7276. //人才库 1
  7277. $job_apply = JobApply::where('job_apply.status', 1)
  7278. ->where('job_apply.receiver_id', $user_id)
  7279. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7280. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7281. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7282. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7283. ->select('job_recruiting', 'job_recruiting.', '', '')
  7284. ->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')
  7285. ->orderBy('updated_at', 'desc')
  7286. // ->limit(5)
  7287. ->get();
  7288. // 职场机会 2
  7289. $job_resume = JobResume::where('job_resume.status', 1)
  7290. ->where('job_resume.receiver_id', $user_id)
  7291. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7292. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7293. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7294. ->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')
  7295. ->orderBy('updated_at', 'desc')
  7296. // ->limit(5)
  7297. ->get();
  7298. //获取5条用户待处理的投诉
  7299. $complaint_deal = Complaint::where('status', 2)
  7300. ->where('deal', 1)
  7301. ->whereJsonContains('re_user_ids', $user_id)
  7302. ->orderBy('updated_at', 'desc')
  7303. // ->limit(5)
  7304. ->get();
  7305. //获取 被通知者未读信息
  7306. $notice_unread = Notice::where('status', 2)
  7307. ->whereJsonContains('re_user_ids', $user_id)
  7308. //未读消息
  7309. ->where(function ($query) use ($user_id) {
  7310. $query->whereJsonDoesntContain('read_id', $user_id)
  7311. ->orWhereNull('read_id');
  7312. })
  7313. ->orderBy('updated_at', 'desc')
  7314. ->get();
  7315. $complaint_unread = Complaint::where('status', 2)
  7316. ->whereJsonContains('re_user_ids', $user_id)
  7317. //未读消息
  7318. ->where(function ($query) use ($user_id) {
  7319. $query->whereJsonDoesntContain('read_id', $user_id)
  7320. ->orWhereNull('read_id');
  7321. })
  7322. ->orderBy('updated_at', 'desc')
  7323. ->get();
  7324. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7325. $complany = Company::where('status', 1)
  7326. ->where('user_id', $user_id)
  7327. ->orderBy('updated_at', 'desc')
  7328. // ->limit(5)
  7329. ->get();
  7330. //获取5条单聊未读聊天消息
  7331. // $chat = ChatRecords::where('is_read', 0)
  7332. // ->where('user_id', $user_id)
  7333. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7334. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7335. // ->where('action', 'recieved')
  7336. // ->where('talk_type', 1)
  7337. // ->orderBy('created_at', 'desc')
  7338. // // ->limit(5)
  7339. // ->get();
  7340. //获取5条未读群聊信息
  7341. // $chat_group = ChatRecords::where('is_read', 0)
  7342. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7343. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7344. // ->where('user_id', $user_id)
  7345. // ->where('talk_type', 2)
  7346. // ->orderBy('created_at', 'desc')
  7347. // // ->limit(5)
  7348. // ->get();
  7349. //获取5条用户的待审核项目
  7350. $project = Project::where('status', 1)
  7351. ->where('user_id', $user_id)
  7352. ->orderBy('updated_at', 'desc')
  7353. // ->limit(5)
  7354. ->get();
  7355. // count($chat) + count($chat_group) +
  7356. $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)
  7357. + count($complany)
  7358. + count($project)
  7359. + count($notice_unread)
  7360. + count($complaint_unread)
  7361. // + count($chat) + count($chat_group)
  7362. ;
  7363. $result = [
  7364. 'apply_articale' => $apply_articale,
  7365. // 'chat' => $chat,
  7366. // 'chat_group' => $chat_group,
  7367. 'good' => $good,
  7368. 'notice' => $notice,
  7369. 'complaint' => $complaint,
  7370. 'book' => $book,
  7371. 'job_hunting' => $job_hunting,
  7372. 'job_recruiting' => $job_recruiting,
  7373. 'job_apply' => $job_apply,
  7374. 'job_resume' => $job_resume,
  7375. 'complaint_deal' => $complaint_deal,
  7376. 'complany' => $complany,
  7377. 'project' => $project,
  7378. 'notice_unread' => $notice_unread,
  7379. 'complaint_unread' => $complaint_unread,
  7380. 'count' => $count,
  7381. ];
  7382. } elseif ($type_id == 12) {
  7383. //最近的5篇已审的文章
  7384. $apply_articale = Article::where('status', 1)
  7385. ->where('admin_user_id', $user_id)
  7386. ->limit(5)->get();
  7387. //获取5条单聊未读聊天消息
  7388. $chat = ChatRecords::where('is_read', 0)
  7389. ->where('user_id', $user_id)
  7390. ->where('talk_type', 1)
  7391. ->orderBy('created_at', 'desc')
  7392. ->limit(5)->get();
  7393. //获取5条未读群聊信息
  7394. $chat_group = ChatRecords::where('is_read', 0)
  7395. ->where('user_id', $user_id)
  7396. ->where('talk_type', 2)
  7397. ->orderBy('created_at', 'desc')
  7398. ->limit(5)->get();
  7399. //获取5条用户的已审核商品
  7400. $good = Good::where('status', 2)
  7401. ->where('user_id', $user_id)
  7402. ->orderBy('updated_at', 'desc')
  7403. ->limit(5)->get();
  7404. //获取5条用户的book
  7405. $book = Book::where('status', 2)
  7406. ->where('user_id', $user_id)
  7407. ->orderBy('updated_at', 'desc')
  7408. ->limit(5)->get();
  7409. //获取5条用户的求职
  7410. //获取5条用户的求职 1
  7411. //count($chat) + count($chat_group)
  7412. $count = count($apply_articale) + count($good);
  7413. $result = [
  7414. 'apply_articale' => $apply_articale,
  7415. 'chat' => $chat,
  7416. 'chat_group' => $chat_group,
  7417. 'good' => $good,
  7418. 'book' => $book,
  7419. 'count' => $count,
  7420. ];
  7421. } elseif ($type_id == 13) {
  7422. //最近的5篇已审的文章
  7423. $apply_articale = Article::where('status', 1)
  7424. ->where('admin_user_id', $user_id)
  7425. ->limit(5)->get();
  7426. //获取5条单聊未读聊天消息
  7427. $chat = ChatRecords::where('is_read', 0)
  7428. ->where('user_id', $user_id)
  7429. ->where('talk_type', 1)
  7430. ->orderBy('created_at', 'desc')
  7431. ->limit(5)->get();
  7432. //获取5条未读群聊信息
  7433. $chat_group = ChatRecords::where('is_read', 0)
  7434. ->where('user_id', $user_id)
  7435. ->where('talk_type', 2)
  7436. ->orderBy('created_at', 'desc')
  7437. ->limit(5)->get();
  7438. //获取5条用户的已审核商品
  7439. $good = Good::where('status', 2)
  7440. ->where('user_id', $user_id)
  7441. ->orderBy('updated_at', 'desc')
  7442. ->limit(5)->get();
  7443. //count($chat) + count($chat_group) +
  7444. $count = count($apply_articale) + count($good);
  7445. $result = [
  7446. 'apply_articale' => $apply_articale,
  7447. 'chat' => $chat,
  7448. 'chat_group' => $chat_group,
  7449. 'good' => $good,
  7450. 'count' => $count,
  7451. ];
  7452. } elseif ($type_id == 14) {
  7453. //最近的5篇已审的文章
  7454. $apply_articale = Article::where('status', 1)
  7455. ->where('admin_user_id', $user_id)
  7456. // ->limit(5)
  7457. ->get();
  7458. //获取5条用户的已审核商品
  7459. $good = Good::where('status', 2)
  7460. ->where('user_id', $user_id)
  7461. ->orderBy('updated_at', 'desc')
  7462. // ->limit(5)
  7463. ->get();
  7464. $count = count($apply_articale) + count($good);
  7465. $result = [
  7466. 'apply_articale' => $apply_articale,
  7467. 'chat' => '',
  7468. 'chat_group' => '',
  7469. 'good' => $good,
  7470. 'count' => $count,
  7471. ];
  7472. } elseif ($type_id == 10000) {
  7473. //获取未审核的5篇文章
  7474. $apply_articale = Article::where('status', 0)
  7475. ->orderBy('updated_at', 'desc')
  7476. // ->limit(5)
  7477. ->get();
  7478. //获取5条单聊未读聊天消息
  7479. //获取5条单聊未读聊天消息
  7480. // $chat = ChatRecords::where('is_read', 0)
  7481. // ->where('user_id', $user_id)
  7482. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7483. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7484. // ->where('action', 'recieved')
  7485. // ->where('talk_type', 1)
  7486. // ->orderBy('created_at', 'desc')
  7487. // // ->limit(5)
  7488. // ->get();
  7489. // //获取5条未读群聊信息
  7490. // $chat_group = ChatRecords::where('is_read', 0)
  7491. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7492. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7493. // ->where('user_id', $user_id)
  7494. // ->where('talk_type', 2)
  7495. // ->orderBy('created_at', 'desc')
  7496. // // ->limit(5)
  7497. // ->get();
  7498. //获取5条用户的已审核商品
  7499. $good = Good::where('status', 1)
  7500. // ->where('user_id', $user_id)
  7501. ->orderBy('updated_at', 'desc')
  7502. // ->limit(5)
  7503. ->get();
  7504. //获取5条用户待审核的公告
  7505. $notice = Notice::where('status', 1)
  7506. ->orderBy('updated_at', 'desc')
  7507. // ->limit(5)
  7508. ->get();
  7509. //获取5条用户的待审核投诉
  7510. $complaint = Complaint::where('status', 1)
  7511. ->orderBy('updated_at', 'desc')
  7512. // ->limit(5)
  7513. ->get();
  7514. //获取5条用户的book
  7515. $book = Book::where('status', 1)
  7516. ->orderBy('updated_at', 'desc')
  7517. // ->limit(5)
  7518. ->get();
  7519. //获取5条用户的求职 1
  7520. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7521. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7522. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7523. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7524. ->orderBy('updated_at', 'desc')
  7525. // ->limit(5)
  7526. ->get();
  7527. //获取5条用户的求职 2
  7528. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7529. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7530. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7531. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7532. ->orderBy('updated_at', 'desc')
  7533. // ->limit(5)
  7534. ->get();
  7535. //人才库 1
  7536. $job_apply = JobApply::where('job_apply.status', 1)
  7537. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7538. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7539. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7540. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7541. ->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')
  7542. ->orderBy('updated_at', 'desc')
  7543. // ->limit(5)
  7544. ->get();
  7545. // 职场机会 2
  7546. $job_resume = JobResume::where('job_resume.status', 1)
  7547. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7548. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7549. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7550. ->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')
  7551. ->orderBy('updated_at', 'desc')
  7552. // ->limit(5)
  7553. ->get();
  7554. //待审核数据com pro
  7555. $complany = Company::where('status', 0)
  7556. ->orderBy('updated_at', 'desc')
  7557. // ->limit(5)
  7558. ->get();
  7559. $project = Project::where('status', 0)
  7560. ->orderBy('updated_at', 'desc')
  7561. // ->limit(5)
  7562. ->get();
  7563. $count =
  7564. // count($chat) +
  7565. // count($chat_group) +
  7566. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7567. // + count($job_apply)
  7568. // + count($job_resume)
  7569. + count($complany)
  7570. + count($project);
  7571. $result = [
  7572. 'apply_articale' => $apply_articale,
  7573. // 'chat' => $chat,
  7574. // 'chat_group' => $chat_group,
  7575. 'good' => $good,
  7576. 'notice' => $notice,
  7577. 'complaint' => $complaint,
  7578. 'book' => $book,
  7579. 'job_hunting' => $job_hunting,
  7580. 'job_recruiting' => $job_recruiting,
  7581. // 'job_apply' => $job_apply,
  7582. // 'job_resume' => $job_resume,
  7583. 'complany' => $complany,
  7584. 'project' => $project,
  7585. 'count' => $count,
  7586. ];
  7587. } elseif ($type_id == 20000) {
  7588. }
  7589. var_dump($type_id, '-----------------test---------');
  7590. return Result::success($result);
  7591. }
  7592. /**
  7593. * @param array $data
  7594. * @return array
  7595. */
  7596. public function getWebsiteProject(array $data): array
  7597. {
  7598. $categorys = json_decode($data['id'], true);
  7599. if (!empty($categorys)) {
  7600. $category_arr = $this->processArticlePro($data['website_id']);
  7601. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7602. $catiall = $category_arr['catiall'];
  7603. // return Result::success($catiall);
  7604. foreach ($categorys as $key => $val) {
  7605. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7606. $level = explode(',', $val['level'])[0];
  7607. $imgnum = explode(',', $val['level'])[1] ?? null;
  7608. $textnum = explode(',', $val['level'])[2] ?? null;
  7609. if ($level == 1) {
  7610. if (!empty($textnum) && $textnum > 0) {
  7611. $text_num = Project::where('level', $level)
  7612. ->where('website_id', $data['website_id'])
  7613. ->where('status', 1)
  7614. ->select(
  7615. 'project.id',
  7616. 'project.title',
  7617. 'project.description',
  7618. 'project.updated_at',
  7619. 'project.category_id',
  7620. 'project.cat_arr_id'
  7621. )
  7622. ->orderBy('updated_at', 'desc')
  7623. ->limit($textnum)
  7624. ->get()->all();
  7625. }
  7626. if (!empty($imgnum) && $imgnum > 0) {
  7627. $img_num = Project::where('level', $level)
  7628. ->where('website_id', $data['website_id'])
  7629. ->where('status', 1)
  7630. ->where('imgurl', '!=', '')
  7631. ->whereNotNull('imgurl')
  7632. ->select(
  7633. 'project.id',
  7634. 'project.title',
  7635. 'project.description',
  7636. 'project.updated_at',
  7637. 'project.imgurl as imgs',
  7638. 'project.category_id',
  7639. 'project.cat_arr_id'
  7640. )
  7641. ->orderBy('updated_at', 'desc')
  7642. ->limit($imgnum)
  7643. ->get()->all();
  7644. }
  7645. } else {
  7646. if (!empty($textnum) && $textnum > 0) {
  7647. $text_num = Project::where('website_id', $data['website_id'])
  7648. ->where('status', 1)
  7649. ->select(
  7650. 'project.id',
  7651. 'project.title',
  7652. 'project.description',
  7653. 'project.updated_at',
  7654. 'project.category_id',
  7655. 'project.cat_arr_id',
  7656. 'project.website_id',
  7657. 'project.updated_at',
  7658. 'project.created_at'
  7659. )
  7660. ->orderBy('updated_at', 'desc')
  7661. ->limit($textnum)
  7662. ->get()->all();
  7663. }
  7664. if (!empty($imgnum) && $imgnum > 0) {
  7665. $img_num = Project::where('website_id', $data['website_id'])
  7666. ->where('status', 1)
  7667. ->where('imgurl', '!=', '')
  7668. ->whereNotNull('imgurl')
  7669. ->select(
  7670. 'project.id',
  7671. 'project.title',
  7672. 'project.description',
  7673. 'project.updated_at',
  7674. 'project.imgurl as imgs',
  7675. 'project.category_id',
  7676. 'project.cat_arr_id'
  7677. )
  7678. ->orderBy('updated_at', 'desc')
  7679. ->limit($imgnum)
  7680. ->get()->all();
  7681. }
  7682. }
  7683. }
  7684. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7685. $category_ids = explode(',', $val['id'])[0];
  7686. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7687. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7688. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7689. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7690. $text_num = Project::whereIn('category_id', $category_arr)
  7691. ->where('website_id', $data['website_id'])
  7692. ->where('status', 1)
  7693. ->select(
  7694. 'project.id',
  7695. 'project.title',
  7696. 'project.description',
  7697. 'project.updated_at',
  7698. 'project.category_id',
  7699. 'project.cat_arr_id'
  7700. )
  7701. ->orderBy('updated_at', 'desc')
  7702. ->limit($cat_textnum)
  7703. ->get()->all();
  7704. }
  7705. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7706. $img_num = Project::whereIn('category_id', $category_arr)
  7707. ->where('website_id', $data['website_id'])
  7708. ->where('status', 1)
  7709. ->where('imgurl', '!=', '')
  7710. ->whereNotNull('imgurl')
  7711. ->select(
  7712. 'project.id',
  7713. 'project.title',
  7714. 'project.description',
  7715. 'project.updated_at',
  7716. 'project.imgurl as imgs',
  7717. 'project.category_id',
  7718. 'project.cat_arr_id'
  7719. )
  7720. ->orderBy('updated_at', 'desc')
  7721. ->limit($cat_imgnum)
  7722. ->get()->all();
  7723. }
  7724. }
  7725. if (!empty($img_num)) {
  7726. foreach ($img_num as $k => $v) {
  7727. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7728. $imgurl = json_decode($v['imgs'], true);
  7729. if (!empty($imgurl)) {
  7730. $img_num[$k]->imgurl = $imgurl[0];
  7731. }
  7732. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7733. }
  7734. }
  7735. if (!empty($text_num)) {
  7736. foreach ($text_num as $k => $v) {
  7737. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7738. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7739. }
  7740. }
  7741. $project[$key]['img_num'] = $img_num ?? [];
  7742. $project[$key]['text_num'] = $text_num ?? [];
  7743. }
  7744. }
  7745. if (empty($project)) {
  7746. return Result::error("暂无相关项目信息", 0);
  7747. }
  7748. return Result::success($project);
  7749. }
  7750. /**
  7751. * @param array $data
  7752. * @return array
  7753. */
  7754. public function getWebsiteProjectInfo(array $data): array
  7755. {
  7756. $project = Project::where('id', $data['id'])
  7757. ->where('status', 1)
  7758. ->where('website_id', $data['website_id'])
  7759. ->select('project.*')
  7760. ->first();
  7761. if (empty($project)) {
  7762. return Result::error("暂无相关项目信息", 0);
  7763. }
  7764. return Result::success($project);
  7765. }
  7766. /**
  7767. * @param array $data
  7768. * @return array
  7769. */
  7770. public function getWebsiteProjectList(array $data): array
  7771. {
  7772. $where = [];
  7773. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7774. $where['category_id'] = $data['category_id'];
  7775. }
  7776. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7777. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7778. }
  7779. $query = Project::where($where)
  7780. ->where('status', 1)
  7781. ->where('website_id', $data['website_id'])
  7782. ->select(
  7783. 'project.id',
  7784. 'project.title',
  7785. 'project.description',
  7786. 'project.imgurl as imgs',
  7787. 'project.category_id',
  7788. 'project.cat_arr_id'
  7789. )
  7790. ->orderBy('updated_at', 'desc');
  7791. $count = $query->count();
  7792. $project = $query->clone()
  7793. ->offset(($data['page'] - 1) * $data['pageSize'])
  7794. ->limit($data['pageSize'])
  7795. ->get()->all();
  7796. if (empty($project)) {
  7797. return Result::error("暂无相关项目信息", 0);
  7798. }
  7799. $categorys = $this->processArticlePro($data['website_id']);
  7800. $catiall = $categorys['catiall'];
  7801. foreach ($project as $key => $val) {
  7802. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7803. if (!empty($val['imgs'])) {
  7804. $imgurl = json_decode($val['imgs'], true);
  7805. if (!empty($imgurl)) {
  7806. $project[$key]->imgurl = $imgurl[0];
  7807. }
  7808. } else {
  7809. $project[$key]->imgurl = '';
  7810. }
  7811. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7812. }
  7813. $result = [
  7814. 'rows' => $project,
  7815. 'count' => $count,
  7816. ];
  7817. return Result::success($result);
  7818. }
  7819. /**
  7820. * @param array $data
  7821. * @return array
  7822. */
  7823. public function getWebsiteCategoryJob(array $data): array
  7824. {
  7825. $categorys = json_decode($data['id'], true);
  7826. if (!empty($categorys)) {
  7827. $category_arr = $this->processArticlePro($data['website_id']);
  7828. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7829. $catiall = $category_arr['catiall'];
  7830. foreach ($categorys as $key => $val) {
  7831. if (isset($val['id']) && !empty($val['id'])) {
  7832. $catid = explode(',', $val['id'])[0] ?? null;
  7833. $type = explode(',', $val['id'])[1] ?? null;
  7834. $textnum = explode(',', $val['id'])[2] ?? null;
  7835. }
  7836. // 4:招聘;5:求职;
  7837. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7838. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7839. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7840. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7841. ->where('job_recruiting.status', 1)
  7842. ->where('job_recruiting.website_id', $data['website_id'])
  7843. ->select(
  7844. 'job_recruiting.id',
  7845. 'job_recruiting.title',
  7846. 'job_company.business_name',
  7847. 'job_recruiting.updated_at',
  7848. 'job_recruiting.cat_arr_id',
  7849. 'job_recruiting.keyword',
  7850. 'job_recruiting.description'
  7851. )
  7852. ->orderBy('job_recruiting.updated_at', 'desc')
  7853. ->limit($textnum)
  7854. ->get()->all();
  7855. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7856. // 状态 审核状态,1待审核2已审核3已拒绝
  7857. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7858. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7859. ->where('job_hunting.status', 2)
  7860. ->where('job_hunting.website_id', $data['website_id'])
  7861. ->select(
  7862. 'job_hunting.id',
  7863. 'job_hunting.name',
  7864. 'job_hunting.cat_arr_id',
  7865. 'job_position.zwname as job_name',
  7866. 'job_hunting.updated_at',
  7867. 'job_hunting.keyword',
  7868. 'job_hunting.slelf_evaluation'
  7869. )
  7870. ->orderBy('updated_at', 'desc')
  7871. ->limit($textnum)
  7872. ->get()->all();
  7873. } else {
  7874. $job = [];
  7875. }
  7876. // var_dump($catid.'222uuuuuuu'.$key);
  7877. if (!empty($job)) {
  7878. foreach ($job as $k => $value) {
  7879. if (isset($value->cat_arr_id)) {
  7880. $catArr = json_decode($value->cat_arr_id, true);
  7881. $catId = end($catArr);
  7882. } else {
  7883. continue;
  7884. }
  7885. if (isset($catiall[$catId])) {
  7886. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7887. }
  7888. }
  7889. }
  7890. // var_dump($catid.'xxxxx'.$key);
  7891. $result[$key] = $job ?? [];
  7892. }
  7893. }
  7894. if (empty($result)) {
  7895. return Result::error("暂无相关分类信息", 0);
  7896. }
  7897. return Result::success($result);
  7898. }
  7899. /**
  7900. * 发送消息
  7901. * @param array $messageData
  7902. * @return void
  7903. */
  7904. public function sendMessage($messageData)
  7905. {
  7906. $msg = [
  7907. 'talk_type' => $messageData['talk_type'],
  7908. 'title' => $messageData['title'],
  7909. 'content' => $messageData['content'],
  7910. 'messageType' => $messageData['messageType'],
  7911. 'user_id' => $messageData['user_id'] ?? '',
  7912. 'time' => microtime(),
  7913. ];
  7914. $message = new MqProducer($msg);
  7915. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7916. $producer->produce($message);
  7917. }
  7918. }