table('courier_bill_lines') ->where('statement_id', $statementId)->where('express_name', '武进韵达') ->whereIn('category', [...Category::PAYABLE, Category::PRIOR])->whereNull('resolution') ->whereRaw('bill_weight - charge_weight > 1') ->whereColumn('bill_amount', '>', 'calc_freight'); } /** 按差额合计计算一半,再四舍五入到分,避免逐行四舍五入累积误差。 */ public function summary(int $statementId): array { $sum = $this->query($statementId)->selectRaw('COUNT(*) AS n, SUM(bill_amount - calc_freight) AS difference')->first(); return ['count' => (int) $sum->n, 'difference' => round((float) $sum->difference, 4), 'amount' => round((float) $sum->difference / 2, 2)]; } }