Browse Source

成品入仓末版超节损计算

unknown 1 week ago
parent
commit
99af6a2e2d
1 changed files with 37 additions and 13 deletions
  1. 37 13
      application/api/controller/FinishedProductWarehousing.php

+ 37 - 13
application/api/controller/FinishedProductWarehousing.php

@@ -459,21 +459,32 @@ public function getList()
         $mongodb = Db::connect(config('database.mongodb'));
         $this->saveFinishStock($data, $mongodb);
 
-        // 接单日期在 2026-08-01 及以后,且中间库 U8_06工单资料存在该工单时才同步
+        $warnings = [];
+
+        // 1. 末板超节损(与同步独立,失败不阻断后续)
+        if ($this->isEndBoard($data['jjcp_smb'])) {
+            try {
+                $this->handleEndBoardSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
+            } catch (\Exception $e) {
+                $warnings[] = '超节损计算失败:' . $e->getMessage();
+            }
+        }
+
+        // 2. 中间表同步(与超节损独立,失败不阻断)
         if ($this->shouldSyncFinishStockMiddle($data['jjcp_gdbh'])) {
             try {
                 $synchronization = new \app\api\controller\Synchronization();
                 $synchronization->syncFinishStockMiddle($data['UniqId'], '新增');
             } catch (\Exception $e) {
-                $this->error('成品入仓已保存,但' . $e->getMessage(), ['UniqId' => $data['UniqId']]);
+                $warnings[] = $e->getMessage();
             }
         }
-        
-        if ($this->isEndBoard($data['jjcp_smb'])) {
-            $this->handleEndBoardSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
-        }
 
-        $this->success('成功', ['UniqId' => $data['UniqId']]);
+        $result = ['UniqId' => $data['UniqId']];
+        if (!empty($warnings)) {
+            $result['warnings'] = $warnings;
+        }
+        $this->success(empty($warnings) ? '成功' : '成品入仓已保存,但部分后续处理失败', $result);
     }
 
     /**
@@ -590,7 +601,18 @@ public function getList()
             $this->error('失败');
         }
 
-        // 同步中间表:
+        $warnings = [];
+
+        // 1. 改为末板时先做超节损(与同步独立)
+        if ($smbChanged && $this->isEndBoard($newSmb)) {
+            try {
+                $this->handleEndBoardSuperLoss($old['jjcp_gdbh'], $old['jjcp_yjno']);
+            } catch (\Exception $e) {
+                $warnings[] = '超节损计算失败:' . $e->getMessage();
+            }
+        }
+
+        // 2. 同步中间表(与超节损独立)
         // - 数量变更:插入差值为新同步数据(增加为正、减少为负)
         // - 仅修改 smb / 时间:正常同步完整数量
         // - 数量与其他同时改:只同步差值
@@ -604,14 +626,16 @@ public function getList()
                     $synchronization->syncFinishStockMiddle($uniqId, '修改', null, $sysId);
                 }
             } catch (\Exception $e) {
-                $this->error('成品入仓已保存,但' . $e->getMessage(), ['UniqId' => $uniqId]);
+                $warnings[] = $e->getMessage();
             }
         }
 
-        if ($smbChanged && $this->isEndBoard($newSmb)) {
-            $this->handleEndBoardSuperLoss($old['jjcp_gdbh'], $old['jjcp_yjno']);
+        if (!empty($warnings)) {
+            $this->success('成品入仓已保存,但部分后续处理失败', [
+                'UniqId'   => $uniqId,
+                'warnings' => $warnings,
+            ]);
         }
-
         $this->success('成功');
     }
 
@@ -1585,7 +1609,7 @@ public function getList()
         $sql = db('工单_质量考核汇总')->fetchSql(true)->insertAll($result);
         $inserted = db()->query($sql);
         if ($inserted === false) {
-            $this->error('超节损数据保存失败');
+            throw new \Exception('超节损数据保存失败');
         }
     }
 }