|
|
@@ -4,6 +4,7 @@ namespace app\admin\controller;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
use app\common\library\AliyunOss;
|
|
|
+use app\common\library\ProcuremenStatus;
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
use think\Config;
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
@@ -413,12 +414,13 @@ class Procuremen extends Backend
|
|
|
$query = Db::table('purchase_order');
|
|
|
$this->applyPurchaseOrderNotDeletedWhere($query);
|
|
|
if ($stage === 'audit') {
|
|
|
- $query->whereIn('wflow_status', [1, '1']);
|
|
|
+ $query->whereIn('wflow_status', ProcuremenStatus::wflowPendingConfirmValues());
|
|
|
} elseif ($stage === 'confirm') {
|
|
|
- $query->where('status', 0)->where(function ($q) {
|
|
|
- $q->where('wflow_status', 2)
|
|
|
+ $query->whereRaw(ProcuremenStatus::sqlPoInProgress('status'))->where(function ($q) {
|
|
|
+ $q->whereIn('wflow_status', ProcuremenStatus::wflowPendingApprovalValues())
|
|
|
->whereOr(function ($q2) {
|
|
|
- $q2->where('wflow_status', 0)->whereRaw($this->purchaseOrderDetailActiveExistsSql('d'));
|
|
|
+ $q2->whereIn('wflow_status', ProcuremenStatus::wflowPendingIssueValues())
|
|
|
+ ->whereRaw($this->purchaseOrderDetailActiveExistsSql('d'));
|
|
|
});
|
|
|
});
|
|
|
} else {
|
|
|
@@ -461,12 +463,13 @@ class Procuremen extends Backend
|
|
|
$query = Db::table('purchase_order');
|
|
|
$this->applyPurchaseOrderNotDeletedWhere($query);
|
|
|
if ($stage === 'audit') {
|
|
|
- $query->whereIn('wflow_status', [1, '1']);
|
|
|
+ $query->whereIn('wflow_status', ProcuremenStatus::wflowPendingConfirmValues());
|
|
|
} elseif ($stage === 'confirm') {
|
|
|
- $query->where('status', 0)->where(function ($q) {
|
|
|
- $q->where('wflow_status', 2)
|
|
|
+ $query->whereRaw(ProcuremenStatus::sqlPoInProgress('status'))->where(function ($q) {
|
|
|
+ $q->whereIn('wflow_status', ProcuremenStatus::wflowPendingApprovalValues())
|
|
|
->whereOr(function ($q2) {
|
|
|
- $q2->where('wflow_status', 0)->whereRaw($this->purchaseOrderDetailActiveExistsSql('d'));
|
|
|
+ $q2->whereIn('wflow_status', ProcuremenStatus::wflowPendingIssueValues())
|
|
|
+ ->whereRaw($this->purchaseOrderDetailActiveExistsSql('d'));
|
|
|
});
|
|
|
});
|
|
|
} else {
|
|
|
@@ -493,16 +496,16 @@ class Procuremen extends Backend
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- /** purchase_order_detail.status:2=废弃归档(保留留痕,不参与当前流程) */
|
|
|
- protected const PURCHASE_DETAIL_STATUS_VOID = 2;
|
|
|
+ /** @deprecated 使用 {@see ProcuremenStatus::POD_VOID} */
|
|
|
+ protected const PURCHASE_DETAIL_STATUS_VOID = '已废弃';
|
|
|
|
|
|
protected function isPurchaseOrderDetailVoid(array $row): bool
|
|
|
{
|
|
|
- if ((int)($row['status'] ?? 0) === self::PURCHASE_DETAIL_STATUS_VOID) {
|
|
|
+ if (ProcuremenStatus::isPodVoid($row['status'] ?? '')) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- return trim((string)($row['status_name'] ?? '')) === '已废弃';
|
|
|
+ return trim((string)($row['status_name'] ?? '')) === ProcuremenStatus::POD_VOID;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -510,9 +513,8 @@ class Procuremen extends Backend
|
|
|
*/
|
|
|
protected function applyActivePurchaseOrderDetailWhere($query): void
|
|
|
{
|
|
|
- $void = self::PURCHASE_DETAIL_STATUS_VOID;
|
|
|
- $query->whereRaw('(`status` IS NULL OR `status` <> ' . $void . ')')
|
|
|
- ->whereRaw('(status_name IS NULL OR TRIM(status_name) = \'\' OR status_name <> \'已废弃\')');
|
|
|
+ $query->whereRaw(ProcuremenStatus::sqlPodNotVoid('status'))
|
|
|
+ ->whereRaw('(status_name IS NULL OR TRIM(status_name) = \'\' OR status_name <> \'' . ProcuremenStatus::POD_VOID . '\')');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -520,12 +522,12 @@ class Procuremen extends Backend
|
|
|
*/
|
|
|
protected function purchaseOrderDetailActiveExistsSql(string $detailAlias = 'd'): string
|
|
|
{
|
|
|
- $void = self::PURCHASE_DETAIL_STATUS_VOID;
|
|
|
+ $void = ProcuremenStatus::POD_VOID;
|
|
|
|
|
|
return 'EXISTS (SELECT 1 FROM purchase_order_detail ' . $detailAlias
|
|
|
. ' WHERE ' . $detailAlias . '.scydgy_id = purchase_order.scydgy_id'
|
|
|
- . ' AND (' . $detailAlias . '.`status` IS NULL OR ' . $detailAlias . '.`status` <> ' . $void . ')'
|
|
|
- . ' AND (' . $detailAlias . '.status_name IS NULL OR TRIM(' . $detailAlias . '.status_name) = \'\' OR ' . $detailAlias . '.status_name <> \'已废弃\')'
|
|
|
+ . ' AND ' . str_replace('`status`', $detailAlias . '.`status`', ProcuremenStatus::sqlPodNotVoid($detailAlias . '.status'))
|
|
|
+ . ' AND (' . $detailAlias . '.status_name IS NULL OR TRIM(' . $detailAlias . '.status_name) = \'\' OR ' . $detailAlias . '.status_name <> \'' . $void . '\')'
|
|
|
. ' LIMIT 1)';
|
|
|
}
|
|
|
|
|
|
@@ -546,14 +548,14 @@ class Procuremen extends Backend
|
|
|
if ($ids === []) {
|
|
|
return;
|
|
|
}
|
|
|
- $void = self::PURCHASE_DETAIL_STATUS_VOID;
|
|
|
+ $void = ProcuremenStatus::POD_VOID;
|
|
|
Db::table('purchase_order_detail')
|
|
|
->where('scydgy_id', 'in', array_keys($ids))
|
|
|
- ->whereRaw('(`status` IS NULL OR `status` <> ' . $void . ')')
|
|
|
- ->whereRaw('(status_name IS NULL OR TRIM(status_name) = \'\' OR status_name <> \'已废弃\')')
|
|
|
+ ->whereRaw(ProcuremenStatus::sqlPodNotVoid('status'))
|
|
|
+ ->whereRaw('(status_name IS NULL OR TRIM(status_name) = \'\' OR status_name <> \'' . $void . '\')')
|
|
|
->update([
|
|
|
'status' => $void,
|
|
|
- 'status_name' => '已废弃',
|
|
|
+ 'status_name' => $void,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
@@ -596,12 +598,13 @@ class Procuremen extends Backend
|
|
|
$query = Db::table('purchase_order')->field($fields);
|
|
|
$this->applyPurchaseOrderNotDeletedWhere($query);
|
|
|
if ($stage === 'audit') {
|
|
|
- $query->whereIn('wflow_status', [1, '1'])->order('pick_time', 'desc')->order('id', 'desc');
|
|
|
+ $query->whereIn('wflow_status', ProcuremenStatus::wflowPendingConfirmValues())->order('pick_time', 'desc')->order('id', 'desc');
|
|
|
} elseif ($stage === 'confirm') {
|
|
|
- $query->where('status', 0)->where(function ($q) {
|
|
|
- $q->where('wflow_status', 2)
|
|
|
+ $query->whereRaw(ProcuremenStatus::sqlPoInProgress('status'))->where(function ($q) {
|
|
|
+ $q->whereIn('wflow_status', ProcuremenStatus::wflowPendingApprovalValues())
|
|
|
->whereOr(function ($q2) {
|
|
|
- $q2->where('wflow_status', 0)->whereRaw($this->purchaseOrderDetailActiveExistsSql('d'));
|
|
|
+ $q2->whereIn('wflow_status', ProcuremenStatus::wflowPendingIssueValues())
|
|
|
+ ->whereRaw($this->purchaseOrderDetailActiveExistsSql('d'));
|
|
|
});
|
|
|
})->order('pick_time', 'desc')->order('id', 'desc');
|
|
|
} else {
|
|
|
@@ -1078,7 +1081,10 @@ class Procuremen extends Backend
|
|
|
$issuedSet = [];
|
|
|
try {
|
|
|
$poList = Db::table('purchase_order')
|
|
|
- ->whereRaw('(`status` = 0 OR `status` = 1)')
|
|
|
+ ->whereIn('status', array_merge(
|
|
|
+ ProcuremenStatus::poInProgressValues(),
|
|
|
+ ProcuremenStatus::poCompletedValues()
|
|
|
+ ))
|
|
|
->column('scydgy_id');
|
|
|
if (is_array($poList)) {
|
|
|
foreach ($poList as $ids) {
|
|
|
@@ -1122,8 +1128,13 @@ class Procuremen extends Backend
|
|
|
try {
|
|
|
$poIds = Db::table('purchase_order')
|
|
|
->where(function ($q) {
|
|
|
- $q->where('wflow_status', '>=', 1)
|
|
|
- ->whereOr('status', 1)
|
|
|
+ $q->whereIn('wflow_status', array_merge(
|
|
|
+ ProcuremenStatus::wflowPendingConfirmValues(),
|
|
|
+ ProcuremenStatus::wflowPendingApprovalValues()
|
|
|
+ ))
|
|
|
+ ->whereOr(function ($q1) {
|
|
|
+ $q1->whereIn('status', ProcuremenStatus::poCompletedValues());
|
|
|
+ })
|
|
|
->whereOr(function ($q2) {
|
|
|
$q2->whereNotNull('pick_time')
|
|
|
->where('pick_time', '<>', '')
|
|
|
@@ -1223,12 +1234,12 @@ class Procuremen extends Backend
|
|
|
if ($sid >= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
- $wf = (int)($dbRow['wflow_status'] ?? 0);
|
|
|
- if ($wf >= 1) {
|
|
|
+ $wf = ProcuremenStatus::normalizeWflowStatus($dbRow['wflow_status'] ?? '');
|
|
|
+ if (ProcuremenStatus::wflowAtLeastConfirm($dbRow['wflow_status'] ?? '')) {
|
|
|
continue;
|
|
|
}
|
|
|
- $st = trim((string)($dbRow['status'] ?? ''));
|
|
|
- if ($st === '1' || $st === '0') {
|
|
|
+ $st = ProcuremenStatus::normalizePoStatus($dbRow['status'] ?? '');
|
|
|
+ if ($st === ProcuremenStatus::PO_COMPLETED || $st === ProcuremenStatus::PO_IN_PROGRESS) {
|
|
|
continue;
|
|
|
}
|
|
|
if (isset($detailSidSet[$sid])) {
|
|
|
@@ -1355,7 +1366,7 @@ class Procuremen extends Backend
|
|
|
try {
|
|
|
$po = Db::table('purchase_order')->where('scydgy_id', $sid)->find();
|
|
|
if (is_array($po)) {
|
|
|
- if ((int)($po['wflow_status'] ?? 0) >= 1) {
|
|
|
+ if (ProcuremenStatus::wflowAtLeastConfirm($po['wflow_status'] ?? '')) {
|
|
|
throw new \InvalidArgumentException('手工新增工序已下发,无法删除');
|
|
|
}
|
|
|
if ($this->isPurchaseOrderSoftDeleted($po['mod_rq'] ?? null)) {
|
|
|
@@ -1420,7 +1431,7 @@ class Procuremen extends Backend
|
|
|
'cywyxm' => trim((string)($params['cywyxm'] ?? '')),
|
|
|
'This_quantity' => trim((string)($params['This_quantity'] ?? '')),
|
|
|
'ceilingPrice' => trim((string)($params['ceilingPrice'] ?? '')),
|
|
|
- 'wflow_status' => 0,
|
|
|
+ 'wflow_status' => ProcuremenStatus::WFLOW_PENDING_ISSUE,
|
|
|
'createtime' => $now,
|
|
|
'dStamp' => $now,
|
|
|
'dputrecord' => $now,
|
|
|
@@ -1477,7 +1488,7 @@ class Procuremen extends Backend
|
|
|
{
|
|
|
$set = [];
|
|
|
try {
|
|
|
- $rows = Db::table('purchase_order_detail')->where('status', 1)->field('scydgy_id')->select();
|
|
|
+ $rows = Db::table('purchase_order_detail')->whereIn('status', ProcuremenStatus::podPickedValues())->field('scydgy_id')->select();
|
|
|
} catch (\Throwable $e) {
|
|
|
$rows = [];
|
|
|
}
|
|
|
@@ -1513,7 +1524,7 @@ class Procuremen extends Backend
|
|
|
try {
|
|
|
$rows = Db::table('purchase_order_detail')
|
|
|
->where('scydgy_id', 'in', $scydgyIds)
|
|
|
- ->where('status', 1)
|
|
|
+ ->whereIn('status', ProcuremenStatus::podPickedValues())
|
|
|
->field('scydgy_id,company_name')
|
|
|
->order('id', 'asc')
|
|
|
->select();
|
|
|
@@ -1521,7 +1532,7 @@ class Procuremen extends Backend
|
|
|
try {
|
|
|
$rows = Db::table('purchase_order_detail')
|
|
|
->where('scydgy_id', 'in', $scydgyIds)
|
|
|
- ->where('status', 1)
|
|
|
+ ->whereIn('status', ProcuremenStatus::podPickedValues())
|
|
|
->field('scydgy_id,company_name')
|
|
|
->order('ID', 'asc')
|
|
|
->select();
|
|
|
@@ -2602,7 +2613,7 @@ class Procuremen extends Backend
|
|
|
|
|
|
if ($asComplete) {
|
|
|
// 主表 status 为 varchar 时统一写 '1',档案 procuremenarchive 按 status=1 查询
|
|
|
- $data['status'] = '1';
|
|
|
+ $data['status'] = ProcuremenStatus::PO_COMPLETED;
|
|
|
}
|
|
|
|
|
|
$qtyCd = trim((string)($data['This_quantity'] ?? ''));
|
|
|
@@ -2886,12 +2897,12 @@ class Procuremen extends Backend
|
|
|
Db::startTrans();
|
|
|
}
|
|
|
try {
|
|
|
- Db::table('purchase_order_detail')->where('scydgy_id', $sid)->update(['status' => 0]);
|
|
|
+ Db::table('purchase_order_detail')->where('scydgy_id', $sid)->update(['status' => ProcuremenStatus::POD_UNPICKED]);
|
|
|
$aff = 0;
|
|
|
try {
|
|
|
- $aff = (int)Db::table('purchase_order_detail')->where('scydgy_id', $sid)->where('id', 'in', $selectedIds)->update(['status' => 1]);
|
|
|
+ $aff = (int)Db::table('purchase_order_detail')->where('scydgy_id', $sid)->where('id', 'in', $selectedIds)->update(['status' => ProcuremenStatus::POD_PICKED]);
|
|
|
} catch (\Throwable $e) {
|
|
|
- $aff = (int)Db::table('purchase_order_detail')->where('scydgy_id', $sid)->where('ID', 'in', $selectedIds)->update(['status' => 1]);
|
|
|
+ $aff = (int)Db::table('purchase_order_detail')->where('scydgy_id', $sid)->where('ID', 'in', $selectedIds)->update(['status' => ProcuremenStatus::POD_PICKED]);
|
|
|
}
|
|
|
if ($aff < 1) {
|
|
|
throw new \Exception('更新选中状态失败');
|
|
|
@@ -2901,12 +2912,12 @@ class Procuremen extends Backend
|
|
|
$poAff = (int)Db::table('purchase_order')
|
|
|
->where('id', $purchaseOrderId)
|
|
|
->where('scydgy_id', $sid)
|
|
|
- ->update(['status' => 1]);
|
|
|
+ ->update(['status' => ProcuremenStatus::POD_PICKED]);
|
|
|
if ($poAff < 1) {
|
|
|
throw new \Exception('主表订单不存在或与工序行不匹配');
|
|
|
}
|
|
|
} else {
|
|
|
- $poAff = (int)Db::table('purchase_order')->where('scydgy_id', $sid)->update(['status' => '1']);
|
|
|
+ $poAff = (int)Db::table('purchase_order')->where('scydgy_id', $sid)->update(['status' => ProcuremenStatus::PO_COMPLETED]);
|
|
|
if ($poAff < 1) {
|
|
|
throw new \Exception('未找到');
|
|
|
}
|
|
|
@@ -3292,8 +3303,7 @@ class Procuremen extends Backend
|
|
|
if ($detailCount > 0) {
|
|
|
return true;
|
|
|
}
|
|
|
- $wf = (int)($main['wflow_status'] ?? 0);
|
|
|
- if ($wf >= 1) {
|
|
|
+ if (ProcuremenStatus::wflowAtLeastConfirm($main['wflow_status'] ?? '')) {
|
|
|
return true;
|
|
|
}
|
|
|
$pickTime = trim((string)($main['pick_time'] ?? ''));
|
|
|
@@ -3408,7 +3418,7 @@ class Procuremen extends Backend
|
|
|
if ($this->detailRowSupplierAccepted($dr)) {
|
|
|
$acceptCnt++;
|
|
|
}
|
|
|
- if ((int)($dr['status'] ?? 0) === 1) {
|
|
|
+ if (ProcuremenStatus::isPodPicked($dr['status'] ?? '')) {
|
|
|
if ($pickedName === '') {
|
|
|
$pickedName = trim((string)($dr['company_name'] ?? ''));
|
|
|
}
|
|
|
@@ -3426,8 +3436,9 @@ class Procuremen extends Backend
|
|
|
if ($poTime === '') {
|
|
|
$poTime = $this->formatProcuremenDetailTime($main['dStamp'] ?? null);
|
|
|
}
|
|
|
- $mainStatus = isset($main['status']) ? (int)$main['status'] : 0;
|
|
|
- $wflowStatus = (int)($main['wflow_status'] ?? 0);
|
|
|
+ $mainCompleted = ProcuremenStatus::isPoCompleted($main['status'] ?? '');
|
|
|
+ $wflowPendingApproval = ProcuremenStatus::isWflowPendingApproval($main['wflow_status'] ?? '');
|
|
|
+ $wflowAtLeastConfirm = ProcuremenStatus::wflowAtLeastConfirm($main['wflow_status'] ?? '');
|
|
|
$issued = $this->isProcuremenOrderIssued($main, $issueCnt);
|
|
|
$issueTime = $issued ? $this->resolveProcuremenIssueTime($main, $details) : '';
|
|
|
|
|
|
@@ -3448,10 +3459,10 @@ class Procuremen extends Backend
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $directComplete = ($mainStatus === 1 && !$issued);
|
|
|
+ $directComplete = ($mainCompleted && !$issued);
|
|
|
|
|
|
$doneTime = '';
|
|
|
- if ($mainStatus === 1) {
|
|
|
+ if ($mainCompleted) {
|
|
|
if ($directComplete) {
|
|
|
$doneTime = $this->resolveProcuremenMarkCompleteTime($scydgyId);
|
|
|
}
|
|
|
@@ -3472,6 +3483,9 @@ class Procuremen extends Backend
|
|
|
if ($doneTime === '') {
|
|
|
$doneTime = $poTime;
|
|
|
}
|
|
|
+ if ($confirmApproveTime !== '') {
|
|
|
+ $doneTime = $confirmApproveTime;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if ($directComplete) {
|
|
|
@@ -3486,20 +3500,20 @@ class Procuremen extends Backend
|
|
|
$step1Done = $issued;
|
|
|
$step2Done = $issued;
|
|
|
$step3Done = $acceptCnt > 0;
|
|
|
- $step4Done = $wflowStatus >= 2;
|
|
|
+ $step4Done = $wflowPendingApproval;
|
|
|
if (!$step4Done) {
|
|
|
foreach ($details as $dr) {
|
|
|
- if (is_array($dr) && (int)($dr['status'] ?? 0) === 1) {
|
|
|
+ if (is_array($dr) && ProcuremenStatus::isPodPicked($dr['status'] ?? '')) {
|
|
|
$step4Done = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $step5Done = $confirmApproveTime !== '' || $mainStatus === 1;
|
|
|
- $step6Done = $mainStatus === 1;
|
|
|
+ $step5Done = $confirmApproveTime !== '' || $mainCompleted;
|
|
|
+ $step6Done = $mainCompleted;
|
|
|
|
|
|
// 已走下发流程并完结:中间环节按业务视为已全部完成(不显示灰色「未到达」)
|
|
|
- if ($mainStatus === 1 && $issued) {
|
|
|
+ if ($mainCompleted && $issued) {
|
|
|
$step3Done = true;
|
|
|
$step4Done = true;
|
|
|
$step5Done = true;
|
|
|
@@ -3710,6 +3724,7 @@ class Procuremen extends Backend
|
|
|
}
|
|
|
$r['delivery_ymd'] = $this->formatDeliveryYmd($r['delivery'] ?? null);
|
|
|
$r['is_void'] = is_array($r) && $this->isPurchaseOrderDetailVoid($r);
|
|
|
+ $r['is_picked'] = is_array($r) && ProcuremenStatus::isPodPicked($r['status'] ?? '');
|
|
|
$r['oper_time_text'] = $this->resolveDetailSupplierOperTime($r);
|
|
|
}
|
|
|
unset($r);
|
|
|
@@ -3894,14 +3909,12 @@ class Procuremen extends Backend
|
|
|
if (!is_array($po)) {
|
|
|
continue;
|
|
|
}
|
|
|
- $wf = (int)($po['wflow_status'] ?? 0);
|
|
|
- $st = $po['status'] ?? null;
|
|
|
- if ($wf >= 1 || $st === 1 || $st === '1') {
|
|
|
+ if (ProcuremenStatus::wflowAtLeastConfirm($po['wflow_status'] ?? '') || ProcuremenStatus::isPoCompleted($po['status'] ?? '')) {
|
|
|
$gymc = trim((string)($r['CGYMC'] ?? ''));
|
|
|
$this->error('工序「' . ($gymc !== '' ? $gymc : ('#' . $id)) . '」已进入审批流程,不能重复下发');
|
|
|
}
|
|
|
$detCnt = (int)($detCntBySid[$id] ?? 0);
|
|
|
- if ($detCnt > 0 && $wf < 1) {
|
|
|
+ if ($detCnt > 0 && !ProcuremenStatus::wflowAtLeastConfirm($po['wflow_status'] ?? '')) {
|
|
|
$gymc = trim((string)($r['CGYMC'] ?? ''));
|
|
|
$this->error('工序「' . ($gymc !== '' ? $gymc : ('#' . $id)) . '」已存在下发明细,请走采购确认或联系管理员');
|
|
|
}
|
|
|
@@ -4040,7 +4053,7 @@ class Procuremen extends Backend
|
|
|
} catch (\Throwable $e) {
|
|
|
$anchor = null;
|
|
|
}
|
|
|
- if (!is_array($anchor) || (int)($anchor['wflow_status'] ?? 0) !== 1) {
|
|
|
+ if (!is_array($anchor) || !ProcuremenStatus::isWflowPendingConfirm($anchor['wflow_status'] ?? '')) {
|
|
|
return $empty;
|
|
|
}
|
|
|
$ccydh = trim((string)($anchor['CCYDH'] ?? ''));
|
|
|
@@ -4048,7 +4061,7 @@ class Procuremen extends Backend
|
|
|
return ['ccydh' => '', 'pos' => [$anchor], 'merge_rows' => $this->scydgyRowsForPurchaseOrders([$anchor])];
|
|
|
}
|
|
|
try {
|
|
|
- $pos = Db::table('purchase_order')->where('CCYDH', $ccydh)->where('wflow_status', 1)->order('scydgy_id', 'asc')->select();
|
|
|
+ $pos = Db::table('purchase_order')->where('CCYDH', $ccydh)->whereIn('wflow_status', ProcuremenStatus::wflowPendingConfirmValues())->order('scydgy_id', 'asc')->select();
|
|
|
} catch (\Throwable $e) {
|
|
|
$pos = [$anchor];
|
|
|
}
|
|
|
@@ -4068,15 +4081,13 @@ class Procuremen extends Backend
|
|
|
*/
|
|
|
protected function purchaseOrderRowInConfirmStage(array $po): bool
|
|
|
{
|
|
|
- $st = $po['status'] ?? null;
|
|
|
- if ($st === 1 || $st === '1') {
|
|
|
+ if (ProcuremenStatus::isPoCompleted($po['status'] ?? '')) {
|
|
|
return false;
|
|
|
}
|
|
|
- $wf = (int)($po['wflow_status'] ?? 0);
|
|
|
- if ($wf === 2) {
|
|
|
+ if (ProcuremenStatus::isWflowPendingApproval($po['wflow_status'] ?? '')) {
|
|
|
return true;
|
|
|
}
|
|
|
- if ($wf === 0) {
|
|
|
+ if (ProcuremenStatus::isWflowPendingIssue($po['wflow_status'] ?? '')) {
|
|
|
$sid = (int)($po['scydgy_id'] ?? 0);
|
|
|
|
|
|
return $this->isValidScydgyRowId($sid) && $this->purchaseOrderDetail($sid) !== [];
|
|
|
@@ -4116,11 +4127,12 @@ class Procuremen extends Backend
|
|
|
try {
|
|
|
$pos = Db::table('purchase_order')
|
|
|
->where('CCYDH', $ccydh)
|
|
|
- ->where('status', 0)
|
|
|
+ ->whereRaw(ProcuremenStatus::sqlPoInProgress('status'))
|
|
|
->where(function ($q) {
|
|
|
- $q->where('wflow_status', 2)
|
|
|
+ $q->whereIn('wflow_status', ProcuremenStatus::wflowPendingApprovalValues())
|
|
|
->whereOr(function ($q2) {
|
|
|
- $q2->where('wflow_status', 0)->whereRaw($this->purchaseOrderDetailActiveExistsSql('d'));
|
|
|
+ $q2->whereIn('wflow_status', ProcuremenStatus::wflowPendingIssueValues())
|
|
|
+ ->whereRaw($this->purchaseOrderDetailActiveExistsSql('d'));
|
|
|
});
|
|
|
})
|
|
|
->order('scydgy_id', 'asc')
|
|
|
@@ -4359,7 +4371,7 @@ class Procuremen extends Backend
|
|
|
if (!is_array($d)) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (!$this->isPurchaseOrderDetailVoid($d) && (int)($d['status'] ?? 0) === 1) {
|
|
|
+ if (!$this->isPurchaseOrderDetailVoid($d) && ProcuremenStatus::isPodPicked($d['status'] ?? '')) {
|
|
|
$cn = trim((string)($d['company_name'] ?? ''));
|
|
|
if ($cn !== '') {
|
|
|
return $cn;
|
|
|
@@ -4474,7 +4486,8 @@ class Procuremen extends Backend
|
|
|
'unit_price_text' => $amountNum !== null ? $this->formatProcuremenMoneyDisplay($amountNum) : trim((string)($d['amount'] ?? '')),
|
|
|
'subtotal_text' => $sub !== null ? $this->formatProcuremenMoneyDisplay($sub) : '',
|
|
|
'delivery_ymd' => $d['delivery_ymd'] ?? $this->formatDeliveryYmd($d['delivery'] ?? null),
|
|
|
- 'status' => (int)($d['status'] ?? 0),
|
|
|
+ 'status' => ProcuremenStatus::normalizePodPickStatus($d['status'] ?? ''),
|
|
|
+ 'is_picked' => ProcuremenStatus::isPodPicked($d['status'] ?? ''),
|
|
|
'is_void' => $isVoid,
|
|
|
'oper_time_text' => $ct,
|
|
|
];
|
|
|
@@ -4881,7 +4894,7 @@ class Procuremen extends Backend
|
|
|
'cywyxm' => $row['cywyxm'] ?? null,
|
|
|
'This_quantity' => $row['This_quantity'] ?? $row['this_quantity'] ?? null,
|
|
|
'ceilingPrice' => $row['ceilingPrice'] ?? $row['ceiling_price'] ?? null,
|
|
|
- 'status' => 0,
|
|
|
+ 'status' => ProcuremenStatus::PO_IN_PROGRESS,
|
|
|
'sys_rq' => $sysRqDb,
|
|
|
];
|
|
|
if ($wflowStatus !== null) {
|
|
|
@@ -4965,7 +4978,7 @@ class Procuremen extends Backend
|
|
|
'email' => isset($c['email']) ? (string)$c['email'] : null,
|
|
|
'phone' => isset($c['phone']) ? (string)$c['phone'] : null,
|
|
|
'createtime' => date('Y-m-d H:i:s'),
|
|
|
- 'status' => 0,
|
|
|
+ 'status' => ProcuremenStatus::POD_UNPICKED,
|
|
|
'status_name' => '未提交',
|
|
|
];
|
|
|
Db::table('purchase_order_detail')->insert($one);
|
|
|
@@ -5599,16 +5612,13 @@ class Procuremen extends Backend
|
|
|
*/
|
|
|
protected function formatProcuremenRfqProgressText(array $row): string
|
|
|
{
|
|
|
- $st = trim((string)($row['status'] ?? ''));
|
|
|
- // status=1 才表示主单已完结;status=0 为流程进行中(与详情 buildProcuremenDetailsViewData 一致)
|
|
|
- if ($st === '1') {
|
|
|
- return '已完结';
|
|
|
+ if (ProcuremenStatus::isPoCompleted($row['status'] ?? '')) {
|
|
|
+ return ProcuremenStatus::PO_COMPLETED;
|
|
|
}
|
|
|
- $wf = (int)($row['wflow_status'] ?? 0);
|
|
|
- if ($wf === 2) {
|
|
|
+ if (ProcuremenStatus::isWflowPendingApproval($row['wflow_status'] ?? '')) {
|
|
|
return '待采购确认';
|
|
|
}
|
|
|
- if ($wf === 1) {
|
|
|
+ if (ProcuremenStatus::isWflowPendingConfirm($row['wflow_status'] ?? '')) {
|
|
|
return '待确认供应商';
|
|
|
}
|
|
|
$sid = (int)($row['scydgy_id'] ?? 0);
|
|
|
@@ -6024,8 +6034,8 @@ class Procuremen extends Backend
|
|
|
continue;
|
|
|
}
|
|
|
Db::table('purchase_order')->where('scydgy_id', $sid)->update([
|
|
|
- 'wflow_status' => 2,
|
|
|
- 'status' => 0,
|
|
|
+ 'wflow_status' => ProcuremenStatus::WFLOW_PENDING_APPROVAL,
|
|
|
+ 'status' => ProcuremenStatus::PO_IN_PROGRESS,
|
|
|
'pick_company_name' => $companyName,
|
|
|
'sys_rq' => $sysRqDb,
|
|
|
]);
|
|
|
@@ -6140,8 +6150,8 @@ class Procuremen extends Backend
|
|
|
Db::table('purchase_order')
|
|
|
->where('scydgy_id', 'in', array_keys($sids))
|
|
|
->update([
|
|
|
- 'wflow_status' => 0,
|
|
|
- 'status' => 0,
|
|
|
+ 'wflow_status' => ProcuremenStatus::WFLOW_PENDING_ISSUE,
|
|
|
+ 'status' => ProcuremenStatus::PO_IN_PROGRESS,
|
|
|
'pick_company_name' => '',
|
|
|
'pick_time' => null,
|
|
|
'sys_rq' => null,
|
|
|
@@ -6193,7 +6203,7 @@ class Procuremen extends Backend
|
|
|
}
|
|
|
try {
|
|
|
$query = Db::table('purchase_order')->where('CCYDH', $ccydh);
|
|
|
- $query->whereRaw("(TRIM(CAST(`status` AS CHAR)) = '1' OR CAST(`status` AS UNSIGNED) = 1)");
|
|
|
+ $query->whereRaw(ProcuremenStatus::sqlPoCompleted('status'));
|
|
|
$pos = $query->order('scydgy_id', 'asc')->select();
|
|
|
} catch (\Throwable $e) {
|
|
|
$pos = [$anchor];
|
|
|
@@ -6419,11 +6429,11 @@ class Procuremen extends Backend
|
|
|
}
|
|
|
|
|
|
Db::table('purchase_order')->where('scydgy_id', $sid)->update([
|
|
|
- 'wflow_status' => 1,
|
|
|
- 'status' => 0,
|
|
|
+ 'wflow_status' => ProcuremenStatus::WFLOW_PENDING_CONFIRM,
|
|
|
+ 'status' => ProcuremenStatus::PO_IN_PROGRESS,
|
|
|
'pick_company_name' => '',
|
|
|
]);
|
|
|
- Db::table('purchase_order_detail')->where('scydgy_id', $sid)->update(['status' => 0]);
|
|
|
+ Db::table('purchase_order_detail')->where('scydgy_id', $sid)->update(['status' => ProcuremenStatus::POD_UNPICKED]);
|
|
|
$this->restorePurchaseOrderDetailStatusNamesAfterReject($sid);
|
|
|
|
|
|
$poId = 0;
|
|
|
@@ -6600,10 +6610,8 @@ class Procuremen extends Backend
|
|
|
$po = null;
|
|
|
}
|
|
|
if (!$isPurchaseConfirm && is_array($po)) {
|
|
|
- $wf = (int)($po['wflow_status'] ?? 0);
|
|
|
- $st = trim((string)($po['status'] ?? ''));
|
|
|
- $isDone = ($st === '1' || $st === 1);
|
|
|
- if ($wf === 2 && !$isDone) {
|
|
|
+ $isDone = ProcuremenStatus::isPoCompleted($po['status'] ?? '');
|
|
|
+ if (ProcuremenStatus::isWflowPendingApproval($po['wflow_status'] ?? '') && !$isDone) {
|
|
|
$isPurchaseConfirm = true;
|
|
|
}
|
|
|
}
|
|
|
@@ -6759,9 +6767,19 @@ class Procuremen extends Backend
|
|
|
*
|
|
|
* @param array<string, mixed> $row purchase_order 行
|
|
|
*/
|
|
|
- protected function resolveCompletedPurchaseOrderYm(array $row): string
|
|
|
+ protected function resolveCompletedPurchaseOrderYm(array $row, array $completeTsMap = []): string
|
|
|
{
|
|
|
- foreach (['createtime', 'dStamp', 'updatetime'] as $key) {
|
|
|
+ $sid = (int)($row['scydgy_id'] ?? 0);
|
|
|
+ if ($sid > 0 && isset($completeTsMap[$sid]) && (int)$completeTsMap[$sid] > 946684800) {
|
|
|
+ return date('Y-m', (int)$completeTsMap[$sid]);
|
|
|
+ }
|
|
|
+ if ($sid > 0) {
|
|
|
+ $logTs = $this->resolveProcuremenOperLogTime($sid, ['purchase_confirm', 'mark_complete']);
|
|
|
+ if ($logTs !== '' && preg_match('/^(\d{4}-\d{2})/', $logTs, $m)) {
|
|
|
+ return $m[1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (['updatetime', 'createtime', 'dStamp'] as $key) {
|
|
|
$raw = $row[$key] ?? null;
|
|
|
if ($raw === null || $raw === '') {
|
|
|
continue;
|
|
|
@@ -6778,6 +6796,45 @@ class Procuremen extends Backend
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array<int, string> $actions
|
|
|
+ * @return array<int, int>
|
|
|
+ */
|
|
|
+ protected function loadProcuremenOperLogTimestampMap(array $scydgyIds, array $actions): array
|
|
|
+ {
|
|
|
+ $out = [];
|
|
|
+ $scydgyIds = array_values(array_unique(array_filter(array_map('intval', $scydgyIds))));
|
|
|
+ $actions = array_values(array_filter(array_map('strval', $actions)));
|
|
|
+ if ($scydgyIds === [] || $actions === []) {
|
|
|
+ return $out;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ $logs = Db::table('purchase_order_oper_log')
|
|
|
+ ->where('scydgy_id', 'in', $scydgyIds)
|
|
|
+ ->where('action', 'in', $actions)
|
|
|
+ ->field('scydgy_id,createtime')
|
|
|
+ ->order('id', 'asc')
|
|
|
+ ->select();
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ $logs = [];
|
|
|
+ }
|
|
|
+ if (!is_array($logs)) {
|
|
|
+ return $out;
|
|
|
+ }
|
|
|
+ foreach ($logs as $log) {
|
|
|
+ if (!is_array($log)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $sid = (int)($log['scydgy_id'] ?? 0);
|
|
|
+ $ct = (int)($log['createtime'] ?? 0);
|
|
|
+ if ($sid > 0 && $ct > 946684800) {
|
|
|
+ $out[$sid] = isset($out[$sid]) ? max($out[$sid], $ct) : $ct;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $out;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 按月份导出:已完结订单(与历史存证、月度列表一致),按完结月份筛选。
|
|
|
* 表头固定 8 列(与历史「协助明细」模板一致):序号、传票号、传票名称、外加工单位、订法、客户名称、工序、加工金额。
|
|
|
@@ -6793,7 +6850,7 @@ class Procuremen extends Backend
|
|
|
$dbRows = [];
|
|
|
try {
|
|
|
$query = Db::table('purchase_order');
|
|
|
- $query->whereRaw("(TRIM(CAST(`status` AS CHAR)) = '1' OR CAST(`status` AS UNSIGNED) = 1)");
|
|
|
+ $query->whereRaw(ProcuremenStatus::sqlPoCompleted('status'));
|
|
|
$dbRows = $query->select();
|
|
|
} catch (\Throwable $e) {
|
|
|
$dbRows = [];
|
|
|
@@ -6801,12 +6858,26 @@ class Procuremen extends Backend
|
|
|
if (!is_array($dbRows)) {
|
|
|
$dbRows = [];
|
|
|
}
|
|
|
- $dbRows = array_values(array_filter($dbRows, function ($dbRow) use ($ym) {
|
|
|
+ $completeTsMap = [];
|
|
|
+ $sidList = [];
|
|
|
+ foreach ($dbRows as $dbRow) {
|
|
|
+ if (!is_array($dbRow)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $sid = (int)($dbRow['scydgy_id'] ?? 0);
|
|
|
+ if ($sid > 0) {
|
|
|
+ $sidList[$sid] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($sidList !== []) {
|
|
|
+ $completeTsMap = $this->loadProcuremenOperLogTimestampMap(array_keys($sidList), ['purchase_confirm', 'mark_complete']);
|
|
|
+ }
|
|
|
+ $dbRows = array_values(array_filter($dbRows, function ($dbRow) use ($ym, $completeTsMap) {
|
|
|
if (!is_array($dbRow)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- return $this->resolveCompletedPurchaseOrderYm($dbRow) === $ym;
|
|
|
+ return $this->resolveCompletedPurchaseOrderYm($dbRow, $completeTsMap) === $ym;
|
|
|
}));
|
|
|
|
|
|
$pool = $this->procuremenPoolFromPurchaseOrderDbRows($dbRows);
|
|
|
@@ -6828,7 +6899,7 @@ class Procuremen extends Backend
|
|
|
try {
|
|
|
$detailRows = Db::table('purchase_order_detail')
|
|
|
->where('scydgy_id', 'in', array_keys($mainBySid))
|
|
|
- ->where('status', '<>', self::PURCHASE_DETAIL_STATUS_VOID)
|
|
|
+ ->whereRaw(ProcuremenStatus::sqlPodNotVoid('status'))
|
|
|
->order('status', 'desc')
|
|
|
->order('CCYDH', 'asc')
|
|
|
->order('company_name', 'asc')
|
|
|
@@ -6838,7 +6909,7 @@ class Procuremen extends Backend
|
|
|
try {
|
|
|
$detailRows = Db::table('purchase_order_detail')
|
|
|
->where('scydgy_id', 'in', array_keys($mainBySid))
|
|
|
- ->where('status', '<>', self::PURCHASE_DETAIL_STATUS_VOID)
|
|
|
+ ->whereRaw(ProcuremenStatus::sqlPodNotVoid('status'))
|
|
|
->order('status', 'desc')
|
|
|
->order('CCYDH', 'asc')
|
|
|
->order('company_name', 'asc')
|
|
|
@@ -6866,7 +6937,7 @@ class Procuremen extends Backend
|
|
|
if (isset($detailSidSeen[$sid])) {
|
|
|
continue;
|
|
|
}
|
|
|
- if ((int)($dr['status'] ?? 0) !== 1) {
|
|
|
+ if (!ProcuremenStatus::isPodPicked($dr['status'] ?? '')) {
|
|
|
continue;
|
|
|
}
|
|
|
$detailSidSeen[$sid] = true;
|