User.php 174 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641
  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. class User extends BaseController
  41. {
  42. use HuiPay;
  43. public $repository;
  44. private $merId;
  45. private $source;
  46. public function __construct(App $app, UserRepository $repository)
  47. {
  48. parent::__construct($app);
  49. $this->repository = $repository;
  50. $this->source = $this->request->header('source');
  51. $this->merId = $this->request->header('merId');
  52. }
  53. /**
  54. * 创建环信账户
  55. * @return mixed
  56. */
  57. public function hxim_create()
  58. {
  59. $uid = $this->request->uid();
  60. try {
  61. $im = new Im();
  62. $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();
  63. if (isset($user['im_uuid']) && $user['im_user_id']) {
  64. return app('json')->success($user);
  65. }
  66. $im_user_id = 'user' . $user['uid'];
  67. $data = [];
  68. $data['im_pass'] = mt_rand(100000, 999999);
  69. $data['im_user_id'] = $im_user_id;
  70. // 获取用户是否存在
  71. $imUser = $im->getImUser('user' . $uid);
  72. if (isset($imUser['activated']) && $imUser['activated'] == true) {
  73. $data['im_uuid'] = $imUser['uuid'];
  74. } else {
  75. $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']);
  76. }
  77. Db::name('User')->where(['uid' => $uid])->update([
  78. 'im' => 1,
  79. 'im_uuid' => $data['im_uuid'],
  80. 'im_userid' => $im_user_id,
  81. 'im_password' => $data['im_pass']
  82. ]);
  83. return app('json')->success($data);
  84. } catch (\Exception $e) {
  85. Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]);
  86. }
  87. return app('json')->fail('注册失败');
  88. }
  89. /**
  90. * @return mixed
  91. * @author xaboy
  92. * @day 2020/6/22
  93. */
  94. public function we_com()
  95. {
  96. $where2['mer_id'] = $this->merId;
  97. $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find();
  98. return app('json')->success($user);
  99. }
  100. public function spread_image()
  101. {
  102. $type = $this->request->param('type');
  103. $res = $type == 'routine'
  104. ? $this->repository->routineSpreadImage($this->request->userInfo())
  105. : $this->repository->wxSpreadImage($this->request->userInfo());
  106. return app('json')->success($res);
  107. }
  108. /**
  109. * @return mixed
  110. * 分享每日海报
  111. */
  112. public function share_day()
  113. {
  114. /**
  115. * 1242
  116. * 2208
  117. */
  118. $user = $this->request->userInfo();
  119. $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
  120. $siteUrl = systemConfig('site_url');
  121. $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);//二维码链接
  122. $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']);
  123. if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
  124. $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg';
  125. $qrcode = $imageInfo['dir'];
  126. dump($qrcode);
  127. $config = array(
  128. 'image' => array(
  129. array(
  130. 'url' => $qrcode,//二维码资源
  131. 'stream' => 0,
  132. 'left' => 533,
  133. 'top' => 1941,
  134. 'right' => 0,
  135. 'bottom' => 0,
  136. 'width' => 184,
  137. 'height' => 182,
  138. 'opacity' => 100
  139. )
  140. ),
  141. 'background' => $filename
  142. );
  143. $data = setSharePoster($config, 'routine/spread/poster');
  144. dump($data);
  145. return app('json')->success($data);
  146. }
  147. public function spread_info()
  148. {
  149. $user = $this->request->userInfo();
  150. $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']);
  151. $data = [
  152. 'lock_brokerage' => $user->lock_brokerage,
  153. 'one_level_count' => $user->one_level_count,
  154. 'two_level_count' => $user->two_level_count,
  155. 'spread_total' => $user->spread_total,
  156. 'yesterday_brokerage' => $user->yesterday_brokerage,
  157. 'total_extract' => $user->total_extract,
  158. 'total_brokerage' => $user->total_brokerage,
  159. 'brokerage_price' => $user->brokerage_price,
  160. 'member_brokerage_price' => $user->member_brokerage_price,
  161. 'now_money' => $user->now_money,
  162. 'broken_day' => (int)systemConfig('lock_brokerage_timer')
  163. ];
  164. return app('json')->success($data);
  165. }
  166. //红包
  167. public function hongbao_info(){
  168. log::info("============hongbao");
  169. $user = $this->request->userInfo();
  170. if($user->uid>0){
  171. //已经入账红包
  172. $data['total_source']=$user->hongbao;
  173. //为生效红包
  174. $data['no_total_source']=Db::name('user_sign_hongbao')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  175. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  176. return app('json')->success($data);
  177. }
  178. }
  179. public function vr_name()
  180. {
  181. $uid = $this->request->uid();
  182. $data = [
  183. "name"=>"VR转账",
  184. "url"=>'https://show.gdjbp.com/?uid=' .$uid,
  185. ];
  186. return app('json')->success($data);
  187. }
  188. public function hongbao_list(){
  189. $pm = $this->request->param('pm');
  190. [$page, $limit] = $this->getPage();
  191. $uid = $this->request->uid();
  192. log::info("hongbao_list==={$uid}");
  193. $where['uid'] = $uid;
  194. if ($pm==0){
  195. $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();
  196. }
  197. if($pm==1){
  198. $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();
  199. }
  200. if($pm==2){
  201. $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();
  202. }
  203. log::info("=======date==={$data}");
  204. return app("json")->success($data);
  205. }
  206. //贡献值
  207. public function gongxian_info(){
  208. log::info("============gongxianinfo");
  209. $user = $this->request->userInfo();
  210. if($user->uid>0){
  211. // $dateObj=DB::name('user_sign_hongbao')->where('uid', $user->uid)->select();
  212. //已经入账贡献值
  213. $data['total_source']=$user->contribute;
  214. //我的团队贡献值
  215. $data['team_gongxian_num']=$user->contribute;
  216. //为生贡献值
  217. $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  218. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  219. return app('json')->success($data);
  220. }
  221. }
  222. public function gongxian_list(){
  223. $pm = $this->request->param('pm');
  224. [$page, $limit] = $this->getPage();
  225. $uid = $this->request->uid();
  226. log::info("green_integral_list==={$uid}");
  227. $where['uid'] = $uid;
  228. if ($pm==0){
  229. $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();
  230. }
  231. // if($pm==1){
  232. // $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();
  233. //
  234. // }
  235. if($pm==2){
  236. $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();
  237. }
  238. log::info("=======date==={$data}");
  239. return app("json")->success($data);
  240. }
  241. //京豆
  242. public function jingdou_info(){
  243. log::info("============hongbao");
  244. $user = $this->request->userInfo();
  245. if($user->uid>0){
  246. //已经入账京豆
  247. //$data['total_source']=$user->vr;//原件
  248. $data['total_source'] = 0;//临时使用
  249. //为生效京豆
  250. $data['no_total_source']=Db::name('user_sign_jingdou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  251. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  252. return app('json')->success($data);
  253. }
  254. }
  255. public function jingdou_list(){
  256. return;
  257. $pm = $this->request->param('pm');
  258. [$page, $limit] = $this->getPage();
  259. $uid = $this->request->uid();
  260. log::info("jingdou_list==={$uid}");
  261. $where['uid'] = $uid;
  262. if ($pm==0){
  263. $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();
  264. }
  265. if($pm==1){
  266. $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();
  267. }
  268. // if($pm==2){
  269. // $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();
  270. // }
  271. // $data['total'] =111;
  272. log::info("=======date==={$data}");
  273. return app("json")->success($data);
  274. }
  275. //复购金
  276. public function fugou_info(){
  277. log::info("============fugou");
  278. $user = $this->request->userInfo();
  279. if($user->uid>0){
  280. //已经入账京豆
  281. $data['total_source']=$user->fugou;
  282. //为生效京豆
  283. $data['no_total_source']=Db::name('user_sign_fugou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  284. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  285. return app('json')->success($data);
  286. }
  287. }
  288. public function fugou_list(){
  289. $pm = $this->request->param('pm');
  290. [$page, $limit] = $this->getPage();
  291. $uid = $this->request->uid();
  292. log::info("fugou_list==={$uid}");
  293. $where['uid'] = $uid;
  294. if ($pm==0){
  295. $data = DB::name('user_sign_fugou')->where($where)->where('type', 1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  296. }
  297. if($pm==1){
  298. $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();
  299. }
  300. if($pm==2){
  301. $data = DB::name('user_sign_fugou')->where($where)->where('status', -1)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  302. }
  303. log::info("=======date==={$data}");
  304. return app("json")->success($data);
  305. }
  306. //VR 购物金
  307. public function vr_info(){
  308. log::info("============vr");
  309. $user = $this->request->userInfo();
  310. if($user->uid>0){
  311. //已经入账京豆
  312. $data['total_source'] = $user->vr;
  313. //为生效京豆
  314. $data['no_total_source']=0;
  315. //$data['no_total_source']=Db::name('user_sign_vr')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  316. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  317. return app('json')->success($data);
  318. }
  319. }
  320. public function vr_list(){
  321. $pm = $this->request->param('pm');
  322. [$page, $limit] = $this->getPage();
  323. $uid = $this->request->uid();
  324. log::info("vr_list==={$uid}");
  325. $where['uid'] = $uid;
  326. $data = DB::name('user_sign_vr')->page($page, $limit)->order("id desc")->select();
  327. if ($pm==0){
  328. $data = DB::name('user_sign_vr')->where($where)->where('type', 1)->page($page, $limit)->order("id desc")->select();
  329. }
  330. if($pm==2){
  331. $data = DB::name('user_sign_vr')->where($where)->where('type', 2)->page($page, $limit)->order("id desc")->select();
  332. }
  333. // if($pm==2){
  334. // $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();
  335. //
  336. // }
  337. log::info("=======date==={$data}");
  338. return app("json")->success($data);
  339. }
  340. public function spread_info_yhc()
  341. {
  342. log::info("============ddddddddd");
  343. $user = $this->request->userInfo();
  344. if($user->uid>0){
  345. //已经入账积分
  346. $data['total_source']=$user->score;
  347. //为生效积分
  348. $data['no_total_source']=Db::name('user_sign_score')->where('status', -1)->where('uid', $user->uid)->sum('reward_socre');;
  349. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  350. return app('json')->success($data);
  351. }
  352. // if ($this->source == 'yhc' && $this->merId) {
  353. // $where['mer_id'] = $this->merId;
  354. // $where['uid'] = $user->uid;
  355. // $enterprise_user = Db::name('enterprise_user')->where($where)->find();
  356. // if ($enterprise_user) {
  357. // $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额
  358. // $data['unsettled_balance'] = 0;//未结算
  359. // $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price');
  360. // $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现
  361. // $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现
  362. // $data['identity'] = $enterprise_user['identity'];
  363. // $data['level'] = $enterprise_user['level'];
  364. // $data['partnership'] = $enterprise_user['partnership'];
  365. // $data['green_integral'] = $enterprise_user['green_integral'];
  366. // $data['green_integral_is'] = $enterprise_user['green_integral_is'];
  367. // $data['operate'] = $enterprise_user['operate'];
  368. // $data['operate_icon'] = '';
  369. // $data['operate_text'] = '';
  370. // $member_settings = merchantConfig($this->merId, 'member_settings');
  371. // if ($data['operate'] == 101) {
  372. // $data['operate_icon'] = $member_settings['yy_one_img'];
  373. // $data['operate_text'] = $member_settings['yy_one_text'];
  374. // }
  375. // if ($data['operate'] == 102) {
  376. // $data['operate_icon'] = $member_settings['yy_two_img'];
  377. // $data['operate_text'] = $member_settings['yy_two_text'];
  378. // }
  379. //
  380. //
  381. // $data['nickname'] = $user->nickname;
  382. // $data['avatar'] = $enterprise_user['avatar'];
  383. //
  384. // $arr = $this->jisuan_fans($user->uid);
  385. // $data['fans_num'] = count($arr);//粉丝总数
  386. //
  387. // $yanglao = 0;
  388. // $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0];
  389. // $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  390. // $yanglao += $offLine1;
  391. // $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  392. // $yanglao += $offLine2;
  393. //
  394. //
  395. // $data['ylj'] = set_price_rtrim($yanglao);
  396. //
  397. // $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money');
  398. //
  399. //
  400. // $data['uid'] = $enterprise_user['uid'];
  401. // if ($enterprise_user['identity'] > 100) {
  402. // $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find();
  403. // if (!$data['identity_data']) {
  404. // $data['identity_data'] = null;
  405. // $data['identity'] = '100';
  406. // }
  407. // } else {
  408. // $data['identity_data'] = null;
  409. // }
  410. //
  411. // $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find();
  412. //
  413. //
  414. // return app('json')->success($data);
  415. // }
  416. // }
  417. return app('json')->fail('用户不存在');
  418. }
  419. /**
  420. * @param UserBillRepository $billRepository
  421. * @return mixed
  422. * @author xaboy
  423. * @day 2020/6/22
  424. */
  425. public function bill(UserBillRepository $billRepository)
  426. {
  427. [$page, $limit] = $this->getPage();
  428. $where = [
  429. // 'now_money' => $this->request->param('type', 0),
  430. 'status' => $this->request->param('status'),
  431. ];
  432. if ($this->request->param('is_red') == true) {
  433. $where['is_red_brokerage'] = 1;
  434. }
  435. return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
  436. }
  437. /**
  438. * @param UserBillRepository $billRepository
  439. * @return mixed
  440. * @author xaboy
  441. * @day 2020/6/22
  442. */
  443. public function brokerage_list(UserBillRepository $billRepository)
  444. {
  445. [$page, $limit] = $this->getPage();
  446. return app('json')->success($billRepository->userList([
  447. 'category' => 'brokerage',
  448. ], $this->request->uid(), $page, $limit));
  449. }
  450. /**
  451. * @return mixed
  452. * @throws \think\db\exception\DataNotFoundException
  453. * @throws \think\db\exception\DbException
  454. * @throws \think\db\exception\ModelNotFoundException
  455. * @author xaboy
  456. * @day 2020/6/22
  457. */
  458. public function spread_order()
  459. {
  460. [$page, $limit] = $this->getPage();
  461. return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit));
  462. }
  463. /**
  464. * TODO
  465. * @return mixed
  466. * @author Qinii
  467. * @day 2020-06-18
  468. */
  469. public function binding()
  470. {
  471. $data = $this->request->params(['phone', 'sms_code']);
  472. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  473. $user = $this->repository->accountByUser($data['phone']);
  474. if ($user) {
  475. $data = ['phone' => $data['phone']];
  476. } else {
  477. $data = ['account' => $data['phone'], 'phone' => $data['phone']];
  478. }
  479. $this->repository->update($this->request->uid(), $data);
  480. return app('json')->success('绑定成功');
  481. }
  482. /**
  483. * TODO
  484. * @return mixed
  485. * @author Qinii
  486. * @day 2020-06-18
  487. */
  488. public function binding_verify()
  489. {
  490. $data = $this->request->params(['user_id', 'captcha']);
  491. $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone");
  492. $data['sms_code'] = $data['captcha'];
  493. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  494. return app('json')->success('验证成功');
  495. }
  496. public function checkSmsCode($phone, $code)
  497. {
  498. $sms_key = 'api.auth.sms.' . $phone;
  499. if (!$cache_code = Cache::get($sms_key)) return false;
  500. if ($code != $cache_code) return false;
  501. Cache::delete($sms_key);
  502. return true;
  503. }
  504. /**
  505. * @return mixed
  506. * @throws \think\db\exception\DataNotFoundException
  507. * @throws \think\db\exception\DbException
  508. * @throws \think\db\exception\ModelNotFoundException
  509. * @author xaboy
  510. * @day 2020/6/22
  511. */
  512. public function spread_list()
  513. {
  514. [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true);
  515. $uid = $this->request->uid();
  516. [$page, $limit] = $this->getPage();
  517. return app('json')->success($level == 2
  518. ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit)
  519. : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit));
  520. }
  521. /**
  522. * @return mixed
  523. * @author xaboy
  524. * @day 2020/6/22
  525. */
  526. public function spread_top()
  527. {
  528. [$page, $limit] = $this->getPage();
  529. $type = $this->request->param('type', 0);
  530. return app('json')->success($type == 1
  531. ? $this->repository->spreadMonthTop($page, $limit)
  532. : $this->repository->spreadWeekTop($page, $limit));
  533. }
  534. /**
  535. * @return mixed
  536. * @author xaboy
  537. * @day 2020/6/22
  538. */
  539. public function brokerage_top()
  540. {
  541. [$page, $limit] = $this->getPage();
  542. $type = $this->request->param('type', 0);
  543. return app('json')->success($type == 1
  544. ? $this->repository->brokerageMonthTop($page, $limit)
  545. : $this->repository->brokerageWeekTop($page, $limit));
  546. }
  547. public function history(UserVisitRepository $repository)
  548. {
  549. $uid = $this->request->uid();
  550. [$page, $limit] = $this->getPage();
  551. return app('json')->success($repository->getHistory($uid, $page, $limit));
  552. }
  553. public function deleteHistory($id, UserVisitRepository $repository)
  554. {
  555. $uid = $this->request->uid();
  556. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  557. return app('json')->fail('数据不存在');
  558. $repository->delete($id);
  559. return app('json')->success('删除成功');
  560. }
  561. public function account()
  562. {
  563. $user = $this->request->userInfo();
  564. if (!$user->phone) return app('json')->fail('请绑定手机号');
  565. return app('json')->success($this->repository->selfUserList($user->phone));
  566. }
  567. public function switchUser()
  568. {
  569. $uid = (int)$this->request->param('uid');
  570. if (!$uid) return app('json')->fail('用户不存在');
  571. $userInfo = $this->request->userInfo();
  572. if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
  573. $user = $this->repository->switchUser($userInfo, $uid);
  574. $tokenInfo = $this->repository->createToken($user);
  575. $this->repository->loginAfter($user);
  576. return app('json')->success($this->repository->returnToken($user, $tokenInfo));
  577. }
  578. /**
  579. * 签到 获取积分
  580. * @return mixed
  581. * @throws \think\db\exception\DataNotFoundException
  582. * @throws \think\db\exception\DbException
  583. * @throws \think\db\exception\ModelNotFoundException
  584. */
  585. public function sub_signin()
  586. {
  587. $member_id = $this->request->uid();
  588. if (!$member_id) return app('json')->fail('用户不存在');
  589. $res = $this->repository->sub_signin($member_id);
  590. return app('json')->success($res);
  591. }
  592. /**
  593. * 获取用户签到记录
  594. * data1 开始时间
  595. * data2 结束时间
  596. * @return mixed
  597. * @throws \think\db\exception\DataNotFoundException
  598. * @throws \think\db\exception\DbException
  599. * @throws \think\db\exception\ModelNotFoundException
  600. */
  601. public function get_signin()
  602. {
  603. $member_id = $this->request->uid();
  604. if (!$member_id) return app('json')->fail('用户不存在');
  605. $where = [];
  606. $data1 = input('data1');
  607. $data2 = input('data2');
  608. if ($data1 && $data2) {
  609. $where["data1"] = $data1;
  610. $where["data2"] = $data2;
  611. }
  612. $res = $this->repository->get_signin($member_id, $where);
  613. return app('json')->success($res);
  614. }
  615. /**
  616. * 提交实名认证
  617. *
  618. * @return void
  619. */
  620. public function add_certification()
  621. {
  622. $member_id = $this->request->uid();
  623. $type = input("type", 0);
  624. if ($type == 1) {
  625. $data = $this->repository->get_cer(["uid" => $member_id]);
  626. return app('json')->success($data);
  627. }
  628. if (!$member_id) return app('json')->fail('用户不存在');
  629. $params = $this->request->params([
  630. 'user_name',
  631. 'mobile',
  632. 'user_card',
  633. 'card_positive',
  634. 'card_reverse',
  635. ]);
  636. $params['create_time'] = time();
  637. $params['uid'] = $member_id;
  638. $baidu = new Ocr();
  639. $image = file_get_contents($params['card_positive']);
  640. $idCardSide = "front";
  641. $result = $baidu->idcard($image, $idCardSide);
  642. $real_user_name = $result['words_result']['姓名']['words'] ?? '';
  643. $real_user_card = $result['words_result']['公民身份号码']['words'] ?? '';
  644. if ($real_user_name != $params['user_name']) {
  645. return app('json')->fail('姓名或身份证号输入有误~');
  646. }
  647. if ($real_user_card != $params['user_card']) {
  648. return app('json')->fail('姓名或身份证号输入有误~');
  649. }
  650. if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) {
  651. $params['status'] = 1;
  652. $res = $this->repository->add_cer($params, $member_id);
  653. if ($res) {
  654. $userRepository = app()->make(UserRepository::class);
  655. //赠送积分 完善实名送90个积分,同时送邀请人50个积分
  656. $userRepository->sign_add($member_id, 90,1,'完善实名系统赠送90个积分','','', '', 1, '', 1);
  657. $member_info = Db::name('user')->where( array('uid' => $member_id) )->find();
  658. if($member_info['spread_uid']){
  659. //好友完善实名系统赠送50个积分
  660. $spreadUid = $member_info['spread_uid'];
  661. $userRepository->sign_add($spreadUid, 50,1,'好友完善实名系统赠送50个积分','','', '', 1, '', 1);
  662. }
  663. return app('json')->success($res);
  664. } else {
  665. return app('json')->fail('认证失败');
  666. }
  667. } else {
  668. return app('json')->fail('认证失败,请重新认证');
  669. }
  670. }
  671. /**
  672. * 申请代理
  673. * name:公司名称
  674. * identity:身份
  675. * license:营业执照
  676. */
  677. public function apply_agent()
  678. {
  679. $name = input("name", "");
  680. $identity = input("identity", 1);
  681. $license = input("license", "");
  682. $province_id = input("province_id", "");
  683. $city_id = input("city_id", "");
  684. $area_id = input("area_id", "");
  685. $street_id = input("street_id", "");
  686. $spread_account = input("spread_account", "");
  687. $member_id = $this->request->uid();
  688. if ($identity != 6 && (!$name || !$identity || !$license)) {
  689. return app('json')->fail('请检查参数');
  690. }
  691. if ($identity == 6 && (!$name || !$identity)) {
  692. return app('json')->fail('请检查参数');
  693. }
  694. $data = [
  695. "name" => $name,
  696. "identity" => $identity,
  697. "license" => $license,
  698. "user_id" => $member_id,
  699. "province_id" => $province_id,
  700. "city_id" => $city_id,
  701. "area_id" => $area_id,
  702. "street_id" => $street_id,
  703. 'spread_account' => $spread_account,
  704. "add_time" => time(),
  705. "update_time" => time()
  706. ];
  707. $res = $this->repository->agent($data);
  708. if ($res['code'] == 400) {
  709. return app('json')->fail($res['msg']);
  710. }
  711. return app('json')->success("申请成功", $res);
  712. }
  713. /*查询是否有已申请或者审核中的代理信息*/
  714. public function isAgent()
  715. {
  716. $uid = $this->request->uid();
  717. $data = $this->repository->isAgent($uid);
  718. return app("json")->success($data);
  719. }
  720. /*查询是否有审核成功的未支付或支付失败的订单*/
  721. public function AgentPayDetail()
  722. {
  723. $uid = $this->request->uid();
  724. if (!$uid) {
  725. return app('json')->fail('请检查参数');
  726. }
  727. $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid];
  728. $data = $this->repository->getAgentPayDetail($where);
  729. return app('json')->success("成功", $data);
  730. }
  731. /**
  732. * 获取信息 全民营销首页
  733. * @return mixed
  734. */
  735. public function get_agent_info()
  736. {
  737. $member_id = $this->request->uid();
  738. $res = $this->repository->get_agent_info($member_id);
  739. if ($res) {
  740. return app('json')->success($res);
  741. } else {
  742. return app('json')->fail('获取失败');
  743. }
  744. }
  745. /**
  746. * 推广统计
  747. * search 搜索
  748. * @return mixed
  749. */
  750. public function get_extension_info()
  751. {
  752. $search = input("search", "");
  753. $where = $this->request->params(["identity"]);
  754. $member_id = $this->request->uid();
  755. $res = $this->repository->get_extension_info($member_id, $search, $where);
  756. if ($res) {
  757. return app('json')->success($res);
  758. } else {
  759. return app('json')->fail('获取失败');
  760. }
  761. }
  762. /**
  763. * 收益统计
  764. * type 搜索
  765. * @return mixed
  766. */
  767. public function get_profit_info()
  768. {
  769. $where = $this->request->params([
  770. 'commission_type',
  771. 'date_on',
  772. 'date_off',
  773. 'order'
  774. ]);
  775. $member_id = $this->request->uid();
  776. $res = $this->repository->get_profit_info($member_id, $where);
  777. if ($res) {
  778. return app('json')->success($res);
  779. } else {
  780. return app('json')->fail('获取失败');
  781. }
  782. }
  783. /**
  784. * 订单统计
  785. * search 搜索
  786. * @return mixed
  787. */
  788. public function get_tuiguang_order()
  789. {
  790. $member_id = $this->request->uid();
  791. $res = $this->repository->get_tuiguang_order($member_id);
  792. if ($res) {
  793. return app('json')->success($res);
  794. } else {
  795. return app('json')->fail('获取失败');
  796. }
  797. }
  798. /*
  799. * 攒金明细统计
  800. * */
  801. public function get_commission_all()
  802. {
  803. $uid = $this->request->uid();
  804. $where['date_on'] = 1;
  805. $where['date_off'] = 0;
  806. // $where['commission_type'] = '';
  807. $date = $this->request->params(['date']);//"today","yesterday","week","month","year"
  808. $where['order'] = $date['date'];
  809. $res = $this->repository->get_profit_info($uid, $where);
  810. return app('json')->success($res);
  811. }
  812. /*
  813. * 攒金明细列表
  814. * */
  815. public function get_commission_list()
  816. {
  817. $uid = $this->request->uid();
  818. [$where['page'], $where['limit']] = $this->getPage();
  819. $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year"
  820. $where['type'] = $data['type'];//0线上;1线下
  821. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  822. $res = $this->repository->get_tuiguang_list($uid, $where);
  823. return app('json')->success($res);
  824. }
  825. /*
  826. * 越攒越多佣金
  827. * */
  828. public function get_com_list()
  829. {
  830. $uid = $this->request->uid();
  831. [$where['page'], $where['limit']] = $this->getPage();
  832. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  833. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  834. $res = $this->repository->get_com_list($uid, $where);
  835. return app('json')->success($res);
  836. }
  837. /*
  838. * 越攒越多统计
  839. * */
  840. public function get_com_all()
  841. {
  842. $uid = $this->request->uid();
  843. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  844. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  845. $res = $this->repository->get_com_all($uid, $where);
  846. return app('json')->success($res);
  847. }
  848. /**
  849. * 养老金详情
  850. * @return mixed
  851. */
  852. public function get_yanglao()
  853. {
  854. $member_id = $this->request->uid();
  855. $res = $this->repository->get_yanglao($member_id);
  856. if ($res) {
  857. return app('json')->success($res);
  858. } else {
  859. return app('json')->fail('获取失败');
  860. }
  861. }
  862. /**
  863. * 养老金明细
  864. */
  865. public function yanglaolog()
  866. {
  867. $member_id = $this->request->uid();
  868. [$page, $limit] = $this->getPage();
  869. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0];
  870. if ($this->source == 'yhc' && $this->merId) {
  871. $where['mer_id'] = $this->merId;
  872. }
  873. $month = $this->request->param('month', '');//年月搜索
  874. $status = $this->request->param('status', 1);
  875. //1-全部 2-已结算 3-未结算 4-已取消
  876. if ($status == 2) {
  877. $where['status'] = 1;
  878. } else if ($status == 3) {
  879. // $where['gzc']=0;
  880. $where['status'] = 0;
  881. } else if ($status == 4) {
  882. $where['status'] = -1;
  883. }
  884. $source = $this->request->param('source', -1);
  885. if ($source > -1) {
  886. $where['source'] = $source;
  887. }
  888. $res = $this->repository->yanglaolog($where, $page, $limit, $month);
  889. if ($res) {
  890. return app('json')->success($res);
  891. } else {
  892. return app('json')->fail('获取失败');
  893. }
  894. }
  895. /*养老金详情*/
  896. public function YangLaoDetail($id)
  897. {
  898. $member_id = $this->request->uid();
  899. $data = $this->request->params([
  900. 'type',
  901. ]);
  902. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id];
  903. $res = $this->repository->yanglaoDetail($where);
  904. return app('json')->success($res);
  905. }
  906. /**
  907. * 消费明细
  908. * @return mixed
  909. */
  910. public function tripartite()
  911. {
  912. $member_id = $this->request->uid();
  913. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]];
  914. $res = $this->repository->yanglaolog($where);
  915. if ($res) {
  916. return app('json')->success($res);
  917. } else {
  918. return app('json')->fail('获取失败');
  919. }
  920. }
  921. /**
  922. * 提现明细
  923. * @return mixed
  924. */
  925. public function withdrawal()
  926. {
  927. $member_id = $this->request->uid();
  928. $data = $this->request->params([
  929. 'type',
  930. ]);
  931. $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2];
  932. if ($this->source == 'yhc') {
  933. $where['mer_id'] = $this->merId;
  934. }
  935. $res = $this->repository->withdrawal_user($where);
  936. if ($res) {
  937. return app('json')->success($res);
  938. } else {
  939. return app('json')->fail('获取失败');
  940. }
  941. }
  942. /**
  943. * 提现详情
  944. * @return mixed
  945. * @author cabbage
  946. * @day 2020/10/31
  947. */
  948. public function withdrawalDetail()
  949. {
  950. $member_id = $this->request->uid();
  951. $extract_id = input("extract_id", 0);
  952. return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id));
  953. }
  954. /*
  955. * 修改个人信息*/
  956. public function updateUser()
  957. {
  958. $data = $this->request->params([
  959. 'nickname',
  960. 'avatar',
  961. 'sex',
  962. 'birthday',
  963. 'addres',
  964. 'mark'
  965. ]);
  966. $uid = $this->request->uid();
  967. $res = '';
  968. if ($this->source == 'yhc') {
  969. $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]);
  970. unset($data['avatar']);
  971. }
  972. $data = $this->repository->updateUser($uid, $data);
  973. if ($data || $res) {
  974. return app("json")->success("修改成功", $data);
  975. }
  976. return app("json")->fail("未做任何修改");
  977. }
  978. /*积分记录*/
  979. public function socreList()
  980. {
  981. [$page, $limit] = $this->getPage();
  982. $uid = $this->request->uid();
  983. $data = $this->repository->socreList($uid, $page, $limit);
  984. return app("json")->success($data);
  985. }
  986. function jisuan_fans($uid)
  987. {
  988. $where22['node_uid'] = $uid;
  989. $where22['mer_id'] = $this->merId;
  990. $arr = $this->jisuantuandui($where22);
  991. $where['puid'] = $uid;
  992. $where['mer_id'] = $this->merId;
  993. $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');//直属粉丝数量
  994. $result = array_unique(array_merge($arr, $direct_fans));
  995. return $result;
  996. }
  997. function jisuantuandui($where, $data = [])
  998. {
  999. $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid');
  1000. $arr = array_merge($data, $enterprise_user_team);
  1001. foreach ($enterprise_user_team as $v) {
  1002. $where['node_uid'] = $v;
  1003. $arr = $this->jisuantuandui($where, $arr);
  1004. }
  1005. return $arr;
  1006. }
  1007. /**
  1008. * 一壶茶-团队列表
  1009. */
  1010. public function team_list_1()
  1011. {
  1012. $teamid = $this->request->uid();
  1013. //$teamid = $this->request->param('teamid');//测试ID
  1014. $teamid = 17;
  1015. $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员
  1016. $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
  1017. if(!empty($datas_jbp)){
  1018. $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
  1019. //判断大小团队(业绩多的是大部门,业绩小的是小部门)
  1020. $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人
  1021. // 获取分页参数
  1022. $data1= [
  1023. "total"=>100,
  1024. "per_page"=> 10,
  1025. "current_page"=> 1,
  1026. "last_page"=> 1,
  1027. ];
  1028. if($type != 2){
  1029. //小部门和大部门列表数据
  1030. foreach($tes as $k=>$v){
  1031. $curr_pv = '';
  1032. if($v['curr_type']==0){
  1033. $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
  1034. }else if($v['curr_type']==1){
  1035. $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
  1036. }else{
  1037. $curr_pv = 0;
  1038. }
  1039. $data1['data'][$k] = [
  1040. "uid"=>$v["id"],
  1041. "nickname"=> $v['user_name'] . $curr_pv,
  1042. "phone"=> "137****3315",
  1043. "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1044. "create_time"=>"2025-01-25 11:00:18",
  1045. "identity"=>"11",
  1046. "level"=> "40002",
  1047. "partnership"=>"22",
  1048. "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
  1049. "new_performance"=> 0,//新增业绩
  1050. "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数)
  1051. ];
  1052. }
  1053. }else{
  1054. //直推列表
  1055. foreach($tes as $k=>$v){
  1056. $data1['data'][$k] = [
  1057. "uid"=>$v["uid"],
  1058. "nickname"=> $v['nickname'],
  1059. "avatar"=>$v['avatar'],
  1060. "create_time"=>"2025-01-25 11:00:18",
  1061. ];
  1062. }
  1063. }
  1064. $data['team_list'] = $data1;
  1065. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数
  1066. $data['new_performance'] = 0;//新增业绩
  1067. $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩
  1068. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟
  1069. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟
  1070. $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV
  1071. $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV
  1072. // $data['effective_fans_num'] = DB::name('enterprise_user')
  1073. }
  1074. //var_dump($data);
  1075. //把新表中的新增邀请用户加到数组中
  1076. //$spread_usersdata = Db::name('user')->where("spread_uid",$teamid)->select();//查询旗下会员
  1077. // 查询当前会员旗下的会员数据
  1078. // 获取分页参数
  1079. [$page, $limit] = $this->getPage();
  1080. // 查询当前会员旗下的会员数据(分页)
  1081. $subordinate_members = Db::name('user')
  1082. ->alias('u')
  1083. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1084. ->where("u.spread_uid", $teamid) // 查询旗下会员
  1085. ->where("so.mer_id", 496)
  1086. // ->where("so.douhuomall", 1)
  1087. // ->where("so.douhuomall_status", 9)
  1088. // ->where("so.status", 0)
  1089. ->group('u.uid') // 确保每个用户只出现一次
  1090. ->page($page, $limit) // 分页查询
  1091. ->select(); // 获取分页数据
  1092. //计算团队总业绩
  1093. // $total_amount=0;
  1094. // foreach($subordinate_members as $k=>$v){
  1095. // }
  1096. // 获取总会员数
  1097. $total_members = Db::name('user') ->alias('u')
  1098. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1099. ->where("u.spread_uid", $teamid) // 查询旗下会员
  1100. ->where("so.mer_id", 496)
  1101. // ->where("so.douhuomall", 1)
  1102. // ->where("so.douhuomall_status", 9)
  1103. // ->where("so.status", 0)
  1104. ->group('u.uid') // 确保每个用户只出现一次
  1105. ->page($page, $limit) // 分页查询
  1106. ->count(); // 获取分页数据
  1107. // 构造分页信息
  1108. $data1 = [
  1109. "total" => $total_members,
  1110. "per_page" => $limit,
  1111. "current_page" => $page,
  1112. "last_page" => ceil($total_members / $limit),
  1113. "data" => []
  1114. ];
  1115. $total_amount_pv_team = 0;//计算总业绩
  1116. //获取团队总数量
  1117. $team_count_total = 0;
  1118. $small_count = 0;//小部门人数
  1119. //var_dump($this->calculatePerformance($subordinate_members));
  1120. //获取大小部门数据(新表)
  1121. $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);//下标0是大部门
  1122. //var_dump( $get_big_small_datas);
  1123. //判断大小部门的人数(根据业绩多的就是大部门,业绩小的就是小部门来计算展示的部门人数);
  1124. $big_team_count = $get_big_small_datas[0]['team_count'];
  1125. $smallteam_count = $get_big_small_datas[1]['team_count'];
  1126. //end
  1127. // 遍历分页数据,构造每个会员的详细信息
  1128. foreach ($subordinate_members as $k => $v) {
  1129. //计算自己和旗下的业绩
  1130. $t_teams_pv = $this->calculatePerformance($v['uid']);
  1131. $total_amount_pv_team += $t_teams_pv['total_performance'];
  1132. $data1['data'][$k] = [
  1133. "uid" => $v["uid"],
  1134. "nickname" => $v['nickname'], // 假设昵称字段为 nickname
  1135. "phone" => substr_replace($v['phone'], '****', 3, 4), // 隐藏手机号中间四位
  1136. "avatar" => $v['avatar'], // 假设头像字段为 avatar
  1137. "create_time" => $v['create_time'], // 假设创建时间为 create_time
  1138. "total_performance" => $t_teams_pv['total_performance'], // 假设总业绩字段需要额外计算
  1139. "new_performance" => $t_teams_pv['total_performance'], // 假设新增业绩字段需要额外计算
  1140. "team_count" => $t_teams_pv['team_count'], // 假设团购人数需要额外计算
  1141. ];
  1142. }
  1143. // 根据 type 参数处理数据
  1144. if ($type == 1) {
  1145. // 大部门:取 total_performance 最大的一个数组
  1146. usort($data1['data'], function ($a, $b) {
  1147. return $b['total_performance'] <=> $a['total_performance'];
  1148. });
  1149. $data1['data'] = array_slice($data1['data'], 0, 1); // 只保留最大的一个
  1150. } elseif ($type == 0) {
  1151. // 小部门:去掉 total_performance 最大的一个数组
  1152. usort($data1['data'], function ($a, $b) {
  1153. return $b['total_performance'] <=> $a['total_performance'];
  1154. });
  1155. $data1['data'] = array_slice($data1['data'], 1); // 去掉第一个
  1156. } elseif ($type == 2) {
  1157. // 直推:不做任何处理
  1158. }
  1159. // 构造最终返回的数据
  1160. $data = [
  1161. 'team_list' => $data1,
  1162. 'fans_num' => $get_big_small_datas[0]['team_count'] + $get_big_small_datas[1]['team_count'], // 粉丝数
  1163. 'new_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 新增业绩
  1164. 'total_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 总业绩
  1165. 'person_nums' => $big_team_count, // 大部门人数
  1166. 'common_nums' => $smallteam_count, // 小部门人数
  1167. 'common_nums_pv' => $get_big_small_datas[0]['total_performance'], // 公共联盟PV
  1168. 'person_nums_pv' => $get_big_small_datas[1]['total_performance'], // 个人联盟PV
  1169. ];
  1170. return app("json")->success($data);
  1171. }
  1172. /**
  1173. * 一壶茶-团队列表
  1174. */
  1175. public function team_list()
  1176. {
  1177. $teamid = $this->request->uid();
  1178. //$teamid = $this->request->param('teamid');//测试ID
  1179. //$teamid = 17;
  1180. if($teamid == 592){
  1181. $teamid = 360;//593
  1182. $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
  1183. return;
  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. foreach ($orders as $order) {
  3104. // var_dump($order['uid']."订单:".$order['total_price']);
  3105. if ($order['total_price'] == 1180) {
  3106. $totalPv += 700;
  3107. } else if ($order['total_price'] == 11800) {
  3108. $totalPv += 7000;
  3109. } else if ($order['total_price'] == 10620) {
  3110. $totalPv += 6300;
  3111. } else if ($order['total_price'] == 2360) {
  3112. $totalPv += 1400;
  3113. } else if ($order['total_price'] == 9440) {
  3114. $totalPv += 5600;
  3115. }
  3116. }
  3117. return $totalPv;
  3118. }
  3119. // 递归获取所有子级 UID 的业绩
  3120. public function getTeamPv11($parentUid) {
  3121. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3122. $children = Db::name("user")
  3123. ->where("spread_uid", $parentUid)
  3124. ->column("uid");
  3125. $allChildren = [];
  3126. foreach ($children as $childUid) {
  3127. $allChildren[] = $childUid;
  3128. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3129. }
  3130. return $allChildren;
  3131. };
  3132. // 获取当前用户及其所有子级的 UID
  3133. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3134. // 查询当前用户及其子级的所有订单
  3135. $orders = Db::name("store_order")
  3136. ->whereIn('status', [0, 1, 2, 3])
  3137. ->whereIn("uid", $allUids)
  3138. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3139. ->select();
  3140. // 计算总业绩
  3141. $totalPv = 0;
  3142. foreach ($orders as $order) {
  3143. switch ($order['total_price']) {
  3144. case 1180:
  3145. $totalPv += 700;
  3146. break;
  3147. case 11800:
  3148. $totalPv += 7000;
  3149. break;
  3150. case 10620:
  3151. $totalPv += 6300;
  3152. break;
  3153. case 2360:
  3154. $totalPv += 1400;
  3155. break;
  3156. case 9440:
  3157. $totalPv += 5600;
  3158. break;
  3159. }
  3160. }
  3161. return $totalPv;
  3162. }
  3163. //根据传递的父级数组,返回他的对应子级的个数
  3164. public function getTeamSize($parentUids) {
  3165. // 初始化结果数组
  3166. $result = [];
  3167. // 遍历每个父级ID
  3168. foreach ($parentUids as $parentUid) {
  3169. // 递归获取所有子级 UID
  3170. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3171. $children = Db::name("user")
  3172. ->where("spread_uid", $parentUid)
  3173. ->column("uid");
  3174. // 确保返回的是数组
  3175. if (!is_array($children)) {
  3176. return [];
  3177. }
  3178. $allChildren = [];
  3179. foreach ($children as $childUid) {
  3180. $allChildren[] = $childUid;
  3181. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3182. }
  3183. return $allChildren;
  3184. };
  3185. // 获取当前父级及其所有子级的 UID
  3186. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3187. // 计算总个数(包括父级自身)
  3188. $totalUids = count($allUids);
  3189. // 将结果存入数组
  3190. $result[] = [
  3191. 'parent_uid' => $parentUid,
  3192. 'total_count' => $totalUids
  3193. ];
  3194. }
  3195. return $result;
  3196. }
  3197. public function processArray($array) {
  3198. // 初始化结果数组
  3199. $result = [
  3200. 'max_value' => null, // 最大值
  3201. 'max_index' => null, // 最大值的下标
  3202. 'remaining_sum' => 0 // 剩余值的总和
  3203. ];
  3204. // 检查数组是否为空
  3205. if (empty($array)) {
  3206. return $result;
  3207. }
  3208. // 找出最大值及其下标
  3209. $maxValue = $array[0];
  3210. $maxIndex = 0;
  3211. for ($i = 1; $i < count($array); $i++) {
  3212. if ($array[$i] > $maxValue) {
  3213. $maxValue = $array[$i];
  3214. $maxIndex = $i;
  3215. }
  3216. }
  3217. // 计算剩余值的总和
  3218. $remainingSum = 0;
  3219. for ($i = 0; $i < count($array); $i++) {
  3220. if ($i != $maxIndex) {
  3221. $remainingSum += $array[$i];
  3222. }
  3223. }
  3224. // 将结果存入数组
  3225. $result['max_value'] = $maxValue;
  3226. $result['max_index'] = $maxIndex;
  3227. $result['remaining_sum'] = $remainingSum;
  3228. return $result;
  3229. }
  3230. /**
  3231. * 获取当前用户业绩
  3232. */
  3233. public function getPerformance($user_id) {
  3234. $team_amount = 0;
  3235. $person_amount = 0;
  3236. $result_big_team_arr = [];
  3237. $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
  3238. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3239. $common_nums = $this->getCommonNums($user_id);
  3240. //var_dump($user_id);
  3241. $get_teams_comm_num = 0;
  3242. $get_teams_comm_pv = 0;
  3243. //1.0系统中有下级,需要在2.0中再加下级数据
  3244. if($user_id < 611){
  3245. //梅红在2.0中的ID是780
  3246. if($user_id == 593){
  3247. $common_nums[] = 780;
  3248. unset($common_nums[0]);
  3249. }
  3250. //var_dump($common_nums);
  3251. //用户三峡所有在2.0系统下面的业绩和人数 start
  3252. $child_nums = [];
  3253. //再加上当前用户直属的子级
  3254. $common_ns = $common_nums;
  3255. $common_ns[] = $user_id;
  3256. //var_dump($common_ns);return;
  3257. //获取当前用户
  3258. foreach($common_ns as $v){
  3259. $child_nums[] = $this->getRecursiveChildren($v);
  3260. }
  3261. //梅红在2.0中的ID是780
  3262. if($user_id == 593){
  3263. $child_nums[0][] = 780;
  3264. }
  3265. //去除空数组,并重新组合有数据的数组
  3266. $filteredData = array_filter($child_nums, function($array) {
  3267. return !empty($array); // 如果数组不为空,则保留
  3268. });
  3269. // 合并所有非空数组
  3270. foreach ($filteredData as $array) {
  3271. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  3272. }
  3273. //var_dump($result_big_team_arr);echo "ppppppppppppppppp";
  3274. //获取当前用户下面在2.0中的下级所有PV
  3275. $get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  3276. //获取当前用户下面在2.0中的下级所有人数
  3277. $get_teams_comm_num = count($result_big_team_arr);
  3278. //var_dump($get_teams_comm_num);
  3279. // var_dump( $get_teams_comm_pv);
  3280. //用户伞下小部门所有在2.0系统下面的业绩和人数 end
  3281. }else{
  3282. //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  3283. $child_nums = $this->getChildren($user_id);
  3284. //获取父级子级下面的个人
  3285. $num_teams = $this->getTeamSize($child_nums);
  3286. //var_dump($num_teams);
  3287. //= $child_nums;
  3288. // $getss = $this->processArray($get_teams_comm_datas);
  3289. // var_dump($getss);
  3290. // var_dump($num_teams[$getss['max_index']]);
  3291. foreach($child_nums as $v){
  3292. $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  3293. }
  3294. if( count($get_teams_comm_datas) ==1 ){
  3295. $get_teams_comm_pv =$get_teams_comm_datas[0];
  3296. $get_teams_comm_num = $num_teams[0]['total_count'];
  3297. }else if(count($get_teams_comm_datas) >1){
  3298. $getss = $this->processArray($get_teams_comm_datas);
  3299. //var_dump($getss);
  3300. $team_datas = $num_teams[$getss['max_index']];
  3301. }
  3302. }
  3303. // var_dump($result_big_team_arr);
  3304. //var_dump(count($get_teams_comm_num));
  3305. //合并业绩和人数
  3306. $team_amount += $get_teams_comm_pv;
  3307. // var_dump($team_amount);
  3308. //1.0获取小区业绩
  3309. $person_nums = $this->getPersonageNums($user_id);
  3310. //var_dump($person_nums);
  3311. $result_small_team_arr = [];
  3312. //1.0系统中有下级,需要在2.0中再加下级数据
  3313. //用户三峡所有在2.0系统下面的业绩和人数 start
  3314. $child_nums_mix = [];
  3315. //再加上当前用户直属的子级
  3316. $common_ns1 = $person_nums;
  3317. $common_ns1[] = $user_id;
  3318. //获取当前用户
  3319. foreach($common_ns1 as $v){
  3320. $child_nums_mix[] = $this->getRecursiveChildren($v);
  3321. }
  3322. //去除空数组,并重新组合有数据的数组
  3323. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  3324. return !empty($array); // 如果数组不为空,则保留
  3325. });
  3326. // 合并所有非空数组
  3327. $result_small_team_arr = [];
  3328. foreach ($filteredData_1 as $array) {
  3329. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  3330. }
  3331. //获取当前用户下面在2.0中的下级所有PV
  3332. $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  3333. //获取当前用户下面在2.0中的下级所有人数
  3334. $get_teams_per_num = count($result_small_team_arr);
  3335. //合并业绩和人数
  3336. $person_amount += $get_teams_per_pv;
  3337. // var_dump($person_amount);
  3338. //用户小部门所有在2.0系统下面的业绩和人数 end
  3339. // $common_nums[] = $user_id;
  3340. foreach ($common_nums as $key => $value) {
  3341. # code...
  3342. $amount = $this->getPerformance1($value);
  3343. $team_amount += $amount;
  3344. }
  3345. foreach ($person_nums as $key => $value) {
  3346. # code...
  3347. $amount = $this->getPerformance1($value);
  3348. $person_amount += $amount;
  3349. }
  3350. //var_dump($team_amount);
  3351. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  3352. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  3353. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3354. $money1180Sum = 0;
  3355. foreach ($user_team_amount as $record) {
  3356. $money1180Sum += $record['money'] - 300 - 180;
  3357. }
  3358. // 获取 status 为 1 且 money 为 11800 的记录集合
  3359. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  3360. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3361. $money11800Sum = 0;
  3362. foreach ($money11800Records as $record) {
  3363. $money11800Sum += $record['money'] - 3000 - 1800;
  3364. }
  3365. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  3366. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3367. $money10620Sum = 0;
  3368. foreach ($money10620Records as $record) {
  3369. $money10620Sum += $record['money'] - 2700 - 1620;
  3370. }
  3371. // 计算除去特定值后的总和
  3372. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  3373. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3374. $otherMoneySum = 0;
  3375. foreach ($otherMoneyRecords as $record) {
  3376. $otherMoneySum += $record['money'];
  3377. }
  3378. // 分别处理特定值的情况并加上其他值的总和
  3379. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3380. // var_dump($all_record_nums);
  3381. $team_amount += $all_record_nums;
  3382. // var_dump($user_team_amount);
  3383. //计算自己的个人联盟总流水
  3384. // // //计算自己的个人联盟总流水
  3385. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  3386. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3387. // $person_amount += $user_person_amount;
  3388. //计算个人的1180单价的业绩 集合
  3389. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  3390. $money1180Sum = 0;
  3391. foreach ($money1180Records as $record) {
  3392. $money1180Sum += $record['money'] - 300 - 180;
  3393. }
  3394. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  3395. //var_dump($person_nums);
  3396. //计算个人的11800单价的业绩 集合
  3397. $money11800Sum = 0;
  3398. foreach ($money11800Records as $record) {
  3399. $money11800Sum += $record['money'] - 3000 - 1800;
  3400. }
  3401. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  3402. //var_dump($person_nums);
  3403. //计算个人的10620单价的业绩 集合
  3404. $money10620Sum = 0;
  3405. foreach ($money10620Records as $record) {
  3406. $money10620Sum += $record['money'] - 2700 - 1620;
  3407. }
  3408. // 计算除去特定值后的总和
  3409. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3410. $otherMoneySum = 0;
  3411. foreach ($otherMoneyRecords as $record) {
  3412. $otherMoneySum += $record['money'];
  3413. }
  3414. // 分别处理特定值的情况并加上其他值的总和
  3415. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  3416. $person_amount += $user_person_amount;
  3417. //级别信息
  3418. $userInfo = Db::name("user")->find($user_id);//
  3419. $zk_level = 4;
  3420. $is_zk = false;
  3421. if($userInfo['user_level_id_old'] == $zk_level) {
  3422. $is_zk = true;
  3423. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  3424. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  3425. } else{
  3426. $sales_incentive = 0;
  3427. }
  3428. $return_data = [
  3429. 'common_nums'=>count($common_nums) + $get_teams_comm_num,
  3430. 'person_nums'=>count($person_nums) + $get_teams_per_num,
  3431. 'common_nums_pv'=> $team_amount,
  3432. 'person_nums_pv'=> $person_amount,
  3433. 'sum_nums_pv' =>$team_amount + $person_amount,
  3434. 'sales_incentive' => $sales_incentive,
  3435. "is_zk"=>$is_zk
  3436. ];
  3437. return $return_data;
  3438. }
  3439. /**
  3440. * 获取当前用户业绩
  3441. */
  3442. public function getPerformance_copy($user_id) {
  3443. // $user_id = $this->request->post("user_id");
  3444. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3445. $common_nums = $this->getCommonNums($user_id);
  3446. //1.0获取小区业绩
  3447. $person_nums = $this->getPersonageNums($user_id);
  3448. //return $person_nums;
  3449. // var_dump( $common_nums);
  3450. $team_amount = 0;
  3451. $person_amount = 0;
  3452. // $common_nums[] = $user_id;
  3453. foreach ($common_nums as $key => $value) {
  3454. # code...
  3455. $amount = $this->getPerformance1($value);
  3456. $team_amount += $amount;
  3457. }
  3458. foreach ($person_nums as $key => $value) {
  3459. # code...
  3460. $amount = $this->getPerformance1($value);
  3461. $person_amount += $amount;
  3462. }
  3463. //var_dump($team_amount);
  3464. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  3465. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  3466. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3467. $money1180Sum = 0;
  3468. foreach ($user_team_amount as $record) {
  3469. $money1180Sum += $record['money'] - 300 - 180;
  3470. }
  3471. // 获取 status 为 1 且 money 为 11800 的记录集合
  3472. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  3473. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3474. $money11800Sum = 0;
  3475. foreach ($money11800Records as $record) {
  3476. $money11800Sum += $record['money'] - 3000 - 1800;
  3477. }
  3478. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  3479. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3480. $money10620Sum = 0;
  3481. foreach ($money10620Records as $record) {
  3482. $money10620Sum += $record['money'] - 2700 - 1620;
  3483. }
  3484. // 计算除去特定值后的总和
  3485. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  3486. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3487. $otherMoneySum = 0;
  3488. foreach ($otherMoneyRecords as $record) {
  3489. $otherMoneySum += $record['money'];
  3490. }
  3491. // 分别处理特定值的情况并加上其他值的总和
  3492. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3493. // var_dump($all_record_nums);
  3494. $team_amount += $all_record_nums;
  3495. //计算自己的个人联盟总流水
  3496. // // //计算自己的个人联盟总流水
  3497. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  3498. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3499. // $person_amount += $user_person_amount;
  3500. //计算个人的1180单价的业绩 集合
  3501. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  3502. $money1180Sum = 0;
  3503. foreach ($money1180Records as $record) {
  3504. $money1180Sum += $record['money'] - 300 - 180;
  3505. }
  3506. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  3507. //var_dump($person_nums);
  3508. //计算个人的11800单价的业绩 集合
  3509. $money11800Sum = 0;
  3510. foreach ($money11800Records as $record) {
  3511. $money11800Sum += $record['money'] - 3000 - 1800;
  3512. }
  3513. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  3514. //var_dump($person_nums);
  3515. //计算个人的10620单价的业绩 集合
  3516. $money10620Sum = 0;
  3517. foreach ($money10620Records as $record) {
  3518. $money10620Sum += $record['money'] - 2700 - 1620;
  3519. }
  3520. // 计算除去特定值后的总和
  3521. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3522. $otherMoneySum = 0;
  3523. foreach ($otherMoneyRecords as $record) {
  3524. $otherMoneySum += $record['money'];
  3525. }
  3526. // 分别处理特定值的情况并加上其他值的总和
  3527. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  3528. $person_amount += $user_person_amount;
  3529. //级别信息
  3530. $userInfo = Db::name("user")->find($user_id);//
  3531. $zk_level = 4;
  3532. $is_zk = false;
  3533. if($userInfo['user_level_id_old'] == $zk_level) {
  3534. $is_zk = true;
  3535. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  3536. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  3537. } else{
  3538. $sales_incentive = 0;
  3539. }
  3540. $return_data = [
  3541. 'common_nums'=>count($common_nums),
  3542. 'person_nums'=>count($person_nums),
  3543. 'common_nums_pv'=> $team_amount,
  3544. 'person_nums_pv'=> $person_amount,
  3545. 'sum_nums_pv' =>$team_amount + $person_amount,
  3546. 'sales_incentive' => $sales_incentive,
  3547. "is_zk"=>$is_zk
  3548. ];
  3549. return $return_data;
  3550. }
  3551. /**
  3552. * 获取指定用户业绩
  3553. */
  3554. public function getPerformanceOf($user_id) {
  3555. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3556. $common_nums = $this->getCommonNums($user_id);
  3557. $person_nums = $this->getPersonageNums($user_id);
  3558. $team_amount = 0;
  3559. $person_amount = 0;
  3560. // $common_nums[] = $user_id;
  3561. foreach ($common_nums as $key => $value) {
  3562. # code...
  3563. $amount = $this->getPerformance1($value);
  3564. $team_amount += $amount;
  3565. }
  3566. foreach ($person_nums as $key => $value) {
  3567. # code...
  3568. $amount = $this->getPerformance1($value);
  3569. $person_amount += $amount;
  3570. }
  3571. // return $person_nums;
  3572. //添加自己共建联盟的流水
  3573. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("spread_id",$user_id)->sum("money");
  3574. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  3575. $team_amount += $user_team_amount;
  3576. // //计算自己的个人联盟总流水
  3577. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("spread_id",$user_id)->sum("money");
  3578. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3579. $person_amount += $user_person_amount;
  3580. $sum_nums_pv = $team_amount + $person_amount;
  3581. $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
  3582. return $sum_nums_pv;
  3583. }
  3584. /**
  3585. * 获取用户星级
  3586. */
  3587. public function getStarLevel($user_id,$team_money=0,$person_money=0) {
  3588. if(empty($team_money)) {
  3589. $common_nums = $this->getCommonNums($user_id);
  3590. $team_money = 0;
  3591. foreach ($common_nums as $key => $value) {
  3592. # code...
  3593. $amount = $this->getPerformance1($value);
  3594. $team_money += $amount;
  3595. }
  3596. //计算自己的共建联盟流水
  3597. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
  3598. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  3599. $team_money += $user_team_amount;
  3600. }else{
  3601. $common_nums = $this->getCommonNums($user_id);
  3602. }
  3603. if(empty($person_money)) {
  3604. $person_nums = $this->getPersonageNums($user_id);
  3605. $person_amount = 0;
  3606. foreach ($person_nums as $key => $value) {
  3607. # code...
  3608. $amount = $this->getPerformance1($value);
  3609. $person_amount += $amount;
  3610. }
  3611. $person_money = $person_amount;
  3612. //计算自己的个人联盟总流水
  3613. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
  3614. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3615. $person_money += $user_person_amount;
  3616. }else{
  3617. $person_nums = $this->getPersonageNums($user_id);
  3618. }
  3619. $slow = $person_money;
  3620. if($team_money < $person_money) {
  3621. $slow = $team_money;
  3622. }
  3623. $sum_money = $team_money + $person_money;
  3624. // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
  3625. // $this->error(0,$data);
  3626. $star_list = Db::name("old_user_star")->order("statement_all_num desc")->select();
  3627. $start_level = "";
  3628. foreach ($star_list as $key => $value) {
  3629. # code...
  3630. if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) {
  3631. return $value;
  3632. }
  3633. }
  3634. return $start_level;
  3635. }
  3636. /**
  3637. * 获取流水信息
  3638. */
  3639. public function getPerformance1($user_id) {
  3640. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  3641. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  3642. // return $amount;
  3643. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  3644. $money1180Sum = 0;
  3645. foreach ($money1180Records as $record) {
  3646. $money1180Sum += $record['money'] - 300 - 180;
  3647. }
  3648. // var_dump($money1180Sum);
  3649. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  3650. //var_dump($person_nums);
  3651. //计算个人的11800单价的业绩 集合
  3652. $money11800Sum = 0;
  3653. foreach ($money11800Records as $record) {
  3654. $money11800Sum += $record['money'] - 3000 - 1800;
  3655. }
  3656. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  3657. //var_dump($person_nums);
  3658. //计算个人的11800单价的业绩 集合
  3659. $money10620Sum = 0;
  3660. foreach ($money10620Records as $record) {
  3661. $money10620Sum += $record['money'] - 2700 - 1620;
  3662. }
  3663. // 计算除去特定值后的总和
  3664. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3665. $otherMoneySum = 0;
  3666. foreach ($otherMoneyRecords as $record) {
  3667. $otherMoneySum += $record['money'];
  3668. }
  3669. // 分别处理特定值的情况并加上其他值的总和
  3670. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3671. return $user_person_amount;
  3672. }
  3673. /**
  3674. * 获取个人业绩统计信息
  3675. */
  3676. public function getPerformanceOfId($user_id)
  3677. {
  3678. //var_dump($user_id);
  3679. //联盟总人数 共建联盟人数 个人联盟人数 总流水 共建联盟流水 个人联盟流水 所属星级(钻卡专属)
  3680. $common_nums = $this->getCommonNums($user_id);
  3681. $person_nums = $this->getPersonageNums($user_id);
  3682. //联盟业绩 查询 共建联盟业绩 个人联盟业绩
  3683. $team_amount = 0;
  3684. $person_amount = 0;
  3685. // $common_nums[] = $user_id;
  3686. foreach ($common_nums as $key => $value) {
  3687. # code...
  3688. $amount = $this->getPerformance1($value);
  3689. $team_amount += $amount;
  3690. }
  3691. //计算自己的共建联盟流水
  3692. //$user_team_amount = Db::name("user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  3693. // $this->error(0,$team_amount);
  3694. //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  3695. $money1180Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 1180)->select();
  3696. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3697. $money1180Sum = 0;
  3698. foreach ($money1180Records as $record) {
  3699. $money1180Sum += $record['money'] - 300 - 180;
  3700. }
  3701. // 获取 status 为 1 且 money 为 11800 的记录集合
  3702. $money11800Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 11800)->select();
  3703. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3704. $money11800Sum = 0;
  3705. foreach ($money11800Records as $record) {
  3706. $money11800Sum += $record['money'] - 3000 - 1800;
  3707. }
  3708. // 获取 status 为 1 且 money 为 11800 的记录集合
  3709. $money10620Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 10620)->select();
  3710. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3711. $money10620Sum = 0;
  3712. foreach ($money10620Records as $record) {
  3713. $money10620Sum += $record['money'] - 2700 - 1620;
  3714. }
  3715. // 计算除去特定值后的总和
  3716. $otherMoneyRecords = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->whereNotIn('money', [1180, 11800,10620])->select();
  3717. $otherMoneySum = 0;
  3718. foreach ($otherMoneyRecords as $record) {
  3719. $otherMoneySum += $record['money'];
  3720. }
  3721. // 分别处理特定值的情况并加上其他值的总和
  3722. $user_team_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3723. $team_amount += $user_team_amount;
  3724. foreach ($person_nums as $key => $value) {
  3725. # code...
  3726. $amount = $this->getPerformance1($value);
  3727. $person_amount += $amount;
  3728. }
  3729. // //计算自己的个人联盟总流水
  3730. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  3731. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3732. $person_amount += $user_person_amount;
  3733. // $this->error(0,$common_nums);
  3734. return $team_amount + $person_amount;
  3735. }
  3736. /**
  3737. * 获取该用户共建联盟
  3738. */
  3739. public function getCommonNums($user_id){
  3740. //先获取共建联盟下用户的id
  3741. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  3742. $new_array_ids =[];
  3743. foreach ($son_ids as $key => $value) {
  3744. # code...
  3745. $son_id = $value['id'];
  3746. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  3747. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  3748. if(count($son_value_ids) > 0) {
  3749. $son_value_ids = array_column($son_value_ids,"id");
  3750. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  3751. }
  3752. }
  3753. return $new_array_ids;
  3754. }
  3755. /**
  3756. * 获取该用户个人联盟
  3757. */
  3758. public function getPersonageNums($user_id){
  3759. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  3760. $new_array_ids =[];
  3761. // return 3343;
  3762. foreach ($son_ids as $key => $value) {
  3763. # code...
  3764. $son_id = $value['id'];
  3765. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  3766. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  3767. if(count($son_value_ids) > 0) {
  3768. $son_value_ids = array_column($son_value_ids,"id");
  3769. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  3770. }
  3771. }
  3772. return $new_array_ids;
  3773. }
  3774. //获取团队递归聚宝盆1
  3775. public function teamPeople( $user_id,$type){
  3776. //var_dump($type);
  3777. //$ftype = 1:大部门,0:小部门
  3778. //业绩小是小部门,业绩大是大部门
  3779. if($type == 1) {
  3780. $list = Db::name("old_user_jbp")
  3781. ->where("spread", $user_id)
  3782. ->where("is_team", 1)
  3783. ->field("user_name, id")
  3784. ->select()
  3785. ->toArray();
  3786. $list = $this->get_yj_amount($list,1);
  3787. $list1 = Db::name("old_user_jbp")
  3788. ->where("spread", $user_id)
  3789. ->where("is_team", 0)
  3790. ->field("user_name, id")
  3791. ->select()
  3792. ->toArray();
  3793. $list1 = $this->get_yj_amount($list1, 0);
  3794. // 检查数组和字段是否存在
  3795. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  3796. // 如果$list的值小于或等于$list1的值,选择$list
  3797. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  3798. return $list1;
  3799. } else {
  3800. return $list;
  3801. }
  3802. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  3803. // 如果只有$list有值,返回$list
  3804. return $list;
  3805. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  3806. // 如果只有$list1有值,返回$list1
  3807. return $list1;
  3808. } else {
  3809. // 如果两个数组都没有该字段,返回空数组
  3810. return [];
  3811. }
  3812. }else if($type == 0) {
  3813. $list = Db::name("old_user_jbp")
  3814. ->where("spread", $user_id)
  3815. ->where("is_team", 1)
  3816. ->field("user_name, id")
  3817. ->select()
  3818. ->toArray();
  3819. $list = $this->get_yj_amount($list,1);
  3820. $list1 = Db::name("old_user_jbp")
  3821. ->where("spread", $user_id)
  3822. ->where("is_team", 0)
  3823. ->field("user_name, id")
  3824. ->select()
  3825. ->toArray();
  3826. $list1 = $this->get_yj_amount($list1, 0);
  3827. // 检查数组和字段是否存在
  3828. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  3829. // 如果$list的值小于或等于$list1的值,选择$list
  3830. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  3831. return $list;
  3832. } else {
  3833. return $list1;
  3834. }
  3835. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  3836. // 如果只有$list有值,返回$list
  3837. return $list;
  3838. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  3839. // 如果只有$list1有值,返回$list1
  3840. return $list1;
  3841. } else {
  3842. // 如果两个数组都没有该字段,返回空数组
  3843. return [];
  3844. }
  3845. }else if($type == 2){
  3846. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid,avatar")->select()->toArray();
  3847. return $list;
  3848. }
  3849. // foreach ($list as $key => $value) {
  3850. // $list[$key]['user_name'] = $value['user_name'] . "业绩";
  3851. // $list[$key]['performance'] = $this->getPerformance($value['id']);
  3852. // //辨别当前是大部门还是小部门。用于显示大小业绩展示
  3853. // $list[$key]['curr_type'] = '';
  3854. // if($type == 1){
  3855. // $list[$key]['curr_type'] = 1;
  3856. // }else if($type == 0){
  3857. // $list[$key]['curr_type'] = 0;
  3858. // }else{
  3859. // $list[$key]['curr_type'] = '';
  3860. // }
  3861. // }
  3862. return $list;
  3863. }
  3864. public function get_yj_amount($list,$type){
  3865. foreach ($list as $key => $value) {
  3866. # code...
  3867. // $amount = $this->getPerformanceOfId($value['id']);
  3868. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  3869. //$list[$key]['total_performance'] = $amount;
  3870. //$performance = $this->getPerformanceOfId($search_name['id']);
  3871. $list[$key]['performance'] = $this->getPerformance($value['id']);
  3872. //辨别当前是大部门还是小部门。用于显示大小业绩展示
  3873. $list[$key]['curr_type'] = '';
  3874. if($type == 1){
  3875. $list[$key]['curr_type'] = 1;
  3876. }else if($type == 0){
  3877. $list[$key]['curr_type'] = 0;
  3878. }else{
  3879. $list[$key]['curr_type'] = '';
  3880. }
  3881. }
  3882. return $list;
  3883. }
  3884. //获取团队递归聚宝盆1
  3885. public function teamPeople_copy( $user_id,$type){
  3886. //var_dump($type);
  3887. //$ftype = 1:大部门,0:小部门
  3888. //$user_id = $this->request->post("user_id");
  3889. //$type = $this->request->post("type",0);
  3890. //查找当前用户id下节点
  3891. if($type == 1) {
  3892. // echo 33;
  3893. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  3894. }else if($type == 0) {
  3895. // echo 44;
  3896. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  3897. }else if($type == 2){
  3898. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid")->select()->toArray();
  3899. return $list;
  3900. }else {
  3901. // echo 55;
  3902. $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  3903. }
  3904. foreach ($list as $key => $value) {
  3905. # code...
  3906. // $amount = $this->getPerformanceOfId($value['id']);
  3907. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  3908. //$list[$key]['total_performance'] = $amount;
  3909. //$performance = $this->getPerformanceOfId($search_name['id']);
  3910. $list[$key]['performance'] = $this->getPerformance($value['id']);
  3911. //辨别当前是大部门还是小部门。用于显示大小业绩展示
  3912. $list[$key]['curr_type'] = '';
  3913. if($type == 1){
  3914. $list[$key]['curr_type'] = 1;
  3915. }else if($type == 0){
  3916. $list[$key]['curr_type'] = 0;
  3917. }else{
  3918. $list[$key]['curr_type'] = '';
  3919. }
  3920. }
  3921. return $list;
  3922. }
  3923. // //获取团队递归聚宝盆1
  3924. // public function teamPeople( $user_id,$type){
  3925. // //$user_id = $this->request->post("user_id");
  3926. // //$type = $this->request->post("type",0);
  3927. // //查找当前用户id下节点
  3928. // if($type == 1) {
  3929. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  3930. // }else if($type == 2) {
  3931. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  3932. // }else {
  3933. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  3934. // }
  3935. // foreach ($list as $key => $value) {
  3936. // # code...
  3937. // $amount = $this->getPerformanceOfId($value['id']);
  3938. // $list[$key]['user_name'] = $value['user_name'] . "-----业绩" . $amount;
  3939. // }
  3940. // return $list;
  3941. // }
  3942. }