53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\service\order;
|
|
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 支付单反查处方业务订单。调用方先按原有权限和分页取得支付单,再批量补充关联。
|
|
*/
|
|
class PaymentPrescriptionOrderService
|
|
{
|
|
/**
|
|
* @param int[] $paymentIds
|
|
* @return array<int, list<array{id: int, order_no: string}>>
|
|
*/
|
|
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;
|
|
}
|
|
}
|