Browse Source

fix:小程序二维码

super-yimizi 1 day ago
parent
commit
5464b3a933

+ 53 - 25
application/api/controller/Withdraw.php

@@ -6,6 +6,7 @@ use think\Db;
 use think\exception\HttpResponseException;
 use think\exception\HttpResponseException;
 use app\common\model\Withdraw as WithdrawModel;
 use app\common\model\Withdraw as WithdrawModel;
 use app\common\Service\Withdraw as WithdrawService;
 use app\common\Service\Withdraw as WithdrawService;
+use app\api\validate\Withdraw as WithdrawValidate;
 
 
 class Withdraw extends Base
 class Withdraw extends Base
 {
 {
@@ -17,15 +18,22 @@ class Withdraw extends Base
     {
     {
         $params = $this->request->param();
         $params = $this->request->param();
         
         
-        // 验证分页参数
-        $this->validate($params, 'Withdraw.index');
+        // 使用验证器验证分页参数
+        $validate = new WithdrawValidate();
+        if (!$validate->scene('index')->check($params)) {
+            $this->error($validate->getError());
+        }
         
         
         $user = auth_user();
         $user = auth_user();
+        
+        // 使用验证后的参数
+        $page_size = isset($params['page_size']) ? (int)$params['page_size'] : 10;
+        
         $withdraws = WithdrawModel::where(['user_id' => $user->id])
         $withdraws = WithdrawModel::where(['user_id' => $user->id])
             ->order('id desc')
             ->order('id desc')
-            ->paginate($this->request->param('page_size', 10))->each(function ($withdraw) {
-            $withdraw->hidden(['withdraw_info']);
-        });
+            ->paginate($page_size)->each(function ($withdraw) {
+                $withdraw->hidden(['withdraw_info']);
+            });
 
 
         $this->success('获取成功', $withdraws);
         $this->success('获取成功', $withdraws);
     }
     }
@@ -47,15 +55,21 @@ class Withdraw extends Base
         $user = auth_user();
         $user = auth_user();
         $params = $this->request->param();
         $params = $this->request->param();
 
 
-        $this->validate($params, 'Withdraw.apply');
+        // 使用验证器验证提现参数:type, amount, account_id
+        $validate = new WithdrawValidate();
+        if (!$validate->scene('apply')->check($params)) {
+            $this->error($validate->getError());
+        }
 
 
         $withdrawService = new WithdrawService($user);
         $withdrawService = new WithdrawService($user);
-        // 申请提现
+        
+        // 申请提现 - 使用事务确保数据一致性
         Db::startTrans();
         Db::startTrans();
         try {
         try {
             $withdraw = $withdrawService->apply($params);
             $withdraw = $withdrawService->apply($params);
             Db::commit();
             Db::commit();
         } catch (HttpResponseException $e) {
         } catch (HttpResponseException $e) {
+            Db::rollback();
             $data = $e->getResponse()->getData();
             $data = $e->getResponse()->getData();
             $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
             $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
             $this->error($message);
             $this->error($message);
@@ -107,57 +121,71 @@ class Withdraw extends Base
         $user = auth_user();
         $user = auth_user();
         $params = $this->request->param();
         $params = $this->request->param();
 
 
-        $this->validate($params, 'Withdraw.transfer');
+        // 使用验证器验证转账参数:type, withdraw_sn
+        $validate = new WithdrawValidate();
+        if (!$validate->scene('transfer')->check($params)) {
+            $this->error($validate->getError());
+        }
 
 
         $withdrawService = new WithdrawService($user);
         $withdrawService = new WithdrawService($user);
-        // 如果 微信提现, result 为 package_info,其他的为 withdrawModel 对象
-        $result = $withdrawService->retry($params);
-
-        $this->success('操作成功', $result);
+        
+        try {
+            // 如果 微信提现, result 为 package_info,其他的为 withdrawModel 对象
+            $result = $withdrawService->retry($params);
+            $this->success('操作成功', $result);
+        } catch (\Exception $e) {
+            $this->error($e->getMessage());
+        }
     }
     }
 
 
     // 取消提现(仅支持微信商家转账)
     // 取消提现(仅支持微信商家转账)
     public function cancel()
     public function cancel()
     {
     {
-
         $user = auth_user();
         $user = auth_user();
         $params = $this->request->param();
         $params = $this->request->param();
 
 
-        $this->validate($params, 'Withdraw.cancel');
+        // 使用验证器验证取消参数:type, withdraw_sn
+        $validate = new WithdrawValidate();
+        if (!$validate->scene('cancel')->check($params)) {
+            $this->error($validate->getError());
+        }
 
 
         $withdrawService = new WithdrawService($user);
         $withdrawService = new WithdrawService($user);
 
 
         try {
         try {
             $result = $withdrawService->cancel($params);
             $result = $withdrawService->cancel($params);
+            $this->success('操作成功', $result);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             $this->error($e->getMessage());
             $this->error($e->getMessage());
         }
         }
-
-        $this->success('操作成功', $result);
     }
     }
 
 
-    // 取消提现(仅支持微信商家转账)
+    // 重试提现(仅支持微信商家转账)
     public function retry()
     public function retry()
     {
     {
         $user = auth_user();
         $user = auth_user();
         $params = $this->request->param();
         $params = $this->request->param();
 
 
-        $this->validate($params, 'Withdraw.retry');
+        // 使用验证器验证重试参数:type, withdraw_sn
+        $validate = new WithdrawValidate();
+        if (!$validate->scene('retry')->check($params)) {
+            $this->error($validate->getError());
+        }
 
 
         $withdrawService = new WithdrawService($user);
         $withdrawService = new WithdrawService($user);
 
 
         try {
         try {
             $withdraw = $withdrawService->retry($params);
             $withdraw = $withdrawService->retry($params);
             $transferData = $withdrawService->handleWechatTransfer($withdraw);
             $transferData = $withdrawService->handleWechatTransfer($withdraw);
+            
+            $this->success('申请成功', [
+                'id' => $withdraw->id,
+                'type' => $withdraw->withdraw_type,
+                'withdraw_sn' => $withdraw->withdraw_sn,
+                'transfer_data' => $transferData ?? null,
+            ]);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             $this->error($e->getMessage());
             $this->error($e->getMessage());
         }
         }
-
-        $this->success('申请成功', [
-            'id' => $withdraw->id,
-            'type' => $withdraw->withdraw_type,
-            'withdraw_sn' => $withdraw->withdraw_sn,
-            'transfer_data' => $transferData ?? null,
-        ]);
     }
     }
 }
 }

