|
|
@@ -570,6 +570,13 @@ public function getList()
|
|
|
$sjChanged = trim((string)$req['jjcp_sj']) !== trim((string)$old['jjcp_sj']);
|
|
|
}
|
|
|
|
|
|
+ $sysIdChanged = false;
|
|
|
+ if ($sysId !== null && $sysId !== '') {
|
|
|
+ $oldSys = trim((string)($old['Sys_id'] ?? ''));
|
|
|
+ $sysIdChanged = trim((string)$sysId) !== $oldSys;
|
|
|
+ }
|
|
|
+ $needsMiddleSync = $hasQty || $hasSmb || $hasSj || $sysIdChanged;
|
|
|
+
|
|
|
// 改为末板时,校验同工单同印件是否已有其他末板记录
|
|
|
if ($smbChanged && $this->isEndBoard($newSmb)) {
|
|
|
$existingEndBoard = $this->findExistingEndBoard($old['jjcp_gdbh'], $old['jjcp_yjno']);
|
|
|
@@ -608,22 +615,11 @@ public function getList()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 2. 同步中间表(与超节损独立;失败/未同步均写入日志)
|
|
|
- // - 数量变更:插入差值为新同步数据(增加为正、减少为负)
|
|
|
- // - 仅修改 smb / 时间:正常同步完整数量
|
|
|
- // - 数量与其他同时改:只同步差值
|
|
|
- if ($qtyChanged || $smbChanged || $sjChanged) {
|
|
|
- $recordForSync = array_merge($old, $data);
|
|
|
- $iQtyOverride = $qtyChanged ? ($newQty - $oldQty) : null;
|
|
|
- $syncMsg = $this->syncFinishStockOrLogSkip(
|
|
|
- $recordForSync,
|
|
|
- $uniqId,
|
|
|
- '修改',
|
|
|
- $iQtyOverride,
|
|
|
- $sysId
|
|
|
- );
|
|
|
- if ($syncMsg !== null) {
|
|
|
- $warnings[] = $syncMsg;
|
|
|
+ // 2. 同步中间表:先「新增」负数量冲销原数据,再「新增」写入修改后数据(不用「修改」类型)
|
|
|
+ if ($needsMiddleSync) {
|
|
|
+ $syncMsgs = $this->syncFinishStockAfterEditOrLogSkip($old, $uniqId, $sysId);
|
|
|
+ if (!empty($syncMsgs)) {
|
|
|
+ $warnings = array_merge($warnings, $syncMsgs);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1207,14 +1203,16 @@ public function getList()
|
|
|
}
|
|
|
}
|
|
|
krsort($data1);
|
|
|
+
|
|
|
//成品入仓中jjcp_smb不为空的工单
|
|
|
|
|
|
$rows2 = db('成品入仓')
|
|
|
->where('jjcp_sj','>=',$date)
|
|
|
+ // ->where('jjcp_smb','<>','末 板')
|
|
|
->group('jjcp_gdbh, jjcp_cpdh')
|
|
|
->column("CONCAT( jjcp_gdbh, '-', jjcp_yjno) AS gdyj, max(jjcp_smb) as jjcp_smb,
|
|
|
sum(jjcp_sl) as jjcp_sls, left(max(jjcp_sj),10) as jjcp_sj,UniqId");
|
|
|
-
|
|
|
+
|
|
|
$data = [];
|
|
|
foreach($data1 as $key=>$value){
|
|
|
|
|
|
@@ -1565,9 +1563,9 @@ public function getList()
|
|
|
if ($gdbh === '' || !isset($gdbh[0]) || $gdbh[0] !== 'Y') {
|
|
|
return ['ok' => false, 'reason' => '不满足同步条件:工单编号不以Y开头或为空[' . $gdbh . ']'];
|
|
|
}
|
|
|
- if ((int)substr($gdbh, 1) < 2608001) {
|
|
|
- return ['ok' => false, 'reason' => '不满足同步条件:工单编号小于Y2608001[' . $gdbh . ']'];
|
|
|
- }
|
|
|
+ // if ((int)substr($gdbh, 1) < 2608001) {
|
|
|
+ // return ['ok' => false, 'reason' => '不满足同步条件:工单编号小于Y2608001[' . $gdbh . ']'];
|
|
|
+ // }
|
|
|
|
|
|
try {
|
|
|
$orderDate = db('工单_基本资料')->where('Gd_gdbh', $gdbh)->value('接单日期');
|
|
|
@@ -1577,9 +1575,9 @@ public function getList()
|
|
|
if (empty($orderDate)) {
|
|
|
return ['ok' => false, 'reason' => '不满足同步条件:工单_基本资料无接单日期[' . $gdbh . ']'];
|
|
|
}
|
|
|
- if (strtotime(trim((string)$orderDate)) < strtotime('2026-08-01')) {
|
|
|
- return ['ok' => false, 'reason' => '不满足同步条件:接单日期[' . trim((string)$orderDate) . ']早于2026-08-01'];
|
|
|
- }
|
|
|
+ // if (strtotime(trim((string)$orderDate)) < strtotime('2026-08-01')) {
|
|
|
+ // return ['ok' => false, 'reason' => '不满足同步条件:接单日期[' . trim((string)$orderDate) . ']早于2026-08-01'];
|
|
|
+ // }
|
|
|
|
|
|
try {
|
|
|
// db3:正式中间库,仅查询 U8_06工单资料是否存在该工单
|
|
|
@@ -1624,6 +1622,54 @@ public function getList()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改后同步中间表:① 新增 + 原数量负数(修改前快照) ② 新增 + 修改后正数量
|
|
|
+ * @param array $old 修改前成品入仓记录
|
|
|
+ * @param int $uniqId
|
|
|
+ * @param string|null $sysId
|
|
|
+ * @return array 失败提示列表,空表示无告警
|
|
|
+ */
|
|
|
+ protected function syncFinishStockAfterEditOrLogSkip(array $old, $uniqId, $sysId = null)
|
|
|
+ {
|
|
|
+ $warnings = [];
|
|
|
+ $gdbh = $old['jjcp_gdbh'] ?? '';
|
|
|
+ $gate = $this->explainFinishStockSyncGate($gdbh);
|
|
|
+ $synchronization = new \app\api\controller\Synchronization();
|
|
|
+ $operator = ($sysId !== null && trim((string)$sysId) !== '') ? $sysId : ($old['Sys_id'] ?? '');
|
|
|
+
|
|
|
+ if (!$gate['ok']) {
|
|
|
+ $synchronization->logFinishStockSync($old, $uniqId, '新增', '未同步', $gate['reason']);
|
|
|
+ return $warnings;
|
|
|
+ }
|
|
|
+
|
|
|
+ $oldQty = (float)$old['jjcp_sl'];
|
|
|
+ if (abs($oldQty) < 0.00001) {
|
|
|
+ $synchronization->logFinishStockSync($old, $uniqId, '新增', '未同步', '原数量为0,跳过冲销同步');
|
|
|
+ return $warnings;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $synchronization->syncFinishStockMiddle(
|
|
|
+ $uniqId,
|
|
|
+ '新增',
|
|
|
+ -1 * $oldQty,
|
|
|
+ $operator,
|
|
|
+ $old
|
|
|
+ );
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $warnings[] = '修改冲销同步失败:' . $e->getMessage();
|
|
|
+ return $warnings;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $synchronization->syncFinishStockMiddle($uniqId, '新增', null, $operator);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $warnings[] = '修改重传同步失败:' . $e->getMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+ return $warnings;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 末版入仓后进入超节损
|
|
|
* @param string $gdbh
|