| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <?php
- namespace app\common\library;
- /**
- * 协助采购状态文案(purchase_order / purchase_order_detail)
- *
- * purchase_order.status(主单是否完结):
- * 进行中 — 协助流程未完结(已下发、待确认、待审批等)
- * 已完结 — 采购确认通过,或协助初选直接点「完结」
- *
- * purchase_order.wflow_status(主单流程阶段,与 status 分工不同):
- * 待下发 — 尚未协助下发,或退回初选后
- * 待确认 — 已通知供应商报价,待采购选定供应商(原 1)
- * 已驳回 — 采购终审驳回,退回确认供应商(可再次选定,业务上等同待确认)
- * 待审批 — 已选定供应商,待采购终审(原 2)
- * 已审核 — 采购终审通过,流程结束(原 3)
- *
- * purchase_order_detail.status(下发明细采购选定):
- * 未选中 — 默认 / 未中标
- * 已选中 — 采购确认选中的供应商明细(原 1)
- * 已废弃 — 退回初选归档,不参与当前流程(原 2)
- *
- * purchase_order_detail.status_name(供应商填单 / 手机端 Tab,保持原中文):
- * 未提交 / 已提交 / 已完成 / 未通过 / 已废弃
- */
- class ProcuremenStatus
- {
- public const PO_IN_PROGRESS = '进行中';
- public const PO_COMPLETED = '已完结';
- public const WFLOW_PENDING_ISSUE = '待下发';
- public const WFLOW_PENDING_CONFIRM = '待确认';
- public const WFLOW_REJECTED = '已驳回';
- public const WFLOW_PENDING_APPROVAL = '待审批';
- public const WFLOW_APPROVED = '已审核';
- public const POD_UNPICKED = '未选中';
- public const POD_PICKED = '已选中';
- public const POD_VOID = '已废弃';
- public static function normalizePoStatus($value): string
- {
- $s = trim((string)$value);
- if ($s === '' || $s === '0' || strcasecmp($s, self::PO_IN_PROGRESS) === 0) {
- return self::PO_IN_PROGRESS;
- }
- if ($s === '1' || strcasecmp($s, self::PO_COMPLETED) === 0) {
- return self::PO_COMPLETED;
- }
- return $s;
- }
- public static function isPoCompleted($value): bool
- {
- return self::normalizePoStatus($value) === self::PO_COMPLETED;
- }
- public static function isPoInProgress($value): bool
- {
- return self::normalizePoStatus($value) === self::PO_IN_PROGRESS;
- }
- public static function normalizeWflowStatus($value): string
- {
- $s = trim((string)$value);
- if ($s === '' || $s === '0' || strcasecmp($s, self::WFLOW_PENDING_ISSUE) === 0) {
- return self::WFLOW_PENDING_ISSUE;
- }
- if ($s === '1' || strcasecmp($s, self::WFLOW_PENDING_CONFIRM) === 0) {
- return self::WFLOW_PENDING_CONFIRM;
- }
- if ($s === '4' || strcasecmp($s, self::WFLOW_REJECTED) === 0) {
- return self::WFLOW_REJECTED;
- }
- if ($s === '2' || strcasecmp($s, self::WFLOW_PENDING_APPROVAL) === 0 || $s === '待审核') {
- return self::WFLOW_PENDING_APPROVAL;
- }
- if ($s === '3' || strcasecmp($s, self::WFLOW_APPROVED) === 0) {
- return self::WFLOW_APPROVED;
- }
- return $s;
- }
- public static function isWflowPendingIssue($value): bool
- {
- return self::normalizeWflowStatus($value) === self::WFLOW_PENDING_ISSUE;
- }
- public static function isWflowRejected($value): bool
- {
- return self::normalizeWflowStatus($value) === self::WFLOW_REJECTED;
- }
- /**
- * 待采购选定供应商:待确认 + 已驳回(驳回后可再次选定)
- */
- public static function isWflowPendingConfirm($value): bool
- {
- $w = self::normalizeWflowStatus($value);
- return $w === self::WFLOW_PENDING_CONFIRM || $w === self::WFLOW_REJECTED;
- }
- public static function isWflowPendingApproval($value): bool
- {
- return self::normalizeWflowStatus($value) === self::WFLOW_PENDING_APPROVAL;
- }
- public static function isWflowApproved($value): bool
- {
- return self::normalizeWflowStatus($value) === self::WFLOW_APPROVED;
- }
- public static function wflowAtLeastConfirm($value): bool
- {
- $w = self::normalizeWflowStatus($value);
- return $w === self::WFLOW_PENDING_CONFIRM
- || $w === self::WFLOW_REJECTED
- || $w === self::WFLOW_PENDING_APPROVAL;
- }
- public static function normalizePodPickStatus($value): string
- {
- $s = trim((string)$value);
- if ($s === '' || $s === '0' || strcasecmp($s, self::POD_UNPICKED) === 0) {
- return self::POD_UNPICKED;
- }
- if ($s === '1' || strcasecmp($s, self::POD_PICKED) === 0) {
- return self::POD_PICKED;
- }
- if ($s === '2' || strcasecmp($s, self::POD_VOID) === 0 || strcasecmp($s, '已废弃') === 0) {
- return self::POD_VOID;
- }
- return $s;
- }
- public static function isPodPicked($value): bool
- {
- return self::normalizePodPickStatus($value) === self::POD_PICKED;
- }
- public static function isPodVoid($value): bool
- {
- return self::normalizePodPickStatus($value) === self::POD_VOID;
- }
- /** @return string[] */
- public static function wflowPendingConfirmValues(): array
- {
- // 已驳回可再次选定供应商,与待确认同属确认页工作队列
- return [self::WFLOW_PENDING_CONFIRM, self::WFLOW_REJECTED, '1', '4'];
- }
- /** @return string[] */
- public static function wflowPendingApprovalValues(): array
- {
- return [self::WFLOW_PENDING_APPROVAL, '2'];
- }
- /** @return string[] */
- public static function wflowApprovedValues(): array
- {
- return [self::WFLOW_APPROVED, '3'];
- }
- /**
- * 确认页 / 审批页共用列表:待确认 + 已驳回 + 待审批 + 已审核
- *
- * @return string[]
- */
- public static function wflowConfirmAndAuditListValues(): array
- {
- return array_values(array_unique(array_merge(
- self::wflowPendingConfirmValues(),
- self::wflowPendingApprovalValues(),
- self::wflowApprovedValues()
- )));
- }
- /**
- * 列表「订单状态」展示:待确认 / 已驳回 / 待审核 / 已审核
- */
- public static function orderStatusLabelForList($value): string
- {
- $w = self::normalizeWflowStatus($value);
- if ($w === self::WFLOW_REJECTED || $w === '已驳回') {
- return '已驳回';
- }
- if ($w === self::WFLOW_PENDING_CONFIRM || $w === '待确认') {
- return '待确认';
- }
- if ($w === self::WFLOW_PENDING_APPROVAL || $w === '待审核') {
- return '待审核';
- }
- if ($w === self::WFLOW_APPROVED || $w === '已审核') {
- return '已审核';
- }
- return $w !== '' ? $w : '';
- }
- /**
- * 确认/审批列表按订单状态排序权重(越小越靠前)
- * - audit(采购供应商确认):已驳回 → 待确认 → 待审核 → 已审核
- * - confirm(采购确认/审批):待审核 → 已驳回 → 待确认 → 已审核
- */
- public static function orderStatusSortWeight(string $stage, $value): int
- {
- $label = self::orderStatusLabelForList($value);
- if ($stage === 'audit') {
- $map = ['已驳回' => 0, '待确认' => 1, '待审核' => 2, '已审核' => 3];
- } else {
- // confirm(审批页)等
- $map = ['待审核' => 0, '已驳回' => 1, '待确认' => 2, '已审核' => 3];
- }
- return $map[$label] ?? 99;
- }
- /** @return string[] */
- public static function wflowPendingIssueValues(): array
- {
- return [self::WFLOW_PENDING_ISSUE, '0', ''];
- }
- /** @return string[] */
- public static function podPickedValues(): array
- {
- return [self::POD_PICKED, '1'];
- }
- /** @return string[] */
- public static function podUnpickedValues(): array
- {
- return [self::POD_UNPICKED, '0', ''];
- }
- /** @return string[] */
- public static function poCompletedValues(): array
- {
- return [self::PO_COMPLETED, '1'];
- }
- /** @return string[] */
- public static function poInProgressValues(): array
- {
- return [self::PO_IN_PROGRESS, '0'];
- }
- public static function sqlPoCompleted(string $column = 'status'): string
- {
- $c = self::quoteSqlIdent($column);
- return "TRIM(CAST({$c} AS CHAR)) IN ('" . self::PO_COMPLETED . "','1')";
- }
- public static function sqlPoInProgress(string $column = 'status'): string
- {
- $c = self::quoteSqlIdent($column);
- return "TRIM(CAST({$c} AS CHAR)) IN ('" . self::PO_IN_PROGRESS . "','0')";
- }
- public static function sqlPodNotVoid(string $column = 'status'): string
- {
- $c = self::quoteSqlIdent($column);
- $void = str_replace("'", "''", self::POD_VOID);
- return "({$c} IS NULL OR TRIM(CAST({$c} AS CHAR)) NOT IN ('{$void}','2'))";
- }
- protected static function quoteSqlIdent(string $column): string
- {
- if (strpos($column, '.') !== false) {
- $parts = explode('.', $column, 2);
- return '`' . str_replace('`', '', $parts[0]) . '`.`' . str_replace('`', '', $parts[1]) . '`';
- }
- return '`' . str_replace('`', '', $column) . '`';
- }
- }
|