diff --git a/app/Services/BalanceService.php b/app/Services/BalanceService.php index 4642b47b..06c9427b 100644 --- a/app/Services/BalanceService.php +++ b/app/Services/BalanceService.php @@ -23,7 +23,13 @@ class BalanceService $balance = $user->balance()->lockForUpdate()->first(); if (is_null($balance)) { - throw new BalanceNotEnoughException(); + if ($changeBalance < 0) { + throw new BalanceNotEnoughException(); + } else { + $user->balance()->create(); + + $balance = $user->balance()->lockForUpdate()->first(); + } } // 变更前余额 diff --git a/app/Services/WalletService.php b/app/Services/WalletService.php index 654e8ef4..1810c4de 100644 --- a/app/Services/WalletService.php +++ b/app/Services/WalletService.php @@ -23,7 +23,13 @@ class WalletService $wallet = $user->wallet()->lockForUpdate()->first(); if (is_null($wallet)) { - throw new WalletNotEnoughException(); + if ($changeBalance < 0) { + throw new WalletNotEnoughException(); + } else { + $user->wallet()->create(); + + $wallet = $user->wallet()->lockForUpdate()->first(); + } } // 变更前余额