User.php 229 KB

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