fix: 修复支付的统计精度问题

This commit is contained in:
邹景立 2024-10-09 21:31:05 +08:00
parent c5d84df71c
commit 9d231881d7

View File

@ -442,7 +442,7 @@ abstract class Payment
*/
public static function leaveAmount(string $orderNo, $orderAmount): float
{
$diff = round(floatval($orderAmount) - self::paidAmount($orderNo, true), 2);
$diff = round(round(floatval($orderAmount), 2) - self::paidAmount($orderNo, true), 2);
return $diff > 0 ? $diff : 0.00;
}
@ -463,9 +463,9 @@ abstract class Payment
'sum(used_integral-refund_integral)' => 'integral',
])->group('channel_type')->select()->map(static function (PluginPaymentRecord $item) use (&$total) {
$type = $item->getAttr('channel_type');
$total['amount'] += $item->getAttr('amount');
$total['amount'] = round($total['amount'] + $item->getAttr('amount'), 2);
if (!in_array($type, [self::INTEGRAL, self::BALANCE])) $type = 'payment';
$total[$type] += $item[$type] ?? 0;
$total[$type] = round($total[$type] + $item[$type] ?? 0, 2);
});
} catch (\Exception $exception) {
trace_file($exception);
@ -486,9 +486,9 @@ abstract class Payment
'refund_account', 'sum(refund_amount) amount', 'sum(used_payment)' => 'payment', 'sum(used_balance)' => 'balance', 'sum(used_integral)' => 'integral',
])->group('refund_account')->select()->map(static function (PluginPaymentRefund $item) use (&$total) {
$type = $item->getAttr('refund_account');
$total['amount'] += $item->getAttr('amount');
$total['amount'] = round($total['amount'] + $item->getAttr('amount'), 2);
if (!in_array($type, [self::INTEGRAL, self::BALANCE])) $type = 'payment';
$total[$type] += $item[$type] ?? 0;
$total[$type] = round($total[$type] + $item[$type] ?? 0, 2);
});
} catch (\Exception $exception) {
trace_file($exception);