Browse Source

成品入仓同步

unknown 1 month ago
parent
commit
2ad2060efe
1 changed files with 230 additions and 250 deletions
  1. 230 250
      application/api/controller/FinishedProductWarehousing.php

+ 230 - 250
application/api/controller/FinishedProductWarehousing.php

@@ -114,70 +114,6 @@ class FinishedProductWarehousing extends Api
      * @param string $date 时间
      * @param string $sys_id 用户
      */
-//     public function getList()
-//     {
-//         //get请求
-//         if(!$this->request->isGet()){
-//             $this->error('请求方式错误');
-//         }
-//         $req = $this->request->param();
-//         if (!isset($req['date'])) $this->error('参数缺失');
-
-// //        if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
-// //        if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
-
-//         if(strpos($req['date'],'-')){
-//             $where = ['c.Sys_rq'=>['like',$req['date'].'%']];
-//             $option = ['Sys_rq'=>['like',$req['date'].'%']];
-//         }else{
-//             $where = [];
-//             $option = [];
-//         }
-//         if (isset($req['sys_id']) && !empty($req['sys_id'])){
-//             $where['c.Sys_id'] = ['LIKE',$req['sys_id'].'%'];
-//             $option['Sys_id'] = ['LIKE',$req['sys_id'].'%'];
-//         }
-//         //客户编号
-//         $rows = db('成品入仓')->alias('c')
-//             ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
-//             rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh, 
-//             c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
-//             rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc, 
-//             rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称, 
-//             rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称, 
-//             rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
-//             ->where($where)
-//             ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh AND g.行号 = c.jjcp_yjno AND g.Gd_cpdh=c.jjcp_cpdh')
-//             ->order('c.UniqId desc')
-//             ->select();
-//         $total = db('成品入仓')->where($option)->count();
-//         foreach ($rows as $key=>$value) {
-//             $row = db('成品入仓')
-//                 ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
-//                 ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
-//                 ->order('Sys_rq desc')
-//                 ->select();
-//             $rows[$key]['jjcp_sls'] = 0;
-//             foreach ($row as $k=>$v) {
-//                 $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
-//             }
-//             if ($value['订单数量']!=0){
-//                 $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
-//             }else{
-//                 $rows[$key]['完成率'] = '';
-//             }
-//             $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
-//             $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
-
-//             $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
-//         }
-
-//         $data = [
-//             'total'          => $total,
-//             'rows'          => $rows,
-//         ];
-//         $this->success('成功',$data);
-//     }
 public function getList()
 {
     // 验证请求方式
@@ -449,13 +385,6 @@ public function getList()
             ->order('j.yj_yjno asc')
             ->select();
 
-        // $rows = db()->table('工单_印件资料')->alias('j')
-        //     ->field('g.Gd_gdbh, j.yj_Yjno as yj_yjno, rtrim(g.销售订单号) as 销售订单号, rtrim(j.yj_Yjdh) as yj_Yjdh,
-        //     rtrim(j.yj_yjmc) as yj_yjmc, rtrim(g.成品代号) as 成品代号, rtrim(g.成品名称) as 成品名称, rtrim(g.客户料号) as 客户料号')
-        //     ->where(['g.Gd_gdbh'=>$gdbh])
-        //     ->join(['工单_基本资料'=>'g'],'g.Gd_gdbh=j.Yj_Gdbh')
-        //     ->select();
-
         foreach ($rows as $key=>$value){
             $rows[$key]['gdyj'] =  $value['Gd_gdbh'].' -'.sprintf("%02d", $value['yj_yjno']).'-'.$value['yj_yjmc'];
         }
@@ -487,11 +416,6 @@ public function getList()
         }else{
             $this->error('参数错误');
         }
-//        if (isset($req['rcsl'])){
-//            $rcsl = $req['rcsl'];
-//        }else{
-//            $this->error('参数错误');
-//        }
 
         $rows = db('工单_基本资料')->alias('g')
             ->field('订单数量*10000 as 订单数量, gd_statu')
