User.php 200 KB

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