Browse Source

我的邀请

lizhen_gitee 2 years ago
parent
commit
7d27c8540f
2 changed files with 141 additions and 2 deletions
  1. 139 1
      application/api/controller/Userintro.php
  2. 2 1
      application/common/controller/Api.php

+ 139 - 1
application/api/controller/Userintro.php

@@ -13,6 +13,144 @@ class Userintro extends Api
     protected $noNeedRight = ['*'];
 
 
-    //
+    //我的收益
+    public function myprofit(){
+        //今日
+        $start = strtotime(date('Y-m-d'));
+        $end   = $start + 86399;
 
+        //收益type
+        $profit_type = [21,22,23,52,54,56];
+
+        //今日收益
+        $map = [
+            'log_type' => ['IN',$profit_type],
+            'user_id' => $this->auth->id,
+            'createtime' => ['between',[$start,$end]],
+        ];
+        $today_profit = Db::name('user_money_log')->where($map)->sum('change_value');
+
+        //今日视频时长
+        $map = [
+            'user_id|to_user_id' => $this->auth->id,
+            'createtime' => ['between',[$start,$end]],
+        ];
+        $today_video_min = Db::name('user_match_video_log')->where($map)->count();
+
+        //今日语音时长
+        $map = [
+            'user_id|to_user_id' => $this->auth->id,
+            'createtime' => ['between',[$start,$end]],
+        ];
+        $today_audio_min = Db::name('user_match_audio_log')->where($map)->count();
+
+        //本周收益
+        $week_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
+        $week_end   = $week_start + 604799;
+
+        $map = [
+            'log_type' => ['IN',$profit_type],
+            'user_id' => $this->auth->id,
+            'createtime' => ['between',[$week_start,$week_end]],
+        ];
+        $week_profit = Db::name('user_money_log')->where($map)->sum('change_value');
+
+        //我的累计收益
+        $map = [
+            'log_type' => ['IN',$profit_type],
+            'user_id' => $this->auth->id,
+        ];
+        $all_profit = Db::name('user_money_log')->where($map)->sum('change_value');
+
+        //我的邀请
+        $my_intro_number = Db::name('user')->where('intro_uid',$this->auth->id)->count('id');
+
+
+        $result = [
+            'avatar' => $this->auth->avatar,
+            'nickname' => $this->auth->nickname,
+            'username' => $this->auth->username,
+
+            'today_profit' => $today_profit,
+            'today_video_min' => $today_video_min,
+            'today_audio_min' => $today_audio_min,
+            'week_profit' => $week_profit,
+            'all_profit' => $all_profit,
+            'my_intro_number' => $my_intro_number,
+        ];
+
+        $this->success('success',$result);
+
+    }
+
+    //我邀请的,成员今日收益
+    public function myintro(){
+        $map = [
+            'intro_uid' => $this->auth->id,
+        ];
+
+        $list = Db::name('user')->field('id,nickname,username,avatar')->where($map)->page($this->page,$this->listrow)->select();
+
+        $rs = [];
+        foreach($list as $key => $user){
+            $rs[] = $this->profit($user);
+        }
+        //dump($rs);
+        $this->success('success',$rs);
+    }
+
+    //收益数据
+    private function profit($userinfo){
+        $uid = $userinfo['id'];
+        //今日
+        $start = strtotime(date('Y-m-d'));
+        $end   = $start + 86399;
+
+        //收益type
+        $profit_type = [21,22,23,52,54,56];
+
+        //今日收益
+        $map = [
+            'log_type' => ['IN',$profit_type],
+            'user_id' => $uid,
+            'createtime' => ['between',[$start,$end]],
+        ];
+        $today_profit = Db::name('user_money_log')->where($map)->sum('change_value');
+
+        //今日视频时长
+        $map = [
+            'user_id|to_user_id' => $uid,
+            'createtime' => ['between',[$start,$end]],
+        ];
+        $today_video_min = Db::name('user_match_video_log')->where($map)->count('id');
+
+        //今日语音时长
+        $map = [
+            'user_id|to_user_id' => $uid,
+            'createtime' => ['between',[$start,$end]],
+        ];
+        $today_audio_min = Db::name('user_match_audio_log')->where($map)->count('id');
+
+        //本周收益
+        $week_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
+        $week_end   = $week_start + 604799;
+
+        $map = [
+            'log_type' => ['IN',$profit_type],
+            'user_id' => $uid,
+            'createtime' => ['between',[$week_start,$week_end]],
+        ];
+        $week_profit = Db::name('user_money_log')->where($map)->sum('change_value');
+
+        $result = [
+            'today_profit' => $today_profit,
+            'today_video_min' => $today_video_min,
+            'today_audio_min' => $today_audio_min,
+            'week_profit' => $week_profit,
+        ];
+
+        $result = array_merge($result,$userinfo);
+
+        return $result;
+    }
 }

+ 2 - 1
application/common/controller/Api.php

@@ -65,7 +65,7 @@ class Api
     protected $responseType = 'json';
 
     public $page = 1;
-    public $limit = 10;
+    public $listrow = 10;
     /**
      * 构造方法
      * @access public
@@ -75,6 +75,7 @@ class Api
     {
         $this->request = is_null($request) ? Request::instance() : $request;
         $this->page = input('page',1);
+        $this->listrow= input('listrow',10);
         // 控制器初始化
         $this->_initialize();
         //日志