|
@@ -12,50 +12,107 @@ class Intro extends Api
|
|
|
protected $noNeedLogin = [];
|
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
+ protected $wallet = [];//登录用户的钱包
|
|
|
+
|
|
|
public function __construct(){
|
|
|
parent::__construct();
|
|
|
|
|
|
-
|
|
|
+ $this->wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
|
|
|
}
|
|
|
|
|
|
//首页
|
|
|
public function index(){
|
|
|
- $user = Db::name('user')->field('id,avatar,nickname')->where('id',$this->auth->id)->find();
|
|
|
- $wallet = Db::name('user_wallet')->field('intro_level')->where('user_id',$this->auth->id)->find();
|
|
|
|
|
|
- //团队总业绩
|
|
|
+ $result = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'nickname' => $this->auth->nickname,
|
|
|
+ 'avatar' => localpath_to_netpath($this->auth->avatar),
|
|
|
+ 'intro_level' => $this->wallet['intro_level'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ //累计佣金
|
|
|
+ $result['leijiyongjin'] = Db::name('user_intromoney_log')->where('user_id',$this->auth->id)->where('log_type','IN',[101,102,111])->sum('change_value');
|
|
|
+
|
|
|
+ //下线总数
|
|
|
+ $zhitui_ids = Db::name('user_wallet')->where('intro_uid',$this->auth->id)->column('user_id');//直推
|
|
|
+ $jiantui_ids = Db::name('user_wallet')->where('intro_uid','IN',$zhitui_ids)->column('user_id');//间推
|
|
|
+
|
|
|
+ $result['xiaxianzongshu'] = count($zhitui_ids) + count($jiantui_ids);
|
|
|
+
|
|
|
+ //可提现金额
|
|
|
+ $result['ketixian'] = $this->wallet['intromoney'];
|
|
|
+
|
|
|
+ //待入账金额,下面计算
|
|
|
+ $result['dairuzhang'] = 0;
|
|
|
+
|
|
|
+ //提现中
|
|
|
+ $result['tixianzhong'] = Db::name('intro_user_take_cash')->where('user_id',$this->auth->id)->where('status',0)->sum('money');
|
|
|
+ //已提现
|
|
|
+ $result['yitixian'] = Db::name('intro_user_take_cash')->where('user_id',$this->auth->id)->where('status',1)->sum('money');
|
|
|
+
|
|
|
+ //直推
|
|
|
+ $list = $this->get_my_down_list();
|
|
|
+ $down_uids = array_column($list,'user_id');
|
|
|
+
|
|
|
+ //间推
|
|
|
+ $list2 = $this->get_my_downdown_list($down_uids);
|
|
|
+ $down_down_uids = array_column($list2,'user_id');
|
|
|
+
|
|
|
+ //团队ids
|
|
|
+ $tuandui_ids = array_merge($down_uids,$down_down_uids);
|
|
|
|
|
|
+ //我的团队人数
|
|
|
+ $result['wodetuandui'] = count($tuandui_ids);
|
|
|
+
|
|
|
+ //邀请好友
|
|
|
+ $result['yaoqinghaoyou'] = count($down_uids);
|
|
|
+
|
|
|
+ //分销订单
|
|
|
+ $result['fenxiaodingdan'] = Db::name('pay_order')->where('user_id','IN',$tuandui_ids)->where('table_name','money_recharge')->where('order_status',1)->count();
|
|
|
+
|
|
|
+ //待入账
|
|
|
+
|
|
|
+
|
|
|
+ $this->success('success',$result);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取我的直推
|
|
|
+ private function get_my_down_list(){
|
|
|
$chuju = config('site.intro_chuju_min_money');
|
|
|
|
|
|
- //下级
|
|
|
+ //直推,下级,入金,等级比我低,未出局
|
|
|
$list = Db::name('user_wallet')->alias('uw')
|
|
|
- ->field('user.id,user.nickname,user.avatar,uw.intro_level')
|
|
|
- ->join('user','uw.user_id = user.id','LEFT')
|
|
|
+ ->field('uw.user_id,uw.money,uw.intro_level,uw.intro_uid')
|
|
|
->where('uw.intro_uid',$this->auth->id) //我邀请的
|
|
|
->where('uw.intro_level','neq','-1') //入金了
|
|
|
- ->where('uw.intro_level','elt',$wallet['intro_level']) //等级比我低
|
|
|
-// ->where('uw.money','lt',$chuju) //金额小于500,出局
|
|
|
+ ->where('uw.intro_level','elt',$this->wallet['intro_level']) //等级比我低
|
|
|
+ ->where('uw.money','lt',$chuju) //金额小于500,出局
|
|
|
->select();
|
|
|
|
|
|
- dump($list);
|
|
|
- $down_uids = array_column($list,'id');
|
|
|
+ return !empty($list) ? $list : [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取我的间推
|
|
|
+ private function get_my_downdown_list($down_uids = false){
|
|
|
+ if($down_uids === false){
|
|
|
+ $list = $this->get_my_down_list();
|
|
|
+ $down_uids = array_column($list,'user_id');
|
|
|
+ }
|
|
|
|
|
|
- //下下级
|
|
|
+ $chuju = config('site.intro_chuju_min_money');
|
|
|
|
|
|
+ //间推,下下级,入金,未出局,等级比我低,等级比自己的上级低
|
|
|
$list2 = Db::name('user_wallet')->alias('uw')
|
|
|
- ->field('user.id,user.nickname,user.avatar,uw.intro_level,intro.id as intro_id,intro.intro_level as kkk')
|
|
|
- ->join('user','uw.user_id = user.id','LEFT')
|
|
|
+ ->field('uw.user_id,uw.money,uw.intro_level,uw.intro_uid')
|
|
|
->join('user_wallet intro','uw.intro_uid = intro.user_id','LEFT') //加这里,就是防止:下下级当中,虽然都比我低,但是有可能高于自己的上级(也就是我的直推)
|
|
|
->whereIN('uw.intro_uid',$down_uids) //下下级
|
|
|
->where('uw.intro_level','neq','-1') //入金了
|
|
|
- ->where('uw.intro_level','elt',$wallet['intro_level']) //等级比我低
|
|
|
+ ->where('uw.money','lt',$chuju) //金额小于500,出局
|
|
|
+ ->where('uw.intro_level','elt',$this->wallet['intro_level']) //等级比我低
|
|
|
->where('uw.intro_level <= intro.intro_level') //加这里,就是防止:下下级当中,虽然都比我低,但是有可能高于自己的上级(也就是我的直推)
|
|
|
- ->select(false);
|
|
|
-
|
|
|
- dump($list2);
|
|
|
- $down_down_uids = array_column($list2,'id');
|
|
|
+ ->select();
|
|
|
|
|
|
-// $this->success('success',$list);
|
|
|
+ return !empty($list2) ? $list2 : [];
|
|
|
}
|
|
|
|
|
|
|