User.php 225 KB

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