瀏覽代碼

超节损优化工单状态变更日志

unknown 2 周之前
父節點
當前提交
d4e9a0e003
共有 2 個文件被更改,包括 36 次插入107 次删除
  1. 24 14
      application/api/controller/OrderSuperLoss.php
  2. 12 93
      application/api/controller/WorkOrder.php

+ 24 - 14
application/api/controller/OrderSuperLoss.php

@@ -1018,17 +1018,17 @@ class OrderSuperLoss extends Api
             if (!$tlRes){
                 $i++;
             }
-            $logData = [
-                'Gd_gdbh'      => $list['st_gdbh'], // 使用原始工单编号
-                'ModifyUser'   => $value['sys_id'],
-                'ModifyTime'   => date('Y-m-d H:i:s'),
-                'FieldName'    => 'st_sl',
-                'OldValue'     => $value['old_number'],
-                'NewValue'     => $value['number'],
-                'ModifySource' => '物料投料数修改'
-            ];
-            $logSql = \db('系统操作日志表')->fetchSql(true)->insert($logData);
-            $result = \db()->query($logSql);
+//            $logData = [
+//                'Gd_gdbh'      => $list['st_gdbh'], // 使用原始工单编号
+//                'ModifyUser'   => $value['sys_id'],
+//                'ModifyTime'   => date('Y-m-d H:i:s'),
+//                'FieldName'    => 'st_sl',
+//                'OldValue'     => $value['old_number'],
+//                'NewValue'     => $value['number'],
+//                'ModifySource' => '物料投料数修改'
+//            ];
+//            $logSql = \db('系统操作日志表')->fetchSql(true)->insert($logData);
+//            $result = \db()->query($logSql);
 
         }
         $total_num = \db('物料_收发记录')
@@ -1052,7 +1052,9 @@ class OrderSuperLoss extends Api
         /**
          * 重新计算工单超节损数据
          **/
+
         $result = $this->OneOrderSuperLoss($list['st_gdbh'],$yjno);
+
         //先删除数据
         \db('工单_质量考核汇总')
             ->where('Gy0_gdbh',$list['st_gdbh'])
@@ -1277,6 +1279,9 @@ class OrderSuperLoss extends Api
             ->where('jjcp_yjno', $param['yjno'])
             ->where('jjcp_smb', '末 板')
             ->find();
+        if (empty($workOrderData)) {
+            $this->error('工单' . $param['gdbh'] . '-' . $param['yjno'] . '未查询到末板入仓记录');
+        }
         //入仓数量
         $total_number = \db('成品入仓')
             ->where('jjcp_gdbh', $param['gdbh'])
@@ -1309,7 +1314,7 @@ class OrderSuperLoss extends Api
                 preg_match('/(\d+)g/',$data['yj_zzmc'], $matches);
                 if ($data['st_dw'] === '吨'){
                     $data['投料'] = round(($data['投料']*1000*1000)/$matches[1]/($number1*$number2)*1000000);
-                    $data['st_dw'] === '张';
+                    $data['st_dw'] = '张';
                 }
             }
 
@@ -1317,10 +1322,10 @@ class OrderSuperLoss extends Api
 
         //将开数、联数为0重新赋值
         if ($data['ls'] == 0) {
-            $data['ls'] === 1;
+            $data['ls'] = 1;
         }
         if ($data['ks'] == 0) {
-            $data['ks'] === 1;
+            $data['ks'] = 1;
         }
 
         //计算工单实际投料
@@ -1336,6 +1341,10 @@ class OrderSuperLoss extends Api
                         (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$workOrderData['jjcp_gdbh']}' AND sczl_yjno = '{$workOrderData['jjcp_yjno']}'
                         UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$workOrderData['jjcp_gdbh']}' AND sczl_yjno = '{$workOrderData['jjcp_yjno']}') AS combined_result";
         $gxh_arr = Db::query($gxh_sql);
+        if (empty($gxh_arr)) {
+            $this->error("工单".$workOrderData['jjcp_gdbh']."-".$workOrderData['jjcp_yjno']."未查询到报工信息,请核查该工单是否已进入超节损");
+
+        }
         //整理查询处理的工序编号
         $gxh_values = array_column($gxh_arr, 'sczl_gxh');
         //将工序号小于10的编号前面加0
@@ -2215,6 +2224,7 @@ class OrderSuperLoss extends Api
             ->field('a.jjcp_gdbh,a.jjcp_yjno')
             ->group('a.jjcp_gdbh,a.jjcp_yjno')
             ->select();
