From f60c6f2ea09926fc4d294e1d766bee731a6d8011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 28 Dec 2021 11:54:00 +0800 Subject: [PATCH] Update --- app/Services/BalanceService.php | 8 +++++++- app/Services/WalletService.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) 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(); + } } // 变更前余额