Money.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 会员中心
  7. */
  8. class Money extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //配置
  13. public function withdraw_config(){
  14. $data = [
  15. 'score' => model('wallet')->getWallet($this->auth->id,'score'),
  16. 'min_withdrawal_money' => config('site.min_withdrawal_money'),
  17. 'max_withdrawal_money' => config('site.max_withdrawal_money'),
  18. 'type_1' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',1)->where('status',1)->field('realname,banknumber,bankname')->find(),
  19. 'type_2' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',2)->where('status',1)->field('realname,banknumber,bankname')->find(),
  20. 'type_3' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',3)->where('status',1)->field('realname,banknumber,bankname')->find(),
  21. ];
  22. $this->success(1,$data);
  23. }
  24. //提现
  25. public function scorewithdraw() {
  26. $type = input('type', 0, 'intval'); //类型:1=支付宝,2=微信,3=银行
  27. $money = input('score', '', 'intval');
  28. if ($money <= 0) {
  29. $this->error('请输入正确兑换金额');
  30. }
  31. $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find();
  32. if($check){
  33. $this->error('目前还有兑换在审核中,请稍后在兑换');
  34. }
  35. //余额查询
  36. $user_money = model('wallet')->getWallet($this->auth->id,'score');
  37. if ($user_money < $money) {
  38. $this->error('余额不足');
  39. }
  40. //查询最低最高提现金额
  41. $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
  42. $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
  43. if ($money < $min_withdrawal_money) {
  44. $this->error('最低提现金额' . $min_withdrawal_money . '元');
  45. }
  46. if ($money > $max_withdrawal_money) {
  47. $this->error('最高提现金额' . $max_withdrawal_money . '元');
  48. }
  49. $data['order_no'] = createUniqueNo('T',$this->auth->id);
  50. $data['user_id'] = $this->auth->id;
  51. $data['score'] = $money;
  52. $data['type'] = $type;
  53. $data['realname'] = input('realname','');
  54. $data['banknumber'] = input('banknumber','');
  55. $data['bankname'] = input('bankname','');
  56. $data['createtime'] = time();
  57. $data['status'] = 0;
  58. //开启事务
  59. Db::startTrans();
  60. //添加提现记录
  61. $log_id = Db::name('user_withdraw')->insertGetId($data);
  62. if (!$log_id) {
  63. Db::rollback();
  64. $this->error('申请兑换失败');
  65. }
  66. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$money,2,'积分兑换','user_withdraw',$log_id);
  67. if ($rs_wallet['status'] == false) {
  68. $this->error($rs_wallet['msg']);
  69. Db::rollback();
  70. }
  71. Db::commit();
  72. $this->success('申请兑换成功,请等待审核');
  73. }
  74. //用户钱包流水
  75. public function scorelog(){
  76. $list = Db::name('user_score_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->autopage()->order('id desc')->select();
  77. foreach($list as $key => &$val){
  78. $val['log_type_text'] = model('wallet')->getlogtype($val['log_type']);
  79. }
  80. $this->success('success',$list);
  81. }
  82. }