+
         $i = 0;
         if (empty($list)) {
             $this->error('未搜索到工单入仓数据');

+ 12 - 93
application/api/controller/WorkOrder.php

@@ -1150,99 +1150,6 @@ class WorkOrder extends Api
      * @throws \think\exception\DbException
      * @throws \think\exception\PDOException
      */
-//    public function ProcessDetailEdit()
-//    {
-//        if (Request::instance()->isPost() === false){
-//            $this->error('请求错误');
-//        }
-//        $param = Request::instance()->post();
-//        if (empty($param) || isset($param['UniqId']) === false){
-//            $this->error('参数错误');
-//        }
-//        // 获取修改前原始数据
-//        $oldData = \db('工单_工艺资料')
-//            ->where('UniqId', $param['UniqId'])
-//            ->find();
-//        //获取工单损耗代号数据
-//        if (empty($param['Gy0_shdh'])){
-//            $rate['rate0'] = 0;
-//            $rate['rate1'] = 0;
-//        }else{
-//            $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
-//        }
-//        if ($param['备选工序'] == ''){
-//            $param['备选工序'] = null;
-//        }
-//        $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
-//        $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
-//        $param['Mod_rq']  = date('Y-m-d H:i:s',time());
-//        $UniqId = $param['UniqId'];
-//        unset($param['UniqId']);
-//        //获取工单第一道工艺编号
-//        $minGxh = \db('工单_工艺资料')->where('Gy0_gdbh',$param['Gy0_gdbh'])->column('min(Gy0_gxh) as gxh');
-//        //修改工艺资料
-//        $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
-//        $res = \db()->query($sql);
-//        //获取工艺资料数据
-//        $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
-//        //如果是第一道工序需从印件资料中获取计划产量
-//        $list['计划接货数'] = \db('工单_印件资料')->where('Yj_Gdbh',$param['Gy0_gdbh'])->where('yj_Yjno',$param['Gy0_yjno'])->column('yj_平张投料')[0];
-//        //修改工单状态
-//        $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
-//        if ($status['status'] !== '2-生产中'){
-//            $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
-//            Db::query($statusSql);
-//        }
-//        //重新分配工序计划产量
-//        if ((int)$list['计划接货数'] > 0){
-//            $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],0,$list['计划接货数']);
-//        }
-//        // 记录变更日志
-//        if ($res) {
-//            $newData = array_merge($oldData, $param); // 合并新旧数据
-//            $changes = [];
-//
-//            // 动态对比所有参数字段(排除系统字段)
-//            $excludeFields = ['UniqId', 'Mod_rq'];
-//            foreach ($param as $field => $newValue) {
-//                if (in_array($field, $excludeFields)) continue;
-//
-//                $oldValue = $oldData[$field] ?? 'NULL';
-//                if ($oldValue != $newValue) {
-//                    $changes[] = [
-//                        'field' => $field,
-//                        'old'   => $oldValue,
-//                        'new'   => $newValue
-//                    ];
-//                }
-//            }
-//
-//            // 批量插入日志
-//            if (!empty($changes)) {
-//                $logData = [];
-//                foreach ($changes as $change) {
-//                    $logData[] = [
-//                        'Gd_gdbh'      => $oldData['Gy0_gdbh'],
-//                        'yjno'         => $oldData['Gy0_yjno'],
-//                        'gxh'          => $oldData['Gy0_gxh'],
-//                        'ModifyUser'   => $param['Sys_id'],
-//                        'ModifyTime'   => date('Y-m-d H:i:s'),
-//                        'FieldName'    => $change['field'],
-//                        'OldValue'     => $change['old'],
-//                        'NewValue'     => $change['new'],
-//                        'ModifySource' => '工艺调整'
-//                    ];
-//                }
-//                $logSql = \db('系统操作日志表')->fetchSql(true)->insertAll($logData);
-//                \db()->query($logSql);
-//            }
-//        }
-//        if ($res !== false){
-//            $this->success('成功');
-//        }else{
-//            $this->error('失败');
-//        }
-//    }
     public function ProcessDetailEdit()
     {
         Db::startTrans();
@@ -1363,6 +1270,16 @@ class WorkOrder extends Api
             if ($status['status'] !== '2-生产中'){
                 $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
                 Db::query($statusSql);
+                $logData = [
+                    'Gd_gdbh'      => $param['Gy0_gdbh'],
+                    'ModifyUser'   => $param['Sys_id'],
+                    'ModifyTime'   => date('Y-m-d H:i:s'),
+                    'FieldName'    => 'gd_statu',
+                    'OldValue'     => $status['status'],
+                    'NewValue'     => '2-生产中',
+                    'ModifySource' => '工单状态变更'
+                ];
+                \db('系统操作日志表')->insert($logData);
             }
             //重新分配工序计划产量
             if ((int)$list['计划接货数'] > 0){
@@ -1955,6 +1872,7 @@ class WorkOrder extends Api
                 ->fetchSql(true)
                 ->update($data);
         }
+
         //开启事务
         Db::startTrans();
         try{
@@ -1964,6 +1882,7 @@ class WorkOrder extends Api
             //提交事务
             \db()->commit();
         } catch (\Exception $e) {
+            echo $e->getMessage();
             // 回滚事务
             \db()->rollback();
         }