Userwallet.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. //use app\common\model\wallet;
  6. /**
  7. * 用户钱包
  8. */
  9. class Userwallet extends Api
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['*'];
  13. //我的钱包余额
  14. public function my_wallet(){
  15. $wallet = model('wallet')->getwallet($this->auth->id);
  16. $this->success('success',$wallet);
  17. }
  18. //我的积分日志
  19. public function my_money_log(){
  20. $type = input_post('type',0);
  21. $map = [
  22. 'user_id' => $this->auth->id,
  23. ];
  24. // if($type){
  25. // $map['log_type'] = $type;
  26. // }
  27. $list = Db::name('user_money_log')
  28. ->field('id,log_type,change_value,remain,createtime, remark log_text')
  29. ->where($map)->order('id desc')->autopage()->select();
  30. // $list = $this->list_appen_logtext($list);
  31. if(!empty($list)){
  32. foreach($list as $key => $val){
  33. $list[$key]['createtime'] = date('Y.m.d H:i', $val['createtime']);
  34. }
  35. }
  36. $this->success('success',$list);
  37. }
  38. //金币日志
  39. public function my_gold_log(){
  40. $type = input_post('type',0);
  41. $map = [
  42. 'user_id' => $this->auth->id,
  43. ];
  44. if($type){
  45. $map['log_type'] = $type; //兑换记录
  46. }
  47. $list = Db::name('user_gold_log')
  48. ->field('id,log_type,change_value,remain,createtime, remark log_text')
  49. ->where($map)->order('id desc')->autopage()->select();
  50. // $list = $this->list_appen_logtext($list);
  51. if(!empty($list)){
  52. foreach($list as $key => $val){
  53. $list[$key]['createtime'] = date('Y.m.d H:i', $val['createtime']);
  54. }
  55. }
  56. $this->success('success',$list);
  57. }
  58. //追加log_text
  59. private function list_appen_logtext($list){
  60. if(!empty($list)){
  61. $conf = config('wallet.logtype');
  62. foreach($list as $key => $val){
  63. $list[$key]['createtime'] = date('Y.m.d H:i', $val['createtime']);
  64. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  65. }
  66. }
  67. return $list;
  68. }
  69. //我的收益,三个数据
  70. public function my_income_count(){
  71. //累计收益,不计来源
  72. $map = [
  73. 'user_id' => $this->auth->id,
  74. //'log_type'=> ['IN',[21,22,23]],
  75. ];
  76. $income_sum = Db::name('user_money_log')->where($map)->sum('change_value');
  77. //可提现总收益
  78. $money_remain = model('wallet')->getwallet($this->auth->id,'money');
  79. //今日收益
  80. $start = strtotime(date('Y-m-d'));
  81. $end = $start + 86399;
  82. $map['createtime'] = ['between',[$start,$end]];
  83. $today_income_sum = Db::name('user_money_log')->where($map)->sum('change_value');
  84. $result = [
  85. 'income_sum' => $income_sum,
  86. 'money_remain' => $money_remain,
  87. 'today_income_sum' => $today_income_sum,
  88. ];
  89. $this->success('success',$result);
  90. }
  91. //每日数据
  92. public function todayincome() {
  93. $start = input('time', 0, 'strtotime'); //时间: 2022-09-30
  94. if (!$start) {
  95. $start = strtotime(date('Y-m-d')); //默认今日
  96. }
  97. $end = $start + 86399;
  98. //收益type
  99. $profit_type = [21,22,23,54,58,60,67];
  100. //今日收益
  101. $today_map = [
  102. 'log_type' => ['IN',$profit_type],
  103. 'user_id' => $this->auth->id,
  104. 'createtime' => ['between',[$start,$end]],
  105. ];
  106. $today_profit = Db::name('user_money_log')->where($today_map)->sum('change_value');
  107. //今日视频时长/收益/人数
  108. $map = [
  109. 'to_user_id' => $this->auth->id,
  110. 'createtime' => ['between',[$start,$end]],
  111. ];
  112. $today_video_min = Db::name('user_match_video_log')->where($map)->sum('call_minutes');
  113. $today_video_income = Db::name('user_match_video_log')->where($map)->sum('money');
  114. $today_video_income = $today_video_income ? : 0;
  115. $today_video_user = Db::name('user_match_video_log')->where($map)->column('user_id');
  116. $today_video_user = array_unique($today_video_user);
  117. $today_video_user_num = count($today_video_user);
  118. //今日语音时长/收益/人数
  119. $today_audio_min = Db::name('user_match_audio_log')->where($map)->sum('call_minutes');
  120. $today_audio_income = Db::name('user_match_audio_log')->where($map)->sum('money');
  121. $today_audio_income = $today_audio_income ? : 0;
  122. $today_audio_user = Db::name('user_match_audio_log')->where($map)->column('user_id');
  123. $today_audio_user = array_unique($today_audio_user);
  124. $today_audio_user_num = count($today_audio_user);
  125. //今日时长/收益/人数
  126. $today_time = $today_video_min + $today_audio_min;
  127. $today_time_income = number_format($today_video_income + $today_audio_income, 2, '.', '');
  128. $today_user_num = $today_video_user_num + $today_audio_user_num;
  129. //礼物收益
  130. $gitft_map = [
  131. 'log_type' => ['IN',[54, 58, 60]],
  132. 'user_id' => $this->auth->id,
  133. 'createtime' => ['between',[$start,$end]],
  134. ];
  135. $today_gift_income = Db::name('user_money_log')->where($gitft_map)->sum('change_value');
  136. //私聊时长/收益/人数
  137. $today_chat_min = Db::name('user_match_typing_log')->where($map)->count('id');
  138. $today_chat_income = Db::name('user_match_typing_log')->where($map)->sum('money');
  139. $today_chat_income = $today_chat_income ? : 0;
  140. $today_chat_user = Db::name('user_match_typing_log')->where($map)->column('user_id');
  141. $today_chat_user = array_unique($today_chat_user);
  142. $today_chat_user_num = count($today_chat_user);
  143. //任务收益 客户要求由money改为gold
  144. $today_task_income = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => 67, 'createtime' => ['between',[$start,$end]]])->sum('change_value');
  145. $today_task_income = $today_task_income ? : 0;
  146. $result = [
  147. 'today_profit' => $today_profit,
  148. 'today_time_income' => $today_time_income,
  149. 'today_gift_income' => $today_gift_income,
  150. 'today_chat_income' => $today_chat_income,
  151. 'today_task_income' => $today_task_income,
  152. 'today_time' => $today_time,
  153. 'today_user_num' => $today_user_num,
  154. 'today_chat_min' => $today_chat_min,
  155. 'today_chat_user_num' => $today_chat_user_num
  156. ];
  157. $this->success('success',$result);
  158. }
  159. //每日数据礼物列表
  160. public function todaygiftlist() {
  161. $start = input('time', 0, 'strtotime'); //时间: 09-30
  162. if (!$start) {
  163. $start = strtotime(date('Y-m-d')); //默认今日
  164. }
  165. $end = $start + 86399;
  166. //今日收益
  167. $today_map = [
  168. 'log_type' => ['IN', [54,/*58,*/60]],
  169. 'user_id' => $this->auth->id,
  170. 'createtime' => ['between',[$start,$end]],
  171. ];
  172. $list = Db::name('user_money_log')->where($today_map)->autopage()->order('id desc')->select();
  173. if (!$list) {
  174. $this->success('success', $list);
  175. }
  176. $mt_gift_user_typing = Db::name('gift_user_typing'); //54
  177. // $mt_gift_user_greet = Db::name('gift_user_greet'); //58
  178. $mt_gift_user_dongtai = Db::name('gift_user_dongtai'); //60
  179. foreach ($list as &$v) {
  180. if ($v['log_type'] == 54) {
  181. $table = $mt_gift_user_typing;
  182. }/* elseif ($v['log_type'] == 58) {
  183. $table = $mt_gift_user_greet;
  184. } */else {
  185. $table = $mt_gift_user_dongtai;
  186. }
  187. $info = $table->where(['id' => $v['table_id']])->find();
  188. $v['gift_name'] = $info['gift_name'];
  189. $v['number'] = $info['number'];
  190. }
  191. $this->success('success', $list);
  192. }
  193. }