platform orders: use configurable tolerance for mysql reconcile mismatch filter
This commit is contained in:
@@ -1651,7 +1651,11 @@ class PlatformOrderController extends Controller
|
|||||||
} else {
|
} else {
|
||||||
// MySQL 下 JSON_EXTRACT 返回 JSON,需要 JSON_UNQUOTE 再 cast;同样按分取整避免浮点误差
|
// MySQL 下 JSON_EXTRACT 返回 JSON,需要 JSON_UNQUOTE 再 cast;同样按分取整避免浮点误差
|
||||||
// total_cents = (payment_summary.total_amount 存在 ? summary*100 : SUM(payment_receipts[].amount)*100)
|
// total_cents = (payment_summary.total_amount 存在 ? summary*100 : SUM(payment_receipts[].amount)*100)
|
||||||
$builder->whereRaw("ABS(ROUND((CASE WHEN JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NOT NULL THEN CAST(JSON_UNQUOTE(JSON_EXTRACT(meta, '$.payment_summary.total_amount')) AS DECIMAL(12,2)) ELSE (SELECT IFNULL(SUM(j.amount), 0) FROM JSON_TABLE(meta, '$.payment_receipts[*]' COLUMNS(amount DECIMAL(12,2) PATH '$.amount')) j) END) * 100) - ROUND(paid_amount * 100)) >= 1");
|
$tol = (float) config('saasshop.amounts.tolerance', 0.01);
|
||||||
|
$tolCents = (int) round($tol * 100);
|
||||||
|
$tolCents = max(1, $tolCents);
|
||||||
|
|
||||||
|
$builder->whereRaw("ABS(ROUND((CASE WHEN JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NOT NULL THEN CAST(JSON_UNQUOTE(JSON_EXTRACT(meta, '$.payment_summary.total_amount')) AS DECIMAL(12,2)) ELSE (SELECT IFNULL(SUM(j.amount), 0) FROM JSON_TABLE(meta, '$.payment_receipts[*]' COLUMNS(amount DECIMAL(12,2) PATH '$.amount')) j) END) * 100) - ROUND(paid_amount * 100)) >= {$tolCents}");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
->when(($filters['receipt_status'] ?? '') !== '', function (Builder $builder) use ($filters) {
|
->when(($filters['receipt_status'] ?? '') !== '', function (Builder $builder) use ($filters) {
|
||||||
|
|||||||
Reference in New Issue
Block a user