瀏覽代碼

Merge branch 'master' of https://git.7in6.com/liuhairui/mes-dc-server-api

zck 1 月之前
父節點
當前提交
3a81c40584

+ 92 - 37
application/api/controller/Manufacture.php

@@ -1285,49 +1285,104 @@ class Manufacture extends Api
         $this->success('成功', $data);
     }
 
+
     /**
-     * 辅料计划入库时间更新
+     * 出货大货报表:辅料计划入库时间 / 计划生产小组(同一入口,按参数区分)
+     * 辅料计划入库时间:Uniqid + rq + sys_id
+     * 计划生产小组:     Uniqid + 计划生产小组 + sys_id(不传 rq)
      */
-    public function AccessoriesInboundTime(){
-        if ($this->request->isPost() === false) {
-            $this->error('请求错误');
+    public function AccessoriesInboundTime()
+    {
+        if (!$this->request->isPost()) {
+            return $this->error('请求错误');
         }
-        $param = Request::instance()->post();
-        if (empty($param)) {
-            $this->error('参数错误');
+
+        $param = $this->request->post();
+
+        // 必传参数
+        if (empty($param['Uniqid']) || empty($param['sys_id'])) {
+            return $this->error('参数错误');
         }
-        // 判断Uniqid是否为多个,多个以逗号分隔
-        $uniqids = strpos($param['Uniqid'], ',') !== false ? explode(',', $param['Uniqid']) : [$param['Uniqid']];
 
+        $uniqids = strpos($param['Uniqid'], ',') !== false
+            ? explode(',', $param['Uniqid'])
+            : [$param['Uniqid']];
+
+        // ===================== 最简逻辑 =====================
+        // 有 rq → 更新时间
         if (!empty($param['rq'])) {
-            // 准备更新数据
             $data = [
-                '辅料计划入库时间' => $param['rq'],
+                '辅料计划入库时间'   => trim($param['rq']),
                 '辅料计划入库操作人' => $param['sys_id'],
             ];
-        }else{
-            // 准备更新数据
+        }
+        // 没有 rq → 更新小组
+        else {
             $data = [
-                '辅料计划入库时间' => date('Y-m-d H:i:s'),
-                '辅料计划入库操作人' => $param['sys_id'],
+                '计划生产小组'       => trim($param['计划生产小组'] ?? ''),
+                '计划生产小组操作人' => $param['sys_id'],
+                '计划生产小组时间'   => date('Y-m-d H:i:s'),
             ];
         }
-        // 遍历所有Uniqid进行更新
         foreach ($uniqids as $uniqid) {
-            $list = \db('工单_基本资料')
-                ->where('Uniqid', $uniqid)
-                ->fetchSql(true)
-                ->update($data);
-            $res = \db()->query($list);
-            // 如果更新失败,直接返回错误
-            if ($res === false) {
-                $this->error('更新辅料计划入库时间失败');
+            $uniqid = trim($uniqid);
+            if ($uniqid) {
+                $list = \db('工单_基本资料')
+                    ->where('Uniqid', $uniqid)
+                    ->fetchSql(true)
+                    ->update($data);
+                $res = \db()->query($list);
+                if ($res === false) {
+                    $this->error('操作失败');
+                }
             }
         }
-        // 所有更新操作都成功时,返回成功
-        $this->success('更新成功');
+        return $this->success('操作成功');
     }
 
+//    /**
+//     * 辅料计划入库时间更新
+//     */
+//    public function AccessoriesInboundTime(){
+//        if ($this->request->isPost() === false) {
+//            $this->error('请求错误');
+//        }
+//        $param = Request::instance()->post();
+//        if (empty($param)) {
+//            $this->error('参数错误');
+//        }
+//        // 判断Uniqid是否为多个,多个以逗号分隔
+//        $uniqids = strpos($param['Uniqid'], ',') !== false ? explode(',', $param['Uniqid']) : [$param['Uniqid']];
+//
+//        if (!empty($param['rq'])) {
+//            // 准备更新数据
+//            $data = [
+//                '辅料计划入库时间' => $param['rq'],
+//                '辅料计划入库操作人' => $param['sys_id'],
+//            ];
+//        }else{
+//            // 准备更新数据
+//            $data = [
+//                '辅料计划入库时间' => date('Y-m-d H:i:s'),
+//                '辅料计划入库操作人' => $param['sys_id'],
+//            ];
+//        }
+//        // 遍历所有Uniqid进行更新
+//        foreach ($uniqids as $uniqid) {
+//            $list = \db('工单_基本资料')
+//                ->where('Uniqid', $uniqid)
+//                ->fetchSql(true)
+//                ->update($data);
+//            $res = \db()->query($list);
+//            // 如果更新失败,直接返回错误
+//            if ($res === false) {
+//                $this->error('更新辅料计划入库时间失败');
+//            }
+//        }
+//        // 所有更新操作都成功时,返回成功
+//        $this->success('更新成功');
+//    }
+
     /**
      * 月度客户订单汇总
      */
@@ -1614,14 +1669,14 @@ public function getDateNodes()
     if ($this->request->isGet() === false) {
         $this->error('请求错误');
     }
-    
+
     //获取所有不重复的年份
     $yearList = \db('设备_产量计酬')
         ->field("DISTINCT DATE_FORMAT(sczl_rq, '%Y') as year")
         ->where('sczl_rq', 'not null')
         ->order('year', 'desc')
         ->select();
-    
+
     foreach ($yearList as $key => $year) {
         //根据年份获取不重复的月份
         $monthList = \db('设备_产量计酬')
@@ -1630,7 +1685,7 @@ public function getDateNodes()
             ->where("DATE_FORMAT(sczl_rq, '%Y') = '{$year['year']}'")
             ->order('month', 'asc')
             ->select();
-        
+
         foreach ($monthList as $k => $month) {
             //根据年份和月份获取不重复的日期
             $dayList = \db('设备_产量计酬')
@@ -1640,13 +1695,13 @@ public function getDateNodes()
                 ->where("DATE_FORMAT(sczl_rq, '%m') = '{$month['month']}'")
                 ->order('day', 'asc')
                 ->select();
-            
+
             $monthList[$k]['day_list'] = $dayList;
         }
-        
+
         $yearList[$key]['month_list'] = $monthList;
     }
-    
+
     $this->success('获取成功', $yearList);
 }
 //获取产量计酬详情数据
@@ -1655,25 +1710,25 @@ public function getCfdataDetail()
     if ($this->request->isGet() === false) {
         $this->error('请求错误');
     }
-    
+
     $param = $this->request->param();
     if (empty($param['year']) || empty($param['month']) || empty($param['day'])) {
         $this->error('请选择日期');
     }
-    
+
     //拼接日期进行筛选
     $date = $param['year'] . '-' . $param['month'] . '-' . $param['day'];
-    
+
     //查询数据
     $list = \db('设备_产量计酬')
         ->where("DATE_FORMAT(sczl_rq, '%Y-%m-%d') = '{$date}'")
         ->field('订单编号, 子订单编号, 款号, 尺码, 数量, sczl_bh')
         ->select();
-     
+
     if (empty($list)) {
         $this->success('暂无数据', []);
     }
-    
+
     $this->success('获取成功', $list);
 }
 }

+ 135 - 101
application/api/controller/OrderSuperLoss.php

@@ -121,10 +121,10 @@ class OrderSuperLoss extends Api
     //             \think\Db::raw('(SELECT SUM(数量) FROM 设备_产量计酬 WHERE 订单编号 = g.订单编号 AND 工序名称 = "包装" AND Mod_rq IS NULL) as 已完成数量'),
 
     //             // 生产组别 - 使用子查询
-    //             \think\Db::raw('(SELECT GROUP_CONCAT(DISTINCT SUBSTRING(sczl_jtbh, 3, 2) ORDER BY SUBSTRING(sczl_jtbh, 3, 2) SEPARATOR "、") 
-    //                         FROM 设备_产量计酬 
-    //                         WHERE 订单编号 = g.订单编号 
-    //                         AND 工序名称 = "车缝" 
+    //             \think\Db::raw('(SELECT GROUP_CONCAT(DISTINCT SUBSTRING(sczl_jtbh, 3, 2) ORDER BY SUBSTRING(sczl_jtbh, 3, 2) SEPARATOR "、")
+    //                         FROM 设备_产量计酬
+    //                         WHERE 订单编号 = g.订单编号
+    //                         AND 工序名称 = "车缝"
     //                         AND Mod_rq IS NULL) as 生产组别'),
 
     //             // 占位字段
@@ -161,109 +161,143 @@ class OrderSuperLoss extends Api
 
     //     $this->success('成功', $list);
     // }
+
     /**
- * 根据月份获取工单数据
- */
-public function getWorkOrdersByMonth()
-{
-    // 1. 请求方法校验
-    if (!$this->request->isGet()) {
-        return $this->error('请求错误');
-    }
+     * 根据月份获取工单数据
+     */
+    public function getWorkOrdersByMonth()
+    {
+        if (!$this->request->isGet()) {
+            return $this->error('请求错误');
+        }
 
-    // 2. 参数接收与严格校验
-    $rq = $this->request->get('rq', '', 'trim');
-    if (empty($rq) || !preg_match('/^\d{4}-\d{2}$/', $rq)) {
-        return $this->error('参数格式错误,请使用 YYYY-MM 格式');
-    }
+        $params = Request::instance()->param();
+        $rq = $this->request->get('rq', '', 'trim');
 
-    // 3. 日期范围计算(安全、无歧义)
-    [$year, $month] = explode('-', $rq);
-    $start = "{$year}-{$month}-01 00:00:00";
-    $end = date('Y-m-01 00:00:00', strtotime("{$year}-{$month}-01 +1 month"));
-
-
-    $productSub = \think\Db::table('设备_产量计酬')
-        ->whereNull('Mod_rq')
-        ->group('订单编号')
-        ->field([
-            '订单编号',
-            "MIN(CASE WHEN 工序名称 = '裁剪' THEN sczl_rq END) AS 开裁日期",
-            "SUM(CASE WHEN 工序名称 = '裁剪' THEN 数量 END) AS 实裁数量",
-            "MIN(CASE WHEN 工序名称 = '车缝' THEN sczl_rq END) AS 上车位日期",
-            "MIN(CASE WHEN 工序名称 = '车缝' AND 尾包 = 1 THEN sczl_rq END) AS 车位完成日期",
-            "MIN(CASE WHEN 工序名称 = '手工' AND 尾包 = 1 THEN sczl_rq END) AS 后道完成日期",
-            "SUM(CASE WHEN 工序名称 = '包装' THEN 数量 END) AS 已完成数量",
-            // 修复长度限制
-            \think\Db::raw('GROUP_CONCAT(DISTINCT CASE WHEN 工序名称 = "车缝" THEN SUBSTRING(sczl_jtbh, 3, 2) END ORDER BY SUBSTRING(sczl_jtbh, 3, 2) SEPARATOR "、") AS 生产组别'),
-        ])
-        ->buildSql();
-
-
-    $stockSub = \think\Db::table('库存_出入库明细')
-        ->whereNull('Mod_rq') // 这里补上!
-        ->group('order_id')
-        ->field([
-            'order_id',
-            'MIN(CASE WHEN name = "入库" THEN rq END) AS 面料入库时间',
-        ])
-        ->buildSql();
-
-
-    $list = \think\Db::table('工单_基本资料')
-        ->alias('g')
-        ->Join([$productSub => 'p'], 'g.订单编号 = p.订单编号')
-        ->Join([$stockSub => 's'], 'g.订单编号 = s.order_id')
-            ->where('g.落货日期', '>=', $start)
-            ->where('g.落货日期', '<', $end)
-            ->whereNull('g.Mod_rq')
-        ->field([
-            'g.Uniqid',
-            'g.订单编号',
-            'g.审核 AS 核批',
-            'g.审核日期 AS 核批日期',
-            'g.接单日期 AS 下单日期',
-            'g.落货日期 AS 货期',
-            'g.生产款号 AS 款号',
-            'g.订单数量',
-            'g.工单入仓数量 AS 入库数量',
-            'g.款式',
-            'g.客户编号 AS 客人编号',
-            'g.辅料计划入库时间',
-            's.面料入库时间',
-            'p.开裁日期',
-            'p.实裁数量',
-            'p.上车位日期',
-            'p.车位完成日期',
-            'p.后道完成日期',
-            'p.已完成数量',
-            'p.生产组别',
-            \think\Db::raw('NULL AS 辅料入库时间'),
-            \think\Db::raw('NULL AS 台产'),
-            \think\Db::raw('NULL AS 产前样批核'),
-            \think\Db::raw('NULL AS 备注'),
-        ])
-        ->select();
-
-
-    $dateFields = [
-        '下单日期', '货期', '面料入库时间', '开裁日期',
-        '上车位日期', '车位完成日期', '后道完成日期'
-    ];
-
-    foreach ($list as &$item) {
-        foreach ($dateFields as $field) {
-            $item[$field] = !empty($item[$field]) ? date('Y-m-d', strtotime($item[$field])) : null;
+        // 分页参数
+        $page = isset($params['page']) ? (int)$params['page'] : 1;
+        $limit = isset($params['limit']) ? (int)$params['limit'] : 30;
+
+        // 构建基础查询条件
+        $where = [];
+        // 搜索条件
+        if (!empty($params['search'])) {
+            $where['g.订单编号|g.生产款号'] = array('like', '%' . $params['search'] . '%');
         }
-        $item['实裁数量'] = (int)($item['实裁数量'] ?? 0);
-        $item['已完成数量'] = (int)($item['已完成数量'] ?? 0);
-        $item['订单数量'] = (int)($item['订单数量'] ?? 0);
-        $item['入库数量'] = (int)($item['入库数量'] ?? 0);
-        $item['生产组别'] = $item['生产组别'] ?? '';
+        // 通用删除标记条件
+        $where['g.Mod_rq'] = null;
+
+        //月份条件非必传
+        if (!empty($rq)) {
+            // 只有传了 rq 月份,才拼接日期范围
+            [$year, $month] = explode('-', $rq);
+            $start = "{$year}-{$month}-01 00:00:00";
+            $end = date('Y-m-01 00:00:00', strtotime("{$year}-{$month}-01 +1 month"));
+
+            $where['g.落货日期'] = ['between', [$start, $end]];
+        }
+
+        // 生产计酬子查询
+        $productSub = \think\Db::table('设备_产量计酬')
+            ->whereNull('Mod_rq')
+            ->group('订单编号')
+            ->field([
+                '订单编号',
+                "MIN(CASE WHEN 工序名称 = '裁剪' THEN sczl_rq END) AS 开裁日期",
+                "SUM(CASE WHEN 工序名称 = '裁剪' THEN 数量 END) AS 实裁数量",
+                "MIN(CASE WHEN 工序名称 = '车缝' THEN sczl_rq END) AS 上车位日期",
+                "MIN(CASE WHEN 工序名称 = '车缝' AND 尾包 = 1 THEN sczl_rq END) AS 车位完成日期",
+                "MIN(CASE WHEN 工序名称 = '手工' AND 尾包 = 1 THEN sczl_rq END) AS 后道完成日期",
+                "SUM(CASE WHEN 工序名称 = '包装' THEN 数量 END) AS 已完成数量",
+                // 1. sczl_bh 作为 生产组别
+                \think\Db::raw('GROUP_CONCAT(DISTINCT CASE WHEN 工序名称 = "车缝" THEN sczl_bh END ORDER BY sczl_bh SEPARATOR "、") AS 生产组别'),
+                // 2. 原来的 sczl_jtbh 截取结果 作为 机台号
+                \think\Db::raw('GROUP_CONCAT(DISTINCT CASE WHEN 工序名称 = "车缝" THEN SUBSTRING(sczl_jtbh, 3, 2) END ORDER BY SUBSTRING(sczl_jtbh, 3, 2) SEPARATOR "、") AS 机台号'),
+            ])
+            ->buildSql();
+
+        // 库存出入库子查询
+        $stockSub = \think\Db::table('库存_出入库明细')
+            ->whereNull('Mod_rq')
+            ->group('order_id')
+            ->field([
+                'order_id',
+                'MIN(CASE WHEN name = "入库" THEN rq END) AS 面料入库时间',
+            ])
+            ->buildSql();
+
+        // ===================== 先查询 总条数 =====================
+        $total = \think\Db::table('工单_基本资料')
+            ->alias('g')
+            ->join([$productSub => 'p'], 'g.订单编号 = p.订单编号', 'LEFT')
+            ->join([$stockSub => 's'], 'g.订单编号 = s.order_id', 'LEFT')
+            ->where($where)
+            ->count();
+
+        // ===================== 再查询 分页列表 =====================
+        $list = \think\Db::table('工单_基本资料')
+            ->alias('g')
+            ->join([$productSub => 'p'], 'g.订单编号 = p.订单编号', 'LEFT')
+            ->join([$stockSub => 's'], 'g.订单编号 = s.order_id', 'LEFT')
+            ->where($where)
+            ->limit(($page - 1) * $limit, $limit)
+            ->field([
+                'g.Uniqid',
+                'g.订单编号',
+                'g.审核 AS 核批',
+                'g.审核日期 AS 核批日期',
+                'g.接单日期 AS 下单日期',
+                'g.落货日期 AS 货期',
+                'g.生产款号 AS 款号',
+                'g.订单数量',
+                'g.工单入仓数量 AS 入库数量',
+                'g.款式',
+                'g.客户编号 AS 客人编号',
+                'g.辅料计划入库时间',
+                'g.计划生产小组',
+                's.面料入库时间',
+                'p.开裁日期',
+                'p.实裁数量',
+                'p.上车位日期',
+                'p.车位完成日期',
+                'p.后道完成日期',
+                'p.已完成数量',
+                'p.机台号',
+                'p.生产组别',
+                \think\Db::raw('NULL AS 辅料入库时间'),
+                \think\Db::raw('NULL AS 台产'),
+                \think\Db::raw('NULL AS 产前样批核'),
+                \think\Db::raw('NULL AS 备注'),
+            ])
+            ->select();
+
+        // 日期格式化 + 数据类型处理
+        $dateFields = [
+            '下单日期', '货期', '面料入库时间', '开裁日期',
+            '上车位日期', '车位完成日期', '后道完成日期'
+        ];
+
+        foreach ($list as &$item) {
+            foreach ($dateFields as $field) {
+                $item[$field] = !empty($item[$field]) ? date('Y-m-d', strtotime($item[$field])) : null;
+            }
+            $item['实裁数量'] = (int)($item['实裁数量'] ?? 0);
+            $item['已完成数量'] = (int)($item['已完成数量'] ?? 0);
+            $item['订单数量'] = (int)($item['订单数量'] ?? 0);
+            $item['入库数量'] = (int)($item['入库数量'] ?? 0);
+            $item['机台号'] = $item['机台号'] ?? '';
+            $item['实际生产小组'] = $item['生产组别'] ?? '';
+        }
+
+        // 返回格式:data + total
+        return $this->success('成功', [
+            'list' => $list,
+            'total' => $total,
+            'page' => $page,
+            'limit' => $limit
+        ]);
     }
 
-    return $this->success('成功', $list);
-}
 
 }
 

+ 89 - 17
application/api/controller/Staff.php

@@ -22,28 +22,38 @@ class Staff extends Api
 
     /**
      * 获取部门列表
+     * 一级:部门 dept_name(固定排序)
+     * 二级:工序 big_process
+     * 排序:裁剪、车缝、手工、大烫、总检、包装、其他
+     * 空工序 = 其他
      */
-    public function getDepartment(){
-        if (Request::instance()->isGet() == false){
+    /**
+     * 获取部门列表
+     * 一级:部门 dept_name
+     * 二级:工序 big_process(按固定顺序:裁剪、车缝、手工、大烫、总检、包装、其他)
+     * 空工序 = 其他
+     */
+    public function getDepartment()
+    {
+        if (Request::instance()->isGet() == false) {
             $this->error('非法请求');
         }
 
-        // 1. 查询所有有效人员(按部门+工序分组)
+        // 1. 查询数据,空工序转为"其他"
         $list = db('人员_基本资料')
-            ->field('dept_name as 所在部门, big_process as 生产工序, COUNT(*) AS count')
+            ->field('dept_name, IF(big_process IS NULL OR big_process = "", "其他", big_process) as big_process, COUNT(*) AS count')
             ->whereNull('mod_rq')
-            ->group('所在部门, 生产工序')
-            ->order('id asc')
+            ->group('dept_name, big_process')
             ->select();
 
-        // 2. 构建 部门 → 工序 二级结构
+        // 2. 构建树形结构(一级:部门,二级:工序)
         $tree = [];
         foreach ($list as $item) {
-            $dept = $item['所在部门'];
-            $process = $item['生产工序'];
+            $dept = $item['dept_name'];
+            $process = $item['big_process'];
             $count = $item['count'];
 
-            // 初始化部门
+            // 初始化部门节点
             if (!isset($tree[$dept])) {
                 $tree[$dept] = [
                     'label' => $dept,
@@ -52,20 +62,82 @@ class Staff extends Api
                 ];
             }
 
-            // 总数累加
+            // 部门数累加
             $tree[$dept]['count'] += $count;
 
-            // 有生产工序 → 加入二级
-            if (!empty($process)) {
-                $tree[$dept]['children'][] = [
-                    'label' => $process,
-                    'count' => $count
-                ];
+            // 工序加入children
+            $tree[$dept]['children'][] = [
+                'label' => $process,
+                'count' => $count
+            ];
+        }
+
+        // 3. 对每个部门下的工序,按固定顺序排序
+        $sortList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装', '其他'];
+        foreach ($tree as &$deptNode) {
+            $sortedChildren = [];
+            foreach ($sortList as $process) {
+                foreach ($deptNode['children'] as $child) {
+                    if ($child['label'] === $process) {
+                        $sortedChildren[] = $child;
+                        break;
+                    }
+                }
             }
+            $deptNode['children'] = $sortedChildren;
         }
+
+        // 4. 转成索引数组返回
         $result = array_values($tree);
+
         $this->success('获取部门数据', $result);
     }
+//    public function getDepartment()
+//    {
+//        if (Request::instance()->isGet() == false) {
+//            $this->error('非法请求');
+//        }
+//
+//        // 1. 查询数据
+//        $list = db('人员_基本资料')
+//            ->field('big_process, dept_name, COUNT(*) AS count')
+//            ->whereNull('mod_rq')
+//            ->group('big_process, dept_name')
+//            ->select();
+//
+//        // 2. 构建树形结构
+//        $tree = [];
+//        foreach ($list as $item) {
+//            $process = $item['big_process'] ?: '其他'; // 空工序 = 其他
+//            $dept = $item['dept_name'];
+//            $count = $item['count'];
+//
+//            if (!isset($tree[$process])) {
+//                $tree[$process] = [
+//                    'label' => $process,
+//                    'count' => 0,
+//                    'children' => []
+//                ];
+//            }
+//
+//            $tree[$process]['count'] += $count;
+//            $tree[$process]['children'][] = [
+//                'label' => $dept,
+//                'count' => $count
+//            ];
+//        }
+//
+//        // 3. 固定排序:裁剪、车缝、手工、大烫、总检、包装、其他
+//        $sortList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装', '其他'];
+//        $result = [];
+//        foreach ($sortList as $item) {
+//            if (isset($tree[$item])) {
+//                $result[] = $tree[$item];
+//            }
+//        }
+//
+//        $this->success('获取部门数据', $result);
+//    }
 
     /**
      * 获取员工列表信息

+ 214 - 27
application/api/controller/WorkOrderProcess.php

@@ -63,7 +63,7 @@ class WorkOrderProcess extends Api
             ->order('part_code')
             ->select();
         if(empty($list)){
-            $this->error('该工单没有部件,请先添加部件');
+            // $this->error('该工单没有部件,请先添加部件');
         }
         $this->success('成功', $list);
     }
@@ -89,7 +89,7 @@ class WorkOrderProcess extends Api
         if (empty($params['part_name'])) {
             $this->error('部件名称不能为空');
         }
-        
+
         // 检查是否传入了part_code
         if (!empty($params['part_code'])) {
             $code = $params['part_code'];
@@ -98,7 +98,7 @@ class WorkOrderProcess extends Api
                 ->where('work_order', $params['workorder'])
                 ->where('part_code', '>=', $code)
                 ->count();
-            
+
             if ($exists > 0) {
                 // 如果存在冲突,将后续编号自动加1
                 db('工单_部件资料')
@@ -113,7 +113,7 @@ class WorkOrderProcess extends Api
                 ->max('part_code');
             $code = $code ? $code + 1 : 1;
         }
-        
+
         $data = [
             'work_order' => $params['workorder'],
             'part_code' => $code,
@@ -209,39 +209,39 @@ class WorkOrderProcess extends Api
         if (!$this->request->isPost()) {
             $this->error('请求方法错误');
         }
-        
+
         $params = $this->request->post();
         if (empty($params['id'])) {
             $this->error('部件ID不能为空');
         }
-        
+
         $ids = explode(',', $params['id']);
         $ids = array_filter(array_map('intval', $ids));
-        
+
         if (empty($ids)) {
             $this->error('无效的部件ID');
         }
-        
+
         $result = db('工单_部件资料')
             ->whereIn('id', $ids)
             ->whereNull('del_rq')
             ->update(['del_rq' => date('Y-m-d H:i:s')]);
-        
+
         if ($result === false) {
             $this->error('删除失败');
         }
-        
+
         if ($result === 0) {
             $this->error('未找到可删除的部件');
         }
-        
+
         $this->success('删除成功');
     }
 
 
     /**
      * 工单工艺列表
-     *  @param workorder 工单编号 
+     *  @param workorder 工单编号
      */
     public function GetProcessList()
     {
@@ -252,22 +252,59 @@ class WorkOrderProcess extends Api
         if (empty($params['workorder'])) {
             $this->error('工单编号不能为空');
         }
+
         $list = db('工单_基础工艺资料')
             ->alias('a')
-            ->join('工单_部件资料 b', 'a.part_code = b.part_code and a.work_order = b.work_order')
+            ->join('工单_部件资料 b', 'a.part_code = b.part_code and a.work_order = b.work_order', 'LEFT')
             ->where('a.del_rq', null)
             ->where('a.work_order', $params['workorder'])
             ->where('b.del_rq', null)
-            ->field('a.id,a.part_code as 部件编号,b.part_name as 部件名称,a.process_code as 工艺编号,
-            a.process_name as 工艺名称,a.big_process as 大工艺,a.standard_hour as 标准工时,
-            a.standard_score as 标准公分,a.remark as 备注,a.coefficient as 系数,a.sys_id as 系统人,a.sys_rq as 系统时间,a.mod_id as 修改人,
-            a.mod_rq as 修改时间')
-            ->order('process_code')
+            ->field('a.id,a.part_code as 部件编号,
+                IFNULL(b.part_name, "") as 部件名称,
+                a.process_code as 工艺编号,
+                a.process_name as 工艺名称,
+                a.big_process as 大工艺,
+                a.standard_hour as 标准工时,
+                a.standard_score as 标准公分,
+                a.remark as 备注,
+                a.coefficient as 系数,
+                a.sys_id as 系统人,
+                a.sys_rq as 系统时间,
+                a.mod_id as 修改人,
+                a.mod_rq as 修改时间')
+            ->order('a.id')
             ->select();
+
         $this->success('成功', $list);
     }
 
-
+       /**
+     * 工单工艺列表
+     *  @param workorder 工单编号 
+     */
+    // public function GetProcessList()
+    // {
+    //     if (!$this->request->isGet()) {
+    //         $this->error('请求方法错误');
+    //     }
+    //     $params = $this->request->param();
+    //     if (empty($params['workorder'])) {
+    //         $this->error('工单编号不能为空');
+    //     }
+    //     $list = db('工单_基础工艺资料')
+    //         ->alias('a')
+    //         ->join('工单_部件资料 b', 'a.part_code = b.part_code and a.work_order = b.work_order')
+    //         ->where('a.del_rq', null)
+    //         ->where('a.work_order', $params['workorder'])
+    //         ->where('b.del_rq', null)
+    //         ->field('a.id,a.part_code as 部件编号,b.part_name as 部件名称,a.process_code as 序号,
+    //         a.process_name as 工序名称,a.big_process as 大工艺,a.standard_hour as 秒,a.standard_minutes as 分钟,
+    //         a.standard_score as 标准公分,a.money as 金额,a.remark as 备注,a.coefficient as 难度系数,a.sys_id as 操作人员,
+    //         a.sys_rq as 系统时间,a.mod_id as 修改人,a.mod_rq as 修改时间')
+    //         ->order('process_code')
+    //         ->select();
+    //     $this->success('成功', $list);
+    // }
     /**
      * 获取部件列表
      *  @param workorder 工单编号
@@ -281,7 +318,7 @@ class WorkOrderProcess extends Api
         if (empty($params['workorder'])) {
             $this->error('工单编号不能为空');
         }
-         $list = db('工单_部件资料')
+        $list = db('工单_部件资料')
             ->where('work_order', $params['workorder'])
             ->where('del_rq', null)
             ->field('part_code as 部件编号,part_name as 部件名称')
@@ -336,7 +373,7 @@ class WorkOrderProcess extends Api
         if (empty($params['sys_id'])) {
             $this->error('系统人不能为空');
         }
-        
+
         // 检查是否传入了process_code
         if (!empty($params['process_code'])) {
             $code = $params['process_code'];
@@ -346,7 +383,7 @@ class WorkOrderProcess extends Api
                 ->where('part_code', $params['part_code'])
                 ->where('process_code', '>=', $code)
                 ->count();
-            
+
             if ($exists > 0) {
                 // 如果存在冲突,将后续编号自动加1
                 db('工单_基础工艺资料')
@@ -363,7 +400,7 @@ class WorkOrderProcess extends Api
                 ->max('process_code');
             $code = $code ? $code + 1 : 1;
         }
-        
+
         $data = [
             'work_order' => $params['workorder'],
             'part_code' => $params['part_code'],
@@ -484,8 +521,8 @@ class WorkOrderProcess extends Api
     /**
      * 工单工艺复制
      *  @param workorder 工单编号
-     *  @param product_code 产品编号    
-     *  @param sys_id 操作人    
+     *  @param product_code 产品编号
+     *  @param sys_id 操作人
      *  @return array
      *  @throws \think\db\exception\DataNotFoundException
      *  @throws \think\db\exception\ModelNotFoundException
@@ -664,12 +701,12 @@ class WorkOrderProcess extends Api
 
         $this->success('排序成功');
     }
-        
+
 
     /**
      * 工单工艺excel导入
      *  @param workorder 工单编号
-     * 
+     *
      */
     public function importProcess()
     {
@@ -845,4 +882,154 @@ class WorkOrderProcess extends Api
         }
         return $data;
     }
+
+
+
+    /**
+     * 获取工单信息和工单制造工分
+     *  @param workorder 工单编号
+     *  @return array
+     *  @throws \think\db\exception\DataNotFoundException
+     *  @throws \think\db\exception\ModelNotFoundException
+     *  @throws \think\exception\DbException
+     */
+    public function getWorkOrderInfo()
+    {
+        if (!$this->request->isGet()) {
+            $this->error('请求方法错误');
+        }
+        $params = $this->request->param();
+        if (empty($params['workorder'])) {
+            $this->error('工单编号不能为空');
+        }
+        $where = [
+            '订单编号' => $params['workorder'],
+            'Mod_rq' => null,
+        ];
+        $workOrderInfo = Db::table('工单_基本资料')
+            ->where($where)
+            ->field('订单编号,客户编号,生产款号,款式,落货日期,审核日期,接单日期,审核,订单数量,计划制造工分,Uniqid')
+            ->find();
+        if (empty($workOrderInfo)) {
+            $this->error('工单不存在');
+        }
+        $this->success('成功', $workOrderInfo);
+        
+    }
+
+
+    /**
+     * 获取工单工艺信息
+     *  @param workorder 工单编号
+     *  @return array
+     *  @throws \think\db\exception\DataNotFoundException
+     *  @throws \think\db\exception\ModelNotFoundException
+     *  @throws \think\exception\DbException
+     */
+    public function getWorkOrderProcess()
+    {
+        if (!$this->request->isGet()) {
+            $this->error('请求方法错误');
+        }
+        $params = $this->request->param();
+        if (empty($params['workorder'])) {
+            $this->error('工单编号不能为空');
+        }
+        $where = [
+            'work_order' => $params['workorder'],
+            'del_rq' => null,
+        ];
+        $workOrderProcess = Db::table('工单_基础工艺资料')
+            ->where($where)
+            ->field('id,part_code as 部件编号,part_name as 部件名称,process_code as 工序编号,process_name as 工序名称,
+            big_process as 大工序,standard_hour as 秒,standard_minutes as 分,standard_score as 定额分,money as 金额,
+            coefficient as 难度系数,remark as 备注,status as 状态')
+            ->select();
+        if (empty($workOrderProcess)) {
+            $this->error('工单工艺不存在');
+        }
+        $this->success('成功', $workOrderProcess);
+    }
+
+
+    /**
+     * 修改工单计划制造工分
+     * @param id 工单Uniqid或订单编号
+     * @param number 计划制造工分
+     * @param sys_id 操作人
+     */
+    public function updateWorkOrderPlanManufacture()
+    {
+        if (!$this->request->isPost()) {
+            $this->error('请求方法错误');
+        }
+        $params = $this->request->post();
+        if (empty($params['id'])) {
+            $this->error('工单ID不能为空');
+        }
+        if (!isset($params['number']) || $params['number'] === '') {
+            $this->error('制造工分不能为空');
+        }
+        if (empty($params['sys_id'])) {
+            $this->error('操作人不能为空');
+        }
+
+        $workOrder = Db::table('工单_基本资料')
+            ->where('Uniqid|订单编号', $params['id'])
+            ->where('Mod_rq', null)
+            ->field('Uniqid,订单编号,计划制造工分')
+            ->find();
+        if (empty($workOrder)) {
+            $this->error('工单不存在');
+        }
+
+        $oldValue = $workOrder['计划制造工分'];
+        $newValue = $params['number'];
+        if ((string)$oldValue === (string)$newValue) {
+            $this->error('计划制造工分未发生变化');
+        }
+
+        $totalStandardScore = Db::table('工单_基础工艺资料')
+            ->where('work_order', $workOrder['订单编号'])
+            ->where('status', 0)
+            ->whereNull('del_rq')
+            ->sum('standard_score');
+        $totalStandardScore = $totalStandardScore ? floatval($totalStandardScore) : 0;
+        if ($totalStandardScore > floatval($newValue)) {
+            $this->error('工序定额分和大于制造工分,请修改确认之后再修改');
+        }
+
+        $operTime = date('Y-m-d H:i:s');
+        $logData = [
+            'order_no' => $workOrder['订单编号'],
+            'change_field' => '计划制造工分',
+            'old_value' => $oldValue === null ? '' : (string)$oldValue,
+            'new_value' => (string)$newValue,
+            'oper_type' => '修改工单计划制造工分',
+            'oper_user_name' => $params['sys_id'],
+            'oper_time' => $operTime,
+        ];
+
+        Db::startTrans();
+        try {
+            $updateResultSql = Db::table('工单_基本资料')
+                ->where('Uniqid', $workOrder['Uniqid'])
+                ->fetchSql(true)
+                ->update(['计划制造工分' => $newValue]);
+            $updateResult = Db::query($updateResultSql);
+            if ($updateResult === false) {
+                throw new \Exception('更新工单失败');
+            }
+            $logResult = Db::name('work_order_operation_log')->insert($logData);
+            if ($logResult === false) {
+                throw new \Exception('写入操作日志失败');
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error('修改失败');
+        }
+        $this->success('修改成功');
+    }
+   
 }