User.php 243 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/6/18
  7. *
  8. *
  9. */
  10. namespace app\controller\api\user;
  11. use app\common\repositories\article\AgreementRepository;
  12. use app\common\repositories\merchant\order\OrderGzcRepository;
  13. use app\common\repositories\merchant\order\OrderMerchantRepository;
  14. use app\common\repositories\store\product\ProductRepository;
  15. use app\common\repositories\user\UnionUsersRepository;
  16. use app\controller\api\merchant\sxy\Access;
  17. use app\controller\api\store\product\DaTaoKe;
  18. use app\controller\api\store\product\Jd;
  19. use app\controller\api\store\product\TaoBao;
  20. use app\controller\api\store\product\TaoKe;
  21. use app\controller\api\store\product\Vip;
  22. use app\model\common\UserThirdModel;
  23. use app\traits\GzcApiRequest;
  24. use app\traits\HuiPay;
  25. use crmeb\basic\BaseController;
  26. use app\common\repositories\user\UserBillRepository;
  27. use app\common\repositories\user\UserRepository;
  28. use app\common\repositories\user\UserVisitRepository;
  29. use crmeb\services\QrcodeService;
  30. use crmeb\services\WechatService;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use think\App;
  33. use think\facade\Db;
  34. use think\Exception;
  35. use think\exception\ValidateException;
  36. use think\facade\Cache;
  37. use BaiduAi\controller\Ocr;
  38. use think\facade\Log;
  39. use think\facade\Request as r;
  40. use app\common\common;
  41. use phpseclib3\Math\BigInteger\Engines\BCMath;
  42. class User extends BaseController
  43. {
  44. use HuiPay;
  45. public $repository;
  46. private $merId;
  47. private $source;
  48. public function __construct(App $app, UserRepository $repository)
  49. {
  50. parent::__construct($app);
  51. $this->repository = $repository;
  52. $this->source = $this->request->header('source');
  53. $this->merId = $this->request->header('merId');
  54. }
  55. /**
  56. * 创建环信账户
  57. * @return mixed
  58. */
  59. public function hxim_create()
  60. {
  61. $uid = $this->request->uid();
  62. try {
  63. $im = new Im();
  64. $user = Db::name('user')->where('uid', $uid)->field('im_uuid,im_userid as im_user_id,im,uid,nickname,im_password as im_pass')->find();
  65. if (isset($user['im_uuid']) && $user['im_user_id']) {
  66. return app('json')->success($user);
  67. }
  68. $im_user_id = 'user' . $user['uid'];
  69. $data = [];
  70. $data['im_pass'] = mt_rand(100000, 999999);
  71. $data['im_user_id'] = $im_user_id;
  72. // 获取用户是否存在
  73. $imUser = $im->getImUser('user' . $uid);
  74. if (isset($imUser['activated']) && $imUser['activated'] == true) {
  75. $data['im_uuid'] = $imUser['uuid'];
  76. } else {
  77. $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']);
  78. }
  79. Db::name('User')->where(['uid' => $uid])->update([
  80. 'im' => 1,
  81. 'im_uuid' => $data['im_uuid'],
  82. 'im_userid' => $im_user_id,
  83. 'im_password' => $data['im_pass']
  84. ]);
  85. return app('json')->success($data);
  86. } catch (\Exception $e) {
  87. Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]);
  88. }
  89. return app('json')->fail('注册失败');
  90. }
  91. /**
  92. * @return mixed
  93. * @author xaboy
  94. * @day 2020/6/22
  95. */
  96. public function we_com()
  97. {
  98. $where2['mer_id'] = $this->merId;
  99. $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find();
  100. return app('json')->success($user);
  101. }
  102. public function spread_image()
  103. {
  104. $type = $this->request->param('type');
  105. $res = $type == 'routine'
  106. ? $this->repository->routineSpreadImage($this->request->userInfo())
  107. : $this->repository->wxSpreadImage($this->request->userInfo());
  108. return app('json')->success($res);
  109. }
  110. /**
  111. * @return mixed
  112. * 分享每日海报
  113. */
  114. public function share_day()
  115. {
  116. /**
  117. * 1242
  118. * 2208
  119. */
  120. $user = $this->request->userInfo();
  121. $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
  122. $siteUrl = systemConfig('site_url');
  123. $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);// 二维码链接
  124. $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']);
  125. if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
  126. $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg';
  127. $qrcode = $imageInfo['dir'];
  128. dump($qrcode);
  129. $config = array(
  130. 'image' => array(
  131. array(
  132. 'url' => $qrcode,// 二维码资源
  133. 'stream' => 0,
  134. 'left' => 533,
  135. 'top' => 1941,
  136. 'right' => 0,
  137. 'bottom' => 0,
  138. 'width' => 184,
  139. 'height' => 182,
  140. 'opacity' => 100
  141. )
  142. ),
  143. 'background' => $filename
  144. );
  145. $data = setSharePoster($config, 'routine/spread/poster');
  146. dump($data);
  147. return app('json')->success($data);
  148. }
  149. public function spread_info()
  150. {
  151. $user = $this->request->userInfo();
  152. $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']);
  153. $data = [
  154. 'lock_brokerage' => $user->lock_brokerage,
  155. 'one_level_count' => $user->one_level_count,
  156. 'two_level_count' => $user->two_level_count,
  157. 'spread_total' => $user->spread_total,
  158. 'yesterday_brokerage' => $user->yesterday_brokerage,
  159. 'total_extract' => $user->total_extract,
  160. 'total_brokerage' => $user->total_brokerage,
  161. 'brokerage_price' => $user->brokerage_price,
  162. 'member_brokerage_price' => $user->member_brokerage_price,
  163. 'now_money' => $user->now_money,
  164. 'broken_day' => (int)systemConfig('lock_brokerage_timer')
  165. ];
  166. return app('json')->success($data);
  167. }
  168. // 红包
  169. public function hongbao_info(){
  170. log::info("============hongbao");
  171. $user = $this->request->userInfo();
  172. if($user->uid>0){
  173. // 已经入账红包
  174. $data['total_source']=$user->hongbao;
  175. // 为生效红包
  176. $data['no_total_source']=Db::name('user_sign_hongbao')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  177. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  178. return app('json')->success($data);
  179. }
  180. }
  181. public function vr_name()
  182. {
  183. $uid = $this->request->uid();
  184. $data = [
  185. "name"=>"VR",
  186. "url"=>'https://show.hxxfb.com/?uid=' .$uid,
  187. ];
  188. return app('json')->success($data);
  189. }
  190. public function hongbao_list(){
  191. $pm = $this->request->param('pm');
  192. [$page, $limit] = $this->getPage();
  193. $uid = $this->request->uid();
  194. log::info("hongbao_list==={$uid}");
  195. $where['uid'] = $uid;
  196. if ($pm==0){
  197. $data = DB::name('user_sign_hongbao')->where($where)->where('type',1)->where('status',1)->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  198. }
  199. if($pm==1){
  200. $data = DB::name('user_sign_hongbao')->where($where)->where(['type' => 2,'status' => 1])->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  201. }
  202. if($pm==2){
  203. $data = DB::name('user_sign_hongbao')->where($where)->where('type',1)->where([['status','in','-1,0']])->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  204. if($data){
  205. $data = $data->toArray();
  206. foreach ($data as $k=>$v){
  207. if($v['status'] == 0){
  208. $data[$k]['mark'] = '(失效)' . $v['mark'];
  209. }
  210. }
  211. }
  212. }
  213. return app("json")->success($data);
  214. }
  215. public function buildTreeContribute($users, $parentId = 0) {
  216. $branch = array();
  217. foreach ($users as $user) {
  218. if ($user['spread_uid'] == $parentId) {
  219. $children = $this->buildTreeContribute($users, $user['uid']); // 递归查找子节点
  220. if ($children) {
  221. $user['children'] = $children; // 如果有子节点,添加到当前节点
  222. }else{
  223. $user['children'] = [];
  224. }
  225. $user['total_contribute'] = $user['contribute_sum']; // 初始化当前节点的总余额为自身余额
  226. if ($children) { // 如果存在子节点,计算总余额
  227. foreach ($children as $child) {
  228. $user['total_contribute'] += $child['total_contribute']; // 累加子节点的总余额
  229. }
  230. }
  231. $branch[] = $user; // 将当前节点添加到树中
  232. }
  233. }
  234. return $branch; // 返回当前分支的所有节点
  235. }
  236. // 根据父级uid,递归获取所有子级UID数组 默认深度10级
  237. public function getRecursiveChildrenChengji($parentUid, $number = 10) {
  238. $user = Db::name('user')->where('uid', $parentUid)->field('uid,spread_uid,contribute,per_contribute')->find();
  239. $user['contribute_sum'] = bcadd($user['contribute'], $user['per_contribute'], 2);
  240. $user['contribute_sum'] = 0;
  241. $uids = [];// 用于存储符合条件的子级 uid
  242. $result = [$user]; // 用于存储符合条件的子级数据
  243. // 定义递归函数
  244. $num = 0;// 当前层级
  245. $recursion = function ($parentUid, $number, $num) use (&$uids, &$result, &$recursion) {
  246. if($num >= $number){
  247. return;
  248. }
  249. // 查询当前父级的所有直接子级
  250. $children = Db::name('user')->field('uid,spread_uid,contribute,per_contribute')->where("spread_uid", $parentUid)->select()->toArray();
  251. // 如果没有子级,直接返回
  252. if (!count($children) && count($children) < 1) {
  253. return;
  254. }else{
  255. $num = $num + 1;
  256. }
  257. // 遍历每个子级
  258. foreach ($children as $childUid) {
  259. // 如果有重复的就跳过 防止死循环
  260. if(in_array($childUid['uid'], $uids)){
  261. continue;
  262. }
  263. // 将符合条件的子级 uid 添加到结果数组
  264. $uids[] = $childUid['uid'];
  265. // 将符合条件的子级 uid 添加到结果数组
  266. $childUid['contribute_sum'] = bcadd($childUid['contribute'], $childUid['per_contribute'], 2);
  267. $result[] = $childUid;
  268. // 递归查询子级的子级
  269. $recursion($childUid['uid'], $number, $num);
  270. }
  271. };
  272. // 从初始父级开始递归查询
  273. $recursion($parentUid, $number, $num);
  274. return $result; // 返回结果数组,并去重
  275. }
  276. // 贡献值
  277. public function gongxian_info(){
  278. log::info("============gongxianinfo");
  279. $user = $this->request->userInfo();
  280. if($user->uid>0){
  281. // 先去更新一下用户身份
  282. $number = Db::name("system_config_value")->where(["config_key" => "team_commission_recursion_depth"])->value("value");
  283. $this->repository->setUserIdentity($user->uid);
  284. $result = $this->repository->getUserContributeInfoByDepth($user->uid, 0);
  285. $con = DB::name('user')->where('uid', $user->uid)->find();
  286. $isNormalUser = false;
  287. if ($con['user_group'] == 1) {
  288. $isNormalUser = true;
  289. }
  290. $data = [
  291. 'no_total_source' => Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number'),
  292. 'team_gongxian_num' => $result['arriveNumTeam'],
  293. 'zhitui' => $result['perContribute'],
  294. 'total_source' => $result['contribute'],
  295. 'largeContribute' => $result['largeContribute'],
  296. 'subordinate' => $result['subordinate'],
  297. 'isNormalUser' => $isNormalUser
  298. ];
  299. return app('json')->success($data);
  300. // $dateObj=DB::name('user_sign_gongxian')->where('uid', $user->uid)->where("status",1)->select();
  301. $con = DB::name('user')->where('uid', $user->uid)->find();
  302. // $totalcon = 0;
  303. // foreach($dateObj as $k=>$v){
  304. // $totalcon += $v['number'];
  305. // }
  306. // 已经入账贡献值
  307. // if( $con['user_group'] <= 2 ){
  308. // $data['total_source'] = $con['contribute'] + $con['per_contribute'];
  309. // }else{
  310. $data['total_source'] = $con['contribute'];
  311. $data['zhitui'] = $con['per_contribute'];
  312. // }
  313. // $getteamscon = $this->getPerformance($user->uid);
  314. //$getcon = $this->getPerformance_getcon( $user->uid);
  315. // $team_userinfo_old_jbp22 = $this->getPerformance22($user->uid);
  316. $user_id = $con['uid'];
  317. $user_group = $con['user_group'];
  318. $number = 10;
  319. if($user_group <= 1){
  320. $number = 1;
  321. }
  322. // 如果下级团队只有一个人 那就不用再查了 为0
  323. // 如果用户等级为用户身份 只查一级直推
  324. // 去除掉贡献值最大的下级
  325. $child_nums = $this->getRecursiveChildrenChengji($user_id, $number);
  326. $child_nums_Tree = $this->buildTreeContribute($child_nums, $con['spread_uid']);
  327. if (empty($child_nums_Tree)){
  328. $child_nums_Tree = $child_nums;
  329. $total_contribute = $child_nums_Tree[0]['per_contribute'];
  330. }else{
  331. // 找到贡献值最大的用户的索引
  332. if(count($child_nums_Tree[0]['children'])){
  333. $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_contribute')), array_column($child_nums_Tree, 'total_contribute'));
  334. // 减去该用户的贡献值
  335. $total_contribute = bcsub($child_nums_Tree[0]['total_contribute'], $child_nums_Tree[0]['children'][$maxBalanceIndex]['total_contribute'], 2);
  336. }else{
  337. $total_contribute = $child_nums_Tree[0]['total_contribute'];
  338. }
  339. }
  340. $data['team_gongxian_num'] = $total_contribute;
  341. // 我的团队贡献值
  342. // if( $con['user_group'] <= 2 ){
  343. // $data['team_gongxian_num'] = $team_userinfo_old_jbp22['person_nums_pv'] - $con['per_contribute'];
  344. // }else{
  345. // $data['team_gongxian_num'] = $team_userinfo_old_jbp22['person_nums_pv'];
  346. // }
  347. // 未生效贡献值
  348. $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');
  349. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  350. return app('json')->success($data);
  351. }
  352. }
  353. // 获取团队贡献值
  354. public function gettemasconvalue($user_id) {
  355. //$user_id = 17;
  356. $children = Db::name("user")
  357. ->where("spread_uid", $user_id)
  358. ->select(); // 获取子级的 uid 列表
  359. $total_pv = 0;
  360. foreach($children as $k=>$v){
  361. //$children_pv = Db::name("store_order")->where("uid", $v['uid'])->whereIn("status",[0,1,2,3])->select();
  362. $children_pv = Db::name("user_sign_gongxian")->where("uid", $v['uid'])->where("status",1)->select();
  363. foreach($children_pv as $k1=>$v1){
  364. $total_pv += $v1['number'];
  365. }
  366. }
  367. }
  368. public function gongxian_list(){
  369. $pm = $this->request->param('pm');
  370. [$page, $limit] = $this->getPage();
  371. $uid = $this->request->uid();
  372. log::info("green_integral_list==={$uid}");
  373. $where['uid'] = $uid;
  374. if ($pm==0){
  375. $data = DB::name('user_sign_gongxian')->where($where)->where('status',1)->where('number', '<>',0)->field('id,mark,number,addtime,order_id,status')->page($page, $limit)->order("addtime DESC,id desc")->select();
  376. }
  377. // if($pm==1){
  378. // $data = DB::name('user_sign_gongxian')->where($where)->where('pm', 2)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  379. //
  380. // }
  381. if($pm==2){
  382. $data = DB::name('user_sign_gongxian')->where($where)->where('number', '<>',0)->where([['status','in','-1,0']])->field('id,mark,number,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  383. if($data){
  384. $data = $data->toArray();
  385. foreach ($data as $k=>$v){
  386. if($v['status'] == 0){
  387. $data[$k]['mark'] = '(失效)' . $v['mark'];
  388. }
  389. }
  390. }
  391. }
  392. return app("json")->success($data);
  393. }
  394. // 京豆
  395. public function jingdou_info(){
  396. log::info("============hongbao");
  397. $user = $this->request->userInfo();
  398. if($user->uid>0){
  399. // 已经入账京豆
  400. //$data['total_source']=$user->vr;//原件
  401. $data['total_source'] = $user->jingdou;// 临时使用
  402. // 为生效京豆
  403. $data['no_total_source']=Db::name('user_sign_jingdou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  404. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  405. return app('json')->success($data);
  406. }
  407. }
  408. public function jingdou_list(){
  409. $pm = $this->request->param('pm');
  410. [$page, $limit] = $this->getPage();
  411. $uid = $this->request->uid();
  412. log::info("jingdou_list==={$uid}");
  413. $where['uid'] = $uid;
  414. if ($pm==0){
  415. $data = DB::name('user_sign_jingdou')->where($where)->where('type', 1)->where('status',1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  416. }
  417. if($pm==1){
  418. $data = DB::name('user_sign_jingdou')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  419. }
  420. if($pm==2){
  421. $data = DB::name('user_sign_jingdou')->where($where)->where([['status','in','-1,0']])->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  422. if($data){
  423. $data = $data->toArray();
  424. foreach ($data as $k=>$v){
  425. if($v['status'] == 0){
  426. $data[$k]['mark'] = '(失效)' . $v['mark'];
  427. }
  428. }
  429. }
  430. }
  431. // $data['total'] =111;
  432. return app("json")->success($data);
  433. }
  434. // 复购金
  435. public function fugou_info(){
  436. log::info("============fugou");
  437. $user = $this->request->userInfo();
  438. if($user->uid>0){
  439. // 已经入账京豆
  440. $data['total_source']=$user->fugou;
  441. // 为生效京豆
  442. $data['no_total_source']=Db::name('user_sign_fugou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  443. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  444. return app('json')->success($data);
  445. }
  446. }
  447. public function fugou_list(){
  448. $pm = $this->request->param('pm');
  449. [$page, $limit] = $this->getPage();
  450. $uid = $this->request->uid();
  451. log::info("fugou_list==={$uid}");
  452. $where['uid'] = $uid;
  453. if ($pm==0){
  454. $data = DB::name('user_sign_fugou')->where($where)->where('type', 1)->where('status',1)->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  455. }
  456. if($pm==1){
  457. $data = DB::name('user_sign_fugou')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  458. }
  459. if($pm==2){
  460. $data = DB::name('user_sign_fugou')->where($where)->where('type', 1)->where([['status','in','-1,0']])->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  461. if($data){
  462. $data = $data->toArray();
  463. foreach ($data as $k=>$v){
  464. if($v['status'] == 0){
  465. $data[$k]['mark'] = '(失效)' . $v['mark'];
  466. }
  467. }
  468. }
  469. }
  470. return app("json")->success($data);
  471. }
  472. // VR 购物金
  473. public function vr_info(){
  474. log::info("============vr");
  475. $user = $this->request->userInfo();
  476. if($user->uid>0){
  477. // 已经入账京豆
  478. $data['total_source'] = $user->vr;
  479. // 为生效京豆
  480. $data['no_total_source']=0;
  481. //$data['no_total_source']=Db::name('user_sign_vr')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  482. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  483. return app('json')->success($data);
  484. }
  485. }
  486. public function vr_list(){
  487. $pm = $this->request->param('pm');
  488. [$page, $limit] = $this->getPage();
  489. $uid = $this->request->uid();
  490. log::info("vr_list==={$uid}");
  491. $where['uid'] = $uid;
  492. $data = DB::name('user_sign_vr')->page($page, $limit)->order("id desc")->select();
  493. if ($pm==0){
  494. $data = DB::name('user_sign_vr')->where($where)->where('type', 1)->page($page, $limit)->order("id desc")->select();
  495. }
  496. if($pm==2){
  497. $data = DB::name('user_sign_vr')->where($where)->where('type', 2)->page($page, $limit)->order("id desc")->select();
  498. }
  499. // if($pm==2){
  500. // $data = DB::name('user_sign_vr')->where($where)->where('status', -1)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  501. //
  502. // }
  503. log::info("=======date==={$data}");
  504. return app("json")->success($data);
  505. }
  506. public function spread_info_yhc()
  507. {
  508. log::info("============ddddddddd");
  509. $user = $this->request->userInfo();
  510. if($user->uid>0){
  511. // 已经入账积分
  512. $data['total_source']=$user->score;
  513. // 为生效积分
  514. $data['no_total_source']=Db::name('user_sign_score')->where('status', -1)->where('uid', $user->uid)->sum('reward_socre');;
  515. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  516. return app('json')->success($data);
  517. }
  518. // if ($this->source == 'yhc' && $this->merId) {
  519. // $where['mer_id'] = $this->merId;
  520. // $where['uid'] = $user->uid;
  521. // $enterprise_user = Db::name('enterprise_user')->where($where)->find();
  522. // if ($enterprise_user) {
  523. // $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额
  524. // $data['unsettled_balance'] = 0;//未结算
  525. // $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price');
  526. // $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现
  527. // $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现
  528. // $data['identity'] = $enterprise_user['identity'];
  529. // $data['level'] = $enterprise_user['level'];
  530. // $data['partnership'] = $enterprise_user['partnership'];
  531. // $data['green_integral'] = $enterprise_user['green_integral'];
  532. // $data['green_integral_is'] = $enterprise_user['green_integral_is'];
  533. // $data['operate'] = $enterprise_user['operate'];
  534. // $data['operate_icon'] = '';
  535. // $data['operate_text'] = '';
  536. // $member_settings = merchantConfig($this->merId, 'member_settings');
  537. // if ($data['operate'] == 101) {
  538. // $data['operate_icon'] = $member_settings['yy_one_img'];
  539. // $data['operate_text'] = $member_settings['yy_one_text'];
  540. // }
  541. // if ($data['operate'] == 102) {
  542. // $data['operate_icon'] = $member_settings['yy_two_img'];
  543. // $data['operate_text'] = $member_settings['yy_two_text'];
  544. // }
  545. //
  546. //
  547. // $data['nickname'] = $user->nickname;
  548. // $data['avatar'] = $enterprise_user['avatar'];
  549. //
  550. // $arr = $this->jisuan_fans($user->uid);
  551. // $data['fans_num'] = count($arr);//粉丝总数
  552. //
  553. // $yanglao = 0;
  554. // $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0];
  555. // $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  556. // $yanglao += $offLine1;
  557. // $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  558. // $yanglao += $offLine2;
  559. //
  560. //
  561. // $data['ylj'] = set_price_rtrim($yanglao);
  562. //
  563. // $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money');
  564. //
  565. //
  566. // $data['uid'] = $enterprise_user['uid'];
  567. // if ($enterprise_user['identity'] > 100) {
  568. // $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find();
  569. // if (!$data['identity_data']) {
  570. // $data['identity_data'] = null;
  571. // $data['identity'] = '100';
  572. // }
  573. // } else {
  574. // $data['identity_data'] = null;
  575. // }
  576. //
  577. // $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find();
  578. //
  579. //
  580. // return app('json')->success($data);
  581. // }
  582. // }
  583. return app('json')->fail('用户不存在');
  584. }
  585. /**
  586. * @param UserBillRepository $billRepository
  587. * @return mixed
  588. * @author xaboy
  589. * @day 2020/6/22
  590. */
  591. public function bill(UserBillRepository $billRepository)
  592. {
  593. [$page, $limit] = $this->getPage();
  594. $where = [
  595. // 'now_money' => $this->request->param('type', 0),
  596. 'status' => $this->request->param('status'),
  597. ];
  598. if ($this->request->param('is_red') == true) {
  599. $where['is_red_brokerage'] = 1;
  600. }
  601. return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
  602. }
  603. /**
  604. * @param UserBillRepository $billRepository
  605. * @return mixed
  606. * @author xaboy
  607. * @day 2020/6/22
  608. */
  609. public function brokerage_list(UserBillRepository $billRepository)
  610. {
  611. [$page, $limit] = $this->getPage();
  612. return app('json')->success($billRepository->userList([
  613. 'category' => 'brokerage',
  614. ], $this->request->uid(), $page, $limit));
  615. }
  616. /**
  617. * @return mixed
  618. * @throws \think\db\exception\DataNotFoundException
  619. * @throws \think\db\exception\DbException
  620. * @throws \think\db\exception\ModelNotFoundException
  621. * @author xaboy
  622. * @day 2020/6/22
  623. */
  624. public function spread_order()
  625. {
  626. [$page, $limit] = $this->getPage();
  627. return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit));
  628. }
  629. /**
  630. * TODO
  631. * @return mixed
  632. * @author Qinii
  633. * @day 2020-06-18
  634. */
  635. public function binding()
  636. {
  637. $data = $this->request->params(['phone', 'sms_code']);
  638. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  639. $user = $this->repository->accountByUser($data['phone']);
  640. if ($user) {
  641. $data = ['phone' => $data['phone']];
  642. } else {
  643. $data = ['account' => $data['phone'], 'phone' => $data['phone']];
  644. }
  645. $this->repository->update($this->request->uid(), $data);
  646. return app('json')->success('绑定成功');
  647. }
  648. /**
  649. * TODO
  650. * @return mixed
  651. * @author Qinii
  652. * @day 2020-06-18
  653. */
  654. public function binding_verify()
  655. {
  656. $data = $this->request->params(['user_id', 'captcha']);
  657. $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone");
  658. $data['sms_code'] = $data['captcha'];
  659. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  660. return app('json')->success('验证成功');
  661. }
  662. public function checkSmsCode($phone, $code)
  663. {
  664. $sms_key = 'api.auth.sms.' . $phone;
  665. if (!$cache_code = Cache::get($sms_key)) return false;
  666. if ($code != $cache_code) return false;
  667. Cache::delete($sms_key);
  668. return true;
  669. }
  670. /**
  671. * @return mixed
  672. * @throws \think\db\exception\DataNotFoundException
  673. * @throws \think\db\exception\DbException
  674. * @throws \think\db\exception\ModelNotFoundException
  675. * @author xaboy
  676. * @day 2020/6/22
  677. */
  678. public function spread_list()
  679. {
  680. [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true);
  681. $uid = $this->request->uid();
  682. [$page, $limit] = $this->getPage();
  683. return app('json')->success($level == 2
  684. ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit)
  685. : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit));
  686. }
  687. /**
  688. * @return mixed
  689. * @author xaboy
  690. * @day 2020/6/22
  691. */
  692. public function spread_top()
  693. {
  694. [$page, $limit] = $this->getPage();
  695. $type = $this->request->param('type', 0);
  696. return app('json')->success($type == 1
  697. ? $this->repository->spreadMonthTop($page, $limit)
  698. : $this->repository->spreadWeekTop($page, $limit));
  699. }
  700. /**
  701. * @return mixed
  702. * @author xaboy
  703. * @day 2020/6/22
  704. */
  705. public function brokerage_top()
  706. {
  707. [$page, $limit] = $this->getPage();
  708. $type = $this->request->param('type', 0);
  709. return app('json')->success($type == 1
  710. ? $this->repository->brokerageMonthTop($page, $limit)
  711. : $this->repository->brokerageWeekTop($page, $limit));
  712. }
  713. public function history(UserVisitRepository $repository)
  714. {
  715. $uid = $this->request->uid();
  716. [$page, $limit] = $this->getPage();
  717. return app('json')->success($repository->getHistory($uid, $page, $limit));
  718. }
  719. public function deleteHistory($id, UserVisitRepository $repository)
  720. {
  721. $uid = $this->request->uid();
  722. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  723. return app('json')->fail('数据不存在');
  724. $repository->delete($id);
  725. return app('json')->success('删除成功');
  726. }
  727. public function account()
  728. {
  729. $user = $this->request->userInfo();
  730. if (!$user->phone) return app('json')->fail('请绑定手机号');
  731. return app('json')->success($this->repository->selfUserList($user->phone));
  732. }
  733. public function switchUser()
  734. {
  735. $uid = (int)$this->request->param('uid');
  736. if (!$uid) return app('json')->fail('用户不存在');
  737. $userInfo = $this->request->userInfo();
  738. if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
  739. $user = $this->repository->switchUser($userInfo, $uid);
  740. $tokenInfo = $this->repository->createToken($user);
  741. $this->repository->loginAfter($user);
  742. return app('json')->success($this->repository->returnToken($user, $tokenInfo));
  743. }
  744. /**
  745. * 签到 获取积分
  746. * @return mixed
  747. * @throws \think\db\exception\DataNotFoundException
  748. * @throws \think\db\exception\DbException
  749. * @throws \think\db\exception\ModelNotFoundException
  750. */
  751. public function sub_signin()
  752. {
  753. $member_id = $this->request->uid();
  754. if (!$member_id) return app('json')->fail('用户不存在');
  755. $res = $this->repository->sub_signin($member_id);
  756. return app('json')->success($res);
  757. }
  758. /**
  759. * 获取用户签到记录
  760. * data1 开始时间
  761. * data2 结束时间
  762. * @return mixed
  763. * @throws \think\db\exception\DataNotFoundException
  764. * @throws \think\db\exception\DbException
  765. * @throws \think\db\exception\ModelNotFoundException
  766. */
  767. public function get_signin()
  768. {
  769. $member_id = $this->request->uid();
  770. if (!$member_id) return app('json')->fail('用户不存在');
  771. $where = [];
  772. $data1 = input('data1');
  773. $data2 = input('data2');
  774. if ($data1 && $data2) {
  775. $where["data1"] = $data1;
  776. $where["data2"] = $data2;
  777. }
  778. $res = $this->repository->get_signin($member_id, $where);
  779. return app('json')->success($res);
  780. }
  781. /**
  782. * 提交实名认证
  783. *
  784. * @return void
  785. */
  786. public function add_certification()
  787. {
  788. $member_id = $this->request->uid();
  789. $type = input("type", 0);
  790. if ($type == 1) {
  791. $data = $this->repository->get_cer(["uid" => $member_id]);
  792. return app('json')->success($data);
  793. }
  794. if (!$member_id) return app('json')->fail('用户不存在');
  795. $params = $this->request->params([
  796. 'user_name',
  797. 'mobile',
  798. 'user_card',
  799. 'card_positive',
  800. 'card_reverse',
  801. ]);
  802. $params['create_time'] = time();
  803. $params['uid'] = $member_id;
  804. $baidu = new Ocr();
  805. $image = file_get_contents($params['card_positive']);
  806. $idCardSide = "front";
  807. $result = $baidu->idcard($image, $idCardSide);
  808. $real_user_name = $result['words_result']['姓名']['words'] ?? '';
  809. $real_user_card = $result['words_result']['公民身份号码']['words'] ?? '';
  810. if ($real_user_name != $params['user_name']) {
  811. return app('json')->fail('姓名或身份证号输入有误~');
  812. }
  813. if ($real_user_card != $params['user_card']) {
  814. return app('json')->fail('姓名或身份证号输入有误~');
  815. }
  816. if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) {
  817. $params['status'] = 1;
  818. $res = $this->repository->add_cer($params, $member_id);
  819. if ($res) {
  820. $userRepository = app()->make(UserRepository::class);
  821. // 赠送积分 完善实名送90个积分,同时送邀请人50个积分
  822. $userRepository->sign_add($member_id, 90,1,'完善实名系统赠送90个积分','','', '', 1, '', 1);
  823. $member_info = Db::name('user')->where( array('uid' => $member_id) )->find();
  824. Db::name('user')
  825. ->where('uid', $member_id)
  826. ->update(['real_name' => $params['user_name'], 'nickname' => $params['user_name']]);
  827. if($member_info['spread_uid']){
  828. // 好友完善实名系统赠送50个积分
  829. $spreadUid = $member_info['spread_uid'];
  830. $userRepository->sign_add($spreadUid, 50,1,'好友完善实名系统赠送50个积分','','', '', 1, '', 1);
  831. }
  832. return app('json')->success($res);
  833. } else {
  834. return app('json')->fail('认证失败');
  835. }
  836. } else {
  837. return app('json')->fail('认证失败,请重新认证');
  838. }
  839. }
  840. /**
  841. * 申请代理
  842. * name:公司名称
  843. * identity:身份
  844. * license:营业执照
  845. */
  846. public function apply_agent()
  847. {
  848. $name = input("name", "");
  849. $identity = input("identity", 1);
  850. $license = input("license", "");
  851. $province_id = input("province_id", "");
  852. $city_id = input("city_id", "");
  853. $area_id = input("area_id", "");
  854. $street_id = input("street_id", "");
  855. $spread_account = input("spread_account", "");
  856. $member_id = $this->request->uid();
  857. if ($identity != 6 && (!$name || !$identity || !$license)) {
  858. return app('json')->fail('请检查参数');
  859. }
  860. if ($identity == 6 && (!$name || !$identity)) {
  861. return app('json')->fail('请检查参数');
  862. }
  863. $data = [
  864. "name" => $name,
  865. "identity" => $identity,
  866. "license" => $license,
  867. "user_id" => $member_id,
  868. "province_id" => $province_id,
  869. "city_id" => $city_id,
  870. "area_id" => $area_id,
  871. "street_id" => $street_id,
  872. 'spread_account' => $spread_account,
  873. "add_time" => time(),
  874. "update_time" => time()
  875. ];
  876. $res = $this->repository->agent($data);
  877. if ($res['code'] == 400) {
  878. return app('json')->fail($res['msg']);
  879. }
  880. return app('json')->success("申请成功", $res);
  881. }
  882. /*查询是否有已申请或者审核中的代理信息*/
  883. public function isAgent()
  884. {
  885. $uid = $this->request->uid();
  886. $data = $this->repository->isAgent($uid);
  887. return app("json")->success($data);
  888. }
  889. /*查询是否有审核成功的未支付或支付失败的订单*/
  890. public function AgentPayDetail()
  891. {
  892. $uid = $this->request->uid();
  893. if (!$uid) {
  894. return app('json')->fail('请检查参数');
  895. }
  896. $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid];
  897. $data = $this->repository->getAgentPayDetail($where);
  898. return app('json')->success("成功", $data);
  899. }
  900. /**
  901. * 获取信息 全民营销首页
  902. * @return mixed
  903. */
  904. public function get_agent_info()
  905. {
  906. $member_id = $this->request->uid();
  907. $res = $this->repository->get_agent_info($member_id);
  908. if ($res) {
  909. return app('json')->success($res);
  910. } else {
  911. return app('json')->fail('获取失败');
  912. }
  913. }
  914. /**
  915. * 推广统计
  916. * search 搜索
  917. * @return mixed
  918. */
  919. public function get_extension_info()
  920. {
  921. $search = input("search", "");
  922. $where = $this->request->params(["identity"]);
  923. $member_id = $this->request->uid();
  924. $res = $this->repository->get_extension_info($member_id, $search, $where);
  925. if ($res) {
  926. return app('json')->success($res);
  927. } else {
  928. return app('json')->fail('获取失败');
  929. }
  930. }
  931. /**
  932. * 收益统计
  933. * type 搜索
  934. * @return mixed
  935. */
  936. public function get_profit_info()
  937. {
  938. $where = $this->request->params([
  939. 'commission_type',
  940. 'date_on',
  941. 'date_off',
  942. 'order'
  943. ]);
  944. $member_id = $this->request->uid();
  945. $res = $this->repository->get_profit_info($member_id, $where);
  946. if ($res) {
  947. return app('json')->success($res);
  948. } else {
  949. return app('json')->fail('获取失败');
  950. }
  951. }
  952. /**
  953. * 订单统计
  954. * search 搜索
  955. * @return mixed
  956. */
  957. public function get_tuiguang_order()
  958. {
  959. $member_id = $this->request->uid();
  960. $res = $this->repository->get_tuiguang_order($member_id);
  961. if ($res) {
  962. return app('json')->success($res);
  963. } else {
  964. return app('json')->fail('获取失败');
  965. }
  966. }
  967. /*
  968. * 攒金明细统计
  969. * */
  970. public function get_commission_all()
  971. {
  972. $uid = $this->request->uid();
  973. $where['date_on'] = 1;
  974. $where['date_off'] = 0;
  975. // $where['commission_type'] = '';
  976. $date = $this->request->params(['date']);//"today","yesterday","week","month","year"
  977. $where['order'] = $date['date'];
  978. $res = $this->repository->get_profit_info($uid, $where);
  979. return app('json')->success($res);
  980. }
  981. /*
  982. * 攒金明细列表
  983. * */
  984. public function get_commission_list()
  985. {
  986. $uid = $this->request->uid();
  987. [$where['page'], $where['limit']] = $this->getPage();
  988. $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year"
  989. $where['type'] = $data['type'];// 0线上;1线下
  990. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  991. $res = $this->repository->get_tuiguang_list($uid, $where);
  992. return app('json')->success($res);
  993. }
  994. /*
  995. * 越攒越多佣金
  996. * */
  997. public function get_com_list()
  998. {
  999. $uid = $this->request->uid();
  1000. [$where['page'], $where['limit']] = $this->getPage();
  1001. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  1002. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  1003. $res = $this->repository->get_com_list($uid, $where);
  1004. return app('json')->success($res);
  1005. }
  1006. /*
  1007. * 越攒越多统计
  1008. * */
  1009. public function get_com_all()
  1010. {
  1011. $uid = $this->request->uid();
  1012. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  1013. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  1014. $res = $this->repository->get_com_all($uid, $where);
  1015. return app('json')->success($res);
  1016. }
  1017. /**
  1018. * 养老金详情
  1019. * @return mixed
  1020. */
  1021. public function get_yanglao()
  1022. {
  1023. $member_id = $this->request->uid();
  1024. $res = $this->repository->get_yanglao($member_id);
  1025. if ($res) {
  1026. return app('json')->success($res);
  1027. } else {
  1028. return app('json')->fail('获取失败');
  1029. }
  1030. }
  1031. /**
  1032. * 养老金明细
  1033. */
  1034. public function yanglaolog()
  1035. {
  1036. $member_id = $this->request->uid();
  1037. [$page, $limit] = $this->getPage();
  1038. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0];
  1039. if ($this->source == 'yhc' && $this->merId) {
  1040. $where['mer_id'] = $this->merId;
  1041. }
  1042. $month = $this->request->param('month', '');// 年月搜索
  1043. $status = $this->request->param('status', 1);
  1044. // 1-全部 2-已结算 3-未结算 4-已取消
  1045. if ($status == 2) {
  1046. $where['status'] = 1;
  1047. } else if ($status == 3) {
  1048. // $where['gzc']=0;
  1049. $where['status'] = 0;
  1050. } else if ($status == 4) {
  1051. $where['status'] = -1;
  1052. }
  1053. $source = $this->request->param('source', -1);
  1054. if ($source > -1) {
  1055. $where['source'] = $source;
  1056. }
  1057. $res = $this->repository->yanglaolog($where, $page, $limit, $month,1);
  1058. if ($res) {
  1059. $res['list'] = $res['list']->toArray();
  1060. if($res['list']){
  1061. foreach ($res['list'] as $k=>$v){
  1062. if($v['status'] == -1){
  1063. $res['list'][$k]['mer_name'] = $v['mer_name'] . '(失效)';
  1064. }
  1065. }
  1066. }
  1067. return app('json')->success($res);
  1068. } else {
  1069. return app('json')->fail('获取失败');
  1070. }
  1071. }
  1072. /*养老金详情*/
  1073. public function YangLaoDetail($id)
  1074. {
  1075. $member_id = $this->request->uid();
  1076. $data = $this->request->params([
  1077. 'type',
  1078. ]);
  1079. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id];
  1080. $res = $this->repository->yanglaoDetail($where);
  1081. return app('json')->success($res);
  1082. }
  1083. /**
  1084. * 消费明细
  1085. * @return mixed
  1086. */
  1087. public function tripartite()
  1088. {
  1089. $member_id = $this->request->uid();
  1090. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]];
  1091. $res = $this->repository->yanglaolog($where);
  1092. if ($res) {
  1093. return app('json')->success($res);
  1094. } else {
  1095. return app('json')->fail('获取失败');
  1096. }
  1097. }
  1098. /**
  1099. * 提现明细
  1100. * @return mixed
  1101. */
  1102. public function withdrawal()
  1103. {
  1104. $member_id = $this->request->uid();
  1105. $data = $this->request->params([
  1106. 'type',
  1107. ]);
  1108. $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2];
  1109. if ($this->source == 'yhc') {
  1110. $where['mer_id'] = $this->merId;
  1111. }
  1112. $res = $this->repository->withdrawal_user($where);
  1113. if ($res) {
  1114. return app('json')->success($res);
  1115. } else {
  1116. return app('json')->fail('获取失败');
  1117. }
  1118. }
  1119. /**
  1120. * 提现详情
  1121. * @return mixed
  1122. * @author cabbage
  1123. * @day 2020/10/31
  1124. */
  1125. public function withdrawalDetail()
  1126. {
  1127. $member_id = $this->request->uid();
  1128. $extract_id = input("extract_id", 0);
  1129. return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id));
  1130. }
  1131. /*
  1132. * 修改个人信息*/
  1133. public function updateUser()
  1134. {
  1135. $uid = $this->request->uid();
  1136. $data['nickname'] = $this->request->param('nickname', null);
  1137. $data['avatar'] = $this->request->param('avatar', null);
  1138. $data['sex'] = $this->request->param('sex', null);
  1139. $data['birthday'] = $this->request->param('birthday', null);
  1140. $data['addres'] = $this->request->param('addres', null);
  1141. $data['mark'] = $this->request->param('mark', null);
  1142. // 新加更换用户手机号逻辑,更换手机号时需验证 当前使用手机号收到的验证码,以确认本人操作
  1143. // 需求描述说:更换用户手机号时,同步更新 商户申请表、商户表、商户管理员表
  1144. $data['phone'] = $this->request->param('phone', null);
  1145. $sms_code = $this->request->param('sms_code', null);
  1146. if (!empty($data['phone'])) {
  1147. $changeUserData = $this->repository->getOne(['phone' => $data['phone']]);
  1148. if (!empty($changeUserData)) {
  1149. return app("json")->fail("该手机号已被用户绑定");
  1150. }
  1151. if (empty($sms_code)) {
  1152. return app("json")->fail("请输入验证码");
  1153. }
  1154. $userData = $this->repository->get($uid)->toArray();
  1155. if (!$this->checkSmsCode($userData['phone'], $sms_code)) {
  1156. return app('json')->fail('验证码不正确');
  1157. }
  1158. // 商户申请表
  1159. Db::name("merchant_intention")
  1160. ->where('uid', $uid)
  1161. ->where('phone', $userData['phone'])
  1162. ->update(['phone' => $data['phone']]);
  1163. // 商户表
  1164. Db::name("merchant")
  1165. ->where('uid', $uid)
  1166. ->where('mer_phone', $userData['phone'])
  1167. ->update(['mer_phone' => $data['phone']]);
  1168. // 商户管理员表
  1169. Db::name("merchant_admin")
  1170. ->where('uid', $uid)
  1171. ->where('account', $userData['phone'])
  1172. ->update(['account' => $data['phone']]);
  1173. }
  1174. if (!empty($data['phone'])) {
  1175. $data['account'] = $data['phone'];
  1176. }
  1177. $data = array_filter($data, function($value) {
  1178. return $value !== null;
  1179. });
  1180. $res = '';
  1181. if ($this->source == 'yhc') {
  1182. $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]);
  1183. unset($data['avatar']);
  1184. }
  1185. $data = $this->repository->updateUser($uid, $data);
  1186. if ($data || $res) {
  1187. return app("json")->success("修改成功", $data);
  1188. }
  1189. return app("json")->fail("未做任何修改");
  1190. }
  1191. /*积分记录*/
  1192. public function socreList()
  1193. {
  1194. [$page, $limit] = $this->getPage();
  1195. $uid = $this->request->uid();
  1196. $data = $this->repository->socreList($uid, $page, $limit);
  1197. return app("json")->success($data);
  1198. }
  1199. function jisuan_fans($uid)
  1200. {
  1201. $where22['node_uid'] = $uid;
  1202. $where22['mer_id'] = $this->merId;
  1203. $arr = $this->jisuantuandui($where22);
  1204. $where['puid'] = $uid;
  1205. $where['mer_id'] = $this->merId;
  1206. $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');// 直属粉丝数量
  1207. $result = array_unique(array_merge($arr, $direct_fans));
  1208. return $result;
  1209. }
  1210. function jisuantuandui($where, $data = [])
  1211. {
  1212. $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid');
  1213. $arr = array_merge($data, $enterprise_user_team);
  1214. foreach ($enterprise_user_team as $v) {
  1215. $where['node_uid'] = $v;
  1216. $arr = $this->jisuantuandui($where, $arr);
  1217. }
  1218. return $arr;
  1219. }
  1220. /**
  1221. * 一壶茶-团队列表
  1222. */
  1223. public function team_list_1()
  1224. {
  1225. $teamid = $this->request->uid();
  1226. //$teamid = $this->request->param('teamid');//测试ID
  1227. $teamid = 17;
  1228. $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();// 查询旧系统是否有当前会员
  1229. $type = $this->request->param('type',0);// 1:大部门,0:小部门,2:直推
  1230. if(!empty($datas_jbp)){
  1231. $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
  1232. // 判断大小团队(业绩多的是大部门,业绩小的是小部门)
  1233. $tes = $this->teamPeople($teamid,$type);// 1:团队,2:个人
  1234. // 获取分页参数
  1235. $data1= [
  1236. "total"=>100,
  1237. "per_page"=> 10,
  1238. "current_page"=> 1,
  1239. "last_page"=> 1,
  1240. ];
  1241. if($type != 2){
  1242. // 小部门和大部门列表数据
  1243. foreach($tes as $k=>$v){
  1244. $curr_pv = '';
  1245. if($v['curr_type']==0){
  1246. $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
  1247. }else if($v['curr_type']==1){
  1248. $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
  1249. }else{
  1250. $curr_pv = 0;
  1251. }
  1252. $data1['data'][$k] = [
  1253. "uid"=>$v["id"],
  1254. "nickname"=> $v['user_name'] . $curr_pv,
  1255. "phone"=> "137****3315",
  1256. "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1257. "create_time"=>"2025-01-25 11:00:18",
  1258. "identity"=>"11",
  1259. "level"=> "40002",
  1260. "partnership"=>"22",
  1261. "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
  1262. "new_performance"=> 0,// 新增业绩
  1263. "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,// 团购人数(加的这个1 是当前用户的数)
  1264. ];
  1265. }
  1266. }else{
  1267. // 直推列表
  1268. foreach($tes as $k=>$v){
  1269. $data1['data'][$k] = [
  1270. "uid"=>$v["uid"],
  1271. "nickname"=> $v['nickname'],
  1272. "avatar"=>$v['avatar'],
  1273. "create_time"=>"2025-01-25 11:00:18",
  1274. ];
  1275. }
  1276. }
  1277. $data['team_list'] = $data1;
  1278. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;// 粉丝数
  1279. $data['new_performance'] = 0;// 新增业绩
  1280. $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];// 总业绩
  1281. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];// 个人联盟
  1282. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];// 共建联盟
  1283. $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);// 公共联盟PV
  1284. $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);// 个人联盟PV
  1285. // $data['effective_fans_num'] = DB::name('enterprise_user')
  1286. }
  1287. // var_dump($data);
  1288. // 把新表中的新增邀请用户加到数组中
  1289. //$spread_usersdata = Db::name('user')->where("spread_uid",$teamid)->select();//查询旗下会员
  1290. // 查询当前会员旗下的会员数据
  1291. // 获取分页参数
  1292. [$page, $limit] = $this->getPage();
  1293. // 查询当前会员旗下的会员数据(分页)
  1294. $subordinate_members = Db::name('user')
  1295. ->alias('u')
  1296. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1297. ->where("u.spread_uid", $teamid) // 查询旗下会员
  1298. ->where("so.mer_id", 496)
  1299. // ->where("so.douhuomall", 1)
  1300. // ->where("so.douhuomall_status", 9)
  1301. // ->where("so.status", 0)
  1302. ->group('u.uid') // 确保每个用户只出现一次
  1303. ->page($page, $limit) // 分页查询
  1304. ->select(); // 获取分页数据
  1305. // 计算团队总业绩
  1306. // $total_amount=0;
  1307. // foreach($subordinate_members as $k=>$v){
  1308. // }
  1309. // 获取总会员数
  1310. $total_members = Db::name('user') ->alias('u')
  1311. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1312. ->where("u.spread_uid", $teamid) // 查询旗下会员
  1313. ->where("so.mer_id", 496)
  1314. // ->where("so.douhuomall", 1)
  1315. // ->where("so.douhuomall_status", 9)
  1316. // ->where("so.status", 0)
  1317. ->group('u.uid') // 确保每个用户只出现一次
  1318. ->page($page, $limit) // 分页查询
  1319. ->count(); // 获取分页数据
  1320. // 构造分页信息
  1321. $data1 = [
  1322. "total" => $total_members,
  1323. "per_page" => $limit,
  1324. "current_page" => $page,
  1325. "last_page" => ceil($total_members / $limit),
  1326. "data" => []
  1327. ];
  1328. $total_amount_pv_team = 0;// 计算总业绩
  1329. // 获取团队总数量
  1330. $team_count_total = 0;
  1331. $small_count = 0;// 小部门人数
  1332. // var_dump($this->calculatePerformance($subordinate_members));
  1333. // 获取大小部门数据(新表)
  1334. $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);// 下标0是大部门
  1335. // var_dump( $get_big_small_datas);
  1336. // 判断大小部门的人数(根据业绩多的就是大部门,业绩小的就是小部门来计算展示的部门人数);
  1337. $big_team_count = $get_big_small_datas[0]['team_count'];
  1338. $smallteam_count = $get_big_small_datas[1]['team_count'];
  1339. // end
  1340. // 遍历分页数据,构造每个会员的详细信息
  1341. foreach ($subordinate_members as $k => $v) {
  1342. // 计算自己和旗下的业绩
  1343. $t_teams_pv = $this->calculatePerformance($v['uid']);
  1344. $total_amount_pv_team += $t_teams_pv['total_performance'];
  1345. $data1['data'][$k] = [
  1346. "uid" => $v["uid"],
  1347. "nickname" => $v['nickname'], // 假设昵称字段为 nickname
  1348. "phone" => substr_replace($v['phone'], '****', 3, 4), // 隐藏手机号中间四位
  1349. "avatar" => $v['avatar'], // 假设头像字段为 avatar
  1350. "create_time" => $v['create_time'], // 假设创建时间为 create_time
  1351. "total_performance" => $t_teams_pv['total_performance'], // 假设总业绩字段需要额外计算
  1352. "new_performance" => $t_teams_pv['total_performance'], // 假设新增业绩字段需要额外计算
  1353. "team_count" => $t_teams_pv['team_count'], // 假设团购人数需要额外计算
  1354. ];
  1355. }
  1356. // 根据 type 参数处理数据
  1357. if ($type == 1) {
  1358. // 大部门:取 total_performance 最大的一个数组
  1359. usort($data1['data'], function ($a, $b) {
  1360. return $b['total_performance'] <=> $a['total_performance'];
  1361. });
  1362. $data1['data'] = array_slice($data1['data'], 0, 1); // 只保留最大的一个
  1363. } elseif ($type == 0) {
  1364. // 小部门:去掉 total_performance 最大的一个数组
  1365. usort($data1['data'], function ($a, $b) {
  1366. return $b['total_performance'] <=> $a['total_performance'];
  1367. });
  1368. $data1['data'] = array_slice($data1['data'], 1); // 去掉第一个
  1369. } elseif ($type == 2) {
  1370. // 直推:不做任何处理
  1371. }
  1372. // 构造最终返回的数据
  1373. $data = [
  1374. 'team_list' => $data1,
  1375. 'fans_num' => $get_big_small_datas[0]['team_count'] + $get_big_small_datas[1]['team_count'], // 粉丝数
  1376. 'new_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 新增业绩
  1377. 'total_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 总业绩
  1378. 'person_nums' => $big_team_count, // 大部门人数
  1379. 'common_nums' => $smallteam_count, // 小部门人数
  1380. 'common_nums_pv' => $get_big_small_datas[0]['total_performance'], // 公共联盟PV
  1381. 'person_nums_pv' => $get_big_small_datas[1]['total_performance'], // 个人联盟PV
  1382. ];
  1383. return app("json")->success($data);
  1384. }
  1385. public function buildTreePv($users, $parentId = 0, $keyword = 'level_id' , $is_b = 1) {
  1386. $branch = array();
  1387. foreach ($users as $user) {
  1388. if ($user[$keyword] == $parentId) {
  1389. if($keyword == 'spread_uid' && $is_b == 1) {
  1390. $children = $this->buildTreePv($users, $user['uid'], 'spread_uid', $is_b+1); // 递归查找子节点
  1391. } else {
  1392. $children = $this->buildTreePv($users, $user['uid'], 'level_id', $is_b+1); // 递归查找子节点
  1393. }
  1394. if ($children) {
  1395. $user['children'] = $children; // 如果有子节点,添加到当前节点
  1396. }else{
  1397. $user['children'] = [];
  1398. }
  1399. $user['team_count'] = count($children);
  1400. $user['total_pv'] = $user['pv']; // 初始化当前节点的总余额为自身余额
  1401. if ($children) { // 如果存在子节点,计算总余额
  1402. foreach ($children as $child) {
  1403. $user['total_pv'] += $child['total_pv']; // 累加子节点的总余额
  1404. $user['team_count'] += $child['team_count'];
  1405. }
  1406. }
  1407. $branch[] = $user; // 将当前节点添加到树中
  1408. }
  1409. }
  1410. return $branch; // 返回当前分支的所有节点
  1411. }
  1412. // 根据父级uid,递归获取所有子级UID数组 默认深度10级
  1413. public function getdepartmentStatistics($parentUid, $keyword = 'level_id') {
  1414. $user = Db::name('user')->where('uid', $parentUid)->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->find();
  1415. $user['pv'] = 0;
  1416. $uids = [];// 用于存储符合条件的子级 uid
  1417. $result = [$user]; // 用于存储符合条件的子级数据
  1418. // 定义递归函数
  1419. $is_a = true;
  1420. $recursion = function ($parentUid) use (&$uids, &$result, &$recursion, &$keyword, &$is_a) {
  1421. if ($keyword == 'spread_uid' && $is_a) {
  1422. $children = Db::name('user')->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->where($keyword, $parentUid)->select()->toArray();
  1423. $is_a = false;
  1424. } else {
  1425. $children = Db::name('user')->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->where('level_id', $parentUid)->select()->toArray();
  1426. }
  1427. // 查询当前父级的所有直接子级
  1428. // 如果没有子级,直接返回
  1429. if (!count($children) && count($children) < 1) {
  1430. return;
  1431. }
  1432. // 遍历每个子级
  1433. foreach ($children as $childUid) {
  1434. // 如果有重复的就跳过 防止死循环
  1435. if(in_array($childUid['uid'], $uids)){
  1436. continue;
  1437. }
  1438. // 将符合条件的子级 uid 添加到结果数组
  1439. $uids[] = $childUid['uid'];
  1440. $result[] = $childUid;
  1441. // 递归查询子级的子级
  1442. $recursion($childUid['uid']);
  1443. }
  1444. };
  1445. // 从初始父级开始递归查询
  1446. $recursion($parentUid);
  1447. return $result; // 返回结果数组,并去重
  1448. }
  1449. /**
  1450. * 一壶茶-团队列表
  1451. */
  1452. public function team_list()
  1453. {
  1454. $teamid = $this->request->uid();
  1455. [$page, $limit] = $this->getPage();
  1456. // 小夏重写部分
  1457. $user_id = $teamid;
  1458. // 如果下级团队只有一个人 那就不用再查了 为0
  1459. // 如果用户等级为用户身份 只查一级直推
  1460. // 去除掉贡献值最大的下级
  1461. $user = Db::name('user')->where('uid', $user_id)->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->find();
  1462. $child_nums = $this->getdepartmentStatistics($user_id, 'level_id');
  1463. $child_nums_Tree = $this->buildTreePv($child_nums, $user['level_id'], 'level_id');
  1464. $new_performance = 0; // 一周内新增总业绩
  1465. // 这周的时间区间
  1466. // $end_time = date('Y-m-d ' . '00:00:00', strtotime('-7 days'));
  1467. $now = time();
  1468. $startTime = date('Y-m-d 00:00:00', strtotime('monday this week', $now)); // 这周星期一的开始时间
  1469. $endTime = date('Y-m-d 23:59:59', strtotime('sunday this week', $now)); // 这周星期日的结束时间
  1470. $person_nums_pv = 0;// 大部门业绩
  1471. $common_nums_pv = 0;// 小部门业绩
  1472. $aLL_list = [];// 直推数据
  1473. $person_list = [];// 大部门数据
  1474. $common_list = [];// 小部门数据
  1475. if (count($child_nums_Tree) && isset($child_nums_Tree[0]['children']) && count($child_nums_Tree[0]['children'])) {
  1476. // 计算总新增业绩
  1477. $uid_list = array_column($child_nums, 'uid');
  1478. $uid_list = array_diff($uid_list, [$user_id]);
  1479. $new_performance = Db::name("user_pv_log")
  1480. ->whereIn('uid', $uid_list)
  1481. ->whereBetween('settlement_time', [$startTime, $endTime])
  1482. ->sum('pv');
  1483. // 获取大部门的key
  1484. $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_pv')), array_column($child_nums_Tree[0]['children'], 'total_pv'));
  1485. foreach ($child_nums_Tree[0]['children'] as $k => $v) {
  1486. $child_nums = $this->getdepartmentStatistics($v['uid'], 'level_id');
  1487. $uid_list = array_column($child_nums, 'uid');
  1488. array_push($uid_list, $v['uid']);
  1489. $new_performance_child = Db::name("user_pv_log")
  1490. ->whereIn('uid', $uid_list)
  1491. ->whereBetween('settlement_time', [$startTime, $endTime])
  1492. ->sum('pv');
  1493. if ($k == $maxBalanceIndex) {
  1494. $person_list[] = [
  1495. "uid" => $v["uid"],
  1496. "spread_uid" => $v['spread_uid'],
  1497. "level_id" => $v['level_id'],
  1498. "nickname" => $v['nickname'],
  1499. "avatar" => $v['avatar'],
  1500. "pv" =>round( $v['pv'],2),
  1501. "total_performance" => round($v['total_pv'],2),
  1502. "create_time" => $v['create_time'],
  1503. 'team_count' => $v['team_count'],
  1504. 'new_performance' => $new_performance_child
  1505. ];
  1506. $person_nums_pv = bcadd($person_nums_pv, $v['total_pv'],2);
  1507. } else {
  1508. $common_list[] = [
  1509. "uid" => $v["uid"],
  1510. "spread_uid" => $v['spread_uid'],
  1511. "level_id" => $v['level_id'],
  1512. "nickname" => $v['nickname'],
  1513. "avatar" => $v['avatar'],
  1514. "pv" => round($v['pv'],2),
  1515. "total_performance" => round($v['total_pv'],2),
  1516. "create_time" => $v['create_time'],
  1517. 'team_count' => $v['team_count'],
  1518. 'new_performance' => $new_performance_child
  1519. ];
  1520. $common_nums_pv = bcadd($common_nums_pv, $v['total_pv'],2);
  1521. }
  1522. // 我的直推 不是大小团队 加起来
  1523. // $aLL_list[] = [
  1524. // "uid" => $v["uid"],
  1525. // "spread_uid" => $v['spread_uid'],
  1526. // "nickname" => $v['nickname'],
  1527. // "avatar" => $v['avatar'],
  1528. // "pv" => $v['pv'],
  1529. // "total_performance" => (int)$v['total_pv'],
  1530. // "create_time" => $v['create_time'],
  1531. // 'team_count'=> $v['team_count'],
  1532. // 'new_performance' => $new_performance_child
  1533. // ];
  1534. }
  1535. }
  1536. $type = $this->request->param('type', 0);// 1:大部门,0:小部门,2:直推
  1537. // 初始化最终返回的数据
  1538. $data = [
  1539. 'team_list' => [],
  1540. 'fans_num' => 0, // 粉丝数
  1541. 'new_performance' => 0, // 新增业绩
  1542. 'total_performance' => 0, // 总业绩
  1543. 'person_nums' => 0, // 个人联盟人数
  1544. 'common_nums' => 0, // 公共联盟人数
  1545. 'common_nums_pv' => 0, // 公共联盟PV
  1546. 'person_nums_pv' => 0, // 个人联盟PV
  1547. ];
  1548. if ($type != 2) {
  1549. if ($type == 1) {
  1550. $data1 = [
  1551. "total" => count($person_list),
  1552. "per_page" => (int)$limit,
  1553. "current_page" => $page,
  1554. "last_page" => ceil(count($person_list) / $limit),
  1555. "data" => array_slice($person_list, ($page - 1) * $limit, $limit)
  1556. ];
  1557. } else {
  1558. $data1 = [
  1559. "total" => count($common_list),
  1560. "per_page" => (int)$limit,
  1561. "current_page" => $page,
  1562. "last_page" => ceil(count($common_list) / $limit),
  1563. "data" => array_slice($common_list, ($page - 1) * $limit, $limit)
  1564. ];
  1565. }
  1566. } else {
  1567. $child_nums = $this->getdepartmentStatistics($user_id, 'spread_uid');
  1568. $child_nums_Tree_spread = $this->buildTreePv($child_nums, $user['spread_uid'], 'spread_uid');
  1569. if (count($child_nums_Tree_spread) && isset($child_nums_Tree_spread[0]['children']) && count($child_nums_Tree_spread[0]['children'])) {
  1570. // 计算总新增业绩
  1571. $uid_list = array_column($child_nums, 'uid');
  1572. $uid_list = array_diff($uid_list, [$user_id]);
  1573. foreach ($child_nums_Tree_spread[0]['children'] as $k => $v) {
  1574. $child_nums = $this->getdepartmentStatistics($v['uid']);
  1575. $uid_list = array_column($child_nums, 'uid');
  1576. array_push($uid_list, $v['uid']);
  1577. $new_performance_child = Db::name("user_pv_log")
  1578. ->whereIn('uid', $uid_list)
  1579. ->whereBetween('settlement_time', [$startTime, $endTime])
  1580. ->sum('pv');
  1581. $aLL_list[] = [
  1582. "uid" => $v["uid"],
  1583. "spread_uid" => $v['spread_uid'],
  1584. "level_id" => $v['level_id'],
  1585. "nickname" => $v['nickname'],
  1586. "avatar" => $v['avatar'],
  1587. "pv" => round($v['pv'],2),
  1588. "total_performance" => round($v['total_pv'], 2),
  1589. "create_time" => $v['create_time'],
  1590. 'team_count'=> $v['team_count'],
  1591. 'new_performance' => $new_performance_child
  1592. ];
  1593. }
  1594. }
  1595. $data1 = [
  1596. "total" => count($aLL_list),
  1597. "per_page" => (int)$limit,
  1598. "current_page" => $page,
  1599. "last_page" => ceil(count($aLL_list) / $limit),
  1600. "data" => array_slice($aLL_list, ($page - 1) * $limit, $limit)
  1601. ];
  1602. }
  1603. // 旧系统中的公共部分数据
  1604. $data['teamid'] = $teamid;
  1605. $data['team_list'] = $data1;
  1606. $data['fans_num'] = $child_nums_Tree[0]['team_count'];// 总人数
  1607. $data['new_performance'] = $new_performance;// 新增总业绩
  1608. $data['total_performance'] = bcadd($child_nums_Tree[0]['total_pv'] ?? 0, 0, 2);// 总业绩
  1609. $data['person_nums'] = count($person_list);// 大部门人数
  1610. $data['common_nums'] = count($common_list);// 小部门人数
  1611. $data['common_nums_pv'] = $person_nums_pv;// 大部门业绩
  1612. $data['person_nums_pv'] = $common_nums_pv;// 小部门业绩
  1613. return app("json")->success($data);
  1614. // // 查询当前会员旗下的会员数据(分页)
  1615. // [$page, $limit] = $this->getPage();
  1616. // $subordinate_members = Db::name('user')
  1617. // // ->alias('u')
  1618. // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1619. // ->where("spread_uid", $teamid)
  1620. // // ->where("so.mer_id", 496)
  1621. // // ->group('u.uid')
  1622. // ->page($page, $limit)
  1623. // ->select();
  1624. // $total_members = Db::name('user')
  1625. // // ->alias('u')
  1626. // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1627. // ->where("spread_uid", $teamid)
  1628. // // ->where("so.mer_id", 496)
  1629. // // ->group('u.uid')
  1630. // ->count();
  1631. // $data1 = [
  1632. // "total" => $total_members,
  1633. // "per_page" => $limit,
  1634. // "current_page" => $page,
  1635. // "last_page" => ceil($total_members / $limit),
  1636. // "data" => []
  1637. // ];
  1638. // $total_amount_pv_team = 0;
  1639. // $team_count_total = 0;
  1640. // foreach ($subordinate_members as $k => $v) {
  1641. // $t_teams_pv = $this->calculatePerformance($v['uid']);
  1642. // $total_amount_pv_team += $t_teams_pv['total_performance'];
  1643. // $team_count_total += $t_teams_pv['team_count'];
  1644. // $data1['data'][$k] = [
  1645. // "uid" => $v["uid"],
  1646. // "nickname" => $v['nickname'],
  1647. // "phone" => substr_replace($v['phone'], '****', 3, 4),
  1648. // "avatar" => $v['avatar'],
  1649. // "create_time" => $v['create_time'],
  1650. // "total_performance" => $t_teams_pv['total_performance'],
  1651. // "new_performance" => $t_teams_pv['total_performance'],
  1652. // "team_count" => $t_teams_pv['team_count'],
  1653. // ];
  1654. // }
  1655. // // 获取大小部门数据
  1656. // $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);
  1657. // // 判断大小部门的人数
  1658. // $big_team_count = $get_big_small_datas[0]['team_count'];
  1659. // $small_team_count = $get_big_small_datas[1]['team_count'];
  1660. // // 根据 type 参数处理数据
  1661. // if ($type == 1) {
  1662. // usort($data1['data'], function ($a, $b) {
  1663. // return $b['total_performance'] <=> $a['total_performance'];
  1664. // });
  1665. // $data1['data'] = array_slice($data1['data'], 0, 1);
  1666. // } elseif ($type == 0) {
  1667. // usort($data1['data'], function ($a, $b) {
  1668. // return $b['total_performance'] <=> $a['total_performance'];
  1669. // });
  1670. // $data1['data'] = array_slice($data1['data'], 1);
  1671. // }
  1672. // // 合并数据
  1673. // if (!empty($datas_jbp)) {
  1674. // // 如果旧系统中有数据,合并新旧数据
  1675. // $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']);
  1676. // $data['fans_num'] += $team_count_total;
  1677. // $data['new_performance'] += $total_amount_pv_team;
  1678. // $data['total_performance'] += $total_amount_pv_team;
  1679. // $data['person_nums'] += $big_team_count;
  1680. // $data['common_nums'] += $small_team_count;
  1681. // $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance'];
  1682. // $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance'];
  1683. // } else {
  1684. // // 如果旧系统中没有数据,直接使用新数据
  1685. // $data['team_list'] = $data1;
  1686. // $data['fans_num'] = $team_count_total;
  1687. // $data['new_performance'] = $total_amount_pv_team;
  1688. // $data['total_performance'] = $total_amount_pv_team;
  1689. // $data['person_nums'] = $big_team_count;
  1690. // $data['common_nums'] = $small_team_count;
  1691. // $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance'];
  1692. // $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance'];
  1693. // }
  1694. // return app("json")->success($data);
  1695. }
  1696. // 计算自己和自己团队下面的业绩。新表
  1697. // 计算自己和自己团队下面的业绩。新表
  1698. public function calculatePerformance($uid)
  1699. {
  1700. // 初始化业绩数组
  1701. $performance = [
  1702. 'personal_performance' => 0, // 个人业绩
  1703. 'team_performance' => 0, // 团队业绩
  1704. 'total_performance' => 0, // 总业绩
  1705. 'team_count' => 0, // 加上自己的团队数量
  1706. ];
  1707. // 定义业绩换算规则
  1708. $performanceMapping = [
  1709. 1180 => 700,
  1710. 10620 => 6300,
  1711. 11800 => 7000
  1712. ];
  1713. // 计算个人业绩
  1714. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  1715. if ($personalOrder) {
  1716. // 将浮点数转换为整数
  1717. $totalPrice = (int)$personalOrder['total_price'];
  1718. if (isset($performanceMapping[$totalPrice])) {
  1719. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  1720. }
  1721. }
  1722. if($uid <= 611){
  1723. // 计算旗下团队成员的业绩
  1724. $teamOrders = Db::name('user')
  1725. ->alias('u')
  1726. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1727. ->where("u.spread_uid", $uid) // 查询旗下会员
  1728. ->where("so.mer_id", 496)
  1729. // ->where("so.douhuomall", 1)
  1730. // ->where("so.douhuomall_status", 9)
  1731. // ->where("so.status", 0)
  1732. ->select();
  1733. $teamOrders_count = Db::name('user')
  1734. ->alias('u')
  1735. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1736. ->where("u.spread_uid", $uid) // 查询旗下会员
  1737. ->where("so.mer_id", 496)
  1738. // ->where("so.douhuomall", 1)
  1739. // ->where("so.douhuomall_status", 9)
  1740. // ->where("so.status", 0)
  1741. ->count();
  1742. $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
  1743. foreach ($teamOrders as $order) {
  1744. if ($order['total_price']) {
  1745. // 将浮点数转换为整数
  1746. $totalPrice = (int)$order['total_price'];
  1747. if (isset($performanceMapping[$totalPrice])) {
  1748. $performance['team_performance'] += $performanceMapping[$totalPrice];
  1749. }
  1750. }
  1751. }
  1752. // 计算总业绩
  1753. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  1754. // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
  1755. return $performance;
  1756. }
  1757. }
  1758. // 获取大小部门业绩(新表)
  1759. public function getbig_samll_datas($subordinate_members){
  1760. // 单独写一个方法获取大小部门的数据
  1761. $arr_team = [];
  1762. foreach ($subordinate_members as $k => $v) {
  1763. // 计算自己和旗下的业绩
  1764. $arr_team[] = $this->calculatePerformance($v['uid']);
  1765. }
  1766. // 初始化变量
  1767. $maxPerformance = 0;
  1768. $maxIndex = -1;
  1769. // 找出 total_performance 最高的记录
  1770. foreach ($arr_team as $index => $item) {
  1771. if ($item['total_performance'] > $maxPerformance) {
  1772. $maxPerformance = $item['total_performance'];
  1773. $maxIndex = $index;
  1774. }
  1775. }
  1776. // 如果找到了最高记录
  1777. if ($maxIndex !== -1) {
  1778. // 提取最高记录
  1779. $maxRecord = $arr_team[$maxIndex];
  1780. // 从原数组中移除该记录
  1781. unset($arr_team[$maxIndex]);
  1782. // 重新索引数组
  1783. $arr_team = array_values($arr_team);
  1784. } else {
  1785. // 如果没有找到记录,可以设置一个默认值
  1786. $maxRecord = null;
  1787. }
  1788. // 计算大部门和小部门的汇总信息
  1789. $majorDepartmentSummary = [
  1790. "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
  1791. "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
  1792. "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
  1793. "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
  1794. "data" => $maxRecord ? [$maxRecord] : []
  1795. ];
  1796. $minorDepartmentSummary = [
  1797. "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
  1798. "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
  1799. "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
  1800. "team_count" => array_sum(array_column($arr_team, 'team_count')),
  1801. "data" => $arr_team
  1802. ];
  1803. // 输出结果
  1804. // echo "大部门汇总信息:\n";
  1805. // print_r($majorDepartmentSummary);
  1806. // echo "小部门汇总信息:\n";
  1807. // print_r($minorDepartmentSummary);
  1808. return array($majorDepartmentSummary,$minorDepartmentSummary);
  1809. }
  1810. // 计算自己和自己团队下面的业绩。新表
  1811. public function calculatePerformance_copy($uid)
  1812. {
  1813. // 初始化业绩数组
  1814. $performance = [
  1815. 'personal_performance' => 0, // 个人业绩
  1816. 'team_performance' => 0, // 团队业绩
  1817. 'total_performance' => 0, // 总业绩
  1818. 'team_count' =>0, // 加上自己的团队数量
  1819. //'team_count_pr'=>0,//实际团队数量(没有加上自己)
  1820. ];
  1821. // 定义业绩换算规则
  1822. $performanceMapping = [
  1823. 1180 => 700,
  1824. 10620 => 6300,
  1825. 11800 => 7000
  1826. ];
  1827. // 计算个人业绩
  1828. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  1829. if ($personalOrder) {
  1830. // 将浮点数转换为整数
  1831. $totalPrice = (int)$personalOrder['total_price'];
  1832. if (isset($performanceMapping[$totalPrice])) {
  1833. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  1834. }
  1835. }
  1836. // 计算旗下团队成员的业绩
  1837. $teamOrders = Db::name('user')
  1838. ->alias('u')
  1839. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1840. ->where("u.spread_uid", $uid) // 查询旗下会员
  1841. ->where("so.mer_id", 496)
  1842. // ->where("so.douhuomall", 1)
  1843. // ->where("so.douhuomall_status", 9)
  1844. // ->where("so.status", 0)
  1845. ->select();
  1846. $teamOrders_count = Db::name('user')
  1847. ->alias('u')
  1848. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1849. ->where("u.spread_uid", $uid) // 查询旗下会员
  1850. ->where("so.mer_id", 496)
  1851. // ->where("so.douhuomall", 1)
  1852. // ->where("so.douhuomall_status", 9)
  1853. // ->where("so.status", 0)
  1854. ->count();
  1855. $performance['team_count'] = $teamOrders_count+1;// 赋值团队数量
  1856. //$performance['team_count_pr'] = $teamOrders_count;//没有加上父级赋值团队数量
  1857. foreach ($teamOrders as $order) {
  1858. if ($order['total_price']) {
  1859. // 将浮点数转换为整数
  1860. $totalPrice = (int)$order['total_price'];
  1861. if (isset($performanceMapping[$totalPrice])) {
  1862. $performance['team_performance'] += $performanceMapping[$totalPrice];
  1863. }
  1864. }
  1865. }
  1866. // 计算总业绩
  1867. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  1868. return $performance;
  1869. }
  1870. public function team_list_copy旧表使用()
  1871. {
  1872. $teamid = $this->request->uid();
  1873. //$teamid = $this->request->param('teamid');//测试ID
  1874. $teamid = 17;
  1875. $type = $this->request->param('type',0);// 1:大部门,0:小部门,2:直推
  1876. $team_userinfo_old_jbp1= $this->getPerformance($teamid);
  1877. // 判断大小团队(业绩多的是大部门,业绩小的是小部门)
  1878. $tes = $this->teamPeople($teamid,$type);// 1:团队,2:个人
  1879. $data1= [
  1880. "total"=>100,
  1881. "per_page"=> 10,
  1882. "current_page"=> 1,
  1883. "last_page"=> 1,
  1884. ];
  1885. if($type != 2){
  1886. // 小部门和大部门列表数据
  1887. foreach($tes as $k=>$v){
  1888. $curr_pv = '';
  1889. if($v['curr_type']==0){
  1890. $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
  1891. }else if($v['curr_type']==1){
  1892. $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
  1893. }else{
  1894. $curr_pv = 0;
  1895. }
  1896. $data1['data'][$k] = [
  1897. "uid"=>$v["id"],
  1898. "nickname"=> $v['user_name'] . $curr_pv,
  1899. "phone"=> "137****3315",
  1900. "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1901. "create_time"=>"2025-01-25 11:00:18",
  1902. "identity"=>"11",
  1903. "level"=> "40002",
  1904. "partnership"=>"22",
  1905. "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
  1906. "new_performance"=> 0,// 新增业绩
  1907. "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,// 团购人数(加的这个1 是当前用户的数)
  1908. ];
  1909. }
  1910. }else{
  1911. // 直推列表
  1912. foreach($tes as $k=>$v){
  1913. $data1['data'][$k] = [
  1914. "uid"=>$v["uid"],
  1915. "nickname"=> $v['nickname'],
  1916. "avatar"=>$v['avatar'],
  1917. "create_time"=>"2025-01-25 11:00:18",
  1918. ];
  1919. }
  1920. }
  1921. $data['team_list'] = $data1;
  1922. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;// 粉丝数
  1923. $data['new_performance'] = 0;// 新增业绩
  1924. $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];// 总业绩
  1925. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];// 个人联盟
  1926. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];// 共建联盟
  1927. $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);// 公共联盟PV
  1928. $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);// 个人联盟PV
  1929. // $data['effective_fans_num'] = DB::name('enterprise_user')
  1930. // 把新表中的新增邀请用户加到数组中
  1931. return app("json")->success($data);
  1932. }
  1933. /**
  1934. * 一壶茶-团队列表
  1935. */
  1936. public function team_list_copy()
  1937. {
  1938. $uid = $this->request->uid();
  1939. $where['puid'] = $uid;
  1940. $where['mer_id'] = $this->merId;
  1941. $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();// 直属粉丝数量
  1942. // var_dump($uid);
  1943. $arr = $this->jisuan_fans($uid);
  1944. $data['fans_num'] = count($arr);// 粉丝总数
  1945. $data['total_performance'] = 12555;// 总业绩
  1946. $data['new_performance'] = 15;// 新增业绩
  1947. [$page, $limit] = $this->getPage();
  1948. $where2['eu.mer_id'] = $this->merId;
  1949. $type = $this->request->param('type', 0);// 1:大部门,0:小部门
  1950. // var_dump($where2);
  1951. $enterprise_user_team = DB::name('enterprise_user')
  1952. ->alias('eu')
  1953. ->join('user u', 'eu.uid=u.uid')
  1954. ->where($where2)
  1955. ->when($type < 1 || $type == 2, function ($q) use ($arr) {
  1956. $q->whereIn('eu.uid', $arr);
  1957. })
  1958. ->when($type == 1, function ($q) use ($uid) {
  1959. $q->whereIn('eu.puid', $uid);
  1960. })
  1961. ->when($type == 2, function ($q) use ($uid) {
  1962. $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]);
  1963. })
  1964. ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership')
  1965. ->order('eu.enterprise_user_id desc')
  1966. ->paginate($limit)
  1967. ->each(function ($item) {
  1968. $item['phone'] = substr_replace($item['phone'], '****', 3, 4);
  1969. return $item;
  1970. });
  1971. // var_dump($enterprise_user_team);
  1972. $data['team_list'] = $enterprise_user_team;
  1973. $data['effective_fans_num'] = DB::name('enterprise_user')
  1974. ->alias('eu')
  1975. ->join('user u', 'eu.uid=u.uid')
  1976. ->where($where2)
  1977. ->whereIn('eu.uid', $arr)
  1978. ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105])
  1979. ->count();// 有效粉丝数量
  1980. return app("json")->success($data);
  1981. }
  1982. public function team_details()
  1983. {
  1984. $uid = $this->request->param('uid', 0);
  1985. $where2['eu.uid'] = $uid;
  1986. $where2['eu.mer_id'] = $this->merId;
  1987. $enterprise_user_team = DB::name('enterprise_user')
  1988. ->alias('eu')
  1989. ->join('user u', 'eu.uid=u.uid')
  1990. ->where($where2)
  1991. ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid')
  1992. ->find();;
  1993. if ($enterprise_user_team) {
  1994. $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4);
  1995. $enterprise_user_team['p_nickname'] = '';
  1996. $enterprise_user_team['p_phone'] = '';
  1997. $yanglao = 0;
  1998. $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0];
  1999. $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  2000. $yanglao += $offLine1;
  2001. $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  2002. $yanglao += $offLine2;
  2003. $enterprise_user_team['ylj'] = set_price_rtrim($yanglao);
  2004. if ($enterprise_user_team['puid'] > 0) {
  2005. $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find();
  2006. if ($user) {
  2007. $enterprise_user_team['p_nickname'] = $user['nickname'];
  2008. $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4);
  2009. }
  2010. }
  2011. }
  2012. return app("json")->success($enterprise_user_team);
  2013. }
  2014. /**
  2015. * 率积分明细
  2016. */
  2017. public function green_integral_list()
  2018. {
  2019. $pm = $this->request->param('pm');
  2020. $status = $this->request->param('status');
  2021. [$page, $limit] = $this->getPage();
  2022. $uid = $this->request->uid();
  2023. log::info("green_integral_list==={$uid}");
  2024. $where['uid'] = $uid;
  2025. // $where['mer_id'] = $this->merId;
  2026. // if ($pm == 1) {
  2027. // $pm_arr = [1, 3];
  2028. // } else {
  2029. // $pm_arr = [2, 4];
  2030. // }
  2031. if ($pm==0){
  2032. $data = DB::name('user_sign_score')->where($where)->where('pm', 1)->where('status',1)->field('id,mark,reward_socre,pm,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  2033. }
  2034. if($pm==1){
  2035. $data = DB::name('user_sign_score')->where($where)->where('pm', 2)->where('status', 1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  2036. }
  2037. if($pm==2){
  2038. $data = DB::name('user_sign_score')->where($where)->where([['status','in','-1,0']])->field('id,mark,reward_socre,pm,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  2039. if($data){
  2040. $data = $data->toArray();
  2041. foreach ($data as $k=>$v){
  2042. if($v['status'] == 0){
  2043. $data[$k]['mark'] = '(失效)' . $v['mark'];
  2044. }
  2045. }
  2046. }
  2047. }
  2048. return app("json")->success($data);
  2049. }
  2050. public function user_invite_profit_list()
  2051. {
  2052. $uid = $this->request->uid();
  2053. [$page, $limit] = $this->getPage();
  2054. $commission_type = $this->request->param('commission_type', 0);
  2055. if ($commission_type) {
  2056. $where['commission_type'] = $commission_type;
  2057. }
  2058. $month = $this->request->param('month', '') ?: date('Y-m');
  2059. $startMonth = date('Y-m-01 00:00:00', strtotime($month));
  2060. $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month)));
  2061. $data['yanglao_clear_all'] = Db::name('user_bill')
  2062. ->where('uid', $uid)
  2063. ->whereBetween('create_time', [$startMonth, $endMonth])
  2064. ->where('commission_type', 5)
  2065. ->where('pm', 1)
  2066. ->where('status', 1)
  2067. ->sum('number');
  2068. $data['yanglao_nclear_all'] = Db::name('user_bill')
  2069. ->where('uid', $uid)
  2070. ->whereBetween('create_time', [$startMonth, $endMonth])
  2071. ->where('commission_type', 5)
  2072. ->where('pm', 1)
  2073. ->where('status', 0)
  2074. ->sum('number');
  2075. $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all'];
  2076. $where['uid'] = $uid;
  2077. $data['totel_money'] = Db::name('user_bill')->where($where)
  2078. ->whereNotIn('commission_type', [0, 5, 17, 19])
  2079. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  2080. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  2081. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  2082. $query->where('commission_type', '<>', 5)
  2083. ->whereBetween('create_time', [$startMonth, $endMonth]);
  2084. })
  2085. ->sum('number');
  2086. $pageInfo = Db::name('user_bill')
  2087. ->where($where)
  2088. ->whereNotIn('commission_type', [0, 5, 17, 19])
  2089. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  2090. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  2091. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  2092. $query->where('commission_type', '<>', 5)
  2093. ->whereBetween('create_time', [$startMonth, $endMonth]);
  2094. })
  2095. ->order('bill_id desc')
  2096. ->paginate($limit);
  2097. $data_arr = [];
  2098. foreach ($pageInfo->items() as $k => $v) {
  2099. $v['money'] = set_price_rtrim($v['number']);
  2100. $v['order_money'] = set_price_rtrim(0);
  2101. $v['commission_rate'] = set_price_rtrim(0);
  2102. $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find();
  2103. if (!empty($order)) {
  2104. $v['order_money'] = set_price_rtrim($order['total_price']);
  2105. $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2));
  2106. }
  2107. if ($v['status'] == 0) {
  2108. // $v['create_time'] = '--';
  2109. }
  2110. if ($v['status'] == 1) {
  2111. // $v['create_time'] = $v['take_time'];
  2112. }
  2113. if ($v['status'] == -1) {
  2114. $v['mark'] = '(失效)' . $v['mark'];
  2115. // $v['status'] = 0;
  2116. }
  2117. $data_arr[] = $v;
  2118. }
  2119. $data['pageInfo']['current_page'] = $pageInfo->currentPage();
  2120. $data['pageInfo']['data'] = $data_arr;
  2121. $data['pageInfo']['last_page'] = $pageInfo->lastPage();
  2122. return app("json")->success($data);
  2123. }
  2124. /*导航转链-用于用户下单绑定*/
  2125. public function changeLink()
  2126. {
  2127. $uid = $this->request->uid();
  2128. if (!$uid) {
  2129. return app("json")->error("请登录");
  2130. }
  2131. $data = $data = $this->request->params([
  2132. 'url',
  2133. 'name'
  2134. ]);
  2135. $data['url'] = urldecode($data['url']);
  2136. $data['name'] = urldecode($data['name']);
  2137. if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) {
  2138. if ($data['name'] == '京东') {
  2139. $url = app()->make(Jd::class)->linkChange($data['url'], $uid);
  2140. }
  2141. if ($data['name'] == '拼多多') {
  2142. $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid);
  2143. }
  2144. if ($data['name'] == '唯品会') {
  2145. $url = app()->make(Vip::class)->changeLink($data['url'], $uid);
  2146. }
  2147. if ($data['name'] == '苏宁易购') {
  2148. $url = $data['url'];
  2149. //$url = app()->make(Su::class)->changeLink($data['url'],$uid);
  2150. }
  2151. if ($data['name'] == '饿了么') {// 获取饿了么官方活动链接
  2152. // 如果用户没有拉取relation_id,
  2153. $where = ['uid' => $uid, 'type' => 5];
  2154. $isRelation = UserThirdModel::where($where)->find();
  2155. if ($isRelation) {
  2156. $result = DaTaoKe::activityChangeLink('20150318020002597', $uid);
  2157. if ($result['code'] == 0) {
  2158. return \app('json')->fail("获取饿了么链接出错", $result['raw']);
  2159. }
  2160. $url = $result['link'];
  2161. } else {// 如果还没有获取用户的relation_id还需要拉淘宝授权
  2162. $state = "{$uid}_h5";
  2163. $url = \app()->make(TaoBao::class)->getAuthUrl($state);
  2164. }
  2165. }
  2166. }
  2167. return app("json")->success($url);
  2168. }
  2169. /*获取协议*/
  2170. public function xieyi()
  2171. {
  2172. $data = $this->request->params([
  2173. 'type'
  2174. ]);
  2175. $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']);
  2176. return app("json")->success($data);
  2177. }
  2178. /*获取规则文章*/
  2179. public function guize()
  2180. {
  2181. $id = $this->request->param('id');
  2182. $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($id);
  2183. if(!$data){
  2184. $data['title']='';
  2185. $data['content']='';
  2186. }
  2187. $html='<!DOCTYPE html>
  2188. <html lang="en">
  2189. <head>
  2190. <meta charset="UTF-8">
  2191. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2192. <title>'.$data['title'].'</title>
  2193. <style>
  2194. body {
  2195. font-family: Arial, sans-serif;
  2196. margin: 0;
  2197. padding: 0;
  2198. }
  2199. .container {
  2200. margin: 0 auto;
  2201. padding: 20px;
  2202. }
  2203. </style>
  2204. </head>
  2205. <body>
  2206. <div class="container">
  2207. '.$data['content'].'
  2208. </div>
  2209. </body>
  2210. </html';
  2211. return $html;
  2212. }
  2213. /**
  2214. * 支付宝获取授权
  2215. * @return mixed
  2216. * @author php迷途小书童
  2217. * @created 2021/1/16 17:03
  2218. */
  2219. public function alipayAuthorization(UserRepository $userRepository)
  2220. {
  2221. $authorization_code = $this->request->param('code');
  2222. $type = $this->request->param('type', 'h5');
  2223. $paramStr = $userRepository->getTokenByCode($authorization_code, false, $type);
  2224. return app("json")->success($paramStr);
  2225. }
  2226. /**
  2227. * 微信获取授权
  2228. * @return mixed
  2229. * @author php迷途小书童
  2230. * @created 2021/1/16 19:08
  2231. */
  2232. public function wechatAuthorization()
  2233. {
  2234. $request = $this->request;
  2235. $wxConfig = [
  2236. "appid" => "wx66f5f8def2b755da",
  2237. "appsecret" => "891572d83222105a635cf9f502363ff8"
  2238. ];
  2239. $oauth = WechatService::create()->getApplication()->oauth;
  2240. // dump($oauth);
  2241. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  2242. try {
  2243. $wechatInfo = $oauth->user()->getOriginal();
  2244. } catch (\Exception $e) {
  2245. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  2246. }
  2247. if (!isset($wechatInfo['nickname'])) {
  2248. return app('json')->fail('授权失败[002]');
  2249. }
  2250. return app("json")->success($wechatInfo);
  2251. }
  2252. /**
  2253. * 解绑微信 支付宝账号
  2254. * 严格来说 应该给 user_account 加一个的字段来表明生效失效,但增加后 需要调整的模块较多,又不能直接删除(担心直接删除后,出问题没地方查)
  2255. * @param UserRepository $userRepository
  2256. * @return mixed
  2257. */
  2258. public function unbindAccount(UserRepository $userRepository)
  2259. {
  2260. $type = $this->request->param('type');
  2261. $uid = $this->request->uid();
  2262. makeLock()->lock();
  2263. try {
  2264. if ($type == 1) {
  2265. $data = ["wechat_user_id" => 0];
  2266. } else {
  2267. $data = ["ali_user_id" => 0];
  2268. }
  2269. $result = $this->repository->updateUser($uid, $data);
  2270. if (!$result) throw new \Exception("修改失败");
  2271. } catch (\Throwable $e) {
  2272. makeLock()->unlock();
  2273. return app("json")->fail("失败" . $e->getMessage());
  2274. }
  2275. makeLock()->unlock();
  2276. return app("json")->success("解绑成功", $data);
  2277. }
  2278. /**
  2279. * 更新绑定微信支付宝账号
  2280. * type=1 微信 2 支付宝
  2281. * openid openid
  2282. */
  2283. public function updateAccount(UserRepository $userRepository)
  2284. {
  2285. $type = $this->request->param('type');
  2286. $openid = $this->request->param('openid');// 前端传的是unionid
  2287. $nickname = $this->request->param('nickname');
  2288. $avater = $this->request->param('avater');
  2289. $alinfo = $this->request->param('alinfo');
  2290. $uid = $this->request->uid();
  2291. $user = $this->request->userInfo();
  2292. if (!$type) {
  2293. return app("json")->fail("失败");
  2294. }
  2295. makeLock()->lock();
  2296. try {
  2297. if ($type == 1) {
  2298. $data = ["wechat_user_id" => $openid];
  2299. $unionId = $openid;
  2300. $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
  2301. if ($check) throw new \Exception("此微信号已被绑定");
  2302. } else {
  2303. $alinfo = json_decode($alinfo, true);
  2304. if (!$alinfo) throw new \Exception("参数异常");
  2305. $data = ["ali_user_id" => $alinfo["userId"]];
  2306. $unionId = $alinfo["userId"];
  2307. $check = Db::name("user")->where("ali_user_id", $unionId)->find();
  2308. if ($check) throw new \Exception("此支付宝号已被绑定");
  2309. // $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true);
  2310. $paramStr = $userRepository->getTokenByCodeWithCert($alinfo["authCode"], true);
  2311. $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"];
  2312. $avater = empty($paramStr["avatar"]) ? "https://cdn.bjtdba.com/vod/image/2025-01-21/20250121180855764.png" : $paramStr["avatar"];
  2313. }
  2314. $data2 = [
  2315. "type" => $type,
  2316. "uid" => $uid,
  2317. "nickname" => $nickname,
  2318. "avater" => $avater,
  2319. ];
  2320. $result = $this->repository->updateUser($uid, $data, $data2);
  2321. if (!$result) throw new \Exception("修改失败");
  2322. $userRepository = app()->make(UserRepository::class);
  2323. $userInfo = $userRepository->getOne(['uid' => $uid]);
  2324. // 绑定线下充值金额
  2325. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  2326. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2327. $notBind = $unionUsersRepository->getAllNotBind($unionId);
  2328. if ($notBind) {
  2329. $orderMerchantRepository->doBindUser($userInfo, $type);
  2330. }
  2331. } catch (\Throwable $e) {
  2332. makeLock()->unlock();
  2333. return app("json")->fail("失败" . $e->getMessage());
  2334. }
  2335. makeLock()->unlock();
  2336. return app("json")->success("修改成功", $data);
  2337. }
  2338. /**
  2339. * 获取账号绑定信息
  2340. * @return mixed
  2341. */
  2342. public function getAccount()
  2343. {
  2344. $uid = $this->request->uid();
  2345. // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id");
  2346. $data = $this->repository->getAccount($uid);
  2347. if ($data) {
  2348. return app("json")->success("查询成功", $data);
  2349. }
  2350. return app("json")->fail("未绑定");
  2351. }
  2352. // /*
  2353. // * 养老金统计
  2354. // * */
  2355. // public function get_yanglao_statistics()
  2356. // {
  2357. // $uid = $this->request->uid();
  2358. // //线下数量
  2359. // // 查询未结算
  2360. //
  2361. // $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no');
  2362. //
  2363. // $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number');
  2364. // $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension');
  2365. // $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension');
  2366. //
  2367. // $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  2368. // $res = GzcApiRequest::checkAmount($userInfo);
  2369. // $gzc = $res['extendData']['amount'] * 0.01;
  2370. // // PCPC-中信公证处
  2371. // $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc));
  2372. // // 总养老金
  2373. // $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc);
  2374. // // 平台养老金
  2375. // $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao);
  2376. // // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的)
  2377. // $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2));
  2378. // // 已结算养老金 已入账
  2379. // $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2));
  2380. // // 已入账养老金
  2381. // $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2));
  2382. // // 平台未入账养老金
  2383. // $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2));
  2384. // // 待发起
  2385. // $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2));
  2386. //
  2387. // return app("json")->success("查询成功", $data);
  2388. // }
  2389. /*
  2390. * 养老金统计
  2391. * */
  2392. public function get_yanglao_statistics()
  2393. {
  2394. $uid = $this->request->uid();
  2395. // 线下数量
  2396. $offLine = \think\facade\Db::name('order_merchant')->where('uid', $uid)->where('status', 1)->field('pension yanglao')->select()->toArray();
  2397. $data['offLine'] = array(
  2398. 'num' => count($offLine),
  2399. 'yanglao' => round($this->num($offLine, 'yanglao'), 2)
  2400. );
  2401. $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>1,'type_shop'=>0];
  2402. if($this->source=='yhc' && $this->merId){
  2403. $offLinewhere['mer_id']=$this->merId;
  2404. }
  2405. $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  2406. $data['offLine'] = array(
  2407. 'num' => count($offLine),
  2408. 'yanglao' => round($this->num($offLine, 'number'), 2)
  2409. );
  2410. // $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  2411. // $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  2412. // $data['offLine'] = array(
  2413. // 'num' => count($offLine),
  2414. // 'yanglao' => round($this->num($offLine, 'number'), 2)
  2415. // );
  2416. // 线上已确认收货
  2417. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '2,3')->select()
  2418. // ->each(function ($item) {
  2419. // //查询养老金金额
  2420. // $UserBillRepository = app()->make(UserBillRepository::class);
  2421. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  2422. // $pension = $bill->number ?? 0;
  2423. // $item['yanglao'] = $pension;
  2424. // return $item;
  2425. // })
  2426. // ->toArray();
  2427. $onLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  2428. if($this->source=='yhc' && $this->merId){
  2429. $onLinewhere['mer_id']=$this->merId;
  2430. }
  2431. $onLine= \think\facade\Db::name('user_bill')->where($onLinewhere)->select()->toArray();
  2432. $data['onLine'] = array(
  2433. 'num' => count($onLine),
  2434. 'yanglao' => round($this->num($onLine, 'number'), 2)
  2435. );
  2436. // 线上未确认收货
  2437. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '0,1')->select()
  2438. // ->each(function ($item) {
  2439. // //查询养老金金额
  2440. // $UserBillRepository = app()->make(UserBillRepository::class);
  2441. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  2442. // $pension = $bill->number ?? 0;
  2443. // $item['yanglao'] = $pension;
  2444. // return $item;
  2445. // })
  2446. // ->toArray();
  2447. $onLine_take_nowhere=['uid'=>$uid,'status'=>'0','commission_type' => '5','source'=>0,'type_shop'=>0];
  2448. if($this->source=='yhc' && $this->merId){
  2449. $onLine_take_nowhere['mer_id']=$this->merId;
  2450. }
  2451. $onLine_take_no=\think\facade\Db::name('user_bill')->where($onLine_take_nowhere)->select()->toArray();
  2452. $data['onLine_take_no'] = array(
  2453. 'num' => count($onLine_take_no),
  2454. 'yanglao' => round($this->num($onLine_take_no, 'number'), 2)
  2455. );
  2456. if($this->source=='yhc' && $this->merId){
  2457. $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'];
  2458. $data['all_yanglao_yhc'] = set_price_rtrim(round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] , 2));// 总养老金
  2459. $data['all_yanglao_a'] = set_price_rtrim(round($data['offLine']['yanglao'] + $data['onLine']['yanglao'], 2));// 已结算养老金
  2460. $data['all_yanglao_yugu'] = set_price_rtrim(round($data['all_yanglao_yhc']-$data['all_yanglao_a'],2));// 预估养老金
  2461. $userInfo = Db::name('UserCertification') -> where('uid',$uid) -> field('user_name,user_card') -> find();
  2462. $res = GzcApiRequest::checkAmount($userInfo);
  2463. $data['all_gzc']=set_price_rtrim(sprintf("%01.2f", $res['extendData']['amount'] * 0.01));
  2464. $data['all_yanglao']=set_price_rtrim( $data['all_yanglao_yhc'] + $data['all_gzc']);
  2465. return app("json")->success("查询成功", $data);
  2466. }
  2467. // 淘宝
  2468. $tb_a = 0;
  2469. $tb_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>5];
  2470. $tb = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($tb_where)->where('status','<>','-1')->select()->each(function ($value) use (&$tb_a) {
  2471. $value['yanglao'] = 0;
  2472. $value['yanglao'] = $value['number'];
  2473. $value['yanglao_a'] = 0;
  2474. if ($value['status'] == 1) {
  2475. $value['yanglao_a'] = $value['yanglao'];
  2476. $tb_a++;
  2477. }
  2478. return $value;
  2479. })->toArray();
  2480. $data['tb'] = array(
  2481. 'num' => count($tb),
  2482. 'num_a' => $tb_a,
  2483. 'yanglao' => round($this->num($tb, 'yanglao'), 2),
  2484. 'yanglao_a' => round($this->num($tb, 'yanglao_a'), 2),
  2485. );
  2486. // 京东
  2487. $jd_a = 0;
  2488. $jd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>6];
  2489. $jd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($jd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$jd_a) {
  2490. $value['yanglao'] = 0;
  2491. $value['yanglao'] = $value['number'];
  2492. $value['yanglao_a'] = 0;
  2493. if ($value['status'] == 1) {
  2494. $value['yanglao_a'] = $value['yanglao'];
  2495. $jd_a++;
  2496. }
  2497. return $value;
  2498. })->toArray();
  2499. $data['jd'] = array(
  2500. 'num' => count($jd),
  2501. 'num_a' => $jd_a,
  2502. 'yanglao' => round($this->num($jd, 'yanglao'), 2),
  2503. 'yanglao_a' => round($this->num($jd, 'yanglao_a'), 2),
  2504. );
  2505. // 苏宁
  2506. $su_a = 0;
  2507. $su_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>3];
  2508. $su = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($su_where)->where('status','<>','-1')->select()->each(function ($value) use (&$su_a) {
  2509. $value['yanglao'] = 0;
  2510. $value['yanglao'] = $value['number'];
  2511. $value['yanglao_a'] = 0;
  2512. if ($value['status'] == 1) {
  2513. $value['yanglao_a'] = $value['yanglao'];
  2514. $su_a++;
  2515. }
  2516. return $value;
  2517. })->toArray();
  2518. $data['su'] = array(
  2519. 'num' => count($su),
  2520. 'num_a' => $su_a,
  2521. 'yanglao' => round($this->num($su, 'yanglao'), 2),
  2522. 'yanglao_a' => round($this->num($su, 'yanglao_a'), 2),
  2523. );
  2524. // 拼多多
  2525. $pdd_a = 0;
  2526. $pdd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>1];
  2527. $pdd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($pdd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$pdd_a) {
  2528. $value['yanglao'] = 0;
  2529. $value['yanglao'] = $value['number'];
  2530. $value['yanglao_a'] = 0;
  2531. if ($value['status'] == 1) {
  2532. $value['yanglao_a'] = $value['yanglao'];
  2533. $pdd_a++;
  2534. }
  2535. return $value;
  2536. })->toArray();
  2537. $data['pdd'] = array(
  2538. 'num' => count($pdd),
  2539. 'num_a' => $pdd_a,
  2540. 'yanglao' => round($this->num($pdd, 'yanglao'), 2),
  2541. 'yanglao_a' => round($this->num($pdd, 'yanglao_a'), 2),
  2542. );
  2543. // 唯品会
  2544. $vip_a = 0;
  2545. $vip_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>2];
  2546. $vip = \think\facade\Db::name('user_bill')->where($vip_where)->where('uid', $uid)->where('status','<>','-1')->select()->each(function ($value) use (&$vip_a) {
  2547. $value['yanglao'] = 0;
  2548. $value['yanglao'] = $value['number'];
  2549. $value['yanglao_a'] = 0;
  2550. if ($value['status'] == 1) {
  2551. $value['yanglao_a'] = $value['yanglao'];
  2552. $vip_a++;
  2553. }
  2554. return $value;
  2555. })->toArray();
  2556. $data['vip'] = array(
  2557. 'num' => count($vip),
  2558. 'num_a' => $vip_a,
  2559. 'yanglao' => round($this->num($vip, 'yanglao'), 2),
  2560. 'yanglao_a' => round($this->num($vip, 'yanglao_a'), 2),
  2561. );
  2562. // 抖音
  2563. $dy_a = 0;
  2564. $dy_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>9];
  2565. $dy = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($dy_where)->where('status','<>','-1')->select()->each(function ($value) use (&$dy_a) {
  2566. $value['yanglao'] = 0;
  2567. $value['yanglao'] = $value['number'];
  2568. $value['yanglao_a'] = 0;
  2569. if ($value['status'] == 1) {
  2570. $value['yanglao_a'] = $value['yanglao'];
  2571. $dy_a++;
  2572. }
  2573. return $value;
  2574. })->toArray();
  2575. $data['dy'] = array(
  2576. 'num' => count($dy),
  2577. 'num_a' => $dy_a,
  2578. 'yanglao' => round($this->num($dy, 'yanglao'), 2),
  2579. 'yanglao_a' => round($this->num($dy, 'yanglao_a'), 2),
  2580. );
  2581. $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'] + $data['tb']['num'] + $data['jd']['num'] + $data['su']['num'] + $data['pdd']['num'] + $data['vip']['num'] + $data['dy']['num'];
  2582. $data['all_yanglao'] = round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] + $data['tb']['yanglao'] + $data['jd']['yanglao'] + $data['su']['yanglao'] + $data['pdd']['yanglao'] + $data['vip']['yanglao'] + $data['dy']['yanglao'], 2);
  2583. $data['all_yanglao_a'] = round($data['offLine']['yanglao'] + $data['onLine']['yanglao'] + $data['tb']['yanglao_a'] + $data['jd']['yanglao_a'] + $data['su']['yanglao_a'] + $data['pdd']['yanglao_a'] + $data['vip']['yanglao_a'] + $data['dy']['yanglao_a'], 2);
  2584. $data['third_party_num']=['all_num'=>$data['tb']['num']+$data['jd']['num']+$data['su']['num']+ $data['pdd']['num'] + $data['vip']['num']+ $data['dy']['num']];
  2585. $data['third_party_num_a']=['all_num_a'=>$data['tb']['num_a']+$data['jd']['num_a']+$data['su']['num_a']+ $data['pdd']['num_a'] + $data['vip']['num_a']+ $data['dy']['num_a']];
  2586. $data['third_party_num_n']=['all_num_n'=>$data['third_party_num']['all_num']-$data['third_party_num_a']['all_num_a']];
  2587. return app("json")->success("查询成功", $data);
  2588. }
  2589. public function num($data, $field)
  2590. {
  2591. $sum = 0;
  2592. foreach ($data as $item) {
  2593. $sum += $item[$field];
  2594. }
  2595. return $sum;
  2596. }
  2597. // 志愿者升级
  2598. public function changeVolunteer()
  2599. {
  2600. $uid = $this->request->uid();
  2601. // 志愿者条件
  2602. $volunteer_achievement = systemConfig("volunteer_achievement");// volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  2603. $volunteer_class = new Volunteer();
  2604. $volunteer = $volunteer_class->volunteer($uid);
  2605. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  2606. $data['grade'] = 0;
  2607. $data['self_yanglao'] = $volunteer['self_yanglao'];
  2608. $data['condition_one'] = systemConfig("volunteer_achievement");// 用户本人满足养老金要求可升级为志愿者
  2609. return app('json')->success($data);
  2610. }
  2611. $volunteer_class->grade($uid, 1, $volunteer);
  2612. return app('json')->success('申请成功');
  2613. }
  2614. public function GZC($uid)
  2615. {
  2616. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2617. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  2618. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  2619. $where = [
  2620. 'uid' => $uid,
  2621. 'pm' => 1,
  2622. 'status' => 1,
  2623. 'type' => 'commission'
  2624. ];
  2625. $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find();
  2626. $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  2627. $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name');
  2628. $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile');
  2629. $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card');
  2630. Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) {
  2631. $is_implement = 1;
  2632. if ($item['source'] == 0) {
  2633. $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid');
  2634. if ($order_data['uid'] == $item['uid']) {
  2635. $is_implement = 0;
  2636. } else {
  2637. $is_implement = 1;
  2638. }
  2639. } else {
  2640. $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid');
  2641. if ($order_data['uid'] == $item['uid']) {
  2642. $is_implement = 0;
  2643. } else {
  2644. $is_implement = 1;
  2645. }
  2646. }
  2647. if ($is_implement == 1) {
  2648. $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']];
  2649. $create = [
  2650. 'uid' => $online['uid'],
  2651. 'platform_no' => $orderId,
  2652. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  2653. 'user_name' => $certification['user_name'],
  2654. 'mobile' => $certification['mobile'],
  2655. 'user_card' => $certification['user_card'],
  2656. 'pension' => $item['number'],
  2657. 'order_type' => 2,
  2658. 'out_trade_no' => $online['order_sn']
  2659. ];
  2660. $OrderGzcRepository->create($create);
  2661. }
  2662. });
  2663. }
  2664. // 20220712版签到
  2665. public function new_sign()
  2666. {
  2667. // return app('json')->fail('不允许签到');
  2668. $uid = $this->request->uid();// 签到用户
  2669. $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();// 上级用户
  2670. // 第一天签到获得2积分,第二天获得4积分,第三天获得6积分,第四天获得 10 积分,第五天获得 14积分第六天获得 20积分,
  2671. // 连续签到从第七天开始,每日签到获得3积分,第七天连续签到额外奖励 38积分,第 14 天连续签到额外奖励 68 积分,第 21天连续签到额外奖励 128 积分第 30 天连续签到额外奖励 188 积分
  2672. // 前6天积分
  2673. $score = [
  2674. 2,// 1
  2675. 4,// 2
  2676. 6,// 3
  2677. 10,// 4
  2678. 14,// 5
  2679. 20// 6
  2680. ];
  2681. // 7-30天积分
  2682. $scoreS = 3;
  2683. // 额外积分
  2684. $scoreExtra = [
  2685. 7 => 38,
  2686. 14 => 68,
  2687. 21 => 128,
  2688. 30 => 188
  2689. ];
  2690. $today_signintime = strtotime(date('Y-m-d', time()));
  2691. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  2692. if (!empty($today_signin_info)) {
  2693. return app('json')->fail('今天已经签到过了');
  2694. } else {
  2695. // 查询昨天是否已经签到了
  2696. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  2697. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  2698. $has_qian = 1;
  2699. if (!empty($yes_signin_info)) {
  2700. $has_qian = $yes_signin_info['continuity_day'] + 1;
  2701. $has_qian = $has_qian > 30 ? 1 : $has_qian;
  2702. }
  2703. $get_score = 0;
  2704. $get_gw_score = 0;
  2705. if ($has_qian <= 6) {
  2706. $get_score = $score[$has_qian - 1];
  2707. } else {
  2708. $get_score = $scoreS;
  2709. if (isset($scoreExtra[$has_qian])) {
  2710. $get_gw_score = $scoreExtra[$has_qian];
  2711. }
  2712. }
  2713. $userRepository = app()->make(UserRepository::class);
  2714. $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, '', 1, '', 1);
  2715. if($get_gw_score > 0){
  2716. $userRepository->sign_add($uid, $get_gw_score,1,'连续签到赠送额外奖励积分', $has_qian, $today_signintime, '', 1, '', 1);
  2717. }
  2718. // 首次签到
  2719. if ($user['first_sign'] == 0) {
  2720. // //首次签到送30积分,同时赠送邀请人30积分
  2721. // $userRepository->sign_add($uid, 30,1,'首次签到送30积分','','', '', 1, '', 1);
  2722. // $member_info = Db::name('user')->where( array('uid' => $uid) )->find();
  2723. // if($member_info['spread_uid']){
  2724. // $spreadUid = $member_info['spread_uid'];
  2725. // $userRepository->sign_add($spreadUid, 30,1,'邀请人首次签到送30积分','','', '', 1, '', 1);
  2726. // }
  2727. Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]);
  2728. } elseif ($user['first_sign'] == 1 && $has_qian == 1) {
  2729. Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]);
  2730. }
  2731. // //非首次签到,第一天,断签
  2732. // //好友连续签到3天 奖励50
  2733. // //好友连续签到14天 奖励100
  2734. // //好友联系签到30天 奖励300
  2735. // if ($user['first_sign'] < 2) {
  2736. // if ($has_qian == 3) {
  2737. // $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, '');
  2738. // } elseif ($has_qian == 14) {
  2739. // $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, '');
  2740. // } elseif ($has_qian == 30) {
  2741. // $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, '');
  2742. // Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]);
  2743. // }
  2744. // }
  2745. return app('json')->success('签到成功', ['score' => $get_score]);
  2746. }
  2747. }
  2748. public function new_sign_info()
  2749. {
  2750. $uid = $this->request->uid();
  2751. // 查询今天是否已经签到
  2752. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  2753. // 查询昨天是否已经签到了
  2754. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  2755. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  2756. $data = [
  2757. 'today' => 0,
  2758. 'day' => 0
  2759. ];
  2760. if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
  2761. if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0;
  2762. if ($today_signin_info) {
  2763. $data['today'] = 1;
  2764. $data['day'] = $data['day'] + 1;
  2765. }
  2766. return app('json')->success($data);
  2767. }
  2768. /**
  2769. * 积分列表
  2770. * @return mixed
  2771. * @throws \think\db\exception\DataNotFoundException
  2772. * @throws \think\db\exception\DbException
  2773. * @throws \think\db\exception\ModelNotFoundException
  2774. */
  2775. public function sign_list()
  2776. {
  2777. [$page, $limit] = $this->getPage();
  2778. $uid = $this->request->uid();
  2779. $month = $this->request->param('month', '') ?: date('Y-m');
  2780. $status = $this->request->param('status');
  2781. $pm = $this->request->param('pm');
  2782. $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
  2783. $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
  2784. $count = Db::name('user_sign_score')
  2785. ->whereBetween('addtime', [$startMonth, $endMonth])
  2786. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  2787. $query->where('status', $status);
  2788. })
  2789. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  2790. $query->where('pm', $pm);
  2791. })
  2792. ->where('uid', $uid)->count();
  2793. $list = Db::name('user_sign_score')
  2794. ->whereBetween('addtime', [$startMonth, $endMonth])
  2795. ->where('uid', $uid)
  2796. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  2797. $query->where('status', $status);
  2798. })
  2799. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  2800. $query->where('pm', $pm);
  2801. })
  2802. ->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  2803. $item['signin_time'] = date('Y-m-d', $item['signin_time']);
  2804. $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
  2805. if (!empty($item['order_id'])) {
  2806. // 线上订单
  2807. if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') {
  2808. $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn");
  2809. } elseif ($item['order_type'] == 'order_merchant') {
  2810. $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no");
  2811. } elseif ($item['order_type'] == 'extract') {
  2812. $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn");
  2813. } else {
  2814. $item['order_sn'] = '';
  2815. }
  2816. } else {
  2817. $item['order_sn'] = '';
  2818. }
  2819. return $item;
  2820. });
  2821. $data['list'] = $list;
  2822. $data['count'] = $count;
  2823. return app('json')->success($data);
  2824. }
  2825. public function getAmountFromGzc()
  2826. {
  2827. $uid = $this->request->uid();
  2828. $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  2829. $res = GzcApiRequest::checkAmount($userInfo);
  2830. return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]);
  2831. }
  2832. public function check_user_annual_fee()
  2833. {
  2834. // INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user;
  2835. // UPDATE `renrenxiang`.`rrx_user_pension_account` SET `start_time` = '2023-04-07 00:00:00', `end_time` = '2024-04-07 23:59:59', `status` = 1, `give` = 1 WHERE `id` > 0;
  2836. $uid = $this->request->uid();
  2837. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  2838. $data = [
  2839. "status" => 3,// 0:未交年费,1:年费到期。2:未实名认证,3:正常
  2840. ];
  2841. // //未交年费
  2842. // if (!$check || $check["status"] == 0) {
  2843. // $data["status"] = 0;
  2844. // return app('json')->success($data);
  2845. // }
  2846. // //到期时间小于当前时间。年费到期
  2847. // if (strtotime($check['end_time']) < time()){
  2848. // $data["status"] = 1;
  2849. // return app('json')->success($data);
  2850. // }
  2851. // $data["start_time"] = $check['start_time'];
  2852. // $data["end_time"] = $check['end_time'];
  2853. //
  2854. // //检查实名认证
  2855. // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find();
  2856. // if (!$checkCertification){
  2857. // $data["status"] = 2;
  2858. // return app('json')->success($data);
  2859. // }
  2860. return app('json')->success($data);
  2861. }
  2862. /**
  2863. *
  2864. * @remarks 创建年费订单
  2865. * @author 小菜菜
  2866. * @created 2023/04/10 14:37
  2867. */
  2868. public function create_annual_order()
  2869. {
  2870. $uid = $this->request->uid();
  2871. $type = $this->request->param('type', 1);
  2872. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2873. if ($type == 1) $price = "12.00";
  2874. elseif ($type == 2) $price = systemConfig('offline_a');
  2875. elseif ($type == 3) $price = systemConfig('offline_b');
  2876. elseif ($type == 4) $price = systemConfig('offline_c');
  2877. else return app('json')->fail("参数错误");
  2878. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  2879. // 到期时间小于当前时间。年费到期
  2880. if (strtotime($check['end_time']) > time() && $check['status'] == 1) {
  2881. return app('json')->fail("账户已开通,不可重复开通账户");
  2882. }
  2883. $insertData = [
  2884. 'pay_price' => $price,
  2885. 'status' => 0,
  2886. 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"),
  2887. 'uid' => $uid,
  2888. 'type' => $type,
  2889. ];
  2890. $order_id = Db::name('user_pension_account_order')->insertGetId($insertData);
  2891. try {
  2892. return app('json')->success(['order_id' => $order_id]);
  2893. } catch (\Exception $e) {
  2894. return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]);
  2895. }
  2896. }
  2897. /**
  2898. * @remarks 会员支付
  2899. * @author Tang
  2900. * @created 2021/8/27 9:18
  2901. */
  2902. public function pay_user_annual()
  2903. {
  2904. try {
  2905. $oid = r::param('oid', '');
  2906. $code = r::param('code', '');
  2907. $payType = r::param('type', '');// wx.ALI
  2908. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  2909. $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  2910. if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
  2911. $access = new Access();
  2912. $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual");
  2913. Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]);
  2914. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  2915. return app('json')->success($res);
  2916. } catch (\Exception $exception) {
  2917. return app('json')->fail();
  2918. }
  2919. }
  2920. /**
  2921. * @remarks 会员支付 线下
  2922. * @author Tang
  2923. * @created 2021/8/27 9:18
  2924. */
  2925. public function pay_user_annual_offline()
  2926. {
  2927. try {
  2928. $oid = r::param('oid', '');
  2929. $payType = r::param('type', '');// WX.ALI
  2930. $pay_user_id = r::param('pay_user_id', '');// 如果是微信。传open_id 如果是支付宝。传user_id
  2931. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  2932. if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确");
  2933. $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  2934. if (!$order) return app('json')->fail('订单不存在或已支付');
  2935. if ($order['type'] == 1) {
  2936. $title = "开通账户";
  2937. } elseif ($order['type'] == 2) {
  2938. $title = "大礼包1";
  2939. } elseif ($order['type'] == 3) {
  2940. $title = "大礼包2";
  2941. } elseif ($order['type'] == 4) {
  2942. $title = "大礼包3";
  2943. } else {
  2944. return app('json')->fail('订单异常');
  2945. }
  2946. if ($order['type'] > 1) {
  2947. // 本人给养老金10%
  2948. $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));// 10%的养老金
  2949. $commission = 0;
  2950. // 上级给佣金10%
  2951. $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find();
  2952. // 推广员id
  2953. $spread_uid = $order_user["spread_uid"];
  2954. if (!empty($spread_uid)) {
  2955. $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));// 10%的佣金
  2956. }
  2957. $pt = sprintf("%01.2f", 12 + $ylj + $commission);
  2958. $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt);
  2959. } else {
  2960. $pt = "12.00";
  2961. $merchant_money = "0.00";
  2962. }
  2963. if ($payType == 'WX') {
  2964. $pay_wx = systemConfig('pay_wx');
  2965. // 微信
  2966. if ($pay_wx == 3) {
  2967. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id');
  2968. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  2969. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  2970. } else {
  2971. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id');
  2972. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  2973. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  2974. }
  2975. $type = '2';
  2976. $pay_channel = 'wx_pub';
  2977. $expend = [
  2978. 'open_id' => $pay_user_id
  2979. ];
  2980. } elseif ($payType == 'ALI') {
  2981. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id');
  2982. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  2983. $type = '1';
  2984. $pay_channel = 'alipay_pub';
  2985. $expend = [
  2986. 'buyer_id' => $pay_user_id
  2987. ];
  2988. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  2989. }
  2990. if ($merchant_money == '0.00') {
  2991. $div_members = [
  2992. [
  2993. 'member_id' => 0,
  2994. 'amount' => $pt,
  2995. 'fee_flag' => 'Y'
  2996. ]
  2997. ];
  2998. } else {
  2999. $div_members = [
  3000. [
  3001. 'member_id' => $member_id,
  3002. 'amount' => $merchant_money,
  3003. 'fee_flag' => 'Y'
  3004. ],
  3005. [
  3006. 'member_id' => 0,
  3007. 'amount' => $pt,
  3008. 'fee_flag' => 'N'
  3009. ]
  3010. ];
  3011. }
  3012. $params = [
  3013. 'order_no' => $order['order_no'] . '_' . rand(000, 999),
  3014. 'app_id' => $app_id,
  3015. 'pay_channel' => $pay_channel,
  3016. 'pay_amt' => (string)$order['pay_price'],
  3017. 'goods_title' => "幸福宝",
  3018. 'goods_desc' => $title,
  3019. 'device_info' => [
  3020. 'device_ip' => app('request')->ip()
  3021. // 'device_ip'=>'115.171.134.68'
  3022. ],
  3023. 'expend' => json_encode($expend),
  3024. 'div_members' => json_encode($div_members),
  3025. 'fee_mode' => 'I',
  3026. 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual"
  3027. ];
  3028. $res = $this->Payment_create_traits($params, $type, $key);
  3029. if (!empty($res['error_code'])) {
  3030. return app('json')->fail($res['return_msg']);
  3031. } else {
  3032. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  3033. return app('json')->success($res);
  3034. }
  3035. } catch (\Exception $exception) {
  3036. Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']);
  3037. return app('json')->fail();
  3038. }
  3039. }
  3040. public function red_log()
  3041. {
  3042. $uid = $this->request->uid();
  3043. [$page, $limit] = $this->getPage();
  3044. $user_rich_log = Db::name('user_rich_log')->where('uid', $uid)->field('uid,red,pm,time,mark')->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  3045. $item['create_time'] = date('Y-m-d H:i:s', $item['time']);
  3046. $item['red'] = set_price_rtrim($item['red']);
  3047. return $item;
  3048. });
  3049. return app('json')->success($user_rich_log);
  3050. }
  3051. public function apply_bang_fu()
  3052. {
  3053. $uid = $this->request->uid();
  3054. $check = Db::name('user_rich')->where('uid', $uid)->find();
  3055. if ($check['type'] < 3) {
  3056. return app('json')->fail("不满足申请条件");
  3057. }
  3058. $check = Db::name('user_bangfu')->where('uid', $uid)->value('status');
  3059. if ($check == 0) {
  3060. return app('json')->fail("审核中");
  3061. }
  3062. if ($check == 1) {
  3063. return app('json')->fail("已是帮扶中心");
  3064. }
  3065. if ($check == 2) {
  3066. return app('json')->fail("审核被拒绝");
  3067. }
  3068. $bang_fu_number = systemConfig("bang_fu_number");
  3069. // 检测用户是否满足条件
  3070. $number = $this->getNumber($uid, $bang_fu_number) - 1;// 满足条件人数 减去自己
  3071. // 条件
  3072. if ($number >= $bang_fu_number) {
  3073. // echo '满足';
  3074. Db::name('user_bangfu')->insert([
  3075. 'uid' => $uid,
  3076. 'time' => time(),
  3077. 'status' => 0
  3078. ]);
  3079. return app('json')->success("提交申请成功");
  3080. }
  3081. return app('json')->fail("不满足申请条件");
  3082. // echo '不满足';
  3083. }
  3084. // 获得满足 1+5 的下级数量
  3085. public function getNumber($uid, $bang_fu_number): int
  3086. {
  3087. $number = 0;
  3088. $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select();
  3089. $count = count($getUid);
  3090. if ($count >= 5) {
  3091. $number = 1;
  3092. foreach ($getUid as $value) {
  3093. $number += $this->getNumber($value['uid'], $bang_fu_number);
  3094. if ($number >= $bang_fu_number) {
  3095. break;
  3096. }
  3097. }
  3098. }
  3099. return $number;
  3100. }
  3101. /**
  3102. * 积分明细
  3103. * @return mixed
  3104. */
  3105. public function score_info()
  3106. {
  3107. $uid = $this->request->uid();;
  3108. $data['score'] = decimal2(Db::name('user_sign_score')
  3109. ->where('uid', $uid)
  3110. ->where('status', 1)
  3111. ->where('pm', 1)
  3112. ->sum('reward_socre'));;
  3113. $data['no_clear_score'] = decimal2(Db::name('user_sign_score')
  3114. ->where('uid', $uid)
  3115. ->where('status', -1)
  3116. ->where('pm', 1)
  3117. ->sum('reward_socre'));
  3118. $data['lose_score'] = decimal2(Db::name('user_sign_score')
  3119. ->where('uid', $uid)
  3120. ->where('pm', 2)
  3121. ->sum('reward_socre'));
  3122. $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']);
  3123. $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score'];
  3124. $data['score'] = decimal2($data['score']);
  3125. Db::name('user')->where('uid', $uid)->update([
  3126. 'score' => $score
  3127. ]);
  3128. // clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分
  3129. return app('json')->success($data);
  3130. }
  3131. /**
  3132. * 新版我的团队
  3133. */
  3134. public function get_team_list()
  3135. {
  3136. $data = [];
  3137. [$page, $limit] = $this->getPage();
  3138. $uid = $this->request->uid();
  3139. $type = intval($this->request->param('type'));
  3140. // 查询团队列表
  3141. $userRepository = app()->make(UserRepository::class);
  3142. $chilid_userids = $userRepository->getSpreadUidBreak($uid);
  3143. $data['fans_count'] = count($chilid_userids);
  3144. $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid');
  3145. $data['direct_count'] = count($direct_uid_list);
  3146. $valid_uid_list = Db::name('store_order')
  3147. ->whereIn('uid', $chilid_userids)
  3148. ->where('paid', 1)
  3149. ->group('uid')
  3150. ->column('uid');
  3151. $data['valid_count'] = count($valid_uid_list);
  3152. $data['count'] = Db::name('user')
  3153. ->whereIn('uid', $chilid_userids)
  3154. ->count();
  3155. $data['list'] = Db::name('user')
  3156. ->field('uid,phone,nickname,user_group,create_time,avatar as picture')
  3157. ->page($page, $limit)
  3158. ->whereIn('uid', $chilid_userids)
  3159. ->when($type == 1, function ($query) use ($direct_uid_list) {
  3160. return $query->whereIn('uid', $direct_uid_list);
  3161. })
  3162. ->when($type == 2, function ($query) use ($valid_uid_list) {
  3163. return $query->whereIn('uid', $valid_uid_list);
  3164. })
  3165. ->order('uid DESC')
  3166. ->select()
  3167. ->toArray();
  3168. foreach ($data['list'] as &$user) {
  3169. $user ['phone'] = substr_replace($user['phone'], '****', 3, 4);
  3170. }
  3171. return app('json')->success($data);
  3172. }
  3173. /**
  3174. * 我的粉丝详情
  3175. */
  3176. public function get_team_info()
  3177. {
  3178. $uid = $this->request->param('uid', '');
  3179. if (!$uid)
  3180. return app('json')->fail("uid不正确");
  3181. $userRepository = app()->make(UserRepository::class);
  3182. $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid());
  3183. if (!in_array($uid, $chilid_userids))
  3184. return app('json')->fail("该用户不在所属团队内");
  3185. $data = Db::name('user')
  3186. ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address')
  3187. ->where('uid', $uid)
  3188. ->find();
  3189. $data['regimental_commander_count'] = Db::name('user')
  3190. ->where('spread_uid', $uid)
  3191. ->where('user_group', 2)
  3192. ->count();
  3193. $data['clear_order_amount'] = Db::name('store_order')
  3194. ->where('uid', $uid)
  3195. ->where('is_settlement', 1)
  3196. ->sum('pay_price');
  3197. $data['mybuy_order_amount'] = Db::name('store_order')
  3198. ->where('uid', $uid)
  3199. ->where('paid', 1)
  3200. ->sum('pay_price');
  3201. $spread_user = Db::name('user')
  3202. ->field('nickname as spread_nickname,phone as spread_phone')
  3203. ->where('uid', $data['spread_uid'])
  3204. ->find();
  3205. $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4);
  3206. $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? '';
  3207. $data ['phone'] = substr_replace($data['phone'], '****', 3, 4);
  3208. $data = array_merge($data, $spread_user);
  3209. if (in_array($data['user_group'], [5, 6])) {
  3210. $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name');
  3211. $data['area_name'] = join($data['area_name']);
  3212. $data['area_bonus_money'] = Db::name('user_bill')
  3213. ->where('uid', $uid)
  3214. ->sum('number');
  3215. }
  3216. unset($data['manage_address']);
  3217. if (in_array($data['user_group'], [4])) {
  3218. $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find();
  3219. $data['mer_id'] = $merchant['mer_id'] ?? 0;
  3220. $data['mer_name'] = $merchant['mer_name'] ?? '';
  3221. }
  3222. return app('json')->success($data);
  3223. }
  3224. /**
  3225. * 我的佣金
  3226. */
  3227. public function get_brokerage_info()
  3228. {
  3229. $uid = $this->request->uid();
  3230. // 佣金余额
  3231. $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  3232. // 总收益
  3233. $data['sum_amount'] = Db::name('user_bill')
  3234. ->where('uid', $uid)
  3235. ->where('commission_type', '<>', 5)
  3236. ->where('commission_type', '<>', 0)
  3237. ->where('pm', 1)
  3238. ->sum('number');
  3239. // 未结算
  3240. $data['no_clear_amount'] = Db::name('user_bill')
  3241. ->where('uid', $uid)
  3242. ->where('commission_type', '<>', 5)
  3243. ->where('commission_type', '<>', 0)
  3244. ->where('pm', 1)
  3245. ->where('status', 0)
  3246. ->sum('number');
  3247. // 已提现
  3248. $data['withdraw_amount'] = Db::name('user_extract')
  3249. ->where('uid', $uid)
  3250. ->whereIn('status', [0, 1])
  3251. ->sum('extract_price');
  3252. // 转VR
  3253. $data['transition_vr_amount'] = Db::name('user_transition_vr')
  3254. ->where('uid', $uid)
  3255. ->where('type', 1)
  3256. ->sum('number');
  3257. // 最终 总收益是 = 佣金余额 + 已提现 + 已转VR
  3258. // $data['sum_amount'] = $data['sum_amount'] + $data['transition_vr_amount'];
  3259. $data['sum_amount'] = set_price_rtrim($data['sum_amount']);
  3260. return app('json')->success($data);
  3261. }
  3262. public function get_token_by_phone(UserRepository $repository){
  3263. $user = $repository->accountByUser($this->request->param('phone'));
  3264. $tokenInfo = $repository->createToken($user);
  3265. return app('json')->success($repository->returnToken($user, $tokenInfo));
  3266. }
  3267. /**
  3268. * 转VR
  3269. */
  3270. public function transition_vr()
  3271. {
  3272. $uid = $this->request->uid();
  3273. $user = $this->request->userInfo();
  3274. $type = $this->request->param('type', 'brokerage');
  3275. $extract_amount = $this->request->param('extract_amount', 0);
  3276. if ($type == 'brokerage') {
  3277. $brokerage_price = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  3278. // 参考结算任务中的代码片段, 余额中 应不包含未结算余额
  3279. // $no_clear_amount = Db::name('user_bill')
  3280. // ->where('uid', $uid)
  3281. // ->where('commission_type', '<>', 5)
  3282. // ->where('pm', 1)
  3283. // ->where('status', 0)
  3284. // ->sum('number');
  3285. // $clear_amount = $brokerage_price - $no_clear_amount;
  3286. $clear_amount = $brokerage_price;
  3287. // if ($user['brokerage_price'] < (systemConfig('withdrawal_money'))){
  3288. // return app('json')->fail('未到达提现最低额度');
  3289. // }
  3290. if($extract_amount > $clear_amount){
  3291. return app('json')->fail("可用金额不足提现");
  3292. }
  3293. $brokerage_price = bcsub($user['brokerage_price'], $extract_amount,2);
  3294. $user->brokerage_price = $brokerage_price;
  3295. $vr = bcadd($user['vr'], $extract_amount, 2);
  3296. $user->vr = $vr;
  3297. $res = $user->save();
  3298. if ($res){
  3299. // 加入转VR记录
  3300. $insertdata = [
  3301. 'uid'=> $uid,
  3302. 'number' => $extract_amount,
  3303. 'surplus' => $vr,
  3304. 'mark' => '佣金转VR',
  3305. 'type' => 1,
  3306. 'create_time' => time(),
  3307. ];
  3308. Db::name('user_transition_vr')->insertGetId($insertdata);
  3309. // VR入账
  3310. $insertdata = [
  3311. 'uid'=> $uid,
  3312. 'number' => $extract_amount,
  3313. 'surplus' => $vr,
  3314. 'mark' => '佣金转VR',
  3315. 'order_id'=> 0,
  3316. 'type' => 1,
  3317. 'addtime' => time(),
  3318. 'settlement_time'=> date('Y-m-d H:i:s', time())
  3319. ];
  3320. Db::name('user_sign_vr')->insertGetId($insertdata);
  3321. return app('json')->success('转VR成功');
  3322. }else{
  3323. return app('json')->fail('转VR失败');
  3324. }
  3325. }
  3326. if ($type == 'hongbao') {
  3327. $hongbao = Db::name('user')->where('uid', $uid)->value('hongbao');
  3328. $no_clear_amount = Db::name('user_sign_hongbao')
  3329. ->where('uid', $uid)
  3330. ->where('type', 1)
  3331. ->where('status', -1)
  3332. ->sum('number');
  3333. $clear_amount = $hongbao - $no_clear_amount;
  3334. if ($user['hongbao'] < (systemConfig('withdrawal_money'))){
  3335. return app('json')->fail('未到达提现最低额度');
  3336. }
  3337. if($extract_amount > $clear_amount){
  3338. return app('json')->fail("可用金额不足提现");
  3339. }
  3340. $hongbao = bcsub($user['hongbao'], $extract_amount,2);
  3341. $user->hongbao = $hongbao;
  3342. $vr = bcadd($user['vr'], $extract_amount, 2);
  3343. $user->vr = $vr;
  3344. $res = $user->save();
  3345. if ($res){
  3346. // 加入转VR记录
  3347. $insertdata = [
  3348. 'uid'=> $uid,
  3349. 'number' => $extract_amount,
  3350. 'surplus' => $vr,
  3351. 'mark' => '红包转VR',
  3352. 'type' => 2,
  3353. 'status' => 1,
  3354. 'addtime' => time(),
  3355. ];
  3356. Db::name('user_sign_hongbao')->insertGetId($insertdata);
  3357. // VR入账
  3358. $insertdata = [
  3359. 'uid'=> $uid,
  3360. 'number' => $extract_amount,
  3361. 'surplus' => $vr,
  3362. 'mark' => '红包转VR',
  3363. 'order_id'=> 0,
  3364. 'type' => 1,
  3365. 'addtime' => time(),
  3366. 'settlement_time'=> date('Y-m-d H:i:s', time())
  3367. ];
  3368. Db::name('user_sign_vr')->insertGetId($insertdata);
  3369. return app('json')->success('转VR成功');
  3370. }else{
  3371. return app('json')->fail('转VR失败');
  3372. }
  3373. }
  3374. return app('json')->fail('转VR失败');
  3375. }
  3376. /**
  3377. * 转VR记录
  3378. */
  3379. public function transition_vr_log()
  3380. {
  3381. $uid = $this->request->uid();
  3382. $type = $this->request->param('type', 1);
  3383. [$page, $limit] = $this->getPage();
  3384. $where = [];
  3385. $where[] = ['uid', '=', $uid];
  3386. $where[] = ['type', '=', $type];
  3387. $query = Db::name("user_transition_vr");
  3388. $count = $query->where($where)->count();
  3389. $list = $query->page($page, $limit)->where($where)->select()->each(function ($item){
  3390. $item['create_time'] = date("Y-m-d H:i:s", $item['create_time']);
  3391. return $item;
  3392. });
  3393. return app('json')->success('获取转VR记录成功', ['list'=>$list, 'count'=>$count]);
  3394. }
  3395. // 根据父级uid,递归获取所有子级UID数组
  3396. public function getRecursiveChildren($parentUid) {
  3397. $result = []; // 用于存储符合条件的子级 uid
  3398. // 定义递归函数
  3399. $recursion = function ($parentUid) use (&$result, &$recursion) {
  3400. // 查询当前父级的所有直接子级
  3401. $children = Db::name("user")
  3402. ->where("spread_uid", $parentUid)
  3403. ->column("uid"); // 获取子级的 uid 列表
  3404. // 如果没有子级,直接返回
  3405. if (empty($children)) {
  3406. return;
  3407. }
  3408. // 遍历每个子级
  3409. foreach ($children as $childUid) {
  3410. // 如果子级的 uid 小于或等于 611,跳过该子级及其所有子级
  3411. if ($childUid <= 611) {
  3412. continue;
  3413. }
  3414. // 将符合条件的子级 uid 添加到结果数组
  3415. $result[] = $childUid;
  3416. // 递归查询子级的子级
  3417. $recursion($childUid);
  3418. }
  3419. };
  3420. // 从初始父级开始递归查询
  3421. $recursion($parentUid);
  3422. return array_unique($result); // 返回结果数组,并去重
  3423. }
  3424. // 2.0 根据父级uid,找到当前用户下面的UID
  3425. public function getChildren($parentUid) {
  3426. $result = []; // 用于存储所有子级的 uid
  3427. $children = Db::name("user")
  3428. ->where("spread_uid", $parentUid)
  3429. ->column("uid"); // 获取子级的 uid 列表
  3430. return $children; // 返回结果数组,并去重
  3431. }
  3432. public function getNewTeamPv($common_nums) {
  3433. // 初始化结果数组
  3434. $result = [
  3435. 'max_value' => null,
  3436. 'max_uid' => null,
  3437. 'remaining_values' => 0, // 剩余值的总和
  3438. 'remaining_uids' => [] // 剩余值对应的 UID
  3439. ];
  3440. // 递归获取所有子级 UID 的函数
  3441. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3442. $children = Db::name("user")
  3443. ->where("spread_uid", $parentUid)
  3444. ->column("uid");
  3445. $allChildren = [];
  3446. foreach ($children as $childUid) {
  3447. $allChildren[] = $childUid;
  3448. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3449. }
  3450. return $allChildren;
  3451. };
  3452. // 获取每个用户的总业绩,包括子级的业绩
  3453. $userTotalPv = [];
  3454. foreach ($common_nums as $uid) {
  3455. // 获取当前用户及其所有子级的 UID
  3456. $allUids = array_merge([$uid], $getRecursiveChildren($uid));
  3457. // 查询当前用户及其子级的所有订单
  3458. $orders = Db::name("store_order")
  3459. ->whereIn('status', [0, 1, 2, 3])
  3460. ->whereIn("uid", $allUids)
  3461. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3462. ->select();
  3463. // 计算总业绩
  3464. $totalPv = 0;
  3465. foreach ($orders as $order) {
  3466. if ($order['total_price'] == 1180) {
  3467. $totalPv += 700;
  3468. } else if ($order['total_price'] == 11800) {
  3469. $totalPv += 7000;
  3470. } else if ($order['total_price'] == 10620) {
  3471. $totalPv += 6300;
  3472. } else if ($order['total_price'] == 2360) {
  3473. $totalPv += 1400;
  3474. } else if ($order['total_price'] == 9440) {
  3475. $totalPv += 5600;
  3476. }
  3477. }
  3478. // 将当前用户的总业绩和 UID 存入数组
  3479. $userTotalPv[] = ['uid' => $uid, 'totalPv' => $totalPv];
  3480. }
  3481. // 如果没有符合条件的订单,直接返回空数组
  3482. if (empty($userTotalPv)) {
  3483. return [];
  3484. }
  3485. // 找到最大值及其对应的 UID
  3486. usort($userTotalPv, function($a, $b) {
  3487. return $b['totalPv'] <=> $a['totalPv']; // 按 totalPv 降序排序
  3488. });
  3489. // 获取最大值及其 UID
  3490. $result['max_value'] = $userTotalPv[0]['totalPv'];
  3491. $result['max_uid'] = $userTotalPv[0]['uid'];
  3492. // 计算剩余值的总和和对应的 UID
  3493. foreach ($userTotalPv as $index => $user) {
  3494. if ($index > 0) { // 跳过第一个(最大值)
  3495. $result['remaining_values'] += $user['totalPv'];
  3496. $result['remaining_uids'][] = $user['uid'];
  3497. }
  3498. }
  3499. return $result;
  3500. }
  3501. // 只获取数组中的业绩
  3502. public function getteampv($common_nums) {
  3503. // 查询当前用户及其子级的所有订单
  3504. $orders = Db::name("store_order")
  3505. ->whereIn('status', [0, 1, 2, 3])
  3506. ->whereIn("uid", $common_nums)
  3507. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3508. ->select();
  3509. // 初始化业绩和人数
  3510. $totalPv = 0;
  3511. $totalUsers = count($common_nums); // 初始化人数为子级总数
  3512. // 遍历订单计算业绩
  3513. foreach ($orders as $order) {
  3514. if ($order['total_price'] == 1180) {
  3515. $totalPv += 700;
  3516. } else if ($order['total_price'] == 11800) {
  3517. $totalPv += 7000;
  3518. } else if ($order['total_price'] == 10620) {
  3519. $totalPv += 6300;
  3520. } else if ($order['total_price'] == 2360) {
  3521. $totalPv += 1400;
  3522. } else if ($order['total_price'] == 9440) {
  3523. $totalPv += 5600;
  3524. }
  3525. }
  3526. // 返回业绩和人数
  3527. return [
  3528. 'totalPv' => $totalPv,
  3529. 'totalUsers' => $totalUsers
  3530. ];
  3531. }
  3532. // 递归获取所有子级 UID 的业绩
  3533. public function getTeamPv11($parentUid) {
  3534. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3535. $children = Db::name("user")
  3536. ->where("spread_uid", $parentUid)
  3537. ->column("uid");
  3538. $allChildren = [];
  3539. foreach ($children as $childUid) {
  3540. $allChildren[] = $childUid;
  3541. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3542. }
  3543. return $allChildren;
  3544. };
  3545. // 获取当前用户及其所有子级的 UID
  3546. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3547. // 查询当前用户及其子级的所有订单
  3548. $orders = Db::name("store_order")
  3549. ->whereIn('status', [0, 1, 2, 3])
  3550. ->whereIn("uid", $allUids)
  3551. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3552. ->select();
  3553. // 计算总业绩
  3554. $totalPv = 0;
  3555. foreach ($orders as $order) {
  3556. switch ($order['total_price']) {
  3557. case 1180:
  3558. $totalPv += 700;
  3559. break;
  3560. case 11800:
  3561. $totalPv += 7000;
  3562. break;
  3563. case 10620:
  3564. $totalPv += 6300;
  3565. break;
  3566. case 2360:
  3567. $totalPv += 1400;
  3568. break;
  3569. case 9440:
  3570. $totalPv += 5600;
  3571. break;
  3572. }
  3573. }
  3574. return $totalPv;
  3575. }
  3576. // 根据传递的父级数组,返回他的对应子级的个数
  3577. public function getTeamSize($parentUids) {
  3578. // 初始化结果数组
  3579. $result = [];
  3580. // 遍历每个父级ID
  3581. foreach ($parentUids as $parentUid) {
  3582. // 递归获取所有子级 UID
  3583. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3584. $children = Db::name("user")
  3585. ->where("spread_uid", $parentUid)
  3586. ->column("uid");
  3587. // 确保返回的是数组
  3588. if (!is_array($children)) {
  3589. return [];
  3590. }
  3591. $allChildren = [];
  3592. foreach ($children as $childUid) {
  3593. $allChildren[] = $childUid;
  3594. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3595. }
  3596. return $allChildren;
  3597. };
  3598. // 获取当前父级及其所有子级的 UID
  3599. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3600. // 计算总个数(包括父级自身)
  3601. $totalUids = count($allUids);
  3602. // 将结果存入数组
  3603. $result[] = [
  3604. 'parent_uid' => $parentUid,
  3605. 'total_count' => $totalUids
  3606. ];
  3607. }
  3608. return $result;
  3609. }
  3610. public function processArray($array) {
  3611. // 初始化结果数组
  3612. $result = [
  3613. 'max_value' => null, // 最大值
  3614. 'max_index' => null, // 最大值的下标
  3615. 'remaining_sum' => 0 // 剩余值的总和
  3616. ];
  3617. // 检查数组是否为空
  3618. if (empty($array)) {
  3619. return $result;
  3620. }
  3621. // 找出最大值及其下标
  3622. $maxValue = $array[0];
  3623. $maxIndex = 0;
  3624. for ($i = 1; $i < count($array); $i++) {
  3625. if ($array[$i] > $maxValue) {
  3626. $maxValue = $array[$i];
  3627. $maxIndex = $i;
  3628. }
  3629. }
  3630. // 计算剩余值的总和
  3631. $remainingSum = 0;
  3632. for ($i = 0; $i < count($array); $i++) {
  3633. if ($i != $maxIndex) {
  3634. $remainingSum += $array[$i];
  3635. }
  3636. }
  3637. // 将结果存入数组
  3638. $result['max_value'] = $maxValue;
  3639. $result['max_index'] = $maxIndex;
  3640. $result['remaining_sum'] = $remainingSum;
  3641. return $result;
  3642. }
  3643. // 获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  3644. public function getparents_child_pv($user_id){
  3645. // 获取直接下级的 UID 列表
  3646. $get_childs = Db::name("user")
  3647. ->where("spread_uid", $user_id)
  3648. ->column("uid");
  3649. // var_dump($get_childs);
  3650. // 初始化总业绩和总人数
  3651. $total_value = 0;
  3652. $total_count = 0;
  3653. $max_value = 0;
  3654. $max_count = 0;
  3655. // 遍历每个直接下级
  3656. foreach ($get_childs as $child) {
  3657. // echo $child;
  3658. // 获取当前下级及其子级
  3659. $child_group = [$child];
  3660. $recursive_children = $this->getRecursiveChildren($child);
  3661. $child_group = array_merge($child_group, $recursive_children);
  3662. // var_dump($child_group );
  3663. // 获取当前分组的业绩和人数
  3664. $result = $this->getteampv($child_group);
  3665. // var_dump($result);
  3666. $group_pv = $result['totalPv'];
  3667. $group_count = $result['totalUsers'];
  3668. // 累加总业绩和总人数
  3669. $total_value += $group_pv;
  3670. $total_count += $group_count;
  3671. // 更新最大业绩及其对应的人数
  3672. if ($group_pv > $max_value) {
  3673. $max_value = $group_pv;
  3674. $max_count = $group_count;
  3675. }
  3676. }
  3677. // 计算小部门的业绩和人数
  3678. $small_department_value = $total_value - $max_value;
  3679. $small_department_count = $total_count - $max_count;
  3680. // 返回结果
  3681. return [
  3682. 'team_pv' => $max_value,
  3683. 'team_num' => $max_count,
  3684. 'per_pv' => $small_department_value,
  3685. 'per_num' => $small_department_count
  3686. ];
  3687. }
  3688. // 1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
  3689. public function getparents_child_pv11($user_id, $bigamount, $smallamount, $common_nums, $person_nums) {
  3690. // 获取直接下级的 UID 列表
  3691. $get_childs = Db::name("user")
  3692. ->where("spread_uid", $user_id)
  3693. ->column("uid");
  3694. // 初始化变量
  3695. $all_departments = []; // 用于存储所有直属下级的业绩和人数
  3696. // 遍历每个直属下级
  3697. foreach ($get_childs as $child) {
  3698. // 获取当前下级及其子级
  3699. $child_group = [$child];
  3700. $recursive_children = $this->getRecursiveChildren($child);
  3701. $child_group = array_merge($child_group, $recursive_children);
  3702. // 获取当前分组的业绩和人数
  3703. $result = $this->getteampv($child_group);
  3704. // if($user_id == 593){
  3705. // var_dump($result);
  3706. // }
  3707. // 将直属下级的业绩和人数加入数组
  3708. $all_departments[] = [
  3709. 'value' => $result['totalPv'],
  3710. 'count' => $result['totalUsers']
  3711. ];
  3712. }
  3713. // 将传入的 $bigamount 和 $smallamount 以及对应的人数加入数组
  3714. $all_departments[] = [
  3715. 'value' => $bigamount,
  3716. 'count' => $common_nums // 大部门的人数
  3717. ];
  3718. $all_departments[] = [
  3719. 'value' => $smallamount,
  3720. 'count' => $person_nums // 小部门的人数
  3721. ];
  3722. // 初始化最大部门和小部门
  3723. $max_department = null;
  3724. $small_department = [
  3725. 'value' => 0,
  3726. 'count' => 0
  3727. ];
  3728. // 遍历 $all_departments,找出最大值并累加小部门的值
  3729. foreach ($all_departments as $department) {
  3730. if ($max_department === null || $department['value'] > $max_department['value']) {
  3731. // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
  3732. $small_department['value'] += $max_department['value'] ?? 0; // 将旧的最大值累加到小部门
  3733. $small_department['count'] += $max_department['count'] ?? 0;
  3734. $max_department = $department; // 更新最大部门
  3735. } else {
  3736. // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
  3737. $small_department['value'] += $department['value'];
  3738. $small_department['count'] += $department['count'];
  3739. }
  3740. }
  3741. // 返回结果
  3742. return [
  3743. 'big_department' => $max_department,
  3744. 'small_department' => $small_department
  3745. ];
  3746. }
  3747. // 根据父级IDS获取伞下的所有子级ID
  3748. public function getRecursiveChildren_s($parentUid) {
  3749. $result = []; // 用于存储所有子级的 uid
  3750. // 定义递归函数
  3751. $recursion = function ($currentUid) use (&$result, &$recursion) {
  3752. // 查询当前父级的所有直接子级
  3753. $children = Db::name("user")
  3754. ->where("spread_uid", $currentUid)
  3755. ->column("uid"); // 获取子级的 uid 列表
  3756. // 如果没有子级,直接返回
  3757. if (empty($children)) {
  3758. return;
  3759. }
  3760. // 遍历每个子级
  3761. foreach ($children as $childUid) {
  3762. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  3763. $recursion($childUid); // 递归查询子级的子级
  3764. }
  3765. };
  3766. // 从初始父级开始递归查询
  3767. $recursion($parentUid);
  3768. return array_unique($result); // 返回结果数组,并去重
  3769. }
  3770. /**
  3771. * 获取当前用户业绩
  3772. */
  3773. public function userupdates($user_id) {
  3774. //$user_id = 17;
  3775. $children = Db::name("user")
  3776. ->where("spread_uid", $user_id)
  3777. ->select(); // 获取子级的 uid 列表
  3778. $total_pv = 0;
  3779. foreach($children as $k=>$v){
  3780. //$children_pv = Db::name("store_order")->where("uid", $v['uid'])->whereIn("status",[0,1,2,3])->select();
  3781. $children_pv = Db::name("user_sign_gongxian")->where("uid", $v['uid'])->where("status",1)->select();
  3782. foreach($children_pv as $k1=>$v1){
  3783. $total_pv += $v1['number'];
  3784. }
  3785. }
  3786. return $total_pv;
  3787. $userdatas = Db::name("user")->where("uid", $user_id)->find();
  3788. // var_dump($userdatas['user_group']);
  3789. // 如果当前用户是普通消费者的情况下
  3790. if($userdatas['user_group'] == 1){
  3791. if($total_pv != 0){
  3792. if($total_pv >= 1180 && $total_pv < 11800){
  3793. Db::name("user")->where("uid", $user_id)->update(['user_group',2]);
  3794. }
  3795. }
  3796. }
  3797. // 如果当前用户是业务员消费者的情况下
  3798. if($userdatas['user_group'] <= 2){
  3799. if($total_pv != 0){
  3800. if(11800 <= $total_pv){
  3801. Db::name("user")->where("uid", $user_id)->update(['user_group',3]);
  3802. }
  3803. }
  3804. }
  3805. }
  3806. /**
  3807. * 获取当前用户业绩
  3808. */
  3809. public function getPerformance22($user_id) {
  3810. $team_amount = 0;
  3811. $person_amount = 0;
  3812. // $user_id = 17; //598 523 536
  3813. $result_big_team_arr = [];
  3814. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  3815. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3816. $common_nums = $this->getCommonNums($user_id);
  3817. // var_dump( $common_nums);
  3818. $get_teams_comm_num = 0;
  3819. $get_teams_comm_pv = 0;
  3820. $get_teams_per_num = 0;// 小部门人数
  3821. // 1.0系统中有下级,需要在2.0中再加下级数据
  3822. if($user_id < 611){
  3823. // 梅红在2.0中的ID是780
  3824. // 用户三峡所有在2.0系统下面的业绩和人数 start
  3825. $child_nums = [];
  3826. // 获取当前用户
  3827. foreach($common_nums as $v){
  3828. $child_nums[] = $this->getRecursiveChildren($v);
  3829. }
  3830. // var_dump($child_nums);
  3831. // 去除空数组,并重新组合有数据的数组
  3832. $filteredData = array_filter($child_nums, function($array) {
  3833. return !empty($array); // 如果数组不为空,则保留
  3834. });
  3835. // 合并所有非空数组
  3836. foreach ($filteredData as $array) {
  3837. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  3838. }
  3839. // var_dump($result_big_team_arr);
  3840. // 获取当前用户下面在2.0中的下级所有PV
  3841. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  3842. $t_pv = $this->getteampv($result_big_team_arr);
  3843. $get_teams_comm_pv =$t_pv['totalPv'];
  3844. // var_dump($t_pv);echo "ttt";
  3845. // 获取当前用户下面在2.0中的下级所有人数
  3846. $get_teams_comm_num = count($result_big_team_arr);
  3847. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  3848. }else{
  3849. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  3850. $child_nums = $this->getChildren($user_id);
  3851. // 获取父级子级下面的个人
  3852. $num_teams = $this->getTeamSize($child_nums);
  3853. // var_dump($num_teams);
  3854. foreach($child_nums as $v){
  3855. $get_teams_comm_datas[] = $this->getTeamPv11($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  3856. }
  3857. //$s = $this->getparents_child_pv($user_id);
  3858. // var_dump($get_teams_comm_datas);
  3859. // 如果只有一个部门,就是默认大部门
  3860. if( count($get_teams_comm_datas) ==1 ){
  3861. $get_teams_comm_pv =$get_teams_comm_datas[0];
  3862. $get_teams_comm_num = $num_teams[0]['total_count'];
  3863. }else if(count($get_teams_comm_datas) >1){
  3864. // var_dump( $get_teams_comm_datas);
  3865. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  3866. $getss = $this->processArray($get_teams_comm_datas);
  3867. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  3868. unset($num_teams[$getss['max_index']]);
  3869. // 获取小部门的人数
  3870. $per_num = 0;
  3871. foreach($num_teams as $k=>$v){
  3872. $per_num +=$v['total_count'];
  3873. }
  3874. // 找到最大值的(大部门)
  3875. $get_teams_comm_num = $max_value_count;
  3876. // 小部门的数量
  3877. $get_teams_per_num = $per_num;
  3878. // var_dump($getss['max_value']);
  3879. $person_amount = $getss['remaining_sum'];
  3880. $get_teams_comm_pv = $getss['max_value'];
  3881. }
  3882. }
  3883. // var_dump($get_teams_comm_pv);
  3884. // 合并业绩和人数
  3885. $team_amount += $get_teams_comm_pv;
  3886. // var_dump($team_amount);
  3887. // 1.0获取小区业绩
  3888. $person_nums = $this->getPersonageNums($user_id);
  3889. // var_dump($person_nums);
  3890. $result_small_team_arr = [];
  3891. // 1.0系统中有下级,需要在2.0中再加下级数据
  3892. // 用户三峡所有在2.0系统下面的业绩和人数 start
  3893. $child_nums_mix = [];
  3894. // 获取当前用户
  3895. foreach($person_nums as $v){
  3896. $child_nums_mix[] = $this->getRecursiveChildren($v);
  3897. }
  3898. // 去除空数组,并重新组合有数据的数组
  3899. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  3900. return !empty($array); // 如果数组不为空,则保留
  3901. });
  3902. // 合并所有非空数组
  3903. $result_small_team_arr = [];
  3904. foreach ($filteredData_1 as $array) {
  3905. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  3906. }
  3907. // var_dump($result_small_team_arr);
  3908. // 获取当前用户下面在2.0中的下级所有PV
  3909. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  3910. $t_pv = $this->getteampv($result_small_team_arr);
  3911. $get_teams_per_pv =$t_pv['totalPv'];
  3912. // var_dump( $get_teams_per_pv);
  3913. // 获取当前用户下面在2.0中的下级所有人数
  3914. $get_teams_per_num += count($result_small_team_arr);
  3915. // 合并业绩和人数
  3916. $person_amount += $get_teams_per_pv;
  3917. // if($user_id == 593){
  3918. // $person_amount = 2800;
  3919. // }
  3920. // var_dump($person_amount);
  3921. // 用户小部门所有在2.0系统下面的业绩和人数 end
  3922. // var_dump($team_amount);
  3923. // $common_nums[] = $user_id;
  3924. foreach ($common_nums as $key => $value) {
  3925. # code...
  3926. $amount = $this->getPerformance1($value);
  3927. $team_amount += $amount;
  3928. }
  3929. foreach ($person_nums as $key => $value) {
  3930. # code...
  3931. $amount = $this->getPerformance1($value);
  3932. $person_amount += $amount;
  3933. }
  3934. // var_dump($team_amount);
  3935. // var_dump($person_amount);
  3936. //
  3937. // var_dump($team_amount);
  3938. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  3939. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  3940. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3941. $money1180Sum = 0;
  3942. foreach ($user_team_amount as $record) {
  3943. $money1180Sum += $record['money'] - 300 - 180;
  3944. }
  3945. // var_dump($money1180Sum );
  3946. // 获取 status 为 1 且 money 为 11800 的记录集合
  3947. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  3948. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3949. $money11800Sum = 0;
  3950. foreach ($money11800Records as $record) {
  3951. $money11800Sum += $record['money'] - 3000 - 1800;
  3952. }
  3953. // var_dump($money11800Sum );
  3954. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  3955. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3956. $money10620Sum = 0;
  3957. foreach ($money10620Records as $record) {
  3958. $money10620Sum += $record['money'] - 2700 - 1620;
  3959. }
  3960. // var_dump($money10620Sum );
  3961. // 计算除去特定值后的总和
  3962. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  3963. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3964. $otherMoneySum = 0;
  3965. foreach ($otherMoneyRecords as $record) {
  3966. $otherMoneySum += $record['money'];
  3967. }
  3968. // 分别处理特定值的情况并加上其他值的总和
  3969. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3970. // var_dump($all_record_nums);
  3971. $team_amount += $all_record_nums;
  3972. // var_dump($team_amount);
  3973. // 计算自己的个人联盟总流水
  3974. // // //计算自己的个人联盟总流水
  3975. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  3976. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3977. // $person_amount += $user_person_amount;
  3978. // 计算个人的1180单价的业绩 集合
  3979. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  3980. $money1180Sum = 0;
  3981. foreach ($money1180Records as $record) {
  3982. $money1180Sum += $record['money'] - 300 - 180;
  3983. }
  3984. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  3985. // var_dump($person_nums);
  3986. // 计算个人的11800单价的业绩 集合
  3987. $money11800Sum = 0;
  3988. foreach ($money11800Records as $record) {
  3989. $money11800Sum += $record['money'] - 3000 - 1800;
  3990. }
  3991. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  3992. // var_dump($person_nums);
  3993. // 计算个人的10620单价的业绩 集合
  3994. $money10620Sum = 0;
  3995. foreach ($money10620Records as $record) {
  3996. $money10620Sum += $record['money'] - 2700 - 1620;
  3997. }
  3998. // 计算除去特定值后的总和
  3999. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4000. $otherMoneySum = 0;
  4001. foreach ($otherMoneyRecords as $record) {
  4002. $otherMoneySum += $record['money'];
  4003. }
  4004. // 分别处理特定值的情况并加上其他值的总和
  4005. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4006. $person_amount += $user_person_amount;
  4007. // 大部门人数
  4008. $teams_num = count($common_nums) + $get_teams_comm_num;
  4009. // 小部门人数
  4010. $per_num = count($person_nums) + $get_teams_per_num;
  4011. // var_dump($team_amount);
  4012. // var_dump($person_amount);
  4013. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  4014. if($user_id < 611){
  4015. // var_dump($team_amount);
  4016. // var_dump($person_amount);
  4017. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4018. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4019. $b_s = $this->getparents_child_pv11($user_id,$team_amount,$person_amount,count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4020. // var_dump($b_s);
  4021. // var_dump($team_amount,$person_amount);
  4022. // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4023. // var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4024. $team_amount = $b_s['big_department']['value'];
  4025. $teams_num = $b_s['big_department']['count'];
  4026. // var_dump($b_s['team_pv']);
  4027. // var_dump($b_s['per_pv']);
  4028. $person_amount = $b_s['small_department']['value'];
  4029. $per_num = $b_s['small_department']['count'];// 小部门人数
  4030. // var_dump( $b_s['team_num'],$b_s['per_num']);
  4031. }
  4032. // 级别信息
  4033. $userInfo = Db::name("user")->find($user_id);//
  4034. $zk_level = 4;
  4035. $is_zk = false;
  4036. if($userInfo['user_level_id_old'] == $zk_level) {
  4037. $is_zk = true;
  4038. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4039. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4040. } else{
  4041. $sales_incentive = 0;
  4042. }
  4043. $return_data = [
  4044. 'common_nums'=>$teams_num,
  4045. 'person_nums'=>$per_num,
  4046. 'common_nums_pv'=> $team_amount,
  4047. 'person_nums_pv'=> $person_amount,
  4048. 'sum_nums_pv' =>$team_amount + $person_amount,
  4049. 'sales_incentive' => $sales_incentive,
  4050. "is_zk"=>$is_zk
  4051. ];
  4052. return $return_data;
  4053. }
  4054. /**
  4055. * 获取当前用户业绩
  4056. */
  4057. public function getPerformance($user_id) {
  4058. $team_amount = 0;
  4059. $person_amount = 0;
  4060. $result_big_team_arr = [];
  4061. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  4062. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4063. $common_nums = $this->getCommonNums($user_id);
  4064. // var_dump($user_id);
  4065. $get_teams_comm_num = 0;
  4066. $get_teams_comm_pv = 0;
  4067. $get_teams_per_num = 0;// 小部门人数
  4068. // 1.0系统中有下级,需要在2.0中再加下级数据
  4069. if($user_id < 611){
  4070. // 梅红在2.0中的ID是780
  4071. // if($user_id == 593){
  4072. // $common_nums[] = 780;
  4073. // unset($common_nums[0]);
  4074. // }
  4075. // var_dump($common_nums);
  4076. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4077. $child_nums = [];
  4078. // 再加上当前用户直属的子级
  4079. $common_ns = $common_nums;
  4080. $common_ns[] = $user_id;
  4081. // var_dump($common_ns);return;
  4082. // 获取当前用户
  4083. foreach($common_nums as $v){
  4084. $child_nums[] = $this->getRecursiveChildren($v);
  4085. }
  4086. // 梅红在2.0中的ID是780
  4087. // if($user_id == 593){
  4088. // $child_nums[0][] = 780;
  4089. // }
  4090. // 去除空数组,并重新组合有数据的数组
  4091. $filteredData = array_filter($child_nums, function($array) {
  4092. return !empty($array); // 如果数组不为空,则保留
  4093. });
  4094. // 合并所有非空数组
  4095. foreach ($filteredData as $array) {
  4096. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  4097. }
  4098. // var_dump($result_big_team_arr);echo "ppppppppppppppppp";
  4099. // 获取当前用户下面在2.0中的下级所有PV
  4100. $t_pv = $this->getteampv($result_big_team_arr);
  4101. $get_teams_comm_pv =$t_pv['totalPv'];
  4102. // if($user_id == 593){
  4103. // $get_teams_comm_pv = 7000;
  4104. // }
  4105. // var_dump($get_teams_comm_pv);
  4106. // 获取当前用户下面在2.0中的下级所有人数
  4107. $get_teams_comm_num = count($result_big_team_arr);
  4108. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  4109. }else{
  4110. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  4111. $child_nums = $this->getChildren($user_id);
  4112. // 获取父级子级下面的个人
  4113. $num_teams = $this->getTeamSize($child_nums);
  4114. foreach($child_nums as $v){
  4115. $get_teams_comm_datas[] = $this->getTeamPv11($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  4116. }
  4117. if( count($get_teams_comm_datas) ==1 ){
  4118. $get_teams_comm_pv =$get_teams_comm_datas[0];
  4119. $get_teams_comm_num = $num_teams[0]['total_count'];
  4120. }else if(count($get_teams_comm_datas) >1){
  4121. // $getss = $this->processArray($get_teams_comm_datas);
  4122. // $team_datas = $num_teams[$getss['max_index']];
  4123. // var_dump( $get_teams_comm_datas);
  4124. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  4125. $getss = $this->processArray($get_teams_comm_datas);
  4126. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  4127. unset($num_teams[$getss['max_index']]);
  4128. // 获取小部门的人数
  4129. $per_num = 0;
  4130. foreach($num_teams as $k=>$v){
  4131. $per_num +=$v['total_count'];
  4132. }
  4133. // 找到最大值的(大部门)
  4134. $get_teams_comm_num = $max_value_count;
  4135. // 小部门的数量
  4136. $get_teams_per_num = $per_num;
  4137. // var_dump($getss['max_value']);
  4138. $person_amount = $getss['remaining_sum'];
  4139. $get_teams_comm_pv = $getss['max_value'];
  4140. }
  4141. }
  4142. // 合并业绩和人数
  4143. $team_amount += $get_teams_comm_pv;
  4144. // var_dump($team_amount);
  4145. // 1.0获取小区业绩
  4146. $person_nums = $this->getPersonageNums($user_id);
  4147. // var_dump($person_nums);
  4148. $result_small_team_arr = [];
  4149. // 1.0系统中有下级,需要在2.0中再加下级数据
  4150. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4151. $child_nums_mix = [];
  4152. // 再加上当前用户直属的子级
  4153. $common_ns1 = $person_nums;
  4154. $common_ns1[] = $user_id;
  4155. // 获取当前用户
  4156. foreach($person_nums as $v){
  4157. $child_nums_mix[] = $this->getRecursiveChildren($v);
  4158. }
  4159. // 去除空数组,并重新组合有数据的数组
  4160. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  4161. return !empty($array); // 如果数组不为空,则保留
  4162. });
  4163. // 合并所有非空数组
  4164. $result_small_team_arr = [];
  4165. foreach ($filteredData_1 as $array) {
  4166. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  4167. }
  4168. // 获取当前用户下面在2.0中的下级所有PV
  4169. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  4170. $t_pv = $this->getteampv($result_small_team_arr);
  4171. $get_teams_per_pv =$t_pv['totalPv'];
  4172. // 获取当前用户下面在2.0中的下级所有人数
  4173. $get_teams_per_num += count($result_small_team_arr);
  4174. // 合并业绩和人数
  4175. $person_amount += $get_teams_per_pv;
  4176. // if($user_id == 593){
  4177. // $person_amount = 2800;
  4178. // }
  4179. // var_dump($person_amount);
  4180. // 用户小部门所有在2.0系统下面的业绩和人数 end
  4181. // $common_nums[] = $user_id;
  4182. foreach ($common_nums as $key => $value) {
  4183. # code...
  4184. $amount = $this->getPerformance1($value);
  4185. $team_amount += $amount;
  4186. }
  4187. foreach ($person_nums as $key => $value) {
  4188. # code...
  4189. $amount = $this->getPerformance1($value);
  4190. $person_amount += $amount;
  4191. }
  4192. // var_dump($team_amount);
  4193. // if($user_id < 611){
  4194. // //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4195. // //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4196. // $b_s = $this->getparents_child_pv($user_id);
  4197. // //var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4198. // $team_amount += $b_s['team_pv'];
  4199. // $get_teams_comm_num += $b_s['team_num'];
  4200. // $person_amount += $b_s['per_pv'];
  4201. // $get_teams_per_num += $b_s['per_num'];//小部门人数
  4202. // //var_dump($team_amount,$person_amount );
  4203. // }
  4204. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  4205. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  4206. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4207. $money1180Sum = 0;
  4208. foreach ($user_team_amount as $record) {
  4209. $money1180Sum += $record['money'] - 300 - 180;
  4210. }
  4211. if($user_id == 593){
  4212. $money1180Sum -= 700;
  4213. }
  4214. // 获取 status 为 1 且 money 为 11800 的记录集合
  4215. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  4216. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4217. $money11800Sum = 0;
  4218. foreach ($money11800Records as $record) {
  4219. $money11800Sum += $record['money'] - 3000 - 1800;
  4220. }
  4221. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  4222. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4223. $money10620Sum = 0;
  4224. foreach ($money10620Records as $record) {
  4225. $money10620Sum += $record['money'] - 2700 - 1620;
  4226. }
  4227. // 计算除去特定值后的总和
  4228. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  4229. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4230. $otherMoneySum = 0;
  4231. foreach ($otherMoneyRecords as $record) {
  4232. $otherMoneySum += $record['money'];
  4233. }
  4234. // 分别处理特定值的情况并加上其他值的总和
  4235. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4236. // var_dump($all_record_nums);
  4237. $team_amount += $all_record_nums;
  4238. // var_dump($user_team_amount);
  4239. // 计算自己的个人联盟总流水
  4240. // // //计算自己的个人联盟总流水
  4241. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  4242. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4243. // $person_amount += $user_person_amount;
  4244. // 计算个人的1180单价的业绩 集合
  4245. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  4246. $money1180Sum = 0;
  4247. foreach ($money1180Records as $record) {
  4248. $money1180Sum += $record['money'] - 300 - 180;
  4249. }
  4250. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  4251. // var_dump($person_nums);
  4252. // 计算个人的11800单价的业绩 集合
  4253. $money11800Sum = 0;
  4254. foreach ($money11800Records as $record) {
  4255. $money11800Sum += $record['money'] - 3000 - 1800;
  4256. }
  4257. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  4258. // var_dump($person_nums);
  4259. // 计算个人的10620单价的业绩 集合
  4260. $money10620Sum = 0;
  4261. foreach ($money10620Records as $record) {
  4262. $money10620Sum += $record['money'] - 2700 - 1620;
  4263. }
  4264. // 计算除去特定值后的总和
  4265. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4266. $otherMoneySum = 0;
  4267. foreach ($otherMoneyRecords as $record) {
  4268. $otherMoneySum += $record['money'];
  4269. }
  4270. // 分别处理特定值的情况并加上其他值的总和
  4271. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4272. $person_amount += $user_person_amount;
  4273. // //临时设置
  4274. // if($user_id == 536){
  4275. // $person_amount = 2800;
  4276. // $team_amount = 7000;
  4277. // }
  4278. // //临时设置
  4279. // if($user_id == 222){
  4280. // $person_amount = 2800;
  4281. // $team_amount = 11900;
  4282. // }
  4283. // 大部门人数
  4284. $teams_num = count($common_nums) + $get_teams_comm_num;
  4285. // 小部门人数
  4286. $per_num = count($person_nums) + $get_teams_per_num;
  4287. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  4288. if($user_id < 611){
  4289. // var_dump($team_amount);
  4290. // var_dump($person_amount);
  4291. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4292. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4293. $b_s = $this->getparents_child_pv11($user_id,$team_amount,$person_amount,count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4294. // var_dump($b_s);
  4295. // var_dump($team_amount,$person_amount);
  4296. // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4297. // var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4298. $team_amount = $b_s['big_department']['value'];
  4299. $teams_num = $b_s['big_department']['count'];
  4300. // var_dump($b_s['team_pv']);
  4301. // var_dump($b_s['per_pv']);
  4302. $person_amount = $b_s['small_department']['value'];
  4303. $per_num = $b_s['small_department']['count'];// 小部门人数
  4304. // var_dump( $b_s['team_num'],$b_s['per_num']);
  4305. }
  4306. // 级别信息
  4307. $userInfo = Db::name("user")->find($user_id);//
  4308. $zk_level = 4;
  4309. $is_zk = false;
  4310. if($userInfo['user_level_id_old'] == $zk_level) {
  4311. $is_zk = true;
  4312. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4313. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4314. } else{
  4315. $sales_incentive = 0;
  4316. }
  4317. $return_data = [
  4318. 'common_nums' => $teams_num,
  4319. 'person_nums' => $per_num,
  4320. 'common_nums_pv'=> $team_amount,
  4321. 'person_nums_pv'=> $person_amount,
  4322. 'sum_nums_pv' =>$team_amount + $person_amount,
  4323. 'sales_incentive' => $sales_incentive,
  4324. "is_zk"=>$is_zk
  4325. ];
  4326. return $return_data;
  4327. }
  4328. /**
  4329. * 获取当前用户业绩
  4330. */
  4331. public function getPerformance_copy($user_id) {
  4332. // $user_id = $this->request->post("user_id");
  4333. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4334. $common_nums = $this->getCommonNums($user_id);
  4335. // 1.0获取小区业绩
  4336. $person_nums = $this->getPersonageNums($user_id);
  4337. // return $person_nums;
  4338. // var_dump( $common_nums);
  4339. $team_amount = 0;
  4340. $person_amount = 0;
  4341. // $common_nums[] = $user_id;
  4342. foreach ($common_nums as $key => $value) {
  4343. # code...
  4344. $amount = $this->getPerformance1($value);
  4345. $team_amount += $amount;
  4346. }
  4347. foreach ($person_nums as $key => $value) {
  4348. # code...
  4349. $amount = $this->getPerformance1($value);
  4350. $person_amount += $amount;
  4351. }
  4352. // var_dump($team_amount);
  4353. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  4354. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  4355. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4356. $money1180Sum = 0;
  4357. foreach ($user_team_amount as $record) {
  4358. $money1180Sum += $record['money'] - 300 - 180;
  4359. }
  4360. // 获取 status 为 1 且 money 为 11800 的记录集合
  4361. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  4362. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4363. $money11800Sum = 0;
  4364. foreach ($money11800Records as $record) {
  4365. $money11800Sum += $record['money'] - 3000 - 1800;
  4366. }
  4367. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  4368. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4369. $money10620Sum = 0;
  4370. foreach ($money10620Records as $record) {
  4371. $money10620Sum += $record['money'] - 2700 - 1620;
  4372. }
  4373. // 计算除去特定值后的总和
  4374. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  4375. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4376. $otherMoneySum = 0;
  4377. foreach ($otherMoneyRecords as $record) {
  4378. $otherMoneySum += $record['money'];
  4379. }
  4380. // 分别处理特定值的情况并加上其他值的总和
  4381. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4382. // var_dump($all_record_nums);
  4383. $team_amount += $all_record_nums;
  4384. // 计算自己的个人联盟总流水
  4385. // // //计算自己的个人联盟总流水
  4386. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  4387. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4388. // $person_amount += $user_person_amount;
  4389. // 计算个人的1180单价的业绩 集合
  4390. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  4391. $money1180Sum = 0;
  4392. foreach ($money1180Records as $record) {
  4393. $money1180Sum += $record['money'] - 300 - 180;
  4394. }
  4395. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  4396. // var_dump($person_nums);
  4397. // 计算个人的11800单价的业绩 集合
  4398. $money11800Sum = 0;
  4399. foreach ($money11800Records as $record) {
  4400. $money11800Sum += $record['money'] - 3000 - 1800;
  4401. }
  4402. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  4403. // var_dump($person_nums);
  4404. // 计算个人的10620单价的业绩 集合
  4405. $money10620Sum = 0;
  4406. foreach ($money10620Records as $record) {
  4407. $money10620Sum += $record['money'] - 2700 - 1620;
  4408. }
  4409. // 计算除去特定值后的总和
  4410. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4411. $otherMoneySum = 0;
  4412. foreach ($otherMoneyRecords as $record) {
  4413. $otherMoneySum += $record['money'];
  4414. }
  4415. // 分别处理特定值的情况并加上其他值的总和
  4416. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4417. $person_amount += $user_person_amount;
  4418. // 级别信息
  4419. $userInfo = Db::name("user")->find($user_id);//
  4420. $zk_level = 4;
  4421. $is_zk = false;
  4422. if($userInfo['user_level_id_old'] == $zk_level) {
  4423. $is_zk = true;
  4424. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4425. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4426. } else{
  4427. $sales_incentive = 0;
  4428. }
  4429. $return_data = [
  4430. 'common_nums'=>count($common_nums),
  4431. 'person_nums'=>count($person_nums),
  4432. 'common_nums_pv'=> $team_amount,
  4433. 'person_nums_pv'=> $person_amount,
  4434. 'sum_nums_pv' =>$team_amount + $person_amount,
  4435. 'sales_incentive' => $sales_incentive,
  4436. "is_zk"=>$is_zk
  4437. ];
  4438. return $return_data;
  4439. }
  4440. /**
  4441. * 获取指定用户业绩
  4442. */
  4443. public function getPerformanceOf($user_id) {
  4444. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4445. $common_nums = $this->getCommonNums($user_id);
  4446. $person_nums = $this->getPersonageNums($user_id);
  4447. $team_amount = 0;
  4448. $person_amount = 0;
  4449. // $common_nums[] = $user_id;
  4450. foreach ($common_nums as $key => $value) {
  4451. # code...
  4452. $amount = $this->getPerformance1($value);
  4453. $team_amount += $amount;
  4454. }
  4455. foreach ($person_nums as $key => $value) {
  4456. # code...
  4457. $amount = $this->getPerformance1($value);
  4458. $person_amount += $amount;
  4459. }
  4460. // return $person_nums;
  4461. // 添加自己共建联盟的流水
  4462. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("spread_id",$user_id)->sum("money");
  4463. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4464. $team_amount += $user_team_amount;
  4465. // //计算自己的个人联盟总流水
  4466. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("spread_id",$user_id)->sum("money");
  4467. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4468. $person_amount += $user_person_amount;
  4469. $sum_nums_pv = $team_amount + $person_amount;
  4470. $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
  4471. return $sum_nums_pv;
  4472. }
  4473. /**
  4474. * 获取用户星级
  4475. */
  4476. public function getStarLevel($user_id,$team_money=0,$person_money=0) {
  4477. if(empty($team_money)) {
  4478. $common_nums = $this->getCommonNums($user_id);
  4479. $team_money = 0;
  4480. foreach ($common_nums as $key => $value) {
  4481. # code...
  4482. $amount = $this->getPerformance1($value);
  4483. $team_money += $amount;
  4484. }
  4485. // 计算自己的共建联盟流水
  4486. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
  4487. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4488. $team_money += $user_team_amount;
  4489. }else{
  4490. $common_nums = $this->getCommonNums($user_id);
  4491. }
  4492. if(empty($person_money)) {
  4493. $person_nums = $this->getPersonageNums($user_id);
  4494. $person_amount = 0;
  4495. foreach ($person_nums as $key => $value) {
  4496. # code...
  4497. $amount = $this->getPerformance1($value);
  4498. $person_amount += $amount;
  4499. }
  4500. $person_money = $person_amount;
  4501. // 计算自己的个人联盟总流水
  4502. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
  4503. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4504. $person_money += $user_person_amount;
  4505. }else{
  4506. $person_nums = $this->getPersonageNums($user_id);
  4507. }
  4508. $slow = $person_money;
  4509. if($team_money < $person_money) {
  4510. $slow = $team_money;
  4511. }
  4512. $sum_money = $team_money + $person_money;
  4513. // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
  4514. // $this->error(0,$data);
  4515. $star_list = Db::name("old_user_star")->order("statement_all_num desc")->select();
  4516. $start_level = "";
  4517. foreach ($star_list as $key => $value) {
  4518. # code...
  4519. if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) {
  4520. return $value;
  4521. }
  4522. }
  4523. return $start_level;
  4524. }
  4525. /**
  4526. * 获取流水信息
  4527. */
  4528. public function getPerformance1($user_id) {
  4529. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  4530. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  4531. // return $amount;
  4532. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  4533. $money1180Sum = 0;
  4534. foreach ($money1180Records as $record) {
  4535. $money1180Sum += $record['money'] - 300 - 180;
  4536. }
  4537. // var_dump($money1180Sum);
  4538. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  4539. // var_dump($person_nums);
  4540. // 计算个人的11800单价的业绩 集合
  4541. $money11800Sum = 0;
  4542. foreach ($money11800Records as $record) {
  4543. $money11800Sum += $record['money'] - 3000 - 1800;
  4544. }
  4545. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  4546. // var_dump($person_nums);
  4547. // 计算个人的11800单价的业绩 集合
  4548. $money10620Sum = 0;
  4549. foreach ($money10620Records as $record) {
  4550. $money10620Sum += $record['money'] - 2700 - 1620;
  4551. }
  4552. // 计算除去特定值后的总和
  4553. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4554. $otherMoneySum = 0;
  4555. foreach ($otherMoneyRecords as $record) {
  4556. $otherMoneySum += $record['money'];
  4557. }
  4558. // 分别处理特定值的情况并加上其他值的总和
  4559. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4560. return $user_person_amount;
  4561. }
  4562. /**
  4563. * 获取个人业绩统计信息
  4564. */
  4565. public function getPerformanceOfId($user_id)
  4566. {
  4567. // var_dump($user_id);
  4568. // 联盟总人数 共建联盟人数 个人联盟人数 总流水 共建联盟流水 个人联盟流水 所属星级(钻卡专属)
  4569. $common_nums = $this->getCommonNums($user_id);
  4570. $person_nums = $this->getPersonageNums($user_id);
  4571. // 联盟业绩 查询 共建联盟业绩 个人联盟业绩
  4572. $team_amount = 0;
  4573. $person_amount = 0;
  4574. // $common_nums[] = $user_id;
  4575. foreach ($common_nums as $key => $value) {
  4576. # code...
  4577. $amount = $this->getPerformance1($value);
  4578. $team_amount += $amount;
  4579. }
  4580. // 计算自己的共建联盟流水
  4581. //$user_team_amount = Db::name("user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  4582. // $this->error(0,$team_amount);
  4583. //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4584. $money1180Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 1180)->select();
  4585. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4586. $money1180Sum = 0;
  4587. foreach ($money1180Records as $record) {
  4588. $money1180Sum += $record['money'] - 300 - 180;
  4589. }
  4590. // 获取 status 为 1 且 money 为 11800 的记录集合
  4591. $money11800Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 11800)->select();
  4592. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4593. $money11800Sum = 0;
  4594. foreach ($money11800Records as $record) {
  4595. $money11800Sum += $record['money'] - 3000 - 1800;
  4596. }
  4597. // 获取 status 为 1 且 money 为 11800 的记录集合
  4598. $money10620Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 10620)->select();
  4599. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4600. $money10620Sum = 0;
  4601. foreach ($money10620Records as $record) {
  4602. $money10620Sum += $record['money'] - 2700 - 1620;
  4603. }
  4604. // 计算除去特定值后的总和
  4605. $otherMoneyRecords = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->whereNotIn('money', [1180, 11800,10620])->select();
  4606. $otherMoneySum = 0;
  4607. foreach ($otherMoneyRecords as $record) {
  4608. $otherMoneySum += $record['money'];
  4609. }
  4610. // 分别处理特定值的情况并加上其他值的总和
  4611. $user_team_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4612. $team_amount += $user_team_amount;
  4613. foreach ($person_nums as $key => $value) {
  4614. # code...
  4615. $amount = $this->getPerformance1($value);
  4616. $person_amount += $amount;
  4617. }
  4618. // //计算自己的个人联盟总流水
  4619. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  4620. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4621. $person_amount += $user_person_amount;
  4622. // $this->error(0,$common_nums);
  4623. return $team_amount + $person_amount;
  4624. }
  4625. /**
  4626. * 获取该用户共建联盟
  4627. */
  4628. public function getCommonNums($user_id){
  4629. // 先获取共建联盟下用户的id
  4630. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  4631. $new_array_ids =[];
  4632. foreach ($son_ids as $key => $value) {
  4633. # code...
  4634. $son_id = $value['id'];
  4635. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4636. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4637. if(count($son_value_ids) > 0) {
  4638. $son_value_ids = array_column($son_value_ids,"id");
  4639. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4640. }
  4641. }
  4642. return $new_array_ids;
  4643. }
  4644. /**
  4645. * 获取该用户个人联盟
  4646. */
  4647. public function getPersonageNums($user_id){
  4648. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  4649. $new_array_ids =[];
  4650. // return 3343;
  4651. foreach ($son_ids as $key => $value) {
  4652. # code...
  4653. $son_id = $value['id'];
  4654. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4655. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4656. if(count($son_value_ids) > 0) {
  4657. $son_value_ids = array_column($son_value_ids,"id");
  4658. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4659. }
  4660. }
  4661. return $new_array_ids;
  4662. }
  4663. // 获取团队递归聚宝盆1
  4664. public function teamPeople( $user_id,$type){
  4665. // var_dump($type);
  4666. //$ftype = 1:大部门,0:小部门
  4667. // 业绩小是小部门,业绩大是大部门
  4668. if($type == 1) {
  4669. $list = Db::name("old_user_jbp")
  4670. ->where("spread", $user_id)
  4671. ->where("is_team", 1)
  4672. ->field("user_name, id")
  4673. ->select()
  4674. ->toArray();
  4675. $list = $this->get_yj_amount($list,1);
  4676. $list1 = Db::name("old_user_jbp")
  4677. ->where("spread", $user_id)
  4678. ->where("is_team", 0)
  4679. ->field("user_name, id")
  4680. ->select()
  4681. ->toArray();
  4682. $list1 = $this->get_yj_amount($list1, 0);
  4683. // 检查数组和字段是否存在
  4684. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  4685. // 如果$list的值小于或等于$list1的值,选择$list
  4686. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  4687. return $list1;
  4688. } else {
  4689. return $list;
  4690. }
  4691. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  4692. // 如果只有$list有值,返回$list
  4693. return $list;
  4694. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  4695. // 如果只有$list1有值,返回$list1
  4696. return $list1;
  4697. } else {
  4698. // 如果两个数组都没有该字段,返回空数组
  4699. return [];
  4700. }
  4701. }else if($type == 0) {
  4702. $list = Db::name("old_user_jbp")
  4703. ->where("spread", $user_id)
  4704. ->where("is_team", 1)
  4705. ->field("user_name, id")
  4706. ->select()
  4707. ->toArray();
  4708. $list = $this->get_yj_amount($list,1);
  4709. $list1 = Db::name("old_user_jbp")
  4710. ->where("spread", $user_id)
  4711. ->where("is_team", 0)
  4712. ->field("user_name, id")
  4713. ->select()
  4714. ->toArray();
  4715. $list1 = $this->get_yj_amount($list1, 0);
  4716. // 检查数组和字段是否存在
  4717. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  4718. // 如果$list的值小于或等于$list1的值,选择$list
  4719. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  4720. return $list;
  4721. } else {
  4722. return $list1;
  4723. }
  4724. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  4725. // 如果只有$list有值,返回$list
  4726. return $list;
  4727. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  4728. // 如果只有$list1有值,返回$list1
  4729. return $list1;
  4730. } else {
  4731. // 如果两个数组都没有该字段,返回空数组
  4732. return [];
  4733. }
  4734. }else if($type == 2){
  4735. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid,avatar")->select()->toArray();
  4736. return $list;
  4737. }
  4738. // foreach ($list as $key => $value) {
  4739. // $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4740. // $list[$key]['performance'] = $this->getPerformance($value['id']);
  4741. // //辨别当前是大部门还是小部门。用于显示大小业绩展示
  4742. // $list[$key]['curr_type'] = '';
  4743. // if($type == 1){
  4744. // $list[$key]['curr_type'] = 1;
  4745. // }else if($type == 0){
  4746. // $list[$key]['curr_type'] = 0;
  4747. // }else{
  4748. // $list[$key]['curr_type'] = '';
  4749. // }
  4750. // }
  4751. return $list;
  4752. }
  4753. public function get_yj_amount($list,$type){
  4754. foreach ($list as $key => $value) {
  4755. # code...
  4756. // $amount = $this->getPerformanceOfId($value['id']);
  4757. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4758. //$list[$key]['total_performance'] = $amount;
  4759. //$performance = $this->getPerformanceOfId($search_name['id']);
  4760. $list[$key]['performance'] = $this->getPerformance($value['id']);
  4761. // 辨别当前是大部门还是小部门。用于显示大小业绩展示
  4762. $list[$key]['curr_type'] = '';
  4763. if($type == 1){
  4764. $list[$key]['curr_type'] = 1;
  4765. }else if($type == 0){
  4766. $list[$key]['curr_type'] = 0;
  4767. }else{
  4768. $list[$key]['curr_type'] = '';
  4769. }
  4770. }
  4771. return $list;
  4772. }
  4773. // 获取团队递归聚宝盆1
  4774. public function teamPeople_copy( $user_id,$type){
  4775. // var_dump($type);
  4776. //$ftype = 1:大部门,0:小部门
  4777. //$user_id = $this->request->post("user_id");
  4778. //$type = $this->request->post("type",0);
  4779. // 查找当前用户id下节点
  4780. if($type == 1) {
  4781. // echo 33;
  4782. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  4783. }else if($type == 0) {
  4784. // echo 44;
  4785. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  4786. }else if($type == 2){
  4787. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid")->select()->toArray();
  4788. return $list;
  4789. }else {
  4790. // echo 55;
  4791. $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  4792. }
  4793. foreach ($list as $key => $value) {
  4794. # code...
  4795. // $amount = $this->getPerformanceOfId($value['id']);
  4796. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4797. //$list[$key]['total_performance'] = $amount;
  4798. //$performance = $this->getPerformanceOfId($search_name['id']);
  4799. $list[$key]['performance'] = $this->getPerformance($value['id']);
  4800. // 辨别当前是大部门还是小部门。用于显示大小业绩展示
  4801. $list[$key]['curr_type'] = '';
  4802. if($type == 1){
  4803. $list[$key]['curr_type'] = 1;
  4804. }else if($type == 0){
  4805. $list[$key]['curr_type'] = 0;
  4806. }else{
  4807. $list[$key]['curr_type'] = '';
  4808. }
  4809. }
  4810. return $list;
  4811. }
  4812. // //获取团队递归聚宝盆1
  4813. // public function teamPeople( $user_id,$type){
  4814. // //$user_id = $this->request->post("user_id");
  4815. // //$type = $this->request->post("type",0);
  4816. // //查找当前用户id下节点
  4817. // if($type == 1) {
  4818. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  4819. // }else if($type == 2) {
  4820. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  4821. // }else {
  4822. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  4823. // }
  4824. // foreach ($list as $key => $value) {
  4825. // # code...
  4826. // $amount = $this->getPerformanceOfId($value['id']);
  4827. // $list[$key]['user_name'] = $value['user_name'] . "-----业绩" . $amount;
  4828. // }
  4829. // return $list;
  4830. // }
  4831. // 获取大小部门贡献值
  4832. /**
  4833. * 获取当前用户大小部门贡献值
  4834. */
  4835. public function getPerformance_getcon($user_id) {
  4836. $team_amount = 0;
  4837. $person_amount = 0;
  4838. // $user_id = 593; //598 523 536
  4839. $result_big_team_arr = [];
  4840. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  4841. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4842. $common_nums = $this->getCommonNums_getcon($user_id);
  4843. // var_dump($common_nums);
  4844. $get_teams_comm_num = 0;
  4845. $get_teams_comm_pv = 0;
  4846. $get_teams_per_num = 0;// 小部门人数
  4847. // 1.0系统中有下级,需要在2.0中再加下级数据
  4848. if($user_id < 611){
  4849. // 梅红在2.0中的ID是780
  4850. // var_dump( $common_nums);
  4851. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4852. $child_nums = [];
  4853. // 获取当前用户
  4854. foreach($common_nums as $v){
  4855. $child_nums[] = $this->getRecursiveChildren_getcon($v);
  4856. }
  4857. // 去除空数组,并重新组合有数据的数组
  4858. $filteredData = array_filter($child_nums, function($array) {
  4859. return !empty($array); // 如果数组不为空,则保留
  4860. });
  4861. // 合并所有非空数组
  4862. foreach ($filteredData as $array) {
  4863. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  4864. }
  4865. // var_dump($result_big_team_arr);
  4866. // 获取当前用户下面在2.0中的下级所有PV
  4867. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  4868. $t_pv = $this->getteampv_getcon($result_big_team_arr);
  4869. $get_teams_comm_pv = $t_pv;
  4870. // var_dump($get_teams_comm_pv);echo "ttt";
  4871. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  4872. }else{
  4873. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  4874. $child_nums = $this->getChildren_getcon($user_id);
  4875. // 获取父级子级下面的个人
  4876. $num_teams = $this->getTeamSize_getcon($child_nums);
  4877. // var_dump($num_teams);
  4878. foreach($child_nums as $v){
  4879. $get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  4880. }
  4881. //$s = $this->getparents_child_pv($user_id);
  4882. // var_dump($get_teams_comm_datas);
  4883. // 如果只有一个部门,就是默认大部门
  4884. if( count($get_teams_comm_datas) ==1 ){
  4885. $get_teams_comm_pv =$get_teams_comm_datas[0];
  4886. $get_teams_comm_num = $num_teams[0]['total_count'];
  4887. }else if(count($get_teams_comm_datas) >1){
  4888. // var_dump( $get_teams_comm_datas);
  4889. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  4890. $getss = $this->processArray_getcon($get_teams_comm_datas);
  4891. // var_dump($getss);
  4892. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  4893. unset($num_teams[$getss['max_index']]);
  4894. // 获取小部门的人数
  4895. $per_num = 0;
  4896. foreach($num_teams as $k=>$v){
  4897. $per_num +=$v['total_count'];
  4898. }
  4899. // 找到最大值的(大部门)
  4900. //$get_teams_comm_num = $max_value_count;
  4901. // 小部门的数量
  4902. // $get_teams_per_num = $per_num;
  4903. // var_dump($getss['max_value']);
  4904. $person_amount = $getss['remaining_sum'];
  4905. $get_teams_comm_pv = $getss['max_value'];
  4906. }
  4907. }
  4908. // var_dump($get_teams_comm_pv);
  4909. // 合并业绩和人数
  4910. $team_amount += $get_teams_comm_pv;
  4911. // var_dump($team_amount);
  4912. // 1.0获取小区业绩
  4913. $person_nums = $this->getPersonageNums_getcon($user_id);
  4914. // var_dump($person_nums);
  4915. $result_small_team_arr = [];
  4916. // 1.0系统中有下级,需要在2.0中再加下级数据
  4917. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4918. $child_nums_mix = [];
  4919. // 获取当前用户
  4920. foreach($person_nums as $v){
  4921. $child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
  4922. }
  4923. // 去除空数组,并重新组合有数据的数组
  4924. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  4925. return !empty($array); // 如果数组不为空,则保留
  4926. });
  4927. // 合并所有非空数组
  4928. $result_small_team_arr = [];
  4929. foreach ($filteredData_1 as $array) {
  4930. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  4931. }
  4932. // var_dump($result_small_team_arr);
  4933. // 获取当前用户下面在2.0中的下级所有PV
  4934. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  4935. $t_pv = $this->getteampv_getcon($result_small_team_arr);
  4936. $get_teams_per_pv =$t_pv;
  4937. // var_dump( $get_teams_per_pv);
  4938. // 获取当前用户下面在2.0中的下级所有人数
  4939. // $get_teams_per_num += count($result_small_team_arr);
  4940. // 合并业绩和人数
  4941. $person_amount += $get_teams_per_pv;
  4942. // 当前会员直属的业绩(1.0大部门)
  4943. $t_pv = $this->getteampv_getcon($common_nums);
  4944. $team_amount += $t_pv;
  4945. // 当前会员直属的业绩(1.0大部门)
  4946. $p_pv = $this->getteampv_getcon($person_nums);
  4947. $person_amount += $p_pv;
  4948. // var_dump($team_amount,$person_amount);
  4949. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  4950. if($user_id < 611){
  4951. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4952. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4953. $b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
  4954. $team_amount = $b_s[0];
  4955. $person_amount = $b_s[1];
  4956. }
  4957. $return_data = [
  4958. 'common_nums_pv'=> $team_amount,
  4959. 'person_nums_pv'=> $person_amount,
  4960. ];
  4961. return $return_data;
  4962. }
  4963. /**
  4964. * 获取该用户共建联盟
  4965. */
  4966. public function getCommonNums_getcon($user_id){
  4967. // 先获取共建联盟下用户的id
  4968. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  4969. $new_array_ids =[];
  4970. foreach ($son_ids as $key => $value) {
  4971. # code...
  4972. $son_id = $value['id'];
  4973. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4974. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4975. if(count($son_value_ids) > 0) {
  4976. $son_value_ids = array_column($son_value_ids,"id");
  4977. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4978. }
  4979. }
  4980. return $new_array_ids;
  4981. }
  4982. /**
  4983. * 获取该用户个人联盟
  4984. */
  4985. public function getPersonageNums_getcon($user_id){
  4986. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  4987. $new_array_ids =[];
  4988. // return 3343;
  4989. foreach ($son_ids as $key => $value) {
  4990. # code...
  4991. $son_id = $value['id'];
  4992. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4993. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4994. if(count($son_value_ids) > 0) {
  4995. $son_value_ids = array_column($son_value_ids,"id");
  4996. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4997. }
  4998. }
  4999. return $new_array_ids;
  5000. }
  5001. // 根据父级uid,递归获取所有子级UID数组
  5002. public function getRecursiveChildren_getcon($parentUid) {
  5003. $result = []; // 用于存储所有子级的 uid
  5004. // 定义递归函数
  5005. $recursion = function ($parentUid) use (&$result, &$recursion) {
  5006. // 查询当前父级的所有直接子级
  5007. $children = Db::name("user")
  5008. ->where("spread_uid", $parentUid)
  5009. ->column("uid"); // 获取子级的 uid 列表
  5010. // 如果没有子级,直接返回
  5011. if (empty($children)) {
  5012. return;
  5013. }
  5014. // 遍历每个子级
  5015. foreach ($children as $childUid) {
  5016. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  5017. $recursion($childUid); // 递归查询子级的子级
  5018. }
  5019. };
  5020. // 从初始父级开始递归查询
  5021. $recursion($parentUid);
  5022. return array_unique($result); // 返回结果数组,并去重
  5023. }
  5024. // 只获取数组中的业绩
  5025. public function getteampv_getcon($common_nums) {
  5026. // // 查询当前用户及其子级的所有订单
  5027. $orders_gongxian = Db::name("user_sign_gongxian")
  5028. ->whereIn('status', [1])
  5029. ->whereIn("uid", $common_nums)
  5030. ->select();
  5031. // var_dump( $common_nums);
  5032. $total_gongxian = 0;
  5033. // // 遍历订单计算业绩
  5034. foreach ($orders_gongxian as $order) {
  5035. if (strpos($order['mark'], "购买") !== false) {
  5036. $total_gongxian += $order['number'];
  5037. }
  5038. }
  5039. return $total_gongxian;
  5040. // // // 查询当前用户及其子级的所有订单
  5041. // $orders = Db::name("store_order")
  5042. // ->whereIn('status', [0, 1, 2, 3])
  5043. // ->whereIn("uid", $common_nums)
  5044. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  5045. // ->select();
  5046. // // 初始化业绩和人数
  5047. // $totalPv = 0;
  5048. // $totalUsers = count($common_nums); // 初始化人数为子级总数
  5049. // // 遍历订单计算业绩
  5050. // foreach ($orders as $order) {
  5051. // if ($order['total_price'] == 1180) {
  5052. // $totalPv += 700;
  5053. // } else if ($order['total_price'] == 11800) {
  5054. // $totalPv += 7000;
  5055. // } else if ($order['total_price'] == 10620) {
  5056. // $totalPv += 6300;
  5057. // } else if ($order['total_price'] == 2360) {
  5058. // $totalPv += 1400;
  5059. // } else if ($order['total_price'] == 9440) {
  5060. // $totalPv += 5600;
  5061. // }
  5062. // }
  5063. // // 返回业绩和人数
  5064. // return [
  5065. // 'totalPv' => $totalPv,
  5066. // 'totalUsers' => $totalUsers
  5067. // ];
  5068. }
  5069. // 2.0 根据父级uid,找到当前用户下面的UID
  5070. public function getChildren_getcon($parentUid) {
  5071. $result = []; // 用于存储所有子级的 uid
  5072. $children = Db::name("user")
  5073. ->where("spread_uid", $parentUid)
  5074. ->column("uid"); // 获取子级的 uid 列表
  5075. return $children; // 返回结果数组,并去重
  5076. }
  5077. // 递归获取所有子级 UID 的业绩
  5078. public function getTeamPv11_getcon($parentUid) {
  5079. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  5080. $children = Db::name("user")
  5081. ->where("spread_uid", $parentUid)
  5082. ->column("uid");
  5083. $allChildren = [];
  5084. foreach ($children as $childUid) {
  5085. $allChildren[] = $childUid;
  5086. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  5087. }
  5088. return $allChildren;
  5089. };
  5090. // 获取当前用户及其所有子级的 UID
  5091. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  5092. $orders_gongxian = Db::name("user_sign_gongxian")
  5093. ->whereIn('status', [1])
  5094. ->whereIn("uid", $allUids)
  5095. ->select();
  5096. $total_gongxian = 0;
  5097. // // 遍历订单计算业绩
  5098. foreach ($orders_gongxian as $order) {
  5099. if (strpos($order['mark'], "购买") !== false) {
  5100. $total_gongxian += $order['number'];
  5101. }
  5102. }
  5103. return $total_gongxian;
  5104. // // 查询当前用户及其子级的所有订单
  5105. // $orders = Db::name("store_order")
  5106. // ->whereIn('status', [0, 1, 2, 3])
  5107. // ->whereIn("uid", $allUids)
  5108. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  5109. // ->select();
  5110. // // 计算总业绩
  5111. // $totalPv = 0;
  5112. // foreach ($orders as $order) {
  5113. // switch ($order['total_price']) {
  5114. // case 1180:
  5115. // $totalPv += 700;
  5116. // break;
  5117. // case 11800:
  5118. // $totalPv += 7000;
  5119. // break;
  5120. // case 10620:
  5121. // $totalPv += 6300;
  5122. // break;
  5123. // case 2360:
  5124. // $totalPv += 1400;
  5125. // break;
  5126. // case 9440:
  5127. // $totalPv += 5600;
  5128. // break;
  5129. // }
  5130. // }
  5131. // return $totalPv;
  5132. }
  5133. // 根据传递的父级数组,返回他的对应子级的个数
  5134. public function getTeamSize_getcon($parentUids) {
  5135. // 初始化结果数组
  5136. $result = [];
  5137. // 遍历每个父级ID
  5138. foreach ($parentUids as $parentUid) {
  5139. // 递归获取所有子级 UID
  5140. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  5141. $children = Db::name("user")
  5142. ->where("spread_uid", $parentUid)
  5143. ->column("uid");
  5144. // 确保返回的是数组
  5145. if (!is_array($children)) {
  5146. return [];
  5147. }
  5148. $allChildren = [];
  5149. foreach ($children as $childUid) {
  5150. $allChildren[] = $childUid;
  5151. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  5152. }
  5153. return $allChildren;
  5154. };
  5155. // 获取当前父级及其所有子级的 UID
  5156. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  5157. // 计算总个数(包括父级自身)
  5158. $totalUids = count($allUids);
  5159. // 将结果存入数组
  5160. $result[] = [
  5161. 'parent_uid' => $parentUid,
  5162. 'total_count' => $totalUids
  5163. ];
  5164. }
  5165. return $result;
  5166. }
  5167. public function processArray_getcon($array) {
  5168. // 初始化结果数组
  5169. $result = [
  5170. 'max_value' => null, // 最大值
  5171. 'max_index' => null, // 最大值的下标
  5172. 'remaining_sum' => 0 // 剩余值的总和
  5173. ];
  5174. // 检查数组是否为空
  5175. if (empty($array)) {
  5176. return $result;
  5177. }
  5178. // 找出最大值及其下标
  5179. $maxValue = $array[0];
  5180. $maxIndex = 0;
  5181. for ($i = 1; $i < count($array); $i++) {
  5182. if ($array[$i] > $maxValue) {
  5183. $maxValue = $array[$i];
  5184. $maxIndex = $i;
  5185. }
  5186. }
  5187. // 计算剩余值的总和
  5188. $remainingSum = 0;
  5189. for ($i = 0; $i < count($array); $i++) {
  5190. if ($i != $maxIndex) {
  5191. $remainingSum += $array[$i];
  5192. }
  5193. }
  5194. // 将结果存入数组
  5195. $result['max_value'] = $maxValue;
  5196. $result['max_index'] = $maxIndex;
  5197. $result['remaining_sum'] = $remainingSum;
  5198. return $result;
  5199. }
  5200. /**
  5201. * 获取流水信息
  5202. */
  5203. public function getPerformance1_getcon($user_id) {
  5204. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  5205. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  5206. // return $amount;
  5207. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  5208. $money1180Sum = 0;
  5209. foreach ($money1180Records as $record) {
  5210. $money1180Sum += $record['money'] - 300 - 180;
  5211. }
  5212. // var_dump($money1180Sum);
  5213. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  5214. // var_dump($person_nums);
  5215. // 计算个人的11800单价的业绩 集合
  5216. $money11800Sum = 0;
  5217. foreach ($money11800Records as $record) {
  5218. $money11800Sum += $record['money'] - 3000 - 1800;
  5219. }
  5220. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  5221. // var_dump($person_nums);
  5222. // 计算个人的11800单价的业绩 集合
  5223. $money10620Sum = 0;
  5224. foreach ($money10620Records as $record) {
  5225. $money10620Sum += $record['money'] - 2700 - 1620;
  5226. }
  5227. // 计算除去特定值后的总和
  5228. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  5229. $otherMoneySum = 0;
  5230. foreach ($otherMoneyRecords as $record) {
  5231. $otherMoneySum += $record['money'];
  5232. }
  5233. // 分别处理特定值的情况并加上其他值的总和
  5234. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  5235. return $user_person_amount;
  5236. }
  5237. // 1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
  5238. public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
  5239. // 获取直接下级的 UID 列表
  5240. $get_childs = Db::name("user")
  5241. ->where("spread_uid", $user_id)
  5242. ->column("uid");
  5243. // 初始化变量
  5244. $all_departments = []; // 用于存储所有直属下级的业绩
  5245. // 遍历每个直属下级
  5246. foreach ($get_childs as $child) {
  5247. // 获取当前下级及其子级
  5248. $child_group = [$child];
  5249. $recursive_children = $this->getRecursiveChildren_getcon($child);
  5250. $child_group = array_merge($child_group, $recursive_children);
  5251. // 获取当前分组的业绩
  5252. $result = $this->getteampv_getcon($child_group);
  5253. // 将直属下级的业绩加入数组
  5254. $all_departments[] = $result;
  5255. }
  5256. // 将传入的 $bigamount 和 $smallamount 加入数组
  5257. $all_departments[] = $bigamount;
  5258. $all_departments[] = $smallamount;
  5259. // 检查是否所有业绩都是 0
  5260. if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
  5261. return [0, 0];
  5262. }
  5263. // 初始化最大部门和小部门
  5264. $max_department = 0;
  5265. $small_department = 0;
  5266. // 遍历 $all_departments,找出最大值并累加小部门的值
  5267. foreach ($all_departments as $department) {
  5268. if ($department > $max_department) {
  5269. // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
  5270. if ($max_department != 0) {
  5271. $small_department += $max_department; // 将旧的最大值累加到小部门
  5272. }
  5273. $max_department = $department; // 更新最大部门
  5274. } else {
  5275. // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
  5276. $small_department += $department;
  5277. }
  5278. }
  5279. // 返回结果
  5280. return [
  5281. $max_department, // 大部门业绩
  5282. $small_department // 小部门业绩
  5283. ];
  5284. // 拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
  5285. // 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
  5286. }
  5287. // 获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  5288. public function getparents_child_pv_getcon($user_id){
  5289. // 获取直接下级的 UID 列表
  5290. //$user_id = 593;
  5291. // $get_childs = $this->getRecursiveChildren($user_id);
  5292. $get_childs = Db::name("user")
  5293. ->where("spread_uid", $user_id)
  5294. ->column("uid"); // 获取子级的 uid 列表
  5295. // 根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
  5296. // 获取直接下级
  5297. $children_group = []; // 用于存储每个直接下级及其子级的分组
  5298. // 遍历每个直接下级
  5299. foreach ($get_childs as $child) {
  5300. $child_group = [$child]; // 将直接下级加入分组
  5301. $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
  5302. $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
  5303. $children_group[] = $child_group; // 将分组加入最终结果
  5304. }
  5305. $get_teams_comm_datas = [];
  5306. foreach($children_group as $v){
  5307. $get_teams_comm_datas[] = $this->getteampv($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  5308. }
  5309. if(count($get_teams_comm_datas) > 0){
  5310. // 找到最大值作为大部门
  5311. $max_value = max($get_teams_comm_datas);
  5312. $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
  5313. // 小部门为总和减去最大值
  5314. $small_department = $total_sum - $max_value;
  5315. // 返回大部门和小部门
  5316. return [
  5317. $max_value,
  5318. $small_department
  5319. ];
  5320. }else{
  5321. return [
  5322. 0,
  5323. 0
  5324. ];
  5325. }
  5326. }
  5327. /**
  5328. * 解绑微信或支付宝
  5329. * @return void
  5330. */
  5331. public function unBindVxOrAli()
  5332. {
  5333. $uid = $this->request->uid();
  5334. $type = request()->param('type','');
  5335. if(!$type) return app('json')->fail('请选择解绑类型');
  5336. if(!$uid) return app('json')->fail('请登录');
  5337. // 1 = 微信 2 = 支付宝 3 = 全部
  5338. if($type == 1){
  5339. Db::name('user')->where('uid',$uid)->update(['wechat_user_id' => 0]);
  5340. }else if ($type == 2){
  5341. Db::name('user')->where('uid',$uid)->update(['ali_user_id' => 0]);
  5342. }else{
  5343. Db::name('user')->where('uid',$uid)->update(['wechat_user_id' => 0,'ali_user_id' => 0]);
  5344. }
  5345. Db::name('log')->insert(['data' => '用户uid:' . $uid . '进行解绑操作type类型为' . $type]);
  5346. return app('json')->success('解绑成功');
  5347. }
  5348. }