Userwallet.php 8.3 KB

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