User.php 244 KB

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