Userwallet.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. //提现配置
  124. public function take_cash_config(){
  125. $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->find();
  126. $data = [
  127. 'money' => model('wallet')->getwallet($this->auth->id,'money'),
  128. 'alipay_account' => ($this->auth->idcard_status == 1 && isset($idcard_confirm['alipay_account'])) ? $idcard_confirm['alipay_account'] : '',
  129. 'min' => 1,
  130. 'max' => 1000,
  131. ];
  132. $this->success('success',$data);
  133. }
  134. //提现
  135. public function take_cash(){
  136. $money = floatval(input_post('money',0));
  137. if(empty($money)){
  138. $this->error();
  139. }
  140. if(empty($this->auth->idcard_status)){
  141. $this->error('请先完成实名认证');
  142. }
  143. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  144. if($check){
  145. $this->error('您已经申请了提现,请等待审核');
  146. }
  147. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  148. if($money > $user_money){
  149. $this->error('提现金额不能大于可提现余额');
  150. }
  151. $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->find();
  152. $data = [
  153. 'user_id' => $this->auth->id,
  154. 'number' => $money,
  155. 'alipay_account' => $idcard_confirm['alipay_account'],
  156. 'status' => 0,
  157. 'createtime' => time(),
  158. 'updatetime' => time(),
  159. ];
  160. Db::name('take_cash')->insertGetId($data);
  161. //审核时候再扣,或者这里先扣,等需求方确认
  162. $this->success('申请成功请等待审核');
  163. }
  164. //提现记录
  165. public function take_cash_log(){
  166. $list = Db::name('take_cash')->where(['user_id'=>$this->auth->id])->autopage()->select();
  167. $this->success('success',$list);
  168. }
  169. }