feat(platform-orders): 列表增加行级回执总额与对账差额列
This commit is contained in:
@@ -146,6 +146,15 @@ class PlatformOrderController extends Controller
|
||||
->paginate(10)
|
||||
->withQueryString();
|
||||
|
||||
// 列表行级对账视图:回执总额 / 差额(便于运营快速定位问题订单)
|
||||
$orders->getCollection()->transform(function (PlatformOrder $o) {
|
||||
$receiptTotal = (float) $this->receiptTotalForOrder($o);
|
||||
$o->setAttribute('receipt_total', $receiptTotal);
|
||||
$o->setAttribute('reconciliation_delta_row', $receiptTotal - (float) $o->paid_amount);
|
||||
|
||||
return $o;
|
||||
});
|
||||
|
||||
$baseQuery = $this->applyFilters(PlatformOrder::query(), $filters);
|
||||
|
||||
// 同步失败原因聚合(Top 5):用于运营快速判断“常见失败原因”
|
||||
@@ -1108,6 +1117,24 @@ class PlatformOrderController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private function receiptTotalForOrder(PlatformOrder $order): float
|
||||
{
|
||||
// 优先读扁平字段 payment_summary.total_amount(更稳定、避免遍历 receipts)
|
||||
$total = (float) (data_get($order->meta, 'payment_summary.total_amount') ?? 0);
|
||||
if ($total > 0) {
|
||||
return $total;
|
||||
}
|
||||
|
||||
// 回退:遍历 payment_receipts[].amount
|
||||
$receipts = (array) (data_get($order->meta, 'payment_receipts', []) ?? []);
|
||||
$sum = 0.0;
|
||||
foreach ($receipts as $r) {
|
||||
$sum += (float) (data_get($r, 'amount') ?? 0);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
protected function sumReceiptAmount($orders): float
|
||||
{
|
||||
$total = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user