NewsService.php 252 KB

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