Userwallet.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 gold_recharge_log(){
  15. $map = [
  16. 'user_id' => $this->auth->id,
  17. 'log_type'=> 10,
  18. ];
  19. $list = Db::name('user_wallet_log')->field('id,change_value,remain,createtime')->where($map)->order('id desc')->autopage()->select();
  20. $this->success('success',$list);
  21. }
  22. //我的收益,三个数据
  23. public function my_income_count(){
  24. //累计收益
  25. $map = [
  26. 'user_id' => $this->auth->id,
  27. 'log_type'=> ['IN',[21,22,23]],
  28. ];
  29. $income_sum = Db::name('user_wallet_log')->where($map)->sum('change_value');
  30. //可提现总收益
  31. $money_remain = model('wallet')->getwallet($this->auth->id,'money');
  32. //今日收益
  33. $start = strtotime(date('Y-m-d'));
  34. $end = $start + 86399;
  35. $map['createtime'] = ['between',[$start,$end]];
  36. $today_income_sum = Db::name('user_wallet_log')->where($map)->sum('change_value');
  37. $result = [
  38. 'income_sum' => $income_sum,
  39. 'money_remain' => $money_remain,
  40. 'today_income_sum' => $today_income_sum,
  41. ];
  42. $this->success('success',$result);
  43. }
  44. //我的钱包日志
  45. public function my_wallet_log(){
  46. $type = input_post('type',0);
  47. $map = [
  48. 'user_id' => $this->auth->id,
  49. ];
  50. if($type){
  51. $map['log_type'] = $type;
  52. }
  53. $list = Db::name('user_wallet_log')->field('id,change_value,remain,createtime')->where($map)->order('id desc')->autopage()->select();
  54. $this->success('success',$list);
  55. }
  56. //提现配置
  57. public function take_cash_config(){
  58. $data = [
  59. 'money' => model('wallet')->getwallet($this->auth->id,'money'),
  60. 'alipay_account' => $this->auth->alipay_account,
  61. 'min' => 1,
  62. 'max' => 1000,
  63. ];
  64. $this->success('success',$data);
  65. }
  66. //提现
  67. public function take_cash(){
  68. $money = floatval(input_post('money',0));
  69. if(empty($money)){
  70. $this->error();
  71. }
  72. if(empty($this->auth->alipay_account)){
  73. $this->error('请先完善支付宝账号信息');
  74. }
  75. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  76. if($check){
  77. $this->error('您已经申请了提现,请等待审核');
  78. }
  79. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  80. if($money > $user_money){
  81. $this->error('提现金额不能大于可提现余额');
  82. }
  83. $data = [
  84. 'user_id' => $this->auth->id,
  85. 'number' => $money,
  86. 'alipay_account' => $this->auth->alipay_account,
  87. 'status' => 0,
  88. 'createtime' => time(),
  89. 'updatetime' => time(),
  90. ];
  91. Db::name('take_cash')->insertGetId($data);
  92. //审核时候再扣,或者这里先扣,等需求方确认
  93. $this->success('申请成功请等待审核');
  94. }
  95. //提现记录
  96. public function take_cash_log(){
  97. $list = Db::name('take_cash')->where(['user_id'=>$this->auth->id])->autopage()->select();
  98. $this->success('success',$list);
  99. }
  100. }