Usercenter.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 会员中心
  7. */
  8. class Usercenter extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //提现
  13. public function moneywithdraw() {
  14. $id = input('id', 0, 'intval'); //提现账号id
  15. $money = input('money', '', 'trim');
  16. if (!$id) {
  17. $this->error('请选择提现账号');
  18. }
  19. $bankinfo = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  20. if (!$bankinfo) {
  21. $this->error('账号不存在');
  22. }
  23. if (!preg_match('/^[0-9]+(.[0-9]{1,8})?$/', $money) || $money <= 0) {
  24. $this->error('请输入正确提现金额');
  25. }
  26. //余额查询
  27. $user_money = model('wallet')->getWallet($this->auth->id,'money');
  28. if ($user_money < $money) {
  29. $this->error('余额不足');
  30. }
  31. //查询最低最高提现金额
  32. $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
  33. $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
  34. if ($money < $min_withdrawal_money) {
  35. $this->error('最低提现金额' . $min_withdrawal_money . '元');
  36. }
  37. if ($money > $max_withdrawal_money) {
  38. $this->error('最高提现金额' . $max_withdrawal_money . '元');
  39. }
  40. //查询提现手续费百分比
  41. $withdrawal_service_fee = (int)config('site.withdrawal_service_fee') ? : 0;
  42. if ($withdrawal_service_fee < 0 || $withdrawal_service_fee >= 100) {
  43. $this->error('提现手续费异常');
  44. }
  45. $real_money = bcdiv(bcmul($money,bcsub(100,$withdrawal_service_fee)),100);
  46. $data['order_no'] = createUniqueNo('T',$this->auth->id);
  47. $data['user_id'] = $this->auth->id;
  48. $data['amount'] = $money;
  49. $data['money'] = $real_money;
  50. $data['user_bank_id'] = $id;
  51. $data['realname'] = $bankinfo['realname'];
  52. $data['banknumber'] = $bankinfo['banknumber'];
  53. $data['bankname'] = $bankinfo['bankname'];
  54. $data['status'] = 0;
  55. $data['createtime'] = time();
  56. //开启事务
  57. Db::startTrans();
  58. //添加提现记录
  59. $log_id = Db::name('user_withdraw')->insertGetId($data);
  60. if (!$log_id) {
  61. Db::rollback();
  62. $this->error('申请提现失败');
  63. }
  64. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'money',$money,4,'提现','user_withdraw',$log_id);
  65. if ($rs_wallet['status'] == false) {
  66. $this->error($rs_wallet['msg']);
  67. Db::rollback();
  68. }
  69. Db::commit();
  70. $this->success('申请提现成功,请等待审核');
  71. }
  72. //用户钱包流水
  73. public function moneylog(){
  74. $list = Db::name('user_money_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->page($this->page,$this->listrow)->select();
  75. foreach($list as $key => &$val){
  76. $val['log_type_text'] = model('wallet')->getlogtype($val['log_type']);
  77. }
  78. $this->success('success',$list);
  79. }
  80. }