Userintro.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 用户推荐
  7. */
  8. class Userintro extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //我的收益
  13. public function myprofit(){
  14. //今日
  15. $start = strtotime(date('Y-m-d'));
  16. $end = $start + 86399;
  17. //收益type
  18. $profit_type = [21,22,23,52,54,56];
  19. //今日收益
  20. $map = [
  21. 'log_type' => ['IN',$profit_type],
  22. 'user_id' => $this->auth->id,
  23. 'createtime' => ['between',[$start,$end]],
  24. ];
  25. $today_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  26. //今日视频时长
  27. $map = [
  28. 'user_id|to_user_id' => $this->auth->id,
  29. 'createtime' => ['between',[$start,$end]],
  30. ];
  31. $today_video_min = Db::name('user_match_video_log')->where($map)->sum('call_minutes');
  32. //今日语音时长
  33. $map = [
  34. 'user_id|to_user_id' => $this->auth->id,
  35. 'createtime' => ['between',[$start,$end]],
  36. ];
  37. $today_audio_min = Db::name('user_match_audio_log')->where($map)->sum('call_minutes');
  38. //本周收益
  39. $week_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  40. $week_end = $week_start + 604799;
  41. $map = [
  42. 'log_type' => ['IN',$profit_type],
  43. 'user_id' => $this->auth->id,
  44. 'createtime' => ['between',[$week_start,$week_end]],
  45. ];
  46. $week_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  47. //我的累计收益
  48. $map = [
  49. 'log_type' => ['IN',$profit_type],
  50. 'user_id' => $this->auth->id,
  51. ];
  52. $all_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  53. //我的邀请
  54. $my_intro_number = Db::name('user')->where('intro_uid',$this->auth->id)->count('id');
  55. $result = [
  56. 'avatar' => $this->auth->avatar,
  57. 'nickname' => $this->auth->nickname,
  58. 'username' => $this->auth->username,
  59. 'today_profit' => $today_profit,
  60. 'today_video_min' => $today_video_min,
  61. 'today_audio_min' => $today_audio_min,
  62. 'week_profit' => $week_profit,
  63. 'all_profit' => $all_profit,
  64. 'my_intro_number' => $my_intro_number,
  65. ];
  66. $this->success('success',$result);
  67. }
  68. //我邀请的,成员今日收益
  69. public function myintro(){
  70. $map = [
  71. 'intro_uid' => $this->auth->id,
  72. ];
  73. $list = Db::name('user')->field('id,nickname,username,avatar')->where($map)->page($this->page,$this->listrow)->select();
  74. $rs = [];
  75. foreach($list as $key => $user){
  76. $rs[] = $this->profit($user);
  77. }
  78. //dump($rs);
  79. $this->success('success',$rs);
  80. }
  81. //收益数据
  82. private function profit($userinfo){
  83. $uid = $userinfo['id'];
  84. //今日
  85. $start = strtotime(date('Y-m-d'));
  86. $end = $start + 86399;
  87. //收益type
  88. $profit_type = [21,22,23,52,54,56];
  89. //今日收益
  90. $map = [
  91. 'log_type' => ['IN',$profit_type],
  92. 'user_id' => $uid,
  93. 'createtime' => ['between',[$start,$end]],
  94. ];
  95. $today_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  96. //今日视频时长
  97. $map = [
  98. 'user_id|to_user_id' => $uid,
  99. 'createtime' => ['between',[$start,$end]],
  100. ];
  101. $today_video_min = Db::name('user_match_video_log')->where($map)->sum('call_minutes');
  102. //今日语音时长
  103. $map = [
  104. 'user_id|to_user_id' => $uid,
  105. 'createtime' => ['between',[$start,$end]],
  106. ];
  107. $today_audio_min = Db::name('user_match_audio_log')->where($map)->sum('call_minutes');
  108. //本周收益
  109. $week_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  110. $week_end = $week_start + 604799;
  111. $map = [
  112. 'log_type' => ['IN',$profit_type],
  113. 'user_id' => $uid,
  114. 'createtime' => ['between',[$week_start,$week_end]],
  115. ];
  116. $week_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  117. $result = [
  118. 'today_profit' => $today_profit,
  119. 'today_video_min' => $today_video_min,
  120. 'today_audio_min' => $today_audio_min,
  121. 'week_profit' => $week_profit,
  122. ];
  123. $result = array_merge($result,$userinfo);
  124. return $result;
  125. }
  126. //我的邀请顶部信息
  127. public function myintrotop() {
  128. //获取本周开始时间
  129. $day = 1; // 一周的第一天
  130. $wday = date('w'); // 星期几的数字表示 0(周日)到 6(周六)
  131. $wday_start = strtotime(date('Y-m-d', strtotime('-' . ($wday ? $wday - $day : 6) . ' day'))); // 本周开始日期
  132. $week_map = [
  133. 'log_type' => ['in', [65, 68]],
  134. 'user_id' => $this->auth->id,
  135. 'createtime' => ['egt', $wday_start],
  136. ];
  137. //本周收益
  138. $week_profit = Db::name('user_money_log')->where($week_map)->sum('change_value');
  139. //上周收益
  140. $week_map['createtime'] = ['between', [$wday_start - 86400 * 7, $wday_start]];
  141. $last_week_profit = Db::name('user_money_log')->where($week_map)->sum('change_value');
  142. //本周邀请人数
  143. $week_count = Db::name('user')->where(['intro_uid' => $this->auth->id, 'invite_time' => ['egt', $wday_start]])->count('id');
  144. //上周邀请人数
  145. $last_week_count = Db::name('user')->where(['intro_uid' => $this->auth->id, 'invite_time' => ['between', [$wday_start - 86400 * 7, $wday_start]]])->count('id');
  146. //总邀请人数
  147. $total_count = Db::name('user')->where(['intro_uid' => $this->auth->id])->count('id');
  148. $list = [
  149. 'week_profit' => $week_profit,
  150. 'last_week_profit' => $last_week_profit,
  151. 'week_count' => $week_count,
  152. 'last_week_count' => $last_week_count,
  153. 'total_count' => $total_count,
  154. ];
  155. $this->success('success',$list);
  156. }
  157. //我的邀请
  158. public function myintrolist() {
  159. $map = [
  160. 'intro_uid' => $this->auth->id,
  161. ];
  162. $list = Db::name('user')->field('id,nickname,avatar,invite_time createtime')->where($map)->autopage()->order('invite_time desc')->select();
  163. if (!$list) {
  164. $this->success('success', $list);
  165. }
  166. foreach ($list as &$v) {
  167. $v['avatar'] = one_domain_image($v['avatar']);
  168. $v['createtime'] = date('Y.m.d H:i', $v['createtime']);
  169. }
  170. $this->success('success',$list);
  171. }
  172. //邀请收益
  173. public function introincome() {
  174. $list = Db::name('user_money_log')->field('user_id, sum(change_value) sum')->where(['log_type' => ['in', [65, 66]]])->group('user_id')->order('sum desc')->autopage()->select();
  175. if (!$list) {
  176. $this->success('success', $list);
  177. }
  178. $mt_user = Db::name('user'); //绑定邀请码
  179. foreach ($list as &$v) {
  180. $user_info = $mt_user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
  181. $v['nickname'] = $user_info['nickname'];
  182. $v['avatar'] = one_domain_image($user_info['avatar']);
  183. $v['sum'] = number_format($v['sum'], 2, '.', '');
  184. $v['intro_num'] = $mt_user->where(['intro_uid' => $v['user_id']])->count('id');
  185. }
  186. $this->success('success', $list);
  187. }
  188. }