Userwallet.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. //我的余额日志
  50. public function my_money_log(){
  51. $type = input_post('type',0);
  52. $map = [
  53. 'user_id' => $this->auth->id,
  54. ];
  55. if($type){
  56. $map['log_type'] = $type;
  57. }
  58. $list = Db::name('user_money_log')->field('id,log_type,change_value,remain,createtime')->where($map)->order('id desc')->autopage()->select();
  59. if(!empty($list)){
  60. $conf = config('wallet.logtype');
  61. foreach($list as $key => $val){
  62. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  63. }
  64. }
  65. $this->success('success',$list);
  66. }
  67. //金币日志
  68. public function my_gold_log(){
  69. $type = input_post('type',0);
  70. $map = [
  71. 'user_id' => $this->auth->id,
  72. ];
  73. if($type){
  74. $map['log_type'] = $type;
  75. }
  76. $list = Db::name('user_gold_log')->field('id,log_type,change_value,remain,createtime')->where($map)->order('id desc')->autopage()->select();
  77. if(!empty($list)){
  78. $conf = config('wallet.logtype');
  79. foreach($list as $key => $val){
  80. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  81. }
  82. }
  83. $this->success('success',$list);
  84. }
  85. //提现配置
  86. public function take_cash_config(){
  87. $data = [
  88. 'money' => model('wallet')->getwallet($this->auth->id,'money'),
  89. 'alipay_account' => $this->auth->alipay_account,
  90. 'min' => 1,
  91. 'max' => 1000,
  92. ];
  93. $this->success('success',$data);
  94. }
  95. //提现
  96. public function take_cash(){
  97. $money = floatval(input_post('money',0));
  98. if(empty($money)){
  99. $this->error();
  100. }
  101. if(empty($this->auth->alipay_account)){
  102. $this->error('请先完善支付宝账号信息');
  103. }
  104. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  105. if($check){
  106. $this->error('您已经申请了提现,请等待审核');
  107. }
  108. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  109. if($money > $user_money){
  110. $this->error('提现金额不能大于可提现余额');
  111. }
  112. $data = [
  113. 'user_id' => $this->auth->id,
  114. 'number' => $money,
  115. 'alipay_account' => $this->auth->alipay_account,
  116. 'status' => 0,
  117. 'createtime' => time(),
  118. 'updatetime' => time(),
  119. ];
  120. Db::name('take_cash')->insertGetId($data);
  121. //审核时候再扣,或者这里先扣,等需求方确认
  122. $this->success('申请成功请等待审核');
  123. }
  124. //提现记录
  125. public function take_cash_log(){
  126. $list = Db::name('take_cash')->where(['user_id'=>$this->auth->id])->autopage()->select();
  127. $this->success('success',$list);
  128. }
  129. }