User.php 233 KB

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