代币优化

This commit is contained in:
Dev
2026-10-27 18:30:40 +08:00
parent f53c142a56
commit 25804d500e
11 changed files with 66 additions and 27 deletions
@@ -481,8 +481,9 @@ class VirtualPayService
}
/**
* 代币数量,保留两位小数。1元=1代币时,0.01元对应 0.01 个代币
* @param float|string $amountYuan
* @return int
* @return float
* @throws \Exception
*/
private static function coinQuantity($amountYuan)
@@ -495,11 +496,9 @@ class VirtualPayService
if ($coinPerYuan < 1) {
$coinPerYuan = 1;
}
if (($fen * $coinPerYuan) % 100 !== 0) {
throw new \Exception('订单金额须为整数元才能按1元=1代币支付');
}
$quantity = bcdiv(bcmul((string)$fen, (string)$coinPerYuan, 0), '100', 2);
return intdiv($fen * $coinPerYuan, 100);
return (float)$quantity;
}
/**