app = $app; $this->amount = $amount; $this->type = $type; $this->feeAmount = $feeAmount; $this->context = $context; } /** * 修改手续费金额 * * @param string $newFeeAmount 新的手续费金额 * @param string $reason 修改原因 * @param string $modifiedBy 修改者标识 * @return void */ public function modifyFeeAmount(string $newFeeAmount, string $reason, string $modifiedBy): void { $this->feeAmount = $newFeeAmount; $this->isModified = true; $this->modificationReason = $reason; $this->modifiedBy = $modifiedBy; } /** * 修改手续费率(会重新计算手续费金额) * * @param float $newFeeRate 新的手续费率 * @param string $reason 修改原因 * @param string $modifiedBy 修改者标识 * @return void */ public function modifyFeeRate(float $newFeeRate, string $reason, string $modifiedBy): void { $this->feeAmount = bcmul($this->amount, (string)$newFeeRate, 4); $this->isModified = true; $this->modificationReason = $reason; $this->modifiedBy = $modifiedBy; } /** * 设置免手续费 * * @param string $reason 免费原因 * @param string $modifiedBy 修改者标识 * @return void */ public function setFree(string $reason, string $modifiedBy): void { $this->feeAmount = '0.0000'; $this->isModified = true; $this->modificationReason = $reason; $this->modifiedBy = $modifiedBy; } /** * 增加手续费金额 * * @param string $additionalFee 额外手续费 * @param string $reason 增加原因 * @param string $modifiedBy 修改者标识 * @return void */ public function addFee(string $additionalFee, string $reason, string $modifiedBy): void { $this->feeAmount = bcadd($this->feeAmount, $additionalFee, 4); $this->isModified = true; $this->modificationReason = $reason; $this->modifiedBy = $modifiedBy; } /** * 减少手续费金额 * * @param string $discountFee 减免手续费 * @param string $reason 减免原因 * @param string $modifiedBy 修改者标识 * @return void */ public function reduceFee(string $discountFee, string $reason, string $modifiedBy): void { $newFeeAmount = bcsub($this->feeAmount, $discountFee, 4); // 确保手续费不为负数 if (bccomp($newFeeAmount, '0', 4) < 0) { $newFeeAmount = '0.0000'; } $this->feeAmount = $newFeeAmount; $this->isModified = true; $this->modificationReason = $reason; $this->modifiedBy = $modifiedBy; } /** * 获取手续费计算结果 * * @return array */ public function getResult(): array { return [ 'fee_amount' => $this->feeAmount, 'is_modified' => $this->isModified, 'modification_reason' => $this->modificationReason, 'modified_by' => $this->modifiedBy, ]; } /** * 获取上下文数据 * * @param string $key 键名 * @param mixed $default 默认值 * @return mixed */ public function getContext(string $key, $default = null) { return $this->context[$key] ?? $default; } /** * 设置上下文数据 * * @param string $key 键名 * @param mixed $value 值 * @return void */ public function setContext(string $key, $value): void { $this->context[$key] = $value; } /** * 检查是否为转入手续费 * * @return bool */ public function isTransferIn(): bool { return $this->type === 'in'; } /** * 检查是否为转出手续费 * * @return bool */ public function isTransferOut(): bool { return $this->type === 'out'; } }