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();