refactor: centralize refund total and refund inconsistent logic on PlatformOrder
This commit is contained in:
@@ -77,13 +77,7 @@ class SiteSubscriptionController extends Controller
|
||||
$noReceiptOrders++;
|
||||
}
|
||||
|
||||
$refundTotal = (float) (data_get($meta, 'refund_summary.total_amount') ?? 0);
|
||||
if ($refundTotal <= 0) {
|
||||
$refunds = (array) (data_get($meta, 'refund_receipts', []) ?? []);
|
||||
foreach ($refunds as $r) {
|
||||
$refundTotal += (float) (data_get($r, 'amount') ?? 0);
|
||||
}
|
||||
}
|
||||
$refundTotal = (float) $o->refundTotal();
|
||||
|
||||
if ($refundTotal > 0) {
|
||||
$refundOrders++;
|
||||
@@ -92,23 +86,7 @@ class SiteSubscriptionController extends Controller
|
||||
$noRefundOrders++;
|
||||
}
|
||||
|
||||
// refund_inconsistent 口径:
|
||||
// 1) payment_status=refunded 但 refund_total < paid_amount(按分取整 + 0.01 容差)
|
||||
// 2) payment_status!=refunded 且 paid_amount>0 且 refund_total >= paid_amount
|
||||
$paidAmount = (float) ($o->paid_amount ?? 0);
|
||||
$paymentStatus = (string) ($o->payment_status ?? '');
|
||||
$refundTotalCents = (int) round($refundTotal * 100);
|
||||
$paidCents = (int) round($paidAmount * 100);
|
||||
|
||||
$isRefundInconsistent = false;
|
||||
if ($paymentStatus === 'refunded') {
|
||||
// 允许 0.01 容差:refund_total + 0.01 < paid
|
||||
$isRefundInconsistent = ($refundTotalCents + 1) < $paidCents;
|
||||
} else {
|
||||
$isRefundInconsistent = $paidCents > 0 && $refundTotalCents >= $paidCents;
|
||||
}
|
||||
|
||||
if ($isRefundInconsistent) {
|
||||
if ($o->isRefundInconsistent()) {
|
||||
$refundInconsistentOrders++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user