User.php 244 KB

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