NewsService.php 272 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  65. class NewsService implements NewsServiceInterface
  66. {
  67. #[Inject]
  68. protected Redis $redis;
  69. /**
  70. * 获取导航池列表
  71. * @param array $data
  72. * @return array
  73. */
  74. public function getCategoryList(array $data): array
  75. {
  76. $search = $data['name'] ?? '';
  77. $page = (int)($data['page'] ?? 1);
  78. $perPage = (int)($data['pageSize'] ?? 10);
  79. // 1. 查出所有匹配的分类id
  80. if ($search) {
  81. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  82. if (empty($matchedIds)) {
  83. return Result::success(['rows' => [], 'total' => 0]);
  84. }
  85. // 2. 递归查所有父级,直到一级分类
  86. $idsStr = implode(',', $matchedIds);
  87. $sql = "
  88. WITH RECURSIVE parents AS (
  89. SELECT * FROM category WHERE id IN ($idsStr)
  90. UNION ALL
  91. SELECT c.* FROM category c
  92. INNER JOIN parents p ON c.id = p.pid
  93. )
  94. SELECT * FROM parents
  95. ";
  96. $parents = Db::select($sql);
  97. $parentIds = [];
  98. foreach ($parents as $row) {
  99. if ($row->pid == 0) {
  100. $parentIds[] = $row->id;
  101. }
  102. }
  103. $parentIds = array_unique($parentIds);
  104. } else {
  105. // 没有搜索,一级分类就是根
  106. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  107. }
  108. // 3. 一级分类分页
  109. $total = count($parentIds);
  110. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  111. if (empty($parentIds)) {
  112. return Result::success(['rows' => [], 'total' => $total]);
  113. }
  114. // 4. 递归查所有子孙
  115. $idsStr = implode(',', $parentIds);
  116. $sql = "
  117. WITH RECURSIVE subcategories AS (
  118. SELECT * FROM category WHERE id IN ($idsStr)
  119. UNION ALL
  120. SELECT c.* FROM category c
  121. INNER JOIN subcategories s ON c.pid = s.id
  122. )
  123. SELECT * FROM subcategories ORDER BY updated_at DESC
  124. ";
  125. $allCategories = Db::select($sql);
  126. // 5. 组装树结构
  127. $categoryMap = [];
  128. foreach ($allCategories as $cat) {
  129. $cat = (array)$cat;
  130. $cat['children'] = [];
  131. $categoryMap[$cat['id']] = $cat;
  132. }
  133. foreach ($categoryMap as $id => &$cat) {
  134. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  135. $categoryMap[$cat['pid']]['children'][] = &$cat;
  136. }
  137. }
  138. unset($cat);
  139. $categoryTree = [];
  140. foreach ($parentIds as $id) {
  141. if (isset($categoryMap[$id])) {
  142. $categoryTree[] = $categoryMap[$id];
  143. }
  144. }
  145. return Result::success([
  146. 'rows' => $categoryTree,
  147. 'total' => $total,
  148. ]);
  149. }
  150. private function findMatchedCategories($search)
  151. {
  152. if ($search) {
  153. return Category::where('name', 'like', "%{$search}%")
  154. ->orderBy('updated_at', 'desc')
  155. ->get();
  156. }
  157. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  158. ->get();
  159. }
  160. private function findAllParents($categories)
  161. {
  162. $allCategories = [];
  163. foreach ($categories as $category) {
  164. $parentId = $category->pid;
  165. while ($parentId > 0) {
  166. $parent = Category::find($parentId);
  167. if ($parent) {
  168. $allCategories[$parent->id] = $parent;
  169. $parentId = $parent->pid;
  170. } else {
  171. break;
  172. }
  173. }
  174. $allCategories[$category->id] = $category;
  175. }
  176. return array_values($allCategories);
  177. }
  178. private function buildCategoryTree($category, $allRequiredCategories)
  179. {
  180. $categoryData = $category->toArray();
  181. $children = [];
  182. foreach ($allRequiredCategories as $c) {
  183. if ($c->pid === $category->id) {
  184. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  185. }
  186. }
  187. if (!empty($children)) {
  188. $categoryData['children'] = $children;
  189. }
  190. return $categoryData;
  191. }
  192. public function myCategoryList(array $data): array
  193. {
  194. $sszq = $data['sszq'] ?? '';
  195. unset($data['sszq']);
  196. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  197. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  198. $where[] = [
  199. 'pid',
  200. '=',
  201. $data['pid'],
  202. ];
  203. if (isset($data['name'])) {
  204. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  205. }
  206. var_dump($where);
  207. //根据分类id,从category表中取出分类信息
  208. $result = Category::where($where)
  209. ->whereIn('category.id', $catorytids)
  210. ->select('category.*', 'category.id as category_id')->get();
  211. if (empty($result)) {
  212. return Result::error("没有栏目数据");
  213. }
  214. return Result::success($result);
  215. }
  216. /**
  217. * @param array $data
  218. * @return array
  219. */
  220. public function categoryList(array $data): array
  221. {
  222. $where[] = [
  223. 'pid',
  224. '=',
  225. $data['pid']
  226. ];
  227. if (isset($data['name'])) {
  228. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  229. }
  230. var_dump($where);
  231. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  232. if (empty($result)) {
  233. return Result::error("没有栏目数据");
  234. }
  235. return Result::success($result);
  236. }
  237. /**
  238. * @param array $data
  239. * @return array
  240. */
  241. public function addCategory(array $data): array
  242. {
  243. if (isset($data['id'])) {
  244. unset($data['id']);
  245. }
  246. $id = Category::insertGetId($data);
  247. if (empty($id)) {
  248. return Result::error("添加失败");
  249. }
  250. return Result::success(['id' => $id]);
  251. }
  252. /**
  253. * @param array $data
  254. * @return array
  255. */
  256. public function delCategory(array $data): array
  257. {
  258. Db::beginTransaction();
  259. try {
  260. $categoryList = Category::where(['pid' => $data['id']])->get();
  261. if ($categoryList->toArray()) {
  262. Db::rollBack();
  263. return Result::error("分类下面有子分类不能删除");
  264. }
  265. $articleList = Article::where(['catid' => $data['id']])->get();
  266. if ($articleList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有资讯不能删除");
  269. }
  270. $result = Category::where($data)->delete();
  271. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  272. if (!$result) {
  273. Db::rollBack();
  274. return Result::error("删除失败");
  275. }
  276. Db::commit();
  277. return Result::success($result);
  278. } catch (\Exception $e) {
  279. Db::rollBack();
  280. return Result::error("删除失败" . $e->getMessage());
  281. }
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function updateCategory(array $data): array
  288. {
  289. $where = [
  290. 'id' => $data['id'],
  291. ];
  292. $result = Category::where($where)->update($data);
  293. if ($result) {
  294. return Result::success($result);
  295. } else {
  296. return Result::error("更新失败");
  297. }
  298. }
  299. /**
  300. * 获取导航池信息
  301. * @param array $data
  302. * @return array
  303. */
  304. public function getCategoryInfo(array $data): array
  305. {
  306. $where = [
  307. 'id' => $data['id'],
  308. ];
  309. $result = Category::where($where)->first();
  310. if ($result) {
  311. return Result::success($result);
  312. } else {
  313. return Result::error("更新失败");
  314. }
  315. }
  316. public function getArticleCommend(array $data): array
  317. {
  318. $where = [
  319. 'website_id' => $data['website_id'],
  320. ];
  321. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  322. var_dump($ids);
  323. if (empty($ids)) {
  324. return Result::error("没有推荐数据");
  325. }
  326. //id
  327. $whereArticle = [];
  328. if (isset($data['id'])) {
  329. $whereArticle['id'] = $data['id'];
  330. }
  331. //title like
  332. if (isset($data['title'])) {
  333. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  334. }
  335. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  336. ->where($whereArticle)
  337. ->orderBy('id', 'desc')
  338. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  339. if ($article) {
  340. $data = [
  341. 'rows' => $article->items(),
  342. 'count' => $article->total(),
  343. ];
  344. return Result::success($data);
  345. } else {
  346. return Result::error("获取失败失败");
  347. }
  348. }
  349. /**
  350. * @param array $data
  351. * @return array
  352. */
  353. public function getArticleList(array $data): array
  354. {
  355. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  356. $type_id = $data['type_id'];
  357. unset($data['type_id']);
  358. $user_id = $data['user_id'];
  359. unset($data['user_id']);
  360. $where = [];
  361. $status1 = [];
  362. if (isset($data['id']) && $data['id']) {
  363. array_push($where, ['article.id', '=', $data['id']]);
  364. }
  365. if (isset($data['title']) && $data['title']) {
  366. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  367. }
  368. if (isset($data['category_name']) && $data['category_name']) {
  369. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  370. }
  371. if (isset($data['catid']) && $data['catid']) {
  372. array_push($where, ['article.catid', '=', $data['catid']]);
  373. }
  374. if (isset($data['author']) && $data['author']) {
  375. array_push($where, ['article.author', '=', $data['author']]);
  376. }
  377. if (isset($data['islink']) && $data['islink'] !== "") {
  378. array_push($where, ['article.islink', '=', $data['islink']]);
  379. }
  380. if (isset($data['status']) && $data['status'] !== "") {
  381. array_push($where, ['article.status', '=', $data['status']]);
  382. }
  383. if (isset($data['status1'])) {
  384. $status1 = json_decode(($data['status1']));
  385. }
  386. //不是管理员展示个人数据;
  387. if ($type_id != 10000) {
  388. $where[] = ['article.admin_user_id', '=', $user_id];
  389. }
  390. $rep = Article::where($where)
  391. ->whereNotIn('article.status', [404])
  392. ->when($status1, function ($query) use ($status1) {
  393. if (isset($status1) && $status1) {
  394. $query->whereIn('article.status', $status1);
  395. }
  396. })
  397. ->leftJoin('category', 'article.catid', 'category.id')
  398. ->leftJoin('website_category', function ($join) {
  399. $join->on('article.web_site_id', '=', 'website_category.website_id')
  400. ->on('article.catid', '=', 'website_category.category_id');
  401. })
  402. ->select("article.*", "category.name as category_name", "website_category.alias")
  403. ->orderBy("article.updated_at", "desc")
  404. ->limit($data['pageSize'])
  405. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  406. $count = Article::where($where)->whereNotIn('article.status', [404])
  407. ->when($status1, function ($query) use ($status1) {
  408. if (isset($status1) && $status1) {
  409. $query->whereIn('article.status', $status1);
  410. }
  411. })
  412. ->leftJoin('category', 'article.catid', 'category.id')->count();
  413. $data = [
  414. 'rows' => $rep->toArray(),
  415. 'count' => $count,
  416. ];
  417. if (empty($rep)) {
  418. return Result::error("没有信息数据");
  419. }
  420. return Result::success($data);
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function addArticle(array $data): array
  427. {
  428. var_dump($data, '----------12-----------1');
  429. unset($data['user_type']);
  430. unset($data['nav_add_pool_id']);
  431. // unset($data['commend_id']);
  432. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  433. Db::beginTransaction();
  434. try {
  435. //处理投票
  436. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  437. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  438. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  439. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  440. unset($data['is_survey']);
  441. unset($data['survey_name']);
  442. unset($data['suvey_array']);
  443. // unset($data['website_id']);
  444. // unset($data['web_site_id']);
  445. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  446. if ($data['hits'] == '') {
  447. $data['hits'] = 0;
  448. }
  449. if ($data['is_original'] == '') {
  450. $data['is_original'] = 0;
  451. }
  452. if ($data['status'] == '') {
  453. $data['status'] = 0;
  454. }
  455. $articleData = $data;
  456. unset($articleData['content']);
  457. //自动处理缩略图、关键字、描述
  458. if ($articleData['imgurl'] == '') {
  459. //如果没有图,设置level=0
  460. $levelArr = json_decode($articleData['level'], true);
  461. var_dump($levelArr, '----------levelArr-----------1');
  462. //content中提取图片第一个图,正则提取
  463. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  464. preg_match_all($reg, $data['content'], $matches);
  465. if (isset($matches[1][0])) {
  466. //截取varchar240
  467. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  468. //如果有图,设置level=3
  469. if (!in_array(3, $levelArr)) {
  470. $levelArr[] = 3;
  471. }
  472. $articleData['level'] = json_encode($levelArr);
  473. } else {
  474. if (!in_array(0, $levelArr)) {
  475. $levelArr[] = 0;
  476. }
  477. $articleData['level'] = json_encode($levelArr);
  478. }
  479. }
  480. var_dump($articleData['level'], '----------$articleData[level]----------1');
  481. if ($articleData['keyword'] == '') {
  482. //提取标题+内容中的关键词
  483. $articleData['keyword'] = $data['title'];
  484. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  485. Jieba::init(); // 初始化 jieba-php
  486. Finalseg::init();
  487. $segList = Jieba::cut($articleData['keyword']);
  488. $segList1 = array_slice($segList, 0, 8);
  489. $articleData['keyword'] = implode(',', $segList1);
  490. }
  491. if ($articleData['introduce'] == '') {
  492. //提取内容中的描述
  493. $content = $data['content'];
  494. // 去除 <style> 和 <script> 标签及其内容
  495. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  496. // 去除所有 HTML 标签
  497. $content = strip_tags($content);
  498. // 去除 HTML 实体
  499. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  500. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  501. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  502. // 去除多余空白
  503. $content = preg_replace('/\s+/u', '', $content);
  504. // 截取 100 个字符
  505. $articleData['introduce'] = mb_substr($content, 0, 100);
  506. }
  507. if ($articleData['status'] == 0) {
  508. $this->sendMessage([
  509. 'talk_type' => 100,
  510. 'title' => $articleData['title'],
  511. 'content' => '提交了审核',
  512. 'messageType' => 2,
  513. ]);
  514. }
  515. $id = Article::insertGetId($articleData);
  516. $articleDataContent = [
  517. 'article_id' => $id,
  518. 'content' => $data['content'],
  519. ];
  520. ArticleData::insertGetId($articleDataContent);
  521. //处理投票
  522. if ($is_survey == 1) {
  523. //生成年月日时分秒+8位随机数
  524. $uuid = date('YmdHis') . rand(10000000, 99999999);
  525. var_dump($suvey_array, 'suvey_array________');
  526. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  527. var_dump($suveys_array, '---------------------1');
  528. var_dump($suvey_array, '---------------------2');
  529. $suvey_data = [];
  530. foreach ($suveys_array as $key => $value) {
  531. if ($value == '') {
  532. continue;
  533. }
  534. if (is_array($value)) {
  535. $suvey_data[] = [
  536. 'sur_id' => $uuid,
  537. 'art_id' => $id,
  538. 'website_id' => $website_id ?? 2,
  539. 'survey_name' => $survey_name,
  540. 'choice_name' => $value[1],
  541. 'is_other' => 1,
  542. 'other_id' => 0,
  543. 'results' => 0,
  544. ];
  545. } else {
  546. $suvey_data[] = [
  547. 'sur_id' => $uuid,
  548. 'art_id' => $id,
  549. 'website_id' => $website_id ?? 2,
  550. 'survey_name' => $survey_name,
  551. 'choice_name' => $value,
  552. 'is_other' => 0,
  553. 'other_id' => 0,
  554. 'results' => 0,
  555. ];
  556. }
  557. if (empty($suvey_data)) {
  558. throw new \Exception("投票数据为空");
  559. }
  560. }
  561. $result = ArticleSurvey::insert($suvey_data);
  562. if (!$result) {
  563. throw new \Exception("投票失败,ArticleSurvey插入失败");
  564. }
  565. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  566. if (!$result) {
  567. throw new \Exception("投票失败,更新主表失败");
  568. }
  569. }
  570. Db::commit();
  571. return Result::success(['id' => $id]);
  572. } catch (\Throwable $ex) {
  573. Db::rollBack();
  574. var_dump($ex->getMessage());
  575. return Result::error("创建失败", 0);
  576. }
  577. }
  578. /**
  579. * @param array $data
  580. * @return array
  581. */
  582. public function delArticle(array $data): array
  583. {
  584. $result = Article::where($data)->delete();
  585. //survey投票删除
  586. articleSurvey::where(['art_id' => $data['id']])->delete();
  587. if (!$result) {
  588. return Result::error("删除失败");
  589. }
  590. return Result::success($result);
  591. }
  592. /**
  593. * @param array $data
  594. * @return array
  595. */
  596. public function updateArticle(array $data): array
  597. {
  598. var_dump($data, '----------12-----------1');
  599. Db::beginTransaction();
  600. unset($data['user_type']);
  601. // unset($data['web_site_id']);
  602. unset($data['nav_add_pool_id']);
  603. try {
  604. //处理投票
  605. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  606. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  607. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  608. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  609. unset($data['is_survey']);
  610. unset($data['survey_name']);
  611. unset($data['suvey_array']);
  612. unset($data['website_id']);
  613. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  614. if ($data['hits'] == '') {
  615. $data['hits'] = 0;
  616. }
  617. if ($data['is_original'] == '') {
  618. $data['is_original'] = 0;
  619. }
  620. if ($data['status'] == '') {
  621. $data['status'] = 0;
  622. }
  623. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  624. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  625. $articleData = $data;
  626. unset($articleData['content']);
  627. unset($articleData['status_name']);
  628. unset($articleData['name']);
  629. unset($articleData['content']);
  630. unset($articleData['pid_arr']);
  631. unset($articleData['pid']);
  632. //自动处理缩略图、关键字、描述
  633. if ($articleData['imgurl'] == '') {
  634. //如果没有图,设置level=0
  635. $levelArr = json_decode($articleData['level'], true);
  636. var_dump($levelArr, '----------levelArr-----------1');
  637. //content中提取图片第一个图,正则提取
  638. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  639. preg_match_all($reg, $data['content'], $matches);
  640. if (isset($matches[1][0])) {
  641. //截取varchar240
  642. // 截取到第一个<
  643. $articleData['imgurl'] = $matches[1][0];
  644. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  645. $pos = strpos($articleData['imgurl'], '"');
  646. if ($pos !== false) {
  647. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  648. }
  649. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  650. //如果有图,设置level=3
  651. if (!in_array(3, $levelArr)) {
  652. $levelArr[] = 3;
  653. }
  654. $articleData['level'] = json_encode($levelArr);
  655. } else {
  656. if (!in_array(0, $levelArr)) {
  657. $levelArr[] = 0;
  658. }
  659. $articleData['level'] = json_encode($levelArr);
  660. }
  661. }
  662. var_dump($articleData['level'], '----------$articleData[level]----------1');
  663. if ($articleData['keyword'] == '') {
  664. //提取标题+内容中的关键词
  665. $articleData['keyword'] = $data['title'];
  666. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  667. Jieba::init(); // 初始化 jieba-php
  668. Finalseg::init();
  669. $segList = Jieba::cut($articleData['keyword']);
  670. $segList1 = array_slice($segList, 0, 8);
  671. $articleData['keyword'] = implode(',', $segList1);
  672. }
  673. if ($articleData['introduce'] == '') {
  674. //提取内容中的描述
  675. $content = $data['content'];
  676. // 去除 <style> 和 <script> 标签及其内容
  677. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  678. // 去除所有 HTML 标签
  679. $content = strip_tags($content);
  680. // 去除 HTML 实体
  681. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  682. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  683. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  684. // 去除多余空白
  685. $content = preg_replace('/\s+/u', '', $content);
  686. // 截取 100 个字符
  687. $articleData['introduce'] = mb_substr($content, 0, 100);
  688. }
  689. if ($articleData['status'] == 0) {
  690. $this->sendMessage([
  691. 'talk_type' => 100,
  692. 'title' => $articleData['title'],
  693. 'content' => '提交了审核',
  694. 'messageType' => 2,
  695. ]);
  696. }
  697. $id = Article::where(['id' => $data['id']])->update($articleData);
  698. $articleDataContent = [
  699. 'content' => $data['content'],
  700. ];
  701. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  702. //处理投票
  703. $id = $data['id'];
  704. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  705. var_dump($suvey_array, 'suvey_array________delete');
  706. //处理投票
  707. if ($is_survey == 1) {
  708. //生成年月日时分秒+8位随机数
  709. $uuid = date('YmdHis') . rand(10000000, 99999999);
  710. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  711. var_dump($suveys_array, '---------------------1');
  712. $suvey_data = [];
  713. if (is_array($suveys_array)) {
  714. foreach ($suveys_array as $key => $value) {
  715. if ($value == '') {
  716. continue;
  717. }
  718. if (is_array($value)) {
  719. $suvey_data[] = [
  720. 'sur_id' => $uuid,
  721. 'art_id' => $id,
  722. 'website_id' => $website_id ?? 2,
  723. 'survey_name' => $survey_name,
  724. 'choice_name' => $value[1],
  725. 'is_other' => 1,
  726. 'other_id' => 0,
  727. 'results' => 0,
  728. ];
  729. } else {
  730. $suvey_data[] = [
  731. 'sur_id' => $uuid,
  732. 'art_id' => $id,
  733. 'website_id' => $website_id ?? 2,
  734. 'survey_name' => $survey_name,
  735. 'choice_name' => $value,
  736. 'is_other' => 0,
  737. 'other_id' => 0,
  738. 'results' => 0,
  739. ];
  740. }
  741. if (empty($suvey_data)) {
  742. throw new \Exception("投票数据为空");
  743. }
  744. }
  745. }
  746. $result = ArticleSurvey::insert($suvey_data);
  747. if (!$result) {
  748. throw new \Exception("投票失败");
  749. }
  750. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. } else {
  755. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  756. }
  757. Db::commit();
  758. return Result::success([]);
  759. } catch (\Throwable $ex) {
  760. Db::rollBack();
  761. var_dump($ex->getMessage());
  762. return Result::error("更新失败" . $ex->getMessage(), 0);
  763. }
  764. }
  765. /**
  766. * 更新资讯状态
  767. * @param array $data
  768. * @return array
  769. */
  770. public function upArticleStatus(array $data): array
  771. {
  772. $articleData = Article::where(['id' => $data['id']])->first();
  773. if ($data['status'] == 1) {
  774. $this->sendMessage([
  775. 'talk_type' => 101,
  776. 'title' => $articleData['title'],
  777. 'content' => '审核通过',
  778. 'messageType' => 2,
  779. 'user_id' => $articleData['admin_user_id'],
  780. ]);
  781. }
  782. if ($data['status'] == 2) {
  783. $this->sendMessage([
  784. 'talk_type' => 101,
  785. 'title' => $articleData['title'],
  786. 'content' => '审核拒绝',
  787. 'messageType' => 2,
  788. 'user_id' => $articleData['admin_user_id'],
  789. ]);
  790. }
  791. if ($data['status'] == 0) {
  792. $this->sendMessage([
  793. 'talk_type' => 100,
  794. 'title' => $articleData['title'],
  795. 'content' => '提交了审核',
  796. 'messageType' => 2,
  797. ]);
  798. }
  799. $result = Article::where(['id' => $data['id']])->update($data);
  800. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  801. //article_ignore 表插入数据 db操作
  802. //转成数组
  803. //删掉数据重新写入
  804. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  805. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  806. $insert_data = [];
  807. foreach ($website_ids as $key => $value) {
  808. $insert_data[] = [
  809. 'article_id' => $data['id'],
  810. 'website_id' => $value,
  811. ];
  812. }
  813. DB::table('article_ignore')->insert($insert_data);
  814. }
  815. if ($result) {
  816. return Result::success();
  817. } else {
  818. return Result::error("更新状态失败", 0);
  819. }
  820. }
  821. /**
  822. * 获取新闻详情
  823. * @param array $data
  824. * @return array
  825. */
  826. public function getArticleInfo(array $data): array
  827. {
  828. $where = [
  829. 'article.id' => $data['id'],
  830. // 'article.status' => 1,
  831. ];
  832. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  833. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  834. $info = $result;
  835. // var_dump($info, 'info');
  836. $info['survey_array'] = $articleSurvey;
  837. if ($result) {
  838. return Result::success($info);
  839. } else {
  840. return Result::error("查询失败", 0);
  841. }
  842. }
  843. /**
  844. * 获取头条新闻
  845. * @param array $data
  846. * @return array
  847. */
  848. public function getWebsiteArticlett(array $data): array
  849. {
  850. $website_id = $data['website_id'];
  851. $categorys = $this->processArticlePro($website_id);
  852. $catiall = $categorys['catiall'];
  853. $categoryIds = $categorys['categoryIds'];
  854. $where = [
  855. 'status' => 1
  856. ];
  857. $website_id = $data['website_id'];
  858. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  859. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  860. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  861. switch ($data['level']) {
  862. case 1:
  863. case 2:
  864. case 3:
  865. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  866. $query = Article::where($where)
  867. ->where('level', 'like', '%' . $data['level'] . '%')
  868. ->orderBy('updated_at', 'desc');
  869. break;
  870. case 4: //最新资讯
  871. $query = Article::where($where)->orderBy('updated_at', 'desc');
  872. break;
  873. case 5: //资讯推荐
  874. $query = Article::where($where)
  875. ->where('updated_at', '>', $month);
  876. break;
  877. case 7: //资讯分类
  878. if (isset($data['id']) && !empty($data['id'])) {
  879. $keyword = Article::where('id', $data['id'])->value('keyword');
  880. $keywordArray = explode(',', $keyword);
  881. $whereL7 = [];
  882. foreach ($keywordArray as $k => $v) {
  883. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  884. }
  885. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  886. break;
  887. } else {
  888. return Result::error("请输入资讯ID", 0);
  889. break;
  890. }
  891. default:
  892. break;
  893. }
  894. // $whereL7 = [];
  895. // if(isset($data['id']) && !empty($data['id'])){
  896. // $keyword = Article::where('id', $data['id'])->value('keyword');
  897. // $keywordArray = explode(',', $keyword);
  898. // foreach ($keywordArray as $k => $v) {
  899. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  900. // }
  901. // }
  902. // $query = Article::where($where)
  903. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  904. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  905. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  906. // }
  907. // if($data['level'] == 7){
  908. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  909. // }
  910. // if($data['level'] == 4){
  911. // $query = $query->inRandomOrder()
  912. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  913. // }
  914. // if($data['level'] == 5){
  915. // $query = $query->orderBy('updated_at','desc');
  916. // }
  917. // });
  918. if ($data['textnum'] > 0) {
  919. $query = clone $query;
  920. $result['text'] = $query
  921. ->whereIn('catid', $categoryIds)
  922. ->leftJoinSub(function ($query) use ($website_id) {
  923. $query->from('article_ignore')
  924. ->where('website_id', $website_id);
  925. }, 'article_ignore', function ($join) {
  926. $join->on('article_ignore.article_id', '=', 'article.id');
  927. })
  928. ->where(function ($query) use ($website_id) {
  929. $query->whereNull('article_ignore.article_id')
  930. ->orWhere('article_ignore.website_id', '!=', $website_id);
  931. })
  932. ->select(
  933. 'article.id',
  934. 'article.title',
  935. 'article.author',
  936. 'article.updated_at',
  937. 'article.introduce',
  938. 'article.islink',
  939. 'article.linkurl',
  940. 'article.copyfrom',
  941. 'article.cat_arr_id',
  942. 'article.catid',
  943. 'article.level'
  944. )
  945. ->offset($data['placeid'])
  946. ->limit($data['textnum'])
  947. ->get()->all();
  948. foreach ($result['text'] as $k => $v) {
  949. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  950. }
  951. }
  952. if ($data['imgnum'] > 0) {
  953. $query = clone $query;
  954. $result['img'] = $query
  955. ->whereIn('catid', $categoryIds)
  956. ->where('article.imgurl', '!=', '')
  957. ->select(
  958. 'article.id',
  959. 'article.title',
  960. 'article.imgurl',
  961. 'article.author',
  962. 'article.updated_at',
  963. 'article.introduce',
  964. 'article.islink',
  965. 'article.linkurl',
  966. 'article.copyfrom',
  967. 'article.cat_arr_id',
  968. 'article.catid',
  969. 'article.level'
  970. )
  971. ->offset($data['placeid'])
  972. ->limit($data['imgnum'])
  973. ->get()->all();
  974. foreach ($result['img'] as $k => $v) {
  975. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  976. }
  977. }
  978. if (empty($result)) {
  979. return Result::error("暂无相关资讯", 0);
  980. }
  981. return Result::success($result);
  982. }
  983. /**
  984. * 获取模块新闻
  985. * @param array $data
  986. * @return array
  987. */
  988. public function getWebsiteModelArticles(array $data): array
  989. {
  990. $catid = $data['catid'];
  991. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  992. $category = $category->toArray();
  993. if (!empty($category)) {
  994. $where = [
  995. 'status' => 1,
  996. 'catid' => $catid,
  997. ];
  998. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  999. // 1:文字新闻;2:轮播图;3:图文;
  1000. // 级别:0:未分类
  1001. // 3:推荐图片
  1002. if ($data['level'] == 1) {
  1003. $data['level'] = 0;
  1004. }
  1005. $result = Article::where($where)
  1006. ->where(function ($query) use ($data) {
  1007. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1008. ->orWhereNull("level")
  1009. ->orWhereRaw("level = '[]'");
  1010. })
  1011. ->where(function ($query) use ($data) {
  1012. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1013. ->orWhereNull("ignore_ids");
  1014. })
  1015. ->orderBy("updated_at", "desc")
  1016. ->offset($placeid)
  1017. ->limit($data['pagesize'])
  1018. ->get();
  1019. if (empty($result)) {
  1020. return Result::error("此栏目暂无相关新闻", 0);
  1021. }
  1022. } else {
  1023. return Result::error("此网站暂无此栏目", 0);
  1024. }
  1025. return Result::success($result);
  1026. }
  1027. /**
  1028. *获取新闻列表
  1029. * @param array $data
  1030. * @return array
  1031. */
  1032. public function getWebsiteArticleList(array $data): array
  1033. {
  1034. // return Result::success($data);
  1035. $where[] = ['status', '=', 1];
  1036. $website_id = $data['website_id'];
  1037. if (isset($data['catid']) && !empty($data['catid'])) {
  1038. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1039. if (empty($category)) {
  1040. return Result::error("此网站暂无此栏目", 0);
  1041. }
  1042. array_push($where, ['catid', '=', $data['catid']]);
  1043. }
  1044. // return Result::success($where);
  1045. $query = Article::where($where)
  1046. ->leftJoinSub(function ($query) use ($website_id) {
  1047. $query->from('article_ignore')
  1048. ->where('website_id', $website_id);
  1049. }, 'article_ignore', function ($join) {
  1050. $join->on('article_ignore.article_id', '=', 'article.id');
  1051. })
  1052. ->where(function ($query) use ($website_id) {
  1053. $query->whereNull('article_ignore.article_id')
  1054. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1055. })
  1056. ->select(
  1057. 'article.id',
  1058. 'article.title',
  1059. 'article.imgurl',
  1060. 'article.author',
  1061. 'article.updated_at',
  1062. 'article.introduce',
  1063. 'article.islink',
  1064. 'article.linkurl',
  1065. 'article.copyfrom',
  1066. 'article.cat_arr_id',
  1067. 'article.catid'
  1068. );
  1069. $count = $query->count();
  1070. $rep = $query->orderBy("updated_at", "desc")
  1071. ->offset(($data['page'] - 1) * $data['pageSize'])
  1072. ->limit($data['pageSize'])
  1073. ->get()->all();
  1074. $categorys = $this->processArticlePro($website_id);
  1075. $cat_1st_arr = $categorys['cat_1st_arr'];
  1076. $catiall = $categorys['catiall'];
  1077. // $web['website_id'] = $data['website_id'];
  1078. foreach ($rep as $k => $v) {
  1079. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1080. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1081. }
  1082. // $rep = $this->processArticles($rep,$web);
  1083. $data = [
  1084. 'rows' => $rep,
  1085. 'count' => $count,
  1086. ];
  1087. if (empty($rep)) {
  1088. return Result::error("没有信息数据");
  1089. }
  1090. return Result::success($data);
  1091. }
  1092. /**
  1093. * 前端-获取新闻详情
  1094. * @param array $data
  1095. * @return array
  1096. */
  1097. public function selectWebsiteArticleInfo(array $data): array
  1098. {
  1099. $where = [
  1100. 'article.id' => $data['id'],
  1101. 'article.status' => 1,
  1102. ];
  1103. $result = Article::where($where)
  1104. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1105. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1106. ->where(function ($query) use ($data) {
  1107. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1108. ->orWhereNull("ignore_ids");
  1109. })
  1110. ->select(
  1111. 'article.*',
  1112. 'article_data.content',
  1113. 'article_data.article_id',
  1114. 'article_extend.website_url',
  1115. 'article_extend.email',
  1116. 'article_extend.contacts',
  1117. 'article_extend.contacts_mobile',
  1118. 'article_extend.contacts_address',
  1119. 'article_extend.zip_code',
  1120. 'article_extend.enterprise_name'
  1121. )
  1122. ->first();
  1123. if (empty($result)) {
  1124. return Result::error("暂无此新闻!", 0);
  1125. }
  1126. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1127. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1128. ->where('website_category.website_id', $data['website_id'])
  1129. ->where(['website_category.category_id' => $result['catid']])
  1130. ->first();
  1131. if (empty($category)) {
  1132. return Result::error("查询失败", 0);
  1133. }
  1134. //手动推荐文章
  1135. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1136. if (empty($commend_ids)) {
  1137. $commendArticle = [];
  1138. } else {
  1139. //去除不存在的文章ID
  1140. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1141. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1142. ->where('article.status', 1)
  1143. ->where('website_category.website_id', $data['website_id'])
  1144. ->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')
  1145. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1146. // ->orderBy('article.updated_at', 'desc')
  1147. ->limit(5)
  1148. ->get();
  1149. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1150. foreach ($commendArticle as $k => $v) {
  1151. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1152. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1153. $cat_arr_id = array_unique($cat_arr_id);
  1154. // 从website_category取出alias_pinyin
  1155. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1156. ->whereIn('category_id', $cat_arr_id)
  1157. ->pluck('alias_pinyin', 'category_id')
  1158. ->toArray();
  1159. // 将cat_arr_id的json转成路径/隔开
  1160. $path_parts = [];
  1161. foreach ($cat_arr_id as $cat_id) {
  1162. if (isset($cat_arr[$cat_id])) {
  1163. $path_parts[] = $cat_arr[$cat_id];
  1164. }
  1165. }
  1166. $v->alias_pinyin = implode('/', $path_parts);
  1167. } else {
  1168. $v->alias_pinyin = '';
  1169. }
  1170. }
  1171. }
  1172. $result['category_id'] = $category['category_id'];
  1173. $result['cat_name'] = $category['alias'];
  1174. $result['website_name'] = $category['website_name'] ?? "";
  1175. $result['suffix'] = $category['suffix'] ?? "";
  1176. $result['commendArticle'] = $commendArticle;
  1177. $result['commend_ids'] = $commend_ids;
  1178. return Result::success($result);
  1179. }
  1180. /**
  1181. * 前端-获取网站调查问卷
  1182. * @param array $data
  1183. * @return array
  1184. */
  1185. public function getWebsiteSurvey(array $data): array
  1186. {
  1187. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1188. $website = Website::where('id', $data['website_id'])->first();
  1189. if (empty($website)) {
  1190. return Result::error("暂无此网站", 0);
  1191. }
  1192. }
  1193. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1194. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1195. if (empty($article)) {
  1196. return Result::error("暂无此文章", 0);
  1197. }
  1198. // return Result::error($data,0);
  1199. $where['art_id'] = $data['art_id'];
  1200. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1201. } else {
  1202. $survey = Article::where(function ($query) {
  1203. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1204. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1205. })
  1206. ->where('status', 1)
  1207. ->where('is_survey', 1)
  1208. ->select('survey_id')
  1209. ->orderBy('updated_at', 'desc')
  1210. ->first();
  1211. if (empty($survey)) {
  1212. return Result::error("暂无调查问卷", 0);
  1213. }
  1214. $where['sur_id'] = $survey['survey_id'];
  1215. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1216. }
  1217. // return Result::success($where);
  1218. $result = ArticleSurvey::where($where)
  1219. ->where(function ($query) {
  1220. $query->where('is_other', 0)
  1221. ->orWhere(function ($subQuery) {
  1222. $subQuery->where('is_other', 1)
  1223. ->where('other_id', 0);
  1224. });
  1225. })
  1226. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1227. ->select('article_survey.*', 'article.survey_type')
  1228. ->get()->all();
  1229. if (empty($result)) {
  1230. return Result::error("此文章暂无调查问卷", 0);
  1231. }
  1232. return Result::success($result);
  1233. }
  1234. /**
  1235. * 前端-添加网站调查问卷选项
  1236. * @param array $data
  1237. * @return array
  1238. */
  1239. public function addWebsiteSurveyOption(array $data): array
  1240. {
  1241. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1242. $website = Website::where('id', $data['website_id'])->first();
  1243. if (empty($website)) {
  1244. return Result::error("暂无此网站", 0);
  1245. }
  1246. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1247. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1248. if (empty($survey)) {
  1249. return Result::error("此调查问卷不可添加选项", 0);
  1250. }
  1251. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1252. $choice = [
  1253. 'art_id' => $survey['art_id'],
  1254. 'website_id' => $data['website_id'],
  1255. 'survey_name' => $survey['survey_name'],
  1256. 'choice_name' => $data['choice_name'],
  1257. 'sur_id' => $survey['sur_id'],
  1258. 'is_other' => 1,
  1259. 'other_id' => $survey['id'],
  1260. ];
  1261. $result = ArticleSurvey::insertGetId($choice);
  1262. if (empty($result)) {
  1263. return Result::error("添加失败", 0);
  1264. }
  1265. return Result::success($result);
  1266. }
  1267. }
  1268. return Result::error("添加失败", 0);
  1269. }
  1270. return Result::error("添加失败", 0);
  1271. }
  1272. /**
  1273. * 前端-调查问卷投票
  1274. * @param array $data
  1275. * @return array
  1276. */
  1277. public function addWebsiteSurveyVote(array $data): array
  1278. {
  1279. // return Result::success($data);
  1280. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1281. $website = Website::where('id', $data['website_id'])->first();
  1282. if (empty($website)) {
  1283. return Result::error("暂无此网站", 0);
  1284. }
  1285. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1286. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1287. // return Result::success($survey);
  1288. if (empty($is_survey)) {
  1289. return Result::error("此调查问卷不存在", 0);
  1290. }
  1291. // return Result::success($survey);
  1292. // 调查问卷类型
  1293. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1294. //多选 若是json型则转化成数组类型
  1295. if (strpos($data['choice_id'], '[') === 0) {
  1296. $data['choice_id'] = json_decode($data['choice_id'], true);
  1297. } else {
  1298. // 单选 也转换成数组
  1299. $data['choice_id'] = [$data['choice_id']];
  1300. }
  1301. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1302. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1303. // ->where('website_id',$data['website_id'])
  1304. ->where('is_other', 1)
  1305. ->where('other_id', 0)
  1306. ->first();
  1307. if (!empty($other)) {
  1308. return Result::error("请选择已有的选项!", 0);
  1309. }
  1310. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1311. // ->where('website_id',$data['website_id'])
  1312. ->where('is_other', 1)
  1313. ->where('other_id', '!=', 0)
  1314. ->first();
  1315. // return Result::success($choice['other']);
  1316. $choice_id = $data['choice_id'];
  1317. if (!empty($choice['other'])) {
  1318. // array_push($data['choice_id'],$choice['other']['other_id']);
  1319. if (!empty($choice_id)) {
  1320. $key = array_search($choice['other']['id'], $choice_id);
  1321. if ($key !== false) {
  1322. unset($choice_id[$key]);
  1323. $choice_id = array_values($choice_id);
  1324. }
  1325. array_push($choice_id, $choice['other']['other_id']);
  1326. } else {
  1327. $choice_id[0] = $choice['other']['other_id'];
  1328. }
  1329. array_push($data['choice_id'], $choice['other']['other_id']);
  1330. }
  1331. // return Result::success($data);
  1332. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1333. // ->where('website_id',$data['website_id'])
  1334. ->increment('results', 1);
  1335. if (empty($choice)) {
  1336. return Result::error("请选择已有的选项!", 0);
  1337. }
  1338. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1339. // ->where('website_id',$data['website_id'])
  1340. ->where('other_id', 0)
  1341. ->get();
  1342. $survey['choice'] = $choice_id;
  1343. return Result::success($survey);
  1344. }
  1345. return Result::error("参数必填!");
  1346. }
  1347. return Result::error("此调查问卷不存在", 0);
  1348. }
  1349. return Result::error("参数必填!");
  1350. }
  1351. /**
  1352. * 后端-获取网站调查问卷列表
  1353. * @param array $data
  1354. * @return array
  1355. */
  1356. public function getSurveyList(array $data): array
  1357. {
  1358. $where = [];
  1359. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1360. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1361. }
  1362. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1363. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1364. }
  1365. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1366. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1367. }
  1368. // return Result::success($where);
  1369. if (!empty($where)) {
  1370. $query = Article::where($where)->where(function ($q) {
  1371. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1372. });
  1373. } else {
  1374. $query = Article::where(function ($q) {
  1375. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1376. });
  1377. }
  1378. $count = $query->count();
  1379. $survey = $query->orderByDesc('id')
  1380. ->limit($data['pageSize'])
  1381. ->offset(($data['page'] - 1) * $data['pageSize'])
  1382. ->get();
  1383. if (empty($survey->toArray())) {
  1384. return Result::error("暂无调查问卷!", 0);
  1385. }
  1386. $result = [
  1387. 'rows' => $survey,
  1388. 'count' => $count,
  1389. ];
  1390. return Result::success($result);
  1391. }
  1392. /**
  1393. * 后端-获取网站调查问卷详情
  1394. * @param array $data
  1395. * @return array
  1396. */
  1397. public function getSurveyInfo(array $data): array
  1398. {
  1399. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1400. $where = ['sur_id' => $data['sur_id']];
  1401. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1402. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1403. ->select('article_survey.*', 'article.survey_type')
  1404. ->get()->all();
  1405. if (empty($choose)) {
  1406. return Result::error("此调查问卷不存在", 0);
  1407. }
  1408. $resultsArray = array_column($choose, 'results');
  1409. $total = array_sum($resultsArray);
  1410. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1411. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1412. // $total = 0;
  1413. if (!empty($other)) {
  1414. $total = $total + $other['results'];
  1415. $other['choice_name'] = '(其他)';
  1416. if (!empty($others)) {
  1417. $other['hasChildren'] = true;
  1418. // array_push($other,['hasChildren','=',true]);
  1419. $other['children'] = $others;
  1420. $other_choices = [$other->toArray()];
  1421. $mer_choice = array_merge($choose, $other_choices);
  1422. $value_choice = array_values($mer_choice);
  1423. } else {
  1424. // return Result::error('1111');
  1425. $other_choices = [$other->toArray()];
  1426. $other_choices = array_merge($choose, $other_choices);
  1427. $value_choice = array_values($other_choices);
  1428. // return Result::success($result);
  1429. }
  1430. } else {
  1431. $value_choice = $choose;
  1432. }
  1433. $result = [
  1434. 'choose' => $value_choice,
  1435. 'total' => $total,
  1436. ];
  1437. }
  1438. return Result::success($result);
  1439. }
  1440. /**
  1441. * 前端-搜索新闻列表
  1442. * @param array $data
  1443. * @return array
  1444. */
  1445. public function selectWebsiteArticle(array $data): array
  1446. {
  1447. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1448. $website_id = $data['website_id'];
  1449. $categorys = $this->processArticlePro($website_id);
  1450. $catiall = $categorys['catiall'];
  1451. $query = Article::where('status', 1)
  1452. ->whereIn('catid', $category)
  1453. ->leftJoinSub(function ($query) use ($website_id) {
  1454. $query->from('article_ignore')
  1455. ->where('website_id', $website_id);
  1456. }, 'article_ignore', function ($join) {
  1457. $join->on('article_ignore.article_id', '=', 'article.id');
  1458. })
  1459. ->where(function ($query) use ($website_id) {
  1460. $query->whereNull('article_ignore.article_id')
  1461. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1462. });
  1463. // return Result::success($all_articles);
  1464. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1465. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1466. }
  1467. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1468. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1469. }
  1470. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1471. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1472. }
  1473. // 计算总数
  1474. $count = $query->count();
  1475. // 分页查询
  1476. $articles = $query
  1477. ->select(
  1478. 'article.id',
  1479. 'article.title',
  1480. 'article.imgurl',
  1481. 'article.author',
  1482. 'article.updated_at',
  1483. 'article.introduce',
  1484. 'article.islink',
  1485. 'article.linkurl',
  1486. 'article.copyfrom',
  1487. 'article.cat_arr_id',
  1488. 'article.catid',
  1489. 'article.department_arr_id',
  1490. 'article.city_arr_id',
  1491. )
  1492. ->orderBy("updated_at", "desc")
  1493. ->offset(($data['page'] - 1) * $data['pageSize'])
  1494. ->limit($data['pageSize'])
  1495. ->get();
  1496. foreach ($articles as $k => $v) {
  1497. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1498. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1499. }
  1500. if (empty($articles)) {
  1501. return Result::error("没有符合条件的资讯数据");
  1502. }
  1503. $result = [
  1504. 'rows' => $articles,
  1505. 'count' => $count,
  1506. ];
  1507. return Result::success($result);
  1508. }
  1509. /**
  1510. * 模块新闻加强版
  1511. * @param array $data
  1512. * @return array
  1513. */
  1514. public function getWebsiteCatidArticle(array $data): array
  1515. {
  1516. $where = [
  1517. 'website_category.category_id' => $data['catid'],
  1518. 'website_category.website_id' => $data['website_id'],
  1519. ];
  1520. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1521. $child_catnum = $data['child_catnum'] ?? 1;
  1522. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1523. $childCategoryIds = array_column($category['child'], 'category_id');
  1524. if (empty($childCategoryIds)) {
  1525. return Result::error("暂无子栏目", 0);
  1526. }
  1527. $imgArticles = [];
  1528. $textArticles = [];
  1529. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1530. // 初始化子分类图片新闻和文字新闻数组
  1531. // 查询所有子级栏目的图文新闻
  1532. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1533. ->where(function ($query) use ($data) {
  1534. $query->where(function ($subQuery) use ($data) {
  1535. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1536. })->orWhereNull("ignore_ids");
  1537. })
  1538. ->where('status', 1)
  1539. ->where('imgurl', '!=', '')
  1540. ->select('*')
  1541. ->orderBy('updated_at', 'desc')
  1542. ->limit($data['child_imgnum'])
  1543. ->get();
  1544. }
  1545. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1546. // 查询所有子级栏目的文字新闻
  1547. $textArticles = Article::where('catid', $childCategoryIds[0])
  1548. ->where('status', 1)
  1549. ->where(function ($query) use ($data) {
  1550. $query->where(function ($subQuery) use ($data) {
  1551. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1552. })->orWhereNull("ignore_ids");
  1553. })
  1554. ->select('*')
  1555. ->orderBy('updated_at', 'desc')
  1556. ->limit($data['child_textnum'])
  1557. ->get();
  1558. }
  1559. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1560. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1561. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1562. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1563. return $child;
  1564. }, $category['child']);
  1565. }
  1566. // }
  1567. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1568. $category['img'] = WebsiteCategory::where($where)
  1569. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1570. ->where('article.status', 1)
  1571. ->where('article.imgurl', '!=', '')
  1572. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1573. ->orderBy('article.updated_at', 'desc')
  1574. ->limit($data['img_num'])
  1575. ->get();
  1576. }
  1577. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1578. $category['text'] = WebsiteCategory::where($where)
  1579. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1580. ->where('article.status', 1)
  1581. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1582. ->orderBy('article.updated_at', 'desc')
  1583. ->limit($data['text_num'])
  1584. ->get();
  1585. }
  1586. // $category = $category->get();
  1587. if (empty($category)) {
  1588. return Result::error("查询失败", 0);
  1589. }
  1590. return Result::success($category);
  1591. }
  1592. /**
  1593. * 模块新闻加强plus版
  1594. * @param array $data
  1595. * @return array
  1596. */
  1597. public function getWebsiteAllArticle(array $data): array
  1598. {
  1599. $time1 = microtime(true);
  1600. $wetbsite_id = $data['website_id'] ?? 2;
  1601. $data = json_decode($data['id'], true);
  1602. $categorys = $this->processArticlePro($wetbsite_id);
  1603. $cat_1st_arr = $categorys['cat_1st_arr'];
  1604. $catiall = $categorys['catiall'];
  1605. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1606. $parent_category = array_column($data, 'parent');
  1607. $parent_cat = [];
  1608. $child_category = array_column($data, 'child');
  1609. if (!empty($parent_category)) {
  1610. foreach ($parent_category as $key => $value) {
  1611. $arr = array_map('intval', explode(',', $value));
  1612. $parent_cat[$key] = $arr[0] ?? 0;
  1613. $parent_category = $arr[0] ?? 0;
  1614. $article_imgnum = $arr[1] ?? 0;
  1615. $article_textnum = $arr[2] ?? 0;
  1616. if ($parent_category != 0) {
  1617. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1618. // return Result::success($category_arr);
  1619. if ($article_imgnum != 0) {
  1620. $img_article = Article::whereIn('catid', $category_arr)
  1621. ->where('status', 1)
  1622. ->where('imgurl', '!=', '')
  1623. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1624. $query->from('article_ignore')
  1625. ->where('website_id', $wetbsite_id);
  1626. }, 'article_ignore', function ($join) {
  1627. $join->on('article_ignore.article_id', '=', 'article.id');
  1628. })
  1629. ->where(function ($query) use ($wetbsite_id) {
  1630. $query->whereNull('article_ignore.article_id')
  1631. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1632. })
  1633. ->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')
  1634. ->orderBy('updated_at', 'desc')
  1635. ->limit($article_imgnum)
  1636. ->get()->all();
  1637. foreach ($img_article as $k => $v) {
  1638. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1639. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1640. }
  1641. } else {
  1642. $img_article = [];
  1643. }
  1644. if ($article_textnum != 0) {
  1645. $text_article = Article::whereIn('catid', $category_arr)
  1646. ->where('status', 1)
  1647. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1648. $query->from('article_ignore')
  1649. ->where('website_id', $wetbsite_id);
  1650. }, 'article_ignore', function ($join) {
  1651. $join->on('article_ignore.article_id', '=', 'article.id');
  1652. })
  1653. ->where(function ($query) use ($wetbsite_id) {
  1654. $query->whereNull('article_ignore.article_id')
  1655. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1656. })
  1657. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1658. ->orderBy('updated_at', 'desc')
  1659. ->limit($article_textnum)
  1660. ->get()->all();
  1661. foreach ($text_article as $k => $v) {
  1662. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1663. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1664. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1665. }
  1666. } else {
  1667. $text_article = [];
  1668. }
  1669. $catiall[$parent_category]['imgnum'] = $img_article;
  1670. $catiall[$parent_category]['textnum'] = $text_article;
  1671. $parent[$key] = $catiall[$parent_category];
  1672. } else {
  1673. $parent[$key] = '';
  1674. }
  1675. }
  1676. }
  1677. if (!empty($child_category)) {
  1678. foreach ($child_category as $key => $value) {
  1679. $arr = array_map('intval', explode(',', $value));
  1680. $parent_category = $parent_cat[$key];
  1681. $child_category = $arr[0] ?? 0;
  1682. $article_imgnum = $arr[1] ?? 0;
  1683. $article_textnum = $arr[2] ?? 0;
  1684. if ($child_category != 0) {
  1685. $all_childcat = $cat_1st_arr[$parent_category];
  1686. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1687. // 从 $websiteInfoIndexed 中获取对应的数据
  1688. $info = $websiteInfoIndexed[$v];
  1689. // 返回一个包含所需信息的数组
  1690. return [
  1691. 'alias' => $info->alias,
  1692. 'category_id' => $info->category_id,
  1693. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1694. 'pid' => $info->pid,
  1695. 'type' => $info->type,
  1696. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1697. 'pinyin' => $info->pinyin,
  1698. ];
  1699. }, $all_childcat);
  1700. if ($article_imgnum != 0) {
  1701. $img_article = Article::where('catid', $child_category)
  1702. ->where('status', 1)
  1703. ->where('imgurl', '!=', '')
  1704. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1705. $query->from('article_ignore')
  1706. ->where('website_id', $wetbsite_id);
  1707. }, 'article_ignore', function ($join) {
  1708. $join->on('article_ignore.article_id', '=', 'article.id');
  1709. })
  1710. ->where(function ($query) use ($wetbsite_id) {
  1711. $query->whereNull('article_ignore.article_id')
  1712. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1713. })
  1714. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1715. ->orderBy('updated_at', 'desc')
  1716. ->limit($article_imgnum)
  1717. ->get()->all();
  1718. foreach ($img_article as $k => $v) {
  1719. // var_dump($v);
  1720. // var_dump($k);
  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::where('catid', $child_category)
  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. // var_dump($v);
  1746. // var_dump($k);
  1747. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1748. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1749. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1750. }
  1751. } else {
  1752. $text_article = [];
  1753. }
  1754. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1755. $catiall[$child_category]['imgnum'] = $img_article;
  1756. $catiall[$child_category]['textnum'] = $text_article;
  1757. $child[$key] = $catiall[$child_category];
  1758. // var_dump($pids);
  1759. } else {
  1760. $child[$key] = '';
  1761. }
  1762. }
  1763. }
  1764. foreach ($parent as $key => $value) {
  1765. $result[$key] = $value;
  1766. if (!empty($child[$key])) {
  1767. // var_dump($child[$key]);
  1768. $result[$key]['child'] = $child[$key];
  1769. // $value[$key]['child'] = $child[$key];
  1770. } else {
  1771. $result[$key]['child'] = [
  1772. "alias" => null,
  1773. "category_id" => null,
  1774. "type" => null,
  1775. "pinyin" => null,
  1776. "all_childcat" => [],
  1777. "imgnum" => [],
  1778. "textnum" => []
  1779. ];
  1780. }
  1781. }
  1782. return Result::success($result);
  1783. }
  1784. /**
  1785. * 辅助方法:获取文章列表
  1786. */
  1787. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1788. {
  1789. sleep(1);
  1790. $query = Article::where('article.status', 1)
  1791. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1792. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1793. ->where(function ($query) use ($website) {
  1794. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1795. })
  1796. ->leftJoin('website_category', function ($join) use ($website) {
  1797. $join->on('article.catid', '=', 'website_category.category_id')
  1798. ->where('website_category.website_id', '=', $website['website_id']);
  1799. })
  1800. ->select(
  1801. 'article.id',
  1802. 'article.title',
  1803. 'article.imgurl',
  1804. 'article.author',
  1805. 'article.updated_at',
  1806. 'article.introduce',
  1807. 'article.islink',
  1808. 'article.linkurl',
  1809. 'article.copyfrom',
  1810. 'article.cat_arr_id',
  1811. 'article.catid',
  1812. 'website_category.alias as category_name'
  1813. )
  1814. ->orderBy('updated_at', 'desc')
  1815. ->limit($limit);
  1816. // 如果是图片文章,添加图片URL条件
  1817. if ($isImageArticle) {
  1818. $query->where('imgurl', '!=', '');
  1819. } else {
  1820. // 文字文章不需要imgurl字段
  1821. $query->addSelect('article.introduce');
  1822. }
  1823. $articles = $query->get();
  1824. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1825. }
  1826. /**
  1827. * 乡村网-获取特殊新闻模块
  1828. * @param array $data
  1829. * @return array
  1830. */
  1831. public function getWebsiteArticles(array $data): array
  1832. {
  1833. $website_id = $data['website_id'];
  1834. $catids = json_decode($data['id'], true);
  1835. $parent_category = array_column($catids, 'parent');
  1836. if (!empty($parent_category) && is_array($parent_category)) {
  1837. $categorys = $this->processArticlePro($website_id);
  1838. $catiall = $categorys['catiall'];
  1839. $cat_1st_arr = $categorys['cat_1st_arr'];
  1840. // return Result::success($categorys);
  1841. foreach ($parent_category as $key => $value) {
  1842. $arr = array_map('intval', explode(',', $value));
  1843. $parent_category = $arr[0] ?? 0;
  1844. $article_imgnum = $arr[1] ?? 0;
  1845. $article_textnum = $arr[2] ?? 0;
  1846. if ($parent_category != 0) {
  1847. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1848. // return Result::success($category_arr);
  1849. if ($article_imgnum != 0) {
  1850. $img_article = Article::whereIn('catid', $category_arr)
  1851. ->where('status', 1)
  1852. ->where('imgurl', '!=', '')
  1853. ->leftJoinSub(function ($query) use ($website_id) {
  1854. $query->from('article_ignore')
  1855. ->where('website_id', $website_id);
  1856. }, 'article_ignore', function ($join) {
  1857. $join->on('article_ignore.article_id', '=', 'article.id');
  1858. })
  1859. ->where(function ($query) use ($website_id) {
  1860. $query->whereNull('article_ignore.article_id')
  1861. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1862. })
  1863. ->select(
  1864. 'id',
  1865. 'title',
  1866. 'imgurl',
  1867. 'author',
  1868. 'updated_at',
  1869. 'introduce',
  1870. 'islink',
  1871. 'linkurl',
  1872. 'copyfrom',
  1873. 'cat_arr_id',
  1874. 'catid as category_id'
  1875. )
  1876. ->orderBy('updated_at', 'desc')
  1877. ->limit($article_imgnum)
  1878. ->get()->all();
  1879. foreach ($img_article as $k => $v) {
  1880. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1881. // return Result::success($v);
  1882. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1883. }
  1884. } else {
  1885. $img_article = [];
  1886. }
  1887. if ($article_textnum != 0) {
  1888. $text_article = Article::whereIn('catid', $category_arr)
  1889. ->where('status', 1)
  1890. ->leftJoinSub(function ($query) use ($website_id) {
  1891. $query->from('article_ignore')
  1892. ->where('website_id', $website_id);
  1893. }, 'article_ignore', function ($join) {
  1894. $join->on('article_ignore.article_id', '=', 'article.id');
  1895. })
  1896. ->where(function ($query) use ($website_id) {
  1897. $query->whereNull('article_ignore.article_id')
  1898. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1899. })
  1900. ->select(
  1901. 'id',
  1902. 'title',
  1903. 'author',
  1904. 'updated_at',
  1905. 'introduce',
  1906. 'islink',
  1907. 'linkurl',
  1908. 'copyfrom',
  1909. 'cat_arr_id',
  1910. 'catid as category_id'
  1911. )
  1912. ->orderBy('updated_at', 'desc')
  1913. ->limit($article_textnum)
  1914. ->get()->all();
  1915. foreach ($text_article as $k => $v) {
  1916. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1917. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1918. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1919. }
  1920. } else {
  1921. $text_article = [];
  1922. }
  1923. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1924. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1925. $parent[$key] = $catiall[$parent_category];
  1926. } else {
  1927. $parent[$key] = [];
  1928. }
  1929. }
  1930. }
  1931. return Result::success($parent);
  1932. }
  1933. // 封装处理商品的路由问题
  1934. function processGoods($goods, $data)
  1935. {
  1936. return $goods->map(function ($good) use ($data) {
  1937. $catid = $good->catid ?? 0;
  1938. // $pinyin = '';
  1939. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1940. if (!empty($category->pid) && $category->pid != 0) {
  1941. $level = json_decode($category->category_arr_id, true);
  1942. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1943. ->whereIn('category_id', $level)
  1944. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1945. ->get(['aLIas_pinyin'])
  1946. ->pluck('aLIas_pinyin')
  1947. ->implode('/');
  1948. } else {
  1949. $pinyin = $category->aLIas_pinyin ?? '';
  1950. }
  1951. if (isset($good->city_id) && !empty($good->city_id)) {
  1952. $city = District::where('id', $good->city_id)->first(['name']);
  1953. $good->city_name = $city->name ?? '';
  1954. }
  1955. // 解析imgurl JSON并取第一条数据
  1956. $imgUrls = json_decode($good->imgurl, true);
  1957. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1958. $good->pinyin = $pinyin;
  1959. return $good;
  1960. });
  1961. }
  1962. /**
  1963. * 获取商城首页-根据栏目id
  1964. * @param array $data
  1965. * @return array
  1966. * */
  1967. function getWebsiteCatidshop(array $data): array
  1968. {
  1969. $input['catid'] = $data['catid'];
  1970. $input['website_id'] = $data['website_id'];
  1971. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1972. $result = array_map(function ($item) use ($input) {
  1973. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1974. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1975. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1976. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1977. if (empty($category) || $category->type != 2) {
  1978. return Result::error("暂无此栏目", 0);
  1979. } else {
  1980. $website['website_id'] = $input['website_id'];
  1981. $goods = Good::where('good.status', 2)
  1982. ->where('good.website_id', $website['website_id'])
  1983. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1984. ->select(
  1985. 'good.id',
  1986. 'good.name',
  1987. 'good.imgurl',
  1988. 'good.description',
  1989. 'good.updated_at',
  1990. 'good.catid',
  1991. 'good.type_id',
  1992. 'good.price',
  1993. 'good.com',
  1994. 'good.level',
  1995. 'good.unit'
  1996. )
  1997. ->orderBy('updated_at', 'desc')
  1998. ->offset($goodStart)
  1999. ->limit($goodNum);
  2000. $all_goods = $goods->get();
  2001. $all_goods = $this->processGoods($all_goods, $website);
  2002. }
  2003. return $all_goods ?? [];
  2004. }
  2005. }, $data);
  2006. return Result::success($result);
  2007. }
  2008. /**
  2009. * 获取商品模块
  2010. * @param array $data
  2011. * @return array
  2012. * */
  2013. public function getWebsiteshop(array $data): array
  2014. {
  2015. $input['id'] = $data['id'];
  2016. $input['website_id'] = $data['website_id'];
  2017. $catid = $data['catid'];
  2018. $data = json_decode($input['id'] ?? '', true) ?? [];
  2019. $result['goods'] = array_map(function ($item) use ($input) {
  2020. // 检查parent元素是否存在且不是undefined
  2021. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2022. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2023. $website = $input['website_id'];
  2024. $query = Good::where('good.status', 2)
  2025. ->where('good.website_id', $website);
  2026. switch ($Levelid) {
  2027. case 1:
  2028. case 2:
  2029. case 3:
  2030. $goods = $query->where(function ($q) use ($Levelid) {
  2031. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2032. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2033. });
  2034. break;
  2035. case 4:
  2036. $goods = $query;
  2037. break;
  2038. case 5:
  2039. $goods = $query->where('type_id', 1);
  2040. break;
  2041. case 6:
  2042. $goods = $query->where('type_id', 2);
  2043. break;
  2044. default:
  2045. return [];
  2046. }
  2047. $all_goods = $goods
  2048. ->select(
  2049. 'good.id',
  2050. 'good.name',
  2051. 'good.imgurl',
  2052. 'good.description',
  2053. 'good.updated_at',
  2054. 'good.catid',
  2055. 'good.type_id',
  2056. 'good.price',
  2057. 'good.level',
  2058. 'good.website_id'
  2059. )
  2060. ->orderBy('updated_at', 'desc')
  2061. ->offset($goodStart)
  2062. ->limit($goodNum)
  2063. ->get();
  2064. $web['website_id'] = $website;
  2065. $all_goods = $this->processGoods($all_goods, $web);
  2066. }
  2067. return $all_goods;
  2068. }, $data);
  2069. $website = $input['website_id'];
  2070. $result['article'] = Article::where(function ($query) use ($website) {
  2071. $query->where(function ($subQuery) use ($website) {
  2072. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2073. })->orWhereNull("ignore_ids");
  2074. })
  2075. ->where('catid', $catid)
  2076. ->where('article.status', 1)
  2077. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2078. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2079. ->orderBy('article.updated_at', 'desc')
  2080. ->first();
  2081. return Result::success($result);
  2082. }
  2083. /**
  2084. * 获取商品分类
  2085. * @param array $data
  2086. * @return array
  2087. * */
  2088. public function getWebsiteshopCat(array $data): array
  2089. {
  2090. $website = $data['website_id'];
  2091. $category = WebsiteCategory::where('website_id', $website)
  2092. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2093. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2094. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2095. ->orderBy('sort')
  2096. ->get();
  2097. $cat = $category->map(function ($item) use ($website) {
  2098. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2099. $pid = $item->pid ?? 0;
  2100. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2101. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2102. ->where('website_id', $website)
  2103. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2104. ->get(['aLIas_pinyin'])
  2105. ->pluck('aLIas_pinyin')
  2106. ->implode('/');
  2107. } else {
  2108. $pinyin = $item->aLIas_pinyin ?? '';
  2109. }
  2110. $item->pinyin = $pinyin;
  2111. });
  2112. if (empty($category)) {
  2113. return Result::error("栏目查询失败", 0);
  2114. }
  2115. $cat_tree = Result::buildMenuTree($category);
  2116. $web['website_id'] = $website;
  2117. $goods = Good::where('website_id', $website)
  2118. ->where('status', 2)
  2119. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2120. ->latest('updated_at')
  2121. ->offset(($data['page'] - 1) * $data['pageSize'])
  2122. ->limit($data['pageSize'])
  2123. ->get();
  2124. if (!empty($goods)) {
  2125. if ($goods->count() > 1 && !empty($goods)) {
  2126. $goods = $this->processGoods($goods, $web);
  2127. }
  2128. } else {
  2129. $goods = [];
  2130. }
  2131. $result = [
  2132. 'category' => $cat_tree,
  2133. 'goods' => $goods,
  2134. ];
  2135. // $resul['goods'] = $goods;
  2136. if (empty($result)) {
  2137. return Result::error("查询失败", 0);
  2138. }
  2139. return Result::success($result);
  2140. }
  2141. /*
  2142. * 获取商品列表
  2143. * @param array $data
  2144. * @return array
  2145. * */
  2146. public function getWebsiteshopList(array $data): array
  2147. {
  2148. // return Result::success($data);
  2149. $where = [
  2150. 'status' => 2,
  2151. 'website_id' => $data['website_id'],
  2152. ];
  2153. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2154. // return Result::error("查询失败", 0);
  2155. // }
  2156. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2157. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2158. $data['catid'] = $category->category_id ?? 0;
  2159. }
  2160. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2161. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2162. }
  2163. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2164. array_push($where, ['type_id', $data['type_id']]);
  2165. }
  2166. $query = Good::where($where)
  2167. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2168. $query->where(function ($q) use ($data) {
  2169. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2170. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2171. });
  2172. })
  2173. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2174. $query->where(function ($q) use ($data) {
  2175. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2176. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2177. });
  2178. })
  2179. ->select(
  2180. 'good.id',
  2181. 'good.name',
  2182. 'good.imgurl',
  2183. 'good.description',
  2184. 'good.updated_at',
  2185. 'good.com',
  2186. 'good.catid',
  2187. 'good.type_id',
  2188. 'good.website_id',
  2189. 'good.cat_arr_id',
  2190. 'good.created_at',
  2191. 'good.city_id'
  2192. )
  2193. ->latest('updated_at');
  2194. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2195. $result['count'] = $query->clone()->count();
  2196. $result['goods'] = $this->processGoods(
  2197. $query->clone()
  2198. ->offset(($data['page'] - 1) * $data['pageSize'])
  2199. ->limit($data['pageSize'])
  2200. ->get(),
  2201. $data
  2202. );
  2203. } else {
  2204. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2205. // 获取 type_id 为 1 的数据
  2206. $result['type1'] = $this->processGoods(
  2207. $query->clone()
  2208. ->where('type_id', 1)
  2209. ->offset(($data['page'] - 1) * $data['pageSize'])
  2210. ->limit($data['pageSize'])
  2211. ->get(),
  2212. $data
  2213. );
  2214. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2215. // 获取 type_id 为 2 的数据
  2216. $result['type2'] = $this->processGoods(
  2217. $query->clone()
  2218. ->where('type_id', 2)
  2219. ->offset(($data['page'] - 1) * $data['pageSize'])
  2220. ->limit($data['pageSize'])
  2221. ->get(),
  2222. $data
  2223. );
  2224. }
  2225. if (empty($result)) {
  2226. return Result::error("查询失败", 0);
  2227. }
  2228. return Result::success($result);
  2229. }
  2230. /**
  2231. * 获取商品详情
  2232. * @param array $data
  2233. * @return array
  2234. * */
  2235. public function getWebsiteshopInfo(array $data): array
  2236. {
  2237. $where = [
  2238. 'good.status' => 2,
  2239. 'good.website_id' => $data['website_id'],
  2240. 'good.id' => $data['id'],
  2241. ];
  2242. $goods = Good::where($where)
  2243. ->where('good.id', $data['id'])
  2244. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2245. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2246. ->first();
  2247. if (empty($goods)) {
  2248. return Result::error("查询失败", 0);
  2249. }
  2250. $goods->imgurl = json_decode($goods->imgurl, true);
  2251. return Result::success($goods);
  2252. }
  2253. /**
  2254. * plus pro 处理文章路由问题
  2255. */
  2256. function processArticlePro($website_id)
  2257. {
  2258. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2259. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2260. // 取出category_id 对应的aLIas_pinyin
  2261. $categoryIds = array_column($categorys, 'category_id');
  2262. $categoryPIds = array_column($categorys, 'pid');
  2263. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2264. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2265. // return Result::success($categorys);
  2266. $catiall = [];
  2267. //一级所有子级的记录
  2268. $cat_1st_arr = [];
  2269. foreach ($categorys as $key => $value) {
  2270. $category_arr_id = json_decode($value->category_arr_id);
  2271. $pinyin_str = '';
  2272. // 算出一级 并且算出子级
  2273. if ($value->pid != 0) {
  2274. $cat_1st_arr[$value->pid][] = $value->category_id;
  2275. }
  2276. foreach ($category_arr_id as $k => $v) {
  2277. $pinyin_str .= $cat_arr[$v] . '/';
  2278. }
  2279. $pinyin_str = rtrim($pinyin_str, '/');
  2280. $catiall[$value->category_id]['alias'] = $value->alias;
  2281. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2282. $catiall[$value->category_id]['type'] = $value->type;
  2283. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2284. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2285. }
  2286. return [
  2287. 'cat_1st_arr' => $cat_1st_arr,
  2288. 'catiall' => $catiall,
  2289. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2290. 'categoryIds' => $categoryIds,
  2291. ];
  2292. }
  2293. /**
  2294. * 封装处理文章的路由问题
  2295. * */
  2296. function processArticles($articles, $data)
  2297. {
  2298. // 检查 $articles 是否为数组或可迭代对象
  2299. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2300. return $articles->map(function ($article) use ($data) {
  2301. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2302. $catid = $article->cat_arr_id ?? '';
  2303. }
  2304. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2305. $catid = $article->category_arr_id ?? '';
  2306. }
  2307. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2308. $level = json_decode($catid, true);
  2309. if (!is_array($level)) {
  2310. return $article;
  2311. } else {
  2312. $level = array_map('intval', $level);
  2313. }
  2314. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2315. ->where($data)
  2316. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2317. ->pluck('aLIas_pinyin')
  2318. ->implode('/');
  2319. $article->pinyin = $pinyin ?? '';
  2320. return $article;
  2321. });
  2322. } else {
  2323. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2324. $catid = $articles->cat_arr_id ?? '';
  2325. $level = json_decode($catid, true);
  2326. if (!is_array($level)) {
  2327. return $articles;
  2328. } else {
  2329. $level = array_map('intval', $level);
  2330. }
  2331. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2332. ->where($data)
  2333. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2334. ->pluck('aLIas_pinyin')
  2335. ->implode('/');
  2336. $articles->pinyin = $pinyin ?? '';
  2337. return $articles;
  2338. }
  2339. }
  2340. // 封装处理由问题
  2341. function processJob($job, $data)
  2342. {
  2343. return $job->map(function ($job) use ($data) {
  2344. $category = $job->cat_arr_id ?? '';
  2345. $cityid = $job->city_arr_id ?? '';
  2346. $city = json_decode($cityid, true);
  2347. $pinyin = '';
  2348. $level = json_decode($category, true);
  2349. // 路由
  2350. if (!empty($level) && is_array($level)) {
  2351. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2352. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2353. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2354. ->get(['aLIas_pinyin'])
  2355. ->pluck('aLIas_pinyin')
  2356. ->implode('/');
  2357. if (empty($pinyin)) {
  2358. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2359. }
  2360. $job->pinyin = $pinyin;
  2361. }
  2362. // 取职位-城市 市??省
  2363. if (!empty($city) && is_array($city)) {
  2364. if (isset($city[1]) && !empty($city[1])) {
  2365. $city = District::where('id', $city[1])->first(['name']);
  2366. $job->city_name = $city->name ?? '';
  2367. } else if (isset($city[0]) && !empty($city[0])) {
  2368. $city = District::where('id', $city[0])->first(['name']);
  2369. $job->city_name = $city->name ?? '';
  2370. } else {
  2371. $job->city_name = '全国';
  2372. }
  2373. }
  2374. // 获取简历最后一级地区
  2375. if (isset($job->city_id) && !empty($job->city_id)) {
  2376. $city = District::where('id', $job->city_id)->first(['name']);
  2377. $job->hunt_cityname = $city->name ?? '';
  2378. }
  2379. // 组合详细地址
  2380. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2381. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2382. if (is_array($address_id) && !empty($address_id)) {
  2383. $address = District::whereIn('id', $address_id)
  2384. ->orderBy('level', 'asc')
  2385. ->get(['name'])
  2386. ->pluck('name')
  2387. ->implode('');
  2388. // $job->address_name = $address ?? '';
  2389. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2390. }
  2391. }
  2392. // 取行业
  2393. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2394. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2395. if (!empty($job->industry)) {
  2396. $query->where('hyid', $job->industry);
  2397. } else if (!empty($job->hy_id)) {
  2398. $query->where('hyid', $job->hy_id);
  2399. } else if (!empty($job->company_hy_id)) {
  2400. $query->where('hyid', $job->company_hy_id);
  2401. } else {
  2402. $query->where('hyid', $job->job_industry);
  2403. }
  2404. })->first(['hyname']);
  2405. $job->hy_name = $hy_name->hyname ?? '';
  2406. }
  2407. // 取职位类别
  2408. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2409. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2410. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2411. $job->zw_name = $zw_name->zwname ?? '';
  2412. }
  2413. // 取具体职位
  2414. 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))) {
  2415. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2416. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2417. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2418. }
  2419. // 取工作经验
  2420. if (isset($job->experience) && !empty($job->experience)) {
  2421. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2422. $job->experience_name = $experience->ename ?? '';
  2423. }
  2424. // 取学历
  2425. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2426. $education = $job->educational ?? $job->school_education;
  2427. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2428. $job->education_name = $education->ename ?? '';
  2429. }
  2430. // 语言
  2431. if (isset($job->language) && !empty($job->language)) {
  2432. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2433. $job->language_name = $language->ename ?? '';
  2434. }
  2435. // 薪资
  2436. if (isset($job->salary) && !empty($job->salary)) {
  2437. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2438. $job->salary_name = $salary->ename ?? '';
  2439. }
  2440. // 职位性质
  2441. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2442. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2443. $job->job_nature_name = $job_nature->ename ?? '';
  2444. }
  2445. // 公司规模
  2446. if (isset($job->company_size) && !empty($job->company_size)) {
  2447. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2448. $job->company_size_name = $company_size->ename ?? '';
  2449. }
  2450. // 公司性质
  2451. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2452. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2453. $job->company_nature_name = $company_nature->nature_name ?? '';
  2454. }
  2455. // $job->pinyin = $pinyin;
  2456. return $job;
  2457. });
  2458. }
  2459. /**
  2460. * 获取书籍模块
  2461. * @param array $data
  2462. * @return array
  2463. * */
  2464. public function getWebsiteBook(array $data): array
  2465. {
  2466. $input['id'] = $data['id'];
  2467. $input['website_id'] = $data['website_id'];
  2468. // 将 JSON 字符串转换为 PHP 数组
  2469. $data = json_decode($input['id'], true);
  2470. // 使用 array_map 处理每个元素
  2471. $result = array_map(function ($item) use ($input) {
  2472. // 检查parent元素是否存在且不是undefined
  2473. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2474. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2475. $website = [
  2476. 'website_id' => $input['website_id'],
  2477. ];
  2478. // 查询栏目名称
  2479. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2480. if (empty($category)) {
  2481. $parent_alias = '';
  2482. $parent_pinyin = null;
  2483. $imgBooks = [];
  2484. $textBooks = [];
  2485. } else {
  2486. $parent_alias = $category->alias ?? '';
  2487. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2488. // 查找子分类ID数组
  2489. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2490. array_push($childCategoryIds, $parentCatId);
  2491. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2492. if ($parentImgNum != 0) {
  2493. // 查询图片新闻
  2494. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2495. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2496. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2497. })
  2498. ->where('book.status', 2)
  2499. ->where('book.img_url', '!=', '')
  2500. ->leftJoin('website_category', function ($join) use ($website) {
  2501. $join->on('book.cat_id', '=', 'website_category.category_id')
  2502. ->where('website_category.website_id', '=', $website['website_id']);
  2503. })
  2504. ->select(
  2505. 'book.id',
  2506. 'book.title',
  2507. 'book.img_url',
  2508. 'book.price',
  2509. 'book.market_price',
  2510. 'book.description',
  2511. 'book.cat_id',
  2512. 'book.description',
  2513. 'book.updated_at',
  2514. 'website_category.alias as category_name',
  2515. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2516. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2517. )
  2518. ->orderBy('updated_at', 'desc')
  2519. ->limit($parentImgNum)
  2520. ->get()->all();
  2521. // 查询文字新闻
  2522. }
  2523. if ($parentTextNum != 0) {
  2524. $textBooks = [];
  2525. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2526. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2527. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2528. })
  2529. ->where('book.status', 2)
  2530. ->leftJoin('website_category', function ($join) use ($website) {
  2531. $join->on('book.cat_id', '=', 'website_category.category_id')
  2532. ->where('website_category.website_id', '=', $website['website_id']);
  2533. })
  2534. ->select(
  2535. 'book.id',
  2536. 'book.title',
  2537. 'book.img_url',
  2538. 'book.price',
  2539. 'book.market_price',
  2540. 'book.description',
  2541. 'book.cat_id',
  2542. 'book.description',
  2543. 'book.updated_at',
  2544. 'website_category.alias as category_name',
  2545. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2546. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2547. )
  2548. ->orderBy('updated_at', 'desc')
  2549. ->limit($parentTextNum)
  2550. ->get()->all();
  2551. }
  2552. }
  2553. }
  2554. $resultItem = [
  2555. 'alias' => $parent_alias ?? '',
  2556. 'category_id' => $parentCatId ?? 0,
  2557. 'pinyin' => $parent_pinyin ?? null,
  2558. 'imgnum' => $imgBooks ?? [],
  2559. 'textnum' => $textBooks ?? [],
  2560. ];
  2561. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2562. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2563. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2564. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2565. ->get()->all();
  2566. if (!empty($childCategory)) {
  2567. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2568. // 查询子栏目名称
  2569. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2570. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2571. ->first();
  2572. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2573. $childImgArticles = [];
  2574. $childTextArticles = [];
  2575. $resultItem['child'] = [];
  2576. } else {
  2577. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2578. // 查询子栏目图片新闻
  2579. $childImgArticles = Book::where('cat_id', $childCatId)
  2580. ->where('status', 2)
  2581. ->where('img_url', '!=', '')
  2582. ->leftJoin('website_category', function ($join) use ($website) {
  2583. $join->on('book.cat_id', '=', 'website_category.category_id')
  2584. ->where('website_category.website_id', '=', $website['website_id']);
  2585. })
  2586. ->select(
  2587. 'book.id',
  2588. 'book.title',
  2589. 'book.img_url',
  2590. 'book.price',
  2591. 'book.market_price',
  2592. 'book.description',
  2593. 'book.cat_id',
  2594. 'book.description',
  2595. 'book.updated_at',
  2596. DB::raw("'$child_pinyin' as pinyin")
  2597. )
  2598. ->orderBy('updated_at', 'desc')
  2599. ->limit($childImgNum)
  2600. ->get()->all();
  2601. // 查询子栏目文字新闻
  2602. $childTextArticles = Book::where('cat_id', $childCatId)
  2603. ->where('status', 2)
  2604. ->leftJoin('website_category', function ($join) use ($website) {
  2605. $join->on('book.cat_id', '=', 'website_category.category_id')
  2606. ->where('website_category.website_id', '=', $website['website_id']);
  2607. })
  2608. ->select(
  2609. 'book.id',
  2610. 'book.title',
  2611. 'book.img_url',
  2612. 'book.price',
  2613. 'book.market_price',
  2614. 'book.description',
  2615. 'book.cat_id',
  2616. 'book.description',
  2617. 'book.updated_at',
  2618. DB::raw("'$child_pinyin' as pinyin")
  2619. )
  2620. ->orderBy('updated_at', 'desc')
  2621. ->limit($childTextNum)
  2622. ->get()->all();
  2623. $resultItem['child'] = [
  2624. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2625. 'category_id' => $childCatId,
  2626. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2627. 'all_childcat' => $childCategory,
  2628. 'imgnum' => $childImgArticles,
  2629. 'textnum' => $childTextArticles,
  2630. ];
  2631. }
  2632. }
  2633. } else {
  2634. $resultItem['child'] = [];
  2635. }
  2636. return $resultItem;
  2637. }, $data);
  2638. return Result::success($result);
  2639. }
  2640. /**
  2641. * 获取书刊列表
  2642. * @param array $data
  2643. * @return array
  2644. * */
  2645. public function getWebsiteBookList(array $data): array
  2646. {
  2647. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2648. if (empty($web)) {
  2649. return Result::error("查询失败", 0);
  2650. }
  2651. $catid = $data['id'];
  2652. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2653. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2654. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2655. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2656. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2657. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2658. ->where('pid', $category['pid'])
  2659. ->select(
  2660. 'category_id',
  2661. 'alias',
  2662. 'aLIas_pinyin',
  2663. 'pid',
  2664. 'sort',
  2665. 'is_url',
  2666. 'web_url',
  2667. 'seo_title',
  2668. 'seo_keywords',
  2669. 'seo_description',
  2670. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2671. )
  2672. ->orderBy('sort')
  2673. ->get()->all();
  2674. if (empty($category)) {
  2675. return Result::error("查询失败", 0);
  2676. }
  2677. $query = Book::where('book.status', 2)
  2678. ->where('book.website_id', $data['website_id'])
  2679. ->where('book.cat_id', $catid)
  2680. ->select(
  2681. 'book.id',
  2682. 'book.title',
  2683. 'book.img_url',
  2684. 'book.description',
  2685. 'book.updated_at',
  2686. 'book.cat_id',
  2687. DB::raw("'$pinyin' as pinyin")
  2688. )
  2689. ->orderBy('book.updated_at', 'desc');
  2690. $count = $query->count();
  2691. $query = clone $query;
  2692. $Book = $query
  2693. ->limit($data['pageSize'])
  2694. ->offset(($data['page'] - 1) * $data['pageSize'])
  2695. ->get()->all();
  2696. $result = [
  2697. 'category' => $categorys,
  2698. 'books' => $Book,
  2699. 'count' => $count,
  2700. ];
  2701. // if(empty($result)){
  2702. // return Result::error("查询失败", 0);
  2703. // }
  2704. return Result::success($result);
  2705. }
  2706. /**
  2707. * 获取书刊详情
  2708. * @param array $data
  2709. * @return array
  2710. * */
  2711. public function getWebsiteBookInfo(array $data): array
  2712. {
  2713. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2714. if (empty($web)) {
  2715. return Result::error("查询失败", 0);
  2716. }
  2717. $book = Book::where('status', 2)
  2718. ->where('website_id', $data['website_id'])
  2719. ->where('id', $data['id'])
  2720. ->select(
  2721. 'book.*',
  2722. )
  2723. ->orderBy('updated_at', 'desc')
  2724. ->first();
  2725. if (empty($book)) {
  2726. return Result::error("查询失败", 0);
  2727. }
  2728. // 先查询当前分类的 pid
  2729. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2730. ->where('category_id', $book['cat_id'])
  2731. ->first(['pid', 'category_id']);
  2732. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2733. if (!empty($carpid)) {
  2734. if ($carpid->pid != 0) {
  2735. $pid = $carpid['pid'];
  2736. // $parent_pinyin = '';
  2737. } else {
  2738. $pid = $carpid['category_id'];
  2739. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2740. }
  2741. }
  2742. $categorys = $query->where('pid', $pid)
  2743. ->select(
  2744. 'category_id',
  2745. 'alias',
  2746. 'aLIas_pinyin',
  2747. 'pid',
  2748. 'sort',
  2749. 'is_url',
  2750. 'web_url',
  2751. 'category_arr_id as cat_arr_id',
  2752. )
  2753. ->orderBy('sort')
  2754. ->get();
  2755. $category = $this->processArticle($categorys, $data);
  2756. $result = [
  2757. 'category' => $category,
  2758. 'books' => $book,
  2759. ];
  2760. return Result::success($result);
  2761. }
  2762. /**
  2763. * 尝试
  2764. * @param array $data
  2765. * @return array
  2766. * */
  2767. public function test(array $data): array
  2768. {
  2769. $input['id'] = $data['id'];
  2770. $input['website_id'] = $data['website_id'];
  2771. // 将 JSON 字符串转换为 PHP 数组
  2772. $data = json_decode($input['id'], true);
  2773. $result = [];
  2774. $article = $data;
  2775. $result = array_map(function ($item) use ($input) {
  2776. $website = [
  2777. 'website_id' => $input['website_id'],
  2778. ];
  2779. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2780. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2781. $parent = [
  2782. 0 => $category['category_id'] ?? [],
  2783. 1 => $parentImgNum ?? [],
  2784. 2 => $parentTextNum ?? [],
  2785. ];
  2786. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2787. $child = [];
  2788. $resultItem = [
  2789. // 'alias' => $parent_alias ?? '',
  2790. 'category_id' => $parentCatId ?? 0,
  2791. 'pinyin' => $parentImgNum ?? null,
  2792. 'imgnum' => $parentTextNum ?? [],
  2793. // 'textnum' => $textArticles ?? [],
  2794. ];
  2795. return $parent;
  2796. }, $data);
  2797. return Result::success($result);
  2798. // });
  2799. }
  2800. /**
  2801. * 封装处理文章的路由问题
  2802. * */
  2803. function processArticle($article, $data)
  2804. {
  2805. return $article->map(function ($article) use ($data) {
  2806. $catid = $article->cat_arr_id ?? '';
  2807. $level = json_decode($catid, true);
  2808. $pinyin = '';
  2809. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2810. if (!empty($level) && is_array($level)) {
  2811. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2812. ->where('website_id', $data['website_id'])
  2813. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2814. ->get(['aLIas_pinyin'])
  2815. ->pluck('aLIas_pinyin')
  2816. ->implode('/');
  2817. } else {
  2818. $pinyin = '';
  2819. }
  2820. $article->pinyin = $pinyin;
  2821. return $article;
  2822. });
  2823. }
  2824. /**
  2825. * c端-获取招工招聘下拉选框
  2826. * @param array $data
  2827. * @return array
  2828. * */
  2829. public function getWebsiteJobSelect(array $data): array
  2830. {
  2831. $web = Website::where('id', $data['website_id'])->first();
  2832. if (empty($web)) {
  2833. return Result::error("该网站不存在", 0);
  2834. }
  2835. $hy = JobIndustry::get()->all();
  2836. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2837. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2838. $result = [
  2839. 'hy' => $hy,
  2840. 'zw' => $zw,
  2841. 'jtzw' => $jtzw,
  2842. ];
  2843. if (empty($result)) {
  2844. return Result::error("查询失败", 0);
  2845. }
  2846. return Result::success($result);
  2847. }
  2848. /**
  2849. * c端-获取招工招聘
  2850. * @param array $data
  2851. * @return array
  2852. * */
  2853. public function getWebsiteJob(array $data): array
  2854. {
  2855. $web = Website::where('id', $data['website_id'])->first();
  2856. if (empty($web)) {
  2857. return Result::error("该网站不存在", 0);
  2858. }
  2859. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2860. ->where('job_hunting.website_id', $data['website_id'])
  2861. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2862. $query->where(function ($q) use ($data) {
  2863. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2864. });
  2865. })
  2866. ->select(
  2867. 'job_hunting.id',
  2868. 'job_hunting.cat_arr_id',
  2869. 'job_hunting.job_name_get',
  2870. 'job_hunting.industry',
  2871. 'job_hunting.name',
  2872. 'job_hunting.sexy',
  2873. 'job_hunting.origin',
  2874. 'job_hunting.city_arr_id',
  2875. 'job_hunting.experience',
  2876. 'job_hunting.updated_at',
  2877. 'job_hunting.salary'
  2878. )
  2879. ->orderBy('updated_at', 'desc')
  2880. ->limit($data['job1_num'])
  2881. ->get();
  2882. $web['website_id'] = $data['website_id'];
  2883. if (empty($job_hunting)) {
  2884. $job_huntings = "未查询到相关简历信息";
  2885. } else {
  2886. $job_huntings = $this->processJob($job_hunting, $web);
  2887. }
  2888. // 0:待审核 1:已通过 2:已拒绝
  2889. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2890. ->where('job_recruiting.website_id', $data['website_id'])
  2891. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2892. $query->where(function ($q) use ($data) {
  2893. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2894. });
  2895. })
  2896. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2897. ->select(
  2898. 'job_recruiting.id',
  2899. 'job_recruiting.cat_arr_id',
  2900. 'job_recruiting.title',
  2901. 'job_recruiting.jtzw_id',
  2902. 'job_recruiting.hy_id',
  2903. 'job_recruiting.city_arr_id',
  2904. 'job_recruiting.due_data',
  2905. 'job_recruiting.updated_at',
  2906. 'job_recruiting.experience',
  2907. 'job_recruiting.educational',
  2908. 'job_recruiting.salary',
  2909. 'job_recruiting.zw_id',
  2910. 'job_company.business_name'
  2911. )
  2912. ->orderBy('updated_at', 'desc')
  2913. ->limit($data['job2_num'])
  2914. ->get();
  2915. if (empty($job_recruiting->toArray())) {
  2916. $job_recruitings = "未查询到相关职位信息";
  2917. } else {
  2918. $job_recruitings = $this->processJob($job_recruiting, $web);
  2919. }
  2920. $result = [
  2921. 'job_hunting' => $job_huntings,
  2922. 'job_recuiting' => $job_recruitings,
  2923. ];
  2924. return Result::success($result);
  2925. }
  2926. /**
  2927. * c端-获取招工招聘列表
  2928. * @param array $data
  2929. * @return array
  2930. * */
  2931. public function getWebsiteJobList(array $data): array
  2932. {
  2933. $recruit_where = [];
  2934. $hunt_where = [];
  2935. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2936. if (empty($web)) {
  2937. return Result::error("此网站不存在", 0);
  2938. }
  2939. $website_id['website_id'] = $data['website_id'];
  2940. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2941. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2942. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2943. }
  2944. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2945. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2946. }
  2947. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2948. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2949. }
  2950. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2951. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2952. }
  2953. $query = JobRecruiting::where('job_recruiting.status', 1)
  2954. ->where('job_recruiting.website_id', $data['website_id'])
  2955. ->where($recruit_where)
  2956. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2957. $query->where(function ($q) use ($data) {
  2958. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2959. });
  2960. })
  2961. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2962. $query->where(function ($q) use ($data) {
  2963. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2964. });
  2965. })
  2966. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2967. ->select(
  2968. 'job_recruiting.id',
  2969. 'job_recruiting.hy_id',
  2970. 'job_recruiting.title',
  2971. 'job_recruiting.zw_id',
  2972. 'job_recruiting.educational',
  2973. 'job_recruiting.jtzw_id',
  2974. 'job_recruiting.city_arr_id',
  2975. 'job_recruiting.due_data',
  2976. 'job_recruiting.experience',
  2977. 'job_recruiting.cat_arr_id',
  2978. 'job_recruiting.updated_at',
  2979. 'job_company.business_name'
  2980. )
  2981. ->orderBy('job_recruiting.updated_at', 'desc');
  2982. $recruit_count = $query->count();
  2983. $query = clone $query;
  2984. $JobRecruiting = $query
  2985. ->offset(($data['page'] - 1) * $data['pageSize'])
  2986. ->limit($data['pageSize'])
  2987. ->get();
  2988. if (empty($JobRecruiting)) {
  2989. $JobRecruiting = "暂无相关职位信息";
  2990. } else {
  2991. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2992. }
  2993. }
  2994. if((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])){
  2995. if(isset($data['zw_id']) && !empty($data['zw_id'])){
  2996. array_push($hunt_where, ['job_hunting.job',$data['zw_id']]);
  2997. }
  2998. if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
  2999. array_push($hunt_where, ['job_hunting.job_name_get',$data['jtzw_id']]);
  3000. }
  3001. if(isset($data['hy_id']) && !empty($data['hy_id'])){
  3002. array_push($hunt_where, ['job_hunting.industry',$data['hy_id']]);
  3003. }
  3004. if(isset($data['keyword']) && !empty($data['keyword'])){
  3005. array_push($hunt_where, ['job_position.zwname','like','%'.$data['keyword'].'%']);
  3006. }
  3007. $query = JobHunting::where('job_hunting.status', 2)
  3008. ->where('job_hunting.website_id', $data['website_id'])
  3009. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3010. ->where($hunt_where)
  3011. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3012. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3013. // })
  3014. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  3015. $query->where(function($q) use ($data) {
  3016. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
  3017. });
  3018. })
  3019. ->when(isset($data['catid_id']) &&!empty($data['catid_id']), function ($query) use ($data) {
  3020. $query->where(function($q) use ($data) {
  3021. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '". intval($data['catid_id']). "') = 1");
  3022. });
  3023. })
  3024. ->select('job_hunting.id','job_hunting.sexy','job_hunting.experience','job_hunting.origin','job_hunting.industry',
  3025. 'job_hunting.name','job_hunting.job','job_hunting.job_name_get','job_hunting.city_arr_id','job_hunting.cat_arr_id',
  3026. 'job_hunting.created_at','job_hunting.updated_at','job_position.zwname as job_name')
  3027. ->orderBy('job_hunting.updated_at', 'desc');
  3028. $hunt_count = $query->count();
  3029. $query = clone $query;
  3030. $JobHunting = $query
  3031. ->offset(($data['page'] - 1) * $data['pageSize'])
  3032. ->limit($data['pageSize'])
  3033. ->get();
  3034. if (empty($JobHunting)) {
  3035. $JobRecruiting = "暂无相关简历信息";
  3036. } else {
  3037. $JobHunting = $this->processJob($JobHunting, $website_id);
  3038. }
  3039. }
  3040. $result = [
  3041. 'JobRecruiting' => $JobRecruiting ?? [],
  3042. 'recruit_count' => $recruit_count ?? 0,
  3043. 'JobHunting' => $JobHunting ?? [],
  3044. 'hunt_count' => $hunt_count ?? 0,
  3045. ];
  3046. return Result::success($result);
  3047. }
  3048. /**
  3049. * c端-获取招工招聘详情
  3050. * @param array $data
  3051. * @return array
  3052. * */
  3053. public function getWebsiteJobInfo(array $data): array
  3054. {
  3055. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3056. if (empty($web)) {
  3057. return Result::error("该网站不存在", 0);
  3058. }
  3059. $webid = [
  3060. 'website_id' => $data['website_id'],
  3061. ];
  3062. // 职位相关信息
  3063. if ($data['type'] == 1) {
  3064. $query = JobRecruiting::where('status', 1)
  3065. ->where('website_id', $data['website_id'])
  3066. ->select('*');
  3067. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3068. $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();
  3069. if (!empty($company)) {
  3070. $result['company'] = $this->processJob($company, $webid);
  3071. }
  3072. $other_job = JobRecruiting::where('status', 1)
  3073. ->where('website_id', $data['website_id'])
  3074. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3075. ->where('id', '!=', $data['id'])
  3076. ->where('user_id', '=', $job[0]['user_id'])
  3077. ->limit($data['pageSize'])
  3078. ->get();
  3079. if (!empty($other_job)) {
  3080. $result['other_job'] = $this->processJob($other_job, $webid);
  3081. }
  3082. } else {
  3083. // 简历相关信息
  3084. $job = JobHunting::where('job_hunting.status', 2)
  3085. ->where('job_hunting.website_id', $data['website_id'])
  3086. ->where('job_hunting.id', $data['id'])
  3087. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3088. ->select('job_hunting.*', 'user_name')
  3089. ->get();
  3090. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3091. if (!empty($resume->toArray())) {
  3092. $result['resume'] = 1;
  3093. } else {
  3094. $result['resume'] = 0;
  3095. }
  3096. }
  3097. if (empty($job->toArray())) {
  3098. return Result::error("id参数错误", 0);
  3099. }
  3100. if (!empty($job[0]['job_experience'])) {
  3101. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3102. if (!empty($job_experience)) {
  3103. // $hy = [];
  3104. foreach ($job_experience as $key => $value) {
  3105. // $id = $value['id'];
  3106. $hy[$key] = $value['job_industry'];
  3107. $zw_id[$key] = $value['job_typename'];
  3108. $jtzw_id[$key] = $value['job_name'];
  3109. }
  3110. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3111. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3112. // 先将关联表转换为索引数组,提高查找效率
  3113. $hyLookup = [];
  3114. foreach ($hy_table as $item) {
  3115. $hyLookup[$item['hyid']] = $item['hyname'];
  3116. }
  3117. $zwLookup = [];
  3118. foreach ($zw_table as $item) {
  3119. $zwLookup[$item['zwid']] = $item['zwname'];
  3120. }
  3121. foreach ($job_experience as $key => &$value) {
  3122. // 处理行业名称
  3123. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3124. $value['hy_name'] = $hyLookup[$hy[$key]];
  3125. }
  3126. // 处理职位名称
  3127. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3128. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3129. }
  3130. // 处理具体职位名称
  3131. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3132. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3133. }
  3134. }
  3135. // 释放引用,防止意外修改后续代码
  3136. unset($value);
  3137. }
  3138. $result['job_experience'] = $job_experience ?? [];
  3139. }
  3140. if (!empty($job[0]['education_experience'])) {
  3141. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3142. if (!empty($education_experience)) {
  3143. foreach ($education_experience as $key => $value) {
  3144. // $id = $value['id'];
  3145. $education[$key] = $value['school_education'];
  3146. }
  3147. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3148. // // 先将关联表转换为索引数组,提高查找效率
  3149. $educationLookup = [];
  3150. foreach ($education_table as $item) {
  3151. $educationLookup[$item['evalue']] = $item['ename'];
  3152. }
  3153. foreach ($education_experience as $key => &$value) {
  3154. // 处理学历名称
  3155. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3156. $value['education_name'] = $educationLookup[$education[$key]];
  3157. }
  3158. }
  3159. }
  3160. $result['education_experience'] = $job_experience ?? [];
  3161. }
  3162. $result['job'] = $this->processJob($job, $webid);
  3163. // // 返现对应的栏目
  3164. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3165. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3166. ->whereIn('category_id', $catid)
  3167. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3168. ->orderBy('pid')->get()->all();
  3169. if (!empty($category)) {
  3170. $result['category'] = $category;
  3171. }
  3172. $result['job'] = $job;
  3173. $result['job_experience'] = $job_experience ?? [];
  3174. $result['education_experience'] = $education_experience ?? [];
  3175. if (empty($result)) {
  3176. return Result::error("参数错误", 0);
  3177. }
  3178. return Result::success($result);
  3179. }
  3180. /**
  3181. * c端-申请职位
  3182. * @param array $data
  3183. * @return array
  3184. * */
  3185. public function getWebsiteJobApply(array $data): array
  3186. {
  3187. // 首先验证网站是否存在
  3188. // return Result::success($data);
  3189. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3190. if (empty($web)) {
  3191. return Result::error("该网站不存在", 0);
  3192. }
  3193. // 验证用户是否存在且为个人会员/管理员
  3194. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3195. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3196. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3197. return Result::error("用户不存在", 0);
  3198. }
  3199. // 去除重复元素和空元素,并保持原始顺序
  3200. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3201. return !empty($value);
  3202. }));
  3203. // 验证职位是否存在 1:审核通过
  3204. $recruiting = JobRecruiting::where('status', 1)
  3205. ->where('website_id', $data['website_id'])
  3206. ->whereIn('id', $data['recruit_id'])
  3207. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3208. if (empty($recruiting)) {
  3209. return Result::error("该职位不存在", 0);
  3210. }
  3211. // 简历是否存在
  3212. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3213. if (empty($hunt_id)) {
  3214. return Result::error("该简历不存在", 0);
  3215. }
  3216. $data['hunt_id'] = $hunt_id['hunt_id'];
  3217. // // 验证是否已投递过该职位
  3218. $apply = JobApply::where('user_id', $data['user_id'])
  3219. ->where('hunt_id', $data['hunt_id'])
  3220. ->where('website_id', $data['website_id'])
  3221. ->whereIn('recruit_id', $data['recruit_id'])
  3222. ->get(['recruit_id']);
  3223. if (!empty($apply->toArray())) {
  3224. return Result::error("您已投递过该职位!");
  3225. }
  3226. $insertData = array_map(function ($recruiting) use ($data) {
  3227. return [
  3228. 'user_id' => $data['user_id'],
  3229. 'hunt_id' => $data['hunt_id'],
  3230. 'website_id' => $data['website_id'],
  3231. 'recruit_id' => $recruiting['recruit_id'],
  3232. 'receiver_id' => $recruiting['receiver_id'],
  3233. 'status' => 1,
  3234. ];
  3235. }, $recruiting);
  3236. // 批量插入数据
  3237. $result = JobApply::insert($insertData);
  3238. if (empty($result)) {
  3239. return Result::error("投递失败", 0);
  3240. }
  3241. return Result::success($result);
  3242. }
  3243. /**
  3244. * 招工招聘-沟通简历
  3245. * @param array $data
  3246. * @return array
  3247. * */
  3248. public function getWebsiteJobResume(array $data): array
  3249. {
  3250. // 首先验证网站是否存在
  3251. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3252. if (empty($web)) {
  3253. return Result::error("该网站不存在", 0);
  3254. }
  3255. // return Result::success($data);
  3256. // 验证用户是否存在且为企业会员/管理员
  3257. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3258. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3259. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3260. return Result::error("用户不存在", 0);
  3261. }
  3262. // 去除重复元素和空元素,并保持原始顺序
  3263. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3264. return !empty($value);
  3265. }));
  3266. // 验证简历是否存在
  3267. $hunting = JobHunting::where('status', 2)
  3268. ->where('website_id', $data['website_id'])
  3269. ->whereIn('id', $data['hunt_id'])
  3270. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3271. if (empty($hunting)) {
  3272. return Result::error("该简历不存在", 0);
  3273. }
  3274. // 验证是否已沟通过该简历
  3275. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3276. ->where('recruit_id', $data['recruit_id'])
  3277. ->where('website_id', $data['website_id'])
  3278. ->whereIn('hunt_id', $data['hunt_id'])
  3279. ->get(['hunt_id']);
  3280. if (!empty($remuse->toArray())) {
  3281. return Result::error("您已沟通过该简历!");
  3282. }
  3283. // 准备要插入的数据数组
  3284. $insertData = array_map(function ($hunting) use ($data) {
  3285. return [
  3286. 'user_id' => $data['user_id'],
  3287. 'recruit_id' => $data['recruit_id'],
  3288. 'website_id' => $data['website_id'],
  3289. 'hunt_id' => $hunting['hunt_id'],
  3290. 'receiver_id' => $hunting['receiver_id'],
  3291. 'status' => 1,
  3292. ];
  3293. }, $hunting);
  3294. // 批量插入数据
  3295. $result = JobRemuse::insert($insertData);
  3296. if (empty($result)) {
  3297. return Result::error("沟通失败", 0);
  3298. }
  3299. return Result::success($result);
  3300. }
  3301. /**
  3302. * 招工招聘 -我的职位(企业会员)
  3303. * @param array $data
  3304. * @return array
  3305. */
  3306. public function getWebsiteJobRecruiting(array $data): array
  3307. {
  3308. $web = Website::where('id', $data['website_id'])->first('id');
  3309. if (empty($web)) {
  3310. return Result::error("该网站不存在", 0);
  3311. }
  3312. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3313. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3314. return Result::error("用户暂无权限!", 0);
  3315. }
  3316. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3317. $result = JobRecruiting::where('website_id', $data['website_id'])
  3318. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3319. $query->where('user_id', $user['id']);
  3320. })
  3321. ->where('status', 1)
  3322. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3323. ->orderBy('updated_at', 'desc')
  3324. ->limit($data['pageSize'])
  3325. ->get();
  3326. if (empty($result)) {
  3327. return Result::error("暂无相关职位信息", 0);
  3328. }
  3329. return Result::success($result);
  3330. }
  3331. /**
  3332. * c端 - 验证路由
  3333. * @param array $data
  3334. * @return array
  3335. */
  3336. /**
  3337. * c端 - 验证路由
  3338. * @param array $data
  3339. * @return array
  3340. */
  3341. public function checkWebsiteRoute(array $data): array
  3342. {
  3343. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3344. if (empty($web)) {
  3345. return Result::error("该网站不存在", 0);
  3346. } elseif ($web['status'] != 1) {
  3347. return Result::error("网站已经关闭", 0);
  3348. }
  3349. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3350. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3351. // 验证路由是否存在
  3352. if (empty($whiteRouterInfo)) {
  3353. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3354. }
  3355. if (!empty($whiteRouterInfo)) {
  3356. return Result::success($whiteRouterInfo->toArray());
  3357. }
  3358. }
  3359. // 验证栏目路由
  3360. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3361. ->where('aLIas_pinyin', $data['last_route'])
  3362. ->get()->all();
  3363. if (count($last_category) == 0) {
  3364. return Result::error("该栏目不存在", 0);
  3365. }
  3366. if(count($last_category) > 1){
  3367. return Result::error("该子级栏目存在多个,路由验证失败!", 0);
  3368. }
  3369. if(count($last_category) == 1){
  3370. $last_category = $last_category[0];
  3371. }
  3372. // return Result::success($last_category);
  3373. if (isset($data['id']) && !empty($data['id'])) {
  3374. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3375. switch ($last_category['type']) {
  3376. case 1:
  3377. // 文章
  3378. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3379. $article = Article::where('status', 1)
  3380. ->where('id', $data['id'])
  3381. ->where(function ($query) use ($data) {
  3382. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3383. ->orWhereNull("ignore_ids");
  3384. })
  3385. ->first(['cat_arr_id']);
  3386. if (empty($article)) {
  3387. return Result::error("该文章不存在", 0);
  3388. }
  3389. // return Result::success($article);
  3390. break;
  3391. case 2:
  3392. // 商品
  3393. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3394. $article = Good::where('website_id', $data['website_id'])
  3395. ->where('status', 2)
  3396. ->where('id', $data['id'])
  3397. ->first(['cat_arr_id']);
  3398. if (empty($article)) {
  3399. return Result::error("该商品不存在", 0);
  3400. }
  3401. break;
  3402. case 3:
  3403. // 书刊信息
  3404. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3405. $article = Book::where('website_id', $data['website_id'])
  3406. ->where('status', 2)
  3407. ->where('id', $data['id'])
  3408. ->first(['id', 'cat_arr_id']);
  3409. if (empty($article)) {
  3410. return Result::error("该书刊不存在", 0);
  3411. }
  3412. break;
  3413. case 4:
  3414. // 招聘
  3415. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3416. $article = JobRecruiting::where('website_id', $data['website_id'])
  3417. ->where('status', 1)
  3418. ->where('id', $data['id'])
  3419. ->first(['cat_arr_id']);
  3420. if (empty($article)) {
  3421. return Result::error("该招聘不存在", 0);
  3422. }
  3423. break;
  3424. case 5:
  3425. // 求职
  3426. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3427. $article = JobHunting::where('website_id', $data['website_id'])
  3428. ->where('status', 2)
  3429. ->where('id', $data['id'])
  3430. ->first(['cat_arr_id']);
  3431. if (empty($article)) {
  3432. return Result::error("该求职不存在", 0);
  3433. }
  3434. break;
  3435. case 6:
  3436. // 企业
  3437. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3438. $article = Company::where('website_id', $data['website_id'])
  3439. ->where('status', 1)
  3440. ->where('id', $data['id'])
  3441. ->first(['cat_arr_id']);
  3442. if (empty($article)) {
  3443. return Result::error("该企业不存在", 0);
  3444. }
  3445. break;
  3446. case 7:
  3447. // 项目
  3448. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3449. $article = Project::where('website_id', $data['website_id'])
  3450. ->where('status', 1)
  3451. ->where('id', $data['id'])
  3452. ->first(['cat_arr_id']);
  3453. if (empty($article)) {
  3454. return Result::error("该项目不存在", 0);
  3455. }
  3456. break;
  3457. default:
  3458. return Result::error("该数据不存在", 0);
  3459. break;
  3460. }
  3461. $catid =0 ;
  3462. $catidArray = json_decode($article['cat_arr_id'], true);
  3463. $catid = !empty($catidArray) ? end($catidArray) : null;
  3464. // return Result::success($article['cat_arr_id']);
  3465. if (empty($catid)) {
  3466. return Result::error("该数据不存在", 0);
  3467. }
  3468. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3469. ->where('category_id',$catid)
  3470. ->select('path')
  3471. ->pluck('path');
  3472. }else{
  3473. if ($last_category['pid'] != 0) {
  3474. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3475. $catid = !empty($cat_arr) ? end($cat_arr) : null;
  3476. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3477. ->where('category_id',$catid)
  3478. ->where('path',$data['all_route'])
  3479. ->pluck('path');
  3480. } else {
  3481. $pinyin[0] = $last_category['aLIas_pinyin'];
  3482. }
  3483. }
  3484. // return Result::success($pinyin[0]);
  3485. if (empty($pinyin) || count($pinyin)>1 || $pinyin[0] != $data['all_route']) {
  3486. return Result::error('非法路径!');
  3487. } else {
  3488. return Result::success($pinyin);
  3489. }
  3490. }
  3491. /**
  3492. * 招工招聘 - 获取推荐职位
  3493. * @param array $data
  3494. * @return array
  3495. */
  3496. public function getWebsiteLevelJob(array $data): array
  3497. {
  3498. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3499. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3500. ->where('job_recruiting.status', 1)
  3501. ->where('job_level', $data['job_level'])
  3502. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3503. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3504. ->orderBy('job_recruiting.updated_at', 'desc')
  3505. ->limit($data['pageSize'])
  3506. ->get();
  3507. $web = ['website_id' => $data['website_id']];
  3508. if (!empty($job)) {
  3509. $result = $this->processJob($job, $web);
  3510. }
  3511. if (empty($result)) {
  3512. return Result::error("暂无相关职位信息", 0);
  3513. }
  3514. return Result::success($result);
  3515. }
  3516. /**
  3517. * 验证导航名称是否重复
  3518. * @return void
  3519. */
  3520. //20250226 产品列表
  3521. public function getGoodList(array $data): array
  3522. {
  3523. var_dump($data, '---------1-2--');
  3524. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3525. unset($data['user_type_id']);
  3526. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3527. $where = [];
  3528. if ($type_id != '10000') {
  3529. $where = [
  3530. 'good.user_id' => $user_id,
  3531. ];
  3532. }
  3533. //类型
  3534. if (isset($data['type_id']) && $data['type_id']) {
  3535. $where['good.type_id'] = $data['type_id'];
  3536. }
  3537. //名称
  3538. if (isset($data['name']) && $data['name']) {
  3539. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3540. }
  3541. //status
  3542. if (isset($data['status']) && $data['status'] != '') {
  3543. $where['good.status'] = $data['status'];
  3544. }
  3545. //status1
  3546. // if (isset($data['status1']) && $data['status1'] == 1) {
  3547. // $status1 = 1;
  3548. // }
  3549. $where1 = [];
  3550. //website_id
  3551. // if (isset($data['website_id']) && $data['website_id']) {
  3552. // $where1 = [
  3553. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3554. // ];
  3555. // }
  3556. // website_name
  3557. if (isset($data['website_name']) && $data['website_name']) {
  3558. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3559. }
  3560. // catid
  3561. if (isset($data['category_name']) && $data['category_name']) {
  3562. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3563. }
  3564. // $result = Good::where($where)
  3565. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3566. var_dump($where, '---------1---');
  3567. $result = Good::where($where)
  3568. ->when(!empty($where1), function ($query) use ($where1) {
  3569. return $query->where($where1);
  3570. })
  3571. //status 1待审核2已审核3已拒绝
  3572. ->when(isset($data['status1']), function ($query) {
  3573. return $query->whereIn('good.status', [1, 3]);
  3574. })
  3575. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3576. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3577. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3578. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3579. ->orderBy("updated_at", "desc")
  3580. ->limit($data['page_size'])
  3581. ->offset(($data['page'] - 1) * $data['page_size'])
  3582. ->get();
  3583. $count = Good::where($where)
  3584. ->when(!empty($where1), function ($query) use ($where1) {
  3585. return $query->where($where1);
  3586. })
  3587. //status 1待审核2已审核3已拒绝
  3588. ->when(isset($data['status1']), function ($query) {
  3589. return $query->whereIn('good.status', [1, 3]);
  3590. })
  3591. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3592. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3593. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3594. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3595. ->orderBy("updated_at", "desc")->count();
  3596. $data = [
  3597. 'rows' => $result->toArray(),
  3598. 'count' => $count,
  3599. ];
  3600. if (empty($result)) {
  3601. return Result::error("此栏目暂无相关产品", 0);
  3602. }
  3603. return Result::success($data);
  3604. }
  3605. public function getGoodInfo(array $data): array
  3606. {
  3607. $result = Good::where('id', $data['id'])->first();
  3608. if (empty($result)) {
  3609. return Result::error("此产品不存在", 0);
  3610. }
  3611. return Result::success($result);
  3612. }
  3613. public function addGood(array $data): array
  3614. {
  3615. // unset($data['city_arr_id']);
  3616. // unset($data['cat_arr_id']);
  3617. $data['city_id'] = end($data['city_arr_id']);
  3618. $data['catid'] = end($data['cat_arr_id']);
  3619. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3620. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3621. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3622. unset($data['imgUrl']); //大小写
  3623. if (isset($data['price']) && $data['price'] == '') {
  3624. $data['price'] = 0;
  3625. }
  3626. if ($data['imgurl'] == '') {
  3627. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3628. preg_match_all($reg, $data['detail'], $matches);
  3629. if (isset($matches[1][0])) {
  3630. //截取varchar240
  3631. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3632. }
  3633. }
  3634. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3635. //提取标题+内容中的关键词
  3636. $data['keyword'] = $data['name'];
  3637. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3638. Jieba::init(); // 初始化 jieba-php
  3639. Finalseg::init();
  3640. $segList = Jieba::cut($data['keyword']);
  3641. $segList1 = array_slice($segList, 0, 8);
  3642. $data['keyword'] = implode(',', $segList1);
  3643. }
  3644. if ($data['description'] == '') {
  3645. //提取内容中的描述
  3646. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3647. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3648. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3649. }
  3650. if ($data['status'] == 1) {
  3651. $this->sendMessage([
  3652. 'talk_type' => 200,
  3653. 'title' => $data['name'],
  3654. 'content' => '提交了审核',
  3655. 'messageType' => 3,
  3656. ]);
  3657. }
  3658. $result = Good::insert($data);
  3659. if (empty($result)) {
  3660. return Result::error("添加失败", 0);
  3661. }
  3662. return Result::success($result);
  3663. }
  3664. public function updateGood(array $data): array
  3665. {
  3666. $data['city_id'] = end($data['city_arr_id']);
  3667. $data['catid'] = end($data['cat_arr_id']);
  3668. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3669. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3670. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3671. //设置东八区
  3672. date_default_timezone_set('Asia/Shanghai');
  3673. $data['updated_at'] = date('Y-m-d H:i:s');
  3674. if (isset($data['price']) && $data['price'] == '') {
  3675. $data['price'] = 0;
  3676. }
  3677. if ($data['imgurl'] == '') {
  3678. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3679. preg_match_all($reg, $data['detail'], $matches);
  3680. if (isset($matches[1][0])) {
  3681. //截取varchar240
  3682. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3683. }
  3684. }
  3685. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3686. //提取标题+内容中的关键词
  3687. $data['keyword'] = $data['name'];
  3688. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3689. Jieba::init(); // 初始化 jieba-php
  3690. Finalseg::init();
  3691. $segList = Jieba::cut($data['keyword']);
  3692. $segList1 = array_slice($segList, 0, 8);
  3693. $data['keyword'] = implode(',', $segList1);
  3694. }
  3695. if ($data['description'] == '') {
  3696. //提取内容中的描述
  3697. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3698. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3699. }
  3700. if ($data['status'] == 1) {
  3701. $this->sendMessage([
  3702. 'talk_type' => 200,
  3703. 'title' => $data['name'],
  3704. 'content' => '提交了审核',
  3705. 'messageType' => 3,
  3706. ]);
  3707. }
  3708. $result = Good::where('id', $data['id'])->update($data);
  3709. if (empty($result)) {
  3710. return Result::error("更新失败", 0);
  3711. }
  3712. return Result::success($result);
  3713. }
  3714. public function delGood(array $data): array
  3715. {
  3716. $result = Good::where('id', $data['id'])->delete();
  3717. if (empty($result)) {
  3718. return Result::error("删除失败", 0);
  3719. }
  3720. return Result::success($result);
  3721. }
  3722. //20250226 产品列表
  3723. //20250306 求职信息
  3724. public function getJobHuntingList(array $data): array
  3725. {
  3726. $where = [];
  3727. if (isset($data['username']) && !empty($data['username'])) {
  3728. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3729. }
  3730. //status 1待审核2已审核3已拒绝
  3731. if (isset($data['status']) && $data['status'] != '') {
  3732. $where = [
  3733. 'job_hunting.status' => $data['status'],
  3734. ];
  3735. }
  3736. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3737. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3738. unset($data['type_id']);
  3739. if ($type_id != '10000') {
  3740. $where[] = ['job_hunting.user_id', '=', $user_id];
  3741. }
  3742. $result = JobHunting::where($where)
  3743. ->when(!empty($data['status1']), function ($query) use ($data) {
  3744. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3745. })
  3746. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3747. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3748. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3749. ->orderBy("updated_at", "desc")
  3750. ->limit($data['page_size'])
  3751. ->offset(($data['page'] - 1) * $data['page_size'])
  3752. ->get();
  3753. if (empty($result)) {
  3754. return Result::error("查询失败", 0);
  3755. }
  3756. $count = JobHunting::where($where)
  3757. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3758. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3759. ->count();
  3760. $data = [
  3761. 'rows' => $result->toArray(),
  3762. 'count' => $count,
  3763. ];
  3764. return Result::success($data);
  3765. }
  3766. public function getJobHuntingApply(array $data): array
  3767. {
  3768. var_dump($data, '-----------------test--------1-');
  3769. $where = [];
  3770. if (isset($data['username']) && !empty($data['username'])) {
  3771. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3772. }
  3773. if (isset($data['salary']) && !empty($data['salary'])) {
  3774. $where[] = [
  3775. 'job_hunting.salary',
  3776. '=',
  3777. $data['salary'],
  3778. ];
  3779. }
  3780. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3781. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3782. unset($data['type_id']);
  3783. if ($type_id != '10000') {
  3784. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3785. }
  3786. var_dump($where, '-----------------test---------');
  3787. $result = jobApply::where($where)
  3788. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3789. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3790. // })
  3791. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3792. ->where('job_enum.egroup', '=', 'income')
  3793. ->where('job_hunting.status', 2) //已审核
  3794. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3795. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3796. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3797. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3798. //职位----是申请职位
  3799. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3800. ->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')
  3801. ->orderBy("job_hunting.updated_at", "desc")
  3802. ->limit($data['page_size'])
  3803. ->offset(($data['page'] - 1) * $data['page_size'])
  3804. ->get();
  3805. if (empty($result)) {
  3806. return Result::error("查询失败", 0);
  3807. }
  3808. $count = jobApply::where($where)
  3809. ->where('job_enum.egroup', '=', 'income')
  3810. ->where('job_hunting.status', 2) //已审核
  3811. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3812. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3813. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3814. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3815. //职位----是申请职位
  3816. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3817. ->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')
  3818. ->count();
  3819. $data = [
  3820. 'rows' => $result->toArray(),
  3821. 'count' => $count,
  3822. ];
  3823. return Result::success($data);
  3824. }
  3825. public function addJobHunting(array $data): array
  3826. {
  3827. date_default_timezone_set('Asia/Shanghai');
  3828. unset($data['company_name']);
  3829. unset($data['job_industry']);
  3830. unset($data['job_name']);
  3831. unset($data['department']);
  3832. unset($data['job_timeList']);
  3833. unset($data['job_content']);
  3834. unset($data['job_typename']); //不知道这是啥,
  3835. $data['created_at'] = date('Y-m-d H:i:s');
  3836. $data['updated_at'] = date('Y-m-d H:i:s');
  3837. //根据用户 user_id 只能添加一次
  3838. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3839. if (!empty($result)) {
  3840. return Result::error("您已添加过求职信息", 0);
  3841. }
  3842. var_dump($result, '-----------------test---------');
  3843. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3844. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3845. $cityArr = json_decode($data['city_arr_id'], true);
  3846. $data['city_id'] = end($cityArr);
  3847. } else {
  3848. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3849. $data['city_id'] = end($data['city_arr_id']);
  3850. }
  3851. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3852. $this->sendMessage([
  3853. 'talk_type' => 600,
  3854. 'title' => $data['name'],
  3855. 'content' => '提交了审核',
  3856. 'messageType' => 11,
  3857. ]);
  3858. }
  3859. $result = JobHunting::create($data);
  3860. if (empty($result)) {
  3861. return Result::error("添加失败", 0);
  3862. }
  3863. return Result::success($result);
  3864. }
  3865. public function delJobHunting(array $data): array
  3866. {
  3867. $result = JobHunting::where('id', $data['id'])->delete();
  3868. if (empty($result)) {
  3869. return Result::error("删除失败", 0);
  3870. }
  3871. return Result::success($result);
  3872. }
  3873. public function updateJobHunting(array $data): array
  3874. {
  3875. //设置东八区
  3876. date_default_timezone_set('Asia/Shanghai');
  3877. unset($data['company_name']);
  3878. unset($data['job_industry']);
  3879. unset($data['job_name']);
  3880. unset($data['department']);
  3881. unset($data['job_timeList']);
  3882. unset($data['job_content']);
  3883. unset($data['job_typename']); //不知道这是啥,
  3884. $data['created_at'] = date('Y-m-d H:i:s');
  3885. $data['updated_at'] = date('Y-m-d H:i:s');
  3886. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3887. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3888. $cityArr = json_decode($data['city_arr_id'], true);
  3889. $data['city_id'] = end($cityArr);
  3890. } else {
  3891. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3892. $data['city_id'] = end($data['city_arr_id']);
  3893. }
  3894. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3895. $this->sendMessage([
  3896. 'talk_type' => 600,
  3897. 'title' => $data['name'],
  3898. 'content' => '提交了审核',
  3899. 'messageType' => 11,
  3900. ]);
  3901. }
  3902. $result = JobHunting::where('id', $data['id'])->update($data);
  3903. if (empty($result)) {
  3904. return Result::error("更新失败", 0);
  3905. }
  3906. return Result::success($result);
  3907. }
  3908. public function getJobHuntingInfo(array $data): array
  3909. {
  3910. $result = JobHunting::where('id', $data['id'])->first();
  3911. if (empty($result)) {
  3912. return Result::error("查询失败", 0);
  3913. }
  3914. return Result::success($result);
  3915. }
  3916. public function getJobHuntingData(array $data): array
  3917. {
  3918. $jobEnum = JobEnum::get();
  3919. $jobIndustry = JobIndustry::get();
  3920. $jobNature = JobNature::get();
  3921. $jobPosition = JobPosition::get();
  3922. $data = [
  3923. 'jobEnum' => $jobEnum,
  3924. 'jobIndustry' => $jobIndustry,
  3925. 'jobNature' => $jobNature,
  3926. 'jobPosition' => $jobPosition,
  3927. ];
  3928. return Result::success($data);
  3929. }
  3930. public function delJobHuntingInfo(array $data): array
  3931. {
  3932. $result = JobHunting::where('id', $data['id'])->delete();
  3933. return Result::success();
  3934. }
  3935. //20250324 通知,公告,消息
  3936. public function delNotice(array $data): array
  3937. {
  3938. $result = Notice::where('id', $data['id'])->delete();
  3939. if ($result) {
  3940. return Result::success();
  3941. } else {
  3942. return Result::error("删除失败", 0);
  3943. }
  3944. }
  3945. public function getNoticeInfo(array $data): array
  3946. {
  3947. $result = Notice::where('id', $data['id'])->first();
  3948. // var_dump($result['re_user_ids'], '--------------------');
  3949. if (empty($result)) {
  3950. return Result::error("查询失败", 0);
  3951. }
  3952. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3953. $re_user_ids = json_decode($result['re_user_ids'], true);
  3954. var_dump($re_user_ids, '--------------1---test---------');
  3955. var_dump($data, '--------------1---test---------');
  3956. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3957. //如果已经存在,就不再添加
  3958. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3959. $read_id = json_decode($result['read_id'], true);
  3960. if (!is_array($read_id)) {
  3961. $read_id = [];
  3962. }
  3963. if (!in_array($data['user_id'], $read_id)) {
  3964. $read_id[] = $data['user_id'];
  3965. $result['read_id'] = json_encode($read_id);
  3966. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3967. }
  3968. } else {
  3969. //如果不存在,就添加
  3970. $result['read_id'] = json_encode([$data['user_id']]);
  3971. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3972. }
  3973. }
  3974. return Result::success($result);
  3975. }
  3976. public function addNotice(array $data): array
  3977. {
  3978. date_default_timezone_set('Asia/Shanghai');
  3979. $data['created_at'] = date('Y-m-d H:i:s');
  3980. $data['updated_at'] = date('Y-m-d H:i:s');
  3981. $user_id = UserInfo::
  3982. //city_id不是null
  3983. whereNotNull('city_id')
  3984. ->whereNotNull('department_id')
  3985. ->where(function ($query) use ($data) {
  3986. $query->where(function ($subQuery) use ($data) {
  3987. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3988. });
  3989. })
  3990. ->where(function ($query) use ($data) {
  3991. $query->where(function ($subQuery) use ($data) {
  3992. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3993. });
  3994. })
  3995. ->pluck('user_id')->toArray();
  3996. $user_id = array_unique($user_id);
  3997. $chat_ids = $user_id;
  3998. $user_id = json_encode($user_id);
  3999. $data['re_user_ids'] = $user_id;
  4000. $this->sendMessage([
  4001. 'talk_type' => 700,
  4002. 'title' => $data['title'],
  4003. 'content' => '提交了审核',
  4004. 'messageType' => 5,
  4005. ]);
  4006. $result = Notice::insertGetId($data);
  4007. if (empty($result)) {
  4008. return Result::error("添加失败", 0);
  4009. }
  4010. return Result::success($result);
  4011. }
  4012. public function updateNotice(array $data): array
  4013. {
  4014. date_default_timezone_set('Asia/Shanghai');
  4015. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4016. $user_id = UserInfo::
  4017. //city_id不是null
  4018. whereNotNull('city_id')
  4019. ->whereNotNull('department_id')
  4020. ->where(function ($query) use ($data) {
  4021. $query->where(function ($subQuery) use ($data) {
  4022. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4023. });
  4024. })
  4025. ->where(function ($query) use ($data) {
  4026. $query->where(function ($subQuery) use ($data) {
  4027. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4028. });
  4029. })
  4030. ->pluck('user_id')->toArray();
  4031. $user_id = array_unique($user_id);
  4032. $user_id = json_encode($user_id);
  4033. $data['re_user_ids'] = $user_id;
  4034. $data['updated_at'] = date('Y-m-d H:i:s');
  4035. $this->sendMessage([
  4036. 'talk_type' => 700,
  4037. 'title' => $data['title'],
  4038. 'content' => '提交了审核',
  4039. 'messageType' => 5,
  4040. ]);
  4041. $result = Notice::where('id', $data['id'])->update($data);
  4042. return Result::success($result);
  4043. }
  4044. public function getNoticeList(array $data): array
  4045. {
  4046. $where = [];
  4047. //title
  4048. if (isset($data['title']) && !empty($data['title'])) {
  4049. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4050. }
  4051. //level
  4052. if (isset($data['level']) && !empty($data['level'])) {
  4053. $where[] = ['notice.level', '=', $data['level']];
  4054. }
  4055. //status
  4056. if (isset($data['status']) && !empty($data['status'])) {
  4057. $where[] = ['notice.status', '=', $data['status']];
  4058. }
  4059. //type
  4060. if (isset($data['type']) && !empty($data['type'])) {
  4061. $where[] = ['notice.type', '=', $data['type']];
  4062. }
  4063. var_dump($data, '------------11111-2----test---------');
  4064. if ($data['type_id'] == 10000) {
  4065. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4066. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4067. })
  4068. ->where($where)
  4069. ->orderBy('updated_at', 'desc')
  4070. ->limit($data['page_size'])
  4071. ->offset(($data['page'] - 1) * $data['page_size'])
  4072. ->get();
  4073. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4074. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4075. })
  4076. ->where($where)
  4077. ->orderBy('updated_at', 'desc')
  4078. ->count();
  4079. } else {
  4080. $result = Notice::where($where)
  4081. // ->where('user_id', $data['user_id'])
  4082. ->Where(function ($query) use ($data) {
  4083. $query->Where(function ($q) use ($data) {
  4084. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4085. ->orWhere('notice.user_id', $data['user_id']);
  4086. });
  4087. })
  4088. ->when(!empty($data['status1']), function ($query) use ($data) {
  4089. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4090. })
  4091. ->orderBy('updated_at', 'desc')
  4092. ->limit($data['page_size'])
  4093. ->offset(($data['page'] - 1) * $data['page_size'])
  4094. ->get();
  4095. $total = Notice::where($where)
  4096. ->when(!empty($data['status1']), function ($query) use ($data) {
  4097. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4098. })
  4099. // ->where('user_id', $data['user_id'])
  4100. ->Where(function ($query) use ($data) {
  4101. $query->Where(function ($q) use ($data) {
  4102. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4103. ->orWhere('notice.user_id', $data['user_id']);
  4104. });
  4105. })
  4106. ->count();
  4107. }
  4108. if (empty($result)) {
  4109. return Result::error("查询失败", 0);
  4110. }
  4111. $data = [
  4112. 'rows' => $result,
  4113. 'count' => $total,
  4114. ];
  4115. return Result::success($data);
  4116. }
  4117. public function getNoticeDetail(array $data): array
  4118. {
  4119. $result = Notice::where('id', $data['id'])->first();
  4120. if (empty($result)) {
  4121. return Result::error("查询失败", 0);
  4122. }
  4123. return Result::success($result);
  4124. }
  4125. public function deleteNotice(array $data): array
  4126. {
  4127. $notice = Notice::where('id', $data['id'])->first();
  4128. if (empty($notice)) {
  4129. return Result::error("删除失败", 0);
  4130. }
  4131. $chat_group_id = $notice->group_id;
  4132. if ($chat_group_id) {
  4133. //删除群聊
  4134. ChatGroups::where('id', $chat_group_id)->delete();
  4135. //删除群成员
  4136. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4137. //删除群聊记录
  4138. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4139. }
  4140. $result = Notice::where('id', $data['id'])->delete();
  4141. return Result::success($result);
  4142. }
  4143. public function getComplaintList(array $data): array
  4144. {
  4145. var_dump($data, '00000001000000000000');
  4146. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4147. unset($data['type_id']);
  4148. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4149. $where = [];
  4150. if ($type_id != 10000 && empty($data['deal_user'])) {
  4151. $where['complaint.user_id'] = $user_id;
  4152. }
  4153. if (!empty($data['title'])) {
  4154. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4155. }
  4156. if (!empty($data['department_id'])) {
  4157. $where['complaint.department_id'] = $data['department_id'];
  4158. }
  4159. if (!empty($data['deal'])) {
  4160. $where['complaint.deal'] = $data['deal'];
  4161. }
  4162. if (!empty($data['status'])) {
  4163. $where['complaint.status'] = $data['status'];
  4164. }
  4165. var_dump(!empty($data['deal_user']), '----------1');
  4166. var_dump($where, '----------2');
  4167. $result = Complaint::where($where)
  4168. ->when(!empty($data['status1']), function ($query) use ($data) {
  4169. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4170. })
  4171. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4172. //json re_user_ids data[user_id]是不是在里面
  4173. $query->Where(function ($q) use ($data) {
  4174. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4175. ->where('complaint.status', 2);
  4176. });
  4177. })
  4178. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4179. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4180. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4181. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4182. ->orderBy('updated_at', 'desc')
  4183. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4184. //sql输出
  4185. if (empty($result)) {
  4186. return Result::error("暂无投诉信息", 0);
  4187. }
  4188. // 取出数据
  4189. $rows = $result->items();
  4190. $count = $result->total();
  4191. $responseData = [
  4192. 'rows' => $rows,
  4193. 'count' => $count,
  4194. ];
  4195. return Result::success($responseData);
  4196. }
  4197. public function getComplaintInfo(array $data): array
  4198. {
  4199. $result = Complaint::where('id', $data['id'])->first();
  4200. if (empty($result)) {
  4201. return Result::error("查询失败", 0);
  4202. }
  4203. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4204. $re_user_ids = json_decode($result['re_user_ids'], true);
  4205. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4206. //如果已经存在,就不再添加
  4207. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4208. $read_id = json_decode($result['read_id'], true);
  4209. if (!is_array($read_id)) {
  4210. $read_id = [];
  4211. }
  4212. if (!in_array($data['user_id'], $read_id)) {
  4213. $read_id[] = $data['user_id'];
  4214. $result['read_id'] = json_encode($read_id);
  4215. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4216. }
  4217. } else {
  4218. //如果不存在,就添加
  4219. $result['read_id'] = json_encode([$data['user_id']]);
  4220. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4221. }
  4222. }
  4223. return Result::success($result);
  4224. }
  4225. public function addComplaint(array $data): array
  4226. {
  4227. date_default_timezone_set('Asia/Shanghai');
  4228. $data['created_at'] = date('Y-m-d H:i:s');
  4229. $data['updated_at'] = date('Y-m-d H:i:s');
  4230. $this->sendMessage([
  4231. 'talk_type' => 800,
  4232. 'title' => $data['title'],
  4233. 'content' => '提交了审核',
  4234. 'messageType' => 6,
  4235. ]);
  4236. $result = Complaint::create($data);
  4237. return Result::success($result);
  4238. }
  4239. public function updateComplaint(array $data): array
  4240. {
  4241. date_default_timezone_set('Asia/Shanghai');
  4242. $data['updated_at'] = date('Y-m-d H:i:s');
  4243. $user_id = $data['user_id'] ?? 0;
  4244. $type_id = $data['type_id'] ?? 0;
  4245. unset($data['user_id']);
  4246. unset($data['type_id']);
  4247. $this->sendMessage([
  4248. 'talk_type' => 800,
  4249. 'title' => $data['title'],
  4250. 'content' => '提交了审核',
  4251. 'messageType' => 6,
  4252. ]);
  4253. $result = Complaint::where('id', $data['id'])->update($data);
  4254. return Result::success($result);
  4255. }
  4256. public function deleteComplaint(array $data): array
  4257. {
  4258. $result = Complaint::where('id', $data['id'])->delete();
  4259. return Result::success($result);
  4260. }
  4261. public function getComplainInfo(array $data): array
  4262. {
  4263. $result = Complaint::where('id', $data['id'])->first();
  4264. if (empty($result)) {
  4265. return Result::error("查询失败", 0);
  4266. }
  4267. return Result::success($result);
  4268. }
  4269. public function updateComplaintStatus(array $data): array
  4270. {
  4271. date_default_timezone_set('Asia/Shanghai');
  4272. $data['updated_at'] = date('Y-m-d H:i:s');
  4273. $user_id = $data['user_id'] ?? 0;
  4274. $type_id = $data['type_id'] ?? 0;
  4275. unset($data['user_id']);
  4276. unset($data['type_id']);
  4277. //处理, 写入处理人
  4278. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4279. $data['real_deal_user'] = $user_id;
  4280. }
  4281. //如果是deal 23,则判断是不是处理人
  4282. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4283. $complaintInof = Complaint::where('id', $data['id'])
  4284. ->where('real_deal_user', $user_id)
  4285. ->first();
  4286. if (empty($complaintInof)) {
  4287. return Result::error("处理人错误", 0);
  4288. }
  4289. }
  4290. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4291. if ($data['status'] == 1) {
  4292. $this->sendMessage([
  4293. 'talk_type' => 800,
  4294. 'title' => $complaintInfo['title'],
  4295. 'content' => '提交了审核',
  4296. 'messageType' => 6,
  4297. ]);
  4298. }
  4299. if ($data['status'] == 2 && !isset($data['deal'])) {
  4300. $this->sendMessage([
  4301. 'talk_type' => 801,
  4302. 'title' => $complaintInfo['title'],
  4303. 'content' => '审核通过',
  4304. 'messageType' => 6,
  4305. 'user_id' => $complaintInfo['user_id'],
  4306. ]);
  4307. $this->sendMessage([
  4308. 'talk_type' => 802,
  4309. 'title' => $complaintInfo['title'],
  4310. 'content' => '待处理',
  4311. 'messageType' => 6,
  4312. 'user_id' => $complaintInfo['re_user_ids'],
  4313. ]);
  4314. }
  4315. if ($data['status'] == 3 && !isset($data['deal'])) {
  4316. $this->sendMessage([
  4317. 'talk_type' => 801,
  4318. 'title' => $complaintInfo['title'],
  4319. 'content' => '审核拒绝',
  4320. 'messageType' => 6,
  4321. 'user_id' => $complaintInfo['user_id'],
  4322. ]);
  4323. }
  4324. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4325. $this->sendMessage([
  4326. 'talk_type' => 802,
  4327. 'title' => $complaintInfo['title'],
  4328. 'content' => '处理中',
  4329. 'messageType' => 6,
  4330. 'user_id' => $complaintInfo['re_user_ids'],
  4331. ]);
  4332. }
  4333. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4334. $this->sendMessage([
  4335. 'talk_type' => 802,
  4336. 'title' => $complaintInfo['title'],
  4337. 'content' => '不予处理',
  4338. 'messageType' => 6,
  4339. 'user_id' => $complaintInfo['re_user_ids'],
  4340. ]);
  4341. }
  4342. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4343. $this->sendMessage([
  4344. 'talk_type' => 802,
  4345. 'title' => $complaintInfo['title'],
  4346. 'content' => '已完结',
  4347. 'messageType' => 6,
  4348. 'user_id' => $complaintInfo['re_user_ids'],
  4349. ]);
  4350. }
  4351. $result = complaint::where('id', $data['id'])->update($data);
  4352. return Result::success($result);
  4353. }
  4354. public function updateGoodStatus(array $data): array
  4355. {
  4356. $user_id = $data['user_id'] ?? 0;
  4357. $type_id = $data['type_id'] ?? 0;
  4358. unset($data['user_id']);
  4359. unset($data['type_id']);
  4360. $goodInfo = Good::where('id', $data['id'])->first();
  4361. if ($data['status'] == 2) {
  4362. $this->sendMessage([
  4363. 'talk_type' => 201,
  4364. 'title' => $goodInfo['name'],
  4365. 'content' => '审核通过',
  4366. 'messageType' => 3,
  4367. 'user_id' => $goodInfo['user_id'],
  4368. ]);
  4369. }
  4370. if ($data['status'] == 3) {
  4371. $this->sendMessage([
  4372. 'talk_type' => 201,
  4373. 'title' => $goodInfo['name'],
  4374. 'content' => '审核拒绝',
  4375. 'messageType' => 3,
  4376. 'user_id' => $goodInfo['user_id'],
  4377. ]);
  4378. }
  4379. if ($data['status'] == 1) {
  4380. $this->sendMessage([
  4381. 'talk_type' => 200,
  4382. 'title' => $goodInfo['name'],
  4383. 'content' => '提交了审核',
  4384. 'messageType' => 3,
  4385. ]);
  4386. }
  4387. $result = Good::where('id', $data['id'])->update($data);
  4388. return Result::success($result);
  4389. }
  4390. public function updateJobHuntingStatus(array $data): array
  4391. {
  4392. $user_id = $data['user_id'] ?? 0;
  4393. $type_id = $data['type_id'] ?? 0;
  4394. unset($data['user_id']);
  4395. unset($data['type_id']);
  4396. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4397. if ($data['status'] == 2) {
  4398. $this->sendMessage([
  4399. 'talk_type' => 601,
  4400. 'title' => $jogHuntingInfo['name'],
  4401. 'content' => '审核通过',
  4402. 'messageType' => 11,
  4403. 'user_id' => $jogHuntingInfo['user_id'],
  4404. ]);
  4405. }
  4406. if ($data['status'] == 3) {
  4407. $this->sendMessage([
  4408. 'talk_type' => 601,
  4409. 'title' => $jogHuntingInfo['name'],
  4410. 'content' => '审核拒绝',
  4411. 'messageType' => 11,
  4412. 'user_id' => $jogHuntingInfo['user_id'],
  4413. ]);
  4414. }
  4415. if ($data['status'] == 1) {
  4416. $this->sendMessage([
  4417. 'talk_type' => 600,
  4418. 'title' => $jogHuntingInfo['name'],
  4419. 'content' => '提交了审核',
  4420. 'messageType' => 11,
  4421. ]);
  4422. }
  4423. $result = JobHunting::where('id', $data['id'])->update($data);
  4424. return Result::success($result);
  4425. }
  4426. public function updateNoticeStatus(array $data): array
  4427. {
  4428. $user_id = $data['user_id'] ?? 0;
  4429. $type_id = $data['type_id'] ?? 0;
  4430. unset($data['user_id']);
  4431. unset($data['type_id']);
  4432. //查询公告
  4433. $notice = Notice::where('id', $data['id'])->first();
  4434. if (empty($notice)) {
  4435. return Result::error("公告不存在", 0);
  4436. }
  4437. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4438. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4439. //chat_group
  4440. $group_id = PublicData::uuid();
  4441. $groupData = [
  4442. 'id' => $group_id,
  4443. 'creator_id' => $notice['user_id'],
  4444. 'group_name' => $notice['group_name'] ?? '',
  4445. 'profile' => $notice['profile'] ?? 0,
  4446. ];
  4447. var_dump($groupData, '-----------------groupData-------');
  4448. $groupResult = ChatGroups::insertGetId($groupData);
  4449. var_dump($groupResult, '-----------------groupid-------');
  4450. $groupMemberData = [
  4451. 'id' => PublicData::uuid(),
  4452. 'user_id' => $notice['user_id'],
  4453. 'group_id' => $group_id,
  4454. 'leader' => 2,
  4455. ];
  4456. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4457. //$chat_ids 去除掉$data['user_id']
  4458. $chat_ids = json_decode($notice['re_user_ids'], true);
  4459. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4460. //插入群成员表
  4461. $groupMemberDataUser = [];
  4462. $chatData = [];
  4463. foreach ($chat_ids as $key => $value) {
  4464. $groupMemberDataUser[] = [
  4465. 'id' => PublicData::uuid(),
  4466. 'user_id' => $value,
  4467. 'group_id' => $group_id,
  4468. 'leader' => 1,
  4469. ];
  4470. $chatData[] = [
  4471. 'user_id' => $value,
  4472. 'msg_type' => 1,
  4473. 'receiver_id' => $group_id,
  4474. 'content' => '通过通知创建群聊',
  4475. 'group_receiver_id' => $notice['user_id'],
  4476. 'action' => 'recieved',
  4477. 'created_at' => date('Y-m-d H:i:s'),
  4478. ];
  4479. }
  4480. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4481. ChatGroupsMember::insert($groupMemberDataUser);
  4482. //插入一条管理员聊天记录
  4483. $chatData[] = [
  4484. 'user_id' => $notice['user_id'],
  4485. 'msg_type' => 1,
  4486. 'receiver_id' => $group_id,
  4487. 'content' => '通过通知创建群聊',
  4488. 'group_receiver_id' => $notice['user_id'],
  4489. 'action' => 'said',
  4490. 'created_at' => date('Y-m-d H:i:s'),
  4491. ];
  4492. var_dump($chatData, '-----------------chatData-------');
  4493. $chatResult = ChatRecords::insert($chatData);
  4494. //更新result的 group_id
  4495. $data['group_id'] = $group_id;
  4496. Notice::where(['id' => $data['id']])->update($data);
  4497. }
  4498. $result = Notice::where('id', $data['id'])->update($data);
  4499. $noticeInfo = Notice::where('id', $data['id'])->first();
  4500. if ($data['status'] == 2) {
  4501. $this->sendMessage([
  4502. 'talk_type' => 701,
  4503. 'title' => $noticeInfo['title'],
  4504. 'content' => '审核通过',
  4505. 'messageType' => 3,
  4506. 'user_id' => $noticeInfo['user_id'],
  4507. ]);
  4508. }
  4509. if ($data['status'] == 3) {
  4510. $this->sendMessage([
  4511. 'talk_type' => 701,
  4512. 'title' => $noticeInfo['title'],
  4513. 'content' => '审核拒绝',
  4514. 'messageType' => 3,
  4515. 'user_id' => $noticeInfo['user_id'],
  4516. ]);
  4517. }
  4518. if ($data['status'] == 1) {
  4519. $this->sendMessage([
  4520. 'talk_type' => 700,
  4521. 'title' => $noticeInfo['title'],
  4522. 'content' => '提交了审核',
  4523. 'messageType' => 3,
  4524. ]);
  4525. }
  4526. return Result::success($result);
  4527. }
  4528. public function getDUser(array $data): array
  4529. {
  4530. if (!empty($data['ids'])) {
  4531. $user = User::whereIn('id', $data['ids'])->getall();
  4532. if (empty($user)) {
  4533. return Result::error('无数据', 0);
  4534. }
  4535. return Result::success($user);
  4536. }
  4537. $where = [];
  4538. if (!empty($data['department_id'])) {
  4539. $where['department_id'] = $data['department_id'];
  4540. }
  4541. if (!empty($data['city_id'])) {
  4542. $where['city_id'] = $data['city_id'];
  4543. }
  4544. $result = User::where('type_id', 2)
  4545. ->where('status', 1)
  4546. ->where($where)
  4547. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4548. ->get();
  4549. if (empty($result)) {
  4550. return Result::error("查询失败", 0);
  4551. }
  4552. return Result::success($result);
  4553. }
  4554. /**
  4555. * 验证导航名称是否重复
  4556. * @return void
  4557. */
  4558. public function checkCategoryName(array $data): array
  4559. {
  4560. $result = Category::when($data, function ($query) use ($data) {
  4561. if (isset($data['name']) && $data['name']) {
  4562. $query->where("name", $data['name']);
  4563. }
  4564. if (isset($data['id']) && $data['id']) {
  4565. $query->where("id", "!=", $data['id']);
  4566. }
  4567. })->first();
  4568. if ($result) {
  4569. return Result::error("已存在");
  4570. } else {
  4571. return Result::success();
  4572. }
  4573. }
  4574. //20250226 产品列表
  4575. // 20250306 -------招聘--------fr
  4576. /*
  4577. * 招聘列表
  4578. * */
  4579. public function getJobRecruitingList(array $data): array
  4580. {
  4581. $where = [];
  4582. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4583. if ($data['checkout'] == 0) {
  4584. $job_status = [0, 2];
  4585. } else {
  4586. $job_status = [1];
  4587. }
  4588. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4589. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4590. }
  4591. $user = User::where('id', $data['user_id'])->first();
  4592. if (empty($user)) {
  4593. return Result::error("用户不存在", 0);
  4594. }
  4595. // 3:企业会员
  4596. if ($user['type_id'] == 3) {
  4597. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4598. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4599. }
  4600. // 如果 $where 为空,则不添加 where 条件
  4601. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4602. return $query->where($where);
  4603. })
  4604. ->whereIn('job_recruiting.status', $job_status)
  4605. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4606. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4607. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4608. ->orderBy("updated_at", "desc")
  4609. ->offset(($data['page'] - 1) * $data['page_size'])
  4610. ->limit($data['page_size'])
  4611. ->get()
  4612. ->all();
  4613. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4614. return $query->where($where);
  4615. })
  4616. ->whereIn('job_recruiting.status', $job_status)
  4617. ->count();
  4618. if (empty($result)) {
  4619. return Result::error("暂无招聘信息", 0);
  4620. }
  4621. return Result::success($result);
  4622. }
  4623. /*
  4624. * 招聘信息添加
  4625. * */
  4626. public function addJobRecruiting(array $data): array
  4627. {
  4628. // return Result::success($data);
  4629. $user = User::where('user.id', $data['user_id'])
  4630. ->where('user.status', 1)
  4631. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4632. ->select(
  4633. 'user.type_id',
  4634. 'user.mobile',
  4635. 'user.email',
  4636. 'user_info.business_name',
  4637. 'user_info.company_hy_id',
  4638. 'user_info.company_nature',
  4639. 'user_info.company_size',
  4640. 'user_info.introduction',
  4641. 'user_info.real_name',
  4642. 'user_info.company_url',
  4643. 'user_info.address_arr_id',
  4644. 'user_info.address'
  4645. )
  4646. ->first();
  4647. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4648. return Result::error("用户不存在", 0);
  4649. }
  4650. $web = Website::where('id', $data['website_id'])->first();
  4651. if (empty($web)) {
  4652. return Result::error("网站不存在", 0);
  4653. }
  4654. // return Result::success($user);
  4655. $data['action_id'] = $data['user_id'];
  4656. $data['user_type'] = $user['type_id'];
  4657. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4658. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4659. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4660. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4661. // 公司地址 管理员必填
  4662. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4663. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4664. // 管理员-企业相关信息
  4665. $company = [
  4666. // 'user_id' => $data['user_id']?? null,
  4667. 'business_name' => $data['business_name'] ?? null,
  4668. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4669. 'company_size' => $data['company_size'] ?? null,
  4670. 'company_nature' => $data['company_nature'] ?? null,
  4671. 'introduction' => $data['introduction'] ?? null,
  4672. 'real_name' => $data['real_name'] ?? null,
  4673. 'mobile' => $data['mobile'] ?? null,
  4674. 'company_url' => $data['company_url'] ?? null,
  4675. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4676. 'address' => $data['address'] ?? null,
  4677. 'email' => $data['email'] ?? null,
  4678. ];
  4679. //去掉相关企业信息
  4680. $job = array_diff_key($data, array_flip(array_keys($company)));
  4681. Db::beginTransaction();
  4682. try {
  4683. // 先添加职位相关信息
  4684. if ($user['type_id'] == 10000) {
  4685. $job['status'] = 1;
  4686. }
  4687. if (empty($data['experience']) || $data['experience'] == '') {
  4688. $job['experience'] = null;
  4689. } else {
  4690. $job['experience'] = $data['experience'];
  4691. }
  4692. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4693. $this->sendMessage([
  4694. 'talk_type' => 500,
  4695. 'title' => $data['title'],
  4696. 'content' => '提交了审核',
  4697. 'messageType' => 10,
  4698. ]);
  4699. }
  4700. $jobId = JobRecruiting::insertGetId($job);
  4701. if (empty($jobId)) {
  4702. Db::rollBack();
  4703. return Result::error("添加失败");
  4704. }
  4705. // 添加公司信息
  4706. $company['user_id'] = $data['user_id'] ?? null;
  4707. $company['job_id'] = $jobId;
  4708. $company['user_type'] = $user['type_id'] ?? null;
  4709. $company['website_id'] = $data['website_id'] ?? null;
  4710. if ($user['type_id'] == 10000) {
  4711. // 管理员添加企业信息
  4712. // return Result::success($company);
  4713. $companyId = JobCompany::insertGetId($company);
  4714. if (empty($companyId)) {
  4715. Db::rollBack();
  4716. return Result::error("添加失败");
  4717. }
  4718. } else {
  4719. // 企业会员添加企业信息
  4720. $company = [
  4721. 'user_id' => $data['user_id'] ?? null,
  4722. 'business_name' => $user['business_name'] ?? null,
  4723. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4724. 'company_size' => $user['company_size'] ?? null,
  4725. 'company_nature' => $user['company_nature'] ?? null,
  4726. 'introduction' => $user['introduction'] ?? null,
  4727. 'real_name' => $user['real_name'] ?? null,
  4728. 'mobile' => $user['mobile'] ?? null,
  4729. 'company_url' => $user['company_url'] ?? null,
  4730. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4731. 'address' => $user['address'] ?? null,
  4732. 'email' => $user['email'] ?? null,
  4733. 'website_id' => $data['website_id'] ?? null,
  4734. 'user_type' => $user['type_id'] ?? null,
  4735. 'job_id' => $jobId,
  4736. ];
  4737. $companyId = JobCompany::insertGetId($company);
  4738. if (empty($companyId)) {
  4739. Db::rollBack();
  4740. return Result::error("添加失败");
  4741. }
  4742. // return Result::success($company);
  4743. }
  4744. Db::commit();
  4745. } catch (\Exception $e) {
  4746. Db::rollBack();
  4747. return Result::error($e->getMessage(), 0);
  4748. }
  4749. $result = [
  4750. 'job_id' => $jobId,
  4751. 'company_id' => $companyId,
  4752. ];
  4753. if (empty($result)) {
  4754. return Result::error("添加失败", 0);
  4755. }
  4756. return Result::success($result);
  4757. }
  4758. /*
  4759. * 获取招聘信息详情
  4760. * */
  4761. public function getJobRecruitingInfo(array $data): array
  4762. {
  4763. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4764. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4765. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4766. ->select(
  4767. 'job_recruiting.*',
  4768. 'website.website_name as website_name',
  4769. 'job_company.business_name',
  4770. 'job_company.company_hy_id',
  4771. 'job_company.company_size',
  4772. 'job_company.company_nature',
  4773. 'job_company.introduction',
  4774. 'job_company.real_name',
  4775. 'job_company.mobile',
  4776. 'job_company.company_url',
  4777. 'job_company.address_arr_id',
  4778. 'job_company.address',
  4779. 'job_company.email'
  4780. )
  4781. ->first();
  4782. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4783. if (!empty($cityId)) {
  4784. if (isset($cityId[1]) && $cityId[1] != null) {
  4785. $city = District::where('id', $cityId[1])->first(['name']);
  4786. } else {
  4787. $city = District::where('id', $cityId[0])->first(['name']);
  4788. }
  4789. $result['city'] = $city['name'] ?? '';
  4790. }
  4791. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4792. if (is_array($addressId) && !empty($addressId)) {
  4793. $address = District::whereIn('id', $addressId)
  4794. ->orderBy('level', 'asc')
  4795. ->get(['name'])
  4796. ->pluck('name')
  4797. ->implode('');
  4798. // $job->address_name = $address ?? '';
  4799. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4800. }
  4801. if (empty($result)) {
  4802. return Result::error("招聘信息不存在", 0);
  4803. }
  4804. // return Result::success($job);
  4805. return Result::success($result);
  4806. }
  4807. /*
  4808. * 修改招聘信息
  4809. * */
  4810. public function upJobRecruiting(array $data): array
  4811. {
  4812. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4813. // return Result::success($job);
  4814. if (empty($job)) {
  4815. return Result::error("招聘信息不存在", 0);
  4816. }
  4817. $user = User::where('id', $data['user_id'])->first();
  4818. // return Result::success($user);
  4819. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4820. return Result::error("用户不存在", 0);
  4821. }
  4822. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4823. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4824. }
  4825. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4826. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4827. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4828. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4829. // 公司地址 管理员必填
  4830. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4831. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4832. // 管理员-企业相关信息
  4833. $company = [
  4834. 'business_name' => $data['business_name'] ?? null,
  4835. 'company_hy_id' => $data['hy_id'] ?? null,
  4836. 'company_size' => $data['company_size'] ?? null,
  4837. 'company_nature' => $data['company_nature'] ?? null,
  4838. 'introduction' => $data['introduction'] ?? null,
  4839. 'real_name' => $data['real_name'] ?? null,
  4840. 'mobile' => $data['mobile'] ?? null,
  4841. 'company_url' => $data['company_url'] ?? null,
  4842. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4843. 'address' => $data['address'] ?? null,
  4844. 'email' => $data['email'] ?? null,
  4845. ];
  4846. //去掉相关企业信息
  4847. $data = array_diff_key($data, array_flip(array_keys($company)));
  4848. $jobId = $data['id'];
  4849. $web = $data['website_id'];
  4850. $data['action_id'] = $data['user_id'];
  4851. unset($data['user_id']);
  4852. unset($data['user_type']);
  4853. unset($data['id']);
  4854. unset($data['website_id']);
  4855. // return Result::success($data);
  4856. Db::beginTransaction();
  4857. try {
  4858. // 管理员修改招聘信息
  4859. if ($user['type_id'] == 10000) {
  4860. $data['website_id'] = $web;
  4861. $company['website_id'] = $data['website_id'];
  4862. $data['status'] = 1;
  4863. } else {
  4864. $data['status'] = 0;
  4865. }
  4866. if (empty($data['experience']) || $data['experience'] == '') {
  4867. $job['experience'] = null;
  4868. } else {
  4869. $job['experience'] = $data['experience'];
  4870. }
  4871. // Db::rollBack();
  4872. // return Result::success($company);
  4873. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4874. $this->sendMessage([
  4875. 'talk_type' => 500,
  4876. 'title' => $data['title'],
  4877. 'content' => '提交了审核',
  4878. 'messageType' => 10,
  4879. ]);
  4880. }
  4881. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4882. if (empty($result['job'])) {
  4883. Db::rollBack();
  4884. return Result::error("修改招聘信息失败");
  4885. }
  4886. // 管理员修改企业相关信息
  4887. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4888. if (empty($result['company'])) {
  4889. Db::rollBack();
  4890. return Result::error("修改企业相关信息失败");
  4891. }
  4892. Db::commit();
  4893. // return Result::success($result);
  4894. } catch (\Exception $e) {
  4895. Db::rollBack();
  4896. return Result::error($e->getMessage(), 0);
  4897. }
  4898. return Result::success($result);
  4899. }
  4900. /*
  4901. * 招聘信息删除
  4902. * */
  4903. public function delJobRecruiting(array $data): array
  4904. {
  4905. $user = User::where('id', $data['user_id'])->first();
  4906. if (empty($user)) {
  4907. return Result::error("用户不存在", 0);
  4908. }
  4909. $job = JobRecruiting::where('id', $data['id'])->first();
  4910. if (empty($job)) {
  4911. return Result::error("招聘信息不存在", 0);
  4912. }
  4913. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4914. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4915. }
  4916. Db::beginTransaction();
  4917. try {
  4918. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4919. if (empty($result['job'])) {
  4920. Db::rollBack();
  4921. return Result::error("删除招聘信息失败");
  4922. }
  4923. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4924. if (empty($result['company'])) {
  4925. Db::rollBack();
  4926. return Result::error("删除企业相关信息失败");
  4927. }
  4928. Db::commit();
  4929. } catch (\Exception $e) {
  4930. Db::rollBack();
  4931. return Result::error($e->getMessage(), 0);
  4932. }
  4933. return Result::success($result);
  4934. }
  4935. /*
  4936. * 获取公司信息
  4937. * */
  4938. public function getJobCompany(array $data): array
  4939. {
  4940. $user = User::where('user.id', $data['user_id'])
  4941. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4942. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4943. ->first();
  4944. // return Result::success($user);
  4945. if (empty($user)) {
  4946. return Result::error("用户不存在", 0);
  4947. }
  4948. if ($user['type_id'] == 3) {
  4949. $result = [
  4950. // 'id' => 0,
  4951. 'user_id' => $data['user_id'],
  4952. 'website_id' => $data['website_id'],
  4953. 'business_name' => $user['business_name'], // 企业名称
  4954. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4955. 'company_nature' => $user['company_nature'], // 公司性质
  4956. 'company_size' => $user['company_size'], // 公司规模
  4957. 'introduction' => $user['introduction'], // 公司简介
  4958. 'real_name' => $user['real_name'], // 企业联系人
  4959. 'mobile' => $user['mobile'], // 企业联系电话
  4960. 'company_url' => $user['company_url'], // 企业网址
  4961. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4962. 'address' => $user['address'], // 企业地址
  4963. 'email' => $user['email'], // 企业邮箱
  4964. ];
  4965. } else {
  4966. return Result::error("用户类型错误", 0);
  4967. }
  4968. if (empty($result)) {
  4969. return Result::error("公司信息不存在", 0);
  4970. }
  4971. return Result::success($result);
  4972. }
  4973. /*
  4974. * 修改公司信息
  4975. * */
  4976. public function upJobCompany(array $data): array
  4977. {
  4978. // return Result::success($data);
  4979. $user = User::where('user.id', $data['user_id'])
  4980. ->where('user.status', 1)
  4981. ->select('user.user_name', 'user.type_id')
  4982. ->first();
  4983. if (empty($user)) {
  4984. return Result::error("用户不存在", 0);
  4985. }
  4986. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4987. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  4988. $company = [
  4989. 'business_name' => $data['business_name'], // 企业名称
  4990. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4991. 'company_nature' => $data['company_nature'], // 公司性质
  4992. 'company_size' => $data['company_size'], // 公司规模
  4993. 'introduction' => $data['introduction'], // 公司简介
  4994. // 'real_name' => $data['real_name'], // 企业联系人
  4995. 'company_url' => $data['company_url'], // 企业网址
  4996. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4997. 'address' => $data['address'], // 企业详细地址
  4998. // 'email' => $data['email'], // 企业邮箱
  4999. ];
  5000. if ($user['type_id'] == 3) {
  5001. Db::beginTransaction();
  5002. try {
  5003. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5004. 'business_name' => $data['business_name'], // 企业名称
  5005. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5006. 'company_nature' => $data['company_nature'], // 公司性质
  5007. 'company_size' => $data['company_size'], // 公司规模
  5008. 'introduction' => $data['introduction'], // 公司简介
  5009. // 'real_name' => $data['real_name'], // 企业联系人
  5010. 'company_url' => $data['company_url'], // 企业网址
  5011. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5012. 'address' => $data['address'], // 企业详细地址
  5013. ]);
  5014. if (empty($result['userinfo'])) {
  5015. Db::rollBack();
  5016. return Result::error('修改企业会员信息失败!');
  5017. }
  5018. $result['user'] = User::where('id', $data['user_id'])->update([
  5019. 'email' => $data['email'], // 企业邮箱
  5020. ]);
  5021. if (empty($result['user'])) {
  5022. Db::rollBack();
  5023. return Result::error('修改个人中心信息失败!');
  5024. }
  5025. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5026. if (!empty($job_company)) {
  5027. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5028. if (empty($result['job_company'])) {
  5029. Db::rollBack();
  5030. return Result::error('修改企业会员信息失败!');
  5031. }
  5032. }
  5033. Db::commit();
  5034. return Result::success($result);
  5035. } catch (\Exception $e) {
  5036. Db::rollBack();
  5037. return Result::error($e->getMessage(), 0);
  5038. }
  5039. } else {
  5040. return Result::error("用户类型错误", 0);
  5041. }
  5042. }
  5043. /*
  5044. * 获取省-市
  5045. * */
  5046. public function getJobRecruitingArea(array $data): array
  5047. {
  5048. if (isset($data['pid']) && $data['pid'] != null) {
  5049. $result = District::where('pid', $data['pid'])->get()->all();
  5050. } else {
  5051. $result = District::where('level', 1)->get()->all();
  5052. }
  5053. if (empty($result)) {
  5054. return Result::error("暂无此省市", 0);
  5055. }
  5056. return Result::success($result);
  5057. }
  5058. /*
  5059. * 获取行业分类
  5060. * */
  5061. public function getIndustry(array $data): array
  5062. {
  5063. $result = JobIndustry::get()->all();
  5064. if (empty($result)) {
  5065. return Result::error("暂无行业分类", 0);
  5066. }
  5067. return Result::success($result);
  5068. }
  5069. /*
  5070. * 获取职位
  5071. * */
  5072. public function getPositionList(array $data): array
  5073. {
  5074. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5075. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5076. } else {
  5077. $result = JobPosition::where('zwpid', 0)->get()->all();
  5078. }
  5079. if (empty($result)) {
  5080. return Result::error("暂无此职位", 0);
  5081. }
  5082. return Result::success($result);
  5083. }
  5084. /*
  5085. * 获取工作性质-菜单
  5086. * */
  5087. public function getJobNature(array $data): array
  5088. {
  5089. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5090. if (empty($result)) {
  5091. return Result::error("暂无工作性质", 0);
  5092. }
  5093. return Result::success($result);
  5094. }
  5095. /*
  5096. * 获取工作经验-菜单
  5097. * */
  5098. public function getExperience(array $data): array
  5099. {
  5100. $result = JobEnum::where('egroup', 'years')->get()->all();
  5101. if (empty($result)) {
  5102. return Result::error("暂无工作经验", 0);
  5103. }
  5104. return Result::success($result);
  5105. }
  5106. /*
  5107. * 获取学历-菜单
  5108. * */
  5109. public function getEducation(array $data): array
  5110. {
  5111. $result = JobEnum::where('egroup', 'education')->get()->all();
  5112. if (empty($result)) {
  5113. return Result::error("暂无学历", 0);
  5114. }
  5115. return Result::success($result);
  5116. }
  5117. /*
  5118. * 获取薪资-菜单
  5119. * */
  5120. public function getSalary(array $data): array
  5121. {
  5122. $result = JobEnum::where('egroup', 'income')->get()->all();
  5123. if (empty($result)) {
  5124. return Result::error("暂无薪资", 0);
  5125. }
  5126. return Result::success($result);
  5127. }
  5128. /*
  5129. * 获取语言-菜单
  5130. * */
  5131. public function getLanguage(array $data): array
  5132. {
  5133. $result = JobEnum::where('egroup', 'language')->get()->all();
  5134. if (empty($result)) {
  5135. return Result::error("暂无语言", 0);
  5136. }
  5137. return Result::success($result);
  5138. }
  5139. /*
  5140. * 获取掌握程度-菜单
  5141. * */
  5142. public function getLevel(array $data): array
  5143. {
  5144. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5145. if (empty($result)) {
  5146. return Result::error("暂无工作性质", 0);
  5147. }
  5148. return Result::success($result);
  5149. }
  5150. // 公司信息
  5151. /*
  5152. * 获取公司性质-菜单
  5153. * */
  5154. public function getCompanyNature(array $data): array
  5155. {
  5156. $result = JobNature::get()->all();
  5157. if (empty($result)) {
  5158. return Result::error("暂无公司性质", 0);
  5159. }
  5160. return Result::success($result);
  5161. }
  5162. /*
  5163. * 获取公司规模-菜单
  5164. * */
  5165. public function getCompanySize(array $data): array
  5166. {
  5167. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5168. if (empty($result)) {
  5169. return Result::error("暂无公司规模", 0);
  5170. }
  5171. return Result::success($result);
  5172. }
  5173. /*
  5174. * 招聘信息审核
  5175. * */
  5176. public function checkJobRecruiting(array $data): array
  5177. {
  5178. $user = User::where('id', $data['user_id'])->first();
  5179. if (empty($user)) {
  5180. return Result::error("用户不存在", 0);
  5181. }
  5182. $job = JobRecruiting::where('id', $data['id'])->first();
  5183. if (empty($job)) {
  5184. return Result::error("招聘信息不存在", 0);
  5185. }
  5186. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5187. if ($user['type_id'] != 10000) {
  5188. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5189. }
  5190. // 驳回原因
  5191. if ($data['status'] == 2) {
  5192. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5193. }
  5194. $data['action_id'] = $data['user_id'];
  5195. unset($data['user_id']);
  5196. if ($data['status'] == 1) {
  5197. $this->sendMessage([
  5198. 'talk_type' => 501,
  5199. 'title' => $job['title'],
  5200. 'content' => '审核通过',
  5201. 'messageType' => 10,
  5202. 'user_id' => $job['user_id'],
  5203. ]);
  5204. }
  5205. if ($data['status'] == 2) {
  5206. $this->sendMessage([
  5207. 'talk_type' => 501,
  5208. 'title' => $job['title'],
  5209. 'content' => '审核拒绝',
  5210. 'messageType' => 10,
  5211. 'user_id' => $job['user_id'],
  5212. ]);
  5213. }
  5214. if ($data['status'] == 0) {
  5215. $this->sendMessage([
  5216. 'talk_type' => 500,
  5217. 'title' => $job['title'],
  5218. 'content' => '提交了审核',
  5219. 'messageType' => 10,
  5220. ]);
  5221. }
  5222. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5223. if (empty($result)) {
  5224. return Result::error("审核失败", 0);
  5225. }
  5226. return Result::success($result);
  5227. }
  5228. public function myApplyList(array $data): array
  5229. {
  5230. var_dump($data, '------参数');
  5231. $user = User::where('id', $data['user_id'])->first();
  5232. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5233. return Result::error("用户不存在", 0);
  5234. }
  5235. // 1:个人会员 职场机会
  5236. if ($user['type_id'] == 1) {
  5237. $where['user_id'] = $user['id'];
  5238. }
  5239. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5240. $query->where('user_id', $user['id']);
  5241. })
  5242. ->pluck('recruit_id');
  5243. $where = [];
  5244. if (isset($data['salary']) && $data['salary'] != null) {
  5245. $where['job_recruiting.salary'] = $data['salary'];
  5246. }
  5247. if (isset($data['experience']) && $data['experience'] != null) {
  5248. $where['job_recruiting.experience'] = $data['experience'];
  5249. }
  5250. if (isset($data['business_name']) && $data['business_name'] != null) {
  5251. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5252. }
  5253. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5254. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5255. ->where($where);
  5256. // ->count();
  5257. $count = $query->count();
  5258. $query = clone $query;
  5259. $job = $query
  5260. ->leftJoin('job_enum as income_enum', function ($join) {
  5261. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5262. ->where('income_enum.egroup', 'income');
  5263. })
  5264. ->leftJoin('job_enum as years_enum', function ($join) {
  5265. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5266. ->where('years_enum.egroup', 'years');
  5267. })
  5268. // ->where($where)
  5269. ->orderBy('job_recruiting.updated_at', 'desc')
  5270. ->select(
  5271. 'job_recruiting.id',
  5272. 'job_recruiting.title',
  5273. 'job_company.business_name',
  5274. 'income_enum.evalue as salary_evalue',
  5275. 'income_enum.ename as salary_ename',
  5276. 'years_enum.evalue as experience_evalue',
  5277. 'years_enum.ename as experience_ename',
  5278. 'job_recruiting.updated_at'
  5279. )
  5280. ->offset(($data['page'] - 1) * $data['pageSize'])
  5281. ->limit($data['pageSize'])
  5282. ->get()
  5283. ->all();
  5284. if (empty($job)) {
  5285. return Result::error("暂无招聘信息", 0);
  5286. }
  5287. $result = [
  5288. 'row' => $job,
  5289. 'count' => $count,
  5290. ];
  5291. return Result::success($result);
  5292. }
  5293. /*
  5294. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5295. * */
  5296. public function getRecruitingList(array $data): array
  5297. {
  5298. $user = User::where('id', $data['user_id'])->first();
  5299. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5300. return Result::error("用户不存在", 0);
  5301. }
  5302. // 1:个人会员 职场机会
  5303. if ($user['type_id'] == 1) {
  5304. $where['user_id'] = $user['id'];
  5305. }
  5306. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5307. $query->where('receiver_id', $user['id']);
  5308. })
  5309. ->pluck('recruit_id');
  5310. // return Result::success($recruitingId);
  5311. $where = [];
  5312. if (isset($data['salary']) && $data['salary'] != null) {
  5313. $where['job_recruiting.salary'] = $data['salary'];
  5314. }
  5315. if (isset($data['experience']) && $data['experience'] != null) {
  5316. $where['job_recruiting.experience'] = $data['experience'];
  5317. }
  5318. if (isset($data['business_name']) && $data['business_name'] != null) {
  5319. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5320. }
  5321. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5322. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5323. ->where($where);
  5324. // ->count();
  5325. $count = $query->count();
  5326. $query = clone $query;
  5327. $job = $query
  5328. ->leftJoin('job_enum as income_enum', function ($join) {
  5329. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5330. ->where('income_enum.egroup', 'income');
  5331. })
  5332. ->leftJoin('job_enum as years_enum', function ($join) {
  5333. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5334. ->where('years_enum.egroup', 'years');
  5335. })
  5336. // ->where($where)
  5337. ->orderBy('job_recruiting.updated_at', 'desc')
  5338. ->select(
  5339. 'job_recruiting.id',
  5340. 'job_recruiting.title',
  5341. 'job_company.business_name',
  5342. 'income_enum.evalue as salary_evalue',
  5343. 'income_enum.ename as salary_ename',
  5344. 'years_enum.evalue as experience_evalue',
  5345. 'years_enum.ename as experience_ename',
  5346. 'job_recruiting.updated_at'
  5347. )
  5348. ->offset(($data['page'] - 1) * $data['pageSize'])
  5349. ->limit($data['pageSize'])
  5350. ->get()
  5351. ->all();
  5352. if (empty($job)) {
  5353. return Result::error("暂无招聘信息", 0);
  5354. }
  5355. $result = [
  5356. 'row' => $job,
  5357. 'count' => $count,
  5358. ];
  5359. return Result::success($result);
  5360. }
  5361. /*
  5362. * 获取企业会员-招聘信息列表
  5363. * */
  5364. public function getRecruitingInfo(array $data): array
  5365. {
  5366. $user = User::where('id', $data['user_id'])->first();
  5367. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5368. return Result::error("用户不存在", 0);
  5369. }
  5370. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5371. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5372. ->select(
  5373. 'job_recruiting.*',
  5374. 'job_company.business_name',
  5375. 'job_company.company_hy_id',
  5376. 'job_company.company_size',
  5377. 'job_company.company_nature',
  5378. 'job_company.introduction',
  5379. 'job_company.real_name',
  5380. 'job_company.mobile',
  5381. 'job_company.company_url',
  5382. 'job_company.address_arr_id',
  5383. 'job_company.address',
  5384. 'job_company.email'
  5385. )
  5386. ->get();
  5387. if (empty($recruiting)) {
  5388. return Result::error("暂无招聘信息", 0);
  5389. }
  5390. return Result::success($recruiting);
  5391. }
  5392. /*
  5393. * 获取企业会员-我的沟通
  5394. * */
  5395. public function getJobResumeList(array $data): array
  5396. {
  5397. $user = User::where('id', $data['user_id'])->first();
  5398. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5399. return Result::error("用户不存在", 0);
  5400. }
  5401. $where = [];
  5402. if (isset($data['salary']) && $data['salary'] != null) {
  5403. $where['job_hunting.salary'] = $data['salary'];
  5404. }
  5405. if (isset($data['user_name']) && $data['user_name'] != null) {
  5406. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5407. }
  5408. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5409. $query->where('job_resume.user_id', $user['id']);
  5410. })
  5411. ->when(!empty($where), function ($query) use ($where) {
  5412. $query->where($where);
  5413. })
  5414. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5415. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5416. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5417. ->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');
  5418. $count = $job->count();
  5419. if ($count == 0) {
  5420. return Result::error("暂无沟通记录", 0);
  5421. }
  5422. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5423. ->offset(($data['page'] - 1) * $data['pageSize'])
  5424. ->limit($data['pageSize'])
  5425. ->get();
  5426. if (empty($jobs)) {
  5427. return Result::error("暂无沟通记录", 0);
  5428. }
  5429. $result['row'] = $this->processJob($jobs, '');
  5430. $result['count'] = $count;
  5431. return Result::success($result);
  5432. }
  5433. // 20250306 招聘
  5434. //20250422 书刊音像
  5435. public function addBook(array $data): array
  5436. {
  5437. $user_id = $data['user_id'] ?? 0;
  5438. $type_id = $data['type_id'] ?? 0;
  5439. // $website_id = $data['website_id'] ?? 0;
  5440. // unset($data['user_id']);
  5441. unset($data['type_id']);
  5442. // unset($data['website_id']);
  5443. //处理数组
  5444. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5445. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5446. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5447. if ($data['img_url'] == '') {
  5448. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5449. preg_match_all($reg, $data['detail'], $matches);
  5450. if (isset($matches[1][0])) {
  5451. //截取varchar240
  5452. $data['img_url'] = substr($matches[1][0], 0, 240);
  5453. }
  5454. }
  5455. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5456. //提取标题+内容中的关键词
  5457. $data['keyword'] = $data['title'];
  5458. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5459. Jieba::init(); // 初始化 jieba-php
  5460. Finalseg::init();
  5461. $segList = Jieba::cut($data['keyword']);
  5462. $segList1 = array_slice($segList, 0, 8);
  5463. $data['keyword'] = implode(',', $segList1);
  5464. }
  5465. if ($data['description'] == '') {
  5466. //提取内容中的描述
  5467. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5468. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5469. }
  5470. var_dump($data, '--');
  5471. if ($data['status'] == 1) {
  5472. $this->sendMessage([
  5473. 'talk_type' => 400,
  5474. 'title' => $data['title'],
  5475. 'content' => '提交了审核',
  5476. 'messageType' => 7,
  5477. ]);
  5478. }
  5479. $result = Book::insertGetId($data);
  5480. if (empty($result)) {
  5481. return Result::error("添加失败", 0);
  5482. }
  5483. return Result::success($result);
  5484. }
  5485. public function getBookList(array $data): array
  5486. {
  5487. $where = [];
  5488. if (!empty($data["title"])) {
  5489. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5490. }
  5491. if (!empty($data['website_name'])) {
  5492. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5493. }
  5494. if (!empty($data['status'])) {
  5495. $where[] = ['book.status', '=', $data['status']];
  5496. }
  5497. $user_id = $data['user_id'];
  5498. $type_id = $data['type_id'];
  5499. // $type_id = 4;
  5500. var_dump($type_id, '------1--------');
  5501. if ($type_id != 10000) {
  5502. $where[] = ['book.user_id', '=', $user_id];
  5503. }
  5504. var_dump(!empty($data['status1']), '=-===1');
  5505. $result = Book::where($where)
  5506. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5507. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5508. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5509. ->when(isset($data['status1']), function ($query) use ($data) {
  5510. $query->whereIn('book.status', [1, 3]);
  5511. })
  5512. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5513. ->orderBy("updated_at", "desc")
  5514. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5515. if (empty($result)) {
  5516. return Result::error("暂无数据", 0);
  5517. }
  5518. // 取出数据
  5519. $rows = $result->items();
  5520. $count = $result->total();
  5521. $responseData = [
  5522. 'rows' => $rows,
  5523. 'count' => $count,
  5524. ];
  5525. return Result::success($responseData);
  5526. }
  5527. public function deleteBook(array $data): array
  5528. {
  5529. $result = Book::where('id', $data['id'])->delete();
  5530. if (empty($result)) {
  5531. return Result::error("删除失败", 0);
  5532. }
  5533. return Result::success($result);
  5534. }
  5535. public function updateBook(array $data): array
  5536. {
  5537. // $user_id = $data['user_id'] ?? 0;
  5538. $type_id = $data['type_id'] ?? 0;
  5539. // $website_id = $data['website_id'] ?? 0;
  5540. unset($data['user_id']);
  5541. unset($data['type_id']);
  5542. // unset($data['website_id']);
  5543. //处理数组
  5544. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5545. if ($data['img_url'] == '') {
  5546. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5547. preg_match_all($reg, $data['detail'], $matches);
  5548. if (isset($matches[1][0])) {
  5549. //截取varchar240
  5550. $data['img_url'] = substr($matches[1][0], 0, 240);
  5551. }
  5552. }
  5553. if ($data['keyword'] == '') {
  5554. //提取标题+内容中的关键词
  5555. $data['keyword'] = $data['title'];
  5556. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5557. Jieba::init(); // 初始化 jieba-php
  5558. Finalseg::init();
  5559. $segList = Jieba::cut($data['keyword']);
  5560. $segList1 = array_slice($segList, 0, 8);
  5561. $data['keyword'] = implode(',', $segList1);
  5562. }
  5563. if ($data['description'] == '') {
  5564. //提取内容中的描述
  5565. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5566. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5567. }
  5568. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5569. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5570. if ($data['status'] == 1) {
  5571. $this->sendMessage([
  5572. 'talk_type' => 400,
  5573. 'title' => $data['title'],
  5574. 'content' => '提交了审核',
  5575. 'messageType' => 7,
  5576. ]);
  5577. }
  5578. $result = Book::where("id", $data["id"])->update($data);
  5579. if (empty($result)) {
  5580. return Result::error("更新失败", 0);
  5581. }
  5582. return Result::success($result);
  5583. }
  5584. public function getBookInfo(array $data): array
  5585. {
  5586. $result = Book::where("id", $data["id"])->first();
  5587. if (empty($result)) {
  5588. return Result::error("获取失败", 0);
  5589. }
  5590. return Result::success($result);
  5591. }
  5592. public function updateBookStatus(array $data): array
  5593. {
  5594. //审核
  5595. unset($data['user_id']);
  5596. $bookInfo = Book::where("id", $data["id"])->first();
  5597. var_dump($bookInfo, '----');
  5598. if ($data['status'] == 2) {
  5599. $this->sendMessage([
  5600. 'talk_type' => 401,
  5601. 'title' => $bookInfo['title'],
  5602. 'content' => '审核通过',
  5603. 'messageType' => 7,
  5604. 'user_id' => $bookInfo['user_id'],
  5605. ]);
  5606. }
  5607. if ($data['status'] == 3) {
  5608. $this->sendMessage([
  5609. 'talk_type' => 401,
  5610. 'title' => $bookInfo['title'],
  5611. 'content' => '审核拒绝',
  5612. 'messageType' => 7,
  5613. 'user_id' => $bookInfo['user_id'],
  5614. ]);
  5615. }
  5616. if ($data['status'] == 1) {
  5617. $this->sendMessage([
  5618. 'talk_type' => 400,
  5619. 'title' => $bookInfo['title'],
  5620. 'content' => '提交了审核',
  5621. 'messageType' => 7,
  5622. // 'user_id'=>$bookInfo['user_id'],
  5623. ]);
  5624. }
  5625. $result = Book::where("id", $data["id"])->update($data);
  5626. if (empty($result)) {
  5627. return Result::error("更新失败", 0);
  5628. }
  5629. return Result::success($result);
  5630. }
  5631. //20250422 书刊音像
  5632. /**
  5633. * 贴身宝贝
  5634. * @param array $data
  5635. * @return array
  5636. */
  5637. public function getWebsiteTsbb(array $data): array
  5638. {
  5639. $month = $data['month'] ?? date('m');
  5640. $day = $data['day'] ?? date('d');
  5641. // 使用缓存键
  5642. $cacheKey = "tsbb_data_{$month}_{$day}";
  5643. // 尝试从缓存获取数据
  5644. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5645. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5646. if ($cachedData = $cache->get($cacheKey)) {
  5647. return Result::success(unserialize($cachedData));
  5648. }
  5649. //查询老黄历
  5650. try {
  5651. $date = date('Y-m-d');
  5652. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5653. // 使用 curl 替代 file_get_contents
  5654. $ch = curl_init();
  5655. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5656. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5657. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5658. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5659. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5660. 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');
  5661. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5662. 'Accept: application/json',
  5663. 'Content-Type: application/json',
  5664. 'Referer: https://www.36jxs.com/'
  5665. ]);
  5666. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5667. curl_setopt($ch, CURLOPT_ENCODING, '');
  5668. $almanacResponse = curl_exec($ch);
  5669. var_dump("====:", $almanacResponse);
  5670. if (curl_errno($ch)) {
  5671. var_dump('Curl error:', curl_error($ch));
  5672. throw new \Exception('Curl error: ' . curl_error($ch));
  5673. }
  5674. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5675. curl_close($ch);
  5676. if ($almanacResponse === false) {
  5677. throw new \Exception('Failed to fetch almanac data');
  5678. }
  5679. $almanacData = json_decode($almanacResponse, true);
  5680. if (json_last_error() !== JSON_ERROR_NONE) {
  5681. throw new \Exception('Failed to parse almanac data');
  5682. }
  5683. $almanacInfo = $almanacData['data'] ?? [];
  5684. } catch (\Exception $e) {
  5685. var_dump('Exception:', $e->getMessage());
  5686. $almanacInfo = [];
  5687. }
  5688. // 获取历史上的今天数据
  5689. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5690. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5691. ->orderBy('year', 'asc')
  5692. ->select("title", "id", "year", DB::raw('1 as type'))
  5693. ->limit(16)
  5694. ->get();
  5695. // 获取节日数据 - 从今天开始获取未来4条
  5696. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5697. ->orderBy('showtime', 'asc')
  5698. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5699. ->limit(16)
  5700. ->get();
  5701. //说文解字
  5702. $chartacterList = Character::orderBy('updated_at', 'desc')
  5703. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5704. ->limit(6)
  5705. ->get();
  5706. //谜语沙龙
  5707. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5708. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5709. ->limit(4)
  5710. ->get();
  5711. //成语欣赏
  5712. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5713. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5714. ->limit(32)
  5715. ->get();
  5716. //名联赏析
  5717. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5718. ->select("id", "first", "second", DB::raw('6 as type'))
  5719. ->limit(6)
  5720. ->get();
  5721. // 获取分类文章数据
  5722. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5723. ->pluck('category_id')
  5724. ->toArray();
  5725. $articlesList = [];
  5726. foreach ($categoryIds as $catid) {
  5727. // 先查有图片的
  5728. $withImg = DB::table('article')
  5729. ->where('status', 1)
  5730. ->where('catid', $catid)
  5731. ->whereNotNull('imgurl')
  5732. ->where('imgurl', '!=', '')
  5733. ->orderBy('updated_at', 'desc')
  5734. ->limit(6)
  5735. ->get();
  5736. $count = $withImg->count();
  5737. if ($count < 6) {
  5738. // 不足6条再查无图片的补足
  5739. $withoutImg = DB::table('article')
  5740. ->where('status', 1)
  5741. ->where('catid', $catid)
  5742. ->where(function ($q) {
  5743. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5744. })
  5745. ->orderBy('updated_at', 'desc')
  5746. ->limit(6 - $count)
  5747. ->get();
  5748. $articles = $withImg->concat($withoutImg);
  5749. } else {
  5750. $articles = $withImg;
  5751. }
  5752. // 组装
  5753. $category = \App\Model\Category::find($catid);
  5754. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5755. $articlesList[] = [
  5756. 'category_name' => $category ? $category->name : '',
  5757. 'catid' => $catid,
  5758. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5759. 'type' => 100,
  5760. 'list' => $articles->map(function ($item) {
  5761. return [
  5762. 'id' => $item->id,
  5763. 'title' => $item->title,
  5764. 'imgurl' => $item->imgurl,
  5765. 'created_at' => $item->created_at
  5766. ];
  5767. })->values()
  5768. ];
  5769. }
  5770. $result = [
  5771. 'almanac' => $almanacInfo,
  5772. 'historyTodayList' => [
  5773. 'category_name' => '历史上的今天',
  5774. 'list' => $historyTodayList,
  5775. 'type' => 1
  5776. ],
  5777. 'festivalList' => [
  5778. 'category_name' => '节日预告',
  5779. 'list' => $festivalList,
  5780. 'type' => 2
  5781. ],
  5782. 'chartacterList' => [
  5783. 'category_name' => '说文解字',
  5784. 'list' => $chartacterList,
  5785. 'type' => 3
  5786. ],
  5787. 'coupletList' => [
  5788. 'category_name' => '名联赏析',
  5789. 'list' => $coupletList,
  5790. 'type' => 6
  5791. ],
  5792. 'riddletList' => [
  5793. 'category_name' => '谜语沙龙',
  5794. 'list' => $riddletList,
  5795. 'type' => 4
  5796. ],
  5797. 'idiomList' => [
  5798. 'category_name' => '成语欣赏',
  5799. 'list' => $idiomList,
  5800. 'type' => 5
  5801. ],
  5802. 'articlesList' => $articlesList
  5803. ];
  5804. // 缓存结果,设置1小时过期
  5805. $cache->set($cacheKey, serialize($result), 3600);
  5806. return Result::success($result);
  5807. }
  5808. /**
  5809. * 获取资讯列表
  5810. */
  5811. public function getWebsiteTsbbList(array $data): array
  5812. {
  5813. $page = $data['page'] ?? 1;
  5814. $pageSize = $data['pageSize'] ?? 10;
  5815. // 如果没有传入月份和日期,则使用今天的日期
  5816. $month = $data['month'] ?? date('m');
  5817. $day = $data['day'] ?? date('d');
  5818. $total = 0;
  5819. $result = [];
  5820. $data['type'] = intval($data['type']);
  5821. var_dump("接收参数:", $data);
  5822. switch ($data['type']) {
  5823. case 1:
  5824. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5825. // 当前月份之后的数据
  5826. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5827. // 或者当前月份且日期大于等于当前日期的数据
  5828. ->orWhere(function ($q) use ($month, $day) {
  5829. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5830. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5831. });
  5832. })
  5833. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5834. $total = $query->count();
  5835. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5836. ->offset(($page - 1) * $pageSize)
  5837. ->limit($pageSize)
  5838. ->get();
  5839. break;
  5840. case 2:
  5841. $query = Festival::where(function ($q) use ($month, $day) {
  5842. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5843. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5844. ->orWhere(function ($q) use ($month, $day) {
  5845. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5846. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5847. });
  5848. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5849. $total = $query->count();
  5850. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5851. ->offset(($page - 1) * $pageSize)
  5852. ->limit($pageSize)
  5853. ->get();
  5854. break;
  5855. case 3:
  5856. $query = Character::orderBy("updated_at", "desc");
  5857. $total = $query->count();
  5858. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5859. ->offset(($page - 1) * $pageSize)
  5860. ->limit($pageSize)
  5861. ->get();
  5862. break;
  5863. case 4:
  5864. $query = Riddle::orderBy("updated_at", "desc");
  5865. $total = $query->count();
  5866. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5867. ->offset(($page - 1) * $pageSize)
  5868. ->limit($pageSize)
  5869. ->get();
  5870. break;
  5871. case 5:
  5872. $query = Idiom::orderBy("updated_at", "desc");
  5873. $total = $query->count();
  5874. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5875. ->offset(($page - 1) * $pageSize)
  5876. ->limit($pageSize)
  5877. ->get();
  5878. break;
  5879. case 6:
  5880. $query = Couplet::orderBy("updated_at", "desc");
  5881. $total = $query->count();
  5882. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5883. ->offset(($page - 1) * $pageSize)
  5884. ->limit($pageSize)
  5885. ->get();
  5886. break;
  5887. default:
  5888. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5889. $total = $query->count();
  5890. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5891. ->offset(($page - 1) * $pageSize)
  5892. ->limit($pageSize)
  5893. ->get();
  5894. }
  5895. return Result::success([
  5896. 'list' => $result,
  5897. 'total' => $total,
  5898. 'page' => (int)$page,
  5899. 'pageSize' => (int)$pageSize,
  5900. 'month' => $month,
  5901. 'day' => $day
  5902. ]);
  5903. }
  5904. /**
  5905. * 1:历史上的今天
  5906. * 2:节日
  5907. * 3:文章
  5908. *
  5909. * 资讯详情信息
  5910. */
  5911. public function getWebsiteTsbbDetail(array $data): array
  5912. {
  5913. $data['type'] = intval($data['type']);
  5914. switch ($data['type']) {
  5915. case 1:
  5916. $result = HistoryToday::where("id", $data['id'])->first();
  5917. break;
  5918. case 2:
  5919. $result = Festival::where("id", $data['id'])->first();
  5920. break;
  5921. case 3:
  5922. $result = Character::where("id", $data['id'])->first();
  5923. break;
  5924. case 4:
  5925. $result = Riddle::where("id", $data['id'])->first();
  5926. break;
  5927. case 5:
  5928. $result = Idiom::where("id", $data['id'])->first();
  5929. break;
  5930. case 6:
  5931. $result = Couplet::where("id", $data['id'])->first();
  5932. break;
  5933. default:
  5934. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5935. break;
  5936. }
  5937. return Result::success($result);
  5938. }
  5939. /**
  5940. * 农网导航首页数据
  5941. */
  5942. public function getWebsiteNwHomeList(array $data): array
  5943. {
  5944. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5945. ->pluck('category_id')
  5946. ->toArray();
  5947. // 使用子查询优化
  5948. $articlesList = DB::table('article')
  5949. ->select([
  5950. 'article.id',
  5951. 'article.title',
  5952. 'article.imgurl',
  5953. 'article.created_at',
  5954. 'category.name as category_name',
  5955. 'category.id as category_id',
  5956. 'website_category.aLIas_pinyin as pinyin',
  5957. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5958. DB::raw('100 as type')
  5959. ])
  5960. ->join('category', 'article.catid', '=', 'category.id')
  5961. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5962. ->leftJoin('website_category as parent_wc', function ($join) {
  5963. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5964. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5965. })
  5966. ->where('website_category.website_id', $data['website_id'])
  5967. ->where('article.status', 1)
  5968. ->whereIn('category.id', $categoryIds)
  5969. ->orderBy('article.created_at', 'desc')
  5970. ->get()
  5971. ->groupBy('category_id')
  5972. ->map(function ($group) {
  5973. // 确保第一条数据有图片
  5974. $firstWithImage = $group->first(function ($item) {
  5975. return !empty($item->imgurl);
  5976. });
  5977. if ($firstWithImage) {
  5978. // 如果有带图片的文章,将其放在第一位
  5979. $group = $group->filter(function ($item) use ($firstWithImage) {
  5980. return $item->id !== $firstWithImage->id;
  5981. })->prepend($firstWithImage);
  5982. }
  5983. return [
  5984. 'category_name' => $group->first()->category_name,
  5985. 'catid' => $group->first()->category_id,
  5986. 'pinyin' => $group->first()->pinyin,
  5987. 'parent_pinyin' => $group->first()->parent_pinyin,
  5988. 'list' => $group->take(4)->map(function ($item) {
  5989. return [
  5990. 'id' => $item->id,
  5991. 'title' => $item->title,
  5992. ];
  5993. })->values()
  5994. ];
  5995. })
  5996. ->values()
  5997. ->toArray();
  5998. return Result::success($articlesList);
  5999. }
  6000. /**
  6001. * 企业管理
  6002. * @param array $data
  6003. * @return array
  6004. */
  6005. public function getCompanyList(array $data): array
  6006. {
  6007. // return Result::success($data);
  6008. $where = [];
  6009. $user = User::where('id', $data['user_id'])->first();
  6010. if (empty($user)) {
  6011. return Result::error('用户不存在!');
  6012. }
  6013. if ($user['type_id'] != 10000) {
  6014. $where['user_id'] = $data['user_id'];
  6015. }
  6016. if (isset($data['title']) && !empty($data['title'])) {
  6017. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6018. }
  6019. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6020. array_push($where, ['website.id', $data['website_id']]);
  6021. }
  6022. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6023. if ($data['ischeck'] == 1) {
  6024. if (isset($data['status']) && $data['status'] != '') {
  6025. array_push($where, ['company.status', $data['status']]);
  6026. $query = Company::where($where);
  6027. } else {
  6028. $query = Company::whereIn('company.status', [0, 2]);
  6029. }
  6030. } else {
  6031. $query = Company::where('company.status', 1);
  6032. }
  6033. }
  6034. $result = $query->where($where)
  6035. ->leftJoin('website_category', function ($query) {
  6036. $query->on('website_category.category_id', '=', 'company.category_id')
  6037. ->on('website_category.website_id', '=', 'company.website_id');
  6038. })
  6039. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6040. ->select(
  6041. 'company.id',
  6042. 'company.title',
  6043. 'company.website_id',
  6044. 'company.category_id',
  6045. 'website.website_name',
  6046. 'website_category.alias as category_name',
  6047. 'company.status',
  6048. 'company.updated_at',
  6049. )
  6050. ->orderBy('company.updated_at', 'desc')
  6051. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6052. if ($result->isEmpty()) {
  6053. return Result::error("暂无企业", 0);
  6054. }
  6055. return Result::success($result);
  6056. }
  6057. /**
  6058. * 添加企业
  6059. * @param array $data
  6060. * @return array
  6061. */
  6062. public function addCompany(array $data): array
  6063. {
  6064. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6065. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6066. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6067. $data['cat_arr_id'] = json_encode($car_arr_id);
  6068. } else {
  6069. $data['cat_arr_id'] = '';
  6070. }
  6071. if ($data['imgurl'] == '') {
  6072. //content中提取图片第一个图,正则提取
  6073. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6074. preg_match_all($reg, $data['content'], $matches);
  6075. if (isset($matches[1][0])) {
  6076. //截取varchar240
  6077. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6078. }
  6079. }
  6080. if ($data['keyword'] == '') {
  6081. //提取标题+内容中的关键词
  6082. $data['keyword'] = $data['title'];
  6083. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6084. Jieba::init(); // 初始化 jieba-php
  6085. Finalseg::init();
  6086. $segList = Jieba::cut($data['keyword']);
  6087. $segList1 = array_slice($segList, 0, 8);
  6088. $data['keyword'] = implode(',', $segList1);
  6089. }
  6090. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6091. //提取内容中的描述
  6092. $content = $data['content'];
  6093. // 去除 <style> 和 <script> 标签及其内容
  6094. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6095. // 去除所有 HTML 标签
  6096. $content = strip_tags($content);
  6097. // 去除 HTML 实体
  6098. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6099. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6100. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6101. // 去除多余空白
  6102. $content = preg_replace('/\s+/u', '', $content);
  6103. // 截取 100 个字符
  6104. $data['introduce'] = mb_substr($content, 0, 100);
  6105. }
  6106. $user = User::where('id', $data['user_id'])->first();
  6107. if (empty($user)) {
  6108. return Result::error('用户不存在!');
  6109. }
  6110. if ($user['type_id'] == 10000) {
  6111. $data['status'] = 1;
  6112. }
  6113. if (isset($data['level']) && $data['level'] != null) {
  6114. $data['level'] = intval($data['level']);
  6115. } else {
  6116. $data['level'] = null;
  6117. }
  6118. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6119. $this->sendMessage([
  6120. 'talk_type' => 900,
  6121. 'title' => $data['title'],
  6122. 'content' => '提交了审核',
  6123. 'messageType' => 8,
  6124. ]);
  6125. }
  6126. $result = Company::insertGetId($data);
  6127. if ($result) {
  6128. return Result::success($result);
  6129. } else {
  6130. return Result::error('添加失败');
  6131. }
  6132. }
  6133. /**
  6134. * 更新企业
  6135. * @param array $data
  6136. * @return array
  6137. */
  6138. public function upCompany(array $data): array
  6139. {
  6140. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6141. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6142. $data['cat_arr_id'] = json_encode($car_arr_id);
  6143. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6144. } else {
  6145. $data['cat_arr_id'] = '';
  6146. }
  6147. if ($data['imgurl'] == '') {
  6148. //content中提取图片第一个图,正则提取
  6149. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6150. preg_match_all($reg, $data['content'], $matches);
  6151. if (isset($matches[1][0])) {
  6152. //截取varchar
  6153. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6154. }
  6155. }
  6156. if ($data['keyword'] == '') {
  6157. //提取标题+内容中的关键词
  6158. $data['keyword'] = $data['title'];
  6159. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6160. Jieba::init(); // 初始化 jieba-php
  6161. Finalseg::init();
  6162. $segList = Jieba::cut($data['keyword']);
  6163. $segList1 = array_slice($segList, 0, 8);
  6164. $data['keyword'] = implode(',', $segList1);
  6165. }
  6166. if ($data['introduce'] == '') {
  6167. //提取内容中的描述
  6168. $content = $data['content'];
  6169. // 去除 <style> 和 <script> 标签及其内容
  6170. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6171. // 去除所有 HTML 标签
  6172. $content = strip_tags($content);
  6173. // 去除 HTML 实体
  6174. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6175. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6176. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6177. // 去除多余空白
  6178. $content = preg_replace('/\s+/u', '', $content);
  6179. // 截取 100 个字符
  6180. $data['introduce'] = mb_substr($content, 0, 100);
  6181. }
  6182. if (isset($data['level']) && $data['level'] != null) {
  6183. $data['level'] = intval($data['level']);
  6184. } else {
  6185. $data['level'] = null;
  6186. }
  6187. $user = User::where('id', $data['user_id'])->first();
  6188. if (empty($user)) {
  6189. return Result::error('用户不存在!');
  6190. }
  6191. if ($user['type_id'] == 10000) {
  6192. $data['status'] = 1;
  6193. } else {
  6194. $data['status'] = 0;
  6195. }
  6196. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6197. $this->sendMessage([
  6198. 'talk_type' => 900,
  6199. 'title' => $data['title'],
  6200. 'content' => '提交了审核',
  6201. 'messageType' => 8,
  6202. ]);
  6203. }
  6204. $result = Company::where('id', $data['id'])->update($data);
  6205. if ($result) {
  6206. return Result::success($result);
  6207. } else {
  6208. return Result::error('修改失败');
  6209. }
  6210. }
  6211. /**
  6212. * 删除企业
  6213. * @param array $data
  6214. * @return array
  6215. */
  6216. public function delCompany(array $data): array
  6217. {
  6218. $result = Company::where('id', $data['id'])->delete();
  6219. if ($result) {
  6220. return Result::success($result);
  6221. } else {
  6222. return Result::error('删除失败');
  6223. }
  6224. }
  6225. /**
  6226. * 审核企业
  6227. * @param array $data
  6228. * @return array
  6229. */
  6230. public function checkCompany(array $data): array
  6231. {
  6232. $user = User::where('id', $data['user_id'])->first();
  6233. if (empty($user)) {
  6234. return Result::error('用户不存在!');
  6235. }
  6236. $company = Company::where('id', $data['id'])->first();
  6237. if (empty($company)) {
  6238. return Result::error('企业不存在!');
  6239. }
  6240. // 状态:0:未审核 1:已审核 2:已拒绝
  6241. if ($data['status'] == 2 || $data['status'] == '2') {
  6242. $this->sendMessage([
  6243. 'talk_type' => 901,
  6244. 'title' => $company['title'],
  6245. 'content' => '审核拒绝',
  6246. 'messageType' => 8,
  6247. 'user_id' => $company['user_id'],
  6248. ]);
  6249. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6250. } else {
  6251. if ($data['status'] == 1) {
  6252. $this->sendMessage([
  6253. 'talk_type' => 901,
  6254. 'title' => $company['title'],
  6255. 'content' => '审核通过',
  6256. 'messageType' => 8,
  6257. 'user_id' => $company['user_id'],
  6258. ]);
  6259. } else if ($data['status'] == 0) {
  6260. $this->sendMessage([
  6261. 'talk_type' => 900,
  6262. 'title' => $company['title'],
  6263. 'content' => '提交了审核',
  6264. 'messageType' => 8,
  6265. ]);
  6266. }
  6267. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6268. }
  6269. if (empty($result)) {
  6270. return Result::error('审核失败!');
  6271. } else {
  6272. return Result::success($result);
  6273. }
  6274. }
  6275. /**
  6276. * 获取企业信息
  6277. * @param array $data
  6278. * @return array
  6279. */
  6280. public function getCompanyInfo(array $data): array
  6281. {
  6282. $result = Company::where('id', $data['id'])->first();
  6283. $city_arr = json_decode($result['city_arr_id']);
  6284. $result['city_name'] = District::whereIn('id', $city_arr)
  6285. ->pluck('name')
  6286. ->implode('-');
  6287. if (empty($result)) {
  6288. return Result::error('企业不存在!');
  6289. } else {
  6290. return Result::success($result);
  6291. }
  6292. }
  6293. /**
  6294. * @param array $data
  6295. * @return array
  6296. */
  6297. public function getWebsiteCompany(array $data): array
  6298. {
  6299. $categorys = json_decode($data['id'], true);
  6300. $category_arr = $this->processArticlePro($data['website_id']);
  6301. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6302. $catiall = $category_arr['catiall'];
  6303. foreach ($categorys as $key => $value) {
  6304. if (array_key_exists('level', $value)) {
  6305. $parts = explode(',', $value['level']);
  6306. $level = $parts[0] ?? null;
  6307. $imgnum = $parts[1] ?? null;
  6308. $textnum = $parts[2] ?? null;
  6309. if (!empty($textnum) && $textnum > 0) {
  6310. $text_num = Company::where('level', $level)
  6311. ->where('website_id', $data['website_id'])
  6312. ->where('status', 1)
  6313. ->select(
  6314. 'company.id',
  6315. 'company.title',
  6316. 'company.description',
  6317. 'company.updated_at',
  6318. 'company.category_id',
  6319. 'company.cat_arr_id'
  6320. )
  6321. ->orderBy('updated_at', 'desc')
  6322. ->limit($textnum)
  6323. ->get()->all();
  6324. }
  6325. if (!empty($imgnum) && $imgnum > 0) {
  6326. $img_num = Company::where('level', $level)
  6327. ->where('website_id', $data['website_id'])
  6328. ->where('status', 1)
  6329. ->where('imgurl', '!=', '')
  6330. ->whereNotNull('imgurl')
  6331. ->select(
  6332. 'company.id',
  6333. 'company.title',
  6334. 'company.description',
  6335. 'company.updated_at',
  6336. 'company.imgurl as imgs',
  6337. 'company.category_id',
  6338. 'company.cat_arr_id'
  6339. )
  6340. ->orderBy('updated_at', 'desc')
  6341. ->limit($imgnum)
  6342. ->get()->all();
  6343. }
  6344. }
  6345. if (array_key_exists('id', $value)) {
  6346. $parts = explode(',', $value['id']);
  6347. $category_id = $parts[0] ?? null;
  6348. $imgnum = $parts[1] ?? null;
  6349. $textnum = $parts[2] ?? null;
  6350. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6351. if (!empty($textnum) && $textnum > 0) {
  6352. $text_num = Company::whereIn('category_id', $category_arr)
  6353. ->where('website_id', $data['website_id'])
  6354. ->where('status', 1)
  6355. ->select(
  6356. 'company.id',
  6357. 'company.title',
  6358. 'company.description',
  6359. 'company.updated_at',
  6360. 'company.category_id',
  6361. 'company.cat_arr_id'
  6362. )
  6363. ->orderBy('updated_at', 'desc')
  6364. ->limit($textnum)
  6365. ->get()->all();
  6366. }
  6367. if (!empty($imgnum) && $imgnum > 0) {
  6368. $img_num = Company::whereIn('category_id', $category_arr)
  6369. ->where('website_id', $data['website_id'])
  6370. ->where('status', 1)
  6371. ->where('imgurl', '!=', '')
  6372. ->whereNotNull('imgurl')
  6373. ->select(
  6374. 'company.id',
  6375. 'company.title',
  6376. 'company.description',
  6377. 'company.updated_at',
  6378. 'company.imgurl as imgs',
  6379. 'company.category_id',
  6380. 'company.cat_arr_id'
  6381. )
  6382. ->orderBy('updated_at', 'desc')
  6383. ->limit($imgnum)
  6384. ->get()->all();
  6385. }
  6386. }
  6387. if (!empty($text_num)) {
  6388. foreach ($text_num as $k => $v) {
  6389. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6390. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6391. }
  6392. }
  6393. if (!empty($img_num)) {
  6394. foreach ($img_num as $k => $v) {
  6395. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6396. $imgurl = json_decode($v['imgs'], true);
  6397. if (!empty($imgurl)) {
  6398. $img_num[$k]->imgurl = $imgurl[0];
  6399. }
  6400. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6401. }
  6402. }
  6403. $company[$key]['img_num'] = $img_num ?? [];
  6404. $company[$key]['text_num'] = $text_num ?? [];
  6405. }
  6406. if (empty($company)) {
  6407. return Result::error("暂无相关企业信息", 0);
  6408. }
  6409. return Result::success($company);
  6410. }
  6411. /**
  6412. * @param array $data
  6413. * @return array
  6414. */
  6415. public function getWebsiteCompanyList(array $data): array
  6416. {
  6417. $where['website_id'] = $data['website_id'];
  6418. $where['status'] = 1;
  6419. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6420. $where['category_id'] = $data['category_id'];
  6421. }
  6422. if (isset($data['keyword']) && !empty($data['keyword'])) {
  6423. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  6424. }
  6425. $query = Company::where($where);
  6426. $company = $this->processArticle(
  6427. $query->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6428. ->orderBy('updated_at', 'desc')
  6429. ->offset(($data['page'] - 1) * $data['pageSize'])
  6430. ->limit($data['pageSize'])
  6431. ->get(),
  6432. $data
  6433. );
  6434. if (empty($company)) {
  6435. return Result::error("暂无相关公司信息", 0);
  6436. }
  6437. $result = [
  6438. 'count' => $query->clone()->count(),
  6439. 'data' => $company,
  6440. ];
  6441. return Result::success($result);
  6442. }
  6443. /**
  6444. * 获取项目列表
  6445. * @param array $data
  6446. * @return array
  6447. */
  6448. public function getProjectList(array $data): array
  6449. {
  6450. $where = [];
  6451. $user = User::where('id', $data['user_id'])->first();
  6452. if (empty($user)) {
  6453. return Result::error('用户不存在!');
  6454. }
  6455. if ($user->type_id != 10000) {
  6456. array_push($where, ['project.user_id', $data['user_id']]);
  6457. }
  6458. $query = Project::query();
  6459. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6460. array_push($where, ['project.website_id', $data['website_id']]);
  6461. }
  6462. if (isset($data['title']) && !empty($data['title'])) {
  6463. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6464. }
  6465. if ($data['status'] != 3) {
  6466. array_push($where, ['project.status', $data['status']]);
  6467. }
  6468. $query = Project::where($where)
  6469. ->when($data['status'] == 3, function ($query) {
  6470. $query->whereIn('project.status', [0, 2]);
  6471. });
  6472. $count = $query->clone()
  6473. ->count();
  6474. $rows = $query->clone()
  6475. ->leftJoin('website', 'project.website_id', 'website.id')
  6476. ->leftJoin('website_category', function ($join) {
  6477. $join->on('project.website_id', '=', 'website_category.website_id')
  6478. ->on('project.category_id', '=', 'website_category.category_id');
  6479. })
  6480. ->select(
  6481. 'project.id',
  6482. 'project.title',
  6483. 'project.updated_at',
  6484. 'project.status',
  6485. 'website.website_name',
  6486. 'website_category.alias as category_name'
  6487. )
  6488. ->orderBy('project.updated_at', 'desc')
  6489. ->offset(($data['page'] - 1) * $data['pageSize'])
  6490. ->limit($data['pageSize'])
  6491. ->get();
  6492. if ($rows->isEmpty()) {
  6493. return Result::error("暂无相关项目信息", 0);
  6494. }
  6495. $result = [
  6496. 'count' => $count,
  6497. 'rows' => $rows,
  6498. ];
  6499. return Result::success($result);
  6500. }
  6501. /**
  6502. * 添加项目
  6503. * @param array $data
  6504. * @return array
  6505. */
  6506. public function addProject(array $data): array
  6507. {
  6508. $user = User::where('id', $data['user_id'])->first();
  6509. if (empty($user)) {
  6510. return Result::error("暂无相关用户信息", 0);
  6511. }
  6512. if ($user->type_id == 10000) {
  6513. $data['status'] = 1;
  6514. } else {
  6515. $data['status'] = 0;
  6516. }
  6517. if ($data['keyword'] == '') {
  6518. //提取标题+内容中的关键词
  6519. $data['keyword'] = $data['title'];
  6520. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6521. Jieba::init(); // 初始化 jieba-php
  6522. Finalseg::init();
  6523. $segList = Jieba::cut($data['keyword']);
  6524. $segList1 = array_slice($segList, 0, 8);
  6525. $data['keyword'] = implode(',', $segList1);
  6526. }
  6527. if ($data['description'] == '') {
  6528. //提取内容中的描述
  6529. // var_dump(11111);
  6530. //提取内容中的描述
  6531. $content = $data['introduce'];
  6532. // 去除 <style> 和 <script> 标签及其内容
  6533. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6534. // 去除所有 HTML 标签
  6535. $content = strip_tags($content);
  6536. // 去除 HTML 实体
  6537. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6538. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6539. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6540. // 去除多余空白
  6541. $content = preg_replace('/\s+/u', '', $content);
  6542. // 截取 100 个字符
  6543. $data['description'] = mb_substr($content, 0, 100);
  6544. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6545. }
  6546. if ($data['status'] == 0) {
  6547. $this->sendMessage([
  6548. 'talk_type' => 1000,
  6549. 'title' => $data['title'],
  6550. 'content' => '提交了审核',
  6551. 'messageType' => 9,
  6552. ]);
  6553. }
  6554. $project = Project::insertGetId($data);
  6555. if (empty($project)) {
  6556. return Result::error("暂无相关项目信息", 0);
  6557. }
  6558. return Result::success($project);
  6559. }
  6560. /**
  6561. * 更新项目
  6562. * @param array $data
  6563. * @return array
  6564. */
  6565. public function upProject(array $data): array
  6566. {
  6567. $project = Project::where('id', $data['id'])->first();
  6568. if (empty($project)) {
  6569. return Result::error("暂无相关项目信息", 0);
  6570. }
  6571. $id = $data['id'];
  6572. unset($data['id']);
  6573. $user = User::where('id', $data['user_id'])->first();
  6574. if (empty($user)) {
  6575. return Result::error("暂无相关用户信息", 0);
  6576. }
  6577. if ($user->type_id == 10000) {
  6578. $data['status'] = 1;
  6579. } else {
  6580. $data['status'] = 0;
  6581. }
  6582. unset($data['user_id']);
  6583. if ($data['keyword'] == '') {
  6584. //提取标题+内容中的关键词
  6585. $data['keyword'] = $data['title'];
  6586. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6587. Jieba::init(); // 初始化 jieba-php
  6588. Finalseg::init();
  6589. $segList = Jieba::cut($data['keyword']);
  6590. $segList1 = array_slice($segList, 0, 8);
  6591. $data['keyword'] = implode(',', $segList1);
  6592. }
  6593. if ($data['description'] == '') {
  6594. //提取内容中的描述
  6595. // var_dump(11111);
  6596. //提取内容中的描述
  6597. $content = $data['introduce'];
  6598. // 去除 <style> 和 <script> 标签及其内容
  6599. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6600. // 去除所有 HTML 标签
  6601. $content = strip_tags($content);
  6602. // 去除 HTML 实体
  6603. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6604. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6605. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6606. // 去除多余空白
  6607. $content = preg_replace('/\s+/u', '', $content);
  6608. // 截取 100 个字符
  6609. $data['description'] = mb_substr($content, 0, 100);
  6610. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6611. }
  6612. if ($data['status'] == 0) {
  6613. $this->sendMessage([
  6614. 'talk_type' => 1000,
  6615. 'title' => $data['title'],
  6616. 'content' => '提交了审核',
  6617. 'messageType' => 9,
  6618. ]);
  6619. }
  6620. $result = Project::where('id', $id)->update($data);
  6621. if (empty($result)) {
  6622. return Result::error("更新失败", 0);
  6623. }
  6624. return Result::success($result);
  6625. }
  6626. /**
  6627. * 删除项目
  6628. * @param array $data
  6629. * @return array
  6630. */
  6631. public function delProject(array $data): array
  6632. {
  6633. $user = User::where('id', $data['user_id'])->first();
  6634. if (empty($user)) {
  6635. return Result::error("暂无相关用户信息", 0);
  6636. }
  6637. $project = Project::where('id', $data['id'])->first();
  6638. if (empty($project)) {
  6639. return Result::error("暂无相关项目信息", 0);
  6640. }
  6641. $result = Project::where('id', $data['id'])->delete();
  6642. if (empty($result)) {
  6643. return Result::error("删除失败", 0);
  6644. }
  6645. return Result::success($result);
  6646. }
  6647. /**
  6648. * 审核项目
  6649. * @param array $data
  6650. * @return array
  6651. */
  6652. public function checkProject(array $data): array
  6653. {
  6654. $user = User::where('id', $data['user_id'])->first();
  6655. if (empty($user)) {
  6656. return Result::error("暂无相关用户信息", 0);
  6657. }
  6658. // 0:未审核; 1:已审核; 2:已拒绝;
  6659. if ($user->type_id != 10000) {
  6660. if ($data['status'] == 1 || $data['status'] == 2) {
  6661. return Result::error("此用户权限不足", 0);
  6662. }
  6663. }
  6664. $project = Project::where('id', $data['id'])->first();
  6665. if (empty($project)) {
  6666. return Result::error("暂无相关项目信息", 0);
  6667. }
  6668. if ($data['status'] == 2) {
  6669. $this->sendMessage([
  6670. 'talk_type' => 1001,
  6671. 'title' => $project['title'],
  6672. 'content' => '审核拒绝',
  6673. 'messageType' => 9,
  6674. 'user_id' => $project['user_id'],
  6675. ]);
  6676. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6677. } else {
  6678. if ($data['status'] == 1) {
  6679. $this->sendMessage([
  6680. 'talk_type' => 1001,
  6681. 'title' => $project['title'],
  6682. 'content' => '审核通过',
  6683. 'messageType' => 9,
  6684. 'user_id' => $project['user_id'],
  6685. ]);
  6686. } else if ($data['status'] == 0) {
  6687. $this->sendMessage([
  6688. 'talk_type' => 1000,
  6689. 'title' => $project['title'],
  6690. 'content' => '提交了审核',
  6691. 'messageType' => 9,
  6692. ]);
  6693. }
  6694. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6695. }
  6696. if (empty($result)) {
  6697. return Result::error("审核失败", 0);
  6698. }
  6699. return Result::success($result);
  6700. }
  6701. /**
  6702. * 获取项目详情
  6703. * @param array $data
  6704. * @return array
  6705. */
  6706. public function getProjectInfo(array $data): array
  6707. {
  6708. $project = Project::where('id', $data['id'])->first();
  6709. if (empty($project)) {
  6710. return Result::error("暂无相关项目信息", 0);
  6711. }
  6712. return Result::success($project);
  6713. }
  6714. public function getWebsiteCompanyInfo(array $data): array
  6715. {
  6716. $company = Company::where('id', $data['id'])
  6717. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6718. ->where('status', 1)
  6719. ->where('website_id', $data['website_id'])
  6720. ->select('company.*', 'job_industry.hyname as hy_name')
  6721. ->first();
  6722. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6723. switch ($company->jobnature_id) {
  6724. case null:
  6725. $company->jobnature_name = '';
  6726. break;
  6727. case 0:
  6728. $company->jobnature_name = '市场监督';
  6729. break;
  6730. case 1:
  6731. $company->jobnature_name = '信访纪检';
  6732. break;
  6733. case 2:
  6734. $company->jobnature_name = '公检法司';
  6735. break;
  6736. case 3:
  6737. $company->jobnature_name = '高关注机构';
  6738. break;
  6739. default:
  6740. $company->jobnature_name = '';
  6741. break;
  6742. }
  6743. $city_arr = $company->city_arr_id;
  6744. if (!empty($city_arr)) {
  6745. $city_arr = json_decode($city_arr, true);
  6746. $cityNames = District::whereIn('id', $city_arr)
  6747. ->pluck('name')
  6748. ->implode('-');
  6749. $company->city_name = $cityNames;
  6750. } else {
  6751. $company->city_name = '';
  6752. }
  6753. if (empty($company)) {
  6754. return Result::error("暂无相关公司信息", 0);
  6755. }
  6756. return Result::success($company);
  6757. }
  6758. public function getMSG(array $data): array
  6759. {
  6760. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6761. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6762. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6763. $result = [];
  6764. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  6765. //最近的5篇已审的文章
  6766. $apply_articale = Article::where('status', 1)
  6767. ->where('admin_user_id', $user_id)
  6768. ->orderBy('updated_at', 'desc')
  6769. // ->limit(5)
  6770. ->get();
  6771. //获取5条用户的已审核商品
  6772. $good = Good::where('status', 2)
  6773. ->where('user_id', $user_id)
  6774. ->orderBy('updated_at', 'desc')
  6775. // ->limit(5)
  6776. ->get();
  6777. //获取5条用户待审核的公告
  6778. $notice = Notice::where('status', 2)
  6779. ->where('user_id', $user_id)
  6780. ->orderBy('updated_at', 'desc')
  6781. ->limit(5)->get();
  6782. //获取5条用户的待审核投诉
  6783. $complaint = Complaint::where('status', 2)
  6784. ->where('user_id', $user_id)
  6785. ->orderBy('updated_at', 'desc')
  6786. // ->limit(5)
  6787. ->get();
  6788. //获取5条用户的book
  6789. $book = Book::where('status', 2)
  6790. ->where('user_id', $user_id)
  6791. ->orderBy('updated_at', 'desc')
  6792. // ->limit(5)
  6793. ->get();
  6794. //获取5条用户的求职
  6795. //获取5条用户的求职 1
  6796. $job_hunting = JobHunting::where('job_hunting.status', 2)
  6797. ->where('job_hunting.user_id', $user_id)
  6798. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6799. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6800. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6801. ->orderBy('updated_at', 'desc')
  6802. // ->limit(5)
  6803. ->get();
  6804. //获取5条用户的求职 2
  6805. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6806. ->where('job_recruiting.user_id', $user_id)
  6807. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6808. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6809. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6810. ->orderBy('updated_at', 'desc')
  6811. // ->limit(5)
  6812. ->get();
  6813. //人才库 1
  6814. $job_apply = JobApply::where('job_apply.status', 1)
  6815. ->where('job_apply.receiver_id', $user_id)
  6816. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6817. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6818. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6819. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6820. ->select('job_recruiting', 'job_recruiting.', '', '')
  6821. ->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')
  6822. ->orderBy('updated_at', 'desc')
  6823. // ->limit(5)
  6824. ->get();
  6825. // 职场机会 2
  6826. $job_resume = JobResume::where('job_resume.status', 1)
  6827. ->where('job_resume.receiver_id', $user_id)
  6828. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6829. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6830. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6831. ->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')
  6832. ->orderBy('updated_at', 'desc')
  6833. // ->limit(5)
  6834. ->get();
  6835. //获取5条用户待处理的投诉
  6836. $complaint_deal = Complaint::where('status', 2)
  6837. ->where('deal', 1)
  6838. ->whereJsonContains('re_user_ids', $user_id)
  6839. ->orderBy('updated_at', 'desc')
  6840. // ->limit(5)
  6841. ->get();
  6842. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  6843. $complany = Company::where('status', 1)
  6844. ->where('user_id', $user_id)
  6845. ->orderBy('updated_at', 'desc')
  6846. // ->limit(5)
  6847. ->get();
  6848. //获取5条单聊未读聊天消息
  6849. // $chat = ChatRecords::where('is_read', 0)
  6850. // ->where('user_id', $user_id)
  6851. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6852. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6853. // ->where('action', 'recieved')
  6854. // ->where('talk_type', 1)
  6855. // ->orderBy('created_at', 'desc')
  6856. // // ->limit(5)
  6857. // ->get();
  6858. //获取5条未读群聊信息
  6859. // $chat_group = ChatRecords::where('is_read', 0)
  6860. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  6861. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  6862. // ->where('user_id', $user_id)
  6863. // ->where('talk_type', 2)
  6864. // ->orderBy('created_at', 'desc')
  6865. // // ->limit(5)
  6866. // ->get();
  6867. //获取5条用户的待审核项目
  6868. $project = Project::where('status', 1)
  6869. ->where('user_id', $user_id)
  6870. ->orderBy('updated_at', 'desc')
  6871. // ->limit(5)
  6872. ->get();
  6873. // count($chat) + count($chat_group) +
  6874. $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)
  6875. + count($complany)
  6876. + count($project)
  6877. // + count($chat) + count($chat_group)
  6878. ;
  6879. $result = [
  6880. 'apply_articale' => $apply_articale,
  6881. // 'chat' => $chat,
  6882. // 'chat_group' => $chat_group,
  6883. 'good' => $good,
  6884. 'notice' => $notice,
  6885. 'complaint' => $complaint,
  6886. 'book' => $book,
  6887. 'job_hunting' => $job_hunting,
  6888. 'job_recruiting' => $job_recruiting,
  6889. 'job_apply' => $job_apply,
  6890. 'job_resume' => $job_resume,
  6891. 'complaint_deal' => $complaint_deal,
  6892. 'complany' => $complany,
  6893. 'project' => $project,
  6894. 'count' => $count,
  6895. ];
  6896. } elseif ($type_id == 12) {
  6897. //最近的5篇已审的文章
  6898. $apply_articale = Article::where('status', 1)
  6899. ->where('admin_user_id', $user_id)
  6900. ->limit(5)->get();
  6901. //获取5条单聊未读聊天消息
  6902. $chat = ChatRecords::where('is_read', 0)
  6903. ->where('user_id', $user_id)
  6904. ->where('talk_type', 1)
  6905. ->orderBy('created_at', 'desc')
  6906. ->limit(5)->get();
  6907. //获取5条未读群聊信息
  6908. $chat_group = ChatRecords::where('is_read', 0)
  6909. ->where('user_id', $user_id)
  6910. ->where('talk_type', 2)
  6911. ->orderBy('created_at', 'desc')
  6912. ->limit(5)->get();
  6913. //获取5条用户的已审核商品
  6914. $good = Good::where('status', 2)
  6915. ->where('user_id', $user_id)
  6916. ->orderBy('updated_at', 'desc')
  6917. ->limit(5)->get();
  6918. //获取5条用户的book
  6919. $book = Book::where('status', 2)
  6920. ->where('user_id', $user_id)
  6921. ->orderBy('updated_at', 'desc')
  6922. ->limit(5)->get();
  6923. //获取5条用户的求职
  6924. //获取5条用户的求职 1
  6925. //count($chat) + count($chat_group)
  6926. $count = count($apply_articale) + count($good);
  6927. $result = [
  6928. 'apply_articale' => $apply_articale,
  6929. 'chat' => $chat,
  6930. 'chat_group' => $chat_group,
  6931. 'good' => $good,
  6932. 'book' => $book,
  6933. 'count' => $count,
  6934. ];
  6935. } elseif ($type_id == 13) {
  6936. //最近的5篇已审的文章
  6937. $apply_articale = Article::where('status', 1)
  6938. ->where('admin_user_id', $user_id)
  6939. ->limit(5)->get();
  6940. //获取5条单聊未读聊天消息
  6941. $chat = ChatRecords::where('is_read', 0)
  6942. ->where('user_id', $user_id)
  6943. ->where('talk_type', 1)
  6944. ->orderBy('created_at', 'desc')
  6945. ->limit(5)->get();
  6946. //获取5条未读群聊信息
  6947. $chat_group = ChatRecords::where('is_read', 0)
  6948. ->where('user_id', $user_id)
  6949. ->where('talk_type', 2)
  6950. ->orderBy('created_at', 'desc')
  6951. ->limit(5)->get();
  6952. //获取5条用户的已审核商品
  6953. $good = Good::where('status', 2)
  6954. ->where('user_id', $user_id)
  6955. ->orderBy('updated_at', 'desc')
  6956. ->limit(5)->get();
  6957. //count($chat) + count($chat_group) +
  6958. $count = count($apply_articale) + count($good);
  6959. $result = [
  6960. 'apply_articale' => $apply_articale,
  6961. 'chat' => $chat,
  6962. 'chat_group' => $chat_group,
  6963. 'good' => $good,
  6964. 'count' => $count,
  6965. ];
  6966. } elseif ($type_id == 14) {
  6967. //最近的5篇已审的文章
  6968. $apply_articale = Article::where('status', 1)
  6969. ->where('admin_user_id', $user_id)
  6970. // ->limit(5)
  6971. ->get();
  6972. //获取5条用户的已审核商品
  6973. $good = Good::where('status', 2)
  6974. ->where('user_id', $user_id)
  6975. ->orderBy('updated_at', 'desc')
  6976. // ->limit(5)
  6977. ->get();
  6978. $count = count($apply_articale) + count($good);
  6979. $result = [
  6980. 'apply_articale' => $apply_articale,
  6981. 'chat' => '',
  6982. 'chat_group' => '',
  6983. 'good' => $good,
  6984. 'count' => $count,
  6985. ];
  6986. } elseif ($type_id == 10000) {
  6987. //获取未审核的5篇文章
  6988. $apply_articale = Article::where('status', 0)
  6989. ->orderBy('updated_at', 'desc')
  6990. // ->limit(5)
  6991. ->get();
  6992. //获取5条单聊未读聊天消息
  6993. //获取5条单聊未读聊天消息
  6994. // $chat = ChatRecords::where('is_read', 0)
  6995. // ->where('user_id', $user_id)
  6996. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6997. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6998. // ->where('action', 'recieved')
  6999. // ->where('talk_type', 1)
  7000. // ->orderBy('created_at', 'desc')
  7001. // // ->limit(5)
  7002. // ->get();
  7003. // //获取5条未读群聊信息
  7004. // $chat_group = ChatRecords::where('is_read', 0)
  7005. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7006. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7007. // ->where('user_id', $user_id)
  7008. // ->where('talk_type', 2)
  7009. // ->orderBy('created_at', 'desc')
  7010. // // ->limit(5)
  7011. // ->get();
  7012. //获取5条用户的已审核商品
  7013. $good = Good::where('status', 1)
  7014. // ->where('user_id', $user_id)
  7015. ->orderBy('updated_at', 'desc')
  7016. // ->limit(5)
  7017. ->get();
  7018. //获取5条用户待审核的公告
  7019. $notice = Notice::where('status', 1)
  7020. ->orderBy('updated_at', 'desc')
  7021. // ->limit(5)
  7022. ->get();
  7023. //获取5条用户的待审核投诉
  7024. $complaint = Complaint::where('status', 1)
  7025. ->orderBy('updated_at', 'desc')
  7026. // ->limit(5)
  7027. ->get();
  7028. //获取5条用户的book
  7029. $book = Book::where('status', 1)
  7030. ->orderBy('updated_at', 'desc')
  7031. // ->limit(5)
  7032. ->get();
  7033. //获取5条用户的求职 1
  7034. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7035. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7036. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7037. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7038. ->orderBy('updated_at', 'desc')
  7039. // ->limit(5)
  7040. ->get();
  7041. //获取5条用户的求职 2
  7042. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7043. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7044. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7045. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7046. ->orderBy('updated_at', 'desc')
  7047. // ->limit(5)
  7048. ->get();
  7049. //人才库 1
  7050. $job_apply = JobApply::where('job_apply.status', 1)
  7051. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7052. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7053. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7054. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7055. ->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')
  7056. ->orderBy('updated_at', 'desc')
  7057. // ->limit(5)
  7058. ->get();
  7059. // 职场机会 2
  7060. $job_resume = JobResume::where('job_resume.status', 1)
  7061. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7062. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7063. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7064. ->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')
  7065. ->orderBy('updated_at', 'desc')
  7066. // ->limit(5)
  7067. ->get();
  7068. //待审核数据com pro
  7069. $complany = Company::where('status', 0)
  7070. ->orderBy('updated_at', 'desc')
  7071. // ->limit(5)
  7072. ->get();
  7073. $project = Project::where('status', 0)
  7074. ->orderBy('updated_at', 'desc')
  7075. // ->limit(5)
  7076. ->get();
  7077. $count =
  7078. // count($chat) +
  7079. // count($chat_group) +
  7080. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7081. + count($job_apply)
  7082. + count($job_resume)
  7083. + count($complany)
  7084. + count($project);
  7085. $result = [
  7086. 'apply_articale' => $apply_articale,
  7087. // 'chat' => $chat,
  7088. // 'chat_group' => $chat_group,
  7089. 'good' => $good,
  7090. 'notice' => $notice,
  7091. 'complaint' => $complaint,
  7092. 'book' => $book,
  7093. 'job_hunting' => $job_hunting,
  7094. 'job_recruiting' => $job_recruiting,
  7095. 'job_apply' => $job_apply,
  7096. 'job_resume' => $job_resume,
  7097. 'complany' => $complany,
  7098. 'project' => $project,
  7099. 'count' => $count,
  7100. ];
  7101. } elseif ($type_id == 20000) {
  7102. }
  7103. var_dump($type_id, '-----------------test---------');
  7104. return Result::success($result);
  7105. }
  7106. /**
  7107. * @param array $data
  7108. * @return array
  7109. */
  7110. public function getWebsiteProject(array $data): array
  7111. {
  7112. $categorys = json_decode($data['id'], true);
  7113. if (!empty($categorys)) {
  7114. $category_arr = $this->processArticlePro($data['website_id']);
  7115. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7116. $catiall = $category_arr['catiall'];
  7117. // return Result::success($catiall);
  7118. foreach ($categorys as $key => $val) {
  7119. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7120. $level = explode(',', $val['level'])[0];
  7121. $imgnum = explode(',', $val['level'])[1] ?? null;
  7122. $textnum = explode(',', $val['level'])[2] ?? null;
  7123. if ($level == 1) {
  7124. if (!empty($textnum) && $textnum > 0) {
  7125. $text_num = Project::where('level', $level)
  7126. ->where('website_id', $data['website_id'])
  7127. ->where('status', 1)
  7128. ->select(
  7129. 'project.id',
  7130. 'project.title',
  7131. 'project.description',
  7132. 'project.updated_at',
  7133. 'project.category_id',
  7134. 'project.cat_arr_id'
  7135. )
  7136. ->orderBy('updated_at', 'desc')
  7137. ->limit($textnum)
  7138. ->get()->all();
  7139. }
  7140. if (!empty($imgnum) && $imgnum > 0) {
  7141. $img_num = Project::where('level', $level)
  7142. ->where('website_id', $data['website_id'])
  7143. ->where('status', 1)
  7144. ->where('imgurl', '!=', '')
  7145. ->whereNotNull('imgurl')
  7146. ->select(
  7147. 'project.id',
  7148. 'project.title',
  7149. 'project.description',
  7150. 'project.updated_at',
  7151. 'project.imgurl as imgs',
  7152. 'project.category_id',
  7153. 'project.cat_arr_id'
  7154. )
  7155. ->orderBy('updated_at', 'desc')
  7156. ->limit($imgnum)
  7157. ->get()->all();
  7158. }
  7159. } else {
  7160. if (!empty($textnum) && $textnum > 0) {
  7161. $text_num = Project::where('website_id', $data['website_id'])
  7162. ->where('status', 1)
  7163. ->select(
  7164. 'project.id',
  7165. 'project.title',
  7166. 'project.description',
  7167. 'project.updated_at',
  7168. 'project.category_id',
  7169. 'project.cat_arr_id',
  7170. 'project.website_id',
  7171. 'project.updated_at',
  7172. 'project.created_at'
  7173. )
  7174. ->orderBy('updated_at', 'desc')
  7175. ->limit($textnum)
  7176. ->get()->all();
  7177. }
  7178. if (!empty($imgnum) && $imgnum > 0) {
  7179. $img_num = Project::where('website_id', $data['website_id'])
  7180. ->where('status', 1)
  7181. ->where('imgurl', '!=', '')
  7182. ->whereNotNull('imgurl')
  7183. ->select(
  7184. 'project.id',
  7185. 'project.title',
  7186. 'project.description',
  7187. 'project.updated_at',
  7188. 'project.imgurl as imgs',
  7189. 'project.category_id',
  7190. 'project.cat_arr_id'
  7191. )
  7192. ->orderBy('updated_at', 'desc')
  7193. ->limit($imgnum)
  7194. ->get()->all();
  7195. }
  7196. }
  7197. }
  7198. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7199. $category_ids = explode(',', $val['id'])[0];
  7200. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7201. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7202. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7203. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7204. $text_num = Project::whereIn('category_id', $category_arr)
  7205. ->where('website_id', $data['website_id'])
  7206. ->where('status', 1)
  7207. ->select(
  7208. 'project.id',
  7209. 'project.title',
  7210. 'project.description',
  7211. 'project.updated_at',
  7212. 'project.category_id',
  7213. 'project.cat_arr_id'
  7214. )
  7215. ->orderBy('updated_at', 'desc')
  7216. ->limit($cat_textnum)
  7217. ->get()->all();
  7218. }
  7219. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7220. $img_num = Project::whereIn('category_id', $category_arr)
  7221. ->where('website_id', $data['website_id'])
  7222. ->where('status', 1)
  7223. ->where('imgurl', '!=', '')
  7224. ->whereNotNull('imgurl')
  7225. ->select(
  7226. 'project.id',
  7227. 'project.title',
  7228. 'project.description',
  7229. 'project.updated_at',
  7230. 'project.imgurl as imgs',
  7231. 'project.category_id',
  7232. 'project.cat_arr_id'
  7233. )
  7234. ->orderBy('updated_at', 'desc')
  7235. ->limit($cat_imgnum)
  7236. ->get()->all();
  7237. }
  7238. }
  7239. if (!empty($img_num)) {
  7240. foreach ($img_num as $k => $v) {
  7241. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7242. $imgurl = json_decode($v['imgs'], true);
  7243. if (!empty($imgurl)) {
  7244. $img_num[$k]->imgurl = $imgurl[0];
  7245. }
  7246. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7247. }
  7248. }
  7249. if (!empty($text_num)) {
  7250. foreach ($text_num as $k => $v) {
  7251. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7252. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7253. }
  7254. }
  7255. $project[$key]['img_num'] = $img_num ?? [];
  7256. $project[$key]['text_num'] = $text_num ?? [];
  7257. }
  7258. }
  7259. if (empty($project)) {
  7260. return Result::error("暂无相关项目信息", 0);
  7261. }
  7262. return Result::success($project);
  7263. }
  7264. /**
  7265. * @param array $data
  7266. * @return array
  7267. */
  7268. public function getWebsiteProjectInfo(array $data): array
  7269. {
  7270. $project = Project::where('id', $data['id'])
  7271. ->where('status', 1)
  7272. ->where('website_id', $data['website_id'])
  7273. ->select('project.*')
  7274. ->first();
  7275. if (empty($project)) {
  7276. return Result::error("暂无相关项目信息", 0);
  7277. }
  7278. return Result::success($project);
  7279. }
  7280. /**
  7281. * @param array $data
  7282. * @return array
  7283. */
  7284. public function getWebsiteProjectList(array $data): array
  7285. {
  7286. $where = [];
  7287. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7288. $where['category_id'] = $data['category_id'];
  7289. }
  7290. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7291. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7292. }
  7293. $query = Project::where($where)
  7294. ->where('status', 1)
  7295. ->where('website_id', $data['website_id'])
  7296. ->select(
  7297. 'project.id',
  7298. 'project.title',
  7299. 'project.description',
  7300. 'project.imgurl as imgs',
  7301. 'project.category_id',
  7302. 'project.cat_arr_id'
  7303. )
  7304. ->orderBy('updated_at', 'desc');
  7305. $count = $query->count();
  7306. $project = $query->clone()
  7307. ->offset(($data['page'] - 1) * $data['pageSize'])
  7308. ->limit($data['pageSize'])
  7309. ->get()->all();
  7310. if (empty($project)) {
  7311. return Result::error("暂无相关项目信息", 0);
  7312. }
  7313. $categorys = $this->processArticlePro($data['website_id']);
  7314. $catiall = $categorys['catiall'];
  7315. foreach ($project as $key => $val) {
  7316. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7317. if (!empty($val['imgs'])) {
  7318. $imgurl = json_decode($val['imgs'], true);
  7319. if (!empty($imgurl)) {
  7320. $project[$key]->imgurl = $imgurl[0];
  7321. }
  7322. } else {
  7323. $project[$key]->imgurl = '';
  7324. }
  7325. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7326. }
  7327. $result = [
  7328. 'rows' => $project,
  7329. 'count' => $count,
  7330. ];
  7331. return Result::success($result);
  7332. }
  7333. /**
  7334. * @param array $data
  7335. * @return array
  7336. */
  7337. public function getWebsiteCategoryJob(array $data): array
  7338. {
  7339. $categorys = json_decode($data['id'], true);
  7340. if (!empty($categorys)) {
  7341. $category_arr = $this->processArticlePro($data['website_id']);
  7342. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7343. $catiall = $category_arr['catiall'];
  7344. foreach ($categorys as $key => $val) {
  7345. if (isset($val['id']) && !empty($val['id'])) {
  7346. $catid = explode(',', $val['id'])[0] ?? null;
  7347. $type = explode(',', $val['id'])[1] ?? null;
  7348. $textnum = explode(',', $val['id'])[2] ?? null;
  7349. }
  7350. // 4:招聘;5:求职;
  7351. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7352. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7353. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7354. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7355. ->where('job_recruiting.status', 1)
  7356. ->where('job_recruiting.website_id', $data['website_id'])
  7357. ->select(
  7358. 'job_recruiting.id',
  7359. 'job_recruiting.title',
  7360. 'job_company.business_name',
  7361. 'job_recruiting.updated_at',
  7362. 'job_recruiting.cat_arr_id'
  7363. )
  7364. ->orderBy('job_recruiting.updated_at', 'desc')
  7365. ->limit($textnum)
  7366. ->get()->all();
  7367. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7368. // 状态 审核状态,1待审核2已审核3已拒绝
  7369. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7370. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7371. ->where('job_hunting.status', 2)
  7372. ->where('job_hunting.website_id', $data['website_id'])
  7373. ->select(
  7374. 'job_hunting.id',
  7375. 'job_hunting.name',
  7376. 'job_hunting.cat_arr_id',
  7377. 'job_position.zwname as job_name',
  7378. 'job_hunting.updated_at'
  7379. )
  7380. ->orderBy('updated_at', 'desc')
  7381. ->limit($textnum)
  7382. ->get()->all();
  7383. } else {
  7384. $job = [];
  7385. }
  7386. // var_dump($catid.'222uuuuuuu'.$key);
  7387. if (!empty($job)) {
  7388. foreach ($job as $k => $value) {
  7389. if (isset($value->cat_arr_id)) {
  7390. $catArr = json_decode($value->cat_arr_id, true);
  7391. $catId = end($catArr);
  7392. } else {
  7393. continue;
  7394. }
  7395. if (isset($catiall[$catId])) {
  7396. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7397. }
  7398. }
  7399. }
  7400. // var_dump($catid.'xxxxx'.$key);
  7401. $result[$key] = $job ?? [];
  7402. }
  7403. }
  7404. if (empty($result)) {
  7405. return Result::error("暂无相关分类信息", 0);
  7406. }
  7407. return Result::success($result);
  7408. }
  7409. /**
  7410. * 发送消息
  7411. * @param array $messageData
  7412. * @return void
  7413. */
  7414. public function sendMessage($messageData)
  7415. {
  7416. $msg = [
  7417. 'talk_type' => $messageData['talk_type'],
  7418. 'title' => $messageData['title'],
  7419. 'content' => $messageData['content'],
  7420. 'messageType' => $messageData['messageType'],
  7421. 'user_id' => $messageData['user_id'] ?? '',
  7422. 'time' => microtime(),
  7423. ];
  7424. $message = new MqProducer($msg);
  7425. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7426. $producer->produce($message);
  7427. }
  7428. }