User.php 225 KB

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