User.php 238 KB

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