User.php 232 KB

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