*/ public static function loadPurchaseOrderOrFail(int $scydgyId, string $message = '未找到订单'): array { self::assertValidScydgyId($scydgyId, $message); try { $row = Db::table('purchase_order')->where('scydgy_id', $scydgyId)->find(); } catch (\Throwable $e) { $row = null; } if (!is_array($row)) { throw new \InvalidArgumentException($message); } self::assertNotSoftDeleted($row, $message); return $row; } public static function assertWflowPendingConfirm(array $po, string $message = '该订单不在待确认供应商状态'): void { if (!ProcuremenStatus::isWflowPendingConfirm($po['wflow_status'] ?? '')) { throw new \InvalidArgumentException($message); } } public static function assertWflowPendingApproval(array $po, string $message = '该订单不在待审批状态'): void { if (!ProcuremenStatus::isWflowPendingApproval($po['wflow_status'] ?? '')) { throw new \InvalidArgumentException($message); } } public static function assertNotCompleted(array $po, string $message = '订单已完结,无法重复操作'): void { if (ProcuremenStatus::isPoCompleted($po['status'] ?? '')) { throw new \InvalidArgumentException($message); } } /** * @param int[] $detailIds */ public static function assertDetailIdsBelongToOrder(int $scydgyId, array $detailIds, string $message = '下发明细与订单不匹配'): void { $detailIds = array_values(array_unique(array_filter(array_map('intval', $detailIds)))); if ($detailIds === []) { throw new \InvalidArgumentException('请选择供应商明细'); } try { $cnt = (int)Db::table('purchase_order_detail') ->where('scydgy_id', $scydgyId) ->where('id', 'in', $detailIds) ->count(); } catch (\Throwable $e) { $cnt = 0; } if ($cnt !== count($detailIds)) { throw new \InvalidArgumentException($message); } } }