User.php 237 KB

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