+ 11 - 12
application/api/validate/Withdraw.php

@@ -7,11 +7,9 @@ use think\Validate;
 class Withdraw extends Validate
 class Withdraw extends Validate
 {
 {
     protected $rule = [
     protected $rule = [
-        'type' => 'require',
-        'money' => 'require|float|gt:0',
-        'account_name' => 'require',
-        'account_no' => 'requireIfAll:type,alipay,bank',
-        'account_header' => 'requireIf:type,bank',
+        'type' => 'require|in:wechat,alipay,bank',
+        'amount' => 'require|float|gt:0',
+        'account_id' => 'require|integer|gt:0',
         'withdraw_sn' => 'require',
         'withdraw_sn' => 'require',
         'page' => 'integer|egt:1',
         'page' => 'integer|egt:1',
         'page_size' => 'integer|between:1,100',
         'page_size' => 'integer|between:1,100',
@@ -19,12 +17,13 @@ class Withdraw extends Validate
 
 
     protected $message = [
     protected $message = [
         'type.require' => '请选择提现类型',
         'type.require' => '请选择提现类型',
-        'money.require' => '请输入提现金额',
-        'money.float' => '请输入正确的提现金额',
-        'money.gt' => '请输入正确的提现金额',
-        'account_name.require' => '请填写真实姓名',
-        'account_no.requireIfAll' => '请填写账号信息',
-        'account_header.requireIf' => '请填写开户行',
+        'type.in' => '请选择正确的提现类型',
+        'amount.require' => '请输入提现金额',
+        'amount.float' => '请输入正确的提现金额',
+        'amount.gt' => '请输入正确的提现金额',
+        'account_id.require' => '请选择提现账户',
+        'account_id.integer' => '账户ID必须为整数',
+        'account_id.gt' => '请选择正确的提现账户',
         'withdraw_sn.require' => '未找到您的提现信息',
         'withdraw_sn.require' => '未找到您的提现信息',
         'page.integer' => '页码必须为整数',
         'page.integer' => '页码必须为整数',
         'page.egt' => '页码必须大于等于1',
         'page.egt' => '页码必须大于等于1',
@@ -34,7 +33,7 @@ class Withdraw extends Validate
 
 
     protected $scene = [
     protected $scene = [
         'index' => ['page', 'page_size'],
         'index' => ['page', 'page_size'],
-        'apply' => ['type', 'money', 'account_name', 'account_no', 'account_header'],
+        'apply' => ['type', 'amount', 'account_id'],
         'transfer' => ['type', 'withdraw_sn'],
         'transfer' => ['type', 'withdraw_sn'],
         'retry' => ['type', 'withdraw_sn'],
         'retry' => ['type', 'withdraw_sn'],
         'cancel' => ['type', 'withdraw_sn'],
         'cancel' => ['type', 'withdraw_sn'],

+ 21 - 0
application/common.php

@@ -89,6 +89,27 @@ if (!function_exists('account_hide')) {
     }
     }
 }
 }
 
 
+if (!function_exists('get_sn')) {
+    /**
+     * 获取唯一编号
+     *
+     * @param mixed $id       唯一标识
+     * @param string $type    类型
+     * @return string
+     */
+    function get_sn($id, $type = '')
+    {
+        $id = (string)$id;
+
+        $rand = $id < 9999 ? mt_rand(100000, 99999999) : mt_rand(100, 99999);
+        $sn = date('Yhis') . $rand;
+
+        $id = str_pad($id, (24 - strlen($sn)), '0', STR_PAD_BOTH);
+
+        return $type . $sn . $id;
+    }
+}
+
 
 
 
 
 
 

+ 2 - 2
application/common/Service/Wallet.php

@@ -4,11 +4,11 @@ namespace app\common\Service;
 
 
 use think\exception\HttpResponseException;
 use think\exception\HttpResponseException;
 use app\common\model\User as UserModel;
 use app\common\model\User as UserModel;
-use app\common\model\WalletLog;
+use app\common\model\user\WalletLog;
 use app\common\library\Operator;
 use app\common\library\Operator;
 use app\common\model\MoneyLog;
 use app\common\model\MoneyLog;
 use app\common\model\ScoreLog;
 use app\common\model\ScoreLog;
-use app\common\exception\BusinessException
+use app\common\exception\BusinessException;
 class Wallet
 class Wallet
 {
 {
     /**
     /**

+ 65 - 51
application/common/Service/Withdraw.php

@@ -9,9 +9,10 @@ use think\exception\HttpResponseException;
 use app\common\model\Withdraw as WithdrawModel;
 use app\common\model\Withdraw as WithdrawModel;
 use app\common\model\WithdrawLog as WithdrawLogModel;
 use app\common\model\WithdrawLog as WithdrawLogModel;
 use app\common\library\Operator;
 use app\common\library\Operator;
+use app\common\library\BcMath;
 use app\common\model\ThirdOauth;
 use app\common\model\ThirdOauth;
 use app\common\Service\Wallet as WalletService;
 use app\common\Service\Wallet as WalletService;
-use app\common\Pay\PayService;
+use app\common\Service\Pay\PayService;
 use app\common\model\User;
 use app\common\model\User;
 
 
 class Withdraw
 class Withdraw
@@ -32,10 +33,10 @@ class Withdraw
 
 
         // 提现规则
         // 提现规则
         $config = shop_config('shop.withdraw');
         $config = shop_config('shop.withdraw');
-        $config['min_amount'] = $config['min_amount'] == 0 ? $config['min_amount'] : number_format(floatval($config['min_amount']), 2, '.', '');
-        $config['max_amount'] = $config['max_amount'] == 0 ? $config['max_amount'] : number_format(floatval($config['max_amount']), 2, '.', '');
+        $config['min_amount'] = BcMath::isZero($config['min_amount']) ? $config['min_amount'] : BcMath::format($config['min_amount'], 2);
+        $config['max_amount'] = BcMath::isZero($config['max_amount']) ? $config['max_amount'] : BcMath::format($config['max_amount'], 2);
         $config['charge_rate_format'] = round(floatval($config['charge_rate']), 1);      // 1 位小数
         $config['charge_rate_format'] = round(floatval($config['charge_rate']), 1);      // 1 位小数
-        $config['charge_rate'] = round((floatval($config['charge_rate']) * 0.01), 3);
+        $config['charge_rate'] = BcMath::div($config['charge_rate'], '100', 3);
         $config['num_unit'] = $config['num_unit'] == 'day' ? '天' : '月';
         $config['num_unit'] = $config['num_unit'] == 'day' ? '天' : '月';
 
 
         $this->config = $config;
         $this->config = $config;
@@ -46,11 +47,11 @@ class Withdraw
     public function apply($params)
     public function apply($params)
     {
     {
         $type = $params['type'];
         $type = $params['type'];
-        $money = $params['money'] ?? 0;
+        $money = $params['amount'] ?? 0;  // money 改为 amount
         $money = (string)$money;
         $money = (string)$money;
 
 
         // 手续费
         // 手续费
-        $charge = bcmul($money, (string)$this->config['charge_rate'], 2);
+        $charge = BcMath::mul($money, $this->config['charge_rate'], 2);
 
 
         // 检查提现规则
         // 检查提现规则
         $this->checkApply($type, $money, $charge);
         $this->checkApply($type, $money, $charge);
@@ -71,7 +72,7 @@ class Withdraw
         $withdraw->save();
         $withdraw->save();
 
 
         // 佣金钱包变动
         // 佣金钱包变动
-        WalletService::change($this->user, 'commission', -bcadd($charge, $money, 2), 'withdraw', [
+        WalletService::change($this->user, 'commission', '-' . BcMath::add($charge, $money, 2), 'withdraw', [
             'withdraw_id' => $withdraw->id,
             'withdraw_id' => $withdraw->id,
             'amount' => $withdraw->amount,
             'amount' => $withdraw->amount,
             'charge_fee' => $withdraw->charge_fee,
             'charge_fee' => $withdraw->charge_fee,
@@ -94,10 +95,10 @@ class Withdraw
             ->find();
             ->find();
 
 
         if (!$withdraw) {
         if (!$withdraw) {
-            throw new ShoproException('提现记录不存在');
+            throw new BusinessException('提现记录不存在');
         }
         }
         if (request()->header('platform') !== $withdraw->platform) {
         if (request()->header('platform') !== $withdraw->platform) {
-            throw new ShoproException('请在发起该次提现的平台操作');
+            throw new BusinessException('请在发起该次提现的平台操作');
         }
         }
 
 
         $this->handleLog($withdraw, '用户重新发起提现申请');
         $this->handleLog($withdraw, '用户重新发起提现申请');
@@ -115,18 +116,18 @@ class Withdraw
             ->find();
             ->find();
 
 
         if (!$withdraw) {
         if (!$withdraw) {
-            throw new ShoproException('提现记录不存在');
+            throw new BusinessException('提现记录不存在');
         }
         }
 
 
         if (request()->header('platform') !== $withdraw->platform) {
         if (request()->header('platform') !== $withdraw->platform) {
-            throw new ShoproException('请在发起该次提现的平台操作');
+            throw new BusinessException('请在发起该次提现的平台操作');
         }
         }
 
 
         // 实时检查提现单状态
         // 实时检查提现单状态
         $withdraw = $this->checkWechatTransferResult($withdraw);
         $withdraw = $this->checkWechatTransferResult($withdraw);
 
 
         if ($withdraw->wechat_transfer_state !== 'WAIT_USER_CONFIRM') {
         if ($withdraw->wechat_transfer_state !== 'WAIT_USER_CONFIRM') {
-            throw new ShoproException('该提现单暂无法发起取消操作,请联系客服');
+            throw new BusinessException('该提现单暂无法发起取消操作,请联系客服');
         }
         }
         // 提交微信撤销单
         // 提交微信撤销单
         $payService = new PayService($withdraw->withdraw_type, $withdraw->platform);
         $payService = new PayService($withdraw->withdraw_type, $withdraw->platform);
@@ -138,7 +139,7 @@ class Withdraw
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             \think\Log::error('撤销提现失败: ' . ': 行号: ' . $e->getLine() . ': 文件: ' . $e->getFile() . ': 错误信息: ' . $e->getMessage());
             \think\Log::error('撤销提现失败: ' . ': 行号: ' . $e->getLine() . ': 文件: ' . $e->getFile() . ': 错误信息: ' . $e->getMessage());
             $this->handleLog($withdraw, '撤销微信商家转账失败: ' . $e->getMessage());
             $this->handleLog($withdraw, '撤销微信商家转账失败: ' . $e->getMessage());
-            throw new ShoproException($e->getMessage());
+            throw new BusinessException($e->getMessage());
         }
         }
 
 
         $withdraw->wechat_transfer_state = $result['state'];
         $withdraw->wechat_transfer_state = $result['state'];
@@ -181,7 +182,7 @@ class Withdraw
             // $withdraw->wechat_transfer_state = 'NOT_FOUND';
             // $withdraw->wechat_transfer_state = 'NOT_FOUND';
             $withdraw->save();
             $withdraw->save();
             $this->handleFail($withdraw, $e->getMessage());
             $this->handleFail($withdraw, $e->getMessage());
-            throw new ShoproException($e->getMessage());
+            throw new BusinessException($e->getMessage());
         }
         }
 
 
         // 发起提现失败,自动处理退还佣金
         // 发起提现失败,自动处理退还佣金
@@ -199,16 +200,16 @@ class Withdraw
             $withdraw = $this->handleWithdraw($withdraw, $this->user);
             $withdraw = $this->handleWithdraw($withdraw, $this->user);
 
 
             Db::commit();
             Db::commit();
-        } catch (ShoproException $e) {
+        } catch (BusinessException $e) {
             Db::commit();       // 不回滚,记录错误日志
             Db::commit();       // 不回滚,记录错误日志
-            throw new ShoproException($e->getMessage());
+            throw new BusinessException($e->getMessage());
         } catch (HttpResponseException $e) {
         } catch (HttpResponseException $e) {
             $data = $e->getResponse()->getData();
             $data = $e->getResponse()->getData();
             $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
             $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
-            throw new ShoproException($message);
+            throw new BusinessException($message);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             Db::rollback();
             Db::rollback();
-            throw new ShoproException($e->getMessage());
+            throw new BusinessException($e->getMessage());
         }
         }
     }
     }
 
 
@@ -218,7 +219,7 @@ class Withdraw
     public function handleAgree($withdraw, $oper = null)
     public function handleAgree($withdraw, $oper = null)
     {
     {
         if ($withdraw->status != 0) {
         if ($withdraw->status != 0) {
-            throw new ShoproException('请勿重复操作');
+            throw new BusinessException('请勿重复操作');
         }
         }
         $withdraw->status = 1;
         $withdraw->status = 1;
         $withdraw->save();
         $withdraw->save();
@@ -230,7 +231,7 @@ class Withdraw
     {
     {
         $withDrawStatus = false;
         $withDrawStatus = false;
         if ($withdraw->status != 1) {
         if ($withdraw->status != 1) {
-            throw new ShoproException('请勿重复操作');
+            throw new BusinessException('请勿重复操作');
         }
         }
         if ($withdraw->withdraw_type !== 'bank') {
         if ($withdraw->withdraw_type !== 'bank') {
             $withDrawStatus = $this->handleTransfer($withdraw);
             $withDrawStatus = $this->handleTransfer($withdraw);
@@ -250,13 +251,13 @@ class Withdraw
     public function handleRefuse($withdraw, $refuse_msg)
     public function handleRefuse($withdraw, $refuse_msg)
     {
     {
         if ($withdraw->status != 0 && $withdraw->status != 1) {
         if ($withdraw->status != 0 && $withdraw->status != 1) {
-            throw new ShoproException('请勿重复操作');
+            throw new BusinessException('请勿重复操作');
         }
         }
         $withdraw->status = -1;
         $withdraw->status = -1;
         $withdraw->save();
         $withdraw->save();
 
 
         // 退回用户佣金
         // 退回用户佣金
-        WalletService::change($this->user, 'commission', bcadd($withdraw->charge_fee, $withdraw->amount, 2), 'withdraw_error', [
+        WalletService::change($this->user, 'commission', BcMath::add($withdraw->charge_fee, $withdraw->amount, 2), 'withdraw_error', [
             'withdraw_id' => $withdraw->id,
             'withdraw_id' => $withdraw->id,
             'amount' => $withdraw->amount,
             'amount' => $withdraw->amount,
             'charge_fee' => $withdraw->charge_fee,
             'charge_fee' => $withdraw->charge_fee,
@@ -271,13 +272,13 @@ class Withdraw
     public function handleFail($withdraw, $refuse_msg, $status = -2)
     public function handleFail($withdraw, $refuse_msg, $status = -2)
     {
     {
         if ($withdraw->status != 0 && $withdraw->status != 1) {
         if ($withdraw->status != 0 && $withdraw->status != 1) {
-            throw new ShoproException('请勿重复操作');
+            throw new BusinessException('请勿重复操作');
         }
         }
         $withdraw->status = $status;
         $withdraw->status = $status;
         $withdraw->save();
         $withdraw->save();
 
 
         // 退回用户佣金
         // 退回用户佣金
-        WalletService::change($this->user, 'commission', bcadd($withdraw->charge_fee, $withdraw->amount, 2), 'withdraw_error', [
+        WalletService::change($this->user, 'commission', BcMath::add($withdraw->charge_fee, $withdraw->amount, 2), 'withdraw_error', [
             'withdraw_id' => $withdraw->id,
             'withdraw_id' => $withdraw->id,
             'amount' => $withdraw->amount,
             'amount' => $withdraw->amount,
             'charge_fee' => $withdraw->charge_fee,
             'charge_fee' => $withdraw->charge_fee,
@@ -293,17 +294,17 @@ class Withdraw
     {
     {
         $withdraw = WithdrawModel::where('withdraw_sn', $withdrawSn)->find();
         $withdraw = WithdrawModel::where('withdraw_sn', $withdrawSn)->find();
         if (!$withdraw) {
         if (!$withdraw) {
-            throw new ShoproException('提现记录不存在');
+            throw new BusinessException('提现记录不存在');
         }
         }
 
 
         if ($withdraw->status !== 1) {
         if ($withdraw->status !== 1) {
-            throw new ShoproException('提现记录状态不正确');
+            throw new BusinessException('提现记录状态不正确');
         }
         }
 
 
         $this->user = User::get($withdraw->user_id);
         $this->user = User::get($withdraw->user_id);
 
 
         if (!$this->user) {
         if (!$this->user) {
-            throw new ShoproException('用户不存在');
+            throw new BusinessException('用户不存在');
         }
         }
 
 
         $withdraw->wechat_transfer_state = $action;
         $withdraw->wechat_transfer_state = $action;
@@ -331,7 +332,7 @@ class Withdraw
     public function checkWechatTransferResult($withdraw)
     public function checkWechatTransferResult($withdraw)
     {
     {
         if ($withdraw->createtime < strtotime('-30 day')) {
         if ($withdraw->createtime < strtotime('-30 day')) {
-            throw new ShoproException('提现单据已过期,请联系客服解决');
+            throw new BusinessException('提现单据已过期,请联系客服解决');
         }
         }
         $payService = new PayService($withdraw->withdraw_type, $withdraw->platform);
         $payService = new PayService($withdraw->withdraw_type, $withdraw->platform);
 
 
@@ -349,7 +350,6 @@ class Withdraw
     // 企业付款提现
     // 企业付款提现
     private function handleTransfer($withdraw)
     private function handleTransfer($withdraw)
     {
     {
-        operate_disabled();
         $type = $withdraw->withdraw_type;
         $type = $withdraw->withdraw_type;
         $platform = $withdraw->platform;
         $platform = $withdraw->platform;
 
 
@@ -378,15 +378,15 @@ class Withdraw
                 $withdraw->save();
                 $withdraw->save();
                 return true;
                 return true;
             }
             }
-            throw new ShoproException(json_encode($response, JSON_UNESCAPED_UNICODE));
+            throw new BusinessException(json_encode($response, JSON_UNESCAPED_UNICODE));
         } catch (HttpResponseException $e) {
         } catch (HttpResponseException $e) {
             $data = $e->getResponse()->getData();
             $data = $e->getResponse()->getData();
             $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
             $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
-            throw new ShoproException($message);
+            throw new BusinessException($message);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             \think\Log::error('提现失败:' . ' 行号:' . $e->getLine() . '文件:' . $e->getFile() . '错误信息:' . $e->getMessage());
             \think\Log::error('提现失败:' . ' 行号:' . $e->getLine() . '文件:' . $e->getFile() . '错误信息:' . $e->getMessage());
             $this->handleLog($withdraw, '提现失败:' . $e->getMessage());
             $this->handleLog($withdraw, '提现失败:' . $e->getMessage());
-            throw new ShoproException($e->getMessage());     // 弹出错误信息
+            throw new BusinessException($e->getMessage());     // 弹出错误信息
         }
         }
         return false;
         return false;
     }
     }
@@ -412,25 +412,28 @@ class Withdraw
     private function checkApply($type, $money, $charge)
     private function checkApply($type, $money, $charge)
     {
     {
         if (!in_array($type, $this->config['methods'])) {
         if (!in_array($type, $this->config['methods'])) {
-            throw new ShoproException('暂不支持该提现方式');
+            throw new BusinessException('暂不支持该提现方式');
         }
         }
 
 
-        if ($money <= 0) {
-            throw new ShoproException('请输入正确的提现金额');
+        // 使用BC数学函数检查金额是否大于0
+        if (!BcMath::isPositive($money)) {
+            throw new BusinessException('请输入正确的提现金额');
         }
         }
 
 
         // 检查最小提现金额
         // 检查最小提现金额
-        if ($this->config['min_amount'] > 0 && $money < $this->config['min_amount']) {
-            throw new ShoproException('提现金额不能少于 ' . $this->config['min_amount'] . '元');
+        if (BcMath::isPositive($this->config['min_amount']) && BcMath::comp($money, $this->config['min_amount']) < 0) {
+            throw new BusinessException('提现金额不能少于 ' . $this->config['min_amount'] . '元');
         }
         }
+        
         // 检查最大提现金额
         // 检查最大提现金额
-        if ($this->config['max_amount'] > 0 && $money > $this->config['max_amount']) {
-            throw new ShoproException('提现金额不能大于 ' . $this->config['max_amount'] . '元');
+        if (BcMath::isPositive($this->config['max_amount']) && BcMath::comp($money, $this->config['max_amount']) > 0) {
+            throw new BusinessException('提现金额不能大于 ' . $this->config['max_amount'] . '元');
         }
         }
 
 
-
-        if ($this->user->commission < bcadd($charge, $money, 2)) {
-            throw new ShoproException('可提现佣金不足');
+        // 检查用户佣金余额是否足够
+        $totalAmount = BcMath::add($charge, $money, 2);
+        if (BcMath::comp($this->user->commission, $totalAmount) < 0) {
+            throw new BusinessException('可提现佣金不足');
         }
         }
 
 
         // 检查最大提现次数
         // 检查最大提现次数
@@ -440,7 +443,7 @@ class Withdraw
             $num = WithdrawModel::where('user_id', $this->user->id)->where('createtime', '>=', $start_time)->count();
             $num = WithdrawModel::where('user_id', $this->user->id)->where('createtime', '>=', $start_time)->count();
 
 
             if ($num >= $this->config['max_num']) {
             if ($num >= $this->config['max_num']) {
-                throw new ShoproException('每' . ($this->config['num_unit'] == 'day' ? '日' : '月') . '提现次数不能大于 ' . $this->config['max_num'] . '次');
+                throw new BusinessException('每' . ($this->config['num_unit'] == 'day' ? '日' : '月') . '提现次数不能大于 ' . $this->config['max_num'] . '次');
             }
             }
         }
         }
     }
     }
@@ -449,6 +452,17 @@ class Withdraw
     // 获取提现账户信息
     // 获取提现账户信息
     private function getAccountInfo($type, $params)
     private function getAccountInfo($type, $params)
     {
     {
+        // 根据账户ID查询账户信息
+        $account = \app\common\model\user\Account::where([
+            'id' => $params['account_id'],
+            'user_id' => $this->user->id,
+            'type' => $type
+        ])->find();
+        
+        if (!$account) {
+            throw new BusinessException('账户信息不存在');
+        }
+        
         $platform = request()->header('platform');
         $platform = request()->header('platform');
 
 
         switch ($type) {
         switch ($type) {
@@ -460,30 +474,30 @@ class Withdraw
                 }
                 }
                 $thirdOauth = ThirdOauth::where('provider', 'wechat')->where('platform', $platform)->where('user_id', $this->user->id)->find();
                 $thirdOauth = ThirdOauth::where('provider', 'wechat')->where('platform', $platform)->where('user_id', $this->user->id)->find();
                 if (!$thirdOauth) {
                 if (!$thirdOauth) {
-                    throw new ShoproException('请先绑定微信账号', -1);
+                    throw new BusinessException('请先绑定微信账号', -1);
                 }
                 }
                 $withdrawInfo = [
                 $withdrawInfo = [
-                    '真实姓名' => $params['account_name'],
+                    '真实姓名' => $account->account_name,
                     '微信用户' => $thirdOauth['nickname'] ?: $this->user['nickname'],
                     '微信用户' => $thirdOauth['nickname'] ?: $this->user['nickname'],
                     '微信ID'  => $thirdOauth['openid'],
                     '微信ID'  => $thirdOauth['openid'],
                 ];
                 ];
                 break;
                 break;
             case 'alipay':
             case 'alipay':
                 $withdrawInfo = [
                 $withdrawInfo = [
-                    '真实姓名' => $params['account_name'],
-                    '支付宝账户' => $params['account_no']
+                    '真实姓名' => $account->account_name,
+                    '支付宝账户' => $account->account_no
                 ];
                 ];
                 break;
                 break;
             case 'bank':
             case 'bank':
                 $withdrawInfo = [
                 $withdrawInfo = [
-                    '真实姓名' => $params['account_name'],
-                    '开户行' => $params['account_header'] ?? '',
-                    '银行卡号' => $params['account_no']
+                    '真实姓名' => $account->account_name,
+                    '开户行' => $account->account_header,
+                    '银行卡号' => $account->account_no
                 ];
                 ];
                 break;
                 break;
         }
         }
         if (!isset($withdrawInfo)) {
         if (!isset($withdrawInfo)) {
-            throw new ShoproException('您的提现信息有误');
+            throw new BusinessException('您的提现信息有误');
         }
         }
 
 
         return $withdrawInfo;
         return $withdrawInfo;

+ 1 - 1
application/common/model/Withdraw.php

@@ -7,7 +7,7 @@ use app\common\model\User;
 
 
 class Withdraw extends Model
 class Withdraw extends Model
 {
 {
-    protected $name = 'shopro_withdraw';
+    protected $name = 'shop_withdraw';
     protected $type = [
     protected $type = [
         'withdraw_info' => 'json'
         'withdraw_info' => 'json'
     ];
     ];