Userwallet.php 8.1 KB

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