User.php 174 KB

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