|
|
@@ -246,15 +246,51 @@ class TransferApp extends ModelCore
|
|
|
* 计算转出手续费
|
|
|
*
|
|
|
* @param string $amount 转出金额
|
|
|
- * @return array ['fee_rate' => 手续费率, 'fee_amount' => 手续费金额, 'actual_amount' => 实际到账金额]
|
|
|
+ * @return array ['fee_rate' => 手续费率, 'fee_amount' => 手续费金额, 'actual_amount' => 用户总支付金额]
|
|
|
*/
|
|
|
public function calculateOutFee(string $amount): array
|
|
|
{
|
|
|
- return $this->calculateFee($amount, $this->fee_out_rate, $this->fee_out_min, $this->fee_out_max);
|
|
|
+ return $this->calculateOutFeeWithExtraCharge($amount, $this->fee_out_rate, $this->fee_out_min, $this->fee_out_max);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算转出手续费的专用方法(额外收取手续费)
|
|
|
+ *
|
|
|
+ * @param string $amount 转出金额
|
|
|
+ * @param float $feeRate 手续费率
|
|
|
+ * @param float $minFee 最低手续费
|
|
|
+ * @param float $maxFee 最高手续费
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function calculateOutFeeWithExtraCharge(string $amount, float $feeRate, float $minFee, float $maxFee): array
|
|
|
+ {
|
|
|
+ $amountDecimal = bcmul($amount, '1', 4); // 转换为4位小数
|
|
|
+
|
|
|
+ // 按比例计算手续费
|
|
|
+ $feeAmount = bcmul($amountDecimal, (string)$feeRate, 4);
|
|
|
+
|
|
|
+ // 应用最低手续费限制
|
|
|
+ if (bccomp($feeAmount, (string)$minFee, 4) < 0) {
|
|
|
+ $feeAmount = bcmul((string)$minFee, '1', 4);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用最高手续费限制(如果设置了)
|
|
|
+ if ($maxFee > 0 && bccomp($feeAmount, (string)$maxFee, 4) > 0) {
|
|
|
+ $feeAmount = bcmul((string)$maxFee, '1', 4);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算用户总支付金额(转出金额 + 手续费)
|
|
|
+ $actualAmount = bcadd($amountDecimal, $feeAmount, 4);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'fee_rate' => $feeRate,
|
|
|
+ 'fee_amount' => $feeAmount,
|
|
|
+ 'actual_amount' => $actualAmount, // 对于转出:用户总支付金额
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 计算手续费的通用方法
|
|
|
+ * 计算手续费的通用方法(从金额中扣除手续费)
|
|
|
*
|
|
|
* @param string $amount 金额
|
|
|
* @param float $feeRate 手续费率
|
|
|
@@ -279,13 +315,13 @@ class TransferApp extends ModelCore
|
|
|
$feeAmount = bcmul((string)$maxFee, '1', 4);
|
|
|
}
|
|
|
|
|
|
- // 计算实际到账金额
|
|
|
+ // 计算实际到账金额(扣除手续费后)
|
|
|
$actualAmount = bcsub($amountDecimal, $feeAmount, 4);
|
|
|
|
|
|
return [
|
|
|
'fee_rate' => $feeRate,
|
|
|
'fee_amount' => $feeAmount,
|
|
|
- 'actual_amount' => $actualAmount,
|
|
|
+ 'actual_amount' => $actualAmount, // 对于转入:用户实际收到金额
|
|
|
];
|
|
|
}
|
|
|
|