userId = $userId; $this->fundId = $fundId; $this->requiredAmount = $requiredAmount; $this->availableAmount = $availableAmount; $context = [ 'user_id' => $userId, 'fund_id' => $fundId, 'required_amount' => $requiredAmount, 'available_amount' => $availableAmount, 'shortage' => bcsub($requiredAmount, $availableAmount, 10), ]; parent::__construct($message, 1001, null, $context); } /** * 获取用户ID */ public function getUserId(): int { return $this->userId; } /** * 获取资金类型ID */ public function getFundId(): int { return $this->fundId; } /** * 获取所需金额 */ public function getRequiredAmount(): string { return $this->requiredAmount; } /** * 获取可用金额 */ public function getAvailableAmount(): string { return $this->availableAmount; } /** * 获取缺少的金额 */ public function getShortage(): string { return bcsub($this->requiredAmount, $this->availableAmount, 10); } /** * 获取详细错误信息 */ public function getDetailedMessage(): string { return sprintf( '用户 %d 的资金类型 %d 余额不足,需要 %s,可用 %s,缺少 %s', $this->userId, $this->fundId, $this->requiredAmount, $this->availableAmount, $this->getShortage() ); } }