|
|
@@ -11115,12 +11115,23 @@ class Procuremen extends Backend
|
|
|
$logSidList[$sid] = true;
|
|
|
}
|
|
|
}
|
|
|
+ if ($logSidList === []) {
|
|
|
+ $this->error('未找到有效工序,无法下发');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 防连点/并发:同一批工序加命名锁,已下发则直接拒绝(避免重复短信邮件)
|
|
|
+ $sidKeys = array_keys($logSidList);
|
|
|
+ sort($sidKeys, SORT_NUMERIC);
|
|
|
+ $pickLockName = 'procuremen_pick_submit_' . md5(implode(',', $sidKeys));
|
|
|
+ if (!$this->acquireProcuremenNamedLock($pickLockName, 15)) {
|
|
|
+ $this->error('下发处理中,请勿重复点击');
|
|
|
+ }
|
|
|
|
|
|
$existingBySid = [];
|
|
|
- if ($logSidList !== []) {
|
|
|
+ try {
|
|
|
try {
|
|
|
$existingRows = Db::table('purchase_order')
|
|
|
- ->where('scydgy_id', 'in', array_keys($logSidList))
|
|
|
+ ->where('scydgy_id', 'in', $sidKeys)
|
|
|
->select();
|
|
|
if (is_array($existingRows)) {
|
|
|
foreach ($existingRows as $poRow) {
|
|
|
@@ -11136,34 +11147,53 @@ class Procuremen extends Backend
|
|
|
} catch (\Throwable $e) {
|
|
|
$existingBySid = [];
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- // ---------- 主表 wflow_status=待确认;明细写入 purchase_order_detail,随后向供应商发短信/邮件 ----------
|
|
|
- foreach ($mergeRows as $row) {
|
|
|
- if (!is_array($row)) {
|
|
|
+ foreach ($sidKeys as $sid) {
|
|
|
+ $poRow = $existingBySid[$sid] ?? null;
|
|
|
+ if (!is_array($poRow)) {
|
|
|
continue;
|
|
|
}
|
|
|
- $sid = $this->extractScydgyRowId($row);
|
|
|
- $this->upsertPurchaseOrderFromRow(
|
|
|
- $row,
|
|
|
- $sysRqDb,
|
|
|
- ProcuremenStatus::WFLOW_PENDING_CONFIRM,
|
|
|
- $issueTime,
|
|
|
- $this->isValidScydgyRowId($sid) ? ($existingBySid[$sid] ?? null) : null,
|
|
|
- $deliveryDeadlineDb,
|
|
|
- $scoreRule
|
|
|
- );
|
|
|
- }
|
|
|
- foreach ($issueCompanies as $c) {
|
|
|
- $this->issuePersistSupplierDetails($c, $mergeRows, false, true);
|
|
|
+ if ($this->isPurchaseOrderSoftDeleted($poRow['mod_rq'] ?? null)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $label = $this->formatProcuremenRowLabel(['CCYDH' => $poRow['CCYDH'] ?? '', 'CGYMC' => $poRow['CGYMC'] ?? '']);
|
|
|
+ if (ProcuremenStatus::isPoCompleted($poRow['status'] ?? '')) {
|
|
|
+ $this->error(($label !== '' ? $label : ('工序#' . $sid)) . '已完结,无法再次下发');
|
|
|
+ }
|
|
|
+ if (!ProcuremenStatus::isWflowPendingIssue($poRow['wflow_status'] ?? '')) {
|
|
|
+ $this->error(($label !== '' ? $label : ('工序#' . $sid)) . '已下发或进入后续流程,请勿重复提交');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- Db::commit();
|
|
|
- } catch (\Throwable $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ // ---------- 主表 wflow_status=待确认;明细写入 purchase_order_detail,随后向供应商发短信/邮件 ----------
|
|
|
+ foreach ($mergeRows as $row) {
|
|
|
+ if (!is_array($row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $sid = $this->extractScydgyRowId($row);
|
|
|
+ $this->upsertPurchaseOrderFromRow(
|
|
|
+ $row,
|
|
|
+ $sysRqDb,
|
|
|
+ ProcuremenStatus::WFLOW_PENDING_CONFIRM,
|
|
|
+ $issueTime,
|
|
|
+ $this->isValidScydgyRowId($sid) ? ($existingBySid[$sid] ?? null) : null,
|
|
|
+ $deliveryDeadlineDb,
|
|
|
+ $scoreRule
|
|
|
+ );
|
|
|
+ }
|
|
|
+ foreach ($issueCompanies as $c) {
|
|
|
+ $this->issuePersistSupplierDetails($c, $mergeRows, false, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ $this->releaseProcuremenNamedLock($pickLockName);
|
|
|
}
|
|
|
|
|
|
$poIdBySid = [];
|