NewsService.php 268 KB

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