Userintro.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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)->count();
  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)->count();
  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)->count('id');
  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)->count('id');
  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. }