User.php 240 KB

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