From 42267794f11cf858fedb2650585823b54bc1dc31 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 17 Jan 2023 13:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E5=85=85=E5=80=BC?= 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 71ff9f0..65d50d0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -211,15 +211,19 @@ public function reduce(string $amount = "0", string $description = "消费", boo /** * 增加余额 * - * @param string $amount - * @param string $payment - * @param string $description - * @param array $options + * @param string|null $amount + * @param string $payment + * @param string $description + * @param array $options * * @return string */ - public function charge(string $amount = "0", string $payment = 'console', string $description = '充值', array $options = []): string + public function charge(string|null $amount = "0", string $payment = 'console', string $description = '充值', array $options = []): string { + if ($amount === null || $amount === '') { + return $this->balance; + } + Cache::lock('user_balance_' . $this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) { $this->refresh(); $this->balance = bcadd($this->balance, $amount, 2);