Ken 6 dienas atpakaļ
vecāks
revīzija
6fe3afebd3
1 mainītis faili ar 16 papildinājumiem un 13 dzēšanām
  1. 16 13
      app/Services/PaymentOrderService.php

+ 16 - 13
app/Services/PaymentOrderService.php

@@ -4,6 +4,7 @@ namespace App\Services;
 
 use App\Constants\HttpStatus;
 use App\Models\PaymentOrder;
+use Exception;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
 use App\Services\Payment\QianBaoService;
@@ -322,25 +323,23 @@ class PaymentOrderService extends BaseService
     }
 
 
-    public static function createPayout($memberId, $amount, $channel, $bank_name, $account, $card_no)
+    public static function createPayout($memberId, $amount, $channel, $bank_name, $account, $card_no): array
     {
-
         DB::beginTransaction();
         $result['chat_id'] = $memberId;
+        $default_amount = $amount;
         try {
-            $default_amount = $amount;
-
             $wallet = WalletService::findOne(['member_id' => $memberId]);
-            if (!$wallet) throw new \Exception('钱包不存在', HttpStatus::CUSTOM_ERROR);
+            if (!$wallet) throw new Exception('钱包不存在', HttpStatus::CUSTOM_ERROR);
             $balance = $wallet->available_balance;
             if (bccomp($balance, $amount, 2) < 0) {
-                throw new \Exception("您的钱包余额不足!", HttpStatus::CUSTOM_ERROR);
+                throw new Exception("您的钱包余额不足!", HttpStatus::CUSTOM_ERROR);
             }
             $available_balance = bcsub($balance, $amount, 10);
 
             // 先预扣款(锁定资金)
             $wallet->available_balance = $available_balance;
-            if (!$wallet->save()) throw new \Exception('钱包更新失败!', HttpStatus::CUSTOM_ERROR);
+            if (!$wallet->save()) throw new Exception('钱包更新失败!', HttpStatus::CUSTOM_ERROR);
 
 
             $data = [];
@@ -368,13 +367,17 @@ class PaymentOrderService extends BaseService
                 $info->id,
                 '钱宝提现费率:0.2%+2'
             );
+
+
+            $balance = bcadd($available_balance, 0, 2);
             $text = "✅ 提现申请已提交!\n\n";
-            $text .= "钱包余额:{$available_balance} RMB\n";
+            $text .= "钱包余额:{$balance} RMB\n";
             $text .= "提现金额:{$default_amount} RMB\n";
             $text .= "⌛️请等待系统处理, 到账时间可能需要几分钟!\n";
             $result['text'] = $text;
             DB::commit();
-        } catch (\Exception $e) {
+        } //
+        catch (Exception $e) {
             DB::rollBack();
             $result['text'] = "系统发生了错误,请联系管理员";
             if ($e->getCode() === HttpStatus::CUSTOM_ERROR) {
@@ -469,7 +472,7 @@ class PaymentOrderService extends BaseService
             // 提交事务,确保预扣款成功
             DB::commit();
 
-        } catch (\Exception $e) {
+        } catch (Exception $e) {
             // 预扣款失败,回滚事务
             DB::rollBack();
             $result['text'] = '系统繁忙,请稍后重试!';
@@ -498,7 +501,7 @@ class PaymentOrderService extends BaseService
 
                 $result['text'] = $text;
 
-            } catch (\Exception $e) {
+            } catch (Exception $e) {
                 DB::rollBack();
                 // 状态更新失败,但资金已扣款且三方支付已成功
                 // 这里可以记录告警,需要人工干预
@@ -536,7 +539,7 @@ class PaymentOrderService extends BaseService
                 DB::commit();
                 $result['text'] = $ret['msg'];
 
-            } catch (\Exception $e) {
+            } catch (Exception $e) {
                 DB::rollBack();
                 // 回滚失败,需要记录告警,人工干预
                 Log::error('提现失败回滚异常: ' . $e->getMessage(), [
@@ -647,7 +650,7 @@ class PaymentOrderService extends BaseService
                     self::sendMessage($chat_id, $text);
                 }
             }
-        } catch (\Exception $e) {
+        } catch (Exception $e) {
             DB::rollBack();
             // 回滚失败,需要记录告警,人工干预
             Log::error('提现失败回滚异常: ' . $e->getMessage(), $params);