@@ -504,104 +428,73 @@ public function getList()
             ->where(['jjcp_gdbh'=>$gdbh, 'jjcp_cpdh'=>$cpdh])
             ->sum('jjcp_sl');
 
-//        if ($rows['订单数量']<($rows['jjcp_sls']+$rcsl) || mb_substr($rows['gd_statu'],-3,3)=='已完工'){
-//            $this->error('已完工或入仓数量超过订单数量',$rows);
-//        }
-
         $this->success('成功',$rows);
     }
 
     /**
      * 新增
      * @ApiMethod (POST)
-     * @param string
      */
     public function add()
     {
-        if(!$this->request->isPost()){
+        if (!$this->request->isPost()) {
             $this->error('请求方式错误');
         }
-        //连接mongodb
-        $mongodb = Db::connect(config('database.mongodb'));
+
         $req = $this->request->param();
-        $arr = [
-            'Sys_id',
-            '入仓类型', '仓库编号', '仓库名称',
-            'jjcp_num',
-            'jjcp_gdbh', 'jjcp_yjno', '订单编号',
-            'jjcp_cpdh', 'jjcp_cpmc',
-            '成品编码', '成品名称',
-            '客户料号',
-            'jjcp_smb', 'jjcp_sj',
-            'jjcp_sl', 'jjcp_dw',
-            '机型备注',
-            'jjcp_desc'
-        ];
-        $name = \db('工单_印件资料')
-            ->where('Yj_Gdbh',$req['jjcp_gdbh'])
-            ->where('yj_Yjno',$req['jjcp_yjno'])
-            ->value('yj_yjmc');
-        if ($name !== $req['jjcp_cpmc']){
-            $this->error('产品名称错误');
-        }
-        $data = [];
-        foreach ($arr as $key => $value){
-            if (!isset($req[$value])){
-                $this->error('参数错误',$value,$key+1);
-            }
-            $data[$value] = $req[$value];
+        $data = $this->buildAddData($req);
+        $this->validateProductName($data['jjcp_gdbh'], $data['jjcp_yjno'], $data['jjcp_cpmc']);
+
+        $existingEndBoard = $this->findExistingEndBoard($data['jjcp_gdbh'], $data['jjcp_yjno']);
+        if ($existingEndBoard) {
+            $this->error(
+                $existingEndBoard['jjcp_gdbh'] . '工单 -- 印件' . $existingEndBoard['jjcp_yjno'] . '已经进入末版,无法继续操作'
+            );
         }
-        $data['Sys_rq'] = date('Y-m-d H:i:s');
 
-        //查询UniqId
-        $UniqId = db('成品入仓')->max('UniqId');
-        $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
+        $this->validateMaterialReceived($data['jjcp_gdbh'], $data['jjcp_yjno']);
 
-        //判断当前工单是否存在已提交模版
-        $existingRecord = db('成品入仓')
-            ->where('jjcp_gdbh', $data['jjcp_gdbh'])
-            ->where('jjcp_yjno', $data['jjcp_yjno'])
-            ->where('jjcp_smb', '<>', '') // 判断 jjcp_smb 不为空
-            ->find();
-        if ($existingRecord) {
-            $this->error($existingRecord['jjcp_gdbh'].'工单 -- 印件'.$existingRecord['jjcp_yjno'].'已经进入末版,无法继续操作');
-        }
+        $data['UniqId'] = $this->generateFinishStockUniqId();
+        $mongodb = Db::connect(config('database.mongodb'));
+        $this->saveFinishStock($data, $mongodb);
 
-        //开启事务
-        db()->startTrans();
-        try{
-            $sql = db('成品入仓')->fetchSql(true)->insert($data);
-            $bool = db()->query($sql);
-            //新增进MongoDB
-            $res = $mongodb->name('finished_products')->insert($data);
-            // 提交事务
-            db()->commit();
+        try {
+            $synchronization = new \app\api\controller\Synchronization();
+            $synchronization->syncFinishStockMiddle($data['UniqId'], '新增');
         } catch (\Exception $e) {
-            // 回滚事务
-            db()->rollback();
-            $this->error($e->getMessage());
+            $this->error('成品入仓已保存,但' . $e->getMessage(), ['UniqId' => $data['UniqId']]);
         }
-        if($bool===false) $this->error('失败');
-        //末版输入进入超节损
-        $oederLoss = new \app\api\controller\OrderSuperLoss();
-        if (strpos($data['jjcp_smb'],'末') !== false){
-            try {
-                $result = $oederLoss->OneOrderSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
-            } catch (DataNotFoundException $e) {
-            } catch (ModelNotFoundException $e) {
-            } catch (DbException $e) {
-            }
-            db('工单_质量考核汇总')
-                ->where('Gy0_gdbh',$data['jjcp_gdbh'])
-                ->where('印件及工序',$data['jjcp_yjno'])
-                ->delete();
-            $sql = db('工单_质量考核汇总')->fetchSql(true)->insertAll($result);
-            $res = db()->query($sql);
-            if($res===false) $this->error('失败');
+
+        if ($this->isEndBoard($data['jjcp_smb'])) {
+            $this->handleEndBoardSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
         }
 
-        $this->success('成功');
+        $this->success('成功', ['UniqId' => $data['UniqId']]);
+    }
+
+    /**
+     * 查询成品入仓同步操作日志
+     * @ApiMethod (GET)
+     * @param int|string $UniqId 成品入仓 UniqId
+     */
+    public function getSyncLog()
+    {
+        if (!$this->request->isGet()) {
+            $this->error('请求方式错误');
+        }
 
+        $uniqId = $this->request->param('UniqId');
+        if ($uniqId === null || $uniqId === '') {
+            $this->error('参数错误', 'UniqId');
+        }
+
+        $list = db('工单_成品入仓同步操作日志')
+            ->where('UniqId', (int)$uniqId)
+            ->field('id,Gdbh,wlbm,yjmc,Yjdh,Yjno,sys_id,sys_rq,type,status,status_msg,UniqId')
+            ->order('id desc')
+            ->select();
+
+        $this->success('成功', $list ?: []);
     }
 
     /**
@@ -670,8 +563,17 @@ public function getList()
             db()->rollback();
             $this->error($e->getMessage());
         }
+        if($bool===false) $this->error('失败');
+
+        try {
+            $synchronization = new \app\api\controller\Synchronization();
+            $synchronization->syncFinishStockMiddle($req['UniqId'], '修改');
+        } catch (\Exception $e) {
+            $this->error('成品入仓已保存,但' . $e->getMessage(), ['UniqId' => $req['UniqId']]);
+        }
+
         $oederLoss = new \app\api\controller\OrderSuperLoss();
-        if (strpos($data['jjcp_smb'],'末') !== false){
+        if (isset($data['jjcp_smb']) && strpos($data['jjcp_smb'],'末') !== false){
             try {
                 $result = $oederLoss->OneOrderSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
             } catch (DataNotFoundException $e) {
@@ -687,8 +589,6 @@ public function getList()
             if($res===false) $this->error('失败');
         }
 
-        if($bool===false) $this->error('失败');
-
         $this->success('成功');
     }
 
@@ -1243,23 +1143,16 @@ public function getList()
         }
         krsort($data1);
         //成品入仓中jjcp_smb不为空的工单
-//        $rows1 = db('成品入仓')
-//            ->where('jjcp_smb','<>','')
-//            ->order('jjcp_gdbh desc')
-//            ->column("CONCAT(jjcp_gdbh, '-', jjcp_yjno) AS gdyj, UniqId");
 
         $rows2 = db('成品入仓')
             ->where('jjcp_sj','>=',$date)
             ->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");
-//        $rows3 = db('工单_印件资料')->cache(true,86400)
-//            ->group('Yj_Gdbh, yj_Yjno')
-//            ->column("CONCAT( Yj_Gdbh, '-',  yj_Yjno) AS gdyj,
-//            Yj_Gdbh, yj_Yjno, yj_yjmc, yj_成品数量, yj_实际投料");
+            
         $data = [];
         foreach($data1 as $key=>$value){
-//            if(!array_key_exists($key,$rows1)){
+
             $subArray = [];
             $gdbh = strtoupper(explode('-',$key)[0]);
             $yjno = explode('-',$key)[1];
@@ -1294,91 +1187,6 @@ public function getList()
             $subArray['sczl_cls'] = (string)floatval($value);
             array_push($data,$subArray);
         }
-//        }
-
-
-        // $rows = db('db_包装产量预报')
-        //     ->field('sczl_rq,sczl_gdbh1,sczl_gdbh2,sczl_gdbh3,sczl_gdbh4,sczl_gdbh5,sczl_gdbh6,Sys_rq,mod_rq,UniqId')
-        //     ->where('Sys_rq','>=','2023-10-25')
-        //     ->select();
-        // $uniqueValues = [];
-        // foreach ($rows as $row) {
-        //     $gdbhArray = array($row['sczl_gdbh1'], $row['sczl_gdbh2'], $row['sczl_gdbh3'], $row['sczl_gdbh4'], $row['sczl_gdbh5'], $row['sczl_gdbh6']);
-        //     $uniqueValues = array_merge($uniqueValues, array_unique($gdbhArray));
-        // }
-
-        // $uniqueValues = array_values(array_unique($uniqueValues));
-        // halt($uniqueValues);
-        // $rows = db('成品入仓')->alias('c')
-        //     ->field('c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
-        //     y.yj_成品数量, y.yj_实际投料, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_smb) as jjcp_smb,
-        //     sum(c.jjcp_sl) as jjcp_sls, left(max(c.Sys_rq),10) as Sys_rq')
-        //     ->where($where)
-        //     ->where('y.yj_Yjdh=c.jjcp_cpdh')
-        //     ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
-        //     ->order('c.jjcp_gdbh desc, c.jjcp_yjno asc')
-        //     ->group('c.jjcp_gdbh, c.jjcp_cpdh')
-        //     ->page($page,$limit)
-        //     ->select();
-
-        // $total = db('成品入仓')->alias('c')
-        //     ->where($where)
-        //     ->where('y.yj_Yjdh=c.jjcp_cpdh')
-        //     ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
-        //     ->group('c.jjcp_gdbh, c.jjcp_cpdh')
-        //     ->count();
-        // $brr = db('成品入仓')
-        //     ->group('jjcp_gdbh,jjcp_cpdh')
-        //     ->column('CONCAT(jjcp_gdbh, "-", rtrim(jjcp_cpdh)), sum(jjcp_sl)');
-
-        // $num = db('db_包装产量预报')->count();
-        // $arr1 = db('db_包装产量预报')
-        //     ->field('sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6,
-        //     substr(sczl_yjGx1,2,1) as sczl_yjGx1, substr(sczl_yjGx2,2,1) as sczl_yjGx2,
-        //     substr(sczl_yjGx3,2,1) as sczl_yjGx3, substr(sczl_yjGx4,2,1) as sczl_yjGx4,
-        //     substr(sczl_yjGx5,2,1) as sczl_yjGx5, substr(sczl_yjGx6,2,1) as sczl_yjGx6,
-        //     (sczl_cl1*sczl_PgCl1+sczl_clAdd1) as sczl_cls1,
-        //     (sczl_cl2*sczl_PgCl2+sczl_clAdd2) as sczl_cls2,
-        //     (sczl_cl3*sczl_PgCl3+sczl_clAdd3) as sczl_cls3,
-        //     (sczl_cl4*sczl_PgCl4+sczl_clAdd4) as sczl_cls4,
-        //     (sczl_cl5*sczl_PgCl5+sczl_clAdd5) as sczl_cls5,
-        //     (sczl_cl6*sczl_PgCl6+sczl_clAdd6) as sczl_cls6
-        //     ')
-        //     ->limit($num)
-        //     ->select();
-
-        // $data1 = [];
-        // foreach ($arr1 as $k=>$v){
-        //     for ($i=1;$i<=6;$i++){
-        //         if(array_key_exists($v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i],$data1)){
-        //             $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] += $v['sczl_cls'.$i];
-        //         }else{
-        //             $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] = $v['sczl_cls'.$i];
-        //         }
-        //     }
-        // }
-
-        // foreach ($rows as $key=>$value) {
-        //     $rows[$key]['yj_成品数量'] = (string)floatval($value['yj_成品数量']*10000);
-        //     $rows[$key]['yj_实际投料'] = (string)floatval($value['yj_实际投料']*10000);
-        //     if(array_key_exists($value['jjcp_gdbh'].'-'.$value['jjcp_yjno'],$data1)){
-        //         $rows[$key]['包装产量'] = $data1[$value['jjcp_gdbh'].'-'.$value['jjcp_yjno']];
-        //     }else{
-        //         $rows[$key]['包装产量'] = '';
-        //     }
-        //     if(array_key_exists($value['jjcp_gdbh'].'-'.$value['jjcp_cpdh'],$brr)){
-        //         $rows[$key]['入仓数量'] = $brr[$value['jjcp_gdbh'].'-'.$value['jjcp_cpdh']];
-        //     }else{
-        //         $rows[$key]['入仓数量'] = '';
-        //     }
-        //     if($value['jjcp_smb'] !=''){
-        //         $rows[$key]['状态'] = '完工';
-        //         $rows[$key]['缺数'] = (int)$rows[$key]['yj_成品数量']-(int)$rows[$key]['包装产量'];
-        //     }else{
-        //         $rows[$key]['状态'] = '';
-        //         $rows[$key]['缺数'] = '';
-        //     }
-        // }
 
         $data = [
             'total'         => count($data),
@@ -1526,4 +1334,176 @@ public function getList()
 
         $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
     }
+
+    /**
+     * 构建新增入仓数据
+     * @param array $req
+     * @return array
+     */
+    protected function buildAddData(array $req)
+    {
+        $fields = [
+            'Sys_id',
+            '入仓类型', '仓库编号', '仓库名称',
+            'jjcp_num',
+            'jjcp_gdbh', 'jjcp_yjno', '订单编号',
+            'jjcp_cpdh', 'jjcp_cpmc',
+            '成品编码', '成品名称',
+            '客户料号',
+            'jjcp_smb', 'jjcp_sj',
+            'jjcp_sl', 'jjcp_dw',
+            '机型备注',
+            'jjcp_desc',
+        ];
+
+        $data = [];
+        foreach ($fields as $index => $field) {
+            if (!isset($req[$field])) {
+                $this->error('参数错误', $field, $index + 1);
+            }
+            $data[$field] = $req[$field];
+        }
+        $data['Sys_rq'] = date('Y-m-d H:i:s');
+
+        return $data;
+    }
+
+    /**
+     * 校验印件产品名称
+     * @param string $gdbh
+     * @param string $yjno
+     * @param string $cpmc
+     */
+    protected function validateProductName($gdbh, $yjno, $cpmc)
+    {
+        $name = db('工单_印件资料')
+            ->where('Yj_Gdbh', $gdbh)
+            ->where('yj_Yjno', $yjno)
+            ->value('yj_yjmc');
+        if ($name !== $cpmc) {
+            $this->error('产品名称错误');
+        }
+    }
+
+    /**
+     * 查询工单印件是否已存在末版记录
+     * @param string $gdbh
+     * @param string $yjno
+     * @return array|null
+     */
+    protected function findExistingEndBoard($gdbh, $yjno)
+    {
+        return db('成品入仓')
+            ->where('jjcp_gdbh', $gdbh)
+            ->where('jjcp_yjno', $yjno)
+            ->where('jjcp_smb', '<>', '')
+            ->find();
+    }
+
+    /**
+     * 校验工单印件是否已完全领料
+     * @param string $gdbh
+     * @param string $yjno
+     */
+    protected function validateMaterialReceived($gdbh, $yjno)
+    {
+        $materialRecord = db('工单_印件资料')
+            ->alias('a')
+            ->join('物料_收发记录 b', 'a.Yj_Gdbh=b.st_gdbh and a.yj_cpdh=b.cpdh')
+            ->where('a.Yj_Gdbh', $gdbh)
+            ->where('a.yj_Yjno', $yjno)
+            ->group('b.st_wlbh')
+            ->order('b.st_wlbh asc')
+            ->column('b.st_wlbh');
+
+        $bomRecord = db('工单_印件资料')
+            ->alias('a')
+            ->join('工单_bom资料 b', 'a.Yj_Gdbh=b.BOM_工单编号 and a.yj_Yjno=b.BOM_工单行号 and a.yj_cpdh=b.BOM_产品编号')
+            ->where('a.Yj_Gdbh', $gdbh)
+            ->where('a.yj_Yjno', $yjno)
+            ->where('b.BOM_实际用量', '<>', 0)
+            ->group('b.BOM_物料编码')
+            ->order('b.BOM_物料编码 asc')
+            ->column('b.BOM_物料编码');
+
+        foreach ($bomRecord as $materialCode) {
+            if (!in_array($materialCode, $materialRecord)) {
+                $this->error('工单' . $gdbh . '印件' . $yjno . '物料' . $materialCode . '未领料');
+            }
+        }
+    }
+
+    /**
+     * 生成成品入仓 UniqId
+     * @return int
+     */
+    protected function generateFinishStockUniqId()
+    {
+        $uniqId = db('成品入仓')->max('UniqId');
+        return $uniqId < 10000000 ? 10000000 : $uniqId + 1;
+    }
+
+    /**
+     * 保存成品入仓数据到 MySQL 和 MongoDB
+     * @param array $data
+     * @param mixed $mongodb
+     */
+    protected function saveFinishStock(array $data, $mongodb)
+    {
+        db()->startTrans();
+        try {
+            $sql = db('成品入仓')->fetchSql(true)->insert($data);
+            $inserted = db()->query($sql);
+            if ($inserted === false) {
+                throw new \Exception('MySQL 保存失败');
+            }
+            $mongodb->name('finished_products')->insert($data);
+            db()->commit();
+        } catch (\Exception $e) {
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+    }
+
+    /**
+     * 判断是否为末版
+     * @param string $smb
+     * @return bool
+     */
+    protected function isEndBoard($smb)
+    {
+        return strpos((string)$smb, '末') !== false;
+    }
+
+    /**
+     * 末版入仓后进入超节损
+     * @param string $gdbh
+     * @param string $yjno
+     */
+    protected function handleEndBoardSuperLoss($gdbh, $yjno)
+    {
+        $orderLoss = new OrderSuperLoss();
+        $result = [];
+        try {
+            $result = $orderLoss->OneOrderSuperLoss($gdbh, $yjno);
+        } catch (DataNotFoundException $e) {
+        } catch (ModelNotFoundException $e) {
+        } catch (DbException $e) {
+        }
+
+        if (empty($result)) {
+            return;
+        }
+
+        db('工单_质量考核汇总')
+            ->where('Gy0_gdbh', $gdbh)
+            ->where('印件及工序', $yjno)
+            ->delete();
+
+        $sql = db('工单_质量考核汇总')->fetchSql(true)->insertAll($result);
+        $inserted = db()->query($sql);
+        if ($inserted === false) {
+            $this->error('超节损数据保存失败');
+        }
+    }
 }