NewsService.php 271 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618
  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. ->first();
  3363. if (empty($last_category)) {
  3364. return Result::error("该栏目不存在", 0);
  3365. }
  3366. if (isset($data['id']) && !empty($data['id'])) {
  3367. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3368. switch ($last_category['type']) {
  3369. case 1:
  3370. // 文章
  3371. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3372. $article = Article::where('status', 1)
  3373. ->where('id', $data['id'])
  3374. ->where(function ($query) use ($data) {
  3375. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3376. ->orWhereNull("ignore_ids");
  3377. })
  3378. ->first(['cat_arr_id']);
  3379. if (empty($article)) {
  3380. return Result::error("该文章不存在", 0);
  3381. }
  3382. // return Result::success($article);
  3383. break;
  3384. case 2:
  3385. // 商品
  3386. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3387. $article = Good::where('website_id', $data['website_id'])
  3388. ->where('status', 2)
  3389. ->where('id', $data['id'])
  3390. ->first(['cat_arr_id']);
  3391. if (empty($article)) {
  3392. return Result::error("该商品不存在", 0);
  3393. }
  3394. break;
  3395. case 3:
  3396. // 书刊信息
  3397. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3398. $article = Book::where('website_id', $data['website_id'])
  3399. ->where('status', 2)
  3400. ->where('id', $data['id'])
  3401. ->first(['id', 'cat_arr_id']);
  3402. if (empty($article)) {
  3403. return Result::error("该书刊不存在", 0);
  3404. }
  3405. break;
  3406. case 4:
  3407. // 招聘
  3408. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3409. $article = JobRecruiting::where('website_id', $data['website_id'])
  3410. ->where('status', 1)
  3411. ->where('id', $data['id'])
  3412. ->first(['cat_arr_id']);
  3413. if (empty($article)) {
  3414. return Result::error("该招聘不存在", 0);
  3415. }
  3416. break;
  3417. case 5:
  3418. // 求职
  3419. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3420. $article = JobHunting::where('website_id', $data['website_id'])
  3421. ->where('status', 2)
  3422. ->where('id', $data['id'])
  3423. ->first(['cat_arr_id']);
  3424. if (empty($article)) {
  3425. return Result::error("该求职不存在", 0);
  3426. }
  3427. break;
  3428. case 6:
  3429. // 企业
  3430. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3431. $article = Company::where('website_id', $data['website_id'])
  3432. ->where('status', 1)
  3433. ->where('id', $data['id'])
  3434. ->first(['cat_arr_id']);
  3435. if (empty($article)) {
  3436. return Result::error("该企业不存在", 0);
  3437. }
  3438. break;
  3439. case 7:
  3440. // 项目
  3441. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3442. $article = Project::where('website_id', $data['website_id'])
  3443. ->where('status', 1)
  3444. ->where('id', $data['id'])
  3445. ->first(['cat_arr_id']);
  3446. if (empty($article)) {
  3447. return Result::error("该项目不存在", 0);
  3448. }
  3449. break;
  3450. default:
  3451. return Result::error("该数据不存在", 0);
  3452. break;
  3453. }
  3454. $catid = json_decode($article['cat_arr_id'], true);
  3455. if (empty($catid)) {
  3456. return Result::error("该数据不存在", 0);
  3457. }
  3458. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3459. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3460. ->whereIn('category_id', $catid)
  3461. ->pluck('aLIas_pinyin')
  3462. ->implode('/');
  3463. }
  3464. if ($last_category['pid'] != 0) {
  3465. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3466. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3467. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3468. ->whereIn('category_id', $cat_arr)
  3469. ->pluck('aLIas_pinyin')
  3470. ->implode('/');
  3471. } else {
  3472. $pinyin = $last_category['aLIas_pinyin'];
  3473. }
  3474. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3475. return Result::error('非法路径!');
  3476. } else {
  3477. return Result::success($pinyin);
  3478. }
  3479. }
  3480. /**
  3481. * 招工招聘 - 获取推荐职位
  3482. * @param array $data
  3483. * @return array
  3484. */
  3485. public function getWebsiteLevelJob(array $data): array
  3486. {
  3487. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3488. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3489. ->where('job_recruiting.status', 1)
  3490. ->where('job_level', $data['job_level'])
  3491. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3492. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3493. ->orderBy('job_recruiting.updated_at', 'desc')
  3494. ->limit($data['pageSize'])
  3495. ->get();
  3496. $web = ['website_id' => $data['website_id']];
  3497. if (!empty($job)) {
  3498. $result = $this->processJob($job, $web);
  3499. }
  3500. if (empty($result)) {
  3501. return Result::error("暂无相关职位信息", 0);
  3502. }
  3503. return Result::success($result);
  3504. }
  3505. /**
  3506. * 验证导航名称是否重复
  3507. * @return void
  3508. */
  3509. //20250226 产品列表
  3510. public function getGoodList(array $data): array
  3511. {
  3512. var_dump($data, '---------1-2--');
  3513. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3514. unset($data['user_type_id']);
  3515. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3516. $where = [];
  3517. if ($type_id != '10000') {
  3518. $where = [
  3519. 'good.user_id' => $user_id,
  3520. ];
  3521. }
  3522. //类型
  3523. if (isset($data['type_id']) && $data['type_id']) {
  3524. $where['good.type_id'] = $data['type_id'];
  3525. }
  3526. //名称
  3527. if (isset($data['name']) && $data['name']) {
  3528. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3529. }
  3530. //status
  3531. if (isset($data['status']) && $data['status'] != '') {
  3532. $where['good.status'] = $data['status'];
  3533. }
  3534. //status1
  3535. // if (isset($data['status1']) && $data['status1'] == 1) {
  3536. // $status1 = 1;
  3537. // }
  3538. $where1 = [];
  3539. //website_id
  3540. // if (isset($data['website_id']) && $data['website_id']) {
  3541. // $where1 = [
  3542. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3543. // ];
  3544. // }
  3545. // website_name
  3546. if (isset($data['website_name']) && $data['website_name']) {
  3547. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3548. }
  3549. // catid
  3550. if (isset($data['category_name']) && $data['category_name']) {
  3551. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3552. }
  3553. // $result = Good::where($where)
  3554. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3555. var_dump($where, '---------1---');
  3556. $result = Good::where($where)
  3557. ->when(!empty($where1), function ($query) use ($where1) {
  3558. return $query->where($where1);
  3559. })
  3560. //status 1待审核2已审核3已拒绝
  3561. ->when(isset($data['status1']), function ($query) {
  3562. return $query->whereIn('good.status', [1, 3]);
  3563. })
  3564. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3565. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3566. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3567. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3568. ->orderBy("updated_at", "desc")
  3569. ->limit($data['page_size'])
  3570. ->offset(($data['page'] - 1) * $data['page_size'])
  3571. ->get();
  3572. $count = Good::where($where)
  3573. ->when(!empty($where1), function ($query) use ($where1) {
  3574. return $query->where($where1);
  3575. })
  3576. //status 1待审核2已审核3已拒绝
  3577. ->when(isset($data['status1']), function ($query) {
  3578. return $query->whereIn('good.status', [1, 3]);
  3579. })
  3580. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3581. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3582. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3583. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3584. ->orderBy("updated_at", "desc")->count();
  3585. $data = [
  3586. 'rows' => $result->toArray(),
  3587. 'count' => $count,
  3588. ];
  3589. if (empty($result)) {
  3590. return Result::error("此栏目暂无相关产品", 0);
  3591. }
  3592. return Result::success($data);
  3593. }
  3594. public function getGoodInfo(array $data): array
  3595. {
  3596. $result = Good::where('id', $data['id'])->first();
  3597. if (empty($result)) {
  3598. return Result::error("此产品不存在", 0);
  3599. }
  3600. return Result::success($result);
  3601. }
  3602. public function addGood(array $data): array
  3603. {
  3604. // unset($data['city_arr_id']);
  3605. // unset($data['cat_arr_id']);
  3606. $data['city_id'] = end($data['city_arr_id']);
  3607. $data['catid'] = end($data['cat_arr_id']);
  3608. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3609. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3610. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3611. unset($data['imgUrl']); //大小写
  3612. if (isset($data['price']) && $data['price'] == '') {
  3613. $data['price'] = 0;
  3614. }
  3615. if ($data['imgurl'] == '') {
  3616. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3617. preg_match_all($reg, $data['detail'], $matches);
  3618. if (isset($matches[1][0])) {
  3619. //截取varchar240
  3620. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3621. }
  3622. }
  3623. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3624. //提取标题+内容中的关键词
  3625. $data['keyword'] = $data['name'];
  3626. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3627. Jieba::init(); // 初始化 jieba-php
  3628. Finalseg::init();
  3629. $segList = Jieba::cut($data['keyword']);
  3630. $segList1 = array_slice($segList, 0, 8);
  3631. $data['keyword'] = implode(',', $segList1);
  3632. }
  3633. if ($data['description'] == '') {
  3634. //提取内容中的描述
  3635. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3636. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3637. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3638. }
  3639. if ($data['status'] == 1) {
  3640. $this->sendMessage([
  3641. 'talk_type' => 200,
  3642. 'title' => $data['name'],
  3643. 'content' => '提交了审核',
  3644. 'messageType' => 3,
  3645. ]);
  3646. }
  3647. $result = Good::insert($data);
  3648. if (empty($result)) {
  3649. return Result::error("添加失败", 0);
  3650. }
  3651. return Result::success($result);
  3652. }
  3653. public function updateGood(array $data): array
  3654. {
  3655. $data['city_id'] = end($data['city_arr_id']);
  3656. $data['catid'] = end($data['cat_arr_id']);
  3657. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3658. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3659. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3660. //设置东八区
  3661. date_default_timezone_set('Asia/Shanghai');
  3662. $data['updated_at'] = date('Y-m-d H:i:s');
  3663. if (isset($data['price']) && $data['price'] == '') {
  3664. $data['price'] = 0;
  3665. }
  3666. if ($data['imgurl'] == '') {
  3667. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3668. preg_match_all($reg, $data['detail'], $matches);
  3669. if (isset($matches[1][0])) {
  3670. //截取varchar240
  3671. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3672. }
  3673. }
  3674. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3675. //提取标题+内容中的关键词
  3676. $data['keyword'] = $data['name'];
  3677. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3678. Jieba::init(); // 初始化 jieba-php
  3679. Finalseg::init();
  3680. $segList = Jieba::cut($data['keyword']);
  3681. $segList1 = array_slice($segList, 0, 8);
  3682. $data['keyword'] = implode(',', $segList1);
  3683. }
  3684. if ($data['description'] == '') {
  3685. //提取内容中的描述
  3686. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3687. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3688. }
  3689. if ($data['status'] == 1) {
  3690. $this->sendMessage([
  3691. 'talk_type' => 200,
  3692. 'title' => $data['name'],
  3693. 'content' => '提交了审核',
  3694. 'messageType' => 3,
  3695. ]);
  3696. }
  3697. $result = Good::where('id', $data['id'])->update($data);
  3698. if (empty($result)) {
  3699. return Result::error("更新失败", 0);
  3700. }
  3701. return Result::success($result);
  3702. }
  3703. public function delGood(array $data): array
  3704. {
  3705. $result = Good::where('id', $data['id'])->delete();
  3706. if (empty($result)) {
  3707. return Result::error("删除失败", 0);
  3708. }
  3709. return Result::success($result);
  3710. }
  3711. //20250226 产品列表
  3712. //20250306 求职信息
  3713. public function getJobHuntingList(array $data): array
  3714. {
  3715. $where = [];
  3716. if (isset($data['username']) && !empty($data['username'])) {
  3717. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3718. }
  3719. //status 1待审核2已审核3已拒绝
  3720. if (isset($data['status']) && $data['status'] != '') {
  3721. $where = [
  3722. 'job_hunting.status' => $data['status'],
  3723. ];
  3724. }
  3725. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3726. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3727. unset($data['type_id']);
  3728. if ($type_id != '10000') {
  3729. $where[] = ['job_hunting.user_id', '=', $user_id];
  3730. }
  3731. $result = JobHunting::where($where)
  3732. ->when(!empty($data['status1']), function ($query) use ($data) {
  3733. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3734. })
  3735. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3736. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3737. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3738. ->orderBy("updated_at", "desc")
  3739. ->limit($data['page_size'])
  3740. ->offset(($data['page'] - 1) * $data['page_size'])
  3741. ->get();
  3742. if (empty($result)) {
  3743. return Result::error("查询失败", 0);
  3744. }
  3745. $count = JobHunting::where($where)
  3746. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3747. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3748. ->count();
  3749. $data = [
  3750. 'rows' => $result->toArray(),
  3751. 'count' => $count,
  3752. ];
  3753. return Result::success($data);
  3754. }
  3755. public function getJobHuntingApply(array $data): array
  3756. {
  3757. var_dump($data, '-----------------test--------1-');
  3758. $where = [];
  3759. if (isset($data['username']) && !empty($data['username'])) {
  3760. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3761. }
  3762. if (isset($data['salary']) && !empty($data['salary'])) {
  3763. $where[] = [
  3764. 'job_hunting.salary',
  3765. '=',
  3766. $data['salary'],
  3767. ];
  3768. }
  3769. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3770. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3771. unset($data['type_id']);
  3772. if ($type_id != '10000') {
  3773. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3774. }
  3775. var_dump($where, '-----------------test---------');
  3776. $result = jobApply::where($where)
  3777. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3778. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3779. // })
  3780. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3781. ->where('job_enum.egroup', '=', 'income')
  3782. ->where('job_hunting.status', 2) //已审核
  3783. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3784. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3785. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3786. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3787. //职位----是申请职位
  3788. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3789. ->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')
  3790. ->orderBy("job_hunting.updated_at", "desc")
  3791. ->limit($data['page_size'])
  3792. ->offset(($data['page'] - 1) * $data['page_size'])
  3793. ->get();
  3794. if (empty($result)) {
  3795. return Result::error("查询失败", 0);
  3796. }
  3797. $count = jobApply::where($where)
  3798. ->where('job_enum.egroup', '=', 'income')
  3799. ->where('job_hunting.status', 2) //已审核
  3800. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3801. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3802. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3803. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3804. //职位----是申请职位
  3805. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3806. ->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')
  3807. ->count();
  3808. $data = [
  3809. 'rows' => $result->toArray(),
  3810. 'count' => $count,
  3811. ];
  3812. return Result::success($data);
  3813. }
  3814. public function addJobHunting(array $data): array
  3815. {
  3816. date_default_timezone_set('Asia/Shanghai');
  3817. unset($data['company_name']);
  3818. unset($data['job_industry']);
  3819. unset($data['job_name']);
  3820. unset($data['department']);
  3821. unset($data['job_timeList']);
  3822. unset($data['job_content']);
  3823. unset($data['job_typename']); //不知道这是啥,
  3824. $data['created_at'] = date('Y-m-d H:i:s');
  3825. $data['updated_at'] = date('Y-m-d H:i:s');
  3826. //根据用户 user_id 只能添加一次
  3827. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3828. if (!empty($result)) {
  3829. return Result::error("您已添加过求职信息", 0);
  3830. }
  3831. var_dump($result, '-----------------test---------');
  3832. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3833. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3834. $cityArr = json_decode($data['city_arr_id'], true);
  3835. $data['city_id'] = end($cityArr);
  3836. } else {
  3837. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3838. $data['city_id'] = end($data['city_arr_id']);
  3839. }
  3840. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3841. $this->sendMessage([
  3842. 'talk_type' => 600,
  3843. 'title' => $data['name'],
  3844. 'content' => '提交了审核',
  3845. 'messageType' => 11,
  3846. ]);
  3847. }
  3848. $result = JobHunting::create($data);
  3849. if (empty($result)) {
  3850. return Result::error("添加失败", 0);
  3851. }
  3852. return Result::success($result);
  3853. }
  3854. public function delJobHunting(array $data): array
  3855. {
  3856. $result = JobHunting::where('id', $data['id'])->delete();
  3857. if (empty($result)) {
  3858. return Result::error("删除失败", 0);
  3859. }
  3860. return Result::success($result);
  3861. }
  3862. public function updateJobHunting(array $data): array
  3863. {
  3864. //设置东八区
  3865. date_default_timezone_set('Asia/Shanghai');
  3866. unset($data['company_name']);
  3867. unset($data['job_industry']);
  3868. unset($data['job_name']);
  3869. unset($data['department']);
  3870. unset($data['job_timeList']);
  3871. unset($data['job_content']);
  3872. unset($data['job_typename']); //不知道这是啥,
  3873. $data['created_at'] = date('Y-m-d H:i:s');
  3874. $data['updated_at'] = date('Y-m-d H:i:s');
  3875. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3876. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3877. $cityArr = json_decode($data['city_arr_id'], true);
  3878. $data['city_id'] = end($cityArr);
  3879. } else {
  3880. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3881. $data['city_id'] = end($data['city_arr_id']);
  3882. }
  3883. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3884. $this->sendMessage([
  3885. 'talk_type' => 600,
  3886. 'title' => $data['name'],
  3887. 'content' => '提交了审核',
  3888. 'messageType' => 11,
  3889. ]);
  3890. }
  3891. $result = JobHunting::where('id', $data['id'])->update($data);
  3892. if (empty($result)) {
  3893. return Result::error("更新失败", 0);
  3894. }
  3895. return Result::success($result);
  3896. }
  3897. public function getJobHuntingInfo(array $data): array
  3898. {
  3899. $result = JobHunting::where('id', $data['id'])->first();
  3900. if (empty($result)) {
  3901. return Result::error("查询失败", 0);
  3902. }
  3903. return Result::success($result);
  3904. }
  3905. public function getJobHuntingData(array $data): array
  3906. {
  3907. $jobEnum = JobEnum::get();
  3908. $jobIndustry = JobIndustry::get();
  3909. $jobNature = JobNature::get();
  3910. $jobPosition = JobPosition::get();
  3911. $data = [
  3912. 'jobEnum' => $jobEnum,
  3913. 'jobIndustry' => $jobIndustry,
  3914. 'jobNature' => $jobNature,
  3915. 'jobPosition' => $jobPosition,
  3916. ];
  3917. return Result::success($data);
  3918. }
  3919. public function delJobHuntingInfo(array $data): array
  3920. {
  3921. $result = JobHunting::where('id', $data['id'])->delete();
  3922. return Result::success();
  3923. }
  3924. //20250324 通知,公告,消息
  3925. public function delNotice(array $data): array
  3926. {
  3927. $result = Notice::where('id', $data['id'])->delete();
  3928. if ($result) {
  3929. return Result::success();
  3930. } else {
  3931. return Result::error("删除失败", 0);
  3932. }
  3933. }
  3934. public function getNoticeInfo(array $data): array
  3935. {
  3936. $result = Notice::where('id', $data['id'])->first();
  3937. // var_dump($result['re_user_ids'], '--------------------');
  3938. if (empty($result)) {
  3939. return Result::error("查询失败", 0);
  3940. }
  3941. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3942. $re_user_ids = json_decode($result['re_user_ids'], true);
  3943. var_dump($re_user_ids, '--------------1---test---------');
  3944. var_dump($data, '--------------1---test---------');
  3945. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3946. //如果已经存在,就不再添加
  3947. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3948. $read_id = json_decode($result['read_id'], true);
  3949. if (!is_array($read_id)) {
  3950. $read_id = [];
  3951. }
  3952. if (!in_array($data['user_id'], $read_id)) {
  3953. $read_id[] = $data['user_id'];
  3954. $result['read_id'] = json_encode($read_id);
  3955. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3956. }
  3957. } else {
  3958. //如果不存在,就添加
  3959. $result['read_id'] = json_encode([$data['user_id']]);
  3960. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3961. }
  3962. }
  3963. return Result::success($result);
  3964. }
  3965. public function addNotice(array $data): array
  3966. {
  3967. date_default_timezone_set('Asia/Shanghai');
  3968. $data['created_at'] = date('Y-m-d H:i:s');
  3969. $data['updated_at'] = date('Y-m-d H:i:s');
  3970. $user_id = UserInfo::
  3971. //city_id不是null
  3972. whereNotNull('city_id')
  3973. ->whereNotNull('department_id')
  3974. ->where(function ($query) use ($data) {
  3975. $query->where(function ($subQuery) use ($data) {
  3976. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3977. });
  3978. })
  3979. ->where(function ($query) use ($data) {
  3980. $query->where(function ($subQuery) use ($data) {
  3981. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3982. });
  3983. })
  3984. ->pluck('user_id')->toArray();
  3985. $user_id = array_unique($user_id);
  3986. $chat_ids = $user_id;
  3987. $user_id = json_encode($user_id);
  3988. $data['re_user_ids'] = $user_id;
  3989. $this->sendMessage([
  3990. 'talk_type' => 700,
  3991. 'title' => $data['title'],
  3992. 'content' => '提交了审核',
  3993. 'messageType' => 5,
  3994. ]);
  3995. $result = Notice::insertGetId($data);
  3996. if (empty($result)) {
  3997. return Result::error("添加失败", 0);
  3998. }
  3999. return Result::success($result);
  4000. }
  4001. public function updateNotice(array $data): array
  4002. {
  4003. date_default_timezone_set('Asia/Shanghai');
  4004. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4005. $user_id = UserInfo::
  4006. //city_id不是null
  4007. whereNotNull('city_id')
  4008. ->whereNotNull('department_id')
  4009. ->where(function ($query) use ($data) {
  4010. $query->where(function ($subQuery) use ($data) {
  4011. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4012. });
  4013. })
  4014. ->where(function ($query) use ($data) {
  4015. $query->where(function ($subQuery) use ($data) {
  4016. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4017. });
  4018. })
  4019. ->pluck('user_id')->toArray();
  4020. $user_id = array_unique($user_id);
  4021. $user_id = json_encode($user_id);
  4022. $data['re_user_ids'] = $user_id;
  4023. $data['updated_at'] = date('Y-m-d H:i:s');
  4024. $this->sendMessage([
  4025. 'talk_type' => 700,
  4026. 'title' => $data['title'],
  4027. 'content' => '提交了审核',
  4028. 'messageType' => 5,
  4029. ]);
  4030. $result = Notice::where('id', $data['id'])->update($data);
  4031. return Result::success($result);
  4032. }
  4033. public function getNoticeList(array $data): array
  4034. {
  4035. $where = [];
  4036. //title
  4037. if (isset($data['title']) && !empty($data['title'])) {
  4038. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4039. }
  4040. //level
  4041. if (isset($data['level']) && !empty($data['level'])) {
  4042. $where[] = ['notice.level', '=', $data['level']];
  4043. }
  4044. //status
  4045. if (isset($data['status']) && !empty($data['status'])) {
  4046. $where[] = ['notice.status', '=', $data['status']];
  4047. }
  4048. //type
  4049. if (isset($data['type']) && !empty($data['type'])) {
  4050. $where[] = ['notice.type', '=', $data['type']];
  4051. }
  4052. var_dump($data, '------------11111-2----test---------');
  4053. if ($data['type_id'] == 10000) {
  4054. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4055. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4056. })
  4057. ->where($where)
  4058. ->orderBy('updated_at', 'desc')
  4059. ->limit($data['page_size'])
  4060. ->offset(($data['page'] - 1) * $data['page_size'])
  4061. ->get();
  4062. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4063. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4064. })
  4065. ->where($where)
  4066. ->orderBy('updated_at', 'desc')
  4067. ->count();
  4068. } else {
  4069. $result = Notice::where($where)
  4070. // ->where('user_id', $data['user_id'])
  4071. ->Where(function ($query) use ($data) {
  4072. $query->Where(function ($q) use ($data) {
  4073. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4074. ->orWhere('notice.user_id', $data['user_id']);
  4075. });
  4076. })
  4077. ->when(!empty($data['status1']), function ($query) use ($data) {
  4078. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4079. })
  4080. ->orderBy('updated_at', 'desc')
  4081. ->limit($data['page_size'])
  4082. ->offset(($data['page'] - 1) * $data['page_size'])
  4083. ->get();
  4084. $total = Notice::where($where)
  4085. ->when(!empty($data['status1']), function ($query) use ($data) {
  4086. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4087. })
  4088. // ->where('user_id', $data['user_id'])
  4089. ->Where(function ($query) use ($data) {
  4090. $query->Where(function ($q) use ($data) {
  4091. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4092. ->orWhere('notice.user_id', $data['user_id']);
  4093. });
  4094. })
  4095. ->count();
  4096. }
  4097. if (empty($result)) {
  4098. return Result::error("查询失败", 0);
  4099. }
  4100. $data = [
  4101. 'rows' => $result,
  4102. 'count' => $total,
  4103. ];
  4104. return Result::success($data);
  4105. }
  4106. public function getNoticeDetail(array $data): array
  4107. {
  4108. $result = Notice::where('id', $data['id'])->first();
  4109. if (empty($result)) {
  4110. return Result::error("查询失败", 0);
  4111. }
  4112. return Result::success($result);
  4113. }
  4114. public function deleteNotice(array $data): array
  4115. {
  4116. $notice = Notice::where('id', $data['id'])->first();
  4117. if (empty($notice)) {
  4118. return Result::error("删除失败", 0);
  4119. }
  4120. $chat_group_id = $notice->group_id;
  4121. if ($chat_group_id) {
  4122. //删除群聊
  4123. ChatGroups::where('id', $chat_group_id)->delete();
  4124. //删除群成员
  4125. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4126. //删除群聊记录
  4127. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4128. }
  4129. $result = Notice::where('id', $data['id'])->delete();
  4130. return Result::success($result);
  4131. }
  4132. public function getComplaintList(array $data): array
  4133. {
  4134. var_dump($data, '00000001000000000000');
  4135. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4136. unset($data['type_id']);
  4137. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4138. $where = [];
  4139. if ($type_id != 10000 && empty($data['deal_user'])) {
  4140. $where['complaint.user_id'] = $user_id;
  4141. }
  4142. if (!empty($data['title'])) {
  4143. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4144. }
  4145. if (!empty($data['department_id'])) {
  4146. $where['complaint.department_id'] = $data['department_id'];
  4147. }
  4148. if (!empty($data['deal'])) {
  4149. $where['complaint.deal'] = $data['deal'];
  4150. }
  4151. if (!empty($data['status'])) {
  4152. $where['complaint.status'] = $data['status'];
  4153. }
  4154. var_dump(!empty($data['deal_user']), '----------1');
  4155. var_dump($where, '----------2');
  4156. $result = Complaint::where($where)
  4157. ->when(!empty($data['status1']), function ($query) use ($data) {
  4158. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4159. })
  4160. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4161. //json re_user_ids data[user_id]是不是在里面
  4162. $query->Where(function ($q) use ($data) {
  4163. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4164. ->where('complaint.status', 2);
  4165. });
  4166. })
  4167. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4168. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4169. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4170. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4171. ->orderBy('updated_at', 'desc')
  4172. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4173. //sql输出
  4174. if (empty($result)) {
  4175. return Result::error("暂无投诉信息", 0);
  4176. }
  4177. // 取出数据
  4178. $rows = $result->items();
  4179. $count = $result->total();
  4180. $responseData = [
  4181. 'rows' => $rows,
  4182. 'count' => $count,
  4183. ];
  4184. return Result::success($responseData);
  4185. }
  4186. public function getComplaintInfo(array $data): array
  4187. {
  4188. $result = Complaint::where('id', $data['id'])->first();
  4189. if (empty($result)) {
  4190. return Result::error("查询失败", 0);
  4191. }
  4192. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4193. $re_user_ids = json_decode($result['re_user_ids'], true);
  4194. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4195. //如果已经存在,就不再添加
  4196. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4197. $read_id = json_decode($result['read_id'], true);
  4198. if (!is_array($read_id)) {
  4199. $read_id = [];
  4200. }
  4201. if (!in_array($data['user_id'], $read_id)) {
  4202. $read_id[] = $data['user_id'];
  4203. $result['read_id'] = json_encode($read_id);
  4204. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4205. }
  4206. } else {
  4207. //如果不存在,就添加
  4208. $result['read_id'] = json_encode([$data['user_id']]);
  4209. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4210. }
  4211. }
  4212. return Result::success($result);
  4213. }
  4214. public function addComplaint(array $data): array
  4215. {
  4216. date_default_timezone_set('Asia/Shanghai');
  4217. $data['created_at'] = date('Y-m-d H:i:s');
  4218. $data['updated_at'] = date('Y-m-d H:i:s');
  4219. $this->sendMessage([
  4220. 'talk_type' => 800,
  4221. 'title' => $data['title'],
  4222. 'content' => '提交了审核',
  4223. 'messageType' => 6,
  4224. ]);
  4225. $result = Complaint::create($data);
  4226. return Result::success($result);
  4227. }
  4228. public function updateComplaint(array $data): array
  4229. {
  4230. date_default_timezone_set('Asia/Shanghai');
  4231. $data['updated_at'] = date('Y-m-d H:i:s');
  4232. $user_id = $data['user_id'] ?? 0;
  4233. $type_id = $data['type_id'] ?? 0;
  4234. unset($data['user_id']);
  4235. unset($data['type_id']);
  4236. $this->sendMessage([
  4237. 'talk_type' => 800,
  4238. 'title' => $data['title'],
  4239. 'content' => '提交了审核',
  4240. 'messageType' => 6,
  4241. ]);
  4242. $result = Complaint::where('id', $data['id'])->update($data);
  4243. return Result::success($result);
  4244. }
  4245. public function deleteComplaint(array $data): array
  4246. {
  4247. $result = Complaint::where('id', $data['id'])->delete();
  4248. return Result::success($result);
  4249. }
  4250. public function getComplainInfo(array $data): array
  4251. {
  4252. $result = Complaint::where('id', $data['id'])->first();
  4253. if (empty($result)) {
  4254. return Result::error("查询失败", 0);
  4255. }
  4256. return Result::success($result);
  4257. }
  4258. public function updateComplaintStatus(array $data): array
  4259. {
  4260. date_default_timezone_set('Asia/Shanghai');
  4261. $data['updated_at'] = date('Y-m-d H:i:s');
  4262. $user_id = $data['user_id'] ?? 0;
  4263. $type_id = $data['type_id'] ?? 0;
  4264. unset($data['user_id']);
  4265. unset($data['type_id']);
  4266. //处理, 写入处理人
  4267. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4268. $data['real_deal_user'] = $user_id;
  4269. }
  4270. //如果是deal 23,则判断是不是处理人
  4271. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4272. $complaintInof = Complaint::where('id', $data['id'])
  4273. ->where('real_deal_user', $user_id)
  4274. ->first();
  4275. if (empty($complaintInof)) {
  4276. return Result::error("处理人错误", 0);
  4277. }
  4278. }
  4279. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4280. if ($data['status'] == 1) {
  4281. $this->sendMessage([
  4282. 'talk_type' => 800,
  4283. 'title' => $complaintInfo['title'],
  4284. 'content' => '提交了审核',
  4285. 'messageType' => 6,
  4286. ]);
  4287. }
  4288. if ($data['status'] == 2 && !isset($data['deal'])) {
  4289. $this->sendMessage([
  4290. 'talk_type' => 801,
  4291. 'title' => $complaintInfo['title'],
  4292. 'content' => '审核通过',
  4293. 'messageType' => 6,
  4294. 'user_id' => $complaintInfo['user_id'],
  4295. ]);
  4296. $this->sendMessage([
  4297. 'talk_type' => 802,
  4298. 'title' => $complaintInfo['title'],
  4299. 'content' => '待处理',
  4300. 'messageType' => 6,
  4301. 'user_id' => $complaintInfo['re_user_ids'],
  4302. ]);
  4303. }
  4304. if ($data['status'] == 3 && !isset($data['deal'])) {
  4305. $this->sendMessage([
  4306. 'talk_type' => 801,
  4307. 'title' => $complaintInfo['title'],
  4308. 'content' => '审核拒绝',
  4309. 'messageType' => 6,
  4310. 'user_id' => $complaintInfo['user_id'],
  4311. ]);
  4312. }
  4313. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4314. $this->sendMessage([
  4315. 'talk_type' => 802,
  4316. 'title' => $complaintInfo['title'],
  4317. 'content' => '处理中',
  4318. 'messageType' => 6,
  4319. 'user_id' => $complaintInfo['re_user_ids'],
  4320. ]);
  4321. }
  4322. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4323. $this->sendMessage([
  4324. 'talk_type' => 802,
  4325. 'title' => $complaintInfo['title'],
  4326. 'content' => '不予处理',
  4327. 'messageType' => 6,
  4328. 'user_id' => $complaintInfo['re_user_ids'],
  4329. ]);
  4330. }
  4331. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4332. $this->sendMessage([
  4333. 'talk_type' => 802,
  4334. 'title' => $complaintInfo['title'],
  4335. 'content' => '已完结',
  4336. 'messageType' => 6,
  4337. 'user_id' => $complaintInfo['re_user_ids'],
  4338. ]);
  4339. }
  4340. $result = complaint::where('id', $data['id'])->update($data);
  4341. return Result::success($result);
  4342. }
  4343. public function updateGoodStatus(array $data): array
  4344. {
  4345. $user_id = $data['user_id'] ?? 0;
  4346. $type_id = $data['type_id'] ?? 0;
  4347. unset($data['user_id']);
  4348. unset($data['type_id']);
  4349. $goodInfo = Good::where('id', $data['id'])->first();
  4350. if ($data['status'] == 2) {
  4351. $this->sendMessage([
  4352. 'talk_type' => 201,
  4353. 'title' => $goodInfo['name'],
  4354. 'content' => '审核通过',
  4355. 'messageType' => 3,
  4356. 'user_id' => $goodInfo['user_id'],
  4357. ]);
  4358. }
  4359. if ($data['status'] == 3) {
  4360. $this->sendMessage([
  4361. 'talk_type' => 201,
  4362. 'title' => $goodInfo['name'],
  4363. 'content' => '审核拒绝',
  4364. 'messageType' => 3,
  4365. 'user_id' => $goodInfo['user_id'],
  4366. ]);
  4367. }
  4368. if ($data['status'] == 1) {
  4369. $this->sendMessage([
  4370. 'talk_type' => 200,
  4371. 'title' => $goodInfo['name'],
  4372. 'content' => '提交了审核',
  4373. 'messageType' => 3,
  4374. ]);
  4375. }
  4376. $result = Good::where('id', $data['id'])->update($data);
  4377. return Result::success($result);
  4378. }
  4379. public function updateJobHuntingStatus(array $data): array
  4380. {
  4381. $user_id = $data['user_id'] ?? 0;
  4382. $type_id = $data['type_id'] ?? 0;
  4383. unset($data['user_id']);
  4384. unset($data['type_id']);
  4385. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4386. if ($data['status'] == 2) {
  4387. $this->sendMessage([
  4388. 'talk_type' => 601,
  4389. 'title' => $jogHuntingInfo['name'],
  4390. 'content' => '审核通过',
  4391. 'messageType' => 11,
  4392. 'user_id' => $jogHuntingInfo['user_id'],
  4393. ]);
  4394. }
  4395. if ($data['status'] == 3) {
  4396. $this->sendMessage([
  4397. 'talk_type' => 601,
  4398. 'title' => $jogHuntingInfo['name'],
  4399. 'content' => '审核拒绝',
  4400. 'messageType' => 11,
  4401. 'user_id' => $jogHuntingInfo['user_id'],
  4402. ]);
  4403. }
  4404. if ($data['status'] == 1) {
  4405. $this->sendMessage([
  4406. 'talk_type' => 600,
  4407. 'title' => $jogHuntingInfo['name'],
  4408. 'content' => '提交了审核',
  4409. 'messageType' => 11,
  4410. ]);
  4411. }
  4412. $result = JobHunting::where('id', $data['id'])->update($data);
  4413. return Result::success($result);
  4414. }
  4415. public function updateNoticeStatus(array $data): array
  4416. {
  4417. $user_id = $data['user_id'] ?? 0;
  4418. $type_id = $data['type_id'] ?? 0;
  4419. unset($data['user_id']);
  4420. unset($data['type_id']);
  4421. //查询公告
  4422. $notice = Notice::where('id', $data['id'])->first();
  4423. if (empty($notice)) {
  4424. return Result::error("公告不存在", 0);
  4425. }
  4426. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4427. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4428. //chat_group
  4429. $group_id = PublicData::uuid();
  4430. $groupData = [
  4431. 'id' => $group_id,
  4432. 'creator_id' => $notice['user_id'],
  4433. 'group_name' => $notice['group_name'] ?? '',
  4434. 'profile' => $notice['profile'] ?? 0,
  4435. ];
  4436. var_dump($groupData, '-----------------groupData-------');
  4437. $groupResult = ChatGroups::insertGetId($groupData);
  4438. var_dump($groupResult, '-----------------groupid-------');
  4439. $groupMemberData = [
  4440. 'id' => PublicData::uuid(),
  4441. 'user_id' => $notice['user_id'],
  4442. 'group_id' => $group_id,
  4443. 'leader' => 2,
  4444. ];
  4445. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4446. //$chat_ids 去除掉$data['user_id']
  4447. $chat_ids = json_decode($notice['re_user_ids'], true);
  4448. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4449. //插入群成员表
  4450. $groupMemberDataUser = [];
  4451. $chatData = [];
  4452. foreach ($chat_ids as $key => $value) {
  4453. $groupMemberDataUser[] = [
  4454. 'id' => PublicData::uuid(),
  4455. 'user_id' => $value,
  4456. 'group_id' => $group_id,
  4457. 'leader' => 1,
  4458. ];
  4459. $chatData[] = [
  4460. 'user_id' => $value,
  4461. 'msg_type' => 1,
  4462. 'receiver_id' => $group_id,
  4463. 'content' => '通过通知创建群聊',
  4464. 'group_receiver_id' => $notice['user_id'],
  4465. 'action' => 'recieved',
  4466. 'created_at' => date('Y-m-d H:i:s'),
  4467. ];
  4468. }
  4469. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4470. ChatGroupsMember::insert($groupMemberDataUser);
  4471. //插入一条管理员聊天记录
  4472. $chatData[] = [
  4473. 'user_id' => $notice['user_id'],
  4474. 'msg_type' => 1,
  4475. 'receiver_id' => $group_id,
  4476. 'content' => '通过通知创建群聊',
  4477. 'group_receiver_id' => $notice['user_id'],
  4478. 'action' => 'said',
  4479. 'created_at' => date('Y-m-d H:i:s'),
  4480. ];
  4481. var_dump($chatData, '-----------------chatData-------');
  4482. $chatResult = ChatRecords::insert($chatData);
  4483. //更新result的 group_id
  4484. $data['group_id'] = $group_id;
  4485. Notice::where(['id' => $data['id']])->update($data);
  4486. }
  4487. $result = Notice::where('id', $data['id'])->update($data);
  4488. $noticeInfo = Notice::where('id', $data['id'])->first();
  4489. if ($data['status'] == 2) {
  4490. $this->sendMessage([
  4491. 'talk_type' => 701,
  4492. 'title' => $noticeInfo['title'],
  4493. 'content' => '审核通过',
  4494. 'messageType' => 3,
  4495. 'user_id' => $noticeInfo['user_id'],
  4496. ]);
  4497. }
  4498. if ($data['status'] == 3) {
  4499. $this->sendMessage([
  4500. 'talk_type' => 701,
  4501. 'title' => $noticeInfo['title'],
  4502. 'content' => '审核拒绝',
  4503. 'messageType' => 3,
  4504. 'user_id' => $noticeInfo['user_id'],
  4505. ]);
  4506. }
  4507. if ($data['status'] == 1) {
  4508. $this->sendMessage([
  4509. 'talk_type' => 700,
  4510. 'title' => $noticeInfo['title'],
  4511. 'content' => '提交了审核',
  4512. 'messageType' => 3,
  4513. ]);
  4514. }
  4515. return Result::success($result);
  4516. }
  4517. public function getDUser(array $data): array
  4518. {
  4519. if (!empty($data['ids'])) {
  4520. $user = User::whereIn('id', $data['ids'])->getall();
  4521. if (empty($user)) {
  4522. return Result::error('无数据', 0);
  4523. }
  4524. return Result::success($user);
  4525. }
  4526. $where = [];
  4527. if (!empty($data['department_id'])) {
  4528. $where['department_id'] = $data['department_id'];
  4529. }
  4530. if (!empty($data['city_id'])) {
  4531. $where['city_id'] = $data['city_id'];
  4532. }
  4533. $result = User::where('type_id', 2)
  4534. ->where('status', 1)
  4535. ->where($where)
  4536. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4537. ->get();
  4538. if (empty($result)) {
  4539. return Result::error("查询失败", 0);
  4540. }
  4541. return Result::success($result);
  4542. }
  4543. /**
  4544. * 验证导航名称是否重复
  4545. * @return void
  4546. */
  4547. public function checkCategoryName(array $data): array
  4548. {
  4549. $result = Category::when($data, function ($query) use ($data) {
  4550. if (isset($data['name']) && $data['name']) {
  4551. $query->where("name", $data['name']);
  4552. }
  4553. if (isset($data['id']) && $data['id']) {
  4554. $query->where("id", "!=", $data['id']);
  4555. }
  4556. })->first();
  4557. if ($result) {
  4558. return Result::error("已存在");
  4559. } else {
  4560. return Result::success();
  4561. }
  4562. }
  4563. //20250226 产品列表
  4564. // 20250306 -------招聘--------fr
  4565. /*
  4566. * 招聘列表
  4567. * */
  4568. public function getJobRecruitingList(array $data): array
  4569. {
  4570. $where = [];
  4571. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4572. if ($data['checkout'] == 0) {
  4573. $job_status = [0, 2];
  4574. } else {
  4575. $job_status = [1];
  4576. }
  4577. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4578. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4579. }
  4580. $user = User::where('id', $data['user_id'])->first();
  4581. if (empty($user)) {
  4582. return Result::error("用户不存在", 0);
  4583. }
  4584. // 3:企业会员
  4585. if ($user['type_id'] == 3) {
  4586. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4587. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4588. }
  4589. // 如果 $where 为空,则不添加 where 条件
  4590. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4591. return $query->where($where);
  4592. })
  4593. ->whereIn('job_recruiting.status', $job_status)
  4594. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4595. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4596. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4597. ->orderBy("updated_at", "desc")
  4598. ->offset(($data['page'] - 1) * $data['page_size'])
  4599. ->limit($data['page_size'])
  4600. ->get()
  4601. ->all();
  4602. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4603. return $query->where($where);
  4604. })
  4605. ->whereIn('job_recruiting.status', $job_status)
  4606. ->count();
  4607. if (empty($result)) {
  4608. return Result::error("暂无招聘信息", 0);
  4609. }
  4610. return Result::success($result);
  4611. }
  4612. /*
  4613. * 招聘信息添加
  4614. * */
  4615. public function addJobRecruiting(array $data): array
  4616. {
  4617. // return Result::success($data);
  4618. $user = User::where('user.id', $data['user_id'])
  4619. ->where('user.status', 1)
  4620. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4621. ->select(
  4622. 'user.type_id',
  4623. 'user.mobile',
  4624. 'user.email',
  4625. 'user_info.business_name',
  4626. 'user_info.company_hy_id',
  4627. 'user_info.company_nature',
  4628. 'user_info.company_size',
  4629. 'user_info.introduction',
  4630. 'user_info.real_name',
  4631. 'user_info.company_url',
  4632. 'user_info.address_arr_id',
  4633. 'user_info.address'
  4634. )
  4635. ->first();
  4636. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4637. return Result::error("用户不存在", 0);
  4638. }
  4639. $web = Website::where('id', $data['website_id'])->first();
  4640. if (empty($web)) {
  4641. return Result::error("网站不存在", 0);
  4642. }
  4643. // return Result::success($user);
  4644. $data['action_id'] = $data['user_id'];
  4645. $data['user_type'] = $user['type_id'];
  4646. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4647. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4648. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4649. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4650. // 公司地址 管理员必填
  4651. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4652. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4653. // 管理员-企业相关信息
  4654. $company = [
  4655. // 'user_id' => $data['user_id']?? null,
  4656. 'business_name' => $data['business_name'] ?? null,
  4657. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4658. 'company_size' => $data['company_size'] ?? null,
  4659. 'company_nature' => $data['company_nature'] ?? null,
  4660. 'introduction' => $data['introduction'] ?? null,
  4661. 'real_name' => $data['real_name'] ?? null,
  4662. 'mobile' => $data['mobile'] ?? null,
  4663. 'company_url' => $data['company_url'] ?? null,
  4664. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4665. 'address' => $data['address'] ?? null,
  4666. 'email' => $data['email'] ?? null,
  4667. ];
  4668. //去掉相关企业信息
  4669. $job = array_diff_key($data, array_flip(array_keys($company)));
  4670. Db::beginTransaction();
  4671. try {
  4672. // 先添加职位相关信息
  4673. if ($user['type_id'] == 10000) {
  4674. $job['status'] = 1;
  4675. }
  4676. if (empty($data['experience']) || $data['experience'] == '') {
  4677. $job['experience'] = null;
  4678. } else {
  4679. $job['experience'] = $data['experience'];
  4680. }
  4681. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4682. $this->sendMessage([
  4683. 'talk_type' => 500,
  4684. 'title' => $data['title'],
  4685. 'content' => '提交了审核',
  4686. 'messageType' => 10,
  4687. ]);
  4688. }
  4689. $jobId = JobRecruiting::insertGetId($job);
  4690. if (empty($jobId)) {
  4691. Db::rollBack();
  4692. return Result::error("添加失败");
  4693. }
  4694. // 添加公司信息
  4695. $company['user_id'] = $data['user_id'] ?? null;
  4696. $company['job_id'] = $jobId;
  4697. $company['user_type'] = $user['type_id'] ?? null;
  4698. $company['website_id'] = $data['website_id'] ?? null;
  4699. if ($user['type_id'] == 10000) {
  4700. // 管理员添加企业信息
  4701. // return Result::success($company);
  4702. $companyId = JobCompany::insertGetId($company);
  4703. if (empty($companyId)) {
  4704. Db::rollBack();
  4705. return Result::error("添加失败");
  4706. }
  4707. } else {
  4708. // 企业会员添加企业信息
  4709. $company = [
  4710. 'user_id' => $data['user_id'] ?? null,
  4711. 'business_name' => $user['business_name'] ?? null,
  4712. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4713. 'company_size' => $user['company_size'] ?? null,
  4714. 'company_nature' => $user['company_nature'] ?? null,
  4715. 'introduction' => $user['introduction'] ?? null,
  4716. 'real_name' => $user['real_name'] ?? null,
  4717. 'mobile' => $user['mobile'] ?? null,
  4718. 'company_url' => $user['company_url'] ?? null,
  4719. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4720. 'address' => $user['address'] ?? null,
  4721. 'email' => $user['email'] ?? null,
  4722. 'website_id' => $data['website_id'] ?? null,
  4723. 'user_type' => $user['type_id'] ?? null,
  4724. 'job_id' => $jobId,
  4725. ];
  4726. $companyId = JobCompany::insertGetId($company);
  4727. if (empty($companyId)) {
  4728. Db::rollBack();
  4729. return Result::error("添加失败");
  4730. }
  4731. // return Result::success($company);
  4732. }
  4733. Db::commit();
  4734. } catch (\Exception $e) {
  4735. Db::rollBack();
  4736. return Result::error($e->getMessage(), 0);
  4737. }
  4738. $result = [
  4739. 'job_id' => $jobId,
  4740. 'company_id' => $companyId,
  4741. ];
  4742. if (empty($result)) {
  4743. return Result::error("添加失败", 0);
  4744. }
  4745. return Result::success($result);
  4746. }
  4747. /*
  4748. * 获取招聘信息详情
  4749. * */
  4750. public function getJobRecruitingInfo(array $data): array
  4751. {
  4752. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4753. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4754. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4755. ->select(
  4756. 'job_recruiting.*',
  4757. 'website.website_name as website_name',
  4758. 'job_company.business_name',
  4759. 'job_company.company_hy_id',
  4760. 'job_company.company_size',
  4761. 'job_company.company_nature',
  4762. 'job_company.introduction',
  4763. 'job_company.real_name',
  4764. 'job_company.mobile',
  4765. 'job_company.company_url',
  4766. 'job_company.address_arr_id',
  4767. 'job_company.address',
  4768. 'job_company.email'
  4769. )
  4770. ->first();
  4771. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4772. if (!empty($cityId)) {
  4773. if (isset($cityId[1]) && $cityId[1] != null) {
  4774. $city = District::where('id', $cityId[1])->first(['name']);
  4775. } else {
  4776. $city = District::where('id', $cityId[0])->first(['name']);
  4777. }
  4778. $result['city'] = $city['name'] ?? '';
  4779. }
  4780. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4781. if (is_array($addressId) && !empty($addressId)) {
  4782. $address = District::whereIn('id', $addressId)
  4783. ->orderBy('level', 'asc')
  4784. ->get(['name'])
  4785. ->pluck('name')
  4786. ->implode('');
  4787. // $job->address_name = $address ?? '';
  4788. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4789. }
  4790. if (empty($result)) {
  4791. return Result::error("招聘信息不存在", 0);
  4792. }
  4793. // return Result::success($job);
  4794. return Result::success($result);
  4795. }
  4796. /*
  4797. * 修改招聘信息
  4798. * */
  4799. public function upJobRecruiting(array $data): array
  4800. {
  4801. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4802. // return Result::success($job);
  4803. if (empty($job)) {
  4804. return Result::error("招聘信息不存在", 0);
  4805. }
  4806. $user = User::where('id', $data['user_id'])->first();
  4807. // return Result::success($user);
  4808. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4809. return Result::error("用户不存在", 0);
  4810. }
  4811. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4812. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4813. }
  4814. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4815. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4816. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4817. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4818. // 公司地址 管理员必填
  4819. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4820. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4821. // 管理员-企业相关信息
  4822. $company = [
  4823. 'business_name' => $data['business_name'] ?? null,
  4824. 'company_hy_id' => $data['hy_id'] ?? null,
  4825. 'company_size' => $data['company_size'] ?? null,
  4826. 'company_nature' => $data['company_nature'] ?? null,
  4827. 'introduction' => $data['introduction'] ?? null,
  4828. 'real_name' => $data['real_name'] ?? null,
  4829. 'mobile' => $data['mobile'] ?? null,
  4830. 'company_url' => $data['company_url'] ?? null,
  4831. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4832. 'address' => $data['address'] ?? null,
  4833. 'email' => $data['email'] ?? null,
  4834. ];
  4835. //去掉相关企业信息
  4836. $data = array_diff_key($data, array_flip(array_keys($company)));
  4837. $jobId = $data['id'];
  4838. $web = $data['website_id'];
  4839. $data['action_id'] = $data['user_id'];
  4840. unset($data['user_id']);
  4841. unset($data['user_type']);
  4842. unset($data['id']);
  4843. unset($data['website_id']);
  4844. // return Result::success($data);
  4845. Db::beginTransaction();
  4846. try {
  4847. // 管理员修改招聘信息
  4848. if ($user['type_id'] == 10000) {
  4849. $data['website_id'] = $web;
  4850. $company['website_id'] = $data['website_id'];
  4851. $data['status'] = 1;
  4852. } else {
  4853. $data['status'] = 0;
  4854. }
  4855. if (empty($data['experience']) || $data['experience'] == '') {
  4856. $job['experience'] = null;
  4857. } else {
  4858. $job['experience'] = $data['experience'];
  4859. }
  4860. // Db::rollBack();
  4861. // return Result::success($company);
  4862. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4863. $this->sendMessage([
  4864. 'talk_type' => 500,
  4865. 'title' => $data['title'],
  4866. 'content' => '提交了审核',
  4867. 'messageType' => 10,
  4868. ]);
  4869. }
  4870. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4871. if (empty($result['job'])) {
  4872. Db::rollBack();
  4873. return Result::error("修改招聘信息失败");
  4874. }
  4875. // 管理员修改企业相关信息
  4876. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4877. if (empty($result['company'])) {
  4878. Db::rollBack();
  4879. return Result::error("修改企业相关信息失败");
  4880. }
  4881. Db::commit();
  4882. // return Result::success($result);
  4883. } catch (\Exception $e) {
  4884. Db::rollBack();
  4885. return Result::error($e->getMessage(), 0);
  4886. }
  4887. return Result::success($result);
  4888. }
  4889. /*
  4890. * 招聘信息删除
  4891. * */
  4892. public function delJobRecruiting(array $data): array
  4893. {
  4894. $user = User::where('id', $data['user_id'])->first();
  4895. if (empty($user)) {
  4896. return Result::error("用户不存在", 0);
  4897. }
  4898. $job = JobRecruiting::where('id', $data['id'])->first();
  4899. if (empty($job)) {
  4900. return Result::error("招聘信息不存在", 0);
  4901. }
  4902. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4903. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4904. }
  4905. Db::beginTransaction();
  4906. try {
  4907. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4908. if (empty($result['job'])) {
  4909. Db::rollBack();
  4910. return Result::error("删除招聘信息失败");
  4911. }
  4912. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4913. if (empty($result['company'])) {
  4914. Db::rollBack();
  4915. return Result::error("删除企业相关信息失败");
  4916. }
  4917. Db::commit();
  4918. } catch (\Exception $e) {
  4919. Db::rollBack();
  4920. return Result::error($e->getMessage(), 0);
  4921. }
  4922. return Result::success($result);
  4923. }
  4924. /*
  4925. * 获取公司信息
  4926. * */
  4927. public function getJobCompany(array $data): array
  4928. {
  4929. $user = User::where('user.id', $data['user_id'])
  4930. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4931. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4932. ->first();
  4933. // return Result::success($user);
  4934. if (empty($user)) {
  4935. return Result::error("用户不存在", 0);
  4936. }
  4937. if ($user['type_id'] == 3) {
  4938. $result = [
  4939. // 'id' => 0,
  4940. 'user_id' => $data['user_id'],
  4941. 'website_id' => $data['website_id'],
  4942. 'business_name' => $user['business_name'], // 企业名称
  4943. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4944. 'company_nature' => $user['company_nature'], // 公司性质
  4945. 'company_size' => $user['company_size'], // 公司规模
  4946. 'introduction' => $user['introduction'], // 公司简介
  4947. 'real_name' => $user['real_name'], // 企业联系人
  4948. 'mobile' => $user['mobile'], // 企业联系电话
  4949. 'company_url' => $user['company_url'], // 企业网址
  4950. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4951. 'address' => $user['address'], // 企业地址
  4952. 'email' => $user['email'], // 企业邮箱
  4953. ];
  4954. } else {
  4955. return Result::error("用户类型错误", 0);
  4956. }
  4957. if (empty($result)) {
  4958. return Result::error("公司信息不存在", 0);
  4959. }
  4960. return Result::success($result);
  4961. }
  4962. /*
  4963. * 修改公司信息
  4964. * */
  4965. public function upJobCompany(array $data): array
  4966. {
  4967. // return Result::success($data);
  4968. $user = User::where('user.id', $data['user_id'])
  4969. ->where('user.status', 1)
  4970. ->select('user.user_name', 'user.type_id')
  4971. ->first();
  4972. if (empty($user)) {
  4973. return Result::error("用户不存在", 0);
  4974. }
  4975. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4976. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  4977. $company = [
  4978. 'business_name' => $data['business_name'], // 企业名称
  4979. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4980. 'company_nature' => $data['company_nature'], // 公司性质
  4981. 'company_size' => $data['company_size'], // 公司规模
  4982. 'introduction' => $data['introduction'], // 公司简介
  4983. // 'real_name' => $data['real_name'], // 企业联系人
  4984. 'company_url' => $data['company_url'], // 企业网址
  4985. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4986. 'address' => $data['address'], // 企业详细地址
  4987. // 'email' => $data['email'], // 企业邮箱
  4988. ];
  4989. if ($user['type_id'] == 3) {
  4990. Db::beginTransaction();
  4991. try {
  4992. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4993. 'business_name' => $data['business_name'], // 企业名称
  4994. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4995. 'company_nature' => $data['company_nature'], // 公司性质
  4996. 'company_size' => $data['company_size'], // 公司规模
  4997. 'introduction' => $data['introduction'], // 公司简介
  4998. // 'real_name' => $data['real_name'], // 企业联系人
  4999. 'company_url' => $data['company_url'], // 企业网址
  5000. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5001. 'address' => $data['address'], // 企业详细地址
  5002. ]);
  5003. if (empty($result['userinfo'])) {
  5004. Db::rollBack();
  5005. return Result::error('修改企业会员信息失败!');
  5006. }
  5007. $result['user'] = User::where('id', $data['user_id'])->update([
  5008. 'email' => $data['email'], // 企业邮箱
  5009. ]);
  5010. if (empty($result['user'])) {
  5011. Db::rollBack();
  5012. return Result::error('修改个人中心信息失败!');
  5013. }
  5014. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5015. if (!empty($job_company)) {
  5016. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5017. if (empty($result['job_company'])) {
  5018. Db::rollBack();
  5019. return Result::error('修改企业会员信息失败!');
  5020. }
  5021. }
  5022. Db::commit();
  5023. return Result::success($result);
  5024. } catch (\Exception $e) {
  5025. Db::rollBack();
  5026. return Result::error($e->getMessage(), 0);
  5027. }
  5028. } else {
  5029. return Result::error("用户类型错误", 0);
  5030. }
  5031. }
  5032. /*
  5033. * 获取省-市
  5034. * */
  5035. public function getJobRecruitingArea(array $data): array
  5036. {
  5037. if (isset($data['pid']) && $data['pid'] != null) {
  5038. $result = District::where('pid', $data['pid'])->get()->all();
  5039. } else {
  5040. $result = District::where('level', 1)->get()->all();
  5041. }
  5042. if (empty($result)) {
  5043. return Result::error("暂无此省市", 0);
  5044. }
  5045. return Result::success($result);
  5046. }
  5047. /*
  5048. * 获取行业分类
  5049. * */
  5050. public function getIndustry(array $data): array
  5051. {
  5052. $result = JobIndustry::get()->all();
  5053. if (empty($result)) {
  5054. return Result::error("暂无行业分类", 0);
  5055. }
  5056. return Result::success($result);
  5057. }
  5058. /*
  5059. * 获取职位
  5060. * */
  5061. public function getPositionList(array $data): array
  5062. {
  5063. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5064. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5065. } else {
  5066. $result = JobPosition::where('zwpid', 0)->get()->all();
  5067. }
  5068. if (empty($result)) {
  5069. return Result::error("暂无此职位", 0);
  5070. }
  5071. return Result::success($result);
  5072. }
  5073. /*
  5074. * 获取工作性质-菜单
  5075. * */
  5076. public function getJobNature(array $data): array
  5077. {
  5078. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5079. if (empty($result)) {
  5080. return Result::error("暂无工作性质", 0);
  5081. }
  5082. return Result::success($result);
  5083. }
  5084. /*
  5085. * 获取工作经验-菜单
  5086. * */
  5087. public function getExperience(array $data): array
  5088. {
  5089. $result = JobEnum::where('egroup', 'years')->get()->all();
  5090. if (empty($result)) {
  5091. return Result::error("暂无工作经验", 0);
  5092. }
  5093. return Result::success($result);
  5094. }
  5095. /*
  5096. * 获取学历-菜单
  5097. * */
  5098. public function getEducation(array $data): array
  5099. {
  5100. $result = JobEnum::where('egroup', 'education')->get()->all();
  5101. if (empty($result)) {
  5102. return Result::error("暂无学历", 0);
  5103. }
  5104. return Result::success($result);
  5105. }
  5106. /*
  5107. * 获取薪资-菜单
  5108. * */
  5109. public function getSalary(array $data): array
  5110. {
  5111. $result = JobEnum::where('egroup', 'income')->get()->all();
  5112. if (empty($result)) {
  5113. return Result::error("暂无薪资", 0);
  5114. }
  5115. return Result::success($result);
  5116. }
  5117. /*
  5118. * 获取语言-菜单
  5119. * */
  5120. public function getLanguage(array $data): array
  5121. {
  5122. $result = JobEnum::where('egroup', 'language')->get()->all();
  5123. if (empty($result)) {
  5124. return Result::error("暂无语言", 0);
  5125. }
  5126. return Result::success($result);
  5127. }
  5128. /*
  5129. * 获取掌握程度-菜单
  5130. * */
  5131. public function getLevel(array $data): array
  5132. {
  5133. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5134. if (empty($result)) {
  5135. return Result::error("暂无工作性质", 0);
  5136. }
  5137. return Result::success($result);
  5138. }
  5139. // 公司信息
  5140. /*
  5141. * 获取公司性质-菜单
  5142. * */
  5143. public function getCompanyNature(array $data): array
  5144. {
  5145. $result = JobNature::get()->all();
  5146. if (empty($result)) {
  5147. return Result::error("暂无公司性质", 0);
  5148. }
  5149. return Result::success($result);
  5150. }
  5151. /*
  5152. * 获取公司规模-菜单
  5153. * */
  5154. public function getCompanySize(array $data): array
  5155. {
  5156. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5157. if (empty($result)) {
  5158. return Result::error("暂无公司规模", 0);
  5159. }
  5160. return Result::success($result);
  5161. }
  5162. /*
  5163. * 招聘信息审核
  5164. * */
  5165. public function checkJobRecruiting(array $data): array
  5166. {
  5167. $user = User::where('id', $data['user_id'])->first();
  5168. if (empty($user)) {
  5169. return Result::error("用户不存在", 0);
  5170. }
  5171. $job = JobRecruiting::where('id', $data['id'])->first();
  5172. if (empty($job)) {
  5173. return Result::error("招聘信息不存在", 0);
  5174. }
  5175. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5176. if ($user['type_id'] != 10000) {
  5177. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5178. }
  5179. // 驳回原因
  5180. if ($data['status'] == 2) {
  5181. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5182. }
  5183. $data['action_id'] = $data['user_id'];
  5184. unset($data['user_id']);
  5185. if ($data['status'] == 1) {
  5186. $this->sendMessage([
  5187. 'talk_type' => 501,
  5188. 'title' => $job['title'],
  5189. 'content' => '审核通过',
  5190. 'messageType' => 10,
  5191. 'user_id' => $job['user_id'],
  5192. ]);
  5193. }
  5194. if ($data['status'] == 2) {
  5195. $this->sendMessage([
  5196. 'talk_type' => 501,
  5197. 'title' => $job['title'],
  5198. 'content' => '审核拒绝',
  5199. 'messageType' => 10,
  5200. 'user_id' => $job['user_id'],
  5201. ]);
  5202. }
  5203. if ($data['status'] == 0) {
  5204. $this->sendMessage([
  5205. 'talk_type' => 500,
  5206. 'title' => $job['title'],
  5207. 'content' => '提交了审核',
  5208. 'messageType' => 10,
  5209. ]);
  5210. }
  5211. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5212. if (empty($result)) {
  5213. return Result::error("审核失败", 0);
  5214. }
  5215. return Result::success($result);
  5216. }
  5217. public function myApplyList(array $data): array
  5218. {
  5219. var_dump($data, '------参数');
  5220. $user = User::where('id', $data['user_id'])->first();
  5221. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5222. return Result::error("用户不存在", 0);
  5223. }
  5224. // 1:个人会员 职场机会
  5225. if ($user['type_id'] == 1) {
  5226. $where['user_id'] = $user['id'];
  5227. }
  5228. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5229. $query->where('user_id', $user['id']);
  5230. })
  5231. ->pluck('recruit_id');
  5232. $where = [];
  5233. if (isset($data['salary']) && $data['salary'] != null) {
  5234. $where['job_recruiting.salary'] = $data['salary'];
  5235. }
  5236. if (isset($data['experience']) && $data['experience'] != null) {
  5237. $where['job_recruiting.experience'] = $data['experience'];
  5238. }
  5239. if (isset($data['business_name']) && $data['business_name'] != null) {
  5240. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5241. }
  5242. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5243. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5244. ->where($where);
  5245. // ->count();
  5246. $count = $query->count();
  5247. $query = clone $query;
  5248. $job = $query
  5249. ->leftJoin('job_enum as income_enum', function ($join) {
  5250. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5251. ->where('income_enum.egroup', 'income');
  5252. })
  5253. ->leftJoin('job_enum as years_enum', function ($join) {
  5254. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5255. ->where('years_enum.egroup', 'years');
  5256. })
  5257. // ->where($where)
  5258. ->orderBy('job_recruiting.updated_at', 'desc')
  5259. ->select(
  5260. 'job_recruiting.id',
  5261. 'job_recruiting.title',
  5262. 'job_company.business_name',
  5263. 'income_enum.evalue as salary_evalue',
  5264. 'income_enum.ename as salary_ename',
  5265. 'years_enum.evalue as experience_evalue',
  5266. 'years_enum.ename as experience_ename',
  5267. 'job_recruiting.updated_at'
  5268. )
  5269. ->offset(($data['page'] - 1) * $data['pageSize'])
  5270. ->limit($data['pageSize'])
  5271. ->get()
  5272. ->all();
  5273. if (empty($job)) {
  5274. return Result::error("暂无招聘信息", 0);
  5275. }
  5276. $result = [
  5277. 'row' => $job,
  5278. 'count' => $count,
  5279. ];
  5280. return Result::success($result);
  5281. }
  5282. /*
  5283. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5284. * */
  5285. public function getRecruitingList(array $data): array
  5286. {
  5287. $user = User::where('id', $data['user_id'])->first();
  5288. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5289. return Result::error("用户不存在", 0);
  5290. }
  5291. // 1:个人会员 职场机会
  5292. if ($user['type_id'] == 1) {
  5293. $where['user_id'] = $user['id'];
  5294. }
  5295. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5296. $query->where('receiver_id', $user['id']);
  5297. })
  5298. ->pluck('recruit_id');
  5299. // return Result::success($recruitingId);
  5300. $where = [];
  5301. if (isset($data['salary']) && $data['salary'] != null) {
  5302. $where['job_recruiting.salary'] = $data['salary'];
  5303. }
  5304. if (isset($data['experience']) && $data['experience'] != null) {
  5305. $where['job_recruiting.experience'] = $data['experience'];
  5306. }
  5307. if (isset($data['business_name']) && $data['business_name'] != null) {
  5308. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5309. }
  5310. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5311. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5312. ->where($where);
  5313. // ->count();
  5314. $count = $query->count();
  5315. $query = clone $query;
  5316. $job = $query
  5317. ->leftJoin('job_enum as income_enum', function ($join) {
  5318. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5319. ->where('income_enum.egroup', 'income');
  5320. })
  5321. ->leftJoin('job_enum as years_enum', function ($join) {
  5322. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5323. ->where('years_enum.egroup', 'years');
  5324. })
  5325. // ->where($where)
  5326. ->orderBy('job_recruiting.updated_at', 'desc')
  5327. ->select(
  5328. 'job_recruiting.id',
  5329. 'job_recruiting.title',
  5330. 'job_company.business_name',
  5331. 'income_enum.evalue as salary_evalue',
  5332. 'income_enum.ename as salary_ename',
  5333. 'years_enum.evalue as experience_evalue',
  5334. 'years_enum.ename as experience_ename',
  5335. 'job_recruiting.updated_at'
  5336. )
  5337. ->offset(($data['page'] - 1) * $data['pageSize'])
  5338. ->limit($data['pageSize'])
  5339. ->get()
  5340. ->all();
  5341. if (empty($job)) {
  5342. return Result::error("暂无招聘信息", 0);
  5343. }
  5344. $result = [
  5345. 'row' => $job,
  5346. 'count' => $count,
  5347. ];
  5348. return Result::success($result);
  5349. }
  5350. /*
  5351. * 获取企业会员-招聘信息列表
  5352. * */
  5353. public function getRecruitingInfo(array $data): array
  5354. {
  5355. $user = User::where('id', $data['user_id'])->first();
  5356. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5357. return Result::error("用户不存在", 0);
  5358. }
  5359. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5360. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5361. ->select(
  5362. 'job_recruiting.*',
  5363. 'job_company.business_name',
  5364. 'job_company.company_hy_id',
  5365. 'job_company.company_size',
  5366. 'job_company.company_nature',
  5367. 'job_company.introduction',
  5368. 'job_company.real_name',
  5369. 'job_company.mobile',
  5370. 'job_company.company_url',
  5371. 'job_company.address_arr_id',
  5372. 'job_company.address',
  5373. 'job_company.email'
  5374. )
  5375. ->get();
  5376. if (empty($recruiting)) {
  5377. return Result::error("暂无招聘信息", 0);
  5378. }
  5379. return Result::success($recruiting);
  5380. }
  5381. /*
  5382. * 获取企业会员-我的沟通
  5383. * */
  5384. public function getJobResumeList(array $data): array
  5385. {
  5386. $user = User::where('id', $data['user_id'])->first();
  5387. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5388. return Result::error("用户不存在", 0);
  5389. }
  5390. $where = [];
  5391. if (isset($data['salary']) && $data['salary'] != null) {
  5392. $where['job_hunting.salary'] = $data['salary'];
  5393. }
  5394. if (isset($data['user_name']) && $data['user_name'] != null) {
  5395. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5396. }
  5397. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5398. $query->where('job_resume.user_id', $user['id']);
  5399. })
  5400. ->when(!empty($where), function ($query) use ($where) {
  5401. $query->where($where);
  5402. })
  5403. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5404. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5405. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5406. ->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');
  5407. $count = $job->count();
  5408. if ($count == 0) {
  5409. return Result::error("暂无沟通记录", 0);
  5410. }
  5411. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5412. ->offset(($data['page'] - 1) * $data['pageSize'])
  5413. ->limit($data['pageSize'])
  5414. ->get();
  5415. if (empty($jobs)) {
  5416. return Result::error("暂无沟通记录", 0);
  5417. }
  5418. $result['row'] = $this->processJob($jobs, '');
  5419. $result['count'] = $count;
  5420. return Result::success($result);
  5421. }
  5422. // 20250306 招聘
  5423. //20250422 书刊音像
  5424. public function addBook(array $data): array
  5425. {
  5426. $user_id = $data['user_id'] ?? 0;
  5427. $type_id = $data['type_id'] ?? 0;
  5428. // $website_id = $data['website_id'] ?? 0;
  5429. // unset($data['user_id']);
  5430. unset($data['type_id']);
  5431. // unset($data['website_id']);
  5432. //处理数组
  5433. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5434. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5435. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5436. if ($data['img_url'] == '') {
  5437. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5438. preg_match_all($reg, $data['detail'], $matches);
  5439. if (isset($matches[1][0])) {
  5440. //截取varchar240
  5441. $data['img_url'] = substr($matches[1][0], 0, 240);
  5442. }
  5443. }
  5444. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5445. //提取标题+内容中的关键词
  5446. $data['keyword'] = $data['title'];
  5447. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5448. Jieba::init(); // 初始化 jieba-php
  5449. Finalseg::init();
  5450. $segList = Jieba::cut($data['keyword']);
  5451. $segList1 = array_slice($segList, 0, 8);
  5452. $data['keyword'] = implode(',', $segList1);
  5453. }
  5454. if ($data['description'] == '') {
  5455. //提取内容中的描述
  5456. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5457. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5458. }
  5459. var_dump($data, '--');
  5460. if ($data['status'] == 1) {
  5461. $this->sendMessage([
  5462. 'talk_type' => 400,
  5463. 'title' => $data['title'],
  5464. 'content' => '提交了审核',
  5465. 'messageType' => 7,
  5466. ]);
  5467. }
  5468. $result = Book::insertGetId($data);
  5469. if (empty($result)) {
  5470. return Result::error("添加失败", 0);
  5471. }
  5472. return Result::success($result);
  5473. }
  5474. public function getBookList(array $data): array
  5475. {
  5476. $where = [];
  5477. if (!empty($data["title"])) {
  5478. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5479. }
  5480. if (!empty($data['website_name'])) {
  5481. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5482. }
  5483. if (!empty($data['status'])) {
  5484. $where[] = ['book.status', '=', $data['status']];
  5485. }
  5486. $user_id = $data['user_id'];
  5487. $type_id = $data['type_id'];
  5488. // $type_id = 4;
  5489. var_dump($type_id, '------1--------');
  5490. if ($type_id != 10000) {
  5491. $where[] = ['book.user_id', '=', $user_id];
  5492. }
  5493. var_dump(!empty($data['status1']), '=-===1');
  5494. $result = Book::where($where)
  5495. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5496. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5497. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5498. ->when(isset($data['status1']), function ($query) use ($data) {
  5499. $query->whereIn('book.status', [1, 3]);
  5500. })
  5501. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5502. ->orderBy("updated_at", "desc")
  5503. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5504. if (empty($result)) {
  5505. return Result::error("暂无数据", 0);
  5506. }
  5507. // 取出数据
  5508. $rows = $result->items();
  5509. $count = $result->total();
  5510. $responseData = [
  5511. 'rows' => $rows,
  5512. 'count' => $count,
  5513. ];
  5514. return Result::success($responseData);
  5515. }
  5516. public function deleteBook(array $data): array
  5517. {
  5518. $result = Book::where('id', $data['id'])->delete();
  5519. if (empty($result)) {
  5520. return Result::error("删除失败", 0);
  5521. }
  5522. return Result::success($result);
  5523. }
  5524. public function updateBook(array $data): array
  5525. {
  5526. // $user_id = $data['user_id'] ?? 0;
  5527. $type_id = $data['type_id'] ?? 0;
  5528. // $website_id = $data['website_id'] ?? 0;
  5529. unset($data['user_id']);
  5530. unset($data['type_id']);
  5531. // unset($data['website_id']);
  5532. //处理数组
  5533. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5534. if ($data['img_url'] == '') {
  5535. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5536. preg_match_all($reg, $data['detail'], $matches);
  5537. if (isset($matches[1][0])) {
  5538. //截取varchar240
  5539. $data['img_url'] = substr($matches[1][0], 0, 240);
  5540. }
  5541. }
  5542. if ($data['keyword'] == '') {
  5543. //提取标题+内容中的关键词
  5544. $data['keyword'] = $data['title'];
  5545. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5546. Jieba::init(); // 初始化 jieba-php
  5547. Finalseg::init();
  5548. $segList = Jieba::cut($data['keyword']);
  5549. $segList1 = array_slice($segList, 0, 8);
  5550. $data['keyword'] = implode(',', $segList1);
  5551. }
  5552. if ($data['description'] == '') {
  5553. //提取内容中的描述
  5554. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5555. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5556. }
  5557. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5558. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5559. if ($data['status'] == 1) {
  5560. $this->sendMessage([
  5561. 'talk_type' => 400,
  5562. 'title' => $data['title'],
  5563. 'content' => '提交了审核',
  5564. 'messageType' => 7,
  5565. ]);
  5566. }
  5567. $result = Book::where("id", $data["id"])->update($data);
  5568. if (empty($result)) {
  5569. return Result::error("更新失败", 0);
  5570. }
  5571. return Result::success($result);
  5572. }
  5573. public function getBookInfo(array $data): array
  5574. {
  5575. $result = Book::where("id", $data["id"])->first();
  5576. if (empty($result)) {
  5577. return Result::error("获取失败", 0);
  5578. }
  5579. return Result::success($result);
  5580. }
  5581. public function updateBookStatus(array $data): array
  5582. {
  5583. //审核
  5584. unset($data['user_id']);
  5585. $bookInfo = Book::where("id", $data["id"])->first();
  5586. var_dump($bookInfo, '----');
  5587. if ($data['status'] == 2) {
  5588. $this->sendMessage([
  5589. 'talk_type' => 401,
  5590. 'title' => $bookInfo['title'],
  5591. 'content' => '审核通过',
  5592. 'messageType' => 7,
  5593. 'user_id' => $bookInfo['user_id'],
  5594. ]);
  5595. }
  5596. if ($data['status'] == 3) {
  5597. $this->sendMessage([
  5598. 'talk_type' => 401,
  5599. 'title' => $bookInfo['title'],
  5600. 'content' => '审核拒绝',
  5601. 'messageType' => 7,
  5602. 'user_id' => $bookInfo['user_id'],
  5603. ]);
  5604. }
  5605. if ($data['status'] == 1) {
  5606. $this->sendMessage([
  5607. 'talk_type' => 400,
  5608. 'title' => $bookInfo['title'],
  5609. 'content' => '提交了审核',
  5610. 'messageType' => 7,
  5611. // 'user_id'=>$bookInfo['user_id'],
  5612. ]);
  5613. }
  5614. $result = Book::where("id", $data["id"])->update($data);
  5615. if (empty($result)) {
  5616. return Result::error("更新失败", 0);
  5617. }
  5618. return Result::success($result);
  5619. }
  5620. //20250422 书刊音像
  5621. /**
  5622. * 贴身宝贝
  5623. * @param array $data
  5624. * @return array
  5625. */
  5626. public function getWebsiteTsbb(array $data): array
  5627. {
  5628. $month = $data['month'] ?? date('m');
  5629. $day = $data['day'] ?? date('d');
  5630. // 使用缓存键
  5631. $cacheKey = "tsbb_data_{$month}_{$day}";
  5632. // 尝试从缓存获取数据
  5633. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5634. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5635. if ($cachedData = $cache->get($cacheKey)) {
  5636. return Result::success(unserialize($cachedData));
  5637. }
  5638. //查询老黄历
  5639. try {
  5640. $date = date('Y-m-d');
  5641. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5642. // 使用 curl 替代 file_get_contents
  5643. $ch = curl_init();
  5644. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5645. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5646. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5647. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5648. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5649. 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');
  5650. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5651. 'Accept: application/json',
  5652. 'Content-Type: application/json',
  5653. 'Referer: https://www.36jxs.com/'
  5654. ]);
  5655. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5656. curl_setopt($ch, CURLOPT_ENCODING, '');
  5657. $almanacResponse = curl_exec($ch);
  5658. var_dump("====:", $almanacResponse);
  5659. if (curl_errno($ch)) {
  5660. var_dump('Curl error:', curl_error($ch));
  5661. throw new \Exception('Curl error: ' . curl_error($ch));
  5662. }
  5663. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5664. curl_close($ch);
  5665. if ($almanacResponse === false) {
  5666. throw new \Exception('Failed to fetch almanac data');
  5667. }
  5668. $almanacData = json_decode($almanacResponse, true);
  5669. if (json_last_error() !== JSON_ERROR_NONE) {
  5670. throw new \Exception('Failed to parse almanac data');
  5671. }
  5672. $almanacInfo = $almanacData['data'] ?? [];
  5673. } catch (\Exception $e) {
  5674. var_dump('Exception:', $e->getMessage());
  5675. $almanacInfo = [];
  5676. }
  5677. // 获取历史上的今天数据
  5678. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5679. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5680. ->orderBy('year', 'asc')
  5681. ->select("title", "id", "year", DB::raw('1 as type'))
  5682. ->limit(16)
  5683. ->get();
  5684. // 获取节日数据 - 从今天开始获取未来4条
  5685. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5686. ->orderBy('showtime', 'asc')
  5687. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5688. ->limit(16)
  5689. ->get();
  5690. //说文解字
  5691. $chartacterList = Character::orderBy('updated_at', 'desc')
  5692. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5693. ->limit(6)
  5694. ->get();
  5695. //谜语沙龙
  5696. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5697. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5698. ->limit(4)
  5699. ->get();
  5700. //成语欣赏
  5701. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5702. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5703. ->limit(32)
  5704. ->get();
  5705. //名联赏析
  5706. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5707. ->select("id", "first", "second", DB::raw('6 as type'))
  5708. ->limit(6)
  5709. ->get();
  5710. // 获取分类文章数据
  5711. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5712. ->pluck('category_id')
  5713. ->toArray();
  5714. $articlesList = [];
  5715. foreach ($categoryIds as $catid) {
  5716. // 先查有图片的
  5717. $withImg = DB::table('article')
  5718. ->where('status', 1)
  5719. ->where('catid', $catid)
  5720. ->whereNotNull('imgurl')
  5721. ->where('imgurl', '!=', '')
  5722. ->orderBy('updated_at', 'desc')
  5723. ->limit(6)
  5724. ->get();
  5725. $count = $withImg->count();
  5726. if ($count < 6) {
  5727. // 不足6条再查无图片的补足
  5728. $withoutImg = DB::table('article')
  5729. ->where('status', 1)
  5730. ->where('catid', $catid)
  5731. ->where(function ($q) {
  5732. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5733. })
  5734. ->orderBy('updated_at', 'desc')
  5735. ->limit(6 - $count)
  5736. ->get();
  5737. $articles = $withImg->concat($withoutImg);
  5738. } else {
  5739. $articles = $withImg;
  5740. }
  5741. // 组装
  5742. $category = \App\Model\Category::find($catid);
  5743. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5744. $articlesList[] = [
  5745. 'category_name' => $category ? $category->name : '',
  5746. 'catid' => $catid,
  5747. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5748. 'type' => 100,
  5749. 'list' => $articles->map(function ($item) {
  5750. return [
  5751. 'id' => $item->id,
  5752. 'title' => $item->title,
  5753. 'imgurl' => $item->imgurl,
  5754. 'created_at' => $item->created_at
  5755. ];
  5756. })->values()
  5757. ];
  5758. }
  5759. $result = [
  5760. 'almanac' => $almanacInfo,
  5761. 'historyTodayList' => [
  5762. 'category_name' => '历史上的今天',
  5763. 'list' => $historyTodayList,
  5764. 'type' => 1
  5765. ],
  5766. 'festivalList' => [
  5767. 'category_name' => '节日预告',
  5768. 'list' => $festivalList,
  5769. 'type' => 2
  5770. ],
  5771. 'chartacterList' => [
  5772. 'category_name' => '说文解字',
  5773. 'list' => $chartacterList,
  5774. 'type' => 3
  5775. ],
  5776. 'coupletList' => [
  5777. 'category_name' => '名联赏析',
  5778. 'list' => $coupletList,
  5779. 'type' => 6
  5780. ],
  5781. 'riddletList' => [
  5782. 'category_name' => '谜语沙龙',
  5783. 'list' => $riddletList,
  5784. 'type' => 4
  5785. ],
  5786. 'idiomList' => [
  5787. 'category_name' => '成语欣赏',
  5788. 'list' => $idiomList,
  5789. 'type' => 5
  5790. ],
  5791. 'articlesList' => $articlesList
  5792. ];
  5793. // 缓存结果,设置1小时过期
  5794. $cache->set($cacheKey, serialize($result), 3600);
  5795. return Result::success($result);
  5796. }
  5797. /**
  5798. * 获取资讯列表
  5799. */
  5800. public function getWebsiteTsbbList(array $data): array
  5801. {
  5802. $page = $data['page'] ?? 1;
  5803. $pageSize = $data['pageSize'] ?? 10;
  5804. // 如果没有传入月份和日期,则使用今天的日期
  5805. $month = $data['month'] ?? date('m');
  5806. $day = $data['day'] ?? date('d');
  5807. $total = 0;
  5808. $result = [];
  5809. $data['type'] = intval($data['type']);
  5810. var_dump("接收参数:", $data);
  5811. switch ($data['type']) {
  5812. case 1:
  5813. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5814. // 当前月份之后的数据
  5815. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5816. // 或者当前月份且日期大于等于当前日期的数据
  5817. ->orWhere(function ($q) use ($month, $day) {
  5818. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5819. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5820. });
  5821. })
  5822. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5823. $total = $query->count();
  5824. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5825. ->offset(($page - 1) * $pageSize)
  5826. ->limit($pageSize)
  5827. ->get();
  5828. break;
  5829. case 2:
  5830. $query = Festival::where(function ($q) use ($month, $day) {
  5831. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5832. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5833. ->orWhere(function ($q) use ($month, $day) {
  5834. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5835. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5836. });
  5837. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5838. $total = $query->count();
  5839. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5840. ->offset(($page - 1) * $pageSize)
  5841. ->limit($pageSize)
  5842. ->get();
  5843. break;
  5844. case 3:
  5845. $query = Character::orderBy("updated_at", "desc");
  5846. $total = $query->count();
  5847. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5848. ->offset(($page - 1) * $pageSize)
  5849. ->limit($pageSize)
  5850. ->get();
  5851. break;
  5852. case 4:
  5853. $query = Riddle::orderBy("updated_at", "desc");
  5854. $total = $query->count();
  5855. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5856. ->offset(($page - 1) * $pageSize)
  5857. ->limit($pageSize)
  5858. ->get();
  5859. break;
  5860. case 5:
  5861. $query = Idiom::orderBy("updated_at", "desc");
  5862. $total = $query->count();
  5863. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5864. ->offset(($page - 1) * $pageSize)
  5865. ->limit($pageSize)
  5866. ->get();
  5867. break;
  5868. case 6:
  5869. $query = Couplet::orderBy("updated_at", "desc");
  5870. $total = $query->count();
  5871. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5872. ->offset(($page - 1) * $pageSize)
  5873. ->limit($pageSize)
  5874. ->get();
  5875. break;
  5876. default:
  5877. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5878. $total = $query->count();
  5879. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5880. ->offset(($page - 1) * $pageSize)
  5881. ->limit($pageSize)
  5882. ->get();
  5883. }
  5884. return Result::success([
  5885. 'list' => $result,
  5886. 'total' => $total,
  5887. 'page' => (int)$page,
  5888. 'pageSize' => (int)$pageSize,
  5889. 'month' => $month,
  5890. 'day' => $day
  5891. ]);
  5892. }
  5893. /**
  5894. * 1:历史上的今天
  5895. * 2:节日
  5896. * 3:文章
  5897. *
  5898. * 资讯详情信息
  5899. */
  5900. public function getWebsiteTsbbDetail(array $data): array
  5901. {
  5902. $data['type'] = intval($data['type']);
  5903. switch ($data['type']) {
  5904. case 1:
  5905. $result = HistoryToday::where("id", $data['id'])->first();
  5906. break;
  5907. case 2:
  5908. $result = Festival::where("id", $data['id'])->first();
  5909. break;
  5910. case 3:
  5911. $result = Character::where("id", $data['id'])->first();
  5912. break;
  5913. case 4:
  5914. $result = Riddle::where("id", $data['id'])->first();
  5915. break;
  5916. case 5:
  5917. $result = Idiom::where("id", $data['id'])->first();
  5918. break;
  5919. case 6:
  5920. $result = Couplet::where("id", $data['id'])->first();
  5921. break;
  5922. default:
  5923. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5924. break;
  5925. }
  5926. return Result::success($result);
  5927. }
  5928. /**
  5929. * 农网导航首页数据
  5930. */
  5931. public function getWebsiteNwHomeList(array $data): array
  5932. {
  5933. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5934. ->pluck('category_id')
  5935. ->toArray();
  5936. // 使用子查询优化
  5937. $articlesList = DB::table('article')
  5938. ->select([
  5939. 'article.id',
  5940. 'article.title',
  5941. 'article.imgurl',
  5942. 'article.created_at',
  5943. 'category.name as category_name',
  5944. 'category.id as category_id',
  5945. 'website_category.aLIas_pinyin as pinyin',
  5946. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5947. DB::raw('100 as type')
  5948. ])
  5949. ->join('category', 'article.catid', '=', 'category.id')
  5950. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5951. ->leftJoin('website_category as parent_wc', function ($join) {
  5952. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5953. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5954. })
  5955. ->where('website_category.website_id', $data['website_id'])
  5956. ->where('article.status', 1)
  5957. ->whereIn('category.id', $categoryIds)
  5958. ->orderBy('article.created_at', 'desc')
  5959. ->get()
  5960. ->groupBy('category_id')
  5961. ->map(function ($group) {
  5962. // 确保第一条数据有图片
  5963. $firstWithImage = $group->first(function ($item) {
  5964. return !empty($item->imgurl);
  5965. });
  5966. if ($firstWithImage) {
  5967. // 如果有带图片的文章,将其放在第一位
  5968. $group = $group->filter(function ($item) use ($firstWithImage) {
  5969. return $item->id !== $firstWithImage->id;
  5970. })->prepend($firstWithImage);
  5971. }
  5972. return [
  5973. 'category_name' => $group->first()->category_name,
  5974. 'catid' => $group->first()->category_id,
  5975. 'pinyin' => $group->first()->pinyin,
  5976. 'parent_pinyin' => $group->first()->parent_pinyin,
  5977. 'list' => $group->take(4)->map(function ($item) {
  5978. return [
  5979. 'id' => $item->id,
  5980. 'title' => $item->title,
  5981. ];
  5982. })->values()
  5983. ];
  5984. })
  5985. ->values()
  5986. ->toArray();
  5987. return Result::success($articlesList);
  5988. }
  5989. /**
  5990. * 企业管理
  5991. * @param array $data
  5992. * @return array
  5993. */
  5994. public function getCompanyList(array $data): array
  5995. {
  5996. // return Result::success($data);
  5997. $where = [];
  5998. $user = User::where('id', $data['user_id'])->first();
  5999. if (empty($user)) {
  6000. return Result::error('用户不存在!');
  6001. }
  6002. if ($user['type_id'] != 10000) {
  6003. $where['user_id'] = $data['user_id'];
  6004. }
  6005. if (isset($data['title']) && !empty($data['title'])) {
  6006. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6007. }
  6008. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6009. array_push($where, ['website.id', $data['website_id']]);
  6010. }
  6011. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6012. if ($data['ischeck'] == 1) {
  6013. if (isset($data['status']) && $data['status'] != '') {
  6014. array_push($where, ['company.status', $data['status']]);
  6015. $query = Company::where($where);
  6016. } else {
  6017. $query = Company::whereIn('company.status', [0, 2]);
  6018. }
  6019. } else {
  6020. $query = Company::where('company.status', 1);
  6021. }
  6022. }
  6023. $result = $query->where($where)
  6024. ->leftJoin('website_category', function ($query) {
  6025. $query->on('website_category.category_id', '=', 'company.category_id')
  6026. ->on('website_category.website_id', '=', 'company.website_id');
  6027. })
  6028. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6029. ->select(
  6030. 'company.id',
  6031. 'company.title',
  6032. 'company.website_id',
  6033. 'company.category_id',
  6034. 'website.website_name',
  6035. 'website_category.alias as category_name',
  6036. 'company.status',
  6037. 'company.updated_at',
  6038. )
  6039. ->orderBy('company.updated_at', 'desc')
  6040. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6041. if ($result->isEmpty()) {
  6042. return Result::error("暂无企业", 0);
  6043. }
  6044. return Result::success($result);
  6045. }
  6046. /**
  6047. * 添加企业
  6048. * @param array $data
  6049. * @return array
  6050. */
  6051. public function addCompany(array $data): array
  6052. {
  6053. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6054. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6055. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6056. $data['cat_arr_id'] = json_encode($car_arr_id);
  6057. } else {
  6058. $data['cat_arr_id'] = '';
  6059. }
  6060. if ($data['imgurl'] == '') {
  6061. //content中提取图片第一个图,正则提取
  6062. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6063. preg_match_all($reg, $data['content'], $matches);
  6064. if (isset($matches[1][0])) {
  6065. //截取varchar240
  6066. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6067. }
  6068. }
  6069. if ($data['keyword'] == '') {
  6070. //提取标题+内容中的关键词
  6071. $data['keyword'] = $data['title'];
  6072. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6073. Jieba::init(); // 初始化 jieba-php
  6074. Finalseg::init();
  6075. $segList = Jieba::cut($data['keyword']);
  6076. $segList1 = array_slice($segList, 0, 8);
  6077. $data['keyword'] = implode(',', $segList1);
  6078. }
  6079. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6080. //提取内容中的描述
  6081. $content = $data['content'];
  6082. // 去除 <style> 和 <script> 标签及其内容
  6083. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6084. // 去除所有 HTML 标签
  6085. $content = strip_tags($content);
  6086. // 去除 HTML 实体
  6087. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6088. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6089. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6090. // 去除多余空白
  6091. $content = preg_replace('/\s+/u', '', $content);
  6092. // 截取 100 个字符
  6093. $data['introduce'] = mb_substr($content, 0, 100);
  6094. }
  6095. $user = User::where('id', $data['user_id'])->first();
  6096. if (empty($user)) {
  6097. return Result::error('用户不存在!');
  6098. }
  6099. if ($user['type_id'] == 10000) {
  6100. $data['status'] = 1;
  6101. }
  6102. if (isset($data['level']) && $data['level'] != null) {
  6103. $data['level'] = intval($data['level']);
  6104. } else {
  6105. $data['level'] = null;
  6106. }
  6107. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6108. $this->sendMessage([
  6109. 'talk_type' => 900,
  6110. 'title' => $data['title'],
  6111. 'content' => '提交了审核',
  6112. 'messageType' => 8,
  6113. ]);
  6114. }
  6115. $result = Company::insertGetId($data);
  6116. if ($result) {
  6117. return Result::success($result);
  6118. } else {
  6119. return Result::error('添加失败');
  6120. }
  6121. }
  6122. /**
  6123. * 更新企业
  6124. * @param array $data
  6125. * @return array
  6126. */
  6127. public function upCompany(array $data): array
  6128. {
  6129. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6130. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6131. $data['cat_arr_id'] = json_encode($car_arr_id);
  6132. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6133. } else {
  6134. $data['cat_arr_id'] = '';
  6135. }
  6136. if ($data['imgurl'] == '') {
  6137. //content中提取图片第一个图,正则提取
  6138. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6139. preg_match_all($reg, $data['content'], $matches);
  6140. if (isset($matches[1][0])) {
  6141. //截取varchar
  6142. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6143. }
  6144. }
  6145. if ($data['keyword'] == '') {
  6146. //提取标题+内容中的关键词
  6147. $data['keyword'] = $data['title'];
  6148. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6149. Jieba::init(); // 初始化 jieba-php
  6150. Finalseg::init();
  6151. $segList = Jieba::cut($data['keyword']);
  6152. $segList1 = array_slice($segList, 0, 8);
  6153. $data['keyword'] = implode(',', $segList1);
  6154. }
  6155. if ($data['introduce'] == '') {
  6156. //提取内容中的描述
  6157. $content = $data['content'];
  6158. // 去除 <style> 和 <script> 标签及其内容
  6159. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6160. // 去除所有 HTML 标签
  6161. $content = strip_tags($content);
  6162. // 去除 HTML 实体
  6163. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6164. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6165. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6166. // 去除多余空白
  6167. $content = preg_replace('/\s+/u', '', $content);
  6168. // 截取 100 个字符
  6169. $data['introduce'] = mb_substr($content, 0, 100);
  6170. }
  6171. if (isset($data['level']) && $data['level'] != null) {
  6172. $data['level'] = intval($data['level']);
  6173. } else {
  6174. $data['level'] = null;
  6175. }
  6176. $user = User::where('id', $data['user_id'])->first();
  6177. if (empty($user)) {
  6178. return Result::error('用户不存在!');
  6179. }
  6180. if ($user['type_id'] == 10000) {
  6181. $data['status'] = 1;
  6182. } else {
  6183. $data['status'] = 0;
  6184. }
  6185. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6186. $this->sendMessage([
  6187. 'talk_type' => 900,
  6188. 'title' => $data['title'],
  6189. 'content' => '提交了审核',
  6190. 'messageType' => 8,
  6191. ]);
  6192. }
  6193. $result = Company::where('id', $data['id'])->update($data);
  6194. if ($result) {
  6195. return Result::success($result);
  6196. } else {
  6197. return Result::error('修改失败');
  6198. }
  6199. }
  6200. /**
  6201. * 删除企业
  6202. * @param array $data
  6203. * @return array
  6204. */
  6205. public function delCompany(array $data): array
  6206. {
  6207. $result = Company::where('id', $data['id'])->delete();
  6208. if ($result) {
  6209. return Result::success($result);
  6210. } else {
  6211. return Result::error('删除失败');
  6212. }
  6213. }
  6214. /**
  6215. * 审核企业
  6216. * @param array $data
  6217. * @return array
  6218. */
  6219. public function checkCompany(array $data): array
  6220. {
  6221. $user = User::where('id', $data['user_id'])->first();
  6222. if (empty($user)) {
  6223. return Result::error('用户不存在!');
  6224. }
  6225. $company = Company::where('id', $data['id'])->first();
  6226. if (empty($company)) {
  6227. return Result::error('企业不存在!');
  6228. }
  6229. // 状态:0:未审核 1:已审核 2:已拒绝
  6230. if ($data['status'] == 2 || $data['status'] == '2') {
  6231. $this->sendMessage([
  6232. 'talk_type' => 901,
  6233. 'title' => $company['title'],
  6234. 'content' => '审核拒绝',
  6235. 'messageType' => 8,
  6236. 'user_id' => $company['user_id'],
  6237. ]);
  6238. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6239. } else {
  6240. if ($data['status'] == 1) {
  6241. $this->sendMessage([
  6242. 'talk_type' => 901,
  6243. 'title' => $company['title'],
  6244. 'content' => '审核通过',
  6245. 'messageType' => 8,
  6246. 'user_id' => $company['user_id'],
  6247. ]);
  6248. } else if ($data['status'] == 0) {
  6249. $this->sendMessage([
  6250. 'talk_type' => 900,
  6251. 'title' => $company['title'],
  6252. 'content' => '提交了审核',
  6253. 'messageType' => 8,
  6254. ]);
  6255. }
  6256. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6257. }
  6258. if (empty($result)) {
  6259. return Result::error('审核失败!');
  6260. } else {
  6261. return Result::success($result);
  6262. }
  6263. }
  6264. /**
  6265. * 获取企业信息
  6266. * @param array $data
  6267. * @return array
  6268. */
  6269. public function getCompanyInfo(array $data): array
  6270. {
  6271. $result = Company::where('id', $data['id'])->first();
  6272. if (empty($result)) {
  6273. return Result::error('企业不存在!');
  6274. } else {
  6275. return Result::success($result);
  6276. }
  6277. }
  6278. /**
  6279. * @param array $data
  6280. * @return array
  6281. */
  6282. public function getWebsiteCompany(array $data): array
  6283. {
  6284. $categorys = json_decode($data['id'], true);
  6285. $category_arr = $this->processArticlePro($data['website_id']);
  6286. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6287. $catiall = $category_arr['catiall'];
  6288. foreach ($categorys as $key => $value) {
  6289. if (array_key_exists('level', $value)) {
  6290. $parts = explode(',', $value['level']);
  6291. $level = $parts[0] ?? null;
  6292. $imgnum = $parts[1] ?? null;
  6293. $textnum = $parts[2] ?? null;
  6294. if (!empty($textnum) && $textnum > 0) {
  6295. $text_num = Company::where('level', $level)
  6296. ->where('website_id', $data['website_id'])
  6297. ->where('status', 1)
  6298. ->select(
  6299. 'company.id',
  6300. 'company.title',
  6301. 'company.description',
  6302. 'company.updated_at',
  6303. 'company.category_id',
  6304. 'company.cat_arr_id'
  6305. )
  6306. ->orderBy('updated_at', 'desc')
  6307. ->limit($textnum)
  6308. ->get()->all();
  6309. }
  6310. if (!empty($imgnum) && $imgnum > 0) {
  6311. $img_num = Company::where('level', $level)
  6312. ->where('website_id', $data['website_id'])
  6313. ->where('status', 1)
  6314. ->where('imgurl', '!=', '')
  6315. ->whereNotNull('imgurl')
  6316. ->select(
  6317. 'company.id',
  6318. 'company.title',
  6319. 'company.description',
  6320. 'company.updated_at',
  6321. 'company.imgurl as imgs',
  6322. 'company.category_id',
  6323. 'company.cat_arr_id'
  6324. )
  6325. ->orderBy('updated_at', 'desc')
  6326. ->limit($imgnum)
  6327. ->get()->all();
  6328. }
  6329. }
  6330. if (array_key_exists('id', $value)) {
  6331. $parts = explode(',', $value['id']);
  6332. $category_id = $parts[0] ?? null;
  6333. $imgnum = $parts[1] ?? null;
  6334. $textnum = $parts[2] ?? null;
  6335. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6336. if (!empty($textnum) && $textnum > 0) {
  6337. $text_num = Company::whereIn('category_id', $category_arr)
  6338. ->where('website_id', $data['website_id'])
  6339. ->where('status', 1)
  6340. ->select(
  6341. 'company.id',
  6342. 'company.title',
  6343. 'company.description',
  6344. 'company.updated_at',
  6345. 'company.category_id',
  6346. 'company.cat_arr_id'
  6347. )
  6348. ->orderBy('updated_at', 'desc')
  6349. ->limit($textnum)
  6350. ->get()->all();
  6351. }
  6352. if (!empty($imgnum) && $imgnum > 0) {
  6353. $img_num = Company::whereIn('category_id', $category_arr)
  6354. ->where('website_id', $data['website_id'])
  6355. ->where('status', 1)
  6356. ->where('imgurl', '!=', '')
  6357. ->whereNotNull('imgurl')
  6358. ->select(
  6359. 'company.id',
  6360. 'company.title',
  6361. 'company.description',
  6362. 'company.updated_at',
  6363. 'company.imgurl as imgs',
  6364. 'company.category_id',
  6365. 'company.cat_arr_id'
  6366. )
  6367. ->orderBy('updated_at', 'desc')
  6368. ->limit($imgnum)
  6369. ->get()->all();
  6370. }
  6371. }
  6372. if (!empty($text_num)) {
  6373. foreach ($text_num as $k => $v) {
  6374. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6375. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6376. }
  6377. }
  6378. if (!empty($img_num)) {
  6379. foreach ($img_num as $k => $v) {
  6380. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6381. $imgurl = json_decode($v['imgs'], true);
  6382. if (!empty($imgurl)) {
  6383. $img_num[$k]->imgurl = $imgurl[0];
  6384. }
  6385. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6386. }
  6387. }
  6388. $company[$key]['img_num'] = $img_num ?? [];
  6389. $company[$key]['text_num'] = $text_num ?? [];
  6390. }
  6391. if (empty($company)) {
  6392. return Result::error("暂无相关企业信息", 0);
  6393. }
  6394. return Result::success($company);
  6395. }
  6396. /**
  6397. * @param array $data
  6398. * @return array
  6399. */
  6400. public function getWebsiteCompanyList(array $data): array
  6401. {
  6402. $where['website_id'] = $data['website_id'];
  6403. $where['status'] = 1;
  6404. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6405. $where['category_id'] = $data['category_id'];
  6406. }
  6407. if (isset($data['keyword']) && !empty($data['keyword'])) {
  6408. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  6409. }
  6410. $query = Company::where($where);
  6411. $company = $this->processArticle(
  6412. $query->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6413. ->orderBy('updated_at', 'desc')
  6414. ->offset(($data['page'] - 1) * $data['pageSize'])
  6415. ->limit($data['pageSize'])
  6416. ->get(),
  6417. $data
  6418. );
  6419. if (empty($company)) {
  6420. return Result::error("暂无相关公司信息", 0);
  6421. }
  6422. $result = [
  6423. 'count' => $query->clone()->count(),
  6424. 'data' => $company,
  6425. ];
  6426. return Result::success($result);
  6427. }
  6428. /**
  6429. * 获取项目列表
  6430. * @param array $data
  6431. * @return array
  6432. */
  6433. public function getProjectList(array $data): array
  6434. {
  6435. $where = [];
  6436. $user = User::where('id', $data['user_id'])->first();
  6437. if (empty($user)) {
  6438. return Result::error('用户不存在!');
  6439. }
  6440. if ($user->type_id != 10000) {
  6441. array_push($where, ['project.user_id', $data['user_id']]);
  6442. }
  6443. $query = Project::query();
  6444. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6445. array_push($where, ['project.website_id', $data['website_id']]);
  6446. }
  6447. if (isset($data['title']) && !empty($data['title'])) {
  6448. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6449. }
  6450. if ($data['status'] != 3) {
  6451. array_push($where, ['project.status', $data['status']]);
  6452. }
  6453. $query = Project::where($where)
  6454. ->when($data['status'] == 3, function ($query) {
  6455. $query->whereIn('project.status', [0, 2]);
  6456. });
  6457. $count = $query->clone()
  6458. ->count();
  6459. $rows = $query->clone()
  6460. ->leftJoin('website', 'project.website_id', 'website.id')
  6461. ->leftJoin('website_category', function ($join) {
  6462. $join->on('project.website_id', '=', 'website_category.website_id')
  6463. ->on('project.category_id', '=', 'website_category.category_id');
  6464. })
  6465. ->select(
  6466. 'project.id',
  6467. 'project.title',
  6468. 'project.updated_at',
  6469. 'project.status',
  6470. 'website.website_name',
  6471. 'website_category.alias as category_name'
  6472. )
  6473. ->orderBy('project.updated_at', 'desc')
  6474. ->offset(($data['page'] - 1) * $data['pageSize'])
  6475. ->limit($data['pageSize'])
  6476. ->get();
  6477. if ($rows->isEmpty()) {
  6478. return Result::error("暂无相关项目信息", 0);
  6479. }
  6480. $result = [
  6481. 'count' => $count,
  6482. 'rows' => $rows,
  6483. ];
  6484. return Result::success($result);
  6485. }
  6486. /**
  6487. * 添加项目
  6488. * @param array $data
  6489. * @return array
  6490. */
  6491. public function addProject(array $data): array
  6492. {
  6493. $user = User::where('id', $data['user_id'])->first();
  6494. if (empty($user)) {
  6495. return Result::error("暂无相关用户信息", 0);
  6496. }
  6497. if ($user->type_id == 10000) {
  6498. $data['status'] = 1;
  6499. } else {
  6500. $data['status'] = 0;
  6501. }
  6502. if ($data['keyword'] == '') {
  6503. //提取标题+内容中的关键词
  6504. $data['keyword'] = $data['title'];
  6505. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6506. Jieba::init(); // 初始化 jieba-php
  6507. Finalseg::init();
  6508. $segList = Jieba::cut($data['keyword']);
  6509. $segList1 = array_slice($segList, 0, 8);
  6510. $data['keyword'] = implode(',', $segList1);
  6511. }
  6512. if ($data['description'] == '') {
  6513. //提取内容中的描述
  6514. // var_dump(11111);
  6515. //提取内容中的描述
  6516. $content = $data['introduce'];
  6517. // 去除 <style> 和 <script> 标签及其内容
  6518. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6519. // 去除所有 HTML 标签
  6520. $content = strip_tags($content);
  6521. // 去除 HTML 实体
  6522. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6523. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6524. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6525. // 去除多余空白
  6526. $content = preg_replace('/\s+/u', '', $content);
  6527. // 截取 100 个字符
  6528. $data['description'] = mb_substr($content, 0, 100);
  6529. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6530. }
  6531. if ($data['status'] == 0) {
  6532. $this->sendMessage([
  6533. 'talk_type' => 1000,
  6534. 'title' => $data['title'],
  6535. 'content' => '提交了审核',
  6536. 'messageType' => 9,
  6537. ]);
  6538. }
  6539. $project = Project::insertGetId($data);
  6540. if (empty($project)) {
  6541. return Result::error("暂无相关项目信息", 0);
  6542. }
  6543. return Result::success($project);
  6544. }
  6545. /**
  6546. * 更新项目
  6547. * @param array $data
  6548. * @return array
  6549. */
  6550. public function upProject(array $data): array
  6551. {
  6552. $project = Project::where('id', $data['id'])->first();
  6553. if (empty($project)) {
  6554. return Result::error("暂无相关项目信息", 0);
  6555. }
  6556. $id = $data['id'];
  6557. unset($data['id']);
  6558. $user = User::where('id', $data['user_id'])->first();
  6559. if (empty($user)) {
  6560. return Result::error("暂无相关用户信息", 0);
  6561. }
  6562. if ($user->type_id == 10000) {
  6563. $data['status'] = 1;
  6564. } else {
  6565. $data['status'] = 0;
  6566. }
  6567. unset($data['user_id']);
  6568. if ($data['keyword'] == '') {
  6569. //提取标题+内容中的关键词
  6570. $data['keyword'] = $data['title'];
  6571. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6572. Jieba::init(); // 初始化 jieba-php
  6573. Finalseg::init();
  6574. $segList = Jieba::cut($data['keyword']);
  6575. $segList1 = array_slice($segList, 0, 8);
  6576. $data['keyword'] = implode(',', $segList1);
  6577. }
  6578. if ($data['description'] == '') {
  6579. //提取内容中的描述
  6580. // var_dump(11111);
  6581. //提取内容中的描述
  6582. $content = $data['introduce'];
  6583. // 去除 <style> 和 <script> 标签及其内容
  6584. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6585. // 去除所有 HTML 标签
  6586. $content = strip_tags($content);
  6587. // 去除 HTML 实体
  6588. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6589. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6590. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6591. // 去除多余空白
  6592. $content = preg_replace('/\s+/u', '', $content);
  6593. // 截取 100 个字符
  6594. $data['description'] = mb_substr($content, 0, 100);
  6595. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6596. }
  6597. if ($data['status'] == 0) {
  6598. $this->sendMessage([
  6599. 'talk_type' => 1000,
  6600. 'title' => $data['title'],
  6601. 'content' => '提交了审核',
  6602. 'messageType' => 9,
  6603. ]);
  6604. }
  6605. $result = Project::where('id', $id)->update($data);
  6606. if (empty($result)) {
  6607. return Result::error("更新失败", 0);
  6608. }
  6609. return Result::success($result);
  6610. }
  6611. /**
  6612. * 删除项目
  6613. * @param array $data
  6614. * @return array
  6615. */
  6616. public function delProject(array $data): array
  6617. {
  6618. $user = User::where('id', $data['user_id'])->first();
  6619. if (empty($user)) {
  6620. return Result::error("暂无相关用户信息", 0);
  6621. }
  6622. $project = Project::where('id', $data['id'])->first();
  6623. if (empty($project)) {
  6624. return Result::error("暂无相关项目信息", 0);
  6625. }
  6626. $result = Project::where('id', $data['id'])->delete();
  6627. if (empty($result)) {
  6628. return Result::error("删除失败", 0);
  6629. }
  6630. return Result::success($result);
  6631. }
  6632. /**
  6633. * 审核项目
  6634. * @param array $data
  6635. * @return array
  6636. */
  6637. public function checkProject(array $data): array
  6638. {
  6639. $user = User::where('id', $data['user_id'])->first();
  6640. if (empty($user)) {
  6641. return Result::error("暂无相关用户信息", 0);
  6642. }
  6643. // 0:未审核; 1:已审核; 2:已拒绝;
  6644. if ($user->type_id != 10000) {
  6645. if ($data['status'] == 1 || $data['status'] == 2) {
  6646. return Result::error("此用户权限不足", 0);
  6647. }
  6648. }
  6649. $project = Project::where('id', $data['id'])->first();
  6650. if (empty($project)) {
  6651. return Result::error("暂无相关项目信息", 0);
  6652. }
  6653. if ($data['status'] == 2) {
  6654. $this->sendMessage([
  6655. 'talk_type' => 1001,
  6656. 'title' => $project['title'],
  6657. 'content' => '审核拒绝',
  6658. 'messageType' => 9,
  6659. 'user_id' => $project['user_id'],
  6660. ]);
  6661. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6662. } else {
  6663. if ($data['status'] == 1) {
  6664. $this->sendMessage([
  6665. 'talk_type' => 1001,
  6666. 'title' => $project['title'],
  6667. 'content' => '审核通过',
  6668. 'messageType' => 9,
  6669. 'user_id' => $project['user_id'],
  6670. ]);
  6671. } else if ($data['status'] == 0) {
  6672. $this->sendMessage([
  6673. 'talk_type' => 1000,
  6674. 'title' => $project['title'],
  6675. 'content' => '提交了审核',
  6676. 'messageType' => 9,
  6677. ]);
  6678. }
  6679. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6680. }
  6681. if (empty($result)) {
  6682. return Result::error("审核失败", 0);
  6683. }
  6684. return Result::success($result);
  6685. }
  6686. /**
  6687. * 获取项目详情
  6688. * @param array $data
  6689. * @return array
  6690. */
  6691. public function getProjectInfo(array $data): array
  6692. {
  6693. $project = Project::where('id', $data['id'])->first();
  6694. if (empty($project)) {
  6695. return Result::error("暂无相关项目信息", 0);
  6696. }
  6697. return Result::success($project);
  6698. }
  6699. public function getWebsiteCompanyInfo(array $data): array
  6700. {
  6701. $company = Company::where('id', $data['id'])
  6702. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6703. ->where('status', 1)
  6704. ->where('website_id', $data['website_id'])
  6705. ->select('company.*', 'job_industry.hyname as hy_name')
  6706. ->first();
  6707. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6708. switch ($company->jobnature_id) {
  6709. case null:
  6710. $company->jobnature_name = '';
  6711. break;
  6712. case 0:
  6713. $company->jobnature_name = '市场监督';
  6714. break;
  6715. case 1:
  6716. $company->jobnature_name = '信访纪检';
  6717. break;
  6718. case 2:
  6719. $company->jobnature_name = '公检法司';
  6720. break;
  6721. case 3:
  6722. $company->jobnature_name = '高关注机构';
  6723. break;
  6724. default:
  6725. $company->jobnature_name = '';
  6726. break;
  6727. }
  6728. $city_arr = $company->city_arr_id;
  6729. if (!empty($city_arr)) {
  6730. $city_arr = json_decode($city_arr, true);
  6731. $cityNames = District::whereIn('id', $city_arr)
  6732. ->pluck('name')
  6733. ->implode('-');
  6734. $company->city_name = $cityNames;
  6735. } else {
  6736. $company->city_name = '';
  6737. }
  6738. if (empty($company)) {
  6739. return Result::error("暂无相关公司信息", 0);
  6740. }
  6741. return Result::success($company);
  6742. }
  6743. public function getMSG(array $data): array
  6744. {
  6745. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6746. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6747. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6748. $result = [];
  6749. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  6750. //最近的5篇已审的文章
  6751. $apply_articale = Article::where('status', 1)
  6752. ->where('admin_user_id', $user_id)
  6753. ->orderBy('updated_at', 'desc')
  6754. // ->limit(5)
  6755. ->get();
  6756. //获取5条用户的已审核商品
  6757. $good = Good::where('status', 2)
  6758. ->where('user_id', $user_id)
  6759. ->orderBy('updated_at', 'desc')
  6760. // ->limit(5)
  6761. ->get();
  6762. //获取5条用户待审核的公告
  6763. $notice = Notice::where('status', 2)
  6764. ->where('user_id', $user_id)
  6765. ->orderBy('updated_at', 'desc')
  6766. ->limit(5)->get();
  6767. //获取5条用户的待审核投诉
  6768. $complaint = Complaint::where('status', 2)
  6769. ->where('user_id', $user_id)
  6770. ->orderBy('updated_at', 'desc')
  6771. // ->limit(5)
  6772. ->get();
  6773. //获取5条用户的book
  6774. $book = Book::where('status', 2)
  6775. ->where('user_id', $user_id)
  6776. ->orderBy('updated_at', 'desc')
  6777. // ->limit(5)
  6778. ->get();
  6779. //获取5条用户的求职
  6780. //获取5条用户的求职 1
  6781. $job_hunting = JobHunting::where('job_hunting.status', 2)
  6782. ->where('job_hunting.user_id', $user_id)
  6783. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6784. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6785. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6786. ->orderBy('updated_at', 'desc')
  6787. // ->limit(5)
  6788. ->get();
  6789. //获取5条用户的求职 2
  6790. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6791. ->where('job_recruiting.user_id', $user_id)
  6792. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6793. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6794. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6795. ->orderBy('updated_at', 'desc')
  6796. // ->limit(5)
  6797. ->get();
  6798. //人才库 1
  6799. $job_apply = JobApply::where('job_apply.status', 1)
  6800. ->where('job_apply.receiver_id', $user_id)
  6801. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6802. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6803. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6804. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6805. ->select('job_recruiting', 'job_recruiting.', '', '')
  6806. ->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')
  6807. ->orderBy('updated_at', 'desc')
  6808. // ->limit(5)
  6809. ->get();
  6810. // 职场机会 2
  6811. $job_resume = JobResume::where('job_resume.status', 1)
  6812. ->where('job_resume.receiver_id', $user_id)
  6813. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6814. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6815. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6816. ->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')
  6817. ->orderBy('updated_at', 'desc')
  6818. // ->limit(5)
  6819. ->get();
  6820. //获取5条用户待处理的投诉
  6821. $complaint_deal = Complaint::where('status', 2)
  6822. ->where('deal', 1)
  6823. ->whereJsonContains('re_user_ids', $user_id)
  6824. ->orderBy('updated_at', 'desc')
  6825. // ->limit(5)
  6826. ->get();
  6827. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  6828. $complany = Company::where('status', 1)
  6829. ->where('user_id', $user_id)
  6830. ->orderBy('updated_at', 'desc')
  6831. // ->limit(5)
  6832. ->get();
  6833. //获取5条单聊未读聊天消息
  6834. // $chat = ChatRecords::where('is_read', 0)
  6835. // ->where('user_id', $user_id)
  6836. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6837. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6838. // ->where('action', 'recieved')
  6839. // ->where('talk_type', 1)
  6840. // ->orderBy('created_at', 'desc')
  6841. // // ->limit(5)
  6842. // ->get();
  6843. //获取5条未读群聊信息
  6844. // $chat_group = ChatRecords::where('is_read', 0)
  6845. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  6846. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  6847. // ->where('user_id', $user_id)
  6848. // ->where('talk_type', 2)
  6849. // ->orderBy('created_at', 'desc')
  6850. // // ->limit(5)
  6851. // ->get();
  6852. //获取5条用户的待审核项目
  6853. $project = Project::where('status', 1)
  6854. ->where('user_id', $user_id)
  6855. ->orderBy('updated_at', 'desc')
  6856. // ->limit(5)
  6857. ->get();
  6858. // count($chat) + count($chat_group) +
  6859. $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)
  6860. + count($complany)
  6861. + count($project)
  6862. // + count($chat) + count($chat_group)
  6863. ;
  6864. $result = [
  6865. 'apply_articale' => $apply_articale,
  6866. // 'chat' => $chat,
  6867. // 'chat_group' => $chat_group,
  6868. 'good' => $good,
  6869. 'notice' => $notice,
  6870. 'complaint' => $complaint,
  6871. 'book' => $book,
  6872. 'job_hunting' => $job_hunting,
  6873. 'job_recruiting' => $job_recruiting,
  6874. 'job_apply' => $job_apply,
  6875. 'job_resume' => $job_resume,
  6876. 'complaint_deal' => $complaint_deal,
  6877. 'complany' => $complany,
  6878. 'project' => $project,
  6879. 'count' => $count,
  6880. ];
  6881. } elseif ($type_id == 12) {
  6882. //最近的5篇已审的文章
  6883. $apply_articale = Article::where('status', 1)
  6884. ->where('admin_user_id', $user_id)
  6885. ->limit(5)->get();
  6886. //获取5条单聊未读聊天消息
  6887. $chat = ChatRecords::where('is_read', 0)
  6888. ->where('user_id', $user_id)
  6889. ->where('talk_type', 1)
  6890. ->orderBy('created_at', 'desc')
  6891. ->limit(5)->get();
  6892. //获取5条未读群聊信息
  6893. $chat_group = ChatRecords::where('is_read', 0)
  6894. ->where('user_id', $user_id)
  6895. ->where('talk_type', 2)
  6896. ->orderBy('created_at', 'desc')
  6897. ->limit(5)->get();
  6898. //获取5条用户的已审核商品
  6899. $good = Good::where('status', 2)
  6900. ->where('user_id', $user_id)
  6901. ->orderBy('updated_at', 'desc')
  6902. ->limit(5)->get();
  6903. //获取5条用户的book
  6904. $book = Book::where('status', 2)
  6905. ->where('user_id', $user_id)
  6906. ->orderBy('updated_at', 'desc')
  6907. ->limit(5)->get();
  6908. //获取5条用户的求职
  6909. //获取5条用户的求职 1
  6910. //count($chat) + count($chat_group)
  6911. $count = count($apply_articale) + count($good);
  6912. $result = [
  6913. 'apply_articale' => $apply_articale,
  6914. 'chat' => $chat,
  6915. 'chat_group' => $chat_group,
  6916. 'good' => $good,
  6917. 'book' => $book,
  6918. 'count' => $count,
  6919. ];
  6920. } elseif ($type_id == 13) {
  6921. //最近的5篇已审的文章
  6922. $apply_articale = Article::where('status', 1)
  6923. ->where('admin_user_id', $user_id)
  6924. ->limit(5)->get();
  6925. //获取5条单聊未读聊天消息
  6926. $chat = ChatRecords::where('is_read', 0)
  6927. ->where('user_id', $user_id)
  6928. ->where('talk_type', 1)
  6929. ->orderBy('created_at', 'desc')
  6930. ->limit(5)->get();
  6931. //获取5条未读群聊信息
  6932. $chat_group = ChatRecords::where('is_read', 0)
  6933. ->where('user_id', $user_id)
  6934. ->where('talk_type', 2)
  6935. ->orderBy('created_at', 'desc')
  6936. ->limit(5)->get();
  6937. //获取5条用户的已审核商品
  6938. $good = Good::where('status', 2)
  6939. ->where('user_id', $user_id)
  6940. ->orderBy('updated_at', 'desc')
  6941. ->limit(5)->get();
  6942. //count($chat) + count($chat_group) +
  6943. $count = count($apply_articale) + count($good);
  6944. $result = [
  6945. 'apply_articale' => $apply_articale,
  6946. 'chat' => $chat,
  6947. 'chat_group' => $chat_group,
  6948. 'good' => $good,
  6949. 'count' => $count,
  6950. ];
  6951. } elseif ($type_id == 14) {
  6952. //最近的5篇已审的文章
  6953. $apply_articale = Article::where('status', 1)
  6954. ->where('admin_user_id', $user_id)
  6955. // ->limit(5)
  6956. ->get();
  6957. //获取5条用户的已审核商品
  6958. $good = Good::where('status', 2)
  6959. ->where('user_id', $user_id)
  6960. ->orderBy('updated_at', 'desc')
  6961. // ->limit(5)
  6962. ->get();
  6963. $count = count($apply_articale) + count($good);
  6964. $result = [
  6965. 'apply_articale' => $apply_articale,
  6966. 'chat' => '',
  6967. 'chat_group' => '',
  6968. 'good' => $good,
  6969. 'count' => $count,
  6970. ];
  6971. } elseif ($type_id == 10000) {
  6972. //获取未审核的5篇文章
  6973. $apply_articale = Article::where('status', 0)
  6974. ->orderBy('updated_at', 'desc')
  6975. // ->limit(5)
  6976. ->get();
  6977. //获取5条单聊未读聊天消息
  6978. //获取5条单聊未读聊天消息
  6979. // $chat = ChatRecords::where('is_read', 0)
  6980. // ->where('user_id', $user_id)
  6981. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6982. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6983. // ->where('action', 'recieved')
  6984. // ->where('talk_type', 1)
  6985. // ->orderBy('created_at', 'desc')
  6986. // // ->limit(5)
  6987. // ->get();
  6988. // //获取5条未读群聊信息
  6989. // $chat_group = ChatRecords::where('is_read', 0)
  6990. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  6991. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  6992. // ->where('user_id', $user_id)
  6993. // ->where('talk_type', 2)
  6994. // ->orderBy('created_at', 'desc')
  6995. // // ->limit(5)
  6996. // ->get();
  6997. //获取5条用户的已审核商品
  6998. $good = Good::where('status', 1)
  6999. // ->where('user_id', $user_id)
  7000. ->orderBy('updated_at', 'desc')
  7001. // ->limit(5)
  7002. ->get();
  7003. //获取5条用户待审核的公告
  7004. $notice = Notice::where('status', 1)
  7005. ->orderBy('updated_at', 'desc')
  7006. // ->limit(5)
  7007. ->get();
  7008. //获取5条用户的待审核投诉
  7009. $complaint = Complaint::where('status', 1)
  7010. ->orderBy('updated_at', 'desc')
  7011. // ->limit(5)
  7012. ->get();
  7013. //获取5条用户的book
  7014. $book = Book::where('status', 1)
  7015. ->orderBy('updated_at', 'desc')
  7016. // ->limit(5)
  7017. ->get();
  7018. //获取5条用户的求职 1
  7019. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7020. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7021. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7022. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7023. ->orderBy('updated_at', 'desc')
  7024. // ->limit(5)
  7025. ->get();
  7026. //获取5条用户的求职 2
  7027. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7028. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7029. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7030. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7031. ->orderBy('updated_at', 'desc')
  7032. // ->limit(5)
  7033. ->get();
  7034. //人才库 1
  7035. $job_apply = JobApply::where('job_apply.status', 1)
  7036. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7037. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7038. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7039. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7040. ->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')
  7041. ->orderBy('updated_at', 'desc')
  7042. // ->limit(5)
  7043. ->get();
  7044. // 职场机会 2
  7045. $job_resume = JobResume::where('job_resume.status', 1)
  7046. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7047. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7048. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7049. ->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')
  7050. ->orderBy('updated_at', 'desc')
  7051. // ->limit(5)
  7052. ->get();
  7053. //待审核数据com pro
  7054. $complany = Company::where('status', 0)
  7055. ->orderBy('updated_at', 'desc')
  7056. // ->limit(5)
  7057. ->get();
  7058. $project = Project::where('status', 0)
  7059. ->orderBy('updated_at', 'desc')
  7060. // ->limit(5)
  7061. ->get();
  7062. $count =
  7063. // count($chat) +
  7064. // count($chat_group) +
  7065. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7066. + count($job_apply)
  7067. + count($job_resume)
  7068. + count($complany)
  7069. + count($project);
  7070. $result = [
  7071. 'apply_articale' => $apply_articale,
  7072. // 'chat' => $chat,
  7073. // 'chat_group' => $chat_group,
  7074. 'good' => $good,
  7075. 'notice' => $notice,
  7076. 'complaint' => $complaint,
  7077. 'book' => $book,
  7078. 'job_hunting' => $job_hunting,
  7079. 'job_recruiting' => $job_recruiting,
  7080. 'job_apply' => $job_apply,
  7081. 'job_resume' => $job_resume,
  7082. 'complany' => $complany,
  7083. 'project' => $project,
  7084. 'count' => $count,
  7085. ];
  7086. } elseif ($type_id == 20000) {
  7087. }
  7088. var_dump($type_id, '-----------------test---------');
  7089. return Result::success($result);
  7090. }
  7091. /**
  7092. * @param array $data
  7093. * @return array
  7094. */
  7095. public function getWebsiteProject(array $data): array
  7096. {
  7097. $categorys = json_decode($data['id'], true);
  7098. if (!empty($categorys)) {
  7099. $category_arr = $this->processArticlePro($data['website_id']);
  7100. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7101. $catiall = $category_arr['catiall'];
  7102. // return Result::success($catiall);
  7103. foreach ($categorys as $key => $val) {
  7104. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7105. $level = explode(',', $val['level'])[0];
  7106. $imgnum = explode(',', $val['level'])[1] ?? null;
  7107. $textnum = explode(',', $val['level'])[2] ?? null;
  7108. if ($level == 1) {
  7109. if (!empty($textnum) && $textnum > 0) {
  7110. $text_num = Project::where('level', $level)
  7111. ->where('website_id', $data['website_id'])
  7112. ->where('status', 1)
  7113. ->select(
  7114. 'project.id',
  7115. 'project.title',
  7116. 'project.description',
  7117. 'project.updated_at',
  7118. 'project.category_id',
  7119. 'project.cat_arr_id'
  7120. )
  7121. ->orderBy('updated_at', 'desc')
  7122. ->limit($textnum)
  7123. ->get()->all();
  7124. }
  7125. if (!empty($imgnum) && $imgnum > 0) {
  7126. $img_num = Project::where('level', $level)
  7127. ->where('website_id', $data['website_id'])
  7128. ->where('status', 1)
  7129. ->where('imgurl', '!=', '')
  7130. ->whereNotNull('imgurl')
  7131. ->select(
  7132. 'project.id',
  7133. 'project.title',
  7134. 'project.description',
  7135. 'project.updated_at',
  7136. 'project.imgurl as imgs',
  7137. 'project.category_id',
  7138. 'project.cat_arr_id'
  7139. )
  7140. ->orderBy('updated_at', 'desc')
  7141. ->limit($imgnum)
  7142. ->get()->all();
  7143. }
  7144. } else {
  7145. if (!empty($textnum) && $textnum > 0) {
  7146. $text_num = Project::where('website_id', $data['website_id'])
  7147. ->where('status', 1)
  7148. ->select(
  7149. 'project.id',
  7150. 'project.title',
  7151. 'project.description',
  7152. 'project.updated_at',
  7153. 'project.category_id',
  7154. 'project.cat_arr_id',
  7155. 'project.website_id',
  7156. 'project.updated_at',
  7157. 'project.created_at'
  7158. )
  7159. ->orderBy('updated_at', 'desc')
  7160. ->limit($textnum)
  7161. ->get()->all();
  7162. }
  7163. if (!empty($imgnum) && $imgnum > 0) {
  7164. $img_num = Project::where('website_id', $data['website_id'])
  7165. ->where('status', 1)
  7166. ->where('imgurl', '!=', '')
  7167. ->whereNotNull('imgurl')
  7168. ->select(
  7169. 'project.id',
  7170. 'project.title',
  7171. 'project.description',
  7172. 'project.updated_at',
  7173. 'project.imgurl as imgs',
  7174. 'project.category_id',
  7175. 'project.cat_arr_id'
  7176. )
  7177. ->orderBy('updated_at', 'desc')
  7178. ->limit($imgnum)
  7179. ->get()->all();
  7180. }
  7181. }
  7182. }
  7183. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7184. $category_ids = explode(',', $val['id'])[0];
  7185. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7186. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7187. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7188. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7189. $text_num = Project::whereIn('category_id', $category_arr)
  7190. ->where('website_id', $data['website_id'])
  7191. ->where('status', 1)
  7192. ->select(
  7193. 'project.id',
  7194. 'project.title',
  7195. 'project.description',
  7196. 'project.updated_at',
  7197. 'project.category_id',
  7198. 'project.cat_arr_id'
  7199. )
  7200. ->orderBy('updated_at', 'desc')
  7201. ->limit($cat_textnum)
  7202. ->get()->all();
  7203. }
  7204. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7205. $img_num = Project::whereIn('category_id', $category_arr)
  7206. ->where('website_id', $data['website_id'])
  7207. ->where('status', 1)
  7208. ->where('imgurl', '!=', '')
  7209. ->whereNotNull('imgurl')
  7210. ->select(
  7211. 'project.id',
  7212. 'project.title',
  7213. 'project.description',
  7214. 'project.updated_at',
  7215. 'project.imgurl as imgs',
  7216. 'project.category_id',
  7217. 'project.cat_arr_id'
  7218. )
  7219. ->orderBy('updated_at', 'desc')
  7220. ->limit($cat_imgnum)
  7221. ->get()->all();
  7222. }
  7223. }
  7224. if (!empty($img_num)) {
  7225. foreach ($img_num as $k => $v) {
  7226. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7227. $imgurl = json_decode($v['imgs'], true);
  7228. if (!empty($imgurl)) {
  7229. $img_num[$k]->imgurl = $imgurl[0];
  7230. }
  7231. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7232. }
  7233. }
  7234. if (!empty($text_num)) {
  7235. foreach ($text_num as $k => $v) {
  7236. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7237. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7238. }
  7239. }
  7240. $project[$key]['img_num'] = $img_num ?? [];
  7241. $project[$key]['text_num'] = $text_num ?? [];
  7242. }
  7243. }
  7244. if (empty($project)) {
  7245. return Result::error("暂无相关项目信息", 0);
  7246. }
  7247. return Result::success($project);
  7248. }
  7249. /**
  7250. * @param array $data
  7251. * @return array
  7252. */
  7253. public function getWebsiteProjectInfo(array $data): array
  7254. {
  7255. $project = Project::where('id', $data['id'])
  7256. ->where('status', 1)
  7257. ->where('website_id', $data['website_id'])
  7258. ->select('project.*')
  7259. ->first();
  7260. if (empty($project)) {
  7261. return Result::error("暂无相关项目信息", 0);
  7262. }
  7263. return Result::success($project);
  7264. }
  7265. /**
  7266. * @param array $data
  7267. * @return array
  7268. */
  7269. public function getWebsiteProjectList(array $data): array
  7270. {
  7271. $where = [];
  7272. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7273. $where['category_id'] = $data['category_id'];
  7274. }
  7275. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7276. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7277. }
  7278. $query = Project::where($where)
  7279. ->where('status', 1)
  7280. ->where('website_id', $data['website_id'])
  7281. ->select(
  7282. 'project.id',
  7283. 'project.title',
  7284. 'project.description',
  7285. 'project.imgurl as imgs',
  7286. 'project.category_id',
  7287. 'project.cat_arr_id'
  7288. )
  7289. ->orderBy('updated_at', 'desc');
  7290. $count = $query->count();
  7291. $project = $query->clone()
  7292. ->offset(($data['page'] - 1) * $data['pageSize'])
  7293. ->limit($data['pageSize'])
  7294. ->get()->all();
  7295. if (empty($project)) {
  7296. return Result::error("暂无相关项目信息", 0);
  7297. }
  7298. $categorys = $this->processArticlePro($data['website_id']);
  7299. $catiall = $categorys['catiall'];
  7300. foreach ($project as $key => $val) {
  7301. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7302. if (!empty($val['imgs'])) {
  7303. $imgurl = json_decode($val['imgs'], true);
  7304. if (!empty($imgurl)) {
  7305. $project[$key]->imgurl = $imgurl[0];
  7306. }
  7307. } else {
  7308. $project[$key]->imgurl = '';
  7309. }
  7310. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7311. }
  7312. $result = [
  7313. 'rows' => $project,
  7314. 'count' => $count,
  7315. ];
  7316. return Result::success($result);
  7317. }
  7318. /**
  7319. * @param array $data
  7320. * @return array
  7321. */
  7322. public function getWebsiteCategoryJob(array $data): array
  7323. {
  7324. $categorys = json_decode($data['id'], true);
  7325. if (!empty($categorys)) {
  7326. $category_arr = $this->processArticlePro($data['website_id']);
  7327. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7328. $catiall = $category_arr['catiall'];
  7329. foreach ($categorys as $key => $val) {
  7330. if (isset($val['id']) && !empty($val['id'])) {
  7331. $catid = explode(',', $val['id'])[0] ?? null;
  7332. $type = explode(',', $val['id'])[1] ?? null;
  7333. $textnum = explode(',', $val['id'])[2] ?? null;
  7334. }
  7335. // 4:招聘;5:求职;
  7336. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7337. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7338. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7339. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7340. ->where('job_recruiting.status', 1)
  7341. ->where('job_recruiting.website_id', $data['website_id'])
  7342. ->select(
  7343. 'job_recruiting.id',
  7344. 'job_recruiting.title',
  7345. 'job_company.business_name',
  7346. 'job_recruiting.updated_at',
  7347. 'job_recruiting.cat_arr_id'
  7348. )
  7349. ->orderBy('job_recruiting.updated_at', 'desc')
  7350. ->limit($textnum)
  7351. ->get()->all();
  7352. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7353. // 状态 审核状态,1待审核2已审核3已拒绝
  7354. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7355. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7356. ->where('job_hunting.status', 2)
  7357. ->where('job_hunting.website_id', $data['website_id'])
  7358. ->select(
  7359. 'job_hunting.id',
  7360. 'job_hunting.name',
  7361. 'job_hunting.cat_arr_id',
  7362. 'job_position.zwname as job_name',
  7363. 'job_hunting.updated_at'
  7364. )
  7365. ->orderBy('updated_at', 'desc')
  7366. ->limit($textnum)
  7367. ->get()->all();
  7368. } else {
  7369. $job = [];
  7370. }
  7371. // var_dump($catid.'222uuuuuuu'.$key);
  7372. if (!empty($job)) {
  7373. foreach ($job as $k => $value) {
  7374. if (isset($value->cat_arr_id)) {
  7375. $catArr = json_decode($value->cat_arr_id, true);
  7376. $catId = end($catArr);
  7377. } else {
  7378. continue;
  7379. }
  7380. if (isset($catiall[$catId])) {
  7381. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7382. }
  7383. }
  7384. }
  7385. // var_dump($catid.'xxxxx'.$key);
  7386. $result[$key] = $job ?? [];
  7387. }
  7388. }
  7389. if (empty($result)) {
  7390. return Result::error("暂无相关分类信息", 0);
  7391. }
  7392. return Result::success($result);
  7393. }
  7394. /**
  7395. * 发送消息
  7396. * @param array $messageData
  7397. * @return void
  7398. */
  7399. public function sendMessage($messageData)
  7400. {
  7401. $msg = [
  7402. 'talk_type' => $messageData['talk_type'],
  7403. 'title' => $messageData['title'],
  7404. 'content' => $messageData['content'],
  7405. 'messageType' => $messageData['messageType'],
  7406. 'user_id' => $messageData['user_id'] ?? '',
  7407. 'time' => microtime(),
  7408. ];
  7409. $message = new MqProducer($msg);
  7410. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7411. $producer->produce($message);
  7412. }
  7413. }