User.php 234 KB

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