User.php 238 KB

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