浏览代码

first commit

liuhairui 8 月之前
父节点
当前提交
1210ddaae3

+ 470 - 2272
application/api/controller/Facility.php

@@ -1,137 +1,54 @@
 <?php
-
 namespace app\api\controller;
-
-
 use app\common\controller\Api;
 use think\Db;
 use think\Request;
-
 /**
  * 质量继绩效管理
  */
-
-class Facility extends Api
-{
+class Facility extends Api{
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
 
 
     /**
-     * 查询月份数据
+     * 1.0查询子订单编号
      */
-    public function ApiMouthlist() {
-        // 检查请求类型是否为GET
+    public function Apiorderids() {
         if ($this->request->isGet() === false) {
             $this->error('请求错误');
         }
         $param = $this->request->param();
-        // 查询符合条件的数据
-        $list = \db('设备_质量汇总')
-            ->where('状态', $param['code'])
-            ->where('mod_rq', null)
-            ->group('Sys_rq')
+        $gdlist = \db('工单_印件资料')
+            ->field('子订单编号')
+            ->where('订单编号',$param['order'])
+            ->where('Mod_rq', null)
             ->select();
-        if (empty($list)) {
-            $this->error('没有找到数据');
-        }
-        // 用于存储按年和月分类的数据
-        $data = [];
-        // 遍历查询结果,将日期按年、月分组
-        foreach ($list as $item) {
-            // 获取 Sys_rq 字段的值(日期)
-            $sys_rq = $item['Sys_rq'];
-
-            // 提取年、月、日
-            $year = date('Y', strtotime($sys_rq));
-            $month = date('Y-m', strtotime($sys_rq));
-            $day = date('Y-m-d', strtotime($sys_rq));
-
-            // 将数据按年、月、日分类
-            if (!isset($data[$year])) {
-                $data[$year] = [];
-            }
-
-            if (!isset($data[$year][$month])) {
-                $data[$year][$month] = [];
-            }
-
-            // 将日期加入到对应的年、月下
-            $data[$year][$month][] = $day;
-        }
-        $this->success('成功', $data);
+        $this->success('成功', [
+            'list' => $gdlist,
+        ]);
     }
 
-
     /**
-     * 新增次品和新增返工
+     * 1.1查询订单号或生产款号
      */
-    public function ApiAddDefective(){
-        if (!$this->request->isPost()) {
-            $this->error('非法请求');
-        }
-        $params = $this->request->param();
-        if (empty($params)){
-            $this->error('参数错误');
-        }
-
-        $res = \db('设备_质量汇总')->where('mod_rq', null)->order('status_num desc')->find();
-        //记录每次新增次数排序
-        $status_num = $res['status_num'];
-
-        // 构建单条记录的函数,传递 $list_gd 作为参数
-        function buildRecords($item,$status_num) {
-            // 拆分物料名称(假设格式为 面料分类-面料名称)
-            $materialParts = explode('-', $item['物料名称']);
-            $materialCategory = isset($materialParts[0]) ? $materialParts[0] : '';  // 面料分类
-            $materialName = isset($materialParts[1]) ? $materialParts[1] : '';  // 面料名称
-
-
-            return [
-                '订单编号' => $item['订单编号'],
-                '生产款号' => $item['生产款号'],
-                '款式' => $item['款式'],
-                '颜色' => $item['颜色'],
-                '尺码' => $item['尺码'],
-                '数量' => $item['数量'],
-                '组别' => $item['组别'],
-                '实际用料' => $item['实际用料'],
-                '计划用料' => $item['计划用料'],
-                '备注' => $item['备注'],
-                '问题分类' => $item['问题分类'],
-                'sczl_rq' => date('Y-m-d H:i:s'),
-                'Sys_rq' =>  $item['Sys_rq'],
-                'Sys_id' => $item['Sys_id'],
-                '状态' => $item['状态'],
-                'status_num' => $status_num + 1,
-                '面料分类' => $materialCategory,
-                '面料名称' => $materialName,
-
-            ];
-        }
-
-        // 检查是否是索引数组(多条记录)
-        if (isset($params[0]) && is_array($params[0])) {
-            foreach ($params as $item) {
-                $list[] = buildRecords($item,$status_num);
-            }
-        } else {
-            // 处理单条记录
-            $list[] = buildRecords($params,$status_num);
-        }
-
-        // 插入数据到设备_产量计酬表
-        $result = \db('设备_质量汇总')->insertAll($list);
-        if ($result) {
-            $this->success('数据插入成功 : ' . date('H:i:s'));
-        } else {
-            $this->error('数据插入失败');
+    public function Apiorder() {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
         }
+        $param = $this->request->param();
+        $gdlist = \db('工单_基本资料')
+            ->field('订单编号,生产款号')
+            ->where('订单编号|生产款号','like','%'.$param['search'].'%')
+            ->where('Mod_rq', null)
+            ->select();
+        $this->success('成功', [
+            'list' => $gdlist,
+        ]);
     }
 
-
     /**
-     * 查询订单对应尺码
+     * 1.2查询新增基本信息
      */
     public function queryOrderSize() {
         // 检查请求类型是否为GET
@@ -140,28 +57,38 @@ class Facility extends Api
         }
         $param = $this->request->param();
 
-        // 获取问题分类
-        $fetchCategory = \db('db_问题分类')->field('问题类型')->select();
-        $category = array_column($fetchCategory, '问题类型'); // 获取问题类型列表
+        //问题分类
+        $fetchCategory = \db('db_问题分类')->field('问题类型, classification as 分类名称')->select();
+        $groupedCategories = [];
+        // 遍历数据,将相同分类名称的问题类型归类
+        foreach ($fetchCategory as $item) {
+            $categoryname = $item['分类名称'];
+            $category = $item['问题类型'];
+            // 如果分类名称不存在,则初始化为空数组
+            if (!isset($groupedCategories[$categoryname])) {
+                $groupedCategories[$categoryname] = [];
+            }
+            // 避免重复添加相同的问题类型
+            if (!in_array($category, $groupedCategories[$categoryname])) {
+                $groupedCategories[$categoryname][] = $category;
+            }
+        }
+
 
-        // 查询订单基本信息
         $gdlist = \db('工单_基本资料')
             ->field('订单编号,生产款号,款式,订单数量')
-//            ->where('订单编号|生产款号','like','%'.$param['订单编号'].'%')
             ->where(['订单编号|生产款号' => $param['订单编号']])
             ->where('Mod_rq', null)
             ->find();
+
         if (empty($gdlist)) {
             $this->error('未找到相关数据');
         }
-
-
         // 查询订单尺码信息
         $sizeData = \db('工单_印件资料')->where(['订单编号' => $gdlist['订单编号']])->where('Mod_rq', null)->select();
         if (empty($sizeData)) {
             $this->error('未找到相关数据');
         }
-
         // 计算所有尺码数据
         $sizes = [];
         foreach ($sizeData as $order) {
@@ -171,8 +98,8 @@ class Facility extends Api
                 }
             }
         }
-        $sizes = array_values(array_unique($sizes)); // 去重后的尺码数据
-
+        // 去重后所有子订单重复的尺码数据
+        $sizes = array_values(array_unique($sizes));
         // 获取颜色备注并统计每个颜色的sctotal和zdtotal
         $colorData = []; // 用于存储每个颜色备注对应的sctotal和zdtotal
         foreach ($sizeData as $item) {
@@ -195,63 +122,30 @@ class Facility extends Api
         // 获取颜色备注(去重)
         $colorremark = array_values(array_unique(array_keys($colorData)));
 
-        // 获取面料数据
-        $getAllFabricData = \db('工单_面料资料')
-            ->field('BOM_desc,BOM_物料名称,BOM_定额门幅,BOM_计划门幅,BOM_颜色')
+
+        //面料分类|面料名称
+        $getarr = \db('工单_bom资料')
+            ->field('物料分类,BOM_物料名称')
             ->where('BOM_工单编号', $param['订单编号'])
             ->where('Mod_rq', null)
             ->select();
-        $fabricData = [];
-        $materialSeen = [];
-        $descNullData = [];
-
-        // 处理面料数据
-        foreach ($getAllFabricData as $value) {
+        $fabricArr = []; // 存储拼接后的数据
+        foreach ($getarr as $value) {
             $materialName = $value['BOM_物料名称'];
-            $bomDesc = $value['BOM_desc'];
-            $combinedData = ($bomDesc ? $bomDesc : '') . ' - ' . $materialName;
-
-            // 如果 BOM_desc 为空,记录该物料名称
-            if (empty($bomDesc)) {
-                $descNullData[] = $combinedData;
-                continue;
-            }
-
-            // 如果 BOM_desc 不为空,检查该物料名称是否已经出现过
-            if (!in_array($materialName, $materialSeen)) {
-                $fabricData[] = $combinedData;
-                $materialSeen[] = $materialName;
-            }
-        }
-
-        // 处理 BOM_desc 为空的物料名称,确保不重复添加
-        foreach ($descNullData as $combinedData) {
-            if (!in_array($combinedData, $fabricData)) {
-                $fabricData[] = $combinedData;
-            }
+            $bomDesc = !empty($value['物料分类']) ? $value['物料分类'] : ''; // 防止null
+            // 拼接字符串,并去除可能的前后空格
+            $combinedData = trim($bomDesc . ' - ' . $materialName, ' -');
+            // 存入数组
+            $fabricArr[] = $combinedData;
         }
 
-        // 去重处理面料数据
-        $finalFabricData = [];
-        $seenDescriptions = [];
-
-        foreach ($fabricData as $item) {
-            $parts = explode(' - ', $item);
-            if (count($parts) == 2) {
-                $desc = $parts[0];
-                $material = $parts[1];
-
-                // 如果物料没有被记录过,或者描述不为空,保留数据
-                if (!in_array($material, $seenDescriptions)) {
-                    $finalFabricData[] = $item;
-                    $seenDescriptions[] = $material;
-                }
-            } else {
-                // 描述为空的直接保留
-                $finalFabricData[] = $item;
-            }
-        }
 
+        // 获取面料颜色
+        $getAllFabricData = \db('工单_面料资料')
+            ->field('BOM_物料名称,BOM_定额门幅,BOM_计划门幅,BOM_颜色')
+            ->where('BOM_工单编号', $param['订单编号'])
+            ->where('Mod_rq', null)
+            ->select();
         // 用于统计每个物料的用料情况
         $uniqueFabricData = []; // 去重后的面料数据
         foreach ($getAllFabricData as $fabric) {
@@ -272,7 +166,6 @@ class Facility extends Api
                 }
             }
         }
-
         // 生成实际用料数据
         $actualUsage = [];
         foreach ($materialUsage as $color => $materials) {
@@ -294,10 +187,16 @@ class Facility extends Api
                 ];
             }
         }
-
         foreach ($actualUsage as &$item) {
-            $item['实际用料'] = $item['sctotal'] * $item['定额门幅'];
-            $item['计划用料'] = $item['zdtotal'] * $item['计划门幅'];
+            // 如果 'sctotal' 或 '定额门幅' 为空,则默认为 0
+            $sctotal = isset($item['sctotal']) && is_numeric($item['sctotal']) ? $item['sctotal'] : 0;
+            $demf = isset($item['定额门幅']) && is_numeric($item['定额门幅']) ? $item['定额门幅'] : 0;
+
+            $zdtotal = isset($item['zdtotal']) && is_numeric($item['zdtotal']) ? $item['zdtotal'] : 0;
+            $jhmf = isset($item['计划门幅']) && is_numeric($item['计划门幅']) ? $item['计划门幅'] : 0;
+
+            $item['实际用料'] = $sctotal * $demf;
+            $item['计划用料'] = $zdtotal * $jhmf;
         }
 
         // 选择显示的字段
@@ -313,2223 +212,522 @@ class Facility extends Api
             $finalResult[] = $filteredItem;
         }
 
-
+        //定义接口
         $this->success('成功', [
             'list' => $gdlist,
             'colorremark' => $colorremark,
-            'fetchCategory' => $category,
-            'FabricData' => $finalFabricData,
+            'fetchCategory' => $groupedCategories,
+            'FabricData' => $fabricArr,
             'size' => $sizes,
             '面料统计' => $finalResult
         ]);
     }
 
-
     /**
-     * 查询次片、返工列表数据
+     * 1.3新增次品或返工
      */
