NewsService.php 269 KB

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