User.php 190 KB

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