From ecc1eb5570f3d3752e0e83232d08af940b143b8c Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 17 Jan 2023 13:09:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/User.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 65d50d0..c25a5c8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -169,15 +169,19 @@ public function startTransfer(User $to, string $amount, string|null $description /** * 扣除费用 * - * @param string $amount - * @param string $description - * @param bool $fail - * @param array $options + * @param string|null $amount + * @param string $description + * @param bool $fail + * @param array $options * * @return string */ - public function reduce(string $amount = "0", string $description = "消费", bool $fail = false, array $options = []): string + public function reduce(string|null $amount = "0", string $description = "消费", bool $fail = false, array $options = []): string { + if ($amount === null || $amount === '') { + return $this->balance; + } + Cache::lock('user_balance_' . $this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) { $this->refresh();