Userwallet.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  55. }
  56. }
  57. return $list;
  58. }
  59. //互动收益,打视频,语音,文字聊天,聊天送礼物
  60. public function hudong_money(){
  61. $map = [
  62. 'user_id' => $this->auth->id,
  63. 'log_type'=> ['IN',[21,22,23,54]],
  64. ];
  65. $list = Db::name('user_money_log')
  66. ->field('id,log_type,change_value,remain,remark,createtime')
  67. ->where($map)->order('id desc')->autopage()->select();
  68. $list = $this->list_appen_logtext($list);
  69. $this->success('success',$list);
  70. }
  71. //音聊收益,语聊间礼物
  72. public function party_money(){
  73. $map = [
  74. 'user_id' => $this->auth->id,
  75. 'log_type'=> 52,
  76. ];
  77. $list = Db::name('user_money_log')
  78. ->field('id,log_type,change_value,remain,remark,createtime')
  79. ->where($map)->order('id desc')->autopage()->select();
  80. $list = $this->list_appen_logtext($list);
  81. $this->success('success',$list);
  82. }
  83. //直播收益,直播间礼物
  84. public function livebc_money(){
  85. $map = [
  86. 'user_id' => $this->auth->id,
  87. 'log_type'=> 56,
  88. ];
  89. $list = Db::name('user_money_log')
  90. ->field('id,log_type,change_value,remain,remark,createtime')
  91. ->where($map)->order('id desc')->autopage()->select();
  92. $list = $this->list_appen_logtext($list);
  93. $this->success('success',$list);
  94. }
  95. //我的余额日志
  96. public function my_money_log(){
  97. $type = input_post('type',0);
  98. $map = [
  99. 'user_id' => $this->auth->id,
  100. ];
  101. if($type){
  102. $map['log_type'] = $type;
  103. }
  104. $list = Db::name('user_money_log')
  105. ->field('id,log_type,change_value,remain,remark,createtime')
  106. ->where($map)->order('id desc')->autopage()->select();
  107. $list = $this->list_appen_logtext($list);
  108. $this->success('success',$list);
  109. }
  110. //金币日志
  111. public function my_gold_log(){
  112. $type = input_post('type',0);
  113. $map = [
  114. 'user_id' => $this->auth->id,
  115. ];
  116. if($type){
  117. $map['log_type'] = $type;
  118. }
  119. $list = Db::name('user_gold_log')->field('id,log_type,change_value,remain,createtime')->where($map)->order('id desc')->autopage()->select();
  120. $list = $this->list_appen_logtext($list);
  121. $this->success('success',$list);
  122. }
  123. }