User.php 233 KB

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