-    /**
-     * 查询次片、返工列表数据
-     */
-    public function ApiSubPieceAndReworkList() {
-        if ($this->request->isGet() === false) {
-            $this->error('请求错误');
+    public function ApiAddDefective(){
+        if (!$this->request->isPost()) {
+            $this->error('非法请求');
         }
         $params = $this->request->param();
-        $where = ['mod_rq' => null];
-        if (!empty($params['code'])) {
-            $where['状态'] = $params['code'];
+        if (empty($params)){
+            $this->error('参数错误');
         }
-        if (!empty($params['search'])) {
-            $where['订单编号|生产款号|面料名称'] = ['like', '%' . $params['search'] . '%'];
+        $res = \db('设备_质量汇总')->where('mod_rq', null)->order('status_num desc')->find();
+        //记录每次新增次数排序
+        $status_num = $res['status_num'];
+
+        // 构建单条记录的函数,传递 $list_gd 作为参数
+        function buildRecords($item,$status_num) {
+            // 拆分物料名称(假设格式为 面料分类-面料名称)
+            $materialParts = explode('-', $item['物料名称']);
+            $materialCategory = isset($materialParts[0]) ? $materialParts[0] : '';  // 面料分类
+            $materialName = isset($materialParts[1]) ? $materialParts[1] : '';  // 面料名称
+
+            // 获取最新的单据编号
+            $resd = \db('设备_质量汇总')
+                ->field('单据编号')
+                ->where('mod_rq', null)
+                ->order('单据编号 desc')
+                ->find();
+
+            // 获取当前日期
+            $currentDate = date('Ymd');  // 获取当前日期,格式为:20250327
+            // 如果查询到最新的单据编号
+            if ($resd) {
+                // 提取最新单据编号的日期和流水号部分
+                preg_match('/ZL(\d{8})(\d{4})/', $resd['单据编号'], $matches);
+                // 如果匹配成功,进行累加
+                if ($matches) {
+                    $lastDate = $matches[1];
+                    $lastNumber = (int)$matches[2];  // 将流水号转为数字
+                    // 如果当前日期和最新单据的日期不同,则从0001开始
+                    $newNumber = ($currentDate !== $lastDate) ? '0001' : str_pad($lastNumber + 1, 4, '0', STR_PAD_LEFT);
+                } else {
+                    // 如果没有匹配到正确的格式,则从0001开始
+                    $newNumber = '0001';
+                }
+            } else {
+                // 如果没有查询到单据编号,默认从0001开始
+                $newNumber = '0001';
+            }
+
+            return [
+                '单据编号' => 'ZL' . $currentDate . $newNumber,
+                '订单编号' => $item['订单编号'],
+                '生产款号' => $item['生产款号'],
+                '款式' => $item['款式'],
+                '颜色' => $item['颜色'],
+                '尺码' => $item['尺码'],
+                '数量' => $item['数量'],
+                '组别' => $item['组别'],
+                '实际用料' => $item['实际用料'],
+                '计划用料' => $item['计划用料'],
+                '备注' => $item['备注'],
+                '问题分类' => $item['问题分类'],
+                'sczl_rq' => date('Y-m-d H:i:s'),
+                'Sys_rq' =>  $item['Sys_rq'],
+                'Sys_id' => $item['Sys_id'],
+                '状态' => $item['状态'],
+                'status_num' => $status_num + 1,
+                '面料分类' => $materialCategory,
+                '面料名称' => $materialName,
+
+            ];
         }
-        if (!empty($params['Sys_rq'])) {
-            $where['Sys_rq'] = $params['Sys_rq'];
+
+        // 检查是否是索引数组(多条记录)
+        if (isset($params[0]) && is_array($params[0])) {
+            foreach ($params as $item) {
+                $list[] = buildRecords($item,$status_num);
+            }
+        } else {
+            // 处理单条记录
+            $list[] = buildRecords($params,$status_num);
+        }
+        $result = \db('设备_质量汇总')->insertAll($list);
+        if ($result) {
+            $this->success('数据插入成功 : ' . date('H:i:s'));
+        } else {
+            $this->error('数据插入失败');
         }
-        $query = \db('设备_质量汇总')
-            ->where($where)
-            ->limit(($params['page'] - 1) * $params['limit'], $params['limit']);
-        $res = $query->select();
-        $total = $query->count();
-        $this->success('成功', ['data' => $res, 'total' => $total]);
     }
 
-//    /**
-//     * 更新问题分类接口
-//     */
-//    public function Production()
-//    {
-//
-//    }
-
     /**
-     * 统计面料次品汇总
-     * 统计面料返工汇总
+     * 1.4质量管理左侧菜单栏查询
      */
-//        if ($this->request->isGet() === false){
-//            $this->error('请求错误');
-//        }
-//        $params = $this->request->param();
-
-    public function ApiDefectsAndRework()
-    {
-        // 查询设备质量汇总数据,mod_rq为空
+    public function ApiMouthlist() {
+        // 检查请求类型是否为GET
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        // 查询符合条件的数据
         $list = \db('设备_质量汇总')
+            ->where('状态', $param['code'])
             ->where('mod_rq', null)
-            ->where('状态', '次片')
+            ->order('Sys_rq desc')
+            ->group('Sys_rq')
             ->select();
+        if (empty($list)) {
+            $this->error('未查询到数据');
+        }
+        // 用于存储按年和月分类的数据
+        $data = [];
+        // 遍历查询结果,将日期按年、月分组
+        foreach ($list as $item) {
+            // 获取 Sys_rq 字段的值(日期)
+            $sys_rq = $item['Sys_rq'];
 
-        // 创建一个空数组来存储面料名称及其对应的总数量
-        $fabricSummary = [];
+            // 提取年、月、日
+            $year = date('Y', strtotime($sys_rq));
+            $month = date('Y-m', strtotime($sys_rq));
+            $day = date('Y-m-d', strtotime($sys_rq));
 
-        // 遍历查询结果,累加相同面料名称的数量
-        foreach ($list as $item) {
-            $fabricName = $item['面料名称'];
-            $quantity = $item['数量'];
-            // 如果该面料名称已存在于数组中,则累加数量
-            if (isset($fabricSummary[$fabricName])) {
-                $fabricSummary[$fabricName] += $quantity;
-            } else {
-                // 如果该面料名称不存在,则初始化数量
-                $fabricSummary[$fabricName] = $quantity;
+            // 将数据按年、月、日分类
+            if (!isset($data[$year])) {
+                $data[$year] = [];
             }
-        }
-
-        // 打印结果
-        echo "<pre>";
-        print_r($fabricSummary);
-        echo "</pre>";
-    }
 
+            if (!isset($data[$year][$month])) {
+                $data[$year][$month] = [];
+            }
 
+            // 将日期加入到对应的年、月下
+            $data[$year][$month][] = $day;
+        }
+        $this->success('成功', $data);
+    }
 
     /**
-     * 工序、印件、完成数量
-     * @ApiMethod (GET)
-     * @param string $workOrder  工单编号
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 1.5查询单据汇总次片、返工列表数据
      */
-    public function Procedure()
-    {
-        if ($this->request->isGet() === false){
+    public function ApiSubPieceAnd() {
+        if ($this->request->isGet() === false) {
             $this->error('请求错误');
         }
-        $workOrder = input('Gd_gdbh');
-        $data = [];
-        if (!empty($workOrder)){
-            //右边工艺及完成数量
-            $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
-                ->distinct(true)->order('sczl_gxh')
-                ->column('sczl_gxh');
-            foreach ($Process as $k=>$v){
-                $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
-                    ->where('sczl_gxh',$v)
-                    ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
-                    ->find();
-                if ($res['sczl_yjno']<10){
-                    $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
-                }
-                $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
-                $processList['completed'] = \db('设备_产量计酬')
-                    ->where('sczl_gdbh',$workOrder)
-                    ->where('sczl_gxh',$v)
-                    ->count();
-                array_push($data,$processList);
-            }
-        }
-        $this->success('成功',$data);
-    }
-
-
-    /**
-     * 班组人员及分配比例
-     * @ApiMethod (GET)
-     * @param string $machine 机台编号
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-
-    public function Team()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
+        $params = $this->request->param();
+        $where = ['mod_rq' => null];
+        if (!empty($params['code'])) {
+            $where['状态'] = $params['code'];
         }
-        $machine = input('machine');
-        if (empty($machine)){
-            $this->error('参数错误');
+        if (!empty($params['search'])) {
+            $where['单据编号|订单编号|生产款号|面料名称|面料分类|颜色|问题分类|款式'] = ['like', '%' . $params['search'] . '%'];
         }
-        $where = [
-            'sczl_jtbh' => $machine,
-        ];
-        $field = 'rtrim(sczl_bzdh) as 班组号,rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
-        rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
-        rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
-        rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
-        rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
-        $team = \db('设备_产量计酬')
-            ->where('sczl_jtbh',$machine)
-            ->field($field)
-            ->order('UniqId desc')
-            ->find();
-        $list = \db('设备_班组资料')->where($where)->field($field)->select();
-        $data = [];
-        foreach ($list as $k=>$v){
-            if ($team == $v){
-                $data[$k]['status'] = 1;
-            }else{
-                $data[$k]['status'] = 0;
-            }
-            $data[$k]['ID'] = $v['ID'];
-            $data[$k]['班组号'] = $v['班组号'];
-            for ($i=1;$i<11;$i++){
-                if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
-                    $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
-                    if ($v['rate'.$i] > 0){
-                        $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
-                    }else{
-                        $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' (0.00%'.')';
-                    }
-
-                }
+        // 处理日期查询(支持按天和按月)
+        if (!empty($params['Sys_rq'])) {
+            if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $params['Sys_rq'])) {
+                // 按天查询
+                $where['Sys_rq'] = $params['Sys_rq'];
+            } elseif (preg_match('/^\d{4}-\d{2}$/', $params['Sys_rq'])) {
+                // 按月查询
+                $where['Sys_rq'] = ['like', $params['Sys_rq'] . '%'];
+            }elseif (preg_match('/^\d{4}$/', $params['Sys_rq'])) {
+                // 按年查询
+                //需要年份查询将代码屏蔽取消
+                // $where['Sys_rq'] = $params['Sys_rq'];
+                $this->success('成功', ['data' => '', 'total' => '']);
+            }
+        }
+        $data = \db('设备_质量汇总')
+            ->field('单据编号,订单编号,生产款号,面料名称,面料分类,问题分类,颜色,数量,款式,Sys_rq,尺码,组别')
+            ->where($where)
+            ->select();
+        $mergedData = [];
+        foreach ($data as $item) {
+            //一条数据
+            if (!isset($mergedData[$item['单据编号']])) {
+                $mergedData[$item['单据编号']] = [
+                    '单据编号' => $item['单据编号'],
+                    '订单编号' => $item['订单编号'],
+                    '款式' => $item['款式'],
+                    '生产款号' => $item['生产款号'],
+                    '问题分类' => $item['问题分类'],
+                    '颜色' => $item['颜色'],
+                    '面料名称' => $item['面料名称'],
+                    '面料分类' => $item['面料分类'],
+                    '数量' => $item['数量'],
+                    '组别' => $item['组别'],
+                    '尺码' => $item['尺码'],
+                    'Sys_rq' => $item['Sys_rq']
+                ];
+            } else {
+                // 多条合并数据、数量进行累加
+                $mergedData[$item['单据编号']]['问题分类'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['问题分类']), [$item['问题分类']]))));
+                $mergedData[$item['单据编号']]['颜色'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['颜色']), [$item['颜色']]))));
+                $mergedData[$item['单据编号']]['面料名称'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['面料名称']), [$item['面料名称']]))));
+                $mergedData[$item['单据编号']]['面料分类'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['面料分类']), [$item['面料分类']]))));
+                $mergedData[$item['单据编号']]['订单编号'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['订单编号']), [$item['订单编号']]))));
+                $mergedData[$item['单据编号']]['生产款号'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['生产款号']), [$item['生产款号']]))));
+                $mergedData[$item['单据编号']]['款式'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['款式']), [$item['款式']]))));
+                $mergedData[$item['单据编号']]['尺码'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['尺码']), [$item['尺码']]))));
+                $mergedData[$item['单据编号']]['组别'] = implode(',', array_unique(array_filter(array_merge(explode(',', $mergedData[$item['单据编号']]['组别']), [$item['组别']]))));
+                $mergedData[$item['单据编号']]['数量'] += $item['数量'];
             }
         }
-        $this->success('成功',$data);
+        $finalData = array_values($mergedData);
+        $this->success('成功', ['data' => $finalData, 'total' => count($finalData)]);
     }
 
-
     /**
-     * 当班产量明细
-     * @ApiMethod (GET)
-     * @param string $machine  机台编号
-     * @param string $workOrder  工单编号
-     * @param string $team   班次
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 1.6查询单据明细次片、返工列表数据
      */
-    public function OutputDetail()
-    {
-        if ($this->request->isGet() === false){
+    public function ApiSubPieceAndReworkList() {
+        if ($this->request->isGet() === false) {
             $this->error('请求错误');
         }
-        $machine = input('machine');
-        $workOrder = input('Gd_gdbh');
-        $team = substr(input('team'),0,1);
-        if (empty($machine) || empty($team)){
-            $this->success('');
-        }
-        $sczlTime = date('Y-m-d H:i:s',time());
-        if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
-            $time = date('Y-m-d 00:00:00',time()-86400);
-        }else{
-            $time = date('Y-m-d 00:00:00');
-        }
-        $where = [
-            'sczl_jtbh' => $machine,
-            'sczl_bzdh' => ['like',$team.'%'],
-            'sczl_rq' => $time,
-        ];
-        $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_num) as 流程单号,rtrim(sczl_dedh) as dedh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
-        rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
-        rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
-        rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
-        rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2,rtrim(UniqId) as UniqId,rtrim(sczl_bh98) as 拉料,rtrim(sczl_ls) as ls';
-        $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
-        if (!empty($list)){
-            foreach ($list as $k=>$v){
-                $name = \db('工单_基本资料')->where('Gd_gdbh',$v['工单编号'])->where('行号',$v['yjno'])->field('rtrim(Gd_cpmc) as productName,rtrim(成品名称) as 成品名称')->find();
-                if ($v['yjno']<10){
-                    $list[$k]['yjno'] = '0'.$v['yjno'];
-                }
-                if (!empty($v['拉料'])){
-                    $list[$k]['拉料姓名'] = \db('人事_基本资料')->where('员工编号',$v['拉料'])->value('rtrim(员工姓名) as 员工姓名');
-                }
-                if (isset($list[$k]['拉料姓名']) === false){
-                    $list[$k]['拉料姓名'] = '';
-                }
-                $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
-                $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
-                $list[$k]['产品名称'] = $name['productName'];
-                if (empty($name['productName'])){
-                    $list[$k]['产品名称'] = $name['成品名称'];
-                }
-            }
-            $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
-        SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
-        SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
-        SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
-            $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
-            $total[0]['版数'] = count($list);
-            $list['total'] = $total[0];
-        }
-
 
-        $this->success('成功',$list);
-    }
+        $params = $this->request->param();
+        $where = ['mod_rq' => null];
 
-    /**
-     * 检验记录
-     * @ApiMethod (GET)
-     * @param string $machine  机台编号
-     * @param string $workOrder  工单编号
-     * @param string $team   班次
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function InspectionRecord()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求失败');
-        }
-        $machine = input('machine');
-        $workOrder = input('Gd_gdbh');
-        $team = input('team');
-        if (empty($machine) || empty($workOrder) || empty($team)){
-            $this->success('');
-        }
-        $where = [
-            '设备编号' => $machine,
-            '工单编号' => $workOrder,
-            '班组编号' => $team,
-            '类别' => ['in',['IPQC检验','机台检验']],
-        ];
-        //检验项目筛选
-        $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
-        //检验时间
-        $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
-        foreach ($InspectionTime as $k=>$v){
-            $InspectionTime[$k] = date('H:i',strtotime($v));
-        }
-        //检测记录详情
-        $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
-        $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
-        $data = [];
-        //检测数据
-        foreach ($item as $key=>$value){
-            $SubmissionTime = \db('制程检验_记录')->where($where)
-                ->where('检验项目',$value)
-                ->where('检验结果','合格')
-                ->field('rtrim(提交时间) as 提交时间')
-                ->select();
-            $time = [];
-            foreach ($SubmissionTime as $k=>$v){
-                $time[$k] = date('H:i',strtotime($v['提交时间']));
-            }
-            $data[$key] = [
-                '工单编号' => $nameDetail['工单编号'],
-                '印件号' => $nameDetail['印件号'],
-                '工序名称' => $nameDetail['工序名称'],
-                '检验项目' => $value,
-                'inspectresult' => implode(',',$time),
-            ];
+        // 状态查询
+        if (!empty($params['code'])) {
+            $where['状态'] = $params['code'];
         }
-        $data['inspectiontime'] = $InspectionTime;
-        $this->success('成功',$data);
-    }
 
-
-    /**
-     * 班组维护->班组添加
-     * @ApiMethod (GET)
-     * @param void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function MachineTeamAdd()
-    {
-        if (Request::instance()->isPost() === false ){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $lastId = \db('设备_班组资料')
-            ->order('UniqId desc')
-            ->value('UniqId');
-        if (empty($lastId)){
-            $lastId = 0;
+        // 关键词模糊搜索
+        if (!empty($params['search'])) {
+            $where['单据编号|订单编号|生产款号|面料名称|面料分类|颜色|问题分类'] = ['like', '%' . $params['search'] . '%'];
         }
-        for($i=1;$i<11;$i++){
-            if (!empty($param['sczl_bh'.$i])){
-                $name = \db('人事_基本资料')->where('员工编号',$param['sczl_bh'.$i])->value('员工编号');
-                if (empty($name)){
-                    $this->error('未找到编号'.$param['sczl_bh'.$i].'员工信息,无法添加,请输入正确的员工编号');
-                }
+
+        // 处理日期查询(支持按天和按月)
+        if (!empty($params['Sys_rq'])) {
+            if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $params['Sys_rq'])) {
+                // 按天查询(2025-03-27)
+                $where['Sys_rq'] = $params['Sys_rq'];
+            } elseif (preg_match('/^\d{4}-\d{2}$/', $params['Sys_rq'])) {
+                // 按月查询(2025-03),匹配该月的所有数据
+                $where['Sys_rq'] = ['like', $params['Sys_rq'] . '%'];
             }
         }
-        $param['sys_rq'] = date('Y-m-d H:i:s',time());
-        $param['UniqId'] = $lastId + 1;
-        $param['mod_rq'] = date('Y-m-d H:i:s',time());
-        $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
+        $res = \db('设备_质量汇总')
+            ->where($where)
+            ->limit(($params['page'] - 1) * $params['limit'], $params['limit'])
+            ->select();
+        $this->success('获取成功', ['data' => $res, 'total' => count($res)]);
+
     }
 
 
-    /**
-     * 机台编号列表
-     * @ApiMethod  (GET)
-     * @return void
-     */
-    public function MachineList()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
-        if (empty($list)){
-            $this->success('未找到机台编号');
-        }
-        $data = [];
-        foreach ($list as $key=>$value){
-            $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
-        }
-        $this->success('成功',$data);
-    }
 
-    /**
-     * 删除班组信息
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\exception\PDOException
-     */
-    public function teamDel()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $machine = \db('设备_班组资料')
-            ->where('UniqId',$param['UniqId'])
-            ->value('sczl_jtbh');
-        $teamId = \db('设备_产量采集')
-            ->where('设备编号',$machine)
-            ->order('UniqId desc')
-            ->value('班组ID');
-        if ($teamId === (int)$param['UniqId']){
-            $this->success('无法删除正在生产的班组资料,请先切换班组');
-        }
-         $res = \db('设备_班组资料')
-            ->where('UniqId',$param['UniqId'])
-            ->delete();
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
 
-    }
 
     /**
-     * 管理人员现场巡检记录->展示
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 查询获取问题分类
      */
-    public function FieldInspectionRecord()
-    {
-        if ($this->request->isGet() === false){
+    public function getProblemCategories() {
+        if (!$this->request->isGet()) {
             $this->error('请求错误');
         }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $date = date('Y-m-d H:i:s',time());
-        if (empty($param['start'])){
-            $startTime = date('Y-m-d 08:30:00',time());
-        }else{
-            $startTime = $param['start'];
-        }
 
-        if ($date<$startTime){
-            $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
-        }
-        $where = [
-            '工单编号' => $param['workOrder'],
-            '开工时间' => $startTime,
-            '类别' => '现场巡查记录',
-            '班组编号' => $param['team']
-        ];
-        $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
-        rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
-        rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
-        $list = \db('制程检验_记录')->where($where)
-            ->field($filed)
-            ->select();
-        if (empty($list)){
-            $this->success('',[]);
-        }
-        foreach ($list as $key=>$value){
-            $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
-            $list[$key]['归属时段'] = $value['开工时间'];
-            $list[$key]['分钟差数'] = $number;
-            if ($number != 0){
-                $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
-            }
+        $params = $this->request->param();
+        $where = ['mod_rq' => null]; // 仅查询未被删除的数据
+
+        // 允许通过问题类型进行搜索
+        if (!empty($params['search'])) {
+            $where['问题类型'] = ['like', '%' . $params['search'] . '%'];
         }
-        $this->success('成功',$list);
-    }
 
-    /**
-     * 管理人员现场巡检记录->添加
-     * @ApiMethod (POST)
-     * @param  void
-     * @return void
-     */
+        $data = \db('db_问题分类')->where($where)->order('update_time desc')->select();
 
-    public function FieldInspectionRecordAdd()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
+        if (!$data) {
+            $this->error('未查询到数据');
         }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        if ($param['processCode']<10){
-            $param['processCode'] = '0'.$param['processCode'];
-        }
-        $date = date('Y-m-d H:i:s',time());
-        $startTime = date('Y-m-d 08:30:00',time());
-        if ($date<$startTime){
-            $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
-        }
-        $data = [
-            '类别' => $param['category'],
-            '工单编号' => $param['workOrder'],
-            '印件号' => $param['printCode'],
-            '工序名称' => $param['processCode'].'-'.$param['process'],
-            '流程单号' => $param['flowCode'],
-            '设备编号' => $param['machine'],
-            '班组编号' => $param['team'],
-            '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
-            '相关标准' => '',
-            '量测仪器' => '',
-            '检验结果' => '',
-            '检验备注' => $param['remark'],
-            '提交时间' => date('Y-m-d H:i:s',time()),
-            '开工时间' => $startTime,
-            'sys_id' => '',
-            'sys_rq' => date('Y-m-d H:i:s',time()),
-            'mod_rq' => '0000-00-00 00:00:00',
-            'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
-        ];
-        $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
-    }
 
-    /**
-     * 设备点检->左侧菜单栏
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
-     */
-    public function SpotCheckItem()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $list = \db('设备_点检项目')
-            ->where('适用机型','LIKE','%;'.$param['machine'].';%')
-            ->distinct(true)
-            ->column('部件名称','部件编号');
-        if (empty($list)){
-            $this->success('');
-        }
-        $this->success('成功',$list);
+        $this->success('获取成功', ['data' => $data, 'total' => count($data)]);
     }
 
     /**
-     * 设备点检->检测项目
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 添加问题分类接口
      */
-    public function  InspectionItem()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $list = \db('设备_点检项目')
-            ->where('部件名称',$param['unitName'])
-            ->where('适用机型','like','%'.$param['machine'].'#%')
-            ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
-            ->select();
-        if (empty($list)){
-            $this->success('未找到检测项目');
+    public function addProblemCategory() {
+        if (!$this->request->isPost()) {
+            $this->error('非法请求');
         }
-        $this->success('成功',$list);
-    }
 
+        $params = $this->request->param();
 
-    /**
-     * 设备点检->检测记录添加
-     * @ApiMethod (POST)
-     * @param  void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public  function InspectionItemAdd()
-    {
-        if (Request::instance()->isPost()  === false){
-            $this->error('请求错误');
+        if (empty($params['问题类型'])) {
+            $this->error('问题类型不能为空');
         }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $lastNumber =  \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
-        if (empty($lastNumber)){
-            $lastId = 0;
-        }else{
-            $lastId = $lastNumber;
-        }
-        $row = [];
-        foreach ($param as $key=>$value){
-            $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
-            $row[$key] = [
-                '日期' => date('Y-m-d 00:00:00',time()),
-                '班组编号' => $value['team'],
-                '点检设备' => $value['machine'],
-                '部件编号' => $unitCode['部件编号'],
-                '部件名称' => $value['unitName'],
-                '检验项目' => $value['itemName'],
-                '判定标准' => $value['standard'],
-                '点检方法' => $value['method'],
-                '点检结果' => $value['status'],
-                '备注说明' => $value['remark'],
-                'Sys_id'  =>'',
-                'Sys_rq'  => date('Y-m-d H:i:s',time()),
-                'Mod_rq'  => date('Y-m-d H:i:s',time()),
-                'Uniqid'  => $lastId+$key+1
-            ];
 
-        }
-        $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
-    }
+        $insertData = [
+            '问题类型' => $params['问题类型'],
+            'sys_id' => $params['sys_id'],
+            'classification' => $params['classification'],
+            'Sys_rq' => date('Y-m-d H:i:s')
+        ];
 
-    /**
-     * 机台印版领用->左侧菜单
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
-     */
-    public function PrintGetTab()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $productCode = $param['productCode'];
-        $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
-                JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
-                WHERE a.YB_Cpdh = '{$productCode}'";
-        $res = Db::query($sql);
-        if (empty($res)){
-            $this->success('');
-        }
-        $this->success('成功',$res);
+        $sql = \db('db_问题分类')
+            ->fetchSql(true)
+            ->insert($insertData);
+        $res = \db()->query($sql);
+
+        $this->success('添加成功');
     }
 
     /**
-     * 机台印版领用记录->数据详情
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
+     * 删除问题分类接口
      */
-    public function PrintDetail()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求失败');
+    public function deleteProblemCategory() {
+        if (!$this->request->isPost()) {
+            $this->error('非法请求');
         }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
+
+        $params = $this->request->param();
+        if (empty($params['id'])) {
+            $this->error('ID 不能为空');
         }
-        $productCode = $param['productCode'];
-        $code = $param['code'].'%';
-        $workOrder = $param['workOrder'];
-        $sql = "SELECT 
-                RTRIM(a.`存货编码`) as `存货编码`,
-                RTRIM(c.`物料名称`) as `存货名称`,
-                RTRIM(b.`印版名称`) as `印版名称`,
-                RTRIM(b.`供方批号`) as `供方批号`,
-                RTRIM(b.`制造日期`) as `制造日期`,
-                SUM(d.`Yb_印数`) as `印数`,
-                RTRIM(e.`名称`) as `印版类别`,
-                SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
-                RTRIM(f.`Gd_客户名称`) as `客户名称`,
-                RTRIM(a.YB_Cpdh) as `产品编号`,
-                RTRIM(f.Gd_cpmc) as `产品名称`,
-                RTRIM(d.UniqID) as UniqId
-                FROM `产品_印版资料` as a 
-                LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
-                JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
-                LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
-                JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
-                JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
-                WHERE a.YB_Cpdh = '{$productCode}' 
-                AND a.`存货编码` LIKE '{$code}'
-                AND f.Gd_gdbh = '{$workOrder}'
-                AND b.`报废日期` = '1900-01-01 00:00:00'
-                GROUP BY b.`供方批号`
-                ORDER BY a.`存货编码`";
-        $list = Db::query($sql);
-        if (empty($list)){
-            $this->success('');
+        $updateData = [
+            'mod_rq' => date('Y-m-d H:i:s')
+        ];
+        $res = \db('db_问题分类')->where('id', $params['id'])->update($updateData);
+        if ($res) {
+            $this->success('删除成功');
+        } else {
+            $this->error('删除失败');
         }
-        $this->success('成功',$list);
     }
 
     /**
-     * 换型清场->左侧菜单栏
-     * @ApiMethod  (GET)
-     * @param  void
-     * @return void
+     * 机台设备查询
      */
-    public function remodelGetTab()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $date = date('Y-m-d 00:00:00',time()-3456000);
-        $nowTime = date('Y-m-d H:i:s',time());
-        $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
-        if (empty($list)){
-            $this->error('失败');
-        }
-        $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId 
-                FROM `设备_基本资料` as a 
-                LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
-                WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
-        $res = Db::query($sql);
-        $data = $result = [];
-        foreach ($list as $key=>$value){
-            $data[$value] = $result[$value]= $time = [];
-            foreach ($res as $k=>$v){
-                if ($value === $v['设备编号']){
-                    $row = [
-                        '日期' => $v['日期'],
-                        'id' => $v['UniqId']
-                    ];
-                    array_push($data[$value],$row);
-
-                }
-            }
-            foreach ($data[$value] as $m=>$n){
-                $time[$m] = $n['日期'];
-            }
-            $time = array_values(array_unique($time));
-            foreach ($time as $kk=>$vv){
-                $i=1;
-                foreach ($data[$value] as $kkk=>$vvv){
-                    if ($kkk>=$kk  && $vv === $vvv['日期']){
-                        array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
-                        $i++;
-                    }
-                }
-            }
-        }
-        $this->success('成功',$result);
+    public function getMachineDeviceTypes(){
+        $res = \db('设备_基本资料')
+            ->where('mod_rq', null)
+            ->select();
+        $this->success('成功', [
+            'list' => $res,
+        ]);
     }
 
     /**
-     * 换型清场->详情
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 更新机台设备
      */
-    public function RemodelDetail()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
-        rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
-        rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
-        rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
-        $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
-        if (empty($list)){
-            $this->success('未找到该条清场记录');
-        }
-        $list['日期'] = date('Y-m-d',strtotime($list['日期']));
-        $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find();
-        if (empty($printNameA)){
-            $list['印件名称A'] = '';
-        }else{
-            $list['印件名称A'] = $printNameA['yjmc'];
+    public function updateMachineDeviceTypes() {
+        if (!$this->request->isPost()) {
+            $this->error('非法请求');
         }
-        $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find();
-        if (empty($printNameB)){
-            $list['印件名称B'] = '';
-        }else{
-            $list['印件名称B'] = $printNameB['yjmc'];
+        $params = $this->request->param();
+        if (empty($params['UniqId'])) {
+            $this->error('UniqId 参数不能为空');
+        }
+        $deviceData = [
+//            'sys_sbID' => $params['sys_sbID'],
+//            '工序' => $params['工序'],
+//            '设备编号' => $params['设备编号'],
+//            '生产工序' => $params['生产工序'],
+//            '设备编组' => $params['设备编组'],
+//            '组长' => $params['组长'],
+            'status' => $params['status'],
+        ];
+        $result = \db('设备_基本资料')
+            ->where('UniqId', $params['UniqId'])
+            ->where('mod_rq', null)
+            ->update($deviceData);
+        if ($result) {
+            $this->success('设备更新成功');
+        } else {
+            $this->error('设备更新失败');
         }
-        $this->success('成功',$list);
     }
 
     /**
-     * 换型清场->当前设备清场记录
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 新增机台设备
      */
-    public function ModelChangeRecord()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
+    public function addMachineDeviceTypes() {
+        if (!$this->request->isPost()) {
+            $this->error('非法请求');
         }
-        $date = date('Y-m-d 00:00:00',time()-3888000);
-        $nowTime = date('Y-m-d H:i:s',time());
-        $where = [
-            '日期' =>['between',[$date,$nowTime]],
-            '机台编号' => $param['machine'],
-            '工单编号A' => ['<>',''],
-            '工单编号B' => ['<>',''],
+        $params = $this->request->param();
+
+        // 生产工序与工序号的映射
+        $processMapping = [
+            '裁剪' => 2,
+            '车缝' => 3,
+            '手工' => 4,
+            '总检' => 6,
+            '大烫' => 5,
+            '包装' => 7,
         ];
-        $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
-        rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
-        rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
-        rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
-        $list = \db('制程_换型清场')
-            ->where($where)
-            ->field($field)
-            ->select();
-        if (empty($list)){
-            $this->success('未找到换型记录');
-        }
-        foreach ($list as $key=>$value){
-            $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->value('rtrim(yj_yjmc) as yjmc');
-            if (empty($printNameA)){
-                $list[$key]['印件名称A'] = '';
-            }else{
-                $list[$key]['印件名称A'] = $printNameA;
-            }
-            $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->value('rtrim(yj_yjmc) as yjmc');
-            if (empty($printNameB)){
-                $list[$key]['印件名称B'] = '';
-            }else{
-                $list[$key]['印件名称B'] = $printNameB;
-            }
+        $productionProcess = $params['生产工序'] ?? '';
+
+        $UniqId = \db('设备_基本资料')
+            ->field('UniqId')
+            ->order('UniqId desc')
+            ->find();
+        // 新的设备数据
+        $deviceData = [
+            'UniqId' => $UniqId['UniqId'] + 1,
+            'sys_sbID' => $params['sys_sbID'],
+            '工序' => $processMapping[$productionProcess],
+            '设备编号' => $params['设备编号'],
+            '生产工序' => $params['生产工序'],
+            '设备编组' => $params['设备编组'],
+            '组长' => $params['组长'],
+            'sys_id' => $params['sys_id'],
+            'sys_rq' => date('Y-m-d H:i:s'),
+            'status' => 1,
+        ];
+        $result = \db('设备_基本资料')->fetchSql(true)
+            ->insert($deviceData);
+        $list_gd = \db()->query($result);
+        if ($result) {
+            $this->success('设备新增成功');
+        } else {
+            $this->error('设备新增失败');
         }
-        $this->success('成功',$list);
     }
 
     /**
-     * 车间机台状态列表展示
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
+     * 订单状态更新
      */
-    public function MachineDetailList()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
+
+    public function Apigdstatus() {
+        if (!$this->request->isPost()) {
+            $this->error('非法请求');
         }
-        $workshop = $param['workshop'];
-        $sql = "SELECT
-                    RTRIM( a.`设备编号` ) AS 设备编号,
-                    RTRIM( a.`设备名称` ) AS 设备名称,
-                    RTRIM( d.`当前状态` ) AS 状态
-                FROM
-                    `设备_基本资料` AS a
-                    JOIN (
-                    SELECT
-                        b.`设备编号`,
-                        b.`当前状态`,
-                        b.`开工时间` 
-                    FROM
-                        `设备_产量采集` AS b
-                        JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号` 
-                        AND b.`UniqId` = c.`UniqId`  
-                    ) AS d ON a.`设备编号` = d.`设备编号`
-                WHERE
-                    a.`使用部门` = '{$workshop}' 
-                GROUP BY
-                    a.`设备编号`
-                ORDER BY 
-                    a.UniqId";
-        $list = \db()->query($sql);
-        foreach ($list as $key=>$value){
-            if ($value['状态'] == ''){
-                $list[$key]['状态'] = '待单';
+        $params = $this->request->param();
+        $uniqids = explode(',', $params['Uniqid']);
+        // 判断gd_statu是否为“3-已完工”,只判断一次
+        $isFinished = $params['gd_statu'] == '3-已完工';
+        foreach ($uniqids as $uniqid) {
+            $uniqid = trim($uniqid);
+            $updateData = [
+                'gd_statu' => $params['gd_statu']
+            ];
+            // 如果是“已完工”,加上完工日期
+            if ($isFinished) {
+                $updateData['工单完工日期'] = date('Y-m-d H:i:s');
+            } else {
+                // 如果不是已完工,清空完工日期
+                $updateData['工单完工日期'] = null;
             }
+            $ReportSql = \db('工单_基本资料')->where('Uniqid', $uniqid)->fetchSql(true)->update($updateData);
+            \db()->query($ReportSql);
         }
-        $this->success('成功',$list);
+        $this->success('订单状态更新成功');
     }
-
     /**
-     * 机台当前参数展示
-     * @ApiMethod (GET)
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 产品BOM资料
      */
-    public function MachineDetail()
-    {
-        if ($this->request->isGet() === false){
+    public function Apibomlistarr(){
+        if ($this->request->isGet() === false) {
             $this->error('请求错误');
         }
         $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $data = [];
-        if ($param['start'] === ''){
-            if (date('Y-m-d H:i:s')>date('Y-m-d 08:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 20:30:00',time())){
-                $param['start'] = date('Y-m-d 08:30:00',time());
-            }elseif (date('Y-m-d H:i:s')>date('Y-m-d 20:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 23:59:59',time())){
-                $param['start'] = date('Y-m-d 20:30:00',time());
-            }else{
-                $param['start'] = date('Y-m-d 20:30:00',time()-86400);
-            }
-        }
-        $machineDetail = \db('设备_产量采集')
+        $page = isset($param['page']) ? (int)$param['page'] : 1;  // 默认第1页
+        $limit = isset($param['limit']) ? (int)$param['limit'] : 50; // 默认每页50条
+        $bomlist = Db::name('工单_bom资料')
             ->alias('a')
-            ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
-            ->join('工单_工艺资料 c','a.工单编号 = c.Gy0_gdbh AND a.设备编号 = c.Gy0_sbbh')
-            ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
-            ->field([
-                'rtrim(a.开工时间)' => '开工时间',
-                'rtrim(a.设备编号)' => '设备编号',
-                'rtrim(a.工单编号)' => '工单编号',
-                'rtrim(b.设备名称)' => '设备名称',
-                'rtrim(c.Gy0_gxh)' => '工序号',
-                'rtrim(c.Gy0_gxmc)' => '工序名称',
-                'rtrim(d.Gd_cpmc)' => '产品名称'
-            ])
-            ->where('a.设备编号', $param['machine'])
-            ->order('a.UniqId desc')
-            ->find();
-        $data['machine'] = [
-            '日期' => $machineDetail['开工时间'],
-            '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
-            '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
-            '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
-        ];
-        //机台状态时间
-        $startTime = \db('设备_产量采集')
-            ->where('设备编号',$param['machine'])
-            ->where('开工时间',$param['start'])
-            ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
-            ->group('当前状态')
-            ->select();
-        if (!empty($startTime)){
-            foreach ($startTime as $key=>$value){
-                $data['timeDifference'][$key] = [
-                    '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
-                    '状态' => $value['状态'] = null?'待单':$value['状态'],
-                ];
-                if ($value['状态'] === '生产'){
-                    $data['当班产量'] = $value['最大产量']-$value['当班产量'];
-                }
-            }
-        }else{
-            $data['timeDifference'][0] = [
-                '时间' => 0,
-                '状态' => '待单'
-            ];
-            $data['当班产量'] = 0;
-        }
-        //机台产能/时间明细
-        $row = \db('设备_产量采集')
-            ->where('设备编号',$param['machine'])
-            ->where('开工时间',$param['start'])
-            ->where('当班产量','<>',-1)
-            ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
-            ->select();
-        if (empty($row)){
-            $data['row'] = [];
-        }
-        foreach ($row  as $key=>$value){
-            $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
-            $data['row'][$key]['状态'] = $value['状态'];
-            if ($key<2){
-                $data['row'][$key]['产能'] = 0;
-            }else{
-                $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
-            }
-        }
-        //机台状态
-        $status = end($row);
-        if (empty($status['状态'])){
-            $data['status'] = '待单';
-        }else{
-            $data['status'] = $status['状态'];
-        }
-        //检验数据
-        $list = \db('制程检验_记录')
-            ->where('开工时间',$param['start'])
-            ->where('设备编号',$param['machine'])
-            ->where('sys_rq','>',$param['start'])
-            ->where('工单编号',$machineDetail['工单编号'])
-            ->field('rtrim(类别) as 类别,提交时间')
+            ->field('
+                a.BOM_工单编号 as 订单编号,
+                a.BOM_desc as 备注,
+                a.BOM_库存总量 as 库存总量,
+                a.BOM_面料结余 as 面料结余,
+                a.BOM_实际门幅 as 实际门幅,
+                a.BOM_物料编码 as 物料编码,
+                a.BOM_物料名称 as 物料名称,
+                a.BOM_投料单位 as 投料单位,
+                a.BOM_标准用量 as 定额用料,
+                a.BOM_计划用量 as 计划用料,
+                a.BOM_实际用量 as 标准用料,
+                a.Bom_领用数量 as 领用数量,
+                a.BOM_退还数量 as 退还数量,
+                a.BOM_退还数量 as 退还数量,
+                a.Sys_ID,
+                a.Sys_rq,
+                a.UNIQID,
+                a.物料分类 as 物料分类,
+                a.BOM_计划门幅 as 计划门幅,
+                a.BOM_定额门幅 as 定额门幅,
+                b.生产款号,
+                b.客户编号,
+                b.款式
+            ')
+            ->join('工单_基本资料 b', 'a.BOM_工单编号 = b.订单编号', 'left')  // 多条件关联
+            ->where('a.BOM_工单编号|a.BOM_物料编码|a.BOM_物料名称|a.物料分类|b.生产款号|b.款式|b.客户编号', 'like', "{$param['search']}%")
+            ->order('a.BOM_工单编号 desc')
+            ->where('a.Mod_rq',null)
+            ->limit(($page - 1) * $limit, $limit)
             ->select();
-        $data['首件'] = $data['自检'] = $data['IPQC'] = [];
-        if (!empty($list)){
-            foreach ($list as $key=>$value){
-                if ($value['类别'] == '首件与过程确认'){
-                    array_push($data['首件'],$value['提交时间']);
-                }
-                if ($value['类别'] == '机台检验'){
-                    array_push($data['自检'],$value['提交时间']);
-                }
-                if ($value['类别'] == 'IPQC检验'){
-                    array_push($data['IPQC'],$value['提交时间']);
-                }
-            }
-            $data['首件'] = array_values(array_unique($data['首件']));
-            $data['自检'] = array_values(array_unique($data['自检']));
-            $data['IPQC'] = array_values(array_unique($data['IPQC']));
-        }else{
-            $data['首件'] = [];
-            $data['自检'] = [];
-            $data['IPQC'] = [];
+
+        // 处理数据,去掉计划用料字段的小数点后多余的0
+        foreach ($bomlist as &$item) {
+            // 转换为浮点数,去掉无意义的 0
+            $item['计划用料'] = floatval($item['计划用料']);
         }
+        // 解除引用,防止意外修改
+        unset($item);
+
+        //统计总数量
+        $count = Db::name('工单_bom资料')
+            ->where('Mod_rq',null)
+            ->count();
+        $data['total'] = $count;
+        $data['list'] = $bomlist;
         $this->success('成功',$data);
     }
 
-    /**
-     * 制程检验记录->检验项目
-     * @ApiMethod (GET)
-     * @param void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function ProcessInspectionRecordsItem()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $list = \db('制程检验_项目')
-            ->where('工序','like','%'.$param['process'].'%')
-            ->select();
-        if (empty($list)){
-            $this->success('未找到检测项目');
-        }
-        $data = [];
-        foreach ($list as $key=>$value){
-            $data['首件']['指标检验'][$key] = [
-                '检验项目' => rtrim($value['检测项目']),
-                '检测方法' => rtrim($value['检测方法']),
-                '检验频率' => rtrim($value['首件签样要求']),
-                '相关标准' => rtrim($value['技术要求'])
-            ];
-            $data['机台检验']['指标检验'][$key] = [
-                '检验项目' => rtrim($value['检测项目']),
-                '检测方法' => rtrim($value['检测方法']),
-                '检验频率' => rtrim($value['机台自检频率']),
-                '相关标准' => rtrim($value['技术要求'])
-            ];
-            $data['IPQC']['指标检验'][$key] = [
-                '检验项目' => rtrim($value['检测项目']),
-                '检测方法' => rtrim($value['检测方法']),
-                '检验频率' => rtrim($value['IPQC检验频率']),
-                '相关标准' => rtrim($value['技术要求'])
-            ];
-        }
-        $row = \db('制程检验_项目附加')
-            ->where('工序','like','%'.$param['process'].'%')
-            ->select();
-        foreach ($row as $key=>$value){
-            $data['首件']['附加'][$key] = [
-                '缺陷备注' => rtrim($value['缺陷备注']),
-                '编号' => rtrim($value['编号'])
-            ];
-            $data['机台检验']['附加'][$key] = [
-                '缺陷备注' => rtrim($value['缺陷备注']),
-                '编号' => rtrim($value['编号'])
-            ];
-            $data['IPQC']['附加'][$key] = [
-                '缺陷备注' => rtrim($value['缺陷备注']),
-                '编号' => rtrim($value['编号'])
-            ];
-        }
-        $this->success('成功',$data);
-    }
-
-    /**
-     * 制程检验记录->检测记录添加
-     * @ApiMethod (POST)
-     * @param void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function ProcessInspectionRecordsItemAdd()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
-        if (empty($startID)){
-            $startID = 0;
-        }
-        $process = \db('工单_工艺资料')
-            ->where('Gy0_gdbh',$param[0]['workOrder'])
-            ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
-            ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
-            ->find();
-        $startTime = \db('设备_产量采集')
-            ->where('设备编号','like','%'.$param[0]['machine'].'#%')
-            ->where('工单编号',$param[0]['workOrder'])
-            ->order('UniqId desc')
-            ->find();
-        if ((int)$process['gxh']<10){
-            $process['gxh'] = '0'.$process['gxh'];
-        }
-        if ($process['add_gxmc'] !== ''){
-            $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
-        }else{
-            $printName = $process['gxh'].'-'.$process['gxmc'];
-        }
-        if (empty($process)){
-            $this->success('数据错误');
-        }
-        $data = [];
-        foreach ($param as $key=>$value){
-            $data[$key] = [
-                '类别' => $value['category'],
-                '工单编号' => $value['workOrder'],
-                '印件号' => $value['yjno'],
-                '工序名称' => $printName,
-                '流程单号' => $value['flow'],
-                '设备编号' => $value['machine'].'#',
-                '班组编号' => $startTime['班组编号'],
-                '检验项目' => $value['item'],
-                '相关标准' => $value['standard'],
-                '量测仪器' => $value['instrument'],
-                '检验结果' => $value['result'],
-                '检验备注' => $value['remark'],
-                '提交时间' => date('Y-m-d H:i:s',time()),
-                '开工时间' => rtrim($startTime['开工时间']),
-                'sys_id' => '',
-                'sys_rq' => date('Y-m-d H:i:s',time()),
-                'mod_rq' => '0000-00-00 00:00:00',
-                'UniqId' => $startID + $key +1
-            ];
-        }
-        $res = \db('制程检验_记录')->insertAll($data);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
-    }
-
-    /**
-     * 制程检验记录->附加检验记录添加
-     * @ApiMethod (POST)
-     * @param  void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function AdditionalInspectionRecordAdd()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
-        if (empty($startID)){
-            $startID = 0;
-        }
-        $process = \db('工单_工艺资料')
-            ->where('Gy0_gdbh',$param[0]['workOrder'])
-            ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
-            ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
-            ->find();
-        $startTime = \db('设备_产量采集')
-            ->where('设备编号','like','%'.$param[0]['machine'].'#%')
-            ->where('工单编号',$param[0]['workOrder'])
-            ->order('UniqId desc')
-            ->find();
-        if ((int)$process['gxh']<10){
-            $process['gxh'] = '0'.$process['gxh'];
-        }
-        if ($process['add_gxmc'] !== ''){
-            $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
-        }else{
-            $printName = $process['gxh'].'-'.$process['gxmc'];
-        }
-        if (empty($process)){
-            $this->success('数据错误');
-        }
-        $data = [];
-        foreach ($param as $key=>$value){
-            $data[$key] = [
-                '工单编号' => $value['workOrder'],
-                '印件号' => $value['yjno'],
-                '工序名称' => $printName,
-                '流程单号' => $value['flow'],
-                '设备编号' => $value['machine'],
-                '班组编号' => $startTime['班组编号'],
-                '缺陷备注' => $value['remark'],
-                '提交时间' => date('Y-m-d H:i:s',time()),
-                '开工时间' => rtrim($startTime['开工时间']),
-                'sys_id' => '',
-                'sys_rq' => date('Y-m-d H:i:s',time()),
-                'mod_rq' => '0000-00-00 00:00:00',
-                'UniqId' => $startID + $key +1
-            ];
-        }
-        $res = \db('制程检验_记录附加')->insertAll($data);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
-    }
-
-    /**
-     * 客诉记录
-     * @ApiMethod (GET)
-     * @param  void
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-     public function ComplaintRecord()
-     {
-         if ($this->request->isGet() === false){
-             $this->error('请求错误');
-         }
-         $param = $this->request->param();
-         if (isset($param['productCode'])){
-             $where['产品编号'] = $param['productCode'];
-         }
-         $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
-         rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
-         rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
-         rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
-         $list = \db('db_客诉记录')
-             ->where($where)
-             ->field($filed)
-             ->select();
-         if (empty($list)){
-             $this->success('未找到该产品客诉记录');
-         }
-         $this->success('成功',$list);
-     }
-
-    /**
-     * 设置机台班组信息
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-
-    public function setMachineTeam()
-    {
-        if (Request::instance()->isPost() == false) {
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (!isset($params['machine']) || empty($params['machine'] )) {
-            $this->error('参数不能为空');
-        }
-        if (!isset($params['order']) || empty($params['order'])){
-            $this->error('工单编号不能为空');
-        }
-        if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
-            $this->error('请先选择班组成员');
-        }
-        $machine = $params['machine'] . '#';
-        $data = [];
-        $lastData = \db('设备_产量采集')
-            ->order('UniqId desc')
-            ->find();
-        $id = $lastData['UniqId']+1;
-        $data['当前状态'] = $params['status'];
-        $data['时间'] = date('Y-m-d H:i:s');
-        $data['设备编号'] = $machine;
-        $data['工单编号'] = empty($params['order']) ? '':$params['order'];
-        $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
-        $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
-        $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
-        $data['当班产量'] = $params['production_now'];
-        $data['累计产量'] = $params['production_all'];
-        $data['班组编号'] = $params['sczl_bzdh'];
-        $data['班组ID'] = $params['team_id'];
-        // 获取当前时间
-        $current_time = time();
-        // 设置时间范围
-        $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
-        $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
-        $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
-        $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
-        // 判断当前时间属于哪个时间范围
-        if ($current_time >= $start_time1 && $current_time <= $end_time1) {
-            $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
-        } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
-            $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
-
-        } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
-            $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
-        }
-        if (!empty($params['order']) && !empty($params['yjno'])){
-            $option['Gy0_gdbh'] = $params['order'];
-            $option['Gy0_yjno'] = $params['yjno'];
-            $option['Gy0_gxh'] = $data['工序号'];
-            $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
-        }else{
-            $data['任务ID'] = '';
-        }
-        $data['UniqId'] = $id;
-        $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
-        $res = Db::query($sql);
-        if ($res === false) {
-            $this->error('设置失败');
-        } else {
-            $this->success('设置成功');
-        }
-    }
-
-    /**
-     * 首页数据
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function index()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $nowTime = date('Y-m-d H:i:s',time());
-        $oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
-        $where =[
-            'Mod_rq' => ['between',[$oldTime,$nowTime]],
-            '行号' => '1'
-        ];
-        $data = [];
-        //按状态查询工单信息
-        $orderList = \db('工单_基本资料')
-            ->where($where)
-            ->field('count(Gd_gdbh) as 数量,rtrim(gd_statu) as 状态')
-            ->group('gd_statu')
-            ->select();
-        foreach ($orderList as $value){
-            if ($value['状态'] === '1-已完工'){
-                $data['workOrderData']['已完工'] = $value['数量'];
-            }
-            if ($value['状态'] === '3-计划中'){
-                $data['workOrderData']['计划中'] = $value['数量'];
-            }
-        }
-        $data['workOrderData']['排程中'] = db('工单_基本资料')->alias('a')
-            ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
-            ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
-            ->where([
-                'a.gd_statu' => '2-生产中',
-                'a.行号' => '1',
-                'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
-                'b.PD_WG' => '1900-01-01 00:00:00',
-                'b.Gy0_sj1' => '1900-01-01 00:00:00',
-                'c.状态' => '',
-            ])
-            ->group('a.Gd_gdbh')
-            ->count();
-        $data['workOrderData']['制程中'] = db('工单_基本资料')->alias('a')
-            ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
-            ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
-            ->where([
-                'a.gd_statu' => '2-生产中',
-                'a.行号' => '1',
-                'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
-                'b.PD_WG' => '1900-01-01 00:00:00',
-                'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
-                'c.状态' => '',
-            ])
-            ->group('a.Gd_gdbh')
-            ->count();
-        //按月份查询工单信息
-        $data['monthData'] = \db('工单_基本资料')
-            ->where('Mod_rq', 'between', [$oldTime, $nowTime])
-            ->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
-            ->group('month')
-            ->order('month')
-            ->select();
-        //查询最近十条客诉信息
-        $data['customer'] = \db('db_客诉记录')
-            ->field('rtrim(客诉描述) as 客诉描述,DATE_FORMAT(客诉日期, "%Y-%m-%d") as 日期,rtrim(UniqID) as UniqId')
-            ->limit(10)
-            ->order('Sys_rq desc')
-            ->select();
-        $this->success('成功',$data);
-    }
-
-    /**
-     * 员工信息获取
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function EmployeeData()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (isset($param['code']) === false){
-            $this->error('参数错误');
-        }
-        $res = \db('人事_基本资料')
-            ->where('员工编号','like',$param['code'].'%')
-            ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
-            ->select();
-        if (empty($res)){
-            $this->success('未找到该员工');
-        }
-        $this->success('成功',$res);
-    }
-
-    /**
-     * 换型清场添加
-     * @return void
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function remodelDataAdd()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
-        $param['sys_id'] = '['.$param['机台编号'].']';
-        $param['sys_rq'] = date('Y-m-d H:i:s',time());
-        $param['mod_rq'] = date('Y-m-d H:i:s',time());
-        $param['UniqId'] = $lastId + 1;
-        $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
-    }
-
-    /**
-     * 换型清场记录修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function remodelDataEdit()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $param['mod_rq'] = date('Y-m-d H:i:s',time());
-        $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
-    }
-
-    /**
-     * 换型清场记录删除
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\exception\PDOException
-     */
-    public function remodelDataDel()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
-        if ($res !== false){
-            $this->success('删除成功');
-        }else{
-            $this->error('删除失败');
-        }
-    }
-
-    /**
-     * 印版领用记录添加
-     * @return void
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function PrintDetailAdd()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
-        foreach ($param as $key=>$value){
-            $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
-            $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
-            $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
-            $param[$key]['UniqID'] = $lastId + $key +1;
-        }
-        $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('添加成功');
-        }else{
-            $this->error('添加失败');
-        }
-    }
-
-    /**
-     * 印版领用记录退还
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function PrintDetailEdit()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-        $idList = explode(',',$param['id']);
-        $i = 0;
-        foreach ($idList as $key=>$value){
-            $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
-            $data['Mod_rq'] = date('Y-m-d H:i:s',time());
-            $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
-            $res = \db()->query($sql);
-            if ($res === false){
-                $i++;
-            }
-        }
-        if ($i !== 0){
-            $this->error('退还失败');
-        }else{
-            $this->success('退还成功');
-        }
-    }
-
-    /**
-     * 当班产量明细修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function chanliangEdit()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param['UniqId'])){
-            $this->error('参数错误');
-        }
-        $param['sczl_打样工时'] = $param['sczl_打样总工时'];
-        $param['sczl_装版工时'] = $param['sczl_装版总工时'];
-        $param['mod_rq'] = date('Y-m-d H:i:s',time());
-        $data = $param;
-        unset($data['UniqId']);
-        $sql = \db('设备_产量计酬')
-            ->where('UniqId',$param['UniqId'])
-            ->fetchSql(true)
-            ->update($data);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('修改成功');
-        }else {
-            $this->error('修改失败');
-        }
-    }
-
-    /**
-     * 获取当日上报产量详细数据
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function MachineChanliangDetail()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param['UniqId'])){
-            $this->error('参数错误');
-        }
-        $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,rtrim(sczl_ls) as 联数,
-        rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
-        rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
-        rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
-        rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,rtrim(sczl_装版工时) as 装版补产工时,rtrim(sczl_打样工时) as 打样补产工时,
-        sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
-        sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId';
-        $list = \db('设备_产量计酬')->where('UniqId',$param['UniqId'])->field($field)->find();
-        if (empty($list)){
-            $this->success('未找到产量详情信息');
-        }
-        $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$list['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
-        $list['印件名称'] = $productName['cpmc'];
-        if (!empty($productName['成品名称'])){
-            $list['cpmc'] = $productName['成品名称'];
-        }elseif (empty($productName['成品名称']) && !empty($productName['cpmc'])){
-            $list['cpmc'] = $productName['cpmc'];
-        }else{
-            $list['cpmc'] = '';
-        }
-        for ($i=1;$i<11;$i++){
-            if (isset($list['sczl_bh'.$i])){
-                $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
-                if (isset($name['name'])){
-                    $list['组员'.$i] = [
-                        '编号' => $list['sczl_bh'.$i],
-                        '姓名' => $name['name'],
-                        '比例' => ((float)$list['sczl_rate'.$i]*100).'%'
-                    ];
-                }
-            }
-            if (empty($list['sczl_bh'.$i])){
-                $list['组员'.$i] = [
-                    '编号' => '',
-                    '姓名' => '',
-                    '比例' => ''
-                ];
-            }
-
-            unset($list['sczl_bh'.$i],$list['sczl_rate'.$i]);
-        }
-        $list['拉料'] = [
-            '编号' => $list['sczl_bh98'],
-            '姓名' => \db('人事_基本资料')->where('员工编号',$list['sczl_bh98'])->value('rtrim(员工姓名)')
-        ];
-        unset($list['sczl_bh98']);
-        $this->success('成功',$list);
-    }
-
-    /**
-     * 当日上报产量详细数据修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function MachineChanliangDetailEdit()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param['UniqId'])){
-            $this->error('参数错误');
-        }
-        $param['sczl_type'] = $param['sczl_gxmc'];
-        $param['mod_rq'] = date('Y-m-d H:i:s',time());
-        $UnidId = $param['UniqId'];
-        unset($param['UniqId']);
-        $sql = \db('设备_产量计酬')->where('UniqId',$UnidId)->fetchSql(true)->update($param);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('修改成功');
-        }else{
-            $this->error('修改失败');
-        }
-    }
-
-    /**
-     * 产量上报数据删除
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\exception\PDOException
-     */
-    public function ChanliangDel()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param['UniqId'])){
-            $this->error('参数错误');
-        }
-        $idList = explode(',',$param['UniqId']);
-        foreach ($idList as $key=>$value){
-            $res = \db('设备_产量计酬')
-                ->where('UniqId',$value)
-                ->delete();
-        }
-        if ($res !== false){
-            $this->success('删除成功');
-        }else{
-            $this->error('删除失败');
-        }
-    }
-
-    /**
-     * 日产量上报添加
-     * @return void
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function ChanliangAdd()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['sczl_gdbh'])){
-            $this->error('参数错误');
-        }
-        $lastId = \db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
-        $params['sczl_type'] = $params['sczl_gxmc'];
-        $params['sczl_wgsj'] = '1900-01-01 00:00:00';
-        $params['sczl_废品率系数'] = 0;
-        $params['sys_rq'] = date('Y-m-d H:i:s',time());
-        $params['mod_rq'] = date('Y-m-d H:i:s',time());
-        $params['UniqId'] = $lastId + 1;
-        $sql = \db('设备_产量计酬')->fetchSql(true)->insert($params);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
-    }
-
-    /**
-     * 日产量上报添加获取工单信息
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function ChanliangWorkorder()
-    {
-        if ($this->request->isGet() === false)
-        {
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-//        $where = [
-//            'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
-//        ];
-//        if (!empty($param['machine'])){
-//            $where = [
-//                'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
-//            ];
-//        }
-        if (!empty($param['search'])){
-            $where['b.Gy0_gdbh'] = ['like','%'.$param['search'].'%'];
-        }
-        $list = \db('工单_基本资料')
-            ->alias('a')
-            ->field('rtrim(Gd_gdbh) as gdbh,rtrim(成品名称) as cpmc')
-            ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
-            ->where($where)
-            ->select();
-        if (empty($list)){
-            $this->success('未找到相关工单');
-        }else{
-            $this->success('成功',$list);
-        }
-    }
-
-    /**
-     * 日产量上报工单印件资料
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function ChanliangPrintDetail()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param['gdbh'])){
-            $this->error('参数错误');
-        }
-        $where = [
-            'Yj_Gdbh' => $param['gdbh']
-        ];
-        $list = \db('工单_印件资料')
-            ->where($where)
-            ->field('rtrim(yj_Yjno) as yjno,rtrim(yj_yjmc) as yjmc,rtrim(yj_ls) as ls')
-            ->select();
-        if (empty($list)){
-            $this->success('未找到印件资料');
-        }else{
-            $this->success('成功',$list);
-        }
-    }
-
-    /**
-     * 日产量上报工艺资料获取
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function ChanliangProcessDetail()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param['gdbh'])){
-            $this->error('参数错误');
-        }
-//        $sys_bh = \db('dic_lzde')->where('适用机型',$param['machine'])->value('sys_bh');
-        $list = \db('工单_工艺资料')
-            ->where('Gy0_gdbh',$param['gdbh'])
-            ->where('Gy0_yjno',$param['yjno'])
-//            ->where('Gy0_sbbh','like','%'.$param['machine'].'%')
-            ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
-            ->select();
-        if (empty($list)){
-            $this->success('未获取工序');
-        }
-//        $time = \db('设备_产量计酬')
-//            ->where('sczl_gdbh',$param['gdbh'])
-//            ->where('sczl_yjno',$param['yjno'])
-//            ->where('sczl_jtbh','like','%'.$param['machine'].'%')
-//            ->order('UniqId desc')
-//            ->value('sczl_sj2');
-//        $newTime = date('Y-m-d H:i:s');
-//        if ($newTime > date('Y-m-d 08:30:00') && $newTime < date('Y-m-d 20:30:00') && $time < date('Y-m-d 08:30:00')){
-//            $time = date('Y-m-d 08:30:00');
-//        }elseif ($newTime > date('Y-m-d 20:30:00') && $time < date('Y-m-d 20:30:00')){
-//            $time = date('Y-m-d 20:30:00');
-//        }
-        foreach ($list as $key=>$value){
-            if ((int)$value['gxh'] < 10){
-                $value['gxh'] = '0'.$value['gxh'];
-            }
-            if (empty($value['add_gxmc'])){
-                $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'];
-            }else{
-                $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
-            }
-            unset( $list[$key]['add_gxmc']);
-//            $list[$key]['time'] = $time;
-        }
-//        $list['sys_bh'] = $sys_bh;
-        $this->success('成功',$list);
-    }
-
-    /**
-     * 工价系数修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function CoefficientEdit()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['id'])){
-            $this->error('参数错误');
-        }
-        $idList = explode(',',$params['id']);
-        $i=0;
-        foreach ($idList as $key=>$value){
-            $sql = \db('设备_产量计酬')
-                ->where('UniqId',$value)
-                ->fetchSql(true)
-                ->update(['sczl_工价系数'=>$params['工价系数']]);
-            $res = \db()->query($sql);
-            if ($res === false){
-                $i++;
-            }
-        }
-        if ($i!==0){
-            $this->error('修改失败');
-        }else{
-            $this->success('修改成功');
-        }
-    }
-
-    /**
-     * 色度系数修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function ChromaDataEdit()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['id'])){
-            $this->error('参数错误');
-        }
-        $idList = explode(',',$params['id']);
-        $i=0;
-        foreach ($idList as $key=>$value){
-            $sql = \db('设备_产量计酬')
-                ->where('UniqId',$value)
-                ->fetchSql(true)
-                ->update(['sczl_ms'=>$params['ms']]);
-            $res = \db()->query($sql);
-            if ($res === false){
-                $i++;
-            }
-        }
-        if ($i!==0){
-            $this->error('修改失败');
-        }else{
-            $this->success('修改成功');
-        }
-    }
-
-    /**
-     * 凹印版距修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function PrintingModeDataEdit()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['id'])){
-            $this->error('参数错误');
-        }
-        $idList = explode(',',$params['id']);
-        //获取工单印件工序
-        $orderList = \db('设备_产量计酬')
-            ->where('UniqId',$idList[0])
-            ->field('rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as 印件号,rtrim(sczl_gxh) as 工序号')
-            ->find();
-        //修改工艺资料
-        $sql = \db('工单_工艺资料')
-            ->where([
-                'Gy0_gdbh'=>$orderList['工单编号'],
-                'Gy0_yjno'=>$orderList['印件号'],
-                'Gy0_gxh'=>$orderList['工序号']
-            ])
-            ->fetchSql(true)
-            ->update(['版距'=>$params['plate'],'印刷方式'=>$params['mode']]);
-        $res = \db()->query($sql);
-        if ($res === false){
-            $this->error('修改失败');
-        }else{
-            $this->success('修改成功');
-        }
-    }
-
-    /**
-     * 废品率系数批量修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function RejectionEdit()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['id'])){
-            $this->error('参数错误');
-        }
-        $idList = explode(',',$params['id']);
-        $i=0;
-        foreach ($idList as $key=>$value){
-            $sql = \db('设备_产量计酬')
-                ->where('UniqId',$value)
-                ->fetchSql(true)
-                ->update(['sczl_废品率系数'=>$params['rejection']]);
-            $res = \db()->query($sql);
-            if ($res === false){
-                $i++;
-            }
-        }
-        if ($i!==0){
-            $this->error('修改失败');
-        }else{
-            $this->success('修改成功');
-        }
-    }
-
-    /**
-     * 日产量上报班组信息批量修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     * @throws \think\exception\PDOException
-     */
-    public function YieldTeamEdit()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (empty($param['Uniqid']) || empty($param['teamID'])){
-            $this->error('参数错误');
-        }
-        $idList = explode(',',$param['Uniqid']);
-        $teamList = \db('设备_班组资料')->where('UniqId',$param['teamID'])->find();
-        $data = [];
-        for ($i=1;$i<11;$i++){
-            $data['sczl_bh'.$i] = $teamList['sczl_bh'.$i];
-            $data['sczl_rate'.$i] = $teamList['sczl_rate'.$i];
-            $data['sczl_bzdh'] = $teamList['sczl_bzdh'];
-        }
-        $j = 0;
-        foreach ($idList as $key => $value){
-            $sql = \db('设备_产量计酬')
-                ->where('UniqId',$value)
-                ->fetchSql(true)
-                ->update($data);
-            $res = \db()->query($sql);
-            if ($res === false){
-                $j++;
-            }
-        }
-        if ($j === 0){
-            $this->success('修改成功');
-        }else{
-            $this->error('修改失败');
-        }
-    }
-
-    /**
-     * 检品机日产量上报数据修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
-     */
-    public function JpChanliangEdit()
-    {
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['UniqId'])){
-            $this->error('参数错误');
-        }
-        $params['mod_rq'] = date('Y-m-d H:i:s');
-        $data = $params;
-        $data['sczl_装版总工时'] = $params['sczl_装版工时'];
-        unset($data['UniqId']);
-        $sql = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
-        $res = \db()->query($sql);
-        if ($res === false){
-            $this->error('修改失败');
-        }else{
-            $this->success('成功');
-        }
-    }
-
-    /**
-     * 检品机日产量上报数据列表
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function JPmachineDetail()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $machine = input('machine');
-        $date = input('date');
-        $where = [
-            'sczl_jtbh' => $machine,
-            'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
-        ];
-        $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_type) as 检验类型,rtrim(sczl_num) as num,rtrim(sczl_cl) as 计件箱数,
-        rtrim(sczl_Pgcl) as 每箱数量,rtrim(sczl_bzdh) as bzdh,IF(sczl_废品率系数 = 0, "",sczl_废品率系数) as 废品率系数,IF(sczl_装版工时 = 0, "",sczl_装版工时) as 换膜补时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
-        rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
-        sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
-        sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号,sczl_rq,sczl_装版总工时 as 换膜总工时';
-        //机台信息
-        $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
-        //组员信息
-        $list = \db('设备_产量计酬')->where($where)->field($field)->select();
-        $totalA = \db('设备_产量计酬')
-            ->where($where)
-            ->where('sczl_bzdh','like','A%')
-            ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数')
-            ->group('检验类型')
-            ->select();
-        $totalB = \db('设备_产量计酬')
-            ->where($where)
-            ->where('sczl_bzdh','like','B%')
-            ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数')
-            ->group('检验类型')
-            ->select();
-        if (empty($list)){
-            $this->success('',[]);
-        }
-        foreach ($list as $key=>$value){
-            //产品名称
-            $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
-            if (!empty($productName)){
-                if (!empty($productName['成品名称'])){
-                    $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
-                    $list[$key]['cpmc'] = $productName['成品名称'];
-                }else{
-                    $list[$key]['产品名称'] = $value['工单编号'];
-                    $list[$key]['cpmc'] = '';
-                }
-            }else{
-                $list[$key]['产品名称'] = $value['工单编号'];
-                $list[$key]['cpmc'] = '';
-            }
-            if (empty($value['定额代号'])){
-                $list[$key]['千件工价'] = '';
-                $list[$key]['日定额'] = '';
-                $list[$key]['补产标准'] = '';
-            }else{
-                $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
-                $list[$key]['千件工价'] = $row['千件工价'];
-                $list[$key]['日定额'] = $row['日定额'];
-                $list[$key]['补产标准'] = $row['补产标准'];
-            }
-            $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
-            for ($i=1;$i<11;$i++){
-                if (isset($value['sczl_bh'.$i])){
-                    $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('员工姓名 as name')->find();
-                    if (isset($name['name'])){
-                        $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
-                        $list[$key]['sczl_name'.$i] = $name['name'];
-                    }else{
-                        $list[$key]['sczl_name'.$i] = '';
-                    }
-                }
-            }
-        }
-        $list['totalA'] = $totalA;
-        $list['totalB'] = $totalB;
-        $this->success('成功',$list);
-    }
 }

+ 8 - 12
application/api/controller/Manufacture.php

@@ -904,9 +904,6 @@ class Manufacture extends Api
 
     /**
      * 子订单领料派单
-     * @return void
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\exception\PDOException
      */
     public function processAdd()
     {
@@ -1677,17 +1674,14 @@ class Manufacture extends Api
         /**
      * 车缝派单列表
      */
-    public function CfdataList()
-    {
+    public function CfdataList(){
         if ($this->request->isGet() === false) {
             $this->error('请求错误');
         }
-
         $param = $this->request->param();
         if (empty($param['machine']) || empty($param['date'])) {
             $this->error('参数错误');
         }
-
         // 将传入的 YYYYMM 格式日期转换为 YYYY-MM-01
         $year = substr($param['date'], 0, 4);
         $month = substr($param['date'], 4, 2);
@@ -1702,14 +1696,16 @@ class Manufacture extends Api
             ->where('c.sczl_rq', '>=', $startDate)
             ->where('c.sczl_rq', '<=', $endDate)
             ->field('
-            c.订单编号, c.款号 as 生产款号, j.款式, j.客户编号, j.订单数量,
-            LEFT(j.落货日期, 10) as 落货日期,j.工单入仓数量 as 工单完工数量,j.订单数量,
-            c.sczl_rq as 创建时间, j.gd_statu as 工单状态
+            c.订单编号, c.款号 as 生产款号, j.款式, j.客户编号,
+            CASE 
+                WHEN c.工序名称 IN ("裁剪", "车缝") THEN sum(c.数量)
+                ELSE sum(c.s_num )
+            END as 完工数量,
+            LEFT(j.落货日期, 10) as 落货日期,j.订单数量 as 制单数,
+            LEFT(c.sczl_rq, 10) as 创建时间, j.gd_statu as 工单状态
         ')
             ->group('c.订单编号')
             ->select();
-
-        // 返回数组结果
         $this->success('请求成功', ['table' => $list, 'length' => count($list)]);
     }
 

+ 292 - 80
application/api/controller/WorkOrder.php

@@ -11,6 +11,7 @@ use think\Db;
 use think\Exception;
 use think\Request;
 use PhpOffice\PhpSpreadsheet\IOFactory;
+use function EasyWeChat\Kernel\Support\rsa_public_encrypt;
 use function fast\e;
 
 
@@ -529,7 +530,7 @@ class WorkOrder extends Api
                     'BOM_物料编码' => $param['款号'].'-'.$param['颜色备注'].($key+1),
                     'BOM_物料名称' => $value['BOM_物料名称'],
                     'U8UID' => $value['UNIQID'],
-                    'BOM_投料单位' => '',
+                    'BOM_投料单位' => '',
                     'Sys_ID' => $param['Sys_id'],
                     'Sys_rq' => date('Y-m-d H:i:s',time()),
                     'BOM_desc' => $value['BOM_desc']
@@ -831,8 +832,12 @@ class WorkOrder extends Api
             ->group('关联编号')  // 按关联编号分组,获取每个订单的最新记录
             ->find();
 
-        // 假设获取到的 version 字段是类似 v1.1, v1.2, v1.9 这样的格式
-        $currentVersion = $latestItems['version'];  // 当前记录的 version
+        // 如果查询为空,设置默认的版本号为 'v1.0'
+        if (!$latestItems) {
+            $currentVersion = 'v1.0';
+        } else {
+            $currentVersion = $latestItems['version'];  // 当前记录的 version
+        }
 
         // 解析当前版本号
         if (preg_match('/v(\d+)\.(\d+)/', $currentVersion, $matches)) {
@@ -1596,6 +1601,7 @@ class WorkOrder extends Api
             a.BOM_计划门幅 as 计划门幅, a.BOM_定额门幅 as 定额门幅,a.Sys_ID as ID,a.Sys_rq as 日期')
             ->where($where)
             ->whereNull('a.Mod_rq')
+            ->order('a.UNIQID desc')
             ->select();
 
         if (!empty($list)) {
@@ -1625,15 +1631,15 @@ class WorkOrder extends Api
             $this->success('成功', $list);
         } else {
             $this->GdGtpAiOrder($param['order']);
-            return $this->success('没有找到相关数据', []);
+            $this->success('没有找到相关数据',[]);
+//            return $this->success('没有找到相关数据', []);
         }
     }
 
     /**
      * Bom资料删除
      * */
-    public function Bomdel()
-    {
+    public function Bomdel(){
         if ($this->request->isGet() === false) {
             $this->error('请求错误');
         }
@@ -1652,6 +1658,9 @@ class WorkOrder extends Api
             $result = \db('工单_bom资料')
                 ->where('UNIQID', $uniqid)
                 ->update($where);
+            $arr = \db('工单_面料资料')
+                ->where('UNIQID', $uniqid)
+                ->update($where);
             if (!$result) {
                 // 如果某个UNIQID更新失败,记录失败的ID
                 $allUpdated = false;
@@ -1672,6 +1681,7 @@ class WorkOrder extends Api
             $this->error('部分更新失败,无法更新以下UNIQID: ' . implode(', ', $failedUniqids));
         }
 
+//        $this->error('删除权限为开放');
     }
 
 
@@ -1709,25 +1719,68 @@ class WorkOrder extends Api
 
             // 处理物料信息
             $massage = empty($list['粘衬']) || $list['粘衬'] == '无' ? $list['面料'] : $list['面料'] . ',粘衬:' . $list['粘衬'];
+            $materialCategories = [];
+            $pattern = '/(\S+?):([^,]+)/'; // 匹配 类别:物料 格式
+
+            preg_match_all($pattern, $massage, $matches, PREG_SET_ORDER);
+
+            foreach ($matches as $match) {
+                $category = $match[1]; // 分类名称
+                $materials = explode('+', $match[2]); // 如果物料名称中有‘+’,则分开处理多个物料
+
+                // 将分类和对应的物料添加到数组中
+                foreach ($materials as $material) {
+                    $materialCategories[$category][] = trim($material); // 去除物料两边的空格
+                }
+            }
+
             $mianliao = $this->Gpt($massage);
 
-            // 插入物料数据
+//            // 插入物料数据
+//            $data = [];
+//            foreach ($mianliao as $key => $value) {
+//                if (!empty($value) && $value !== '粘衬') { // 排除空值和粘衬
+//                    $data[] = [
+//                        'BOM_工单编号' => $list['订单编号'],
+//                        'BOM_物料名称' => $value,
+//                        'BOM_desc' => '',
+//                        '物料分类' => '',
+//                        'Sys_rq' => date('Y-m-d H:i:s'),
+//                        'Sys_ID' => $list['Sys_id']
+//                    ];
+//                }
+//            }
             $data = [];
-            foreach ($mianliao as $key => $value) {
+            foreach ($mianliao as $value) {
                 if (!empty($value) && $value !== '粘衬') { // 排除空值和粘衬
+                    $category = '';
+
+                    // 查找物料对应的分类
+                    foreach ($materialCategories as $cat => $materials) {
+                        if (in_array($value, $materials)) {
+                            $category = $cat;
+                            break;
+                        }
+                    }
+
+                    // 如果找到分类,将数据存入BOM
                     $data[] = [
                         'BOM_工单编号' => $list['订单编号'],
                         'BOM_物料名称' => $value,
                         'BOM_desc' => '',
-                        '物料分类' => '',
+                        '物料分类' => $category ? $category : '',
                         'Sys_rq' => date('Y-m-d H:i:s'),
                         'Sys_ID' => $list['Sys_id']
                     ];
                 }
             }
-            echo "<pre>";
-            print_r($data);
-            echo "<pre>";
+            foreach ($data as &$item) {
+                if (empty($item['物料分类'])) {
+                    $item['物料分类'] = '';
+                }
+                // 去除所有非汉字字符
+                $item['物料分类'] = preg_replace('/[^\p{Han}]/u', '', $item['物料分类']);
+            }
             // 批量插入BOM资料
             if (!empty($data)) {
                 \db('工单_bom资料')->insertAll($data);
@@ -1863,10 +1916,12 @@ class WorkOrder extends Api
         if ($this->request->isPost() === false){
             $this->error('请求错误');
         }
+
         $param = Request::instance()->post();
         if (empty($param)){
             $this->error('请求错误');
         }
+
         // 判断前端传来的参数是否为空,避免空订单编号造成问题
         if(empty($param[0]['BOM_工单编号'])){
             $this->error('请求错误,请重新打开此页面');
@@ -1890,10 +1945,112 @@ class WorkOrder extends Api
                 $this->error('修改失败');
             }
         }
+        // 查询工单基本资料
+        $orderList = \db('工单_基本资料')
+            ->field('订单编号, 生产款号, Sys_id')
+            ->where('订单编号', $param[0]['BOM_工单编号'])
+            ->find();
+
+        if (!$orderList) {
+            $this->error('工单基本资料未找到');
+        }
+
+        // 查询所有颜色备注
+        $colorList = \db('工单_印件资料')
+            ->field('颜色备注')
+            ->where('订单编号', $orderList['订单编号'])
+            ->group('颜色备注')
+            ->select();
+
+        // 获取 BOM 面料数据
+        $BomList = \db('工单_bom资料')
+            ->where('BOM_工单编号', $orderList['订单编号'])
+            ->whereNull('Mod_rq')
+            ->select();
+
+        if (!$BomList) {
+            $this->error('BOM 面料数据未找到');
+        }
+
+        // 获取当前最大关联编号
+        $AssociatedNumber = \db('工单关联表')->order('关联编号 desc')->value('关联编号');
+        $number = empty($AssociatedNumber) ? 0 : (int)substr($AssociatedNumber, 4);
+
+        $MaterielList = [];
+        $MaterielLists = [];
+        $colorCounter = []; // 记录每种颜色的序号
+
+        foreach ($colorList as $color) {
+            $colorName = $color['颜色备注'];
+            $colorCounter[$colorName] = 1;
+
+            foreach ($BomList as $bom) {
+                $wulbm = $orderList['生产款号'] . '-' . $colorName . $colorCounter[$colorName]++;
+
+                // 检查工单面料资料是否存在
+                $existsMateriel = \db('工单_面料资料')
+                    ->where([
+                        'BOM_工单编号' => $orderList['订单编号'],
+                        'BOM_颜色' => $colorName,
+                        'BOM_物料名称' => $bom['BOM_物料名称']
+                    ])
+                    ->find();
+
+                if (!$existsMateriel) {
+                    $MaterielList[] = [
+                        'BOM_工单编号' => $orderList['订单编号'],
+                        'BOM_颜色' => $colorName,
+                        'BOM_物料名称' => $bom['BOM_物料名称'],
+                        'BOM_标准用量' => $bom['BOM_标准用量'],
+                        'BOM_计划用量' => $bom['BOM_计划用量'],
+                        'BOM_计划门幅' => $bom['BOM_计划门幅'],
+                        'BOM_定额门幅' => $bom['BOM_定额门幅'],
+                        'BOM_投料单位' => $bom['BOM_投料单位'],
+                        'BOM_desc' => $bom['BOM_desc'],
+                        'BOM_物料编码' => $wulbm,
+                        'Sys_ID' => $bom['Sys_ID'],
+                        'Sys_rq' => date('Y-m-d H:i:s')
+                    ];
+                }
+
+                // 检查工单关联表是否存在
+                $existsRelation = \db('工单关联表')
+                    ->where([
+                        '订单编号' => $orderList['订单编号'],
+                        '颜色' => $colorName,
+                        '物料名称' => $bom['BOM_物料名称']
+                    ])
+                    ->find();
+
+                if (!$existsRelation) {
+                    $MaterielLists[] = [
+                        '关联编号' => 'GDGL' . ($number + 1),
+                        '订单编号' => $orderList['订单编号'],
+                        '生产款号' => $orderList['生产款号'],
+                        '颜色' => $colorName,
+                        '物料编号' => $wulbm,
+                        '物料名称' => $bom['BOM_物料名称'],
+                        '备注' => $bom['BOM_desc'],
+                        'Sys_id' => $bom['Sys_ID'],
+                        'Sys_rq' => date('Y-m-d H:i:s')
+                    ];
+                    $number++;
+                }
+            }
+        }
+
+        // 批量插入数据
+        if (!empty($MaterielList)) {
+            \db('工单_面料资料')->insertAll($MaterielList);
+        }
+
+        if (!empty($MaterielLists)) {
+            \db('工单关联表')->insertAll($MaterielLists);
+        }
+
         $this->success('修改成功');
     }
 
-
     /**
      * 入库、出库、退还详情数据
      */
@@ -2035,6 +2192,12 @@ class WorkOrder extends Api
         $apiKey = 'sk-e0JuPjMntkbgi1BoMjrqyyzMKzAxILkQzyGMSy3xiMupuoWY'; // 替换为您的 API 密钥
 
         // 要发送给 GPT 的消息
+//        $messages = [
+//            [
+//                'role' => 'user',
+//                'content' => '你好,帮我按照:面料1、面料2、面料3……来整理归纳下面的面料信息,我只需要面料信息,不需要其他:'.$massage
+//            ]
+//        ];
         $messages = [
             [
                 'role' => 'user',
@@ -2099,34 +2262,63 @@ class WorkOrder extends Api
      */
     public function fabricListmonth()
     {
-        // 使用DATE_FORMAT函数提取年月部分,格式为 "YYYY-MM"
         $list = \db('物料_库存')
-            ->group('date')
-            ->order('date desc')
-            ->column('DATE_FORMAT(sys_rq, "%Y-%m") as date');
-        // 格式化返回的数据,生成期望的结构
+            ->group("DATE_FORMAT(sys_rq, '%Y-%m')")
+            ->orderRaw("DATE_FORMAT(sys_rq, '%Y-%m') desc")
+            ->column("DATE_FORMAT(sys_rq, '%Y-%m') as date");
+
         $result = [];
-        foreach ($list as $item){
+        foreach ($list as $item) {
             $result[$item] = \db('物料_库存')
-                ->group('date')
-                ->order('date desc')
-                ->column('DATE_FORMAT(sys_rq, "%Y-%m-%d") as date');
+                ->whereRaw("DATE_FORMAT(sys_rq, '%Y-%m') = ?", [$item])
+                ->order('sys_rq desc')
+                ->distinct('sys_rq')
+                ->column("DATE_FORMAT(sys_rq, '%Y-%m-%d') as date");
         }
         if (!empty($result)) {
-            $this->success('成功', $result);  // 返回查询到的结果
+            $this->success('成功', $result);
         } else {
-            $this->success('没有找到相关数据', []);  // 如果没有数据,返回空数组
+            $this->success('没有找到相关数据', []);
         }
     }
 
+    /**
+     * 获取每月的面料记录\设备_报工日志
+     * 入库出库退还日期
+     */
+    public function fetchMonthlyFabricRecords() {
+        $types = ['入库', '出库', '退还'];
+        $list = [];
+
+        foreach ($types as $type) {
+            $data = \db('设备_报工日志')
+                ->where('name', $type)
+                ->whereNull('Mod_rq')
+                ->field('DISTINCT DATE_FORMAT(rq, "%Y-%m") as month, DATE_FORMAT(rq, "%Y-%m-%d") as date')
+                ->order('rq desc')
+                ->select();
+
+            // 按照月份分组数据
+            $groupedData = [];
+            foreach ($data as $entry) {
+                $groupedData[$entry['month']][] = $entry['date'];
+            }
+
+            // 进一步去重,避免意外重复
+            foreach ($groupedData as $month => $dates) {
+                $groupedData[$month] = array_values(array_unique($dates));
+            }
+
+            // 添加到返回列表
+            $list[$type] = $groupedData;
+        }
+
+        $this->success('成功', $list);
+    }
 
 
     /**
      * 面料库存列表
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
      */
     public function fabricList()
     {
@@ -2147,8 +2339,8 @@ class WorkOrder extends Api
         }
 
         // 分页参数,防止未传递时出错
-        $page = isset($param['page']) ? (int)$param['page'] : 1;
-        $limit = isset($param['limit']) ? (int)$param['limit'] : 50;  // 默认每页50条数据
+        $page = isset($param['page']) ? (int)$param['page'] : 1;  // 默认第1页
+        $limit = isset($param['limit']) ? (int)$param['limit'] : 50; // 默认每页50条
 
         // 获取数据
         $data = \db('工单_面料资料')
@@ -2156,44 +2348,32 @@ class WorkOrder extends Api
             ->join('工单_基本资料 b', 'b.订单编号 = a.BOM_工单编号')
             ->field('a.BOM_工单编号 as 订单编号,a.BOM_颜色 as 颜色, b.生产款号 as 生产款号, b.客户编号 as 客户编号, b.款式 as 款式,
             a.BOM_物料编码,a.BOM_物料名称 as 物料名称, a.BOM_投料单位 as 投料单位,
+            a.BOM_标准用量 as 定额用料,a.Mod_rq,
             a.BOM_实际用量 as 裁床实际用料, a.BOM_领用数量 as 裁床领用面料, a.BOM_退还数量 as 裁床退回仓库面料,a.BOM_desc,
             a.BOM_desc as 备注, a.UNIQID, a.BOM_库存总量 as 入库总量, a.BOM_计划门幅 as 计划门幅, a.BOM_定额门幅 as 定额门幅, 
             a.BOM_面料结余 as 面料结余, a.Sys_ID as ID, a.Sys_rq as 日期')
             ->where($where)
             ->group('a.BOM_物料编码')
-            ->order("a.BOM_工单编号 desc")
+            ->order("a.Sys_rq desc")
+            ->where('a.Mod_rq',null)
             ->limit(($page - 1) * $limit, $limit)
             ->select();
 
-        // 获取数据总数
-        $count = \db('工单_面料资料')
-            ->alias('a')
-            ->join('工单_基本资料 b', 'b.订单编号 = a.BOM_工单编号')
-            ->where($where)
-            ->count();
-
-        // 如果查询到数据
-        if (!empty($data)) {
-            // 构建返回数据
-            $list = [
-                'total' => $count,  // 总数
-                'table' => $data    // 数据内容
-            ];
-            // 返回成功响应
-            $this->success('成功', $list);
-        } else {
-            // 没有查询到数据
-            $this->success('没有找到相关数据', []);
-        }
+
+        // 统计条数进行分页
+        $count = \db('工单_面料资料')->where('BOM_工单编号',$param['order'])->count();
+        // 确保返回的格式固定
+        $list = [
+            'total' => $count,
+            'table' => $data ?: [] // 如果 $data 为空,返回空数组,而不是 ''
+        ];
+
+        $this->success('成功', $list);
     }
 
 
     /**
      * 单条面料详情
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
      */
     public function oneFabricDetail()
     {
@@ -2253,6 +2433,7 @@ class WorkOrder extends Api
             ->join('物料_库存 c','a.物料编码 = c.物料编号 AND a.批次号 = c.批次号')
             ->where('a.receipt_number',$param['receipt'])
             ->field('a.order_id as 订单编号,a.款号,a.物料名称,a.number as 数量,a.rq as 日期,a.sys_id as 操作机台,
+            a.departname,a.remark,
             a.receipt_number as 出库单据编号,a.recipient as 领用人员,b.BOM_颜色,c.单位,b.BOM_计划门幅 as 计划门幅,
             b.BOM_定额门幅 as 定额门幅,c.实际门幅,c.状态,c.库存数量,c.入仓总量')
             ->whereNull('a.Mod_rq')
@@ -2265,14 +2446,9 @@ class WorkOrder extends Api
     }
 
     /**
-     * 出库单列表
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 入库、出库、退还单号列表
      */
-    public function ReceiptList()
-    {
+    public function ReceiptList(){
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
@@ -2282,44 +2458,83 @@ class WorkOrder extends Api
         }
         $where= [];
         if (isset($param['search'])) {
-            $where['物料名称|款号|order_id|receipt_number'] = ['like', $param['search'] . '%'];
+            $where['物料名称|款号|order_id|receipt_number|款式|物料编码'] = ['like', $param['search'] . '%'];
         }
         if (isset($param['mouth'])) {
             $where['rq'] = ['like', $param['mouth'] . '%'];
         }
-        $page = $param['page'];
-        $limit = $param['limit'];
+        $page = isset($param['page']) ? (int)$param['page'] : 1;  // 默认第1页
+        $limit = isset($param['limit']) ? (int)$param['limit'] : 50; // 默认每页50条
+
         $list = \db('设备_报工日志')
+            ->where('Mod_rq', null)
             ->where($where)
-            ->field('receipt_number as 出库单,order_id as 订单编号,款号,物料编码,物料名称,rq as 日期,sys_id as 操作机台,recipient as 领料人员,name as 单号类型,sum(number) as 总数')
-            ->group('出库单')
+            ->where('name',$param['code'])
             ->order('rq desc')
-            ->where('Mod_rq',null)
             ->limit(($page-1)*$limit,$limit)
             ->select();
+        // 初始化一个合并后的数组
+        $merged = [];
+        foreach ($list as $item) {
+            $key = $item['receipt_number'];
+            if (!isset($merged[$key])) {
+                // 首次出现,初始化
+                $merged[$key] = [
+                    '单号类型' => $item['name'],
+                    '出库单' => $item['receipt_number'],
+                    '订单编号' => $item['order_id'],
+                    '款号' => $item['款号'],
+                    '款式' => $item['款式'],
+                    '物料编码' => $item['物料编码'],
+                    '物料名称' => $item['物料名称'],
+                    '总数' => floatval($item['number']),
+                    '日期' => $item['rq'],
+                    '操作机台' => $item['sys_id'],
+                    '领料人员' => $item['recipient'],
+                ];
+            } else {
+                // 合并相同 receipt_number 的记录
+                $merged[$key]['订单编号'] .= ',' . $item['order_id'];
+                $merged[$key]['款号'] .= ',' . $item['款号'];
+                $merged[$key]['款式'] .= ',' . $item['款式'];
+                $merged[$key]['物料编码'] .= ',' . $item['物料编码'];
+                $merged[$key]['物料名称'] .= ',' . $item['物料名称'];
+                $merged[$key]['总数'] += floatval($item['number']);
+            }
+        }
+
+        // 对需要的字段进行逗号分隔后的去重
+        foreach ($merged as &$item) {
+            $item['订单编号'] = implode(',', array_unique(explode(',', $item['订单编号'])));
+            $item['款号'] = implode(',', array_unique(explode(',', $item['款号'])));
+            $item['款式'] = implode(',', array_unique(explode(',', $item['款式'])));
+            $item['物料编码'] = implode(',', array_unique(explode(',', $item['物料编码'])));
+            $item['物料名称'] = implode(',', array_unique(explode(',', $item['物料名称'])));
+        }
+        unset($item); // 避免引用问题
+
+        //统计数量
         $count = \db('设备_报工日志')
             ->where($where)
+            ->where('name',$param['code'])
             ->field('receipt_number as 出库单')
             ->group('出库单')
             ->where('Mod_rq',null)
             ->order('rq desc')
             ->select();
-        if (empty($list)){
-            $this->success('未找到数据');
-        }else{
+
+        if (empty($merged)){
+            $this->success('未找到数据', '');
+        } else {
             $data['total'] = count($count);
-            $data['table'] = $list;
-            $this->success('成功',$data);
+            $data['table'] = array_values($merged);
+            $this->success('成功', $data);
         }
 
     }
 
     /**
      * 出库单左侧菜单
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
      */
     public function getReceiptTab()
     {
@@ -2438,7 +2653,4 @@ class WorkOrder extends Api
         }
     }
 
-
-    //单条工单BOM删除接口
-
 }

+ 243 - 184
application/api/controller/WorkOrderSpotCheck.php

@@ -489,7 +489,12 @@ class WorkOrderSpotCheck extends Api{
                     $where['c.工序编号'] = '3';
                     $where['c.mod_rq'] = null;
                     $existingRecords = \db('设备_产量计酬')->alias('c')
-                        ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num,c.UniqId,
+                        ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, 
+                         CASE 
+                            WHEN c.工序名称 IN ("裁剪", "车缝") THEN c.数量
+                            ELSE c.s_num 
+                            END as 数量,
+                         c.sczl_jtbh, c.sczl_bh, c.尾包, c.sys_rq, c.serial, c.serial_num,c.UniqId,
                                 y.zdtotal, y.sctotal, j.款式, y.颜色,y.颜色备注, CAST(c.serial_num AS SIGNED) as serial_num_numeric')
                         ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
                         ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
@@ -774,10 +779,9 @@ class WorkOrderSpotCheck extends Api{
                     // 将 $result 插入到 $sizeData['records'] 的最前面
                     array_unshift($sizeData['records'], $result);
 
-
                     $this->success('请求成功', [
-                        'serial' => $serial['serial'], // 流水号
-                        'serial_num' => $serial['serial_num'], // 序号
+                        'serial' => $serial['serial']+1, // 流水号
+                        'serial_num' => $serial['serial_num']+1, // 序号
                         'list' => $matchedOrder, // 报工
                         'headers' => $sizeData['headers'], // 尺码表头
                         'records' => $sizeData['records'] // 查询历史记录
@@ -2560,11 +2564,7 @@ class WorkOrderSpotCheck extends Api{
     }
 
     /**
-     * 出库报工
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
+     * 面料出库报工
      */
     public function outReport()
     {
@@ -2575,47 +2575,57 @@ class WorkOrderSpotCheck extends Api{
         if (empty($param)){
             $this->error('参数错误');
         }
-        foreach ($param as $item){
-            //查询库存表中的数量
+        foreach ($param as $item) {
+            // 更新库存数据
             $Inventory = \db('物料_库存')
                 ->where('批次号',$item['批次号'])
                 ->field('库存数量,领用数量')
                 ->find();
-            //构建物料库存数据
             $InventoryData = [
+                '批次号'   =>  $item['批次号'],
+                '关联号'   => $item['关联编号'],
+                '物料编号' => $item['物料编码'],
+                '物料名称' => $item['物料名称'],
+                '领用数量' => $Inventory['领用数量'] + (int)$item['number'],
                 '库存数量' => $Inventory['库存数量'] - (int)$item['number'],
-                '领用数量' => $Inventory['领用数量'] + (int)$item['number']
+                '实际门幅' => $item['实际门幅'],
+                '单位'     => $item['单位'],
+                '状态'     => 1,
+                'departname'        => $item['departname'],
+                'remark'        => $item['remark'],
+                'sys_id'   => $item['sys_id'],
+                'sys_rq'   => date('Y-m-d H:i:s'),
             ];
-            $ReportData = $item;
-            unset($ReportData['关联编号']);
-            $ReportData['批次号'] = $item['批次号'];
-            $ReportData['rq'] = date('Y-m-d H:i:s',time());
-            $ReportData['库存数量'] = $InventoryData['库存数量'];
-            //创建事务,存储库存表数据和入库报工表数据
-            Db::startTrans();
-            try {
-                //存储库存表数据
-                $InventorySql = \db('物料_库存')->where('批次号',$item['批次号'])->fetchSql(true)->update($InventoryData);
-                \db()->query($InventorySql);
-                //存储入库报工表数据
-                $ReportSql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
-                \db()->query($ReportSql);
-
-                //提交事务
-                Db::commit();
-            }catch (\Exception $e){
-                Db::rollback();
-            }
+            $sql = \db('物料_库存')->where('批次号',$item['批次号'])->fetchSql(true)->update($InventoryData);
+            \db()->query($sql);
+
+            // 记录入库报工日志
+            $ReportData = [
+                '批次号'       => $item['批次号'],
+                'order_id'     => $item['order_id'],
+                '款号'     => $item['款号'],
+                '物料编码'     => $item['物料编码'],
+                '物料名称'     => $item['物料名称'],
+                '库存数量'     => $item['number'],
+                'number'       => $item['number'],
+                'rq'          => $item['rq'],
+                'name'         => $item['name'],
+                'sys_id'       => $item['sys_id'],
+                'receipt_number' => $item['receipt_number'],
+                '客户编号'     => $item['客户编号'],
+                'departname'        => $item['departname'],
+                'remark'        => $item['remark'],
+                '款式'        => $item['款式'],
+                'sys_rq'      => date('Y-m-d H:i:s'),
+            ];
+            $sql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
+            \db()->query($sql);
         }
         $this->success('成功');
     }
 
     /**
      * 入库订单信息模糊查询
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
      */
     public function InputOrderSearch()
     {
@@ -2630,7 +2640,7 @@ class WorkOrderSpotCheck extends Api{
             ->alias('a')
             ->join('工单_面料资料 b','a.订单编号 = b.BOM_工单编号')
             ->join('工单关联表 c','a.订单编号 = c.订单编号 AND b.BOM_物料编码 = c.物料编号')
-            ->where('a.订单编号|a.生产款号','like','%'.$param['search'].'%')
+            ->where('a.生产款号|a.订单编号|b.BOM_物料编码','like','%'.$param['search'].'%')
             ->where('a.Mod_rq',null)
             ->where('b.Mod_rq',null)
             ->field('a.订单编号,a.生产款号,a.客户编号,a.款式,a.订单数量,a.落货日期,a.接单日期,a.Sys_id as 创建人员,
@@ -2647,116 +2657,99 @@ class WorkOrderSpotCheck extends Api{
 
     /**
      * 面料入库报工
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
      */
     public function inputStash()
     {
-        if ($this->request->isPost() === false){
+        if (!$this->request->isPost()) {
             $this->error('请求错误');
         }
         $param = Request::instance()->post();
-        if (empty($param)){
+        if (empty($param)) {
             $this->error('参数错误');
         }
-        foreach ($param as $item){
-            //查询批次号是否存在
-            $BatchNumber = \db('物料_库存')
-                ->where('物料编号',$item['物料编码'])
-                ->where('关联号',$item['关联编号'])
-                ->column('批次号');
-            if (empty($BatchNumber)){
-                $LastNumber = \db('物料_库存')
-                    ->order('批次号 desc')
+            foreach ($param as $item) {
+                // 查询是否已存在批次号
+                $BatchNumber = \db('物料_库存')
+                    ->where('物料编号', $item['物料编码'])
+                    ->where('关联号', $item['关联编号'])
                     ->value('批次号');
-                if (!empty($LastNumber)){
-                    $BatchNumber[0] = 'PCH'.((int)substr($LastNumber,3) + 1);
 
-                }else{
-                    $BatchNumber[0] = 'PCH1';
-                }
-                //构建库存表数据
-                $InventoryData = [
-                    '批次号' => $BatchNumber[0],
-                    '关联号' => $item['关联编号'],
-                    '物料编号' => $item['物料编码'],
-                    '物料名称' => $item['物料名称'],
-                    '入仓总量' => $item['number'],
-                    '库存数量' => $item['number'],
-                    '单位' => '米',
-                    '实际门幅' => $item['实际门幅'],
-                    '状态' => 1,
-                    'sys_id' => $item['sys_id'],
-                    'sys_rq' => date('Y-m-d H:i:s',time())
-                ];
-                $ReportData = $item;
-                unset($ReportData['关联编号']);
-                unset($ReportData['实际门幅']);
-                $ReportData['批次号'] = $BatchNumber[0];
-                $ReportData['rq'] = date('Y-m-d H:i:s',time());
-                $ReportData['库存数量'] = $InventoryData['库存数量'];
-                //创建事务,存储库存表数据和入库报工表数据
-                db()->startTrans();
-                try {
-                    //存储库存表数据
-                    $InventorySql = \db('物料_库存')->fetchSql(true)->insert($InventoryData);
-                    \db()->query($InventorySql);
-                    //存储入库报工表数据
-                    $ReportSql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
-                    \db()->query($ReportSql);
-
-                    //提交事务
-                    \db()->commit();
-                }catch (\Exception $e){
-                    \db()->rollback();
-                    $this->error($e->getMessage());
+                // 生成批次号
+                if (empty($BatchNumber)) {
+                    $LastNumber = \db('物料_库存')->order('批次号 DESC')->value('批次号');
+                    $BatchNumber = !empty($LastNumber) ? 'PCH' . ((int)substr($LastNumber, 3) + 1) : 'PCH1';
+
+                    // 物料_库存
+                    $InventoryData = [
+                        '批次号'   => $BatchNumber,
+                        '关联号'   => $item['关联编号'],
+                        '物料编号' => $item['物料编码'],
+                        '物料名称' => $item['物料名称'],
+                        '入仓总量' => $item['number'],
+                        '库存数量' => $item['number'],
+                        '单位'     => $item['单位'],
+                        '实际门幅' => $item['实际门幅'],
+                        '状态'     => 1,
+                        'departname'        => $item['departname'],
+                        'remark'        => $item['remark'],
+                        'sys_id'   => $item['sys_id'],
+                        'sys_rq'   => date('Y-m-d H:i:s'),
+                    ];
+                    $sql = \db('物料_库存')->fetchSql(true)->insert($InventoryData);
+                    \db()->query($sql);
+                } else {
+                    // 更新库存数据
+                    $Inventory = \db('物料_库存')
+                        ->where('批次号', $BatchNumber)
+                        ->field('入仓总量,库存数量')
+                        ->find();
+                    $InventoryData = [
+                        '批次号'   =>  $item['批次号'],
+                        '关联号'   => $item['关联编号'],
+                        '物料编号' => $item['物料编码'],
+                        '物料名称' => $item['物料名称'],
+                        '入仓总量' => $Inventory['入仓总量'] + $item['number'],
+                        '库存数量' => $Inventory['库存数量'] + $item['number'],
+                        '实际门幅' => $item['实际门幅'],
+                        '单位'     => $item['单位'],
+                        '状态'     => 1,
+                        'departname'        => $item['departname'],
+                        'remark'        => $item['remark'],
+                        'sys_id'   => $item['sys_id'],
+                        'sys_rq'   => date('Y-m-d H:i:s'),
+                    ];
+                    $sql = \db('物料_库存')->fetchSql(true)->where('批次号',$BatchNumber)->update($InventoryData);
+                    \db()->query($sql);
                 }
-            }else{
-                //查询库存表中的数量
-                $Inventory = \db('物料_库存')
-                    ->where('批次号',$BatchNumber[0])
-                    ->field('入仓总量,库存数量')
-                    ->find();
-                //构建物料库存数据
-                $InventoryData = [
-                    '实际门幅' => $item['实际门幅'],
-                    '入仓总量' => $Inventory['入仓总量'] + $item['number'],
-                    '库存数量' => $Inventory['库存数量'] + $item['number']
+
+                // 记录入库报工日志
+                $ReportData = [
+                    '批次号'       => $BatchNumber,
+                    'order_id'     => $item['order_id'],
+                    '款号'     => $item['款号'],
+                    '物料编码'     => $item['物料编码'],
+                    '物料名称'     => $item['物料名称'],
+                    '库存数量'     => $item['number'],
+                    'number'       => $item['number'],
+                    'rq'          => $item['rq'],
+                    'name'         => $item['name'],
+                    'sys_id'       => $item['sys_id'],
+                    'receipt_number' => $item['receipt_number'],
+                    'departname'        => $item['departname'],
+                    'remark'        => $item['remark'],
+                    '客户编号'     => $item['客户编号'],
+                    '款式'        => $item['款式'],
+                    'sys_rq'      => date('Y-m-d H:i:s'),
                 ];
-                $ReportData = $item;
-                unset($ReportData['关联编号']);
-                unset($ReportData['实际门幅']);
-                $ReportData['批次号'] = $BatchNumber[0];
-                $ReportData['rq'] = date('Y-m-d H:i:s',time());
-                $ReportData['库存数量'] = $InventoryData['库存数量'];
-                //创建事务,存储库存表数据和入库报工表数据
-                \db()->startTrans();
-                try {
-                    //存储库存表数据
-                    $InventorySql = \db('物料_库存')->where('批次号',$BatchNumber[0])->fetchSql(true)->update($InventoryData);
-                    \db()->query($InventorySql);
-                    //存储入库报工表数据
-                    $ReportSql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
-                    \db()->query($ReportSql);
-
-                    //提交事务
-                    \db()->commit();
-                }catch (\Exception $e){
-                    \db()->rollback();
-                }
+                $sql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
+                \db()->query($sql);
             }
-        }
-        $this->success('成功');
+            $this->success('成功');
     }
 
+
     /**
      * 出库订单信息查询
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
      */
     public function OutOrderSearch()
     {
@@ -2772,7 +2765,7 @@ class WorkOrderSpotCheck extends Api{
             ->join('工单_面料资料 b','a.订单编号 = b.BOM_工单编号')
             ->join('物料_库存 c','b.BOM_物料编码 = c.物料编号','left')
             ->join('工单关联表 d','a.订单编号 = d.订单编号 AND d.物料编号 = b.BOM_物料编码')
-            ->where('a.订单编号|a.生产款号','like','%'.$param['search'].'%')
+            ->where('a.生产款号|a.订单编号|b.BOM_物料编码','like','%'.$param['search'].'%')
             ->where('a.Mod_rq',null)
             ->where('b.Mod_rq',null)
             ->where('c.状态',1)
@@ -2789,10 +2782,6 @@ class WorkOrderSpotCheck extends Api{
 
     /**
      * 获取入库面料信息
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
      */
     public function getInputDetail()
     {
@@ -2808,6 +2797,7 @@ class WorkOrderSpotCheck extends Api{
             ->join('物料_库存 a','a.物料编号 = b.BOM_物料编码 AND a.物料名称 = b.BOM_物料名称','left')
             ->join('工单关联表 c','b.BOM_物料编码 = c.物料编号 AND b.BOM_工单编号 = c.订单编号')
             ->field('a.批次号,c.关联编号,b.BOM_物料编码,b.BOM_物料名称,a.入仓总量,a.库存数量,a.领用数量,a.退还数量,a.单位,a.实际门幅,
+            a.departname,
             b.BOM_工单编号,b.BOM_颜色,b.BOM_计划门幅,b.BOM_定额门幅,b.BOM_计划用量 as 计划用料,b.BOM_标准用量 as 定额用料')
             ->where('c.关联编号',$param['关联编号'])
             ->where('c.订单编号',$param['订单编号'])
@@ -2837,60 +2827,129 @@ class WorkOrderSpotCheck extends Api{
         if (empty($param)){
             $this->error('参数错误');
         }
-        foreach ($param as $item){
-            //搜索批次号库存表中中数据
+        foreach ($param as $item) {
+            // 查询库存数据
             $number = \db('物料_库存')
-                ->where('批次号',$item['批次号'])
-                ->where('关联号',$item['关联编号'])
-                ->where('物料编号',$item['物料编码'])
-                ->field('库存数量,退还数量')
+                ->where('批次号', $item['批次号'])
+                ->where('关联号', $item['关联编号'])
+                ->where('物料编号', $item['物料编码'])
+                ->field('库存数量, 退还数量')
                 ->find();
-            if ($item['type'] === '退面料'){
-                //构建库存表数据
-                $InventoryData = [
-                    '退还数量' => $number['退还数量'] + (int)$item['number'],
-                    '库存数量' => $number['库存数量'] + (int)$item['number'],
-                ];
-            }elseif ($item['type'] === '退厂商'){
-                $InventoryData = [
-                    '退还数量' => $number['退还数量'],
-                    '库存数量' => $number['库存数量'] - (int)$item['number'],
-                ];
+
+            // 根据类型调整库存
+            if ($item['type'] === '退面料') {
+                $returnQuantity = $number['退还数量'] + (int)$item['number'];
+                $stockQuantity  = $number['库存数量'] + (int)$item['number'];
+            } elseif ($item['type'] === '退厂商') {
+                $returnQuantity = $item['number'];
+                $stockQuantity = $number['库存数量'] - (int)$item['number'];
             }else{
-                $InventoryData = [
-                    '退还数量' => $number['退还数量'],
-                    '库存数量' => $number['库存数量'],
-                ];
-            }
-            $ReportData = $item;
-            unset($ReportData['关联编号']);
-            unset($ReportData['实际门幅']);
-            $ReportData['批次号'] = $item['批次号'];
-            $ReportData['rq'] = date('Y-m-d H:i:s',time());
-            $ReportData['库存数量'] = $InventoryData['库存数量'];
-            //创建事务,存储库存表数据和入库报工表数据
-            db()->startTrans();
-            try {
-                //存储库存表数据
-                $InventorySql = \db('物料_库存')
-                    ->where('批次号',$item['批次号'])
-                    ->where('关联号',$item['关联编号'])
-                    ->where('物料编号',$item['物料编码'])
-                    ->fetchSql(true)
-                    ->update($InventoryData);
-                \db()->query($InventorySql);
-                //存储入库报工表数据
-                $ReportSql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
-                \db()->query($ReportSql);
-
-                //提交事务
-                \db()->commit();
-            }catch (\Exception $e){
-                \db()->rollback();
-                $this->error($e->getMessage());
+                $returnQuantity = $number['退还数量'];
+                $stockQuantity = $number['库存数量'];
             }
+
+            // 构建库存数据
+            $inventoryData = [
+                '批次号'   => $item['批次号'],
+                '关联号'   => $item['关联编号'],
+                '物料编号' => $item['物料编码'],
+                '物料名称' => $item['物料名称'],
+                '实际门幅' => $item['实际门幅'],
+                '单位'     => $item['单位'],
+                '状态'     => 1,
+                'sys_id'   => $item['sys_id'],
+                'departname'  => $item['departname'],
+                'remark'  => $item['remark'],
+                'sys_rq'   => date('Y-m-d H:i:s'),
+                '退还数量' => $returnQuantity, // 确保数据不会被覆盖
+                '库存数量' => $stockQuantity, // 确保数据不会被覆盖
+            ];
+
+            $InventorySql = \db('物料_库存')
+                ->where('批次号',$item['批次号'])
+                ->where('关联号',$item['关联编号'])
+                ->where('物料编号',$item['物料编码'])
+                ->fetchSql(true)
+                ->update($inventoryData);
+            \db()->query($InventorySql);
+
+            // 记录入库报工日志
+            $ReportData = [
+                '批次号'       => $item['批次号'],
+                'order_id'     => $item['order_id'],
+                '款号'     => $item['款号'],
+                '物料编码'     => $item['物料编码'],
+                '物料名称'     => $item['物料名称'],
+                '库存数量'     => $item['number'],
+                'number'       => $item['number'],
+                'rq'          => $item['rq'],
+                'name'         => $item['name'],
+                'sys_id'       => $item['sys_id'],
+                'receipt_number' => $item['receipt_number'],
+                'departname'  => $item['departname'],
+                'remark'  => $item['remark'],
+                '客户编号'     => $item['客户编号'],
+                '款式'        => $item['款式'],
+                'sys_rq'      => date('Y-m-d H:i:s'),
+            ];
+            $sql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
+            \db()->query($sql);
         }
         $this->success('成功');
+//        foreach ($param as $item){
+//            //搜索批次号库存表中中数据
+//            $number = \db('物料_库存')
+//                ->where('批次号',$item['批次号'])
+//                ->where('关联号',$item['关联编号'])
+//                ->where('物料编号',$item['物料编码'])
+//                ->field('库存数量,退还数量')
+//                ->find();
+//            if ($item['type'] === '退面料'){
+//                //构建库存表数据
+//                $InventoryData = [
+//                    '退还数量' => $number['退还数量'] + (int)$item['number'],
+//                    '库存数量' => $number['库存数量'] + (int)$item['number'],
+//                ];
+//            }elseif ($item['type'] === '退厂商'){
+//                $InventoryData = [
+//                    '退还数量' => $number['退还数量'],
+//                    '库存数量' => $number['库存数量'] - (int)$item['number'],
+//                ];
+//            }else{
+//                $InventoryData = [
+//                    '退还数量' => $number['退还数量'],
+//                    '库存数量' => $number['库存数量'],
+//                ];
+//            }
+//            $ReportData = $item;
+//            unset($ReportData['关联编号']);
+//            unset($ReportData['实际门幅']);
+//            $ReportData['批次号'] = $item['批次号'];
+//            $ReportData['rq'] = date('Y-m-d H:i:s',time());
+//            $ReportData['库存数量'] = $InventoryData['库存数量'];
+//            //创建事务,存储库存表数据和入库报工表数据
+//            db()->startTrans();
+//            try {
+//                //存储库存表数据
+//                $InventorySql = \db('物料_库存')
+//                    ->where('批次号',$item['批次号'])
+//                    ->where('关联号',$item['关联编号'])
+//                    ->where('物料编号',$item['物料编码'])
+//                    ->fetchSql(true)
+//                    ->update($InventoryData);
+//                \db()->query($InventorySql);
+//                //存储入库报工表数据
+//                $ReportSql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
+//                \db()->query($ReportSql);
+//
+//                //提交事务
+//                \db()->commit();
+//            }catch (\Exception $e){
+//                \db()->rollback();
+//                $this->error($e->getMessage());
+//            }
+//        }
+//        $this->success('成功');
     }
 
 }

+ 0 - 77
application/api/controller/WorkOrderVerification.php

@@ -74,83 +74,6 @@ class WorkOrderVerification extends Api
 //        ]);
 //    }
 
-    /**
-     * 记录报工日志历史记录
-     */
-    public function getTabByGdbh()
-    {
-        if (Request::instance()->isPost() === false){
-            $this->error('请求错误');
-        }
-        $param = Request::instance()->post();
-        if (empty($param)){
-            $this->error('参数错误');
-        }
-
-        $rows = db()->table('工单_基本资料')
-            ->where('订单编号',$param['订单编号'])
-            ->find();
-
-        $param['客户编号'] = $rows['客户编号'];
-        $sql= \db('设备_报工记录')->fetchSql(true)->insert($param);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
-        }
-
-    }
-
-    /**
-     * 获取报工日志
-     * @ApiMethod (GET)
-     */
-    public function getList()
-    {
-        if(!$this->request->isGet()){
-            $this->error('请求方式错误');
-        }
-        $param = $this->request->param();
-        // 判断订单编号是否包含 '-'
-        if (strpos($param['order'], '-') !== false) {
-            // 如果订单包含 '-',则按子订单编号精确匹配
-            $where['子订单编号'] = $param['order'];
-        } else {
-            // 如果订单不包含 '-',则按订单编号进行模糊匹配
-            $where['订单编号'] = ['like', '%' . $param['order'] . '%'];
-        }
-        // 过滤条件中的 code
-        $where['code'] = $param['code'];
-        // 查询数据库
-        $rows = db()->table('设备_报工记录')
-            ->where($where)
-            ->order('子订单编号 desc')
-            ->select();
-        // 提取 cm1 到 cm10 的数据
-        $headers = [];
-        if (!empty($rows)) {
-            foreach ($rows as $row) {
-                for ($i = 1; $i <= 10; $i++) {
-                    $cmField = 'cm' . $i;
-                    if (isset($row[$cmField]) && $row[$cmField] !== '') {
-                        // 仅在字段不为空时添加到 headers
-                        $headers[] = $row[$cmField];
-                    }
-                }
-            }
-            // 去重,避免重复值
-            $headers = array_unique($headers);
-            sort($headers);
-        }
-        $data = [
-            'table'   => $rows,
-            'headers' => $headers,
-            'total'   => count($rows),
-        ];
-        $this->success('成功', $data);
-    }
-
     /**
      * 生产产量进度月报表(Excel)
      */