> */ public static function forPaymentIds(array $paymentIds): array { $paymentIds = array_values(array_unique(array_filter( array_map('intval', $paymentIds), static fn (int $id): bool => $id > 0 ))); if ($paymentIds === []) { return []; } $result = array_fill_keys($paymentIds, []); // 历史 linked_pay_order_id 已由迁移写入关联表;不能用旧字段恢复已移除或已拆分的关联。 // 不按履约/支付状态筛选,保留仍有关联的取消、退款订单历史。 $rows = Db::name('tcm_prescription_order_pay_order')->alias('link') ->join('tcm_prescription_order po', 'po.id = link.prescription_order_id') ->whereIn('link.pay_order_id', $paymentIds) ->whereNull('po.delete_time') ->field(['link.pay_order_id', 'po.id', 'po.order_no']) ->order('po.id', 'asc') ->select() ->toArray(); foreach ($rows as $row) { $result[(int) $row['pay_order_id']][(int) $row['id']] = [ 'id' => (int) $row['id'], 'order_no' => (string) $row['order_no'], ]; } foreach ($result as &$orders) { $orders = array_values($orders); } unset($orders); return $result; } }