NewsService.php 267 KB

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