Userintro.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 introincome() {
  128. $list = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [64,65,66]]])->autopage()->select();
  129. if (!$list) {
  130. $this->success('success', $list);
  131. }
  132. //64 => '邀请注册奖励',
  133. //65 => '邀请人充值奖励',
  134. //66 => '邀请人获礼物奖励',
  135. $mt_user = Db::name('user'); //绑定邀请码
  136. $mt_pay_order = Db::name('pay_order'); //充值
  137. $mt_gift_user_dongtai = Db::name('gift_user_dongtai'); //动态送礼
  138. // $mt_gift_user_greet = Db::name('gift_user_greet'); //打招呼送礼
  139. $mt_gift_user_typing = Db::name('gift_user_typing'); //聊天送礼
  140. foreach ($list as &$v) {
  141. if ($v['log_type'] == 64) {
  142. $user_id = $v['table_id'];
  143. } elseif ($v['log_type'] == 65) {
  144. $user_id = $mt_pay_order->where(['id' => $v['table_id']])->value('user_id');
  145. } else {
  146. if ($v['remark'] == '打招呼礼物获赠奖励') {
  147. // $user_id = $mt_gift_user_greet->where(['id' => $v['table_id']])->value('user_to_id');
  148. } elseif ($v['remark'] == '聊天礼物获赠奖励') {
  149. $user_id = $mt_gift_user_typing->where(['id' => $v['table_id']])->value('user_to_id');
  150. } else {
  151. $user_id = $mt_gift_user_dongtai->where(['id' => $v['table_id']])->value('user_to_id');
  152. }
  153. }
  154. $user_info = $mt_user->field('nickname, avatar')->where(['id' => $user_id])->find();
  155. $v['nickname'] = $user_info['nickname'];
  156. $v['avatar'] = one_domain_image($user_info['avatar']);
  157. $v['createtime'] = date('Y.m.d H:i', $v['createtime']);
  158. }
  159. $this->success('success', $list);
  160. }*/
  161. //我的邀请顶部信息
  162. public function myintrotop() {
  163. //获取本周开始时间
  164. $day = 1; // 一周的第一天
  165. $wday = date('w'); // 星期几的数字表示 0(周日)到 6(周六)
  166. $wday_start = strtotime(date('Y-m-d', strtotime('-' . ($wday ? $wday - $day : 6) . ' day'))); // 本周开始日期
  167. $week_map = [
  168. 'log_type' => ['in', [65, 68]],
  169. 'user_id' => $this->auth->id,
  170. 'createtime' => ['egt', $wday_start],
  171. ];
  172. //本周收益
  173. $week_profit = Db::name('user_money_log')->where($week_map)->sum('change_value');
  174. //上周收益
  175. $week_map['createtime'] = ['between', [$wday_start - 86400 * 7, $wday_start]];
  176. $last_week_profit = Db::name('user_money_log')->where($week_map)->sum('change_value');
  177. //本周邀请人数
  178. $week_count = Db::name('user')->where(['intro_uid' => $this->auth->id, 'invite_time' => ['egt', $wday_start]])->count('id');
  179. //上周邀请人数
  180. $last_week_count = Db::name('user')->where(['intro_uid' => $this->auth->id, 'invite_time' => ['between', [$wday_start - 86400 * 7, $wday_start]]])->count('id');
  181. //总邀请人数
  182. $total_count = Db::name('user')->where(['intro_uid' => $this->auth->id])->count('id');
  183. $list = [
  184. 'week_profit' => $week_profit,
  185. 'last_week_profit' => $last_week_profit,
  186. 'week_count' => $week_count,
  187. 'last_week_count' => $last_week_count,
  188. 'total_count' => $total_count,
  189. ];
  190. $this->success('success',$list);
  191. }
  192. //我的邀请
  193. public function myintrolist() {
  194. $map = [
  195. 'intro_uid' => $this->auth->id,
  196. ];
  197. $list = Db::name('user')->field('id,nickname,avatar,invite_time createtime')->where($map)->autopage()->order('invite_time desc')->select();
  198. if (!$list) {
  199. $this->success('success', $list);
  200. }
  201. // $mt_take_cash = Db::name('take_cash');
  202. foreach ($list as &$v) {
  203. $v['avatar'] = one_domain_image($v['avatar']);
  204. $v['createtime'] = date('Y.m.d H:i', $v['createtime']);
  205. // $number = $mt_take_cash->where(['user_id' => $v['id'], 'status' => 1])->sum('number');
  206. // $v['cash_money'] = $number ? number_format($number, 2, '.', ''): '0.00';
  207. }
  208. $this->success('success',$list);
  209. }
  210. //邀请收益
  211. public function introincome() {
  212. $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();
  213. if (!$list) {
  214. $this->success('success', $list);
  215. }
  216. $mt_user = Db::name('user'); //绑定邀请码
  217. foreach ($list as &$v) {
  218. $user_info = $mt_user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
  219. $v['nickname'] = $user_info['nickname'];
  220. $v['avatar'] = one_domain_image($user_info['avatar']);
  221. $v['sum'] = number_format($v['sum'], 2, '.', '');
  222. $v['intro_num'] = $mt_user->where(['intro_uid' => $v['user_id']])->count('id');
  223. }
  224. $this->success('success', $list);
  225. }
  226. }