User.php 224 